diff --git a/.gitignore b/.gitignore index 810ab28..4fbb628 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,57 @@ src/scratch.c src/RNAcode stamp-h1 RNAcode*.tar.gz + +##### C +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e69de29 diff --git a/.idea/RNAcode.iml b/.idea/RNAcode.iml new file mode 100644 index 0000000..bc2cd87 --- /dev/null +++ b/.idea/RNAcode.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0907017 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..38a4ad1 --- /dev/null +++ b/Makefile @@ -0,0 +1,829 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/RNAcode +pkgincludedir = $(includedir)/RNAcode +pkglibdir = $(libdir)/RNAcode +pkglibexecdir = $(libexecdir)/RNAcode +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = . +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ + $(am__configure_deps) $(am__DIST_COMMON) +am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ + configure.lineno config.status.lineno +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(docudir)" +DATA = $(docu_DATA) +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + cscope distdir dist dist-all distcheck +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \ + $(LISP)config.h.in +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +CSCOPE = cscope +DIST_SUBDIRS = $(SUBDIRS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in AUTHORS \ + COPYING ChangeLog INSTALL NEWS README compile depcomp \ + install-sh missing +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +distdir = $(PACKAGE)-$(VERSION) +top_distdir = $(distdir) +am__remove_distdir = \ + if test -d "$(distdir)"; then \ + find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ + && rm -rf "$(distdir)" \ + || { sleep 5 && rm -rf "$(distdir)"; }; \ + else :; fi +am__post_remove_distdir = $(am__remove_distdir) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +DIST_ARCHIVES = $(distdir).tar.gz +GZIP_ENV = --best +DIST_TARGETS = dist-gzip +distuninstallcheck_listfiles = find . -type f -print +am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ + | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' +distcleancheck_listfiles = find . -type f -print +ACLOCAL = ${SHELL} /home/work/projects/RNAcode/missing aclocal-1.15 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 1 +AUTOCONF = ${SHELL} /home/work/projects/RNAcode/missing autoconf +AUTOHEADER = ${SHELL} /home/work/projects/RNAcode/missing autoheader +AUTOMAKE = ${SHELL} /home/work/projects/RNAcode/missing automake-1.15 +AWK = gawk +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -g -O2 +CPP = gcc -E +CPPFLAGS = +CXX = g++ +CXXDEPMODE = depmode=gcc3 +CXXFLAGS = -g -O2 +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +EXEEXT = +GREP = /bin/grep +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +ISODATE = 2020-08-24 +LDFLAGS = +LIBOBJS = +LIBS = +LTLIBOBJS = +MAKEINFO = ${SHELL} /home/work/projects/RNAcode/missing makeinfo +MKDIR_P = /bin/mkdir -p +OBJEXT = o +PACKAGE = RNAcode +PACKAGE_BUGREPORT = wash@mit.edu +PACKAGE_NAME = RNAcode +PACKAGE_STRING = RNAcode 0.3 +PACKAGE_TARNAME = RNAcode +PACKAGE_URL = +PACKAGE_VERSION = 0.3 +PATH_SEPARATOR = : +RANLIB = ranlib +SET_MAKE = +SHELL = /bin/bash +STRIP = +VERSION = 0.3 +abs_builddir = /home/work/projects/RNAcode +abs_srcdir = /home/work/projects/RNAcode +abs_top_builddir = /home/work/projects/RNAcode +abs_top_srcdir = /home/work/projects/RNAcode +ac_ct_CC = gcc +ac_ct_CXX = g++ +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build_alias = +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host_alias = +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /home/work/projects/RNAcode/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = +top_builddir = . +top_srcdir = . +SUBDIRS = phyml levmar seqgen librna src examples +docu_DATA = INSTALL README AUTHORS COPYING +EXTRA_DIST = INSTALL README AUTHORS COPYING manual.pdf color-legend.pdf +docudir = $(pkgdatadir) +all: config.h + $(MAKE) $(AM_MAKEFLAGS) all-recursive + +.SUFFIXES: +am--refresh: Makefile + @: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + echo ' cd $(srcdir) && $(AUTOMAKE) --gnu'; \ + $(am__cd) $(srcdir) && $(AUTOMAKE) --gnu \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + echo ' $(SHELL) ./config.status'; \ + $(SHELL) ./config.status;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + $(SHELL) ./config.status --recheck + +$(top_srcdir)/configure: $(am__configure_deps) + $(am__cd) $(srcdir) && $(AUTOCONF) +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) +$(am__aclocal_m4_deps): + +config.h: stamp-h1 + @test -f $@ || rm -f stamp-h1 + @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1 + +stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status + @rm -f stamp-h1 + cd $(top_builddir) && $(SHELL) ./config.status config.h +$(srcdir)/config.h.in: $(am__configure_deps) + ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) + rm -f stamp-h1 + touch $@ + +distclean-hdr: + -rm -f config.h stamp-h1 +install-docuDATA: $(docu_DATA) + @$(NORMAL_INSTALL) + @list='$(docu_DATA)'; test -n "$(docudir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(docudir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(docudir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(docudir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(docudir)" || exit $$?; \ + done + +uninstall-docuDATA: + @$(NORMAL_UNINSTALL) + @list='$(docu_DATA)'; test -n "$(docudir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(docudir)'; $(am__uninstall_files_from_dir) + +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-recursive +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-recursive + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscope: cscope.files + test ! -s cscope.files \ + || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS) +clean-cscope: + -rm -f cscope.files +cscope.files: clean-cscope cscopelist +cscopelist: cscopelist-recursive + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + -rm -f cscope.out cscope.in.out cscope.po.out cscope.files + +distdir: $(DISTFILES) + $(am__remove_distdir) + test -d "$(distdir)" || mkdir "$(distdir)" + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done + -test -n "$(am__skip_mode_fix)" \ + || find "$(distdir)" -type d ! -perm -755 \ + -exec chmod u+rwx,go+rx {} \; -o \ + ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ + || chmod -R a+r "$(distdir)" +dist-gzip: distdir + tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz + $(am__post_remove_distdir) + +dist-bzip2: distdir + tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2 + $(am__post_remove_distdir) + +dist-lzip: distdir + tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz + $(am__post_remove_distdir) + +dist-xz: distdir + tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz + $(am__post_remove_distdir) + +dist-tarZ: distdir + @echo WARNING: "Support for distribution archives compressed with" \ + "legacy program 'compress' is deprecated." >&2 + @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 + tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z + $(am__post_remove_distdir) + +dist-shar: distdir + @echo WARNING: "Support for shar distribution archives is" \ + "deprecated." >&2 + @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 + shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz + $(am__post_remove_distdir) + +dist-zip: distdir + -rm -f $(distdir).zip + zip -rq $(distdir).zip $(distdir) + $(am__post_remove_distdir) + +dist dist-all: + $(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:' + $(am__post_remove_distdir) + +# This target untars the dist file and tries a VPATH configuration. Then +# it guarantees that the distribution is self-contained by making another +# tarfile. +distcheck: dist + case '$(DIST_ARCHIVES)' in \ + *.tar.gz*) \ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ + *.tar.bz2*) \ + bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ + *.tar.lz*) \ + lzip -dc $(distdir).tar.lz | $(am__untar) ;;\ + *.tar.xz*) \ + xz -dc $(distdir).tar.xz | $(am__untar) ;;\ + *.tar.Z*) \ + uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ + *.shar.gz*) \ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ + *.zip*) \ + unzip $(distdir).zip ;;\ + esac + chmod -R a-w $(distdir) + chmod u+w $(distdir) + mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst + chmod a-w $(distdir) + test -d $(distdir)/_build || exit 0; \ + dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ + && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ + && am__cwd=`pwd` \ + && $(am__cd) $(distdir)/_build/sub \ + && ../../configure \ + $(AM_DISTCHECK_CONFIGURE_FLAGS) \ + $(DISTCHECK_CONFIGURE_FLAGS) \ + --srcdir=../.. --prefix="$$dc_install_base" \ + && $(MAKE) $(AM_MAKEFLAGS) \ + && $(MAKE) $(AM_MAKEFLAGS) dvi \ + && $(MAKE) $(AM_MAKEFLAGS) check \ + && $(MAKE) $(AM_MAKEFLAGS) install \ + && $(MAKE) $(AM_MAKEFLAGS) installcheck \ + && $(MAKE) $(AM_MAKEFLAGS) uninstall \ + && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ + distuninstallcheck \ + && chmod -R a-w "$$dc_install_base" \ + && ({ \ + (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ + distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ + } || { rm -rf "$$dc_destdir"; exit 1; }) \ + && rm -rf "$$dc_destdir" \ + && $(MAKE) $(AM_MAKEFLAGS) dist \ + && rm -rf $(DIST_ARCHIVES) \ + && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ + && cd "$$am__cwd" \ + || exit 1 + $(am__post_remove_distdir) + @(echo "$(distdir) archives ready for distribution: "; \ + list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ + sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' +distuninstallcheck: + @test -n '$(distuninstallcheck_dir)' || { \ + echo 'ERROR: trying to run $@ with an empty' \ + '$$(distuninstallcheck_dir)' >&2; \ + exit 1; \ + }; \ + $(am__cd) '$(distuninstallcheck_dir)' || { \ + echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \ + exit 1; \ + }; \ + test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \ + || { echo "ERROR: files left after uninstall:" ; \ + if test -n "$(DESTDIR)"; then \ + echo " (check DESTDIR support)"; \ + fi ; \ + $(distuninstallcheck_listfiles) ; \ + exit 1; } >&2 +distcleancheck: distclean + @if test '$(srcdir)' = . ; then \ + echo "ERROR: distcleancheck can only run from a VPATH build" ; \ + exit 1 ; \ + fi + @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ + || { echo "ERROR: files left in build directory after distclean:" ; \ + $(distcleancheck_listfiles) ; \ + exit 1; } >&2 +check-am: all-am +check: check-recursive +all-am: Makefile $(DATA) config.h +installdirs: installdirs-recursive +installdirs-am: + for dir in "$(DESTDIR)$(docudir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-recursive + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-hdr distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: install-docuDATA + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -rf $(top_srcdir)/autom4te.cache + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-docuDATA + +.MAKE: $(am__recursive_targets) all install-am install-strip + +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ + am--refresh check check-am clean clean-cscope clean-generic \ + cscope cscopelist-am ctags ctags-am dist dist-all dist-bzip2 \ + dist-gzip dist-lzip dist-shar dist-tarZ dist-xz dist-zip \ + distcheck distclean distclean-generic distclean-hdr \ + distclean-tags distcleancheck distdir distuninstallcheck dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-docuDATA install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + installdirs-am maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \ + tags-am uninstall uninstall-am uninstall-docuDATA + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..7a91e9c --- /dev/null +++ b/Makefile.in @@ -0,0 +1,837 @@ +# Makefile.in generated by automake 1.16.2 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2020 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = . +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ + $(am__configure_deps) $(am__DIST_COMMON) +am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ + configure.lineno config.status.lineno +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(docudir)" +DATA = $(docu_DATA) +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + cscope distdir distdir-am dist dist-all distcheck +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \ + config.h.in +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +CSCOPE = cscope +DIST_SUBDIRS = $(SUBDIRS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in AUTHORS \ + COPYING ChangeLog INSTALL NEWS README compile config.guess \ + config.sub depcomp install-sh missing +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +distdir = $(PACKAGE)-$(VERSION) +top_distdir = $(distdir) +am__remove_distdir = \ + if test -d "$(distdir)"; then \ + find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ + && rm -rf "$(distdir)" \ + || { sleep 5 && rm -rf "$(distdir)"; }; \ + else :; fi +am__post_remove_distdir = $(am__remove_distdir) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +DIST_ARCHIVES = $(distdir).tar.gz +GZIP_ENV = --best +DIST_TARGETS = dist-gzip +distuninstallcheck_listfiles = find . -type f -print +am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ + | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' +distcleancheck_listfiles = find . -type f -print +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +ISODATE = @ISODATE@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +SUBDIRS = phyml/src levmar seqgen librna src examples +docu_DATA = INSTALL README AUTHORS COPYING +EXTRA_DIST = INSTALL README AUTHORS COPYING manual.pdf color-legend.pdf +docudir = $(pkgdatadir) +all: config.h + $(MAKE) $(AM_MAKEFLAGS) all-recursive + +.SUFFIXES: +am--refresh: Makefile + @: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + echo ' cd $(srcdir) && $(AUTOMAKE) --gnu'; \ + $(am__cd) $(srcdir) && $(AUTOMAKE) --gnu \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + echo ' $(SHELL) ./config.status'; \ + $(SHELL) ./config.status;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + $(SHELL) ./config.status --recheck + +$(top_srcdir)/configure: $(am__configure_deps) + $(am__cd) $(srcdir) && $(AUTOCONF) +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) +$(am__aclocal_m4_deps): + +config.h: stamp-h1 + @test -f $@ || rm -f stamp-h1 + @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1 + +stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status + @rm -f stamp-h1 + cd $(top_builddir) && $(SHELL) ./config.status config.h +$(srcdir)/config.h.in: $(am__configure_deps) + ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) + rm -f stamp-h1 + touch $@ + +distclean-hdr: + -rm -f config.h stamp-h1 +install-docuDATA: $(docu_DATA) + @$(NORMAL_INSTALL) + @list='$(docu_DATA)'; test -n "$(docudir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(docudir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(docudir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(docudir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(docudir)" || exit $$?; \ + done + +uninstall-docuDATA: + @$(NORMAL_UNINSTALL) + @list='$(docu_DATA)'; test -n "$(docudir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(docudir)'; $(am__uninstall_files_from_dir) + +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-recursive +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-recursive + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscope: cscope.files + test ! -s cscope.files \ + || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS) +clean-cscope: + -rm -f cscope.files +cscope.files: clean-cscope cscopelist +cscopelist: cscopelist-recursive + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + -rm -f cscope.out cscope.in.out cscope.po.out cscope.files + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + $(am__remove_distdir) + test -d "$(distdir)" || mkdir "$(distdir)" + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done + -test -n "$(am__skip_mode_fix)" \ + || find "$(distdir)" -type d ! -perm -755 \ + -exec chmod u+rwx,go+rx {} \; -o \ + ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ + || chmod -R a+r "$(distdir)" +dist-gzip: distdir + tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz + $(am__post_remove_distdir) + +dist-bzip2: distdir + tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2 + $(am__post_remove_distdir) + +dist-lzip: distdir + tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz + $(am__post_remove_distdir) + +dist-xz: distdir + tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz + $(am__post_remove_distdir) + +dist-zstd: distdir + tardir=$(distdir) && $(am__tar) | zstd -c $${ZSTD_CLEVEL-$${ZSTD_OPT--19}} >$(distdir).tar.zst + $(am__post_remove_distdir) + +dist-tarZ: distdir + @echo WARNING: "Support for distribution archives compressed with" \ + "legacy program 'compress' is deprecated." >&2 + @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 + tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z + $(am__post_remove_distdir) + +dist-shar: distdir + @echo WARNING: "Support for shar distribution archives is" \ + "deprecated." >&2 + @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 + shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz + $(am__post_remove_distdir) + +dist-zip: distdir + -rm -f $(distdir).zip + zip -rq $(distdir).zip $(distdir) + $(am__post_remove_distdir) + +dist dist-all: + $(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:' + $(am__post_remove_distdir) + +# This target untars the dist file and tries a VPATH configuration. Then +# it guarantees that the distribution is self-contained by making another +# tarfile. +distcheck: dist + case '$(DIST_ARCHIVES)' in \ + *.tar.gz*) \ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ + *.tar.bz2*) \ + bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ + *.tar.lz*) \ + lzip -dc $(distdir).tar.lz | $(am__untar) ;;\ + *.tar.xz*) \ + xz -dc $(distdir).tar.xz | $(am__untar) ;;\ + *.tar.Z*) \ + uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ + *.shar.gz*) \ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ + *.zip*) \ + unzip $(distdir).zip ;;\ + *.tar.zst*) \ + zstd -dc $(distdir).tar.zst | $(am__untar) ;;\ + esac + chmod -R a-w $(distdir) + chmod u+w $(distdir) + mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst + chmod a-w $(distdir) + test -d $(distdir)/_build || exit 0; \ + dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ + && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ + && am__cwd=`pwd` \ + && $(am__cd) $(distdir)/_build/sub \ + && ../../configure \ + $(AM_DISTCHECK_CONFIGURE_FLAGS) \ + $(DISTCHECK_CONFIGURE_FLAGS) \ + --srcdir=../.. --prefix="$$dc_install_base" \ + && $(MAKE) $(AM_MAKEFLAGS) \ + && $(MAKE) $(AM_MAKEFLAGS) dvi \ + && $(MAKE) $(AM_MAKEFLAGS) check \ + && $(MAKE) $(AM_MAKEFLAGS) install \ + && $(MAKE) $(AM_MAKEFLAGS) installcheck \ + && $(MAKE) $(AM_MAKEFLAGS) uninstall \ + && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ + distuninstallcheck \ + && chmod -R a-w "$$dc_install_base" \ + && ({ \ + (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ + distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ + } || { rm -rf "$$dc_destdir"; exit 1; }) \ + && rm -rf "$$dc_destdir" \ + && $(MAKE) $(AM_MAKEFLAGS) dist \ + && rm -rf $(DIST_ARCHIVES) \ + && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ + && cd "$$am__cwd" \ + || exit 1 + $(am__post_remove_distdir) + @(echo "$(distdir) archives ready for distribution: "; \ + list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ + sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' +distuninstallcheck: + @test -n '$(distuninstallcheck_dir)' || { \ + echo 'ERROR: trying to run $@ with an empty' \ + '$$(distuninstallcheck_dir)' >&2; \ + exit 1; \ + }; \ + $(am__cd) '$(distuninstallcheck_dir)' || { \ + echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \ + exit 1; \ + }; \ + test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \ + || { echo "ERROR: files left after uninstall:" ; \ + if test -n "$(DESTDIR)"; then \ + echo " (check DESTDIR support)"; \ + fi ; \ + $(distuninstallcheck_listfiles) ; \ + exit 1; } >&2 +distcleancheck: distclean + @if test '$(srcdir)' = . ; then \ + echo "ERROR: distcleancheck can only run from a VPATH build" ; \ + exit 1 ; \ + fi + @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ + || { echo "ERROR: files left in build directory after distclean:" ; \ + $(distcleancheck_listfiles) ; \ + exit 1; } >&2 +check-am: all-am +check: check-recursive +all-am: Makefile $(DATA) config.h +installdirs: installdirs-recursive +installdirs-am: + for dir in "$(DESTDIR)$(docudir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-recursive + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-hdr distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: install-docuDATA + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -rf $(top_srcdir)/autom4te.cache + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-docuDATA + +.MAKE: $(am__recursive_targets) all install-am install-strip + +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ + am--refresh check check-am clean clean-cscope clean-generic \ + cscope cscopelist-am ctags ctags-am dist dist-all dist-bzip2 \ + dist-gzip dist-lzip dist-shar dist-tarZ dist-xz dist-zip \ + dist-zstd distcheck distclean distclean-generic distclean-hdr \ + distclean-tags distcleancheck distdir distuninstallcheck dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-docuDATA install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + installdirs-am maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \ + tags-am uninstall uninstall-am uninstall-docuDATA + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/README b/README index 74ce4c8..5444bce 100644 --- a/README +++ b/README @@ -21,6 +21,7 @@ coding potential together with an associated p-value. You can compile and install RNAcode like this: +# ./autogen.sh # ./configure # make # make install (as root) @@ -211,3 +212,12 @@ RNA (2011), in revision ========== Stefan Washietl + + +5. Changes from phyml version 1 to version 3 +============================================ + +As the default parameters of phyml changed, the results may differ between both versions. +To change the options for phyml, take a look at parameter in Read_Command_Line() in phyml/cl.c. + + diff --git a/compile b/compile new file mode 120000 index 0000000..80e119e --- /dev/null +++ b/compile @@ -0,0 +1 @@ +/usr/share/automake-1.15/compile \ No newline at end of file diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..0e9aac7 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,402 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# examples/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/RNAcode +pkgincludedir = $(includedir)/RNAcode +pkglibdir = $(libdir)/RNAcode +pkglibexecdir = $(libexecdir)/RNAcode +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = examples +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +am__DIST_COMMON = $(srcdir)/Makefile.in +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} /home/work/projects/RNAcode/missing aclocal-1.15 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 1 +AUTOCONF = ${SHELL} /home/work/projects/RNAcode/missing autoconf +AUTOHEADER = ${SHELL} /home/work/projects/RNAcode/missing autoheader +AUTOMAKE = ${SHELL} /home/work/projects/RNAcode/missing automake-1.15 +AWK = gawk +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -g -O2 +CPP = gcc -E +CPPFLAGS = +CXX = g++ +CXXDEPMODE = depmode=gcc3 +CXXFLAGS = -g -O2 +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +EXEEXT = +GREP = /bin/grep +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +ISODATE = 2020-08-24 +LDFLAGS = +LIBOBJS = +LIBS = +LTLIBOBJS = +MAKEINFO = ${SHELL} /home/work/projects/RNAcode/missing makeinfo +MKDIR_P = /bin/mkdir -p +OBJEXT = o +PACKAGE = RNAcode +PACKAGE_BUGREPORT = wash@mit.edu +PACKAGE_NAME = RNAcode +PACKAGE_STRING = RNAcode 0.3 +PACKAGE_TARNAME = RNAcode +PACKAGE_URL = +PACKAGE_VERSION = 0.3 +PATH_SEPARATOR = : +RANLIB = ranlib +SET_MAKE = +SHELL = /bin/bash +STRIP = +VERSION = 0.3 +abs_builddir = /home/work/projects/RNAcode/examples +abs_srcdir = /home/work/projects/RNAcode/examples +abs_top_builddir = /home/work/projects/RNAcode +abs_top_srcdir = /home/work/projects/RNAcode +ac_ct_CC = gcc +ac_ct_CXX = g++ +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build_alias = +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host_alias = +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /home/work/projects/RNAcode/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../ +top_builddir = .. +top_srcdir = .. +EXTRA_DIST = coding.aln coding.maf genomic.maf genomic-preprocessed.maf noncoding.aln noncoding.maf +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu examples/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +tags TAGS: + +ctags CTAGS: + +cscope cscopelist: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic cscopelist-am \ + ctags-am distclean distclean-generic distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ + pdf-am ps ps-am tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/examples/Makefile.in b/examples/Makefile.in new file mode 100644 index 0000000..9bf1811 --- /dev/null +++ b/examples/Makefile.in @@ -0,0 +1,402 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = examples +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +am__DIST_COMMON = $(srcdir)/Makefile.in +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +ISODATE = @ISODATE@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +EXTRA_DIST = coding.aln coding.maf genomic.maf genomic-preprocessed.maf noncoding.aln noncoding.maf +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu examples/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +tags TAGS: + +ctags CTAGS: + +cscope cscopelist: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic cscopelist-am \ + ctags-am distclean distclean-generic distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ + pdf-am ps ps-am tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/examples/coding.aln b/examples/coding.aln index 5226be9..0ee5c6a 100644 --- a/examples/coding.aln +++ b/examples/coding.aln @@ -1,4 +1,4 @@ -CLUSTAL W(1.81) multiple sequence alignment +CLUSTAL W(1.81) multiple sequence 8 137 ec_K12.chr_fwd/3401506-3401703 TGCAGGCGTTACTTTTAGAACAGCAGGACGGCAAAACTCTCGCATCAGTACA--GACTCT diff --git a/examples/coding.aln_phyml_stats.txt b/examples/coding.aln_phyml_stats.txt new file mode 100644 index 0000000..e69de29 diff --git a/examples/coding.aln_phyml_tree.txt b/examples/coding.aln_phyml_tree.txt new file mode 100644 index 0000000..e69de29 diff --git a/examples/coding.maf_mc_stats.txt b/examples/coding.maf_mc_stats.txt new file mode 100644 index 0000000..e69de29 diff --git a/examples/coding.maf_mc_tree.txt b/examples/coding.maf_mc_tree.txt new file mode 100644 index 0000000..e69de29 diff --git a/examples/example.maf b/examples/example.maf new file mode 100644 index 0000000..1c7cb98 --- /dev/null +++ b/examples/example.maf @@ -0,0 +1,24 @@ +##maf version=1 scoring=tba.v8 +# tba.v8 (((human chimp) baboon) (mouse rat)) + +a score=23262.0 +s hg18.chr7 27578828 38 + 158545518 AAA-GGGAATGTTAACCAAATGA---ATTGTCTCTTACGGTG +s panTro1.chr6 28741140 38 + 161576975 AAA-GGGAATGTTAACCAAATGA---ATTGTCTCTTACGGTG +s baboon 116834 38 + 4622798 AAA-GGGAATGTTAACCAAATGA---GTTGTCTCTTATGGTG +s mm4.chr6 53215344 38 + 151104725 -AATGGGAATGTTAAGCAAACGA---ATTGTCTCTCAGTGTG +s rn3.chr4 81344243 40 + 187371129 -AA-GGGGATGCTAAGCCAATGAGTTGTTGTCTCTCAATGTG + +a score=5062.0 +s hg18.chr7 27699739 6 + 158545518 TAAAGA +s panTro1.chr6 28862317 6 + 161576975 TAAAGA +s baboon 241163 6 + 4622798 TAAAGA +s mm4.chr6 53303881 6 + 151104725 TAAAGA +s rn3.chr4 81444246 6 + 187371129 taagga + +a score=6636.0 +s hg18.chr7 27707221 13 + 158545518 gcagctgaaaaca +s panTro1.chr6 28869787 13 + 161576975 gcagctgaaaaca +s baboon 249182 13 + 4622798 gcagctgaaaaca +s mm4.chr6 53310102 13 + 151104725 ACAGCTGAAAATA + + diff --git a/levmar/Makefile b/levmar/Makefile new file mode 100644 index 0000000..cfc7d4a --- /dev/null +++ b/levmar/Makefile @@ -0,0 +1,540 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# levmar/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/RNAcode +pkgincludedir = $(includedir)/RNAcode +pkglibdir = $(libdir)/RNAcode +pkglibexecdir = $(libexecdir)/RNAcode +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = levmar +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +AR = ar +ARFLAGS = cru +AM_V_AR = $(am__v_AR_$(V)) +am__v_AR_ = $(am__v_AR_$(AM_DEFAULT_VERBOSITY)) +am__v_AR_0 = @echo " AR " $@; +am__v_AR_1 = +liblevmar_a_AR = $(AR) $(ARFLAGS) +liblevmar_a_LIBADD = +am_liblevmar_a_OBJECTS = Axb.$(OBJEXT) lmbc.$(OBJEXT) lm.$(OBJEXT) \ + lmlec.$(OBJEXT) misc.$(OBJEXT) +liblevmar_a_OBJECTS = $(am_liblevmar_a_OBJECTS) +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I. -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(liblevmar_a_SOURCES) +DIST_SOURCES = $(liblevmar_a_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} /home/work/projects/RNAcode/missing aclocal-1.15 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 1 +AUTOCONF = ${SHELL} /home/work/projects/RNAcode/missing autoconf +AUTOHEADER = ${SHELL} /home/work/projects/RNAcode/missing autoheader +AUTOMAKE = ${SHELL} /home/work/projects/RNAcode/missing automake-1.15 +AWK = gawk +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -g -O2 +CPP = gcc -E +CPPFLAGS = +CXX = g++ +CXXDEPMODE = depmode=gcc3 +CXXFLAGS = -g -O2 +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +EXEEXT = +GREP = /bin/grep +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +ISODATE = 2020-08-24 +LDFLAGS = +LIBOBJS = +LIBS = +LTLIBOBJS = +MAKEINFO = ${SHELL} /home/work/projects/RNAcode/missing makeinfo +MKDIR_P = /bin/mkdir -p +OBJEXT = o +PACKAGE = RNAcode +PACKAGE_BUGREPORT = wash@mit.edu +PACKAGE_NAME = RNAcode +PACKAGE_STRING = RNAcode 0.3 +PACKAGE_TARNAME = RNAcode +PACKAGE_URL = +PACKAGE_VERSION = 0.3 +PATH_SEPARATOR = : +RANLIB = ranlib +SET_MAKE = +SHELL = /bin/bash +STRIP = +VERSION = 0.3 +abs_builddir = /home/work/projects/RNAcode/levmar +abs_srcdir = /home/work/projects/RNAcode/levmar +abs_top_builddir = /home/work/projects/RNAcode +abs_top_srcdir = /home/work/projects/RNAcode +ac_ct_CC = gcc +ac_ct_CXX = g++ +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build_alias = +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host_alias = +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /home/work/projects/RNAcode/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../ +top_builddir = .. +top_srcdir = .. +noinst_LIBRARIES = liblevmar.a +liblevmar_a_SOURCES = Axb.c lmbc.c lm.c lmlec.c misc.c lm.h misc.h +noinst_HEADERS = lm.h misc.h Axb_core.c lmbc_core.c lmlec_core.c misc_core.c lm_core.c +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu levmar/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu levmar/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +liblevmar.a: $(liblevmar_a_OBJECTS) $(liblevmar_a_DEPENDENCIES) $(EXTRA_liblevmar_a_DEPENDENCIES) + $(AM_V_at)-rm -f liblevmar.a + $(AM_V_AR)$(liblevmar_a_AR) liblevmar.a $(liblevmar_a_OBJECTS) $(liblevmar_a_LIBADD) + $(AM_V_at)$(RANLIB) liblevmar.a + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +include ./$(DEPDIR)/Axb.Po +include ./$(DEPDIR)/lm.Po +include ./$(DEPDIR)/lmbc.Po +include ./$(DEPDIR)/lmlec.Po +include ./$(DEPDIR)/misc.Po + +.c.o: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ $< + +.c.obj: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-noinstLIBRARIES cscopelist-am ctags ctags-am distclean \ + distclean-compile distclean-generic distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/levmar/Makefile.in b/levmar/Makefile.in new file mode 100644 index 0000000..a744a5c --- /dev/null +++ b/levmar/Makefile.in @@ -0,0 +1,540 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = levmar +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +AR = ar +ARFLAGS = cru +AM_V_AR = $(am__v_AR_@AM_V@) +am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@) +am__v_AR_0 = @echo " AR " $@; +am__v_AR_1 = +liblevmar_a_AR = $(AR) $(ARFLAGS) +liblevmar_a_LIBADD = +am_liblevmar_a_OBJECTS = Axb.$(OBJEXT) lmbc.$(OBJEXT) lm.$(OBJEXT) \ + lmlec.$(OBJEXT) misc.$(OBJEXT) +liblevmar_a_OBJECTS = $(am_liblevmar_a_OBJECTS) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(liblevmar_a_SOURCES) +DIST_SOURCES = $(liblevmar_a_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +ISODATE = @ISODATE@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +noinst_LIBRARIES = liblevmar.a +liblevmar_a_SOURCES = Axb.c lmbc.c lm.c lmlec.c misc.c lm.h misc.h +noinst_HEADERS = lm.h misc.h Axb_core.c lmbc_core.c lmlec_core.c misc_core.c lm_core.c +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu levmar/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu levmar/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +liblevmar.a: $(liblevmar_a_OBJECTS) $(liblevmar_a_DEPENDENCIES) $(EXTRA_liblevmar_a_DEPENDENCIES) + $(AM_V_at)-rm -f liblevmar.a + $(AM_V_AR)$(liblevmar_a_AR) liblevmar.a $(liblevmar_a_OBJECTS) $(liblevmar_a_LIBADD) + $(AM_V_at)$(RANLIB) liblevmar.a + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Axb.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lm.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lmbc.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lmlec.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-noinstLIBRARIES cscopelist-am ctags ctags-am distclean \ + distclean-compile distclean-generic distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/librna/Makefile b/librna/Makefile new file mode 100644 index 0000000..adfa227 --- /dev/null +++ b/librna/Makefile @@ -0,0 +1,552 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# librna/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/RNAcode +pkgincludedir = $(includedir)/RNAcode +pkglibdir = $(libdir)/RNAcode +pkglibexecdir = $(libexecdir)/RNAcode +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = librna +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +AR = ar +ARFLAGS = cru +AM_V_AR = $(am__v_AR_$(V)) +am__v_AR_ = $(am__v_AR_$(AM_DEFAULT_VERBOSITY)) +am__v_AR_0 = @echo " AR " $@; +am__v_AR_1 = +libRNA_a_AR = $(AR) $(ARFLAGS) +libRNA_a_LIBADD = +am_libRNA_a_OBJECTS = fold_vars.$(OBJEXT) read_epars.$(OBJEXT) \ + energy_par.$(OBJEXT) utils.$(OBJEXT) fold.$(OBJEXT) \ + params.$(OBJEXT) alifold.$(OBJEXT) PS_dot.$(OBJEXT) \ + aln_util.$(OBJEXT) naview.$(OBJEXT) +libRNA_a_OBJECTS = $(am_libRNA_a_OBJECTS) +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I. -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libRNA_a_SOURCES) +DIST_SOURCES = $(libRNA_a_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} /home/work/projects/RNAcode/missing aclocal-1.15 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 1 +AUTOCONF = ${SHELL} /home/work/projects/RNAcode/missing autoconf +AUTOHEADER = ${SHELL} /home/work/projects/RNAcode/missing autoheader +AUTOMAKE = ${SHELL} /home/work/projects/RNAcode/missing automake-1.15 +AWK = gawk +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -g -O2 +CPP = gcc -E +CPPFLAGS = +CXX = g++ +CXXDEPMODE = depmode=gcc3 +CXXFLAGS = -g -O2 +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +EXEEXT = +GREP = /bin/grep +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +ISODATE = 2020-08-24 +LDFLAGS = +LIBOBJS = +LIBS = +LTLIBOBJS = +MAKEINFO = ${SHELL} /home/work/projects/RNAcode/missing makeinfo +MKDIR_P = /bin/mkdir -p +OBJEXT = o +PACKAGE = RNAcode +PACKAGE_BUGREPORT = wash@mit.edu +PACKAGE_NAME = RNAcode +PACKAGE_STRING = RNAcode 0.3 +PACKAGE_TARNAME = RNAcode +PACKAGE_URL = +PACKAGE_VERSION = 0.3 +PATH_SEPARATOR = : +RANLIB = ranlib +SET_MAKE = +SHELL = /bin/bash +STRIP = +VERSION = 0.3 +abs_builddir = /home/work/projects/RNAcode/librna +abs_srcdir = /home/work/projects/RNAcode/librna +abs_top_builddir = /home/work/projects/RNAcode +abs_top_srcdir = /home/work/projects/RNAcode +ac_ct_CC = gcc +ac_ct_CXX = g++ +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build_alias = +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host_alias = +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /home/work/projects/RNAcode/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../ +top_builddir = .. +top_srcdir = .. +noinst_LIBRARIES = libRNA.a +libRNA_a_SOURCES = fold_vars.c read_epars.c \ + energy_par.c utils.c fold.c params.c alifold.c PS_dot.c aln_util.c naview.c + +noinst_HEADERS = alifold.h energy_const.h fold.h\ + intloops.h params.h utils.h energy_par.h fold_vars.h\ + pair_mat.h PS_dot.h aln_util.h circfold.inc alicircfold.inc + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu librna/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu librna/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +libRNA.a: $(libRNA_a_OBJECTS) $(libRNA_a_DEPENDENCIES) $(EXTRA_libRNA_a_DEPENDENCIES) + $(AM_V_at)-rm -f libRNA.a + $(AM_V_AR)$(libRNA_a_AR) libRNA.a $(libRNA_a_OBJECTS) $(libRNA_a_LIBADD) + $(AM_V_at)$(RANLIB) libRNA.a + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +include ./$(DEPDIR)/PS_dot.Po +include ./$(DEPDIR)/alifold.Po +include ./$(DEPDIR)/aln_util.Po +include ./$(DEPDIR)/energy_par.Po +include ./$(DEPDIR)/fold.Po +include ./$(DEPDIR)/fold_vars.Po +include ./$(DEPDIR)/naview.Po +include ./$(DEPDIR)/params.Po +include ./$(DEPDIR)/read_epars.Po +include ./$(DEPDIR)/utils.Po + +.c.o: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ $< + +.c.obj: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-noinstLIBRARIES cscopelist-am ctags ctags-am distclean \ + distclean-compile distclean-generic distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/librna/Makefile.am b/librna/Makefile.am index c10b1cb..5718629 100644 --- a/librna/Makefile.am +++ b/librna/Makefile.am @@ -5,5 +5,7 @@ libRNA_a_SOURCES = fold_vars.c read_epars.c \ noinst_HEADERS =alifold.h energy_const.h fold.h\ intloops.h params.h utils.h energy_par.h fold_vars.h\ - pair_mat.h PS_dot.h aln_util.h circfold.inc alicircfold.inc - + pair_mat.h PS_dot.h aln_util.h circfold.inc alicircfold.inc + +all-local: + objcopy --weaken libRNA.a libRNA.a diff --git a/librna/Makefile.in b/librna/Makefile.in new file mode 100644 index 0000000..d2f0f53 --- /dev/null +++ b/librna/Makefile.in @@ -0,0 +1,552 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = librna +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +AR = ar +ARFLAGS = cru +AM_V_AR = $(am__v_AR_@AM_V@) +am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@) +am__v_AR_0 = @echo " AR " $@; +am__v_AR_1 = +libRNA_a_AR = $(AR) $(ARFLAGS) +libRNA_a_LIBADD = +am_libRNA_a_OBJECTS = fold_vars.$(OBJEXT) read_epars.$(OBJEXT) \ + energy_par.$(OBJEXT) utils.$(OBJEXT) fold.$(OBJEXT) \ + params.$(OBJEXT) alifold.$(OBJEXT) PS_dot.$(OBJEXT) \ + aln_util.$(OBJEXT) naview.$(OBJEXT) +libRNA_a_OBJECTS = $(am_libRNA_a_OBJECTS) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libRNA_a_SOURCES) +DIST_SOURCES = $(libRNA_a_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +ISODATE = @ISODATE@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +noinst_LIBRARIES = libRNA.a +libRNA_a_SOURCES = fold_vars.c read_epars.c \ + energy_par.c utils.c fold.c params.c alifold.c PS_dot.c aln_util.c naview.c + +noinst_HEADERS = alifold.h energy_const.h fold.h\ + intloops.h params.h utils.h energy_par.h fold_vars.h\ + pair_mat.h PS_dot.h aln_util.h circfold.inc alicircfold.inc + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu librna/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu librna/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +libRNA.a: $(libRNA_a_OBJECTS) $(libRNA_a_DEPENDENCIES) $(EXTRA_libRNA_a_DEPENDENCIES) + $(AM_V_at)-rm -f libRNA.a + $(AM_V_AR)$(libRNA_a_AR) libRNA.a $(libRNA_a_OBJECTS) $(libRNA_a_LIBADD) + $(AM_V_at)$(RANLIB) libRNA.a + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PS_dot.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alifold.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/aln_util.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/energy_par.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fold.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fold_vars.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/naview.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/params.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/read_epars.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-noinstLIBRARIES cscopelist-am ctags ctags-am distclean \ + distclean-compile distclean-generic distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/phyml/.gitignore b/phyml/.gitignore new file mode 100755 index 0000000..4baf71f --- /dev/null +++ b/phyml/.gitignore @@ -0,0 +1,48 @@ +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +Makefile.in +config.guess* +config.sub* +config.h.in +aclocal.m4 +compile +configure +depcomp +install-sh +missing +autom4te.cache +*~ +doc/html +doc/latex +\#*# +ltmain.sh +m4/*.m4 +*.orig \ No newline at end of file diff --git a/phyml/.travis.yml b/phyml/.travis.yml new file mode 100644 index 0000000..7ba9236 --- /dev/null +++ b/phyml/.travis.yml @@ -0,0 +1,34 @@ +sudo: required +cache: apt +language: c + +os: + - linux + - osx + +compiler: + - gcc + +script: +# build and install software into $HOME/local + - ./autogen.sh + - ./configure + - make + - sudo make install + - ./configure --enable-phyrex + - make clean + - make + - ./configure --enable-phytime + - make clean + - make + +# put the installed binary into the $PATH + - export PATH=$HOME/local/bin:$PATH + +# install testiphy + - cd + - git clone https://gitlab.com/testiphy/testiphy.git + +# run testiphy + - cd testiphy + - ./testiphy phyml \ No newline at end of file diff --git a/phyml/Makefile b/phyml/Makefile new file mode 100644 index 0000000..5d4e9e5 --- /dev/null +++ b/phyml/Makefile @@ -0,0 +1,673 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# phyml/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2018 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/RNAcode +pkgincludedir = $(includedir)/RNAcode +pkglibdir = $(libdir)/RNAcode +pkglibexecdir = $(libexecdir)/RNAcode +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = phyml +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +AR = ar +ARFLAGS = cru +AM_V_AR = $(am__v_AR_$(V)) +am__v_AR_ = $(am__v_AR_$(AM_DEFAULT_VERBOSITY)) +am__v_AR_0 = @echo " AR " $@; +am__v_AR_1 = +libPHYML_a_AR = $(AR) $(ARFLAGS) +libPHYML_a_LIBADD = +am_libPHYML_a_OBJECTS = alrt.$(OBJEXT) avx.$(OBJEXT) bionj.$(OBJEXT) \ + cl.$(OBJEXT) draw.$(OBJEXT) free.$(OBJEXT) help.$(OBJEXT) \ + interface.$(OBJEXT) io.$(OBJEXT) make.$(OBJEXT) mg.$(OBJEXT) \ + models.$(OBJEXT) nexus.$(OBJEXT) pars.$(OBJEXT) \ + rates.$(OBJEXT) simu.$(OBJEXT) sse.$(OBJEXT) tbe.$(OBJEXT) \ + tiporder.$(OBJEXT) xml.$(OBJEXT) ancestral.$(OBJEXT) \ + checkpoint.$(OBJEXT) date.$(OBJEXT) eigen.$(OBJEXT) \ + init.$(OBJEXT) lk.$(OBJEXT) main.$(OBJEXT) mcmc.$(OBJEXT) \ + mixt.$(OBJEXT) optimiz.$(OBJEXT) phyrex.$(OBJEXT) \ + rwrapper.$(OBJEXT) spr.$(OBJEXT) stats.$(OBJEXT) \ + times.$(OBJEXT) utilities.$(OBJEXT) +libPHYML_a_OBJECTS = $(am_libPHYML_a_OBJECTS) +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I. -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/alrt.Po ./$(DEPDIR)/ancestral.Po \ + ./$(DEPDIR)/avx.Po ./$(DEPDIR)/bionj.Po \ + ./$(DEPDIR)/checkpoint.Po ./$(DEPDIR)/cl.Po \ + ./$(DEPDIR)/date.Po ./$(DEPDIR)/draw.Po ./$(DEPDIR)/eigen.Po \ + ./$(DEPDIR)/free.Po ./$(DEPDIR)/help.Po ./$(DEPDIR)/init.Po \ + ./$(DEPDIR)/interface.Po ./$(DEPDIR)/io.Po ./$(DEPDIR)/lk.Po \ + ./$(DEPDIR)/main.Po ./$(DEPDIR)/make.Po ./$(DEPDIR)/mcmc.Po \ + ./$(DEPDIR)/mg.Po ./$(DEPDIR)/mixt.Po ./$(DEPDIR)/models.Po \ + ./$(DEPDIR)/nexus.Po ./$(DEPDIR)/optimiz.Po \ + ./$(DEPDIR)/pars.Po ./$(DEPDIR)/phyrex.Po ./$(DEPDIR)/rates.Po \ + ./$(DEPDIR)/rwrapper.Po ./$(DEPDIR)/simu.Po ./$(DEPDIR)/spr.Po \ + ./$(DEPDIR)/sse.Po ./$(DEPDIR)/stats.Po ./$(DEPDIR)/tbe.Po \ + ./$(DEPDIR)/times.Po ./$(DEPDIR)/tiporder.Po \ + ./$(DEPDIR)/utilities.Po ./$(DEPDIR)/xml.Po +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libPHYML_a_SOURCES) +DIST_SOURCES = $(libPHYML_a_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} /home/work/projects/RNAcode/missing aclocal-1.16 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 1 +AUTOCONF = ${SHELL} /home/work/projects/RNAcode/missing autoconf +AUTOHEADER = ${SHELL} /home/work/projects/RNAcode/missing autoheader +AUTOMAKE = ${SHELL} /home/work/projects/RNAcode/missing automake-1.16 +AWK = gawk +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -g -O2 +CPP = gcc -E +CPPFLAGS = +CXX = g++ +CXXDEPMODE = depmode=gcc3 +CXXFLAGS = -g -O2 +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +EXEEXT = +GREP = /bin/grep +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +ISODATE = 2020-09-22 +LDFLAGS = +LIBOBJS = +LIBS = +LTLIBOBJS = +MAKEINFO = ${SHELL} /home/work/projects/RNAcode/missing makeinfo +MKDIR_P = /bin/mkdir -p +OBJEXT = o +PACKAGE = RNAcode +PACKAGE_BUGREPORT = wash@mit.edu +PACKAGE_NAME = RNAcode +PACKAGE_STRING = RNAcode 0.3 +PACKAGE_TARNAME = RNAcode +PACKAGE_URL = +PACKAGE_VERSION = 0.3 +PATH_SEPARATOR = : +RANLIB = ranlib +SET_MAKE = +SHELL = /bin/bash +STRIP = +VERSION = 0.3 +abs_builddir = /home/work/projects/RNAcode/phyml +abs_srcdir = /home/work/projects/RNAcode/phyml +abs_top_builddir = /home/work/projects/RNAcode +abs_top_srcdir = /home/work/projects/RNAcode +ac_ct_CC = gcc +ac_ct_CXX = g++ +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build_alias = +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host_alias = +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /home/work/projects/RNAcode/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../ +top_builddir = .. +top_srcdir = .. +noinst_LIBRARIES = libPHYML.a +libPHYML_a_SOURCES = alrt.c avx.c bionj.c cl.c draw.c free.c help.c interface.c io.c make.c mg.c models.c nexus.c pars.c rates.c simu.c sse.c tbe.c tiporder.c xml.c ancestral.c checkpoint.c date.c eigen.c init.c lk.c main.c mcmc.c mixt.c optimiz.c phyrex.c rwrapper.c spr.c stats.c times.c utilities.c +noinst_HEADERS = alrt.h avx.h bionj.h cl.h draw.h free.h help.h interface.h io.h m4.h mcmc.h mixt.h mpi_boot.h nexus.h pars.h rates.h simu.h sse.h tbe.h tiporder.h xml.h ancestral.h beagle_utils.h checkpoint.h date.h eigen.h geo.h init.h invitee.h lk.h make.h mg.h models.h mxml.h optimiz.h phyrex.h rwrapper.h spr.h stats.h times.h utilities.h +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu phyml/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu phyml/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +libPHYML.a: $(libPHYML_a_OBJECTS) $(libPHYML_a_DEPENDENCIES) $(EXTRA_libPHYML_a_DEPENDENCIES) + $(AM_V_at)-rm -f libPHYML.a + $(AM_V_AR)$(libPHYML_a_AR) libPHYML.a $(libPHYML_a_OBJECTS) $(libPHYML_a_LIBADD) + $(AM_V_at)$(RANLIB) libPHYML.a + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +include ./$(DEPDIR)/alrt.Po # am--include-marker +include ./$(DEPDIR)/ancestral.Po # am--include-marker +include ./$(DEPDIR)/avx.Po # am--include-marker +include ./$(DEPDIR)/bionj.Po # am--include-marker +include ./$(DEPDIR)/checkpoint.Po # am--include-marker +include ./$(DEPDIR)/cl.Po # am--include-marker +include ./$(DEPDIR)/date.Po # am--include-marker +include ./$(DEPDIR)/draw.Po # am--include-marker +include ./$(DEPDIR)/eigen.Po # am--include-marker +include ./$(DEPDIR)/free.Po # am--include-marker +include ./$(DEPDIR)/help.Po # am--include-marker +include ./$(DEPDIR)/init.Po # am--include-marker +include ./$(DEPDIR)/interface.Po # am--include-marker +include ./$(DEPDIR)/io.Po # am--include-marker +include ./$(DEPDIR)/lk.Po # am--include-marker +include ./$(DEPDIR)/main.Po # am--include-marker +include ./$(DEPDIR)/make.Po # am--include-marker +include ./$(DEPDIR)/mcmc.Po # am--include-marker +include ./$(DEPDIR)/mg.Po # am--include-marker +include ./$(DEPDIR)/mixt.Po # am--include-marker +include ./$(DEPDIR)/models.Po # am--include-marker +include ./$(DEPDIR)/nexus.Po # am--include-marker +include ./$(DEPDIR)/optimiz.Po # am--include-marker +include ./$(DEPDIR)/pars.Po # am--include-marker +include ./$(DEPDIR)/phyrex.Po # am--include-marker +include ./$(DEPDIR)/rates.Po # am--include-marker +include ./$(DEPDIR)/rwrapper.Po # am--include-marker +include ./$(DEPDIR)/simu.Po # am--include-marker +include ./$(DEPDIR)/spr.Po # am--include-marker +include ./$(DEPDIR)/sse.Po # am--include-marker +include ./$(DEPDIR)/stats.Po # am--include-marker +include ./$(DEPDIR)/tbe.Po # am--include-marker +include ./$(DEPDIR)/times.Po # am--include-marker +include ./$(DEPDIR)/tiporder.Po # am--include-marker +include ./$(DEPDIR)/utilities.Po # am--include-marker +include ./$(DEPDIR)/xml.Po # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ $< + +.c.obj: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/alrt.Po + -rm -f ./$(DEPDIR)/ancestral.Po + -rm -f ./$(DEPDIR)/avx.Po + -rm -f ./$(DEPDIR)/bionj.Po + -rm -f ./$(DEPDIR)/checkpoint.Po + -rm -f ./$(DEPDIR)/cl.Po + -rm -f ./$(DEPDIR)/date.Po + -rm -f ./$(DEPDIR)/draw.Po + -rm -f ./$(DEPDIR)/eigen.Po + -rm -f ./$(DEPDIR)/free.Po + -rm -f ./$(DEPDIR)/help.Po + -rm -f ./$(DEPDIR)/init.Po + -rm -f ./$(DEPDIR)/interface.Po + -rm -f ./$(DEPDIR)/io.Po + -rm -f ./$(DEPDIR)/lk.Po + -rm -f ./$(DEPDIR)/main.Po + -rm -f ./$(DEPDIR)/make.Po + -rm -f ./$(DEPDIR)/mcmc.Po + -rm -f ./$(DEPDIR)/mg.Po + -rm -f ./$(DEPDIR)/mixt.Po + -rm -f ./$(DEPDIR)/models.Po + -rm -f ./$(DEPDIR)/nexus.Po + -rm -f ./$(DEPDIR)/optimiz.Po + -rm -f ./$(DEPDIR)/pars.Po + -rm -f ./$(DEPDIR)/phyrex.Po + -rm -f ./$(DEPDIR)/rates.Po + -rm -f ./$(DEPDIR)/rwrapper.Po + -rm -f ./$(DEPDIR)/simu.Po + -rm -f ./$(DEPDIR)/spr.Po + -rm -f ./$(DEPDIR)/sse.Po + -rm -f ./$(DEPDIR)/stats.Po + -rm -f ./$(DEPDIR)/tbe.Po + -rm -f ./$(DEPDIR)/times.Po + -rm -f ./$(DEPDIR)/tiporder.Po + -rm -f ./$(DEPDIR)/utilities.Po + -rm -f ./$(DEPDIR)/xml.Po + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/alrt.Po + -rm -f ./$(DEPDIR)/ancestral.Po + -rm -f ./$(DEPDIR)/avx.Po + -rm -f ./$(DEPDIR)/bionj.Po + -rm -f ./$(DEPDIR)/checkpoint.Po + -rm -f ./$(DEPDIR)/cl.Po + -rm -f ./$(DEPDIR)/date.Po + -rm -f ./$(DEPDIR)/draw.Po + -rm -f ./$(DEPDIR)/eigen.Po + -rm -f ./$(DEPDIR)/free.Po + -rm -f ./$(DEPDIR)/help.Po + -rm -f ./$(DEPDIR)/init.Po + -rm -f ./$(DEPDIR)/interface.Po + -rm -f ./$(DEPDIR)/io.Po + -rm -f ./$(DEPDIR)/lk.Po + -rm -f ./$(DEPDIR)/main.Po + -rm -f ./$(DEPDIR)/make.Po + -rm -f ./$(DEPDIR)/mcmc.Po + -rm -f ./$(DEPDIR)/mg.Po + -rm -f ./$(DEPDIR)/mixt.Po + -rm -f ./$(DEPDIR)/models.Po + -rm -f ./$(DEPDIR)/nexus.Po + -rm -f ./$(DEPDIR)/optimiz.Po + -rm -f ./$(DEPDIR)/pars.Po + -rm -f ./$(DEPDIR)/phyrex.Po + -rm -f ./$(DEPDIR)/rates.Po + -rm -f ./$(DEPDIR)/rwrapper.Po + -rm -f ./$(DEPDIR)/simu.Po + -rm -f ./$(DEPDIR)/spr.Po + -rm -f ./$(DEPDIR)/sse.Po + -rm -f ./$(DEPDIR)/stats.Po + -rm -f ./$(DEPDIR)/tbe.Po + -rm -f ./$(DEPDIR)/times.Po + -rm -f ./$(DEPDIR)/tiporder.Po + -rm -f ./$(DEPDIR)/utilities.Po + -rm -f ./$(DEPDIR)/xml.Po + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-noinstLIBRARIES cscopelist-am ctags \ + ctags-am distclean distclean-compile distclean-generic \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/phyml/Makefile.am b/phyml/Makefile.am index 56ec660..0c41732 100644 --- a/phyml/Makefile.am +++ b/phyml/Makefile.am @@ -1,5 +1,7 @@ noinst_LIBRARIES = libPHYML.a + +libPHYML_a_SOURCES = alrt.c avx.c bionj.c cl.c draw.c free.c help.c interface.c io.c make.c mg.c models.c nexus.c pars.c rates.c simu.c sse.c tbe.c tiporder.c xml.c ancestral.c checkpoint.c date.c eigen.c init.c lk.c main.c mcmc.c mixt.c optimiz.c phyrex.c rwrapper.c spr.c stats.c times.c utilities.c -libPHYML_a_SOURCES = alrt.c bionj.c cl.c draw.c eigen.c free.c interface.c lk.c m4.c main.c mc.c models.c optimiz.c options.c pars.c rates.c simu.c spr.c utilities.c -noinst_HEADERS = alrt.h bionj.h cl.h draw.h eigen.h free.h interface.h lk.h m4.h mc.h models.h optimiz.h options.h pars.h rates.h simu.h spr.h utilities.h mg.h +noinst_HEADERS = alrt.h avx.h bionj.h cl.h draw.h free.h help.h interface.h io.h m4.h mcmc.h mixt.h mpi_boot.h nexus.h pars.h rates.h simu.h sse.h tbe.h tiporder.h xml.h ancestral.h beagle_utils.h checkpoint.h date.h eigen.h geo.h init.h invitee.h lk.h make.h mg.h models.h mxml.h optimiz.h phyrex.h rwrapper.h spr.h stats.h times.h utilities.h + diff --git a/phyml/Makefile.in b/phyml/Makefile.in new file mode 100644 index 0000000..0c565f9 --- /dev/null +++ b/phyml/Makefile.in @@ -0,0 +1,673 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = phyml +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +AR = ar +ARFLAGS = cru +AM_V_AR = $(am__v_AR_@AM_V@) +am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@) +am__v_AR_0 = @echo " AR " $@; +am__v_AR_1 = +libPHYML_a_AR = $(AR) $(ARFLAGS) +libPHYML_a_LIBADD = +am_libPHYML_a_OBJECTS = alrt.$(OBJEXT) avx.$(OBJEXT) bionj.$(OBJEXT) \ + cl.$(OBJEXT) draw.$(OBJEXT) free.$(OBJEXT) help.$(OBJEXT) \ + interface.$(OBJEXT) io.$(OBJEXT) make.$(OBJEXT) mg.$(OBJEXT) \ + models.$(OBJEXT) nexus.$(OBJEXT) pars.$(OBJEXT) \ + rates.$(OBJEXT) simu.$(OBJEXT) sse.$(OBJEXT) tbe.$(OBJEXT) \ + tiporder.$(OBJEXT) xml.$(OBJEXT) ancestral.$(OBJEXT) \ + checkpoint.$(OBJEXT) date.$(OBJEXT) eigen.$(OBJEXT) \ + init.$(OBJEXT) lk.$(OBJEXT) main.$(OBJEXT) mcmc.$(OBJEXT) \ + mixt.$(OBJEXT) optimiz.$(OBJEXT) phyrex.$(OBJEXT) \ + rwrapper.$(OBJEXT) spr.$(OBJEXT) stats.$(OBJEXT) \ + times.$(OBJEXT) utilities.$(OBJEXT) +libPHYML_a_OBJECTS = $(am_libPHYML_a_OBJECTS) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/alrt.Po ./$(DEPDIR)/ancestral.Po \ + ./$(DEPDIR)/avx.Po ./$(DEPDIR)/bionj.Po \ + ./$(DEPDIR)/checkpoint.Po ./$(DEPDIR)/cl.Po \ + ./$(DEPDIR)/date.Po ./$(DEPDIR)/draw.Po ./$(DEPDIR)/eigen.Po \ + ./$(DEPDIR)/free.Po ./$(DEPDIR)/help.Po ./$(DEPDIR)/init.Po \ + ./$(DEPDIR)/interface.Po ./$(DEPDIR)/io.Po ./$(DEPDIR)/lk.Po \ + ./$(DEPDIR)/main.Po ./$(DEPDIR)/make.Po ./$(DEPDIR)/mcmc.Po \ + ./$(DEPDIR)/mg.Po ./$(DEPDIR)/mixt.Po ./$(DEPDIR)/models.Po \ + ./$(DEPDIR)/nexus.Po ./$(DEPDIR)/optimiz.Po \ + ./$(DEPDIR)/pars.Po ./$(DEPDIR)/phyrex.Po ./$(DEPDIR)/rates.Po \ + ./$(DEPDIR)/rwrapper.Po ./$(DEPDIR)/simu.Po ./$(DEPDIR)/spr.Po \ + ./$(DEPDIR)/sse.Po ./$(DEPDIR)/stats.Po ./$(DEPDIR)/tbe.Po \ + ./$(DEPDIR)/times.Po ./$(DEPDIR)/tiporder.Po \ + ./$(DEPDIR)/utilities.Po ./$(DEPDIR)/xml.Po +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libPHYML_a_SOURCES) +DIST_SOURCES = $(libPHYML_a_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +ISODATE = @ISODATE@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +noinst_LIBRARIES = libPHYML.a +libPHYML_a_SOURCES = alrt.c avx.c bionj.c cl.c draw.c free.c help.c interface.c io.c make.c mg.c models.c nexus.c pars.c rates.c simu.c sse.c tbe.c tiporder.c xml.c ancestral.c checkpoint.c date.c eigen.c init.c lk.c main.c mcmc.c mixt.c optimiz.c phyrex.c rwrapper.c spr.c stats.c times.c utilities.c +noinst_HEADERS = alrt.h avx.h bionj.h cl.h draw.h free.h help.h interface.h io.h m4.h mcmc.h mixt.h mpi_boot.h nexus.h pars.h rates.h simu.h sse.h tbe.h tiporder.h xml.h ancestral.h beagle_utils.h checkpoint.h date.h eigen.h geo.h init.h invitee.h lk.h make.h mg.h models.h mxml.h optimiz.h phyrex.h rwrapper.h spr.h stats.h times.h utilities.h +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu phyml/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu phyml/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +libPHYML.a: $(libPHYML_a_OBJECTS) $(libPHYML_a_DEPENDENCIES) $(EXTRA_libPHYML_a_DEPENDENCIES) + $(AM_V_at)-rm -f libPHYML.a + $(AM_V_AR)$(libPHYML_a_AR) libPHYML.a $(libPHYML_a_OBJECTS) $(libPHYML_a_LIBADD) + $(AM_V_at)$(RANLIB) libPHYML.a + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alrt.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ancestral.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/avx.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bionj.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/checkpoint.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cl.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/date.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/draw.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eigen.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/free.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/help.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/init.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interface.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lk.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/make.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mcmc.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mg.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mixt.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/models.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nexus.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/optimiz.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pars.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/phyrex.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rates.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rwrapper.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simu.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/spr.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sse.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stats.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tbe.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/times.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tiporder.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utilities.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xml.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/alrt.Po + -rm -f ./$(DEPDIR)/ancestral.Po + -rm -f ./$(DEPDIR)/avx.Po + -rm -f ./$(DEPDIR)/bionj.Po + -rm -f ./$(DEPDIR)/checkpoint.Po + -rm -f ./$(DEPDIR)/cl.Po + -rm -f ./$(DEPDIR)/date.Po + -rm -f ./$(DEPDIR)/draw.Po + -rm -f ./$(DEPDIR)/eigen.Po + -rm -f ./$(DEPDIR)/free.Po + -rm -f ./$(DEPDIR)/help.Po + -rm -f ./$(DEPDIR)/init.Po + -rm -f ./$(DEPDIR)/interface.Po + -rm -f ./$(DEPDIR)/io.Po + -rm -f ./$(DEPDIR)/lk.Po + -rm -f ./$(DEPDIR)/main.Po + -rm -f ./$(DEPDIR)/make.Po + -rm -f ./$(DEPDIR)/mcmc.Po + -rm -f ./$(DEPDIR)/mg.Po + -rm -f ./$(DEPDIR)/mixt.Po + -rm -f ./$(DEPDIR)/models.Po + -rm -f ./$(DEPDIR)/nexus.Po + -rm -f ./$(DEPDIR)/optimiz.Po + -rm -f ./$(DEPDIR)/pars.Po + -rm -f ./$(DEPDIR)/phyrex.Po + -rm -f ./$(DEPDIR)/rates.Po + -rm -f ./$(DEPDIR)/rwrapper.Po + -rm -f ./$(DEPDIR)/simu.Po + -rm -f ./$(DEPDIR)/spr.Po + -rm -f ./$(DEPDIR)/sse.Po + -rm -f ./$(DEPDIR)/stats.Po + -rm -f ./$(DEPDIR)/tbe.Po + -rm -f ./$(DEPDIR)/times.Po + -rm -f ./$(DEPDIR)/tiporder.Po + -rm -f ./$(DEPDIR)/utilities.Po + -rm -f ./$(DEPDIR)/xml.Po + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/alrt.Po + -rm -f ./$(DEPDIR)/ancestral.Po + -rm -f ./$(DEPDIR)/avx.Po + -rm -f ./$(DEPDIR)/bionj.Po + -rm -f ./$(DEPDIR)/checkpoint.Po + -rm -f ./$(DEPDIR)/cl.Po + -rm -f ./$(DEPDIR)/date.Po + -rm -f ./$(DEPDIR)/draw.Po + -rm -f ./$(DEPDIR)/eigen.Po + -rm -f ./$(DEPDIR)/free.Po + -rm -f ./$(DEPDIR)/help.Po + -rm -f ./$(DEPDIR)/init.Po + -rm -f ./$(DEPDIR)/interface.Po + -rm -f ./$(DEPDIR)/io.Po + -rm -f ./$(DEPDIR)/lk.Po + -rm -f ./$(DEPDIR)/main.Po + -rm -f ./$(DEPDIR)/make.Po + -rm -f ./$(DEPDIR)/mcmc.Po + -rm -f ./$(DEPDIR)/mg.Po + -rm -f ./$(DEPDIR)/mixt.Po + -rm -f ./$(DEPDIR)/models.Po + -rm -f ./$(DEPDIR)/nexus.Po + -rm -f ./$(DEPDIR)/optimiz.Po + -rm -f ./$(DEPDIR)/pars.Po + -rm -f ./$(DEPDIR)/phyrex.Po + -rm -f ./$(DEPDIR)/rates.Po + -rm -f ./$(DEPDIR)/rwrapper.Po + -rm -f ./$(DEPDIR)/simu.Po + -rm -f ./$(DEPDIR)/spr.Po + -rm -f ./$(DEPDIR)/sse.Po + -rm -f ./$(DEPDIR)/stats.Po + -rm -f ./$(DEPDIR)/tbe.Po + -rm -f ./$(DEPDIR)/times.Po + -rm -f ./$(DEPDIR)/tiporder.Po + -rm -f ./$(DEPDIR)/utilities.Po + -rm -f ./$(DEPDIR)/xml.Po + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-noinstLIBRARIES cscopelist-am ctags \ + ctags-am distclean distclean-compile distclean-generic \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/phyml/alrt.c b/phyml/alrt.c index d517aa6..f63b70c 100644 --- a/phyml/alrt.c +++ b/phyml/alrt.c @@ -18,16 +18,10 @@ Authors : Jean-Francois Dufayard & Stephane Guindon. */ - -#include "utilities.h" -#include "lk.h" -#include "optimiz.h" -#include "models.h" -#include "free.h" -#include "simu.h" #include "alrt.h" -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// /* * Check every testable branch of the tree, @@ -35,7 +29,7 @@ Authors : Jean-Francois Dufayard & Stephane Guindon. * param tree : the tree to check */ -int Check_NNI_Five_Branches(arbre *tree) +int Check_NNI_Five_Branches(t_tree *tree) { int best_edge; phydbl best_gain; @@ -46,282 +40,339 @@ int Check_NNI_Five_Branches(arbre *tree) phydbl init_lnL; init_lnL = UNLIKELY; - better_found = 1; - + better_found = YES; + //While there is at least one NNI to do... - while(better_found) + while(better_found == YES) { Update_Dirs(tree); - + //Interface output - if (tree->mod->s_opt->print) printf("\n\n. Checking for NNIs, optimizing five branches...\n"); - + if(tree->verbose > VL0 && tree->io->quiet == NO) PhyML_Printf("\n\n. Checking for NNIs, optimizing five branches...\n"); + better_found = 0; result = -1; best_edge = -1; - best_gain = -1.0; + best_gain = tree->mod->s_opt->min_diff_lk_local; best_config = -1; - - tree->both_sides = 1; - init_lnL = Return_Lk(tree); - + + MIXT_Set_Alias_Subpatt(YES,tree); + Set_Both_Sides(YES,tree); + init_lnL = Lk(NULL,tree); + MIXT_Set_Alias_Subpatt(NO,tree); + + //For every branch - For(i,2*tree->n_otu-3) - { - //if this branch is not terminal - if((!tree->t_edges[i]->left->tax) && (!tree->t_edges[i]->rght->tax)) - { - result = -1; - - //Try every NNIs for the tested branch - result = NNI_Neigh_BL(tree->t_edges[i],tree); - - //Look for possible NNI to do, and check if it is the best one - switch(result) - { - case 1 : /* lk1 > lk0 > lk2 */ - { - better_found = 1; - if(best_gain < (tree->t_edges[i]->nni->lk1 - tree->t_edges[i]->nni->lk0)) - { - best_edge = i; - best_gain = tree->t_edges[i]->nni->lk1-tree->t_edges[i]->nni->lk0; - best_config = 1; - } - break; - } - case 2 : /* lk2 > lk0 > lk1 */ - { - better_found = 1; - if(best_gain < (tree->t_edges[i]->nni->lk2 - tree->t_edges[i]->nni->lk0)) - { - best_edge = i; - best_gain = tree->t_edges[i]->nni->lk2-tree->t_edges[i]->nni->lk0; - best_config = 2; - } - break; - } - case 3 : /* lk1 > lk2 > lk0 */ - { - better_found = 1; - if(best_gain < (tree->t_edges[i]->nni->lk1 - tree->t_edges[i]->nni->lk2)) - { - best_edge = i; - best_gain = tree->t_edges[i]->nni->lk1-tree->t_edges[i]->nni->lk2; - best_config = 1; - } - break; - } - case 4 : /* lk2 > lk1 > lk0 */ - { - better_found = 1; - if(best_gain < (tree->t_edges[i]->nni->lk2 - tree->t_edges[i]->nni->lk1)) - { - best_edge = i; - best_gain = tree->t_edges[i]->nni->lk2-tree->t_edges[i]->nni->lk1; - best_config = 2; - } - break; - } - default : /* lk2 = lk1 = lk0 */ - { - if(best_gain < .0) best_gain = .0; - break; - } - } - } - } - + for(i=0;i<2*tree->n_otu-3;++i) + { + //if this branch is not terminal + if((!tree->a_edges[i]->left->tax) && (!tree->a_edges[i]->rght->tax)) + { + result = -1; + + //Try every NNIs for the tested branch + result = NNI_Neigh_BL(tree->a_edges[i],tree); + + //Look for possible NNI to do, and check if it is the best one + switch(result) + { + case 1 : /* lk1 > lk0 > lk2 */ + { + if((tree->a_edges[i]->nni->lk0 - tree->a_edges[i]->nni->lk1) < best_gain) + { + better_found = YES; + best_edge = i; + best_gain = tree->a_edges[i]->nni->lk0-tree->a_edges[i]->nni->lk1; + best_config = 1; + } + break; + } + case 2 : /* lk2 > lk0 > lk1 */ + { + if((tree->a_edges[i]->nni->lk0 - tree->a_edges[i]->nni->lk2) < best_gain) + { + better_found = YES; + best_edge = i; + best_gain = tree->a_edges[i]->nni->lk0-tree->a_edges[i]->nni->lk2; + best_config = 2; + } + break; + } + case 3 : /* lk1 > lk2 > lk0 */ + { + if((tree->a_edges[i]->nni->lk2 - tree->a_edges[i]->nni->lk1) < best_gain) + { + better_found = YES; + best_edge = i; + best_gain = tree->a_edges[i]->nni->lk2-tree->a_edges[i]->nni->lk1; + best_config = 1; + } + break; + } + case 4 : /* lk2 > lk1 > lk0 */ + { + if((tree->a_edges[i]->nni->lk1 - tree->a_edges[i]->nni->lk2) < best_gain) + { + better_found = YES; + best_edge = i; + best_gain = tree->a_edges[i]->nni->lk1-tree->a_edges[i]->nni->lk2; + best_config = 2; + } + break; + } + default : /* lk2 = lk1 = lk0 */ + { + if(best_gain > .0) best_gain = .0; + break; + } + } + } + } + + if((tree->c_lnL < init_lnL - tree->mod->s_opt->min_diff_lk_local) || (tree->c_lnL > init_lnL + tree->mod->s_opt->min_diff_lk_local)) - { - printf("\n\n. tree->c_lnL = %f init_lnL = %f.",tree->c_lnL,init_lnL); - printf("\n. Err in file %s at line %d.\n",__FILE__,__LINE__); - Warn_And_Exit("\n"); - } - + { + PhyML_Fprintf(stderr,"\n\n== tree->c_lnL = %f init_lnL = %f.",tree->c_lnL,init_lnL); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d\n\n.\n",__FILE__,__LINE__); + Warn_And_Exit("\n"); + } + //Don't do any NNI if the user doesn't want to optimize topology - - if(!tree->mod->s_opt->opt_topo) better_found = 0; + if(!tree->mod->s_opt->opt_topo) better_found = NO; +/* if(FABS(best_gain) <= tree->mod->s_opt->min_diff_lk_move) better_found = 0; */ //If there is one swap to do, make the best one. if(better_found) - { - Make_Target_Swap(tree,tree->t_edges[best_edge],best_config); - Lk(tree); - - if(tree->c_lnL < init_lnL) - { - printf("\n\n. tree->c_lnL = %f init_lnL = %f.",tree->c_lnL,init_lnL); - printf("\n. Err in file %s at line %d.\n",__FILE__,__LINE__); - Warn_And_Exit("\n"); - } - - if(tree->mod->s_opt->print) - { - Print_Lk(tree,"[Topology ]"); - printf("\n"); - } - return 1; - } + { + Make_Target_Swap(tree,tree->a_edges[best_edge],best_config); + + MIXT_Set_Alias_Subpatt(YES,tree); + Lk(NULL,tree); + MIXT_Set_Alias_Subpatt(YES,tree); + + if(tree->c_lnL < init_lnL) + { + PhyML_Fprintf(stderr,"\n\n== tree->c_lnL = %f init_lnL = %f.",tree->c_lnL,init_lnL); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d\n\n.\n",__FILE__,__LINE__); + Exit("\n"); + } + + if(tree->verbose > VL0 && tree->io->quiet == NO) Print_Lk(tree,"[Topology ]"); + + if(FABS(tree->c_lnL - init_lnL) < tree->mod->s_opt->min_diff_lk_move) return 0; + return 1; + } } return 0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// /* Compute aLRT supports */ -void aLRT(arbre *tree) +void aLRT(t_tree *tree) { int i; - - + char *method; + +// Print_All_Edge_Likelihoods(tree); + Unscale_Br_Len_Multiplier_Tree(tree); + Br_Len_Not_Involving_Invar(tree); +// Print_All_Edge_Likelihoods(tree); /* aLRT support will label each internal branch */ - tree->print_alrt_val = 1; + tree->io->print_support_val = YES; /* The topology will not be modified when assessing the branch support. We make sure that it will - not be modified afterward bo locking the topology */ + not be modified afterwards by locking the topology */ + + method = (char *)mCalloc(100,sizeof(char)); + + switch(tree->io->ratio_test) + { + case ALRTCHI2: { strcpy(method,"aLRT"); break; } + case MINALRTCHI2SH: { strcpy(method,"aLRT"); break; } + case ALRTSTAT: { strcpy(method,"aLRT"); break; } + case SH: { strcpy(method,"SH"); break; } + case ABAYES: { strcpy(method,"aBayes"); break; } + default : return; + } + + if(tree->io->quiet == NO) PhyML_Printf("\n\n. Calculating fast branch supports (using '%s').",method); + Free(method); + + MIXT_Set_Alias_Subpatt(YES,tree); + Set_Both_Sides(YES,tree); + // Print_All_Edge_Likelihoods(tree); + Lk(NULL,tree); + // Print_All_Edge_Likelihoods(tree); + MIXT_Set_Alias_Subpatt(NO,tree); + Update_Dirs(tree); - tree->both_sides = 1; - Lk(tree); + for(i=0;i<2*tree->n_otu-3;++i) + { + if((!tree->a_edges[i]->left->tax) && (!tree->a_edges[i]->rght->tax)) + { + /* Compute likelihoods for each of the three configuration */ + NNI_Neigh_BL(tree->a_edges[i],tree); + /* Compute the corresponding statistical support */ + Compute_Likelihood_Ratio_Test(tree->a_edges[i],tree); + } + } + + tree->lock_topo = YES; - For(i,2*tree->n_otu-3) - if((!tree->t_edges[i]->left->tax) && (!tree->t_edges[i]->rght->tax)) - { - /* Compute likelihoods for each of the three configuration */ - NNI_Neigh_BL(tree->t_edges[i],tree); - /* Compute the corresponding statistical support */ - Compute_Likelihood_Ratio_Test(tree->t_edges[i],tree); - } + Br_Len_Involving_Invar(tree); + Rescale_Br_Len_Multiplier_Tree(tree); - tree->lock_topo = 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /* * Launch one branch testing, * analyse the result * and convert supports as wished by the user. * param tree : the tree to check -* param tested_edge : the tested edge of the tree +* param tested_t_edge : the tested t_edge of the tree * param old_loglk : the initial likelihood, before any aLRT analysis * param isBoot : 1 if used from the Bootstrap procedure, 0 if not * return an integer, informative to analyse the results and potential NNIs to do */ -int Compute_Likelihood_Ratio_Test(edge *tested_edge, arbre *tree) +int Compute_Likelihood_Ratio_Test(t_edge *tested_edge, t_tree *tree) { int result=0; - tested_edge->ratio_test = 0.0; + tested_edge->ratio_test = 0.0; tested_edge->alrt_statistic = -1.0; - + if((tested_edge->nni->lk0 > tested_edge->nni->lk1) && (tested_edge->nni->lk0 > tested_edge->nni->lk2)) { if(tested_edge->nni->lk1 < tested_edge->nni->lk2) - { - //lk0 > lk2 > lk1 - tested_edge->alrt_statistic = 2*(tested_edge->nni->lk0 - tested_edge->nni->lk2); - } + { + //lk0 > lk2 > lk1 + tested_edge->alrt_statistic = 2*(tested_edge->nni->lk0 - tested_edge->nni->lk2); + } else - { - //lk0 > lk1 >= lk2 - tested_edge->alrt_statistic = 2*(tested_edge->nni->lk0 - tested_edge->nni->lk1); - } + { + //lk0 > lk1 >= lk2 + tested_edge->alrt_statistic = 2*(tested_edge->nni->lk0 - tested_edge->nni->lk1); + } if (tested_edge->alrt_statistic < 0.0) - { - tested_edge->alrt_statistic = 0.0; - tested_edge->ratio_test = 0.0; - } + { + tested_edge->alrt_statistic = 0.0; + tested_edge->ratio_test = 0.0; + } else - { - //aLRT statistic is valid, compute the wished support - if (tree->io->ratio_test == 2) - tested_edge->ratio_test = Statistics_To_Probabilities(tested_edge->alrt_statistic); - - else if(tree->io->ratio_test == 3) - { - phydbl sh_support; - phydbl param_support; - - sh_support = Statistics_To_SH(tree); - param_support = Statistics_To_Probabilities(tested_edge->alrt_statistic); - - if(sh_support < param_support) tested_edge->ratio_test = sh_support; - else tested_edge->ratio_test = param_support; - } - - else if(tree->io->ratio_test == 1) - { - tested_edge->ratio_test=tested_edge->alrt_statistic; - } - else - { - tested_edge->ratio_test = Statistics_To_SH(tree); - } - } - } + { + //aLRT statistic is valid, compute the branch support + if (tree->io->ratio_test == ALRTCHI2) + { + tested_edge->ratio_test = Statistics_To_Probabilities(tested_edge->alrt_statistic); + } + else if(tree->io->ratio_test == MINALRTCHI2SH) + { + phydbl sh_support; + phydbl param_support; + + sh_support = Statistics_To_SH(tree); + param_support = Statistics_To_Probabilities(tested_edge->alrt_statistic); + + if(sh_support < param_support) tested_edge->ratio_test = sh_support; + else tested_edge->ratio_test = param_support; + } + + else if(tree->io->ratio_test == ALRTSTAT) + { + tested_edge->ratio_test=tested_edge->alrt_statistic; + } + else if(tree->io->ratio_test == SH) + { + tested_edge->ratio_test = Statistics_To_SH(tree); + } + else if(tree->io->ratio_test == ABAYES) + { + phydbl Kp0,Kp1,Kp2,logK; + + logK = 1. - MAX(MAX(tested_edge->nni->lk0,tested_edge->nni->lk1),tested_edge->nni->lk2); + + Kp0 = exp(tested_edge->nni->lk0+logK); + Kp1 = exp(tested_edge->nni->lk1+logK); + Kp2 = exp(tested_edge->nni->lk2+logK); + tested_edge->ratio_test = Kp0/(Kp0+Kp1+Kp2); + } + } + } //statistic is not valid, give the negative statistics if wished, or a zero support. else if((tested_edge->nni->lk1 > tested_edge->nni->lk0) && (tested_edge->nni->lk1 > tested_edge->nni->lk2)) { - tested_edge->alrt_statistic = 2*(tested_edge->nni->lk0-tested_edge->nni->lk1); + /* tested_edge->ratio_test = 2*(tested_edge->nni->lk0-tested_edge->nni->lk1); */ + tested_edge->ratio_test = 0.0; if(tree->io->ratio_test > 1) tested_edge->alrt_statistic = 0.0; } else if((tested_edge->nni->lk2 > tested_edge->nni->lk0) && (tested_edge->nni->lk2 > tested_edge->nni->lk1)) { - tested_edge->alrt_statistic = 2*(tested_edge->nni->lk0-tested_edge->nni->lk2); + /* tested_edge->ratio_test = 2*(tested_edge->nni->lk0-tested_edge->nni->lk2); */ + tested_edge->ratio_test = 0.0; if(tree->io->ratio_test > 1) tested_edge->alrt_statistic = 0.0; } else // lk0 ~ lk1 ~ lk2 { - tested_edge->alrt_statistic = 0.0; + tested_edge->ratio_test = 0.0; if(tree->io->ratio_test > 1) tested_edge->ratio_test = 0.0; } - return result; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /* * Test the 3 NNI positions for one branch. * param tree : the tree to check -* param tested_edge : the tested edge of the tree +* param tested_t_edge : the tested t_edge of the tree * param old_loglk : the initial likelihood, before any aLRT analysis * param isBoot : 1 if used from the Bootstrap procedure, 0 if not */ -int NNI_Neigh_BL(edge *b_fcus, arbre *tree) +int NNI_Neigh_BL(t_edge *b_fcus, t_tree *tree) { - int n_patterns; - int l_r, r_l, l_v1, l_v2, r_v3, r_v4, site; - node *v1,*v2,*v3,*v4; - edge *e1,*e2,*e3,*e4; - phydbl len_e1,len_e2,len_e3,len_e4; + /*! + syntax : (node) [edge] + (left_1) . .(right_1) + \ (left) (right) / + \._____________./ + / [b_fcus] \ + / \ + (left_2) . .(right_2) + + */ + + int site; + t_node *v1,*v2,*v3,*v4; + t_edge *e1,*e2,*e3,*e4; + scalar_dbl *len_e1,*len_e2,*len_e3,*len_e4; + scalar_dbl *var_e1,*var_e2,*var_e3,*var_e4; phydbl lk0, lk1, lk2; - phydbl bl_init; - phydbl l1,l2,l3; - phydbl l_infa, l_infb, l_max; + scalar_dbl *l_init,*v_init; phydbl lk_init, lk_temp; int i; - int result,counter,wei; + int result; + void *buff; result = 0; - //Initialization - bl_init = b_fcus->l; - lk_init = tree->c_lnL; - lk_temp = UNLIKELY; - n_patterns = (int)floor(tree->n_pattern*tree->prop_of_sites_to_consider); - - b_fcus->nni->score = .0; + /*! Initialization */ + l_init = Duplicate_Scalar_Dbl(b_fcus->l); + v_init = Duplicate_Scalar_Dbl(b_fcus->l_var); + lk_init = tree->c_lnL; + lk_temp = UNLIKELY; lk0 = lk1 = lk2 = UNLIKELY; v1 = v2 = v3 = v4 = NULL; - - l_r = r_l = l_v1 = l_v2 = r_v3 = r_v4 = -1; - - l_r = b_fcus->l_r; - r_l = b_fcus->r_l; - - //vertices + Init_NNI_Score(0.0,b_fcus,tree); + + /*! vertices */ v1 = b_fcus->left->v[b_fcus->l_v1]; v2 = b_fcus->left->v[b_fcus->l_v2]; v3 = b_fcus->rght->v[b_fcus->r_v1]; @@ -329,349 +380,340 @@ int NNI_Neigh_BL(edge *b_fcus, arbre *tree) if(v1->num < v2->num) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n\n",__FILE__,__LINE__); + Exit(""); } + if(v3->num < v4->num) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n\n",__FILE__,__LINE__); + Exit(""); } - - l1 = l2 = l3 = -1.; - l1 = b_fcus->l; - - //edges + /*! edges */ e1 = b_fcus->left->b[b_fcus->l_v1]; e2 = b_fcus->left->b[b_fcus->l_v2]; e3 = b_fcus->rght->b[b_fcus->r_v1]; e4 = b_fcus->rght->b[b_fcus->r_v2]; - //record initial branch lengths - len_e1 = e1->l; - len_e2 = e2->l; - len_e3 = e3->l; - len_e4 = e4->l; - - //Optimize branch lengths and update likelihoods for - //the original configuration. - + /*! record initial branch lengths */ + len_e1 = Duplicate_Scalar_Dbl(e1->l); + len_e2 = Duplicate_Scalar_Dbl(e2->l); + len_e3 = Duplicate_Scalar_Dbl(e3->l); + len_e4 = Duplicate_Scalar_Dbl(e4->l); + var_e1 = Duplicate_Scalar_Dbl(e1->l_var); + var_e2 = Duplicate_Scalar_Dbl(e2->l_var); + var_e3 = Duplicate_Scalar_Dbl(e3->l_var); + var_e4 = Duplicate_Scalar_Dbl(e4->l_var); + + /*! Optimize branch lengths and update likelihoods for + the original configuration. + */ do { lk0 = lk_temp; - For(i,3) - if(b_fcus->left->v[i] != b_fcus->rght) - { - Update_P_Lk(tree,b_fcus->left->b[i],b_fcus->left); - - l_infa = 10.*b_fcus->left->b[i]->l; - l_max = b_fcus->left->b[i]->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus->left->b[i],tree, - tree->mod->s_opt->brent_it_max); - } - - Update_P_Lk(tree,b_fcus,b_fcus->left); - - l_infa = 10.*b_fcus->l; - l_max = b_fcus->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus,tree, - tree->mod->s_opt->brent_it_max); - - - For(i,3) - if(b_fcus->rght->v[i] != b_fcus->left) - { - Update_P_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); - - l_infa = 10.*b_fcus->rght->b[i]->l; - l_max = b_fcus->rght->b[i]->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus->rght->b[i],tree, - tree->mod->s_opt->brent_it_max); - } - - Update_P_Lk(tree,b_fcus,b_fcus->rght); + for(i=0;i<3;i++) //a branch has three nodes + if(b_fcus->left->v[i] != b_fcus->rght) //Only consider left_1 and left_2 + { + Update_Partial_Lk(tree,b_fcus->left->b[i],b_fcus->left); + lk_temp = Br_Len_Opt(&(b_fcus->left->b[i]->l->v),b_fcus->left->b[i],tree); + } + + Update_Partial_Lk(tree,b_fcus,b_fcus->left); + lk_temp = Br_Len_Opt(&(b_fcus->l->v),b_fcus,tree); + + for(i=0;i<3;i++) + if(b_fcus->rght->v[i] != b_fcus->left) //Only consider right_1 and right_2 + { + Update_Partial_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); + lk_temp = Br_Len_Opt(&(b_fcus->rght->b[i]->l->v),b_fcus->rght->b[i],tree); + } + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); if(lk_temp < lk0 - tree->mod->s_opt->min_diff_lk_local) - { - printf("\n. lk_temp = %f lk0 = %f\n",lk_temp,lk0); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } + { + PhyML_Fprintf(stderr,"\n. lk_temp = %f lk0 = %f\n",lk_temp,lk0); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n\n",__FILE__,__LINE__); + Exit("\n"); + } } while(fabs(lk_temp-lk0) > tree->mod->s_opt->min_diff_lk_global); - - + //until no significative improvement is detected + lk0 = tree->c_lnL; - counter=0; - For(site,n_patterns) + + buff = (t_tree *)tree; + do { - wei=0; - For(wei,tree->data->wght[site]) - { - tree->log_lks_aLRT[0][counter]= tree->c_lnL_sorted[site] / tree->data->wght[site]; - counter++; - } + for(site=0;siten_pattern;site++) tree->log_lks_aLRT[0][site] = tree->c_lnL_sorted[site]; + tree = tree->next_mixt; } + while(tree); + + tree = (t_tree *)buff; + + /*! Go back to initial branch lengths */ + Copy_Scalar_Dbl(len_e1,e1->l); + Copy_Scalar_Dbl(len_e2,e2->l); + Copy_Scalar_Dbl(len_e3,e3->l); + Copy_Scalar_Dbl(len_e4,e4->l); + Copy_Scalar_Dbl(l_init,b_fcus->l); + Copy_Scalar_Dbl(var_e1,e1->l_var); + Copy_Scalar_Dbl(var_e2,e2->l_var); + Copy_Scalar_Dbl(var_e3,e3->l_var); + Copy_Scalar_Dbl(var_e4,e4->l_var); + Copy_Scalar_Dbl(v_init,b_fcus->l_var); - /* Go back to initial branch lengths */ - e1->l = len_e1; - e2->l = len_e2; - e3->l = len_e3; - e4->l = len_e4; - b_fcus->l = bl_init; Update_PMat_At_Given_Edge(e1,tree); Update_PMat_At_Given_Edge(e2,tree); Update_PMat_At_Given_Edge(e3,tree); Update_PMat_At_Given_Edge(e4,tree); Update_PMat_At_Given_Edge(b_fcus,tree); + /* Sanity check */ + MIXT_Set_Alias_Subpatt(YES,tree); + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); + Update_Partial_Lk(tree,b_fcus,b_fcus->left); + lk_temp = Lk(b_fcus,tree); + MIXT_Set_Alias_Subpatt(NO,tree); + if((lk_temp > lk_init + tree->mod->s_opt->min_diff_lk_local) || (lk_temp < lk_init - tree->mod->s_opt->min_diff_lk_local)) + { + PhyML_Fprintf(stderr,"\n. lk_temp = %f lk_init = %f",lk_temp,lk_init); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } - //Do first possible swap - Swap(v2,b_fcus->left,b_fcus->rght,v3,tree); - - - tree->both_sides = 1; - lk1 = Update_Lk_At_Given_Edge(b_fcus,tree); - For(i,3) + /*! Do first possible swap */ + Swap(v2,b_fcus->left,b_fcus->rght,v3,tree); + MIXT_Set_Alias_Subpatt(YES,tree); + Set_Both_Sides(YES,tree); + Update_Partial_Lk(tree,b_fcus,b_fcus->left); + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); + lk1 = Lk(b_fcus,tree); + MIXT_Set_Alias_Subpatt(NO,tree); + + for(i=0;i<3;i++) if(b_fcus->left->v[i] != b_fcus->rght) - Update_P_Lk(tree,b_fcus->left->b[i],b_fcus->left); - - For(i,3) + Update_Partial_Lk(tree,b_fcus->left->b[i],b_fcus->left); + + for(i=0;i<3;i++) if(b_fcus->rght->v[i] != b_fcus->left) - Update_P_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); - - - //Optimize branch lengths and update likelihoods + Update_Partial_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); + + + /*! Optimize branch lengths and update likelihoods */ lk_temp = UNLIKELY; do { lk1 = lk_temp; - - For(i,3) - if(b_fcus->left->v[i] != b_fcus->rght) - { - Update_P_Lk(tree,b_fcus->left->b[i],b_fcus->left); - - l_infa = 10.*b_fcus->left->b[i]->l; - l_max = b_fcus->left->b[i]->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus->left->b[i],tree, - tree->mod->s_opt->brent_it_max); - } - - - Update_P_Lk(tree,b_fcus,b_fcus->left); - - l_infa = 10.*b_fcus->l; - l_max = b_fcus->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus,tree, - tree->mod->s_opt->brent_it_max); - - - - For(i,3) - if(b_fcus->rght->v[i] != b_fcus->left) - { - Update_P_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); - - l_infa = 10.*b_fcus->rght->b[i]->l; - l_max = b_fcus->rght->b[i]->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus->rght->b[i],tree, - tree->mod->s_opt->brent_it_max); - } - - Update_P_Lk(tree,b_fcus,b_fcus->rght); - - + + for(i=0;i<3;i++) + if(b_fcus->left->v[i] != b_fcus->rght) + { + Update_Partial_Lk(tree,b_fcus->left->b[i],b_fcus->left); + lk_temp = Br_Len_Opt(&(b_fcus->left->b[i]->l->v),b_fcus->left->b[i],tree); + } + + Update_Partial_Lk(tree,b_fcus,b_fcus->left); + lk_temp = Br_Len_Opt(&(b_fcus->l->v),b_fcus,tree); + + for(i=0;i<3;i++) + if(b_fcus->rght->v[i] != b_fcus->left) + { + Update_Partial_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); + lk_temp = Br_Len_Opt(&(b_fcus->rght->b[i]->l->v),b_fcus->rght->b[i],tree); + } + + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); + if(lk_temp < lk1 - tree->mod->s_opt->min_diff_lk_local) - { - printf("\n. lk_temp = %f lk1 = %f\n",lk_temp,lk1); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } + { + PhyML_Fprintf(stderr,"\n. lk_temp = %f lk1 = %f\n",lk_temp,lk1); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n\n",__FILE__,__LINE__); + Exit(""); + } } - while(fabs(lk_temp-lk1) > tree->mod->s_opt->min_diff_lk_global); - //until no significative improvement is detected + while(FABS(lk_temp-lk1) > tree->mod->s_opt->min_diff_lk_global); + /*! until no significative improvement is detected */ lk1 = tree->c_lnL; - //save likelihood of each sites, in order to compute branch supports - counter=0; - For(site,n_patterns) + /*! record likelihood of each site, in order to compute branch supports */ + + buff = (t_tree *)tree; + do { - wei=0; - For(wei,tree->data->wght[site]) - { - tree->log_lks_aLRT[1][counter]= tree->c_lnL_sorted[site] / tree->data->wght[site]; - counter++; - } + for(site=0;siten_pattern;site++) tree->log_lks_aLRT[1][site]= tree->c_lnL_sorted[site]; + tree = tree->next_mixt; } - - //save current length - l2 = b_fcus->l; - - //undo the swap + while(tree); + tree = (t_tree *)buff; + Swap(v3,b_fcus->left,b_fcus->rght,v2,tree); - /* Go back to initial branch lengths */ - e1->l = len_e1; - e2->l = len_e2; - e3->l = len_e3; - e4->l = len_e4; - b_fcus->l = bl_init; - + /*! Go back to initial branch lengths */ + Copy_Scalar_Dbl(len_e1,e1->l); + Copy_Scalar_Dbl(len_e2,e2->l); + Copy_Scalar_Dbl(len_e3,e3->l); + Copy_Scalar_Dbl(len_e4,e4->l); + Copy_Scalar_Dbl(l_init,b_fcus->l); + Copy_Scalar_Dbl(var_e1,e1->l_var); + Copy_Scalar_Dbl(var_e2,e2->l_var); + Copy_Scalar_Dbl(var_e3,e3->l_var); + Copy_Scalar_Dbl(var_e4,e4->l_var); + Copy_Scalar_Dbl(v_init,b_fcus->l_var); + Update_PMat_At_Given_Edge(e1,tree); Update_PMat_At_Given_Edge(e2,tree); Update_PMat_At_Given_Edge(e3,tree); Update_PMat_At_Given_Edge(e4,tree); Update_PMat_At_Given_Edge(b_fcus,tree); - - /***********/ - //do the second possible swap + + + /* Sanity check */ + MIXT_Set_Alias_Subpatt(YES,tree); + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); + Update_Partial_Lk(tree,b_fcus,b_fcus->left); + lk_temp = Lk(b_fcus,tree); + MIXT_Set_Alias_Subpatt(NO,tree); + if((lk_temp > lk_init + tree->mod->s_opt->min_diff_lk_local) || (lk_temp < lk_init - tree->mod->s_opt->min_diff_lk_local)) + { + PhyML_Fprintf(stderr,"\n== lk_temp = %f lk_init = %f",lk_temp,lk_init); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + /*! do the second possible swap */ Swap(v2,b_fcus->left,b_fcus->rght,v4,tree); - b_fcus->l = bl_init; - tree->both_sides = 1; - - lk2 = Update_Lk_At_Given_Edge(b_fcus,tree); - - For(i,3) + Set_Both_Sides(YES,tree); + MIXT_Set_Alias_Subpatt(YES,tree); + Update_Partial_Lk(tree,b_fcus,b_fcus->left); + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); + lk2 = Lk(b_fcus,tree); + MIXT_Set_Alias_Subpatt(NO,tree); + + for(i=0;i<3;i++) if(b_fcus->left->v[i] != b_fcus->rght) - Update_P_Lk(tree,b_fcus->left->b[i],b_fcus->left); - - For(i,3) + Update_Partial_Lk(tree,b_fcus->left->b[i],b_fcus->left); + + for(i=0;i<3;i++) if(b_fcus->rght->v[i] != b_fcus->left) - Update_P_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); - - - //Optimize branch lengths and update likelihoods + Update_Partial_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); + + /*! Optimize branch lengths and update likelihoods */ lk_temp = UNLIKELY; do { lk2 = lk_temp; - - For(i,3) - if(b_fcus->left->v[i] != b_fcus->rght) - { - Update_P_Lk(tree,b_fcus->left->b[i],b_fcus->left); - - l_infa = 10.*b_fcus->left->b[i]->l; - l_max = b_fcus->left->b[i]->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus->left->b[i],tree, - tree->mod->s_opt->brent_it_max); - } - - - Update_P_Lk(tree,b_fcus,b_fcus->left); - - l_infa = 10.*b_fcus->l; - l_max = b_fcus->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus,tree, - tree->mod->s_opt->brent_it_max); - - For(i,3) - if(b_fcus->rght->v[i] != b_fcus->left) - { - Update_P_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); - - l_infa = 10.*b_fcus->rght->b[i]->l; - l_max = b_fcus->rght->b[i]->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus->rght->b[i],tree, - tree->mod->s_opt->brent_it_max); - } - - Update_P_Lk(tree,b_fcus,b_fcus->rght); - + + for(i=0;i<3;i++) + if(b_fcus->left->v[i] != b_fcus->rght) + { + Update_Partial_Lk(tree,b_fcus->left->b[i],b_fcus->left); + lk_temp = Br_Len_Opt(&(b_fcus->left->b[i]->l->v),b_fcus->left->b[i],tree); + + if(lk_temp < lk2 - tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Fprintf(stderr,"\n== l: %f var:%f",b_fcus->left->b[i]->l->v,b_fcus->left->b[i]->l_var->v); + PhyML_Fprintf(stderr,"\n== lk_temp = %f lk2 = %f",lk_temp,lk2); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d",__FILE__,__LINE__); + Exit("\n"); + } + } + Update_Partial_Lk(tree,b_fcus,b_fcus->left); + lk_temp = Br_Len_Opt(&(b_fcus->l->v),b_fcus,tree); + if(lk_temp < lk2 - tree->mod->s_opt->min_diff_lk_local) - { - printf("\n. lk_temp = %f lk2 = %f\n",lk_temp,lk2); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } + { + PhyML_Fprintf(stderr,"\n== l: %f var:%f",b_fcus->l->v,b_fcus->l_var->v); + PhyML_Fprintf(stderr,"\n== lk_temp = %f lk2 = %f",lk_temp,lk2); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d",__FILE__,__LINE__); + Exit("\n"); + } + + for(i=0;i<3;i++) + if(b_fcus->rght->v[i] != b_fcus->left) + { + Update_Partial_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); + lk_temp = Br_Len_Opt(&(b_fcus->rght->b[i]->l->v),b_fcus->rght->b[i],tree); + + if(lk_temp < lk2 - tree->mod->s_opt->min_diff_lk_local) + { + Set_Both_Sides(YES,tree); + Lk(b_fcus,tree); + Check_Lk_At_Given_Edge(YES,tree); + PhyML_Fprintf(stderr,"\n== l: %f var:%f",b_fcus->rght->b[i]->l->v,b_fcus->rght->b[i]->l_var->v); + PhyML_Fprintf(stderr,"\n== lk_temp = %f lk2 = %f",lk_temp,lk2); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d",__FILE__,__LINE__); + Exit("\n"); + } + } + + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); + } - while(fabs(lk_temp-lk2) > tree->mod->s_opt->min_diff_lk_global); + while(FABS(lk_temp-lk2) > tree->mod->s_opt->min_diff_lk_global); //until no significative improvement is detected lk2 = tree->c_lnL; - - //save likelihood of each sites, in order to compute branch supports - counter=0; - For(site,n_patterns) + + /*! save likelihood of each sites, in order to compute branch supports */ + buff = (t_tree *)tree; + do { - wei=0; - For(wei,tree->data->wght[site]) - { - tree->log_lks_aLRT[2][counter]= tree->c_lnL_sorted[site] / tree->data->wght[site]; - counter++; - } + for(site=0;siten_pattern;site++) tree->log_lks_aLRT[2][site]= tree->c_lnL_sorted[site]; + tree = tree->next_mixt; } + while(tree); + tree = (t_tree *)buff; + - //save current length - l3 = b_fcus->l; - //undo the swap + /*! undo the swap */ Swap(v4,b_fcus->left,b_fcus->rght,v2,tree); /***********/ - //restore the initial branch length values - e1->l = len_e1; - e2->l = len_e2; - e3->l = len_e3; - e4->l = len_e4; - b_fcus->l = bl_init; + /*! restore the initial branch length values */ + Copy_Scalar_Dbl(len_e1,e1->l); + Copy_Scalar_Dbl(len_e2,e2->l); + Copy_Scalar_Dbl(len_e3,e3->l); + Copy_Scalar_Dbl(len_e4,e4->l); + Copy_Scalar_Dbl(l_init,b_fcus->l); + Copy_Scalar_Dbl(var_e1,e1->l_var); + Copy_Scalar_Dbl(var_e2,e2->l_var); + Copy_Scalar_Dbl(var_e3,e3->l_var); + Copy_Scalar_Dbl(var_e4,e4->l_var); + Copy_Scalar_Dbl(v_init,b_fcus->l_var); - //recompute likelihoods + + /*! recompute likelihoods */ Update_PMat_At_Given_Edge(e1,tree); Update_PMat_At_Given_Edge(e2,tree); Update_PMat_At_Given_Edge(e3,tree); Update_PMat_At_Given_Edge(e4,tree); Update_PMat_At_Given_Edge(b_fcus,tree); - Update_P_Lk(tree,b_fcus,b_fcus->rght); - Update_P_Lk(tree,b_fcus,b_fcus->left); + MIXT_Set_Alias_Subpatt(YES,tree); + Update_Partial_Lk(tree,b_fcus,b_fcus->left); + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); - For(i,3) + for(i=0;i<3;i++) if(b_fcus->left->v[i] != b_fcus->rght) - Update_P_Lk(tree,b_fcus->left->b[i],b_fcus->left); + Update_Partial_Lk(tree,b_fcus->left->b[i],b_fcus->left); - For(i,3) + for(i=0;i<3;i++) if(b_fcus->rght->v[i] != b_fcus->left) - Update_P_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); + Update_Partial_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); - lk_temp = Lk_At_Given_Edge(b_fcus,tree); + MIXT_Set_Alias_Subpatt(NO,tree); + lk_temp = Lk(b_fcus,tree); if((lk_temp > lk_init + tree->mod->s_opt->min_diff_lk_local) || (lk_temp < lk_init - tree->mod->s_opt->min_diff_lk_local)) { - printf("\n. lk_temp = %f lk_init = %f\n",lk_temp,lk_init); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Fprintf(stderr,"\n== lk_temp = %f lk_init = %f",lk_temp,lk_init); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d\n",__FILE__,__LINE__); Warn_And_Exit(""); } @@ -696,51 +738,51 @@ int NNI_Neigh_BL(edge *b_fcus, arbre *tree) if(b_fcus->nni->lk0 > b_fcus->nni->lk2) result = 1; //lk1 > lk0 > lk2 else result = 3; //lk1 > lk2 > lk0 } - else if((b_fcus->nni->lk2 > b_fcus->nni->lk0) && (b_fcus->nni->lk2 > b_fcus->nni->lk1)) + else if((b_fcus->nni->lk2 > b_fcus->nni->lk0) && (b_fcus->nni->lk2 > b_fcus->nni->lk1)) { if(b_fcus->nni->lk0 > b_fcus->nni->lk1) result = 2; //lk2 > lk0 > lk1 else result = 4; //lk2 > lk1 > lk0 } - -/* int counter=0; */ -/* For(site,n_patterns) */ -/* { */ -/* printf("%3d %3d %15f ",b_fcus->num,tree->data->wght[site],b_fcus->nni->score); */ -/* printf("%15f %15f\n", */ -/* tree->log_lks_aLRT[0][counter], */ -/* (lk1 > lk2)?(tree->log_lks_aLRT[1][counter]):(tree->log_lks_aLRT[2][counter])); */ -/* counter+=tree->data->wght[site]; */ -/* } */ + + + Free_Scalar_Dbl(len_e1); + Free_Scalar_Dbl(len_e2); + Free_Scalar_Dbl(len_e3); + Free_Scalar_Dbl(len_e4); + Free_Scalar_Dbl(l_init); + Free_Scalar_Dbl(var_e1); + Free_Scalar_Dbl(var_e2); + Free_Scalar_Dbl(var_e3); + Free_Scalar_Dbl(var_e4); + Free_Scalar_Dbl(v_init); + return result; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /* * Make one target swap, optimizing five branches. * param tree : the tree to check -* param tested_edge : the swaping edge of the tree +* param tested_t_edge : the swaping t_edge of the tree * param swapToDo : 1 or 2, to select the first or the second swap to do */ -void Make_Target_Swap(arbre *tree, edge *b_fcus, int swaptodo) +void Make_Target_Swap(t_tree *tree, t_edge *b_fcus, int swaptodo) { - int l_r, r_l, l_v1, l_v2, r_v3, r_v4; - node *v1,*v2,*v3,*v4; - edge *e1,*e2,*e3,*e4; + t_node *v1,*v2,*v3,*v4; phydbl lktodo; - phydbl bl_init; - phydbl l_infa, l_infb, l_max; phydbl lk_init, lk_temp; int i; if(swaptodo < 0) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Fprintf(stderr,"\n== Err in file %s at line %d\n\n",__FILE__,__LINE__); Warn_And_Exit(""); } //Initialization - bl_init = b_fcus->l; lk_init = tree->c_lnL; b_fcus->nni->score = .0; @@ -748,11 +790,6 @@ void Make_Target_Swap(arbre *tree, edge *b_fcus, int swaptodo) lktodo = UNLIKELY; v1 = v2 = v3 = v4 = NULL; - l_r = r_l = l_v1 = l_v2 = r_v3 = r_v4 = -1; - - l_r = b_fcus->l_r; - r_l = b_fcus->r_l; - v1 = b_fcus->left->v[b_fcus->l_v1]; v2 = b_fcus->left->v[b_fcus->l_v2]; v3 = b_fcus->rght->v[b_fcus->r_v1]; @@ -760,43 +797,42 @@ void Make_Target_Swap(arbre *tree, edge *b_fcus, int swaptodo) if(v1->num < v2->num) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Fprintf(stderr,"\n== Err in file %s at line %d\n\n",__FILE__,__LINE__); Warn_And_Exit(""); } if(v3->num < v4->num) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); Warn_And_Exit(""); } - e1 = b_fcus->left->b[b_fcus->l_v1]; - e2 = b_fcus->left->b[b_fcus->l_v2]; - e3 = b_fcus->rght->b[b_fcus->r_v1]; - e4 = b_fcus->rght->b[b_fcus->r_v2]; - /***********/ //make the selected swap if(swaptodo==1) { Swap(v2,b_fcus->left,b_fcus->rght,v3,tree); + if(!Check_Topo_Constraints(tree,tree->io->cstr_tree)) Swap(v3,b_fcus->left,b_fcus->rght,v2,tree); } else { Swap(v2,b_fcus->left,b_fcus->rght,v4,tree); + if(!Check_Topo_Constraints(tree,tree->io->cstr_tree)) Swap(v4,b_fcus->left,b_fcus->rght,v2,tree); } - tree->both_sides = 1; + MIXT_Set_Alias_Subpatt(YES,tree); + Set_Both_Sides(YES,tree); lktodo = Update_Lk_At_Given_Edge(b_fcus,tree); - - For(i,3) + + for(i=0;i<3;i++) if(b_fcus->left->v[i] != b_fcus->rght) - Update_P_Lk(tree,b_fcus->left->b[i],b_fcus->left); - - For(i,3) + Update_Partial_Lk(tree,b_fcus->left->b[i],b_fcus->left); + + for(i=0;i<3;i++) if(b_fcus->rght->v[i] != b_fcus->left) - Update_P_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); + Update_Partial_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); + MIXT_Set_Alias_Subpatt(NO,tree); //Optimize branch lengths and update likelihoods lk_temp = UNLIKELY; @@ -804,84 +840,60 @@ void Make_Target_Swap(arbre *tree, edge *b_fcus, int swaptodo) { lktodo = lk_temp; - For(i,3) - if(b_fcus->left->v[i] != b_fcus->rght) - { - Update_P_Lk(tree,b_fcus->left->b[i],b_fcus->left); - - l_infa = 10.*b_fcus->left->b[i]->l; - l_max = b_fcus->left->b[i]->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus->left->b[i],tree, - tree->mod->s_opt->brent_it_max); - } + for(i=0;i<3;i++) + if(b_fcus->left->v[i] != b_fcus->rght) + { + Update_Partial_Lk(tree,b_fcus->left->b[i],b_fcus->left); + lk_temp = Br_Len_Opt(&(b_fcus->left->b[i]->l->v),b_fcus->left->b[i],tree); + } - Update_P_Lk(tree,b_fcus,b_fcus->left); + Update_Partial_Lk(tree,b_fcus,b_fcus->left); + lk_temp = Br_Len_Opt(&(b_fcus->l->v),b_fcus,tree); - l_infa = 10.*b_fcus->l; - l_max = b_fcus->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus,tree, - tree->mod->s_opt->brent_it_max); - - - - For(i,3) - if(b_fcus->rght->v[i] != b_fcus->left) - { - Update_P_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); - - l_infa = 10.*b_fcus->rght->b[i]->l; - l_max = b_fcus->rght->b[i]->l; - l_infb = BL_MIN; - lk_temp = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus->rght->b[i],tree, - tree->mod->s_opt->brent_it_max); - } - - Update_P_Lk(tree,b_fcus,b_fcus->rght); + for(i=0;i<3;i++) + if(b_fcus->rght->v[i] != b_fcus->left) + { + Update_Partial_Lk(tree,b_fcus->rght->b[i],b_fcus->rght); + lk_temp = Br_Len_Opt(&(b_fcus->rght->b[i]->l->v),b_fcus->rght->b[i],tree); + } + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); if(lk_temp < lktodo - tree->mod->s_opt->min_diff_lk_local) - { - printf("\n. Edge %3d lk_temp = %f lktodo = %f\n",b_fcus->num,lk_temp,lktodo); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } + { + PhyML_Fprintf(stderr,"\n== Edge %3d lk_temp = %f lktodo = %f\n",b_fcus->num,lk_temp,lktodo); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } } - while(fabs(lk_temp-lktodo) > tree->mod->s_opt->min_diff_lk_global); + while(FABS(lk_temp-lktodo) > tree->mod->s_opt->min_diff_lk_global); //until no significative improvement is detected -/* printf("\n.<< [%3d] l=%f lk_init=%f tree->c_lnL=%f score=%12f v1=%3d v2=%3d v3=%3d v4=%3d >>", */ +/* PhyML_Printf("\n.<< [%3d] l=%f lk_init=%f tree->c_lnL=%f score=%12f v1=%3d v2=%3d v3=%3d v4=%3d >>", */ /* b_fcus->num, */ -/* b_fcus->l, */ +/* b_fcus->l->v, */ /* lk_init, */ /* tree->c_lnL, */ /* lk_init-tree->c_lnL, */ /* v1->num,v2->num,v3->num,v4->num); */ - if(tree->c_lnL < lk_init) + if(tree->c_lnL < lk_init - tree->mod->s_opt->min_diff_lk_global) { - printf("\n. [%3d] v1=%d v2=%d v3=%d v4=%d", - b_fcus->num,v1->num,v2->num,v3->num,v4->num); - printf("\n. tree->c_lnL = %f lk_init = %f\n",tree->c_lnL,lk_init); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Fprintf(stderr,"\n== [%3d] v1=%d v2=%d v3=%d v4=%d",b_fcus->num,v1->num,v2->num,v3->num,v4->num); + PhyML_Fprintf(stderr,"\n== tree->c_lnL = %f lk_init = %f\n",tree->c_lnL,lk_init); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d\n\n",__FILE__,__LINE__); Warn_And_Exit(""); } - } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /** -* Convert an aLRT statistic to a none parametric support +* Convert an aLRT statistic to a non-parametric support * param in: the statistic */ @@ -1050,61 +1062,74 @@ phydbl Statistics_To_Probabilities(phydbl in) return rough_value; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /** * deprecated * Compute a RELL support, using the latest tested branch * param tree: the tested tree */ -phydbl Statistics_to_RELL(arbre *tree) +phydbl Statistics_to_RELL(t_tree *tree) { int i; - int occurence=1000; + int occurence=10000; phydbl nb=0.0; - phydbl res; + phydbl res,*pi; int site; phydbl lk0=0.0; phydbl lk1=0.0; phydbl lk2=0.0; - phydbl buff = -1.; int position = -1; + t_tree *buff_tree; + int* samples; - //1000 times - For(i,occurence) + /*! 1000 times */ + for(i=0;idata->init_len) - { - buff = rand(); - buff /= (RAND_MAX+1.); -/* buff *= tree->data->crunch_len; */ - buff *= tree->data->init_len; - position = (int)floor(buff); - - lk0+=tree->log_lks_aLRT[0][position]; - lk1+=tree->log_lks_aLRT[1][position]; - lk2+=tree->log_lks_aLRT[2][position]; - } - if (lk0>=lk1 && lk0>=lk2) nb++; + + /*! Shuffle the data and increment the support, if needed */ + buff_tree = tree; + do + { + pi = (phydbl *)mCalloc(tree->data->crunch_len,sizeof(phydbl)); + for(site=0;siten_pattern;site++) pi[site] = tree->data->wght[site] / (phydbl)tree->data->init_len; + + samples = Sample_n_i_With_Proba_pi(pi,tree->n_pattern,tree->data->init_len); + For(site, tree->data->init_len) + { + position = samples[site]; + lk0+=tree->log_lks_aLRT[0][position]; + lk1+=tree->log_lks_aLRT[1][position]; + lk2+=tree->log_lks_aLRT[2][position]; + } + if (lk0>=lk1 && lk0>=lk2) nb++; + tree = tree->next_mixt; + Free(samples); + Free(pi); + } + while(tree); + tree = buff_tree; } res= nb/(phydbl)occurence; return res; } -/*********************************************************/ -/** -* deprecated -* Compute a SH-like support, using the latest tested branch -* param tree: the tested tree +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/*! + Compute a SH-like support, using the latest tested branch + param tree: the tested tree */ -phydbl Statistics_To_SH(arbre *tree) +phydbl Statistics_To_SH(t_tree *tree) { int i; - int occurence=1000; + int occurence=10000; phydbl nb=0.0; phydbl res; int site; @@ -1114,125 +1139,148 @@ phydbl Statistics_To_SH(arbre *tree) phydbl c0=0.0; phydbl c1=0.0; phydbl c2=0.0; - phydbl buff=-1.; int position=-1; phydbl delta_local=-1.; + phydbl delta=0.0; + t_tree *buff_tree; + phydbl *pi; + int* samples; + + /*! Compute the total log-lk of each NNI position */ + buff_tree = tree; + do + { + For(site, tree->n_pattern) + { + c0+=tree->log_lks_aLRT[0][site] * tree->data->wght[site]; + c1+=tree->log_lks_aLRT[1][site] * tree->data->wght[site]; + c2+=tree->log_lks_aLRT[2][site] * tree->data->wght[site]; + } + tree = tree->next_mixt; + } + while(tree); + tree = buff_tree; - //Compute the total log-lk of each NNI position - For(site, tree->data->init_len) + + if (c0>=c1 && c0>=c2) + { + if (c1>=c2) + { + delta=c0-c1; + } + else + { + delta=c0-c2; + } + } + else if(c1>=c0 && c1>=c2) { - c0+=tree->log_lks_aLRT[0][site]; - c1+=tree->log_lks_aLRT[1][site]; - c2+=tree->log_lks_aLRT[2][site]; + if (c0>=c2) + { + delta=c1-c0; + } + else + { + delta=c1-c2; + } } - phydbl delta=0.0; - if (c0>=c1 && c0>=c2) - { - if (c1>=c2) - { - delta=c0-c1; - } - else - { - delta=c0-c2; - } - } - else if(c1>=c0 && c1>=c2) - { - if (c0>=c2) - { - delta=c1-c0; - } - else - { - delta=c1-c2; - } - } + else + { + if (c1>=c0) + { + delta=c2-c1; + } else - { - if (c1>=c0) - - { - delta=c2-c1; - } - else - { - delta=c2-c0; - } - } - //1000 times - For(i,occurence) + { + delta=c2-c0; + } + } + + /*! 1000 times */ + for(i=0;idata->init_len) - { - buff = rand(); - buff /= (RAND_MAX+1.); - buff *= tree->data->init_len; - position = (int)floor(buff); - - lk0+=tree->log_lks_aLRT[0][position]; - lk1+=tree->log_lks_aLRT[1][position]; - lk2+=tree->log_lks_aLRT[2][position]; - } - - //return to null hypothesis + buff_tree = tree; + do + { + pi = (phydbl *)mCalloc(tree->data->crunch_len,sizeof(phydbl)); + for(site=0;siten_pattern;site++) pi[site] = tree->data->wght[site] / (phydbl)tree->data->init_len; + + samples = Sample_n_i_With_Proba_pi(pi,tree->n_pattern,tree->data->init_len); + /*! Shuffle the data */ + For(site, tree->data->init_len) + { + position = samples[site]; + lk0+=tree->log_lks_aLRT[0][position]; + lk1+=tree->log_lks_aLRT[1][position]; + lk2+=tree->log_lks_aLRT[2][position]; + } + + tree = tree->next_mixt; + Free(samples); + Free(pi); + } + while(tree); + tree = buff_tree; + + /*! return to null hypothesis */ lk0=lk0-c0; lk1=lk1-c1; lk2=lk2-c2; - //compute results and increment if needed + /*! compute results and increment if needed */ delta_local=0.0; if (lk0>=lk1 && lk0>=lk2) - { - if (lk1>=lk2) - { - delta_local=lk0-lk1; - } - else - { - delta_local=lk0-lk2; - } - } + { + if (lk1>=lk2) + { + delta_local=lk0-lk1; + } + else + { + delta_local=lk0-lk2; + } + } else if(lk1>=lk0 && lk1>=lk2) - { - if (lk0>=lk2) - { - delta_local=lk1-lk0; - } - else - { - delta_local=lk1-lk2; - } - } + { + if (lk0>=lk2) + { + delta_local=lk1-lk0; + } + else + { + delta_local=lk1-lk2; + } + } else - { - if (lk1>=lk0) - - { - delta_local=lk2-lk1; - } - else - { - delta_local=lk2-lk0; - } - } - - if (delta>(delta_local+0.1)) { - nb++; - } - } - + { + if (lk1>=lk0) + { + delta_local=lk2-lk1; + } + else + { + delta_local=lk2-lk0; + } + } + + if (delta>(delta_local+0.1)) + { + nb++; + } + } + res= nb/occurence; - + return res; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /** * deprecated * Compute one side likelihood @@ -1240,22 +1288,34 @@ phydbl Statistics_To_SH(arbre *tree) * param tree : b_fcus tree * param exclude : side to exclude for computation */ -phydbl Update_Lk_At_Given_Edge_Excluding(edge *b_fcus, arbre *tree, node *exclude) +phydbl Update_Lk_At_Given_Edge_Excluding(t_edge *b_fcus, t_tree *tree, t_node *exclude) { if((!b_fcus->left->tax) && (exclude == NULL || exclude != b_fcus->left)) - Update_P_Lk(tree,b_fcus,b_fcus->left); + Update_Partial_Lk(tree,b_fcus,b_fcus->left); if((!b_fcus->rght->tax) && (exclude == NULL || exclude != b_fcus->rght)) - Update_P_Lk(tree,b_fcus,b_fcus->rght); + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); - tree->c_lnL = Lk_At_Given_Edge(b_fcus,tree); + tree->c_lnL = Lk(b_fcus,tree); return tree->c_lnL; } -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + diff --git a/phyml/alrt.h b/phyml/alrt.h index 8815d7b..2a211fe 100644 --- a/phyml/alrt.h +++ b/phyml/alrt.h @@ -10,17 +10,27 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef ALRT_H #define ALRT_H -void aLRT(arbre *tree); -int Check_NNI_Five_Branches(arbre *tree); -int Compute_Likelihood_Ratio_Test(edge *tested_edge, arbre *tree); -int NNI_Neigh_BL(edge *b_fcus, arbre *tree); -void Make_Target_Swap(arbre *tree, edge *b_fcus, int swaptodo); +#include "utilities.h" +#include "lk.h" +#include "optimiz.h" +#include "models.h" +#include "free.h" +#include "simu.h" + + +void aLRT(t_tree *tree); +int Check_NNI_Five_Branches(t_tree *tree); +int Compute_Likelihood_Ratio_Test(t_edge *tested_edge, t_tree *tree); +int NNI_Neigh_BL(t_edge *b_fcus, t_tree *tree); +void Make_Target_Swap(t_tree *tree, t_edge *b_fcus, int swaptodo); phydbl Statistics_To_Probabilities(phydbl in); -phydbl Statistics_To_RELL(arbre *tree); -phydbl Statistics_To_SH(arbre *tree); -phydbl Update_Lk_At_Given_Edge_Excluding(edge *b_fcus, arbre *tree, node *exclude); +phydbl Statistics_To_RELL(t_tree *tree); +phydbl Statistics_To_SH(t_tree *tree); +phydbl Update_Lk_At_Given_Edge_Excluding(t_edge *b_fcus, t_tree *tree, t_node *exclude); #endif diff --git a/phyml/ancestral.c b/phyml/ancestral.c new file mode 100644 index 0000000..65d87c7 --- /dev/null +++ b/phyml/ancestral.c @@ -0,0 +1,1071 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "ancestral.h" + +void Sample_Ancestral_Seq(int fullmutmap, int fromprior, t_tree *tree) +{ + int rate_cat; + int i,j,k,l; + phydbl *probs; + phydbl sum; + int n_mut; + FILE *fp; + phydbl *muttime; + int *muttype,*muttax; + char *s,*mut_string; + int *ordering; + + + if(tree->is_mixt_tree == YES) + { + MIXT_Sample_Ancestral_Seq(fullmutmap,fromprior,tree); + return; + } + + probs = (phydbl *)mCalloc(tree->mod->ras->n_catg,sizeof(phydbl)); + + muttime = (phydbl *)mCalloc((2*tree->n_otu-3)*5, // At most 5 mutations per branch on average + sizeof(phydbl)); + + muttype = (int *)mCalloc((2*tree->n_otu-3)*5, // At most 5 mutations per branch on average + sizeof(int)); + + muttax = (int *)mCalloc((2*tree->n_otu-3)*5, // At most 5 mutations per branch on average + sizeof(int)); + + ordering = (int *)mCalloc((2*tree->n_otu-3)*5, // At most 5 mutations per branch on average + sizeof(int)); + + s = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + for(i=0;i<2*tree->n_otu-1;++i) + if(tree->a_nodes[i]->tax == NO) + { + tree->a_nodes[i]->c_seq_anc = (align *)mCalloc(1,sizeof(align));; + tree->a_nodes[i]->c_seq_anc->state = (char *)mCalloc(tree->n_pattern,sizeof(char)); + } + + + /* Update P(D_x|X=i) for each state i and node X */ + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + + + for(i=0;in_pattern;++i) + { + /* Sample the rate class from its posterior density */ + for(j=0;jmod->ras->n_catg;j++) + { + if(fromprior == NO) + probs[j] = + tree->unscaled_site_lk_cat[i*tree->mod->ras->n_catg+j]* + tree->mod->ras->gamma_r_proba->v[j]; + else + probs[j] = tree->mod->ras->gamma_r_proba->v[j]; + } + + /* Scale probas. */ + sum = .0; + for(j=0;jmod->ras->n_catg;j++) sum += probs[j]; + for(j=0;jmod->ras->n_catg;j++) probs[j]/=sum; + + rate_cat = Sample_i_With_Proba_pi(probs,tree->mod->ras->n_catg); + + n_mut = 0; + if(tree->n_root != NULL) + { + Sample_Ancestral_Seq_Pre(tree->n_root,tree->n_root->v[1],tree->n_root->b[1], + i,rate_cat, + muttype,muttime,muttax,&n_mut, + fullmutmap,fromprior,tree); + + + Sample_Ancestral_Seq_Pre(tree->n_root,tree->n_root->v[2],tree->n_root->b[2], + i,rate_cat, + muttype,muttime,muttax,&n_mut, + fullmutmap,fromprior,tree); + + + } + else + { + Sample_Ancestral_Seq_Pre(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree->a_nodes[0]->b[0], + i,rate_cat, + muttype,muttime,muttax,&n_mut, + fullmutmap,fromprior,tree); + } + + for(j=0;j muttime[j]) ordering[k]++; + else ordering[j]++; + } + } + + strcpy(s,"mutmap."); + sprintf(s+strlen(s),"%d.",tree->io->r_seed); + sprintf(s+strlen(s),"%d",i); + fp = fopen(s,"a"); + PhyML_Fprintf(fp,"\n-1 -1 -1.0 -1 %d",tree->mixt_tree ? tree->mixt_tree->mcmc->run : tree->mcmc->run); + + Reverse_Muttime(muttime,n_mut,tree); + + for(j=0;jdata->init_len;l++) if(tree->data->sitepatt[l] == i) break; + mut_string = Mutation_Id(muttype[k],tree); + PhyML_Fprintf(fp,"\n%4d %s %g %4d %s",j,mut_string,muttime[k],l,tree->a_nodes[muttax[k]]->name); + Free(mut_string); + break; + } + } + } + + + for(j=0;j> a: %d d: %d b->left: %d b->rght: %d",a?a->num:-1,d?d->num:-1,b?b->left->num:-1,b?b->rght->num:-1); */ + + ns = tree->mod->ns; + + probs = (phydbl *)mCalloc(ns,sizeof(phydbl)); + + if(a->tax == TRUE) // Sample state at tip if observed state is ambiguous + { + assert(b); + if(a == b->left) for(i=0;ip_lk_tip_l[site*ns+i]; + else for(i=0;ip_lk_tip_r[site*ns+i]; + for(i=0;imod->e_frq->pi->v[i]; + sum = 0.0; + for(i=0;in_root) + { + sa = Sample_Ancestral_Seq_Core(NULL,tree->n_root,NULL,r_cat,site,tree); + } + else + { + sa = Assign_State(a->c_seq_anc->state + site, + tree->mod->io->datatype, + tree->mod->io->state_len); + } + + sd = Sample_Ancestral_Seq_Core(a,d,b,r_cat,site,tree); + + if(fullmutmap == YES) Map_Mutations(a,d,sa,sd,b,site,r_cat,muttype,muttime,muttax,n_mut,tree); + + if(d->tax) return; + else + { + for(i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + Sample_Ancestral_Seq_Pre(d,d->v[i],d->b[i],site,r_cat,muttype,muttime,muttax,n_mut,fullmutmap,fromprior,tree); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Sample_Ancestral_Seq_Core(t_node *a, t_node *d, t_edge *b, int r_cat, int site, t_tree *tree) +{ + int i,j; + int ns; + + ns = tree->mod->ns; + + int dim1 = tree->mod->ras->n_catg * ns; + int dim2 = ns; + int dim3 = ns * ns; + + phydbl *probs,*Pij,sum; + + int state; + + + probs = (phydbl *)mCalloc(ns,sizeof(phydbl)); + state = -1; + + if(d->tax == YES) + { + assert(b); + if(d == b->left) for(i=0;ip_lk_tip_l[site*ns+i]; + else if(d == b->rght) for(i=0;ip_lk_tip_r[site*ns+i]; + else assert(FALSE); + for(i=0;imod->e_frq->pi->v[i]; + sum = 0.0; + for(i=0;in_root); + + phydbl r,l; + + Update_PMat_At_Given_Edge(tree->n_root->b[1],tree); + Update_PMat_At_Given_Edge(tree->n_root->b[2],tree); + + for(i=0;ie_root->left == tree->n_root->v[1]) + Pij = tree->n_root->b[1]->Pij_rr; + else + Pij = tree->n_root->b[2]->Pij_rr; + + l = 0.0; + for(j=0;je_root->left->tax == NO) + l += tree->e_root->p_lk_left[site*dim1+r_cat*dim2+j] * Pij[r_cat*dim3+i*dim2+j]; + else + l += tree->e_root->p_lk_tip_l[site*dim2+j] * Pij[r_cat*dim3+i*dim2+j]; + } + + + if(tree->e_root->rght == tree->n_root->v[1]) + Pij = tree->n_root->b[1]->Pij_rr; + else + Pij = tree->n_root->b[2]->Pij_rr; + + r = 0.0; + for(j=0;je_root->rght->tax == NO) + r += tree->e_root->p_lk_rght[site*dim1+r_cat*dim2+j] * Pij[r_cat*dim3+i*dim2+j]; + else + r += tree->e_root->p_lk_tip_r[site*dim2+j] * Pij[r_cat*dim3+i*dim2+j]; + } + + probs[i] = r*l*tree->mod->e_frq->pi->v[i]; + } + + sum = 0.0; + for(i=0;ic_seq_anc->state[site] = Reciproc_Assign_State(state,tree->io->datatype); + } + else + { + assert(b); + + // State (already) sampled at node a + state = Assign_State(a->c_seq_anc->state + site, + tree->mod->io->datatype, + tree->mod->io->state_len); + + Pij = b->Pij_rr; + + for(i=0;ileft) + probs[i] = b->p_lk_left[site*dim1+r_cat*dim2+i] * Pij[r_cat*dim3+state*dim2+i]; + else if(d == b->rght) + probs[i] = b->p_lk_rght[site*dim1+r_cat*dim2+i] * Pij[r_cat*dim3+state*dim2+i]; + else assert(FALSE); + } + + sum = 0.0; + for(i=0;ic_seq_anc->state[site] = Reciproc_Assign_State(state,tree->io->datatype); + } + } + + Free(probs); + return state; + +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Map_Mutations(t_node *a, t_node *d, int sa, int sd, t_edge *b, int site, int rcat, int *muttype, phydbl *muttime, int *muttax, int *n_mut, t_tree *tree) +{ + int i,j; + phydbl *probs,*all_probs; + int slast,snew; // Last state visited + phydbl tlast; + phydbl *Q; + phydbl u,sum; + int *mut; // Array of mutations + int thismut; + int n_mut_branch; + int n_iter; + int first_mut; + phydbl T; + int ns,tax_idx; + phydbl rr; + + ns = tree->mod->ns; + + all_probs = (phydbl *)mCalloc(ns*ns,sizeof(phydbl)); + mut = (int *)mCalloc(ns*ns,sizeof(int)); + + // Site relative rate + rr = tree->mod->ras->gamma_rr->v[rcat]; + + // Rate matrix + Q = tree->mod->r_mat->qmat->v; + + // Length of the 'time' interval considered. + T = 0.0; +#ifdef PHYTIME + T = tree->rates->cur_l[d->num]*rr; +#else + T = b->l->v*rr; +#endif + + + /* PhyML_Printf("\n. Mutmap: a:%d d:%d ta:%G td:%G cr:%G rr:%G l:%G", */ + /* a?a->num:-1,d?d->num:-1, */ + /* tree->rates->nd_t[a->num], */ + /* tree->rates->nd_t[d->num], */ + /* cr,rr, */ + /* fabs(tree->rates->nd_t[a->num]-tree->rates->nd_t[d->num])*cr*rr); */ + + // Matrix of change probabilities + for(i=0;ii)=0.0; + all_probs[i*ns+i] = 0.0; + + // Normalise so that \sum_j p(i->j) = 1.0; + sum = 0; + for(j=0;j sample a new mutation event + if(tlast < T) + { + first_mut = NO; + + n_mut_branch++; + + if(n_mut_branch > 5 && n_mut_branch%10 == 0) + PhyML_Printf("\n. # of mutations on edge %d (length: %g) exceeds 5 (%d) ! The program will probably crash soon...:(", + b->num, + tree->rates ? tree->rates->cur_l[d->num] : b->l->v, + n_mut_branch); + + snew = Sample_i_With_Proba_pi(probs,ns); + + // Record mutation type + mut[slast*ns+snew]++; + + // Record mutation type in the site mutation array + thismut = slast*ns+snew; + + muttype[(*n_mut)+n_mut_branch-1] = thismut; + + // Record time of mutation + muttime[(*n_mut)+n_mut_branch-1] = tlast; + +#ifdef PHYTIME + // Transform into time in calendar units + muttime[(*n_mut)+n_mut_branch-1] /= tree->rates->cur_l[d->num]; + muttime[(*n_mut)+n_mut_branch-1] *= fabs(tree->rates->nd_t[a->num]-tree->rates->nd_t[d->num]); +#endif + + tax_idx = -1; + Random_Tax_Idx(a,d,&tax_idx,tree); + muttax[(*n_mut)+n_mut_branch-1] = tax_idx; + + // Update the last state + slast = snew; + } + else + { + if(slast == sd) break; + else + { + // Restart from the beginning + for(i=0;i 0) */ + /* { */ + /* thismut = MIN(i,j) * ns + MAX(i,j) - (MIN(i,j)+1+(int)POW(MIN(i,j)+1,2))/2; */ + + /* if(tree->mixt_tree != NULL) */ + /* tree->mixt_tree->mutmap[thismut*(tree->n_pattern)*(2*tree->n_otu-3) + b->num*(tree->n_pattern) + site]++; */ + /* else */ + /* tree->mutmap[thismut*(tree->n_pattern)*(2*tree->n_otu-3) + b->num*(tree->n_pattern) + site]++; */ + /* } */ + /* } */ + /* } */ + + Free(all_probs); + Free(mut); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Ancestral_Sequences(t_tree *tree, int print) +{ + int i; + + if(print == YES) + { + + PhyML_Printf("\n\n. Estimating ancestral sequences..."); + + strcpy(tree->io->out_ancestral_seq_file,tree->io->out_file); + strcat(tree->io->out_ancestral_seq_file,"_phyml_ancestral_"); + if(tree->io->append_run_ID) + { + strcat(tree->io->out_ancestral_seq_file,tree->io->run_id_string); + strcat(tree->io->out_ancestral_seq_file,"_"); + } + strcat(tree->io->out_ancestral_seq_file,"seq.txt"); + tree->io->fp_out_ancestral_seq = Openfile(tree->io->out_ancestral_seq_file,1); + + + strcpy(tree->io->out_ancestral_tree_file,tree->io->out_file); + strcat(tree->io->out_ancestral_tree_file,"_phyml_ancestral_"); + if(tree->io->append_run_ID) + { + strcat(tree->io->out_ancestral_tree_file,tree->io->run_id_string); + strcat(tree->io->out_ancestral_tree_file,"_"); + } + strcat(tree->io->out_ancestral_tree_file,"tree.txt"); + tree->io->fp_out_ancestral_tree = Openfile(tree->io->out_ancestral_tree_file,1); + + + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n\n\n"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. Printing marginal probabilities of ancestral sequences at each site"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. of the alignment and each node of the tree. The tree in Newick format"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. with internal nodes labels corresponding to those given below can be"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. found in the file '%s'.",tree->io->out_ancestral_tree_file); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. Ancestral reconstruction is conducted based on the \"Minimum Posterior Expected"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. Error\" (MPEE) criterion, which accomodates for uncertainty in the selection of "); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. ancestral character states."); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. Recommended citation:"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. Oliva A., Pulicani S., Lefort V., Brehelin L., Gascuel O. and S. Guindon,"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. \"Accounting for ambiguity in ancestral sequence reconstruction\","); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n. Bioinformatics, Volume 35, Issue 21, 1 November 2019."); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n"); + + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n\n"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"Site\tNodeLabel\t"); + for(i=0;imod->ns;i++) PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"%10c\t",Reciproc_Assign_State(i,tree->io->datatype)); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"MPEE\t"); + PhyML_Fprintf(tree->io->fp_out_ancestral_seq,"\n"); + + + short int bck_support = tree->io->print_support_val; + + tree->io->print_node_num = YES; + tree->io->print_support_val = NO; + char *s = Write_Tree(tree); + PhyML_Fprintf(tree->io->fp_out_ancestral_tree,"%s",s); + tree->io->print_node_num = NO; + tree->io->print_support_val = bck_support; + + Free(s); + fclose(tree->io->fp_out_ancestral_tree); + } + + for(i=0;i<2*tree->n_otu-2;i++) + if(tree->a_nodes[i]->tax == NO) + Ancestral_Sequences_One_Node(tree->a_nodes[i],tree,print); + + if(tree->n_root) Ancestral_Sequences_One_Node(tree->n_root,tree,print); + + + fclose(tree->io->fp_out_ancestral_seq); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Ancestral_Sequences_One_Node(t_node *d, t_tree *tree, int print) +{ + if(d->tax) return; + else + { + if(tree->is_mixt_tree) + { + MIXT_Ancestral_Sequences_One_Node(d,tree,print); + } + else + { + t_node *v0,*v1,*v2; // three neighbours of d + t_edge *b0,*b1,*b2; + int i,j; + int catg; + phydbl p0, p1, p2; + phydbl *p; + int site,csite; + phydbl *p_lk0, *p_lk1, *p_lk2; + int *sum_scale0, *sum_scale1, *sum_scale2; + phydbl sum_probas; + phydbl *Pij0, *Pij1, *Pij2; + phydbl inc,sum_scale; + FILE *fp; + + unsigned const int ncatg = tree->mod->ras->n_catg; + unsigned const int ns = tree->mod->ns; + unsigned const int nsns = ns*ns; + unsigned const int ncatgns = ns*ncatg; + + + if(tree->scaling_method == SCALE_RATE_SPECIFIC) + { + PhyML_Fprintf(stderr,"\n. Likelihood rescaling method not compatible with the calculation of ancestral state probabilities."); + Exit("\n"); + } + + + if(!d) return; + + fp = tree->io->fp_out_ancestral_seq; + assert(fp != NULL); + + + p = (phydbl *)mCalloc(ns,sizeof(phydbl)); + + for(site=0;sitedata->init_len;site++) // For each site in the current partition element + { + csite = tree->data->sitepatt[site]; + + for(i=0;iv[0]; + v1 = d->v[1]; + v2 = d->v[2]; + + b0 = d->b[0]; + b1 = d->b[1]; + b2 = d->b[2]; + + Pij0 = b0->Pij_rr; + Pij1 = b1->Pij_rr; + Pij2 = b2->Pij_rr; + + sum_scale = 0.0; + + if(v0 == b0->left) + { + p_lk0 = b0->p_lk_left; + sum_scale0 = b0->sum_scale_left; + } + else + { + p_lk0 = b0->p_lk_rght; + sum_scale0 = b0->sum_scale_rght; + } + + if(v1 == b1->left) + { + p_lk1 = b1->p_lk_left; + sum_scale1 = b1->sum_scale_left; + } + else + { + p_lk1 = b1->p_lk_rght; + sum_scale1 = b1->sum_scale_rght; + } + + if(v2 == b2->left) + { + p_lk2 = b2->p_lk_left; + sum_scale2 = b2->sum_scale_left; + } + else + { + p_lk2 = b2->p_lk_rght; + sum_scale2 = b2->sum_scale_rght; + } + + + for(catg=0;catgtax) + { + for(j=0;jb[0]->p_lk_tip_r[csite*ns+j] * Pij0[catg*nsns+i*ns+j]; + + if(isinf(p0) || isnan(p0)) + { + PhyML_Fprintf(stderr,"\n. p0: %G v0->b[0]->p_lk_tip_r[csite*ns+j]: %G Pij0[catg*nsns+i*ns+j]: %G\n", + p0, + v0->b[0]->p_lk_tip_r[csite*ns+j], + Pij0[catg*nsns+i*ns+j]); + Exit("\n"); + } + } + } + else + { + for(j=0;jtax) + { + for(j=0;jb[0]->p_lk_tip_r[csite*ns+j] * Pij1[catg*nsns+i*ns+j]; + + if(isinf(p1) || isnan(p1)) + { + PhyML_Fprintf(stderr,"\n. p1: %G v1->b[0]->p_lk_tip_r[csite*ns+j]: %G Pij1[catg*nsns+i*ns+j]: %G\n", + p1, + v1->b[0]->p_lk_tip_r[csite*ns+j], + Pij1[catg*nsns+i*ns+j]); + Exit("\n"); + } + } + } + else + { + for(j=0;jtax) + { + for(j=0;jb[0]->p_lk_tip_r[csite*ns+j] * Pij2[catg*nsns+i*ns+j]; + } + } + else + { + for(j=0;jmod->e_frq->pi->v[i] * + tree->mod->ras->gamma_r_proba->v[catg]; + + p[i] += inc; + + + if(isinf(p[i]) || isnan(p[i])) + { + PhyML_Fprintf(stderr,"\n. site: %4d p0: %G p1: %G p2: %G tree->mod->e_frq->pi->v[i]: %G tree->cur_site_lk[csite]: %G tree->mod->ras->gamma_r_proba->v[catg]: %G tree->c_lnL_sorted[csite]: %G", + csite, + p0,p1,p2, + tree->mod->e_frq->pi->v[i] , + tree->cur_site_lk[csite] , + tree->mod->ras->gamma_r_proba->v[catg], + tree->c_lnL_sorted[csite]); + Exit("\n"); + } + } + + /* printf("\n. site: %d || %d %d %d", */ + /* csite, */ + /* v0->tax ? -1 : sum_scale0[csite*ncatg+catg], */ + /* v1->tax ? -1 : sum_scale1[csite*ncatg+catg], */ + /* v2->tax ? -1 : sum_scale2[csite*ncatg+catg]); */ + + } + + if(tree->mod->ras->invar == YES) + { + int num_prec_issue = NO; + phydbl inv_site_lk = Invariant_Lk(sum_scale,csite,&num_prec_issue,tree); + + + switch(num_prec_issue) + { + case YES : + { + assert(isinf(inv_site_lk)); + inv_site_lk = Invariant_Lk(0,csite,&num_prec_issue,tree); + for(i=0;imod->ras->pinvar->v * tree->mod->e_frq->pi->v[i]; + break; + } + case NO : + { + for(i=0;imod->ras->pinvar->v) + inv_site_lk * tree->mod->ras->pinvar->v * tree->mod->e_frq->pi->v[i]; + break; + } + } + + } + + + for(i=0;ic_lnL_sorted[csite]; + for(i=0;inum); + for(i=0;i highest_count) + { + highest_count = count[i]; + highest_count_idx = i; + } + } + + most_frequent_state = best_state[highest_count_idx]; + + Free(alpha); + Free(best_state); + Free(idx); + Free(count); + + return(most_frequent_state); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int MPEE_Score(const phydbl *alpha, int *idx, const phydbl *p, const int ns) +{ + unsigned int i; + phydbl *mpee_score,*cdf_sorted; + int min_idx,res; + phydbl a,b; + phydbl min; + + mpee_score = (phydbl *)mCalloc(ns,sizeof(phydbl)); + cdf_sorted = (phydbl *)mCalloc(ns,sizeof(phydbl)); + + + cdf_sorted[0] = p[idx[0]]; + for(i=1;i + +#ifndef ANCESTRAL_H +#define ANCESTRAL_H + +#include "utilities.h" + + +void Sample_Ancestral_Seq(int fullmutmap, int fromprior, t_tree *tree); +void Sample_Ancestral_Seq_Pre(t_node *a, t_node *d, t_edge *b, + int site, int r_cat, + int *muttype, phydbl *muttime, int *muttax, int *n_mut, + int fullmutmap, int fromprior, t_tree *tree); +int Sample_Ancestral_Seq_Core(t_node *a, t_node *d, t_edge *b, int r_cat, int site, t_tree *tree); +void Map_Mutations(t_node *a, t_node *d, int sa, int sd, t_edge *b, int site, int rcat, int *muttype, phydbl *muttime, int *muttax, int *n_mut, t_tree *tree); +void Ancestral_Sequences(t_tree *tree, int print); +void Ancestral_Sequences_One_Node(t_node *d, t_tree *tree, int print); +int MPEE_Score(const phydbl *alpha, int *idx, const phydbl *p, const int ns); +int MPEE_Infer(const phydbl *p, const int ns); +void Reverse_Muttime(phydbl *muttime, int n_mut, t_tree *tree); + +#endif diff --git a/phyml/avx.c b/phyml/avx.c new file mode 100644 index 0000000..69e404a --- /dev/null +++ b/phyml/avx.c @@ -0,0 +1,669 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "assert.h" +#include "avx.h" + +#if defined(__AVX__) + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void AVX_Update_Eigen_Lr(t_edge *b, t_tree *tree) +{ + unsigned int site,catg; + unsigned int i,j; + + unsigned const int npattern = tree->n_pattern; + unsigned const int ncatg = tree->mod->ras->n_catg; + unsigned const int ns = tree->mod->ns; + unsigned const int sz = (int)BYTE_ALIGN / 8; + unsigned const int nblocks = ns / sz; + unsigned const int ncatgns = ncatg*ns; + + const phydbl *p_lk_left,*p_lk_rght,*pi; + phydbl *dot_prod,*p_lk_left_pi; + phydbl *l_ev,*r_ev; + + __m256d *_l_ev,*_r_ev,*_prod_left,*_prod_rght; + +#ifndef WIN32 + if(posix_memalign((void **)&p_lk_left_pi,BYTE_ALIGN,(size_t) ns * sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&l_ev,BYTE_ALIGN,(size_t) ns * ns * sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_l_ev,BYTE_ALIGN,(size_t) ns * ns / sz * sizeof(__m256d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_r_ev,BYTE_ALIGN,(size_t) ns * ns / sz * sizeof(__m256d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_prod_left,BYTE_ALIGN,(size_t) ns / sz * sizeof(__m256d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_prod_rght,BYTE_ALIGN,(size_t) ns / sz * sizeof(__m256d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + p_lk_left_pi = _aligned_malloc(ns * sizeof(phydbl),BYTE_ALIGN); + l_ev = _aligned_malloc(ns * ns * sizeof(phydbl),BYTE_ALIGN); + _l_ev = _aligned_malloc(ns * ns / sz * sizeof(__m256d),BYTE_ALIGN); + _r_ev = _aligned_malloc(ns * ns / sz * sizeof(__m256d),BYTE_ALIGN); + _prod_left = _aligned_malloc(ns / sz * sizeof(__m256d),BYTE_ALIGN); + _prod_rght = _aligned_malloc(ns / sz * sizeof(__m256d),BYTE_ALIGN); +#endif + + + assert(sz == 4); + assert(tree->update_eigen_lr == YES); + + r_ev = tree->mod->eigen->r_e_vect; + + /* Copy transpose of matrix of left eigen vectors */ + for(i=0;imod->eigen->l_e_vect[j*ns+i]; + + /* Load into AVX registers */ + for(i=0;ileft->tax ? b->p_lk_tip_l : b->p_lk_left; + p_lk_rght = b->rght->tax ? b->p_lk_tip_r : b->p_lk_rght; + pi = tree->mod->e_frq->pi->v; + dot_prod = tree->dot_prod; + + for(site=0;sitedata->wght[site] > SMALL) + { + for(catg=0;catgleft->tax == NO) p_lk_left += ns; + if(b->rght->tax == NO) p_lk_rght += ns; + } + + if(b->left->tax == YES) p_lk_left += ns; + if(b->rght->tax == YES) p_lk_rght += ns; + } + else + { + if(b->left->tax == YES) p_lk_left += ns; + else p_lk_left += ncatgns; + + if(b->rght->tax == YES) p_lk_rght += ns; + else p_lk_rght += ncatgns; + + dot_prod += ncatgns; + } + } + + Free(l_ev); + Free(_l_ev); + Free(_r_ev); + Free(_prod_left); + Free(_prod_rght); + Free(p_lk_left_pi); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl AVX_Lk_Core_One_Class_No_Eigen_Lr(const phydbl *p_lk_left, const phydbl *p_lk_rght, const phydbl *Pij, const phydbl *tPij, const phydbl *pi, const int ns, const int ambiguity_check, const int observed_state) +{ + const unsigned int sz = (int)BYTE_ALIGN / 8; + const unsigned nblocks = ns/sz; + + if(nblocks == 1) + { + __m256d _plk_r,_plk_l; + + if(ambiguity_check == NO) // tip case. + { + Pij += observed_state*ns; + _plk_r = _mm256_mul_pd(_mm256_load_pd(Pij),_mm256_load_pd(p_lk_left)); + return pi[observed_state] * AVX_Vect_Norm(_plk_r); + } + else + { + unsigned int i; + __m256d _pijplk,_pij; + + _plk_r = _mm256_mul_pd(_mm256_load_pd(p_lk_rght),_mm256_load_pd(pi)); + _pijplk = _mm256_setzero_pd(); + + for(i=0;in_pattern; + const unsigned int ns = tree->mod->ns; + const unsigned int ncatg = tree->mod->ras->n_catg; + + const unsigned int ncatgns = ncatg * ns; + const unsigned int nsns = ns * ns; + + const unsigned int sz = (int)BYTE_ALIGN / 8; + const unsigned nblocks = ns/sz; + + __m256d *_tPij1,*_tPij2,*_pmat1plk1,*_pmat2plk2,*_plk0,*_init_tPij1,*_init_tPij2; + + +#ifndef WIN32 + if(posix_memalign((void **)&_tPij1,BYTE_ALIGN,(size_t)(ncatg * nsns / sz) * sizeof(__m256d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_tPij2,BYTE_ALIGN,(size_t)(ncatg * nsns / sz) * sizeof(__m256d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_pmat1plk1,BYTE_ALIGN,(size_t)ns / sz * sizeof(__m256d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_pmat2plk2,BYTE_ALIGN,(size_t)ns / sz * sizeof(__m256d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_plk0,BYTE_ALIGN,(size_t)(ns / sz) * sizeof(__m256d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + _tPij1 = _aligned_malloc(ncatg * nsns / sz * sizeof(__m256d),BYTE_ALIGN); + _tPij2 = _aligned_malloc(ncatg * nsns / sz * sizeof(__m256d),BYTE_ALIGN); + tPij1 = _aligned_malloc(ncatg * nsns / sz * sizeof(__m256d),BYTE_ALIGN); + tPij2 = _aligned_malloc(ncatg * nsns / sz * sizeof(__m256d),BYTE_ALIGN); + _pmat1plk1 = _aligned_malloc(ns / sz * sizeof(__m256d),BYTE_ALIGN); + _pmat2plk2 = _aligned_malloc(ns / sz * sizeof(__m256d),BYTE_ALIGN); + _plk0 = _aligned_malloc(ns / sz * sizeof(__m256d),BYTE_ALIGN); +#endif + + _init_tPij1 = _tPij1; + _init_tPij2 = _tPij2; + + sum_scale_v1_val = 0; + sum_scale_v2_val = 0; + n_v1 = n_v2 = NULL; + plk0 = plk1 = plk2 = NULL; + Pij1 = Pij2 = NULL; + tPij1 = tPij2 = NULL; + sum_scale_v1 = sum_scale_v2 = NULL; + p_lk_loc = NULL; + state_v1 = state_v2 = -1; + + + Set_All_Partial_Lk(&n_v1,&n_v2, + &plk0,&sum_scale,&p_lk_loc, + &Pij1,&tPij1,&plk1,&sum_scale_v1, + &Pij2,&tPij2,&plk2,&sum_scale_v2, + d,b,tree); + + // Copy transpose of transition matrices into AVX registers + for(i=0;imod->augmented == YES) + { + PhyML_Printf("\n== AVX version of the Update_Partial_Lk function does not"); + PhyML_Printf("\n== allow augmented data."); + assert(FALSE); + } + + /* For every site in the alignment */ + for(site=0;sitedata->wght[site] > SMALL) + { + state_v1 = state_v2 = -1; + ambiguity_check_v1 = ambiguity_check_v2 = YES; + + if(n_v1 && n_v1->tax) + { + ambiguity_check_v1 = n_v1->c_seq->is_ambigu[site]; + if(ambiguity_check_v1 == NO) state_v1 = n_v1->c_seq->d_state[site]; + } + + if(n_v2 && n_v2->tax) + { + ambiguity_check_v2 = n_v2->c_seq->is_ambigu[site]; + if(ambiguity_check_v2 == NO) state_v2 = n_v2->c_seq->d_state[site]; + } + + _tPij1 = _init_tPij1; + _tPij2 = _init_tPij2; + + for(catg=0;catgtax) ? 0 : ns; + plk2 += (n_v2->tax) ? 0 : ns; + } + + plk1 += (n_v1->tax) ? ns : 0; + plk2 += (n_v2->tax) ? ns : 0; + + if(tree->scaling_method == SCALE_FAST) + { + sum_scale_v1_val = (sum_scale_v1)?(sum_scale_v1[site]):(0); + sum_scale_v2_val = (sum_scale_v2)?(sum_scale_v2[site]):(0); + sum_scale[site] = sum_scale_v1_val + sum_scale_v2_val; + + if(sum_scale[site] >= 1024) + { + /* plk0 -= ncatgns; */ + /* plk1 -= (n_v1->tax) ? ns : ncatgns; */ + /* plk2 -= (n_v2->tax) ? ns : ncatgns; */ + /* PhyML_Fprintf(stderr,"\n. PARTIAL site: %d plk0: %p [%g %g %g %g] plk1: %p [%g %g %g %g] plk2: %p [%g %g %g %g]", */ + /* site, */ + /* plk0, */ + /* plk0[0], */ + /* plk0[1], */ + /* plk0[2], */ + /* plk0[3], */ + /* plk1, */ + /* plk1[0], */ + /* plk1[1], */ + /* plk1[2], */ + /* plk1[3], */ + /* plk2, */ + /* plk2[0], */ + /* plk2[1], */ + /* plk2[2], */ + /* plk2[3] */ + /* ); */ + /* PhyML_Fprintf(stderr,"\n. PARTIAL site: %d d: %d n_v1: %d n_v2: %d",site,d->num,n_v1->num,n_v2->num); */ + /* PhyML_Fprintf(stderr,"\n. PARTIAL site: %d sum n: %d sum n_v1: %d sum n_v2: %d",site,sum_scale[site],sum_scale_v1_val,sum_scale_v2_val); */ + + /* plk0 += ncatgns; */ + /* plk1 += (n_v1->tax) ? ns : ncatgns; */ + /* plk2 += (n_v2->tax) ? ns : ncatgns; */ + /* Exit("\n"); */ + } + + plk0 -= ncatgns; + largest_p_lk = -BIG; + for(i=0;i largest_p_lk) + largest_p_lk = plk0[i]; + + if(largest_p_lk < INV_TWO_TO_THE_LARGE && + tree->mod->augmented == NO && + tree->apply_lk_scaling == YES) + { + for(i=0;itax) ? ns : ncatgns; + plk2 += (n_v2->tax) ? ns : ncatgns; + } + } + Free(_init_tPij1); + Free(_init_tPij2); + Free(_pmat1plk1); + Free(_pmat2plk2); + Free(_plk0); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void AVX_Partial_Lk_Exex(const __m256d *_tPij1, const int state1, const __m256d *_tPij2, const int state2, const int ns, __m256d *plk0) +{ + unsigned const int sz = (int)BYTE_ALIGN / 8; + unsigned const int nblocks = ns / sz; + unsigned int i; + + _tPij1 = _tPij1 + state1 * nblocks; + _tPij2 = _tPij2 + state2 * nblocks; + for(i=0;i plk0: %f",x[i]); */ + + /* _mm256_store_pd(x,_tPij1[0]); */ + /* for(int i=0;i<4;++i) PhyML_Printf("\n> Pij1: %f",x[i]); */ + + /* _mm256_store_pd(x,_tPij2[0]); */ + /* for(int i=0;i<4;++i) PhyML_Printf("\n> Pij2: %f",x[i]); */ + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void AVX_Partial_Lk_Exin(const __m256d *_tPij1, const int state1, const __m256d *_tPij2, const phydbl *_plk2, __m256d *_pmat2plk2, const int ns, __m256d *_plk0) +{ + unsigned const int sz = (int)BYTE_ALIGN / 8; + unsigned const int nblocks = ns / sz; + unsigned int i; + + _tPij1 = _tPij1 + state1 * nblocks; + AVX_Matrix_Vect_Prod(_tPij2,_plk2,ns,_pmat2plk2); + + for(i=0;i 1.0 || plk1[i] < 1.0 || plk2[i] > 1.0 || plk2[i] < 1.0) break; + + if(i != ns) + { + AVX_Matrix_Vect_Prod(_tPij1,plk1,ns,_pmat1plk1); + AVX_Matrix_Vect_Prod(_tPij2,plk2,ns,_pmat2plk2); + + for(i=0;i + +#ifndef AVX_H +#define AVX_H + +#include "utilities.h" +#include "optimiz.h" +#include "models.h" +#include "free.h" +#include "times.h" +#include "mixt.h" + + +#if defined(__AVX__) + +void AVX_Update_Partial_Lk(t_tree *tree,t_edge *b_fcus,t_node *n); +void AVX_Update_Eigen_Lr(t_edge *b, t_tree *tree); +phydbl AVX_Lk_Core_One_Class_Eigen_Lr(const phydbl *dot_prod, const phydbl *expl, const unsigned int ns); +void AVX_Lk_dLk_Core_One_Class_Eigen_Lr(const phydbl *dot_prod, const phydbl *expl, const unsigned int ns, phydbl *lk, phydbl *dlk); +phydbl AVX_Lk_Core_One_Class_No_Eigen_Lr(const phydbl *p_lk_left, const phydbl *p_lk_rght, const phydbl *Pij, const phydbl *tPij, const phydbl *pi, const int ns, const int ambiguity_check, const int observed_state); +phydbl AVX_Vect_Norm(__m256d _z); +phydbl AVX_Lk_Core(int state, int ambiguity_check, t_edge *b, t_tree *tree); +phydbl AVX_Lk_Core_Nucl(int state, int ambiguity_check, t_edge *b, t_tree *tree); +phydbl AVX_Lk_Core_AA(int state, int ambiguity_check, t_edge *b, t_tree *tree); +void AVX_Partial_Lk_Exex(const __m256d *_tPij1, const int state1, const __m256d *_tPij2, const int state2, const int ns, __m256d *plk0); +void AVX_Partial_Lk_Exin(const __m256d *_tPij1, const int state1, const __m256d *_tPij2, const phydbl *_plk2, __m256d *_pmat2plk2, const int ns, __m256d *_plk0); +void AVX_Partial_Lk_Inin(const __m256d *_tPij1, const phydbl *plk1, __m256d *_pmat1plk1, const __m256d *_tPij2, const phydbl *plk2, __m256d *_pmat2plk2, const int ns, __m256d *_plk0); +void AVX_Matrix_Vect_Prod(const __m256d *_m_transpose, const phydbl *_v, const int ns, __m256d *res); +__m256d AVX_Horizontal_Add(const __m256d x[4]); +phydbl AVX_Lk_Core_One_Class_No_Eigen_Lr_Block(const phydbl *p_lk_left, const phydbl *p_lk_rght, const phydbl *Pij, const phydbl *tPij, const phydbl *pi, const int ns, const int ambiguity_check, const int observed_state); +phydbl AVX_Lk_Core_One_Class_No_Eigen_Lr_No_Block(const phydbl *p_lk_left, const phydbl *p_lk_rght, const phydbl *Pij, const phydbl *tPij, const phydbl *pi, const int ns, const int ambiguity_check, const int observed_state); + + +#endif +#endif diff --git a/phyml/beagle_utils.c b/phyml/beagle_utils.c new file mode 100644 index 0000000..5fcf6df --- /dev/null +++ b/phyml/beagle_utils.c @@ -0,0 +1,398 @@ +/* + * author: Imran Fanaswala + */ + +#ifndef BEAGLE_UTILS_CPP +#define BEAGLE_UTILS_CPP + +#include +#include "beagle_utils.h" + +#define CLEAN_BEAGLE_API /* Attempting to remove unnecessary communication with BEAGLE device */ + +double* int_to_double(const int* src, int num_elems) +{ + double* dest = (double*)malloc(num_elems*sizeof(double)); if (NULL==dest) Warn_And_Exit("\n. Couldn't allocate memory.\n"); + int i; + for(i=0; ilength; i++) { + fprintf(stdout, "\t\tResource %i:\n\t\tName : %s\n", i, rList->list[i].name); + fprintf(stdout, "\t\t\tDesc : %s\n", rList->list[i].description); + fprintf(stdout, "\t\t\tFlags:"); + print_beagle_flags(rList->list[i].supportFlags); + fprintf(stdout, "\n"); + } + fflush(stdout); +} + +void print_beagle_instance_details(BeagleInstanceDetails *inst) +{ + int rNumber = inst->resourceNumber; + fprintf(stdout, "\tUsing resource %i:\n", rNumber); + fprintf(stdout, "\t\tRsrc Name : %s\n", inst->resourceName); + fprintf(stdout, "\t\tImpl Name : %s\n", inst->implName); + fprintf(stdout, "\t\tImpl Desc : %s\n", inst->implDescription); + fprintf(stdout, "\t\tFlags:"); + fflush(stdout); + print_beagle_flags(inst->flags); + fflush(stdout); +} + +int create_beagle_instance(t_tree *tree, int quiet, option* io) +{ + if(UNINITIALIZED != tree->b_inst){ +// fprintf(stdout,"\n\tWARNING: Creating a BEAGLE instance on a tree with an existing BEAGLE instance:%d\n",tree->b_inst); + } + if(!quiet){ +// print_beagle_resource_list(); + } + int i; + BeagleInstanceDetails inst_d; + int num_rate_catg = tree->mod->ras->n_catg; + int num_branches = 2*tree->n_otu-1; //rooted tree + //Recall that in PhyML, each edge has a "left" and "right" partial vectors. Therefore, + //in BEAGLE we have 2*num_branches number of partials. + //BEAGLE's partials buffer = [ tax1, tax2, ..., taxN, b1Left, b2Left, b3Left,...,bMLeft, b1Rght, b2Rght, b3Rght,...,bMRght] (N taxa, M branches) + int num_partials = 2*(tree->n_otu + num_branches); /* TODO: This does not seem correct; suspect poor indexing elsewhere */ + /* In update_operations, indexes range from 0 to almost 2 (n_otu + num_branches), but not all integers are used */ + + int resourceList[1]; + resourceList[0] = io->beagle_resource; + +// DUMP_I(tree->n_otu, num_rate_catg, num_partials, num_branches, tree->mod->ns, tree->n_pattern, tree->mod->whichmodel); + int beagle_inst = beagleCreateInstance( + tree->n_otu, /**< Number of tip data elements (input) */ + num_partials, /**< Number of partial buffer (input) */ + /* PhyML uses partials */ 0, /**< Number of compact state representation buffers to create (input) */ + tree->mod->ns, /**< Number of states in the continuous-time Markov chain (input) */ + tree->n_pattern, /**< Number of site patterns to be handled by the instance (input) */ + 1, /**< Number of rate matrix eigen-decomposition,state freqs, and category weight buffers*/ + num_branches, /**< Number of rate matrix buffers (input) */ + num_rate_catg, /**< Number of rate categories (input) */ + -1, /**< Number of scaling buffers. Unused because we use SCALING_ALWAYS */ + resourceList, /**< List of potential resource on which this instance is allowed (input, NULL implies no restriction */ + 1, /**< Length of resourceList list (input) */ + BEAGLE_FLAG_FRAMEWORK_CPU | BEAGLE_FLAG_PROCESSOR_CPU | BEAGLE_FLAG_SCALING_ALWAYS | BEAGLE_FLAG_EIGEN_REAL | ((sizeof(float)==sizeof(phydbl)) ? BEAGLE_FLAG_PRECISION_SINGLE:BEAGLE_FLAG_PRECISION_DOUBLE), + 0, /**< Bit-flags indicating required implementation characteristics, see BeagleFlags (input) */ + &inst_d); + if (beagle_inst < 0){ + fprintf(stderr, "beagleCreateInstance() failed:%i\n\n",beagle_inst); + return beagle_inst; + } + + if(!quiet){ + fprintf(stdout, "\n\tUnique BEAGLE instance id:%i\n", beagle_inst); + print_beagle_instance_details(&inst_d); + } + + //Set the tips + for(i=0; i<2*tree->n_otu-1; ++i) //taxa+internal nodes + { + // Print_Tip_Partials(tree, tree->a_nodes[i]); + if(tree->a_nodes[i]->tax) + { + assert(tree->a_nodes[i]->c_seq->len == tree->n_pattern); // number of compacts sites == number of distinct site patterns + double* tip = short_to_double(tree->a_nodes[i]->b[0]->p_lk_tip_r, tree->n_pattern*tree->mod->ns); //The tip states are stored on the branch leading to the tip + //Recall we store tip partials on the branch leading to the tip, rather than the tip itself. + int ret = beagleSetTipPartials(beagle_inst, tree->a_nodes[i]->b[0]->p_lk_tip_idx, tip); + if(ret<0){ + fprintf(stderr, "beagleSetTipPartials() on instance %i failed:%i\n\n",beagle_inst,ret); + Free(tip); + return ret; + } + Free(tip); + } + } + + //Set the pattern weights + double* pwts = int_to_double(tree->data->wght,tree->n_pattern); //BTW, These weights are absolute counts, and not freqs + int ret = beagleSetPatternWeights(beagle_inst, pwts); + if(ret<0){ + fprintf(stderr, "beagleSetPatternWeights() on instance %i failed:%i\n\n",beagle_inst,ret); + Free(pwts); + return ret; + } + Free(pwts); + + tree->mod->b_inst=beagle_inst; + + update_beagle_ras(tree->mod); + update_beagle_efrqs(tree->mod); + + return beagle_inst; +} + +/* Update partial likelihood on edge b on the side of b where + node d lies. +*/ +void update_beagle_partials(t_tree* tree, t_edge* b, t_node* d) +{ + /* + | + |<- b + | + d + / \ + b1 / \ b2 + / \ + n_v1 n_v2 + */ + + if(d->tax) //Partial likelihoods are only calculated on internal nodes + { + PhyML_Printf("\n== t_node %d is a leaf...",d->num); + PhyML_Printf("\n== Err. in file %s at line %d (function '%s')\n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit("\n"); + } + + //Determine d's "left" and "right" neighbors. + t_node *n_v1, *n_v2;//d's "left" and "right" neighbor nodes + phydbl *p_lk,*p_lk_v1,*p_lk_v2; + phydbl *Pij1,*Pij2; + int *sum_scale, *sum_scale_v1, *sum_scale_v2; + int *p_lk_loc; + int dest_p_idx, child1_p_idx, child2_p_idx, Pij1_idx, Pij2_idx; + n_v1 = n_v2 = NULL; + p_lk = p_lk_v1 = p_lk_v2 = NULL; + Pij1 = Pij2 = NULL; + sum_scale_v1 = sum_scale_v2 = NULL; + p_lk_loc = NULL; + dest_p_idx = child1_p_idx = child2_p_idx = Pij1_idx = Pij2_idx = UNINITIALIZED; + Set_All_P_Lk(&n_v1,&n_v2, + &p_lk,&sum_scale,&p_lk_loc, + &Pij1,&p_lk_v1,&sum_scale_v1, + &Pij2,&p_lk_v2,&sum_scale_v2, + d,b,tree, + &dest_p_idx, &child1_p_idx, &child2_p_idx, &Pij1_idx, &Pij2_idx); + + + // fprintf(stdout, "\nUpdating partials on Branch %d (on the side where Node %d lies)\n",b->num,d->num);fflush(stdout); + // double* p_lk_v1_b = (double*)malloc(tree->mod->ras->n_catg*tree->mod->ns*tree->n_pattern*sizeof(double));if(NULL==p_lk_v1_b) Warn_And_Exit("Couldnt allocate memory"); + // beagleGetPartials(tree->b_inst, child1_p_idx, BEAGLE_OP_NONE, (double*)p_lk_v1_b); + // double* p_lk_v2_b = (double*)malloc(tree->mod->ras->n_catg*tree->mod->ns*tree->n_pattern*sizeof(double));if(NULL==p_lk_v2_b) Warn_And_Exit("Couldnt allocate memory"); + // beagleGetPartials(tree->b_inst, child2_p_idx, BEAGLE_OP_NONE, (double*)p_lk_v2_b); + + // fprintf(stdout, "Left partials :");fflush(stdout); + // Dump_Arr_D(p_lk_v1_b, tree->mod->ras->n_catg*tree->mod->ns*tree->n_pattern); + // fprintf(stdout, "Right partials:");fflush(stdout); + // Dump_Arr_D(p_lk_v2_b, tree->mod->ras->n_catg*tree->mod->ns*tree->n_pattern); + // Free(p_lk_v1_b); + // Free(p_lk_v2_b); + + + //Create the corresponding BEAGLE operation + + // fprintf(stderr,"%d, %d, %d, ", dest_p_idx, child1_p_idx, child2_p_idx); + + BeagleOperation operations[1] = {{dest_p_idx, BEAGLE_OP_NONE, BEAGLE_OP_NONE, child1_p_idx, Pij1_idx, child2_p_idx, Pij2_idx}}; + //Compute the partials + int ret = beagleUpdatePartials(tree->b_inst, operations, 1, BEAGLE_OP_NONE); + if(ret<0){ + fprintf(stderr, "beagleUpdatePartials() on instance %i failed:%i\n\n",tree->b_inst,ret); + Exit(""); + } + //Load the computed/updated partial partials +#ifndef CLEAN_BEAGLE_API + ret = beagleGetPartials(tree->b_inst, dest_p_idx, BEAGLE_OP_NONE, (double*)p_lk); + if(ret<0){ + fprintf(stderr, "beagleGetPartials() on instance %i failed:%i\n\n",tree->b_inst,ret); + Exit(""); + } +#endif + + // fprintf(stdout, "Updated partials:");fflush(stdout); + // Dump_Arr_D(p_lk, tree->mod->ras->n_catg*tree->mod->ns*tree->n_pattern); +} + +int finalize_beagle_instance(t_tree *tree) +{ + if(tree->b_inst >= 0) { + int ret = beagleFinalizeInstance(tree->b_inst); + if(ret<0) fprintf(stderr, "\nFailed to finalize BEAGLE instance %i: %i\n\n", tree->b_inst, ret); + return ret; + } + return 0; +} + +void update_beagle_ras(t_mod* mod) +{ + assert(UNINITIALIZED != mod->b_inst); + + int ret=-1; + if((sizeof(float)==sizeof(phydbl))) //Do we need to convert? + { + double* catg_rates = float_to_double(mod->ras->gamma_rr->v, mod->ras->n_catg); + ret = beagleSetCategoryRates(mod->b_inst, catg_rates); + Free(catg_rates); + if(ret<0){ + fprintf(stderr, "beagleSetCategoryRates() on instance %i failed:%i\n\n",mod->b_inst,ret); + Exit(""); + } + double* catg_wts = float_to_double(mod->ras->gamma_r_proba->v, mod->ras->n_catg); + if(!mod->optimizing_topology) { + ret = beagleSetCategoryWeights(mod->b_inst, 0, catg_wts); + Free(catg_wts); + if(ret<0){ + fprintf(stderr, "beagleSetCategoryWeights() on instance %i failed:%i\n\n",mod->b_inst,ret); + Exit(""); + } + } + } + else + { + ret = beagleSetCategoryRates(mod->b_inst, mod->ras->gamma_rr->v); + if(ret<0){ + fprintf(stderr, "beagleSetCategoryRates() on instance %i failed:%i\n\n",mod->b_inst,ret); + Exit(""); + } + if(!mod->optimizing_topology) { + ret = beagleSetCategoryWeights(mod->b_inst, 0, mod->ras->gamma_r_proba->v); + if(ret<0){ + fprintf(stderr, "beagleSetCategoryWeights() on instance %i failed:%i\n\n",mod->b_inst,ret); + Exit(""); + } + + } + } +} + +void update_beagle_efrqs(t_mod* mod) +{ + assert(UNINITIALIZED != mod->b_inst); + + int ret=-1; + if((sizeof(float)==sizeof(phydbl))) { + double* efrqs = float_to_double(mod->e_frq->pi->v, mod->ns); + ret = beagleSetStateFrequencies(mod->b_inst, 0, efrqs); + Free(efrqs); + } else { + ret = beagleSetStateFrequencies(mod->b_inst, 0, mod->e_frq->pi->v); + } + if(ret<0){ + fprintf(stderr, "beagleSetStateFrequencies() on instance %i failed:%i\n\n",mod->b_inst,ret); + Exit(""); + } +} + +void calc_edgelks_beagle(t_edge *b, t_tree *tree) +{ + assert(UNINITIALIZED != tree->b_inst); + + //Compute the edge likelihood + int parents[1] = {b->p_lk_left_idx}; + int children[1] = {b->rght->tax?b->p_lk_tip_idx:b->p_lk_rght_idx}; + int pmats[1] = {b->Pij_rr_idx}; + int other[1] = {0};//Category Weights and State Frequencies both have a single buffer, hence they are both indexed at 0 + double lnL[1] = {UNINITIALIZED}; + // DUMP_I(parents[0], children[0], pmats[0], b->num, b->rght->tax); + int ret=beagleCalculateEdgeLogLikelihoods(tree->b_inst, parents, children, pmats, NULL, NULL, other, other, NULL, 1, lnL, NULL, NULL); + int i; + +if(ret<0){ + fprintf(stderr, "beagleCalculateEdgeLogLikelihoods() on instance %i failed:%i\n\n",tree->b_inst,ret); + Exit(""); + } + + tree->c_lnL = sizeof(phydbl)==sizeof(float)?(float)lnL[0]:lnL[0]; + + //Retrieve the site likelihoods that were computed during the previous edge likelihood computation + ret = beagleGetSiteLogLikelihoods(tree->b_inst,tree->cur_site_lk);//TODO: Handle when cur_site_lk is float + if(ret<0){ + fprintf(stderr, "beagleGetSiteLogLikelihoods() on instance %i failed:%i\n\n",tree->b_inst,ret); + Exit(""); + } + //Transform + for(i=0;in_pattern;++i) + tree->cur_site_lk[i]=exp(tree->cur_site_lk[i]); +} + +void update_beagle_eigen(t_mod* mod) +{ + assert(UNINITIALIZED != mod->b_inst); + + int whichmodel = mod->whichmodel; + //We use Eigen Decomposition only for GTR models and AA datasets + if((mod->io->datatype == AA || whichmodel==GTR || whichmodel==CUSTOM) && mod->use_m4mod == NO) + { + //Beagle expects untransformed eigen-values (i.e. recall e_val is exp() scaled, so we undo that) + phydbl* evals = (phydbl*)malloc(mod->ns * sizeof(phydbl)); + int i; + for(i=0;ins;++i) evals[i]=log(mod->eigen->e_val[i]); + int ret=-1; + if((sizeof(float)==sizeof(phydbl)))//Need to convert to doubles? + { + double* eigen_vects = float_to_double(mod->eigen->r_e_vect, mod->eigen->size*mod->eigen->size); + double* eigen_vects_inv = float_to_double(mod->eigen->l_e_vect, mod->eigen->size*mod->eigen->size); + double* eigen_vals = float_to_double(evals,mod->eigen->size); + ret = beagleSetEigenDecomposition(mod->b_inst,0,eigen_vects,eigen_vects_inv,eigen_vals); + Free(eigen_vects);Free(eigen_vects_inv);Free(eigen_vals); + } else { + ret = beagleSetEigenDecomposition(mod->b_inst,0,mod->eigen->r_e_vect,mod->eigen->l_e_vect,evals); + } + if(ret<0){ + fprintf(stderr, "beagleSetEigenDecomposition() on instance %i failed:%i\n\n",mod->b_inst,ret); + Free(evals); + Exit(""); + } + Free(evals); + } +} + +#endif // BEAGLE_UTILS_CPP + diff --git a/phyml/beagle_utils.h b/phyml/beagle_utils.h new file mode 100644 index 0000000..bcab8d9 --- /dev/null +++ b/phyml/beagle_utils.h @@ -0,0 +1,77 @@ +/* + * author: Imran Fanaswala + */ + +#ifndef BEAGLE_UTILS_H +#define BEAGLE_UTILS_H + +#include "assert.h" +#include "libhmsbeagle/beagle.h" +#include "utilities.h" +#define UNINITIALIZED -42 + +/* +BEAGLE is a library that abstracts the core computations common to most +phylogenetic packages. The following paragraphs serve as a "design document" for +the implementation details of how BEAGLE has been integrated with PhyML. The +reader is expected to be familiar with phylogenetics, skimmed the BEAGLE API, +and seen a couple of its examples. + +PARTIAL LIKELIHOODS: +- For each internal edge, PhyML maintains a vector of partials that lie to the +"right" and "left", to faciliate both post-order and pre-order tree traversal. +Therefore each t_edge has a `p_lk_right` and `p_lk_left` field +- PhyML represents a tip as a vector of partials (where one bit is "1", and +the rest are "0"). Therefore, a t_edge connected to a tip has `p_lk_tip` field. +Also by convention, the tip always lies to the right of the edge its connected +to. In other words, if b->right->tax is True, then b->p_lk_tip holds the tip +partials. +- Therefore for BEAGLE, we allocate N+(2*num_edges) partial buffers. +- Recall that BEAGLE requires each partial buffer to be uniquely indexed. Thus +each edge also has an additional `p_lk_rght_idx` and `p_lk_left_idx` field. +These fields are used to create a BeagleOperation struct during the call to +beagleUpdatePartials(). +- In PhyML, Update_P_Lk() updates the partials for a specific edge lieing along +a specific "direction". The "direction" depends on which tree-traversal is being +employed. In other words, the tree-traversal dictates whether we are computing +"up"/"right" or "down"/"left" partials relative to the t_node*. Specifically, +Set_All_P_Lk() handles the nitty gritty of determining whether we are computing +"right" or "left" partials. Therefore this function has been modified to also +set the appropriate BEAGLE indices. + +P-MATS and EDGELIKELIHOODS: +- (1) Observe that PhyML does eigen decomposition for only GTR and AA models and +thus the P-matrix is computed using Beagle. This implies the usage of +SetEigenDecomposition() and UpdateTransitionMatricies() calls. +- (2) On the other hand, in case of simpler models (JC69, F81, etc), the +P-Matrix is explicitly set in BEAGLE thus implying the usage of +SetTransitionMatrix(). +- The choice between (1) and (2) is made in Update_PMat_At_Given_Edge(). BTW, +upon reading Update_PMat_At_Given_Edge(), it may appear that the P-Matrix is +being computed in PhyML *and* in BEAGLE; afterall because PMat() function in all +cases. However, when BEAGLE is enabled, observe that in PMat() essentially does +nothing. +- Lk_Core() computes the edgelikelihoods, and calc_edgelks_beagle() is the +corresponding BEAGLE function that does the same. + + +*/ + + + +#define TODO_BEAGLE "TODO. This codepath has not been implemented in PhyML-X, please post your usecase on the PhyML discussion list" + +int create_beagle_instance(t_tree* tree, int quiet, option* io); +int finalize_beagle_instance(t_tree* tree); +void update_beagle_partials(t_tree* tree, t_edge* b, t_node* d); +void update_beagle_ras(t_mod* mod); +void update_beagle_efrqs(t_mod* mod); +void update_beagle_eigen(t_mod* mod); +void calc_edgelks_beagle(t_edge* b, t_tree* tree); +double* int_to_double(const int* src, int num_elems); +double* short_to_double(const short* src, int num_elems); +double* float_to_double(const phydbl *src, int num_elems); + + + +#endif // BEAGLE_UTILS_H diff --git a/phyml/bionj.c b/phyml/bionj.c index 25b18f0..e1a3c3e 100644 --- a/phyml/bionj.c +++ b/phyml/bionj.c @@ -20,7 +20,7 @@ on a simple model of sequence data." (1997) O. Gascuel. Mol Biol Evol. */ #include "bionj.h" -#include "free.h" + void Bionj(matrix *mat) { @@ -28,9 +28,10 @@ void Bionj(matrix *mat) phydbl vxy,lx,ly,lamda,score; Clean_Tree_Connections(mat->tree); - For(i,mat->tree->n_otu) mat->tip_node[i] = mat->tree->noeud[i]; - mat->tree->num_curr_branch_available = 0; + for(i=0;itree->n_otu;i++) mat->tip_node[i] = mat->tree->a_nodes[i]; + mat->tree->num_curr_branch_available = mat->tree->n_otu; + while(mat->r > 3) { x = y = 0; @@ -38,29 +39,33 @@ void Bionj(matrix *mat) score = .0; Compute_Sx(mat); Best_Pair(mat,&x,&y,&score); - vxy=Variance(mat,x,y); + vxy=BioNJ_Variance(mat,x,y); lx=Br_Length(mat,x,y); ly=Br_Length(mat,y,x); lamda=Lamda(mat,x,y,vxy); Update_Mat(mat,x,y,lx,ly,vxy,lamda); Update_Tree(mat,x,y,lx,ly,score); } + Finish(mat); + } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Finish(matrix *mat) { phydbl dxy,dxz,dyz; int x,y,z; - node *nx,*ny,*nz,*new; + t_node *nx,*ny,*nz,*new; int i; dxy = dxz = dyz = -1.; x = y = z = -1; - For(i,mat->n_otu) + for(i=0;in_otu;i++) { if(mat->on_off[i]) { @@ -78,7 +83,7 @@ void Finish(matrix *mat) ny = mat->tip_node[y]; nz = mat->tip_node[z]; - new = mat->tree->noeud[mat->curr_int]; + new = mat->tree->a_nodes[mat->curr_int]; new->num = mat->curr_int; new->v[0] = nx; new->v[1] = ny; @@ -88,25 +93,34 @@ void Finish(matrix *mat) ny->v[0] = new; nz->v[0] = new; - - Connect_One_Edge_To_Two_Nodes(new,nx,mat->tree->t_edges[mat->tree->num_curr_branch_available],mat->tree); - mat->tree->num_curr_branch_available++; - Connect_One_Edge_To_Two_Nodes(new,ny,mat->tree->t_edges[mat->tree->num_curr_branch_available],mat->tree); - mat->tree->num_curr_branch_available++; - Connect_One_Edge_To_Two_Nodes(new,nz,mat->tree->t_edges[mat->tree->num_curr_branch_available],mat->tree); - mat->tree->num_curr_branch_available++; - + if(nx->tax) + Connect_One_Edge_To_Two_Nodes(new,nx,mat->tree->a_edges[nx->num],mat->tree); + else + Connect_One_Edge_To_Two_Nodes(new,nx,mat->tree->a_edges[mat->tree->num_curr_branch_available],mat->tree); + + if(ny->tax) + Connect_One_Edge_To_Two_Nodes(new,ny,mat->tree->a_edges[ny->num],mat->tree); + else + Connect_One_Edge_To_Two_Nodes(new,ny,mat->tree->a_edges[mat->tree->num_curr_branch_available],mat->tree); + + if(nz->tax) + Connect_One_Edge_To_Two_Nodes(new,nz,mat->tree->a_edges[nz->num],mat->tree); + else + Connect_One_Edge_To_Two_Nodes(new,nz,mat->tree->a_edges[mat->tree->num_curr_branch_available],mat->tree); + - nx->b[0]->l = .5*(dxy-dyz+dxz); - ny->b[0]->l = .5*(dyz-dxz+dxy); - nz->b[0]->l = .5*(dxz-dxy+dyz); + nx->b[0]->l->v = .5*(dxy-dyz+dxz); + ny->b[0]->l->v = .5*(dyz-dxz+dxy); + nz->b[0]->l->v = .5*(dxz-dxy+dyz); - new->b[0]->l = nx->b[0]->l; - new->b[1]->l = ny->b[0]->l; - new->b[2]->l = nz->b[0]->l; + new->b[0]->l->v = nx->b[0]->l->v; + new->b[1]->l->v = ny->b[0]->l->v; + new->b[2]->l->v = nz->b[0]->l->v; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Update_Mat(matrix *mat, int x, int y, phydbl lx, phydbl ly, phydbl vxy, phydbl lamda) { @@ -114,7 +128,7 @@ void Update_Mat(matrix *mat, int x, int y, phydbl lx, phydbl ly, phydbl vxy, phy int a,b; a = b = -1; - For(i,mat->n_otu) + for(i=0;in_otu;i++) { if((mat->on_off[i]) && (i != x) && (i != y)) { @@ -134,47 +148,53 @@ void Update_Mat(matrix *mat, int x, int y, phydbl lx, phydbl ly, phydbl vxy, phy } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// void Update_Tree(matrix *mat, int x, int y, phydbl lx, phydbl ly, phydbl score) { - node *new, *nx, *ny; + t_node *new, *nx, *ny; nx = mat->tip_node[x]; ny = mat->tip_node[y]; - new = mat->tree->noeud[mat->curr_int]; + new = mat->tree->a_nodes[mat->curr_int]; nx->v[0] = new; ny->v[0] = new; new->v[1] = nx; new->v[2] = ny; new->num = mat->curr_int; + + if(nx->tax) + Connect_One_Edge_To_Two_Nodes(new,nx,mat->tree->a_edges[nx->num],mat->tree); + else + Connect_One_Edge_To_Two_Nodes(new,nx,mat->tree->a_edges[mat->tree->num_curr_branch_available],mat->tree); - Connect_One_Edge_To_Two_Nodes(new,nx,mat->tree->t_edges[mat->tree->num_curr_branch_available],mat->tree); - mat->tree->num_curr_branch_available++; - Connect_One_Edge_To_Two_Nodes(new,ny,mat->tree->t_edges[mat->tree->num_curr_branch_available],mat->tree); - mat->tree->num_curr_branch_available++; + if(ny->tax) + Connect_One_Edge_To_Two_Nodes(new,ny,mat->tree->a_edges[ny->num],mat->tree); + else + Connect_One_Edge_To_Two_Nodes(new,ny,mat->tree->a_edges[mat->tree->num_curr_branch_available],mat->tree); - nx->b[0]->l = lx; - ny->b[0]->l = ly; - new->b[1]->l = lx; - new->b[2]->l = ly; + nx->b[0]->l->v = lx; + ny->b[0]->l->v = ly; + + new->b[1]->l->v = lx; + new->b[2]->l->v = ly; new->score[0] = score; - nx->l[0] = lx; - ny->l[0] = ly; - - new->l[1] = lx; - new->l[2] = ly; - + nx->b[0]->l->v = lx; + ny->b[0]->l->v = ly; + mat->tip_node[x] = new; mat->on_off[y] = 0; mat->curr_int++; mat->r--; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Best_Pair(matrix *mat, int *x, int *y,phydbl *score) { @@ -188,7 +208,7 @@ void Best_Pair(matrix *mat, int *x, int *y,phydbl *score) Qmin = 1.e+10; - For(i,mat->n_otu) + for(i=0;in_otu;i++) { if(mat->on_off[i]) { @@ -210,7 +230,7 @@ void Best_Pair(matrix *mat, int *x, int *y,phydbl *score) } /* n_ties = 0; */ -/* For(i,mat->n_otu) */ +/* for(i=0;in_otu;i++) */ /* { */ /* if(mat->on_off[i]) */ /* { */ @@ -230,7 +250,7 @@ void Best_Pair(matrix *mat, int *x, int *y,phydbl *score) /* if(!n_ties) */ /* { */ -/* printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); */ +/* PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); */ /* Warn_And_Exit(""); */ /* } */ @@ -240,7 +260,7 @@ void Best_Pair(matrix *mat, int *x, int *y,phydbl *score) /* { */ /* int cand; */ /* *x = *y = -1; */ -/* cand = (int)rint(rand()/(phydbl)(RAND_MAX) * (n_ties-1)); */ +/* cand = (int)RINT(rand()/(phydbl)(RAND_MAX) * (n_ties-1)); */ /* *x = (int)(ties[cand] / mat->n_otu); */ /* *y = (int)(ties[cand] % mat->n_otu); */ /* } */ @@ -249,34 +269,36 @@ void Best_Pair(matrix *mat, int *x, int *y,phydbl *score) Qmin2 = 1e+10; - For(i,mat->n_otu) + for(i=0;in_otu;i++) { if((i != *y) && (i != *x) && (t_Qij[mat->n_otu*(*x)+i] < Qmin2)) Qmin2 = t_Qij[mat->n_otu*(*x)+i]; } - For(i,mat->n_otu) + for(i=0;in_otu;i++) { if((i != *y) && (i != *x) && (t_Qij[mat->n_otu*i+(*y)] < Qmin2)) Qmin2 = t_Qij[mat->n_otu*i+(*y)]; } - *score = fabs(Qmin2 - Qmin)/fabs(Qmin); + *score = FABS(Qmin2 - Qmin)/FABS(Qmin); Free(t_Qij); /* Free(ties); */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Compute_Sx(matrix *mat) { int i,j; - For(i,mat->n_otu) + for(i=0;in_otu;i++) { mat->dist[i][i] = .0; if(mat->on_off[i]) { - For(j,mat->n_otu) + for(j=0;jn_otu;j++) { if((i != j) && (mat->on_off[j])) { @@ -287,14 +309,18 @@ void Compute_Sx(matrix *mat) } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + phydbl Sum_S(matrix *mat, int i) { return mat->dist[i][i]; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + phydbl Dist(matrix *mat, int x, int y) { @@ -304,9 +330,10 @@ phydbl Dist(matrix *mat, int x, int y) return(mat->dist[y][x]); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Variance(matrix *mat, int x, int y) +phydbl BioNJ_Variance(matrix *mat, int x, int y) { if(x > y) { @@ -318,7 +345,9 @@ phydbl Variance(matrix *mat, int x, int y) } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + phydbl Br_Length(matrix *mat, int x, int y) { @@ -326,7 +355,9 @@ phydbl Br_Length(matrix *mat, int x, int y) (Sum_S(mat,x)-Sum_S(mat,y))/(phydbl)(mat->r-2.)); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + phydbl Dist_Red(matrix *mat, int x, phydbl lx, int y, phydbl ly, int i, phydbl lamda) { @@ -336,18 +367,21 @@ phydbl Dist_Red(matrix *mat, int x, phydbl lx, int y, phydbl ly, int i, phydbl l return(Dui); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// phydbl Var_Red(matrix *mat, int x, int y, int i, phydbl lamda, phydbl vxy) { phydbl Vui; - Vui=lamda*(Variance(mat,x,i)) - +(1.-lamda)*(Variance(mat,y,i)) + Vui=lamda*(BioNJ_Variance(mat,x,i)) + +(1.-lamda)*(BioNJ_Variance(mat,y,i)) -lamda*(1.-lamda)*vxy; return(Vui); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + phydbl Lamda(matrix *mat, int x, int y, phydbl vxy) { @@ -358,14 +392,14 @@ phydbl Lamda(matrix *mat, int x, int y, phydbl vxy) lamda = 0.5; else /* BioNJ (Gascuel, 1997) */ { - if(vxy==0.0) + if(vxy < SMALL && vxy > -SMALL) lamda=0.5; else { - For(i,mat->n_otu) + for(i=0;in_otu;i++) { if((x != i) && (y != i) && (mat->on_off[i])) - lamda = lamda + Variance(mat,y,i) - Variance(mat,x,i); + lamda = lamda + BioNJ_Variance(mat,y,i) - BioNJ_Variance(mat,x,i); } lamda = 0.5 + lamda/(2.*(mat->r-2)*vxy); } @@ -379,7 +413,9 @@ phydbl Lamda(matrix *mat, int x, int y, phydbl vxy) return(lamda); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + phydbl Q_Agglo(matrix *mat, int x, int y) { @@ -390,21 +426,25 @@ phydbl Q_Agglo(matrix *mat, int x, int y) return(Qxy); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Bionj_Br_Length(matrix *mat) { int x; - x = Bionj_Br_Length_Post(mat->tree->noeud[0], - mat->tree->noeud[0]->v[0], + x = Bionj_Br_Length_Post(mat->tree->a_nodes[0], + mat->tree->a_nodes[0]->v[0], mat); - mat->tree->noeud[0]->b[0]->l = Dist(mat,0,x); + mat->tree->a_nodes[0]->b[0]->l->v = Dist(mat,0,x); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Bionj_Br_Length_Post(node *a, node *d, matrix *mat) + +int Bionj_Br_Length_Post(t_node *a, t_node *d, matrix *mat) { int i; @@ -419,7 +459,7 @@ int Bionj_Br_Length_Post(node *a, node *d, matrix *mat) int x,y; d_v1 = d_v2 = -1; - For(i,3) + for(i=0;i<3;i++) if(d->v[i] != a) {(d_v1 < 0)?(d_v1 = i):(d_v2 = i);} @@ -428,14 +468,14 @@ int Bionj_Br_Length_Post(node *a, node *d, matrix *mat) vxy = .0; Compute_Sx(mat); - vxy=Variance(mat,(x),(y)); + vxy=BioNJ_Variance(mat,(x),(y)); lx=Br_Length(mat,(x),(y)); ly=Br_Length(mat,(y),(x)); lamda=Lamda(mat,(x),(y),vxy); Update_Mat(mat,(x),(y),lx,ly,vxy,lamda); - d->b[d_v1]->l = lx; - d->b[d_v2]->l = ly; + d->b[d_v1]->l->v = lx; + d->b[d_v2]->l->v = ly; mat->on_off[y] = 0; mat->r--; @@ -444,7 +484,9 @@ int Bionj_Br_Length_Post(node *a, node *d, matrix *mat) } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + diff --git a/phyml/bionj.h b/phyml/bionj.h index b73c4f9..8f0d6c7 100644 --- a/phyml/bionj.h +++ b/phyml/bionj.h @@ -10,12 +10,14 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef NJ_H #define NJ_H #include "utilities.h" #include "optimiz.h" -/*#include "tools.h"*/ +#include "free.h" void Bionj(matrix *mat); void Finish(matrix *mat); @@ -23,7 +25,7 @@ void Compute_Sx(matrix *mat); phydbl Sum_S(matrix *mat, int i); phydbl Dist(matrix *mat, int x, int y); phydbl Q_Agglo(matrix *mat, int x, int y); -phydbl Variance(matrix *mat, int x, int y); +phydbl BioNJ_Variance(matrix *mat, int x, int y); phydbl Br_Length(matrix *mat, int x, int y); void Update_Dist(matrix *mat, int x, int y); phydbl Lamda(matrix *mat, int x, int y, phydbl vxy); @@ -34,7 +36,7 @@ void Update_Mat(matrix *mat, int x, int y, phydbl lx, phydbl ly, phydbl vxy, phydbl lamda); phydbl Dist_Red(matrix *mat, int x, phydbl lx, int y, phydbl ly, int i, phydbl lamda); -int Bionj_Br_Length_Post(node *a, node *d, matrix *mat); +int Bionj_Br_Length_Post(t_node *a, t_node *d, matrix *mat); void Bionj_Br_Length(matrix *mat); #endif diff --git a/phyml/checkpoint.c b/phyml/checkpoint.c new file mode 100644 index 0000000..0827e3a --- /dev/null +++ b/phyml/checkpoint.c @@ -0,0 +1,36 @@ +#include "checkpoint.h" + + +void CHECK_Main(int argc,char **argv) +{ + // Up to you Salva... + + +} + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + diff --git a/phyml/checkpoint.h b/phyml/checkpoint.h new file mode 100644 index 0000000..0f5aa7c --- /dev/null +++ b/phyml/checkpoint.h @@ -0,0 +1,10 @@ +#include + +#ifndef CHECKPOINT_H +#define CHECKPOINT_H + +#include "utilities.h" + +void CHECK_Main(int argc, char **argv); + +#endif diff --git a/phyml/cl.c b/phyml/cl.c index b813e55..8024a6d 100644 --- a/phyml/cl.c +++ b/phyml/cl.c @@ -10,27 +10,25 @@ the GNU public licence. See http://www.opensource.org for details. */ -#include -#include -#include "utilities.h" -#include "options.h" #include "cl.h" -#include "models.h" -#include "free.h" -#include "interface.h" -#include "mg.h" -#include "m4.h" /*********************************************************/ /** * Fill the Option fields, with the argc array */ -void Read_Command_Line(option *io, int argc, char **argv) +int Read_Command_Line(option *io, int argc, char **argv) { int c; - int open_ps_file; - int use_gamma; + int idx; + int i; + int writemode; + + writemode = WRITE; + + if(argc == 1) Exit("\n. No argument was passed to the program. Please check the documentation. \n"); + PhyML_Printf("",writemode); + struct option longopts[] = { {"n_rgrft", required_argument,NULL,0}, @@ -65,6 +63,7 @@ void Read_Command_Line(option *io, int argc, char **argv) {"random_boot", required_argument,NULL,29}, {"print_trace", no_argument,NULL,30}, {"print_site_lnl", no_argument,NULL,31}, + {"print_site_lk", no_argument,NULL,31}, {"cov", no_argument,NULL,32}, {"cov_delta", required_argument,NULL,33}, {"cov_alpha", required_argument,NULL,34}, @@ -73,251 +72,725 @@ void Read_Command_Line(option *io, int argc, char **argv) {"cov_free", no_argument,NULL,37}, {"no_gap", no_argument,NULL,38}, {"n_rr_branch", required_argument,NULL,39}, + {"append", no_argument,NULL,40}, + {"no_five_branch", no_argument,NULL,41}, + {"pars_thresh", required_argument,NULL,42}, + {"min_diff_lk_move", required_argument,NULL,43}, + {"hybrid", no_argument,NULL,44}, + {"use_median", no_argument,NULL,45}, + {"run_id", required_argument,NULL,46}, + {"pars", no_argument,NULL,47}, + {"quiet", no_argument,NULL,48}, + {"version", no_argument,NULL,49}, + {"calibration_file", required_argument,NULL,50}, + {"calibration", required_argument,NULL,50}, + {"clade_file", required_argument,NULL,50}, + {"boot_progress_every", required_argument,NULL,51}, + {"aa_rate_file", required_argument,NULL,52}, + {"chain_len", required_argument,NULL,53}, + {"sample_freq", required_argument,NULL,54}, + {"burnin", required_argument,NULL,55}, + {"no_memory_check", no_argument,NULL,56}, + {"no_colalias", no_argument,NULL,57}, + {"alias_subpatt", no_argument,NULL,58}, + {"no_sequences", no_argument,NULL,59}, + {"prior", no_argument,NULL,59}, + {"fastlk", no_argument,NULL,60}, + {"free_rates", no_argument,NULL,61}, + {"freerates", no_argument,NULL,61}, + {"freerate", no_argument,NULL,61}, + {"free_rate", no_argument,NULL,61}, + {"is", no_argument,NULL,62}, + // no 63 since it corresponds to character '?' + {"rate_model", required_argument,NULL,64}, + {"ratemodel", required_argument,NULL,64}, + {"log_l", no_argument,NULL,65}, + {"gamma_lens", no_argument,NULL,66}, + {"il", no_argument,NULL,66}, + {"codpos", required_argument,NULL,67}, + {"constraint_file", required_argument,NULL,68}, + {"constraint_tree", required_argument,NULL,68}, + {"help", no_argument,NULL,69}, + {"mutmap", no_argument,NULL,70}, + {"parvals", required_argument,NULL,71}, + {"constrained_lens", no_argument,NULL,72}, + {"xml", required_argument,NULL,73}, + {"l_var", required_argument,NULL,74}, +#ifdef BEAGLE + {"beagle_resource", required_argument,NULL,75}, +#endif + {"ancestral", no_argument,NULL,76}, + {"anc", no_argument,NULL,76}, + {"coord_file", required_argument,NULL,77}, + {"json_trace", no_argument,NULL,78}, + {"weights", required_argument,NULL,79}, + {"tbe", no_argument,NULL,80}, + {"leave_duplicates", no_argument,NULL,81}, + {"precision", required_argument,NULL,82}, + {"l_min", required_argument,NULL,83}, {0,0,0,0} }; - open_ps_file = 0; - use_gamma = 0; - while((c = getopt_long(argc,argv,"qi:d:m:b:n:t:f:zk:v:c:a:u:ho:s:x:g:l:e",longopts,NULL)) != -1) - { - switch(c) - { - case 39 : - { - io->mod->n_rr_branch = (int)atoi(optarg); - if(io->mod->n_rr_branch < 1) - { - printf("\n. The number of classes must be an integer greater than 0.\n"); - printf("\n. Type any key to exit.\n"); - Exit("\n"); - } - break; - } - case 38 : - { - io->rm_ambigu = 1; - break; - } - case 37 : - { - io->mod->s_opt->opt_cov_free_rates = 1; - break; - } - case 36 : - { - open_ps_file = 1; - break; - } - case 35 : - { - io->m4_model = YES; - if(!io->mod->m4mod) io->mod->m4mod = (m4 *)M4_Make_Light((io->mod->datatype == NT)?(4):(20)); - io->mod->m4mod->n_h = (int)atoi(optarg); - - if(io->mod->m4mod->n_h < 1) - { - char choix; - printf("\n. The number of classes must be greater than 0.\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - break; - } - case 34 : - { - io->m4_model = YES; - if(!io->mod->m4mod) io->mod->m4mod = (m4 *)M4_Make_Light((io->mod->datatype == NT)?(4):(20)); - io->mod->m4mod->use_cov_alpha = 1; - io->mod->m4mod->use_cov_free = 0; - - if(!strcmp(optarg,"e") || !strcmp(optarg,"E") || - !strcmp(optarg,"estimated") || !strcmp(optarg,"ESTIMATED")) - { - io->mod->s_opt->opt_cov_alpha = 1; - io->mod->m4mod->alpha = 1.0; - } - else - { - io->mod->m4mod->alpha = (phydbl)atof(optarg); - - if(io->mod->m4mod->alpha < 1.E-5) - { - char choix; - printf("\n. The value of alpha must be greater than 1.E-5.\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - } - break; - } - - case 33 : - { - io->m4_model = YES; - if(!io->mod->m4mod) io->mod->m4mod = (m4 *)M4_Make_Light((io->mod->datatype == NT)?(4):(20)); - - if(!strcmp(optarg,"e") || !strcmp(optarg,"E") || - !strcmp(optarg,"estimated") || !strcmp(optarg,"ESTIMATED")) - { - io->mod->s_opt->opt_cov_delta = 1; - io->mod->m4mod->delta = 1.0; - } - else - { - io->mod->m4mod->delta = (phydbl)atof(optarg); - - if(atof(optarg) < 1.E-10) - { - char choix; - printf("\n. The value of delta must be larger than 1.E-10.\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - } - break; - } - case 32 : - { - io->m4_model = YES; - break; - } - case 31 : - { - io->print_site_lnl = 1; - break; - } - case 30 : - { - io->print_trace = 1; - break; - } - case 29 : - { - io->random_boot_seq_order = (int)atoi(optarg); - break; - } - case 28 : - { - io->collapse_boot = (int)atoi(optarg); - break; - } - case 27 : - { - io->r_seed = (int)atoi(optarg); - break; - } - case 26 : - { - io->mod->s_opt->general_pars = 1; - break; - } - case 25 : - { - io->mod->s_opt->fast_nni = 1; - break; - } - case 24 : - { - io->mod->s_opt->p_moves_to_examine = (double)atof(optarg); - break; - } - case 23 : - { - io->mod->s_opt->wim_inside_opt = 1; - break; - } - case 0 : - { - io->mod->s_opt->wim_n_rgrft = atoi(optarg); - break; - } - case 1 : - { - io->mod->s_opt->wim_n_globl = atoi(optarg); - break; - } - case 2 : - { - io->mod->s_opt->wim_max_dist = atoi(optarg); - break; - } - case 3 : - { - io->mod->s_opt->wim_n_optim = atoi(optarg); - break; - } - case 4 : - { - io->mod->s_opt->wim_n_best = atoi(optarg); - break; - } - case 16 : - { - io->mod->s_opt->min_diff_lk_local = atof(optarg); - break; - } + io->datatype = UNDEFINED; + + #ifndef PHYML + int open_ps_file = 0; + #endif + + idx=-1; + + do + { + c = getopt_long(argc,argv,"qi:d:m:b:n:t:f:zk:v:c:a:u:ho:s:x:g:l:ep",longopts,&idx); + + switch(c) + { + case 83 : + { + io->mod->l_min = String_To_Dbl(optarg); + break; + } + case 82 : + { + if ((!atoi(optarg)) || (atoi(optarg) < 1) || (atoi(optarg) > DECIMAL_DIG -3)) + { + PhyML_Printf("\n. The number of digits must be [1 - %d]\n", DECIMAL_DIG -3); + Exit("\n"); + } + else + { + io->precision = atoi(optarg); + } + break; + } + case 81 : + { + io->leave_duplicates = YES; + break; + } + case 80 : + { + io->do_tbe = YES; + io->do_boot = NO; + io->do_alrt = NO; + break; + } + case 79: + { + io->has_io_weights = YES; + strcpy(io->weight_file, optarg); + break; + } + case 78: + { + io->print_json_trace = YES; + break; + } + + case 77: + { + char *tmp; + tmp = (char *)mCalloc(T_MAX_FILE, sizeof(char)); + + if(strlen(optarg) > T_MAX_FILE -11) + { + char choix; + strcpy (tmp, "\n. The file name'"); + strcat (tmp, optarg); + strcat (tmp, "' is too long.\n"); + PhyML_Printf("%s",tmp); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else if (!Filexists (optarg)) + { + char choix; + strcpy (tmp, "\n. The file '"); + strcat (tmp, optarg); + strcat (tmp, "' doesn't exist.\n"); + PhyML_Printf("%s",tmp); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else + { + strcpy(io->in_coord_file, optarg); + io->fp_in_coord = Openfile(io->in_coord_file,READ); + } + Free(tmp); + break; + } + + case 76: + { + io->ancestral = YES; + break; + } +#ifdef BEAGLE + case 75: + { + io->beagle_resource = (int)atoi(optarg); + break; + } +#endif + case 74: + { + io->mod->l_var_sigma = String_To_Dbl(optarg); + break; + } + case 73: + { +#ifdef INVITEE + + Free_Optimiz(io->mod->s_opt); + Free_Model_Basic(io->mod); + Free_Input(io); + PhyTime_XML(optarg); + return 0; + +#elif defined(PHYML) + + Free_Optimiz(io->mod->s_opt); + Free_Model_Basic(io->mod); + Free_Input(io); + io = PhyML_XML(optarg); + Free(io); + return 0; + +#elif defined(PHYTIME) + + Free_Optimiz(io->mod->s_opt); + Free_Model_Basic(io->mod); + Free_Input(io); + DATE_XML(optarg); + return 0; + +#elif defined(PHYREX) + + Free_Optimiz(io->mod->s_opt); + Free_Model_Basic(io->mod); + Free_Input(io); + PHYREX_XML(optarg); + return 0; + +#endif + break; + } + case 72: + { + io->mod->s_opt->constrained_br_len = YES; + break; + } + case 71: + { + io->mcmc->in_fp_par = fopen(optarg,"r"); + io->mcmc->randomize = NO; + break; + } + case 70: + { + io->mutmap = YES; + break; + } + case 68: + { + char *tmp; + tmp = (char *)mCalloc(T_MAX_FILE, sizeof(char)); + + if(strlen(optarg) > T_MAX_FILE -11) + { + char choix; + strcpy (tmp, "\n. The file name'"); + strcat (tmp, optarg); + strcat (tmp, "' is too long.\n"); + PhyML_Printf("%s",tmp); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else if (!Filexists (optarg)) + { + char choix; + strcpy (tmp, "\n. The file '"); + strcat (tmp, optarg); + strcat (tmp, "' doesn't exist.\n"); + PhyML_Printf("%s",tmp); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else + { + strcpy(io->in_constraint_tree_file, optarg); + io->fp_in_constraint_tree = Openfile(io->in_constraint_tree_file,0); + } + Free(tmp); + break; + } + case 67: + { + phydbl pos; + pos = atof(optarg); + io->codpos = (int)pos; + if(io->codpos < 1 || io->codpos > 3) + { + char choix; + PhyML_Printf("\n. Coding position must be set to 1, 2 or 3.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + break; - case 17 : - { - io->mod->s_opt->min_diff_lk_global = atof(optarg); - break; - } - case 18 : - { - io->mod->s_opt->steph_spr = 0; - io->mod->s_opt->greedy = 1; - break; - } - case 19 : - { - io->mod->s_opt->brent_it_max = atoi(optarg); - break; - } - case 20 : - { - io->mod->s_opt->random_input_tree = 1; - break; - } - case 21 : - { - io->mod->s_opt->random_input_tree = 1; - io->mod->s_opt->n_rand_starts = atoi(optarg); - } - case 's':case 6: - { - if((!strcmp(optarg,"spr")) || (!strcmp(optarg,"SPR"))) - { - io->mod->s_opt->topo_search = SPR_MOVE; - io->mod->s_opt->greedy = (io->mod->s_opt->steph_spr)?(0):(1); - } - else if((!strcmp(optarg,"nni")) || (!strcmp(optarg,"NNI"))) - { - io->mod->s_opt->topo_search = NNI_MOVE; - io->mod->s_opt->random_input_tree = 0; - } - else if((!strcmp(optarg,"nni+spr")) || (!strcmp(optarg,"NNI+SPR"))) - { - io->mod->s_opt->topo_search = NNI_MOVE; - io->mod->s_opt->random_input_tree = 0; - io->mod->s_opt->spr_step_after_nnis = 1; - io->mod->s_opt->greedy = (io->mod->s_opt->steph_spr)?(0):(1); - } - break; - } + break; + } + case 66: + { + io->mod->gamma_mgf_bl = YES; + io->mod->s_opt->opt_gamma_br_len = YES; + break; + } + case 65: + { + io->mod->log_l = YES; + break; + } + case 64: + { + char *s; + int i; + s = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + i = 0; + while(optarg[i++]) s[i]=tolower(optarg[i]); + if(!strcmp(optarg,"gbd")) io->rates->model = THORNE; + else if(!strcmp(optarg,"geom")) io->rates->model = GUINDON; + else if(!strcmp(optarg,"lognorm")) io->rates->model = LOGNORMAL; + else if(!strcmp(optarg,"clock")) io->rates->model = STRICTCLOCK; + else if(!strcmp(optarg,"strictclock")) io->rates->model = STRICTCLOCK; + else if(!strcmp(optarg,"strict_clock")) io->rates->model = STRICTCLOCK; + else + { + PhyML_Printf("\n. rate_model should be 'gbs', 'gbd', 'gamma' or 'clock'."); + Exit("\n"); + } + Free(s); + break; + } + + + case 62: + { + io->mcmc->is = YES; + break; + } + case 61: + { + io->mod->ras->free_mixt_rates = YES; + io->mod->s_opt->opt_free_mixt_rates = YES; + break; + } + case 60: + { + io->lk_approx = NORMAL; + break; + } + case 59: + { + break; + } + case 58: + { + io->do_alias_subpatt = YES; + break; + } + case 57: + { + io->colalias = NO; + break; + } + case 56: + { + io->mem_question = NO; + break; + } + case 55: + { + phydbl len; + len = atof(optarg); + io->mcmc->chain_len_burnin = (int)len; + if(io->mcmc->chain_len_burnin < 1) + { + char choix; + PhyML_Printf("\n. chain_len_burnin must be an integer greater than 0.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + break; + } + case 54: + { + phydbl len; + len = atof(optarg); + io->mcmc->sample_interval = (int)len; + if(io->mcmc->sample_interval < 1) + { + char choix; + PhyML_Printf("\n. sample_interval must be an integer greater than 0.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + break; + } + case 53: + { + phydbl len; + len = atof(optarg); + io->mcmc->chain_len = (int)len; + if(io->mcmc->chain_len < 1) + { + char choix; + PhyML_Printf("\n. chain_len must be an integer greater than 0.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + break; + } + case 52: + { + char *s; + s = (char *)mCalloc(T_MAX_FILE, sizeof(char)); + strcpy(s,optarg); + io->mod->fp_aa_rate_mat = Openfile(s,0); + strcpy(io->mod->aa_rate_mat_file->s,s); + Free(s); + break; + } + case 51: + { + io->boot_prog_every = atoi(optarg); + if(io->boot_prog_every < 1) + { + char choix; + PhyML_Printf("\n. boot_progress_every must be an integer greater than 0.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + break; + } + case 50: + { + strcpy(io->clade_list_file,optarg); + break; + } + case 49: + { + PhyML_Printf("\n. This is PhyML version %s.\n\n",VERSION); + Exit(""); + break; + } + case 48 : + { + io->quiet = 1; + break; + } + case 'p' : case 47 : + { + io->in_tree = 1; + break; + } + case 46 : + { + if(strlen(optarg) > 0) + { + io->append_run_ID = YES; + strcpy(io->run_id_string,optarg); + } + break; + } + case 45 : + { + io->mod->ras->gamma_median = 1; + break; + } + case 44 : + { + io->mod->s_opt->hybrid_thresh = 0; + break; + } + case 43 : + { + io->mod->s_opt->min_diff_lk_move = atof(optarg); + if(io->mod->s_opt->min_diff_lk_move < 0) + { + char choix; + PhyML_Printf("\n. Min_diff_lk_move must be a double greater than 0.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + break; + } + case 42 : + { + io->mod->s_opt->pars_thresh = (int)atoi(optarg); + if(io->mod->s_opt->pars_thresh < 0) + { + PhyML_Printf("\n. The parsimony threshold must be an integer greater than 0.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + Exit("\n"); + } + break; + } + case 41 : + { + io->mod->s_opt->opt_five_branch = 0; + break; + } + case 40 : + { + writemode = APPEND; + break; + } + case 39 : + { + break; + } + case 38 : + { + io->rm_ambigu = 1; + break; + } + case 37 : + { + io->mod->s_opt->opt_cov_free_rates = YES; +#ifdef M4 + io->mod->m4mod->use_cov_alpha = NO; + io->mod->m4mod->use_cov_free = YES; +#endif + break; + } + case 36 : + { +#ifndef PHYML + open_ps_file = 1; +#endif + break; + } + case 35 : + { +#ifdef M4 + io->mod->m4mod->n_h = (int)atoi(optarg); + + if(io->mod->m4mod->n_h < 1) + { + char choix; + PhyML_Printf("\n. The number of classes must be greater than 0.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } +#endif + break; + } + case 34 : + { +#ifdef M4 + io->mod->m4mod->use_cov_alpha = YES; + io->mod->m4mod->use_cov_free = NO; - case 'd':case 7: - if(!strcmp(optarg,"nt")) - /* if(atoi(optarg) == NT) */ + if(!strcmp(optarg,"e") || !strcmp(optarg,"E") || + !strcmp(optarg,"estimated") || !strcmp(optarg,"ESTIMATED")) + { + io->mod->s_opt->opt_cov_alpha = YES; + io->mod->m4mod->alpha = 1.0; + } + else { - io->mod->datatype = NT; - io->mod->stepsize = 1; - io->mod->ns = 4; + io->mod->m4mod->alpha = (phydbl)atof(optarg); - if( - (io->mod->whichmodel == LG) || + if(io->mod->m4mod->alpha < 1.E-5) + { + char choix; + PhyML_Printf("\n. The value of alpha must be greater than 1.E-5.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + } +#endif + break; + } + case 33 : + { +#ifdef M4 + if(!strcmp(optarg,"e") || !strcmp(optarg,"E") || + !strcmp(optarg,"estimated") || !strcmp(optarg,"ESTIMATED")) + { + io->mod->s_opt->opt_cov_delta = YES; + io->mod->m4mod->delta = 1.0; + } + else + { + io->mod->m4mod->delta = (phydbl)atof(optarg); + + if(atof(optarg) < 1.E-10) + { + char choix; + PhyML_Printf("\n. The value of delta must be larger than 1.E-10.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + } +#endif + break; + } + case 32 : + { + io->mod->use_m4mod = YES; + break; + } + case 31 : + { + io->print_site_lnl = YES; + break; + } + case 30 : + { + io->print_trace = YES; + break; + } + case 29 : + { + io->random_boot_seq_order = (int)atoi(optarg); + break; + } + case 28 : + { + io->collapse_boot = (int)atoi(optarg); + break; + } + case 27 : + { + io->r_seed = (int)atoi(optarg); + break; + } + case 26 : + { + io->mod->s_opt->general_pars = YES; + break; + } + case 25 : + { + io->mod->s_opt->fast_nni = YES; + break; + } + case 24 : + { + io->mod->s_opt->p_moves_to_examine = (phydbl)atof(optarg); + break; + } + case 23 : + { + io->mod->s_opt->wim_inside_opt = 1; + break; + } + case 0 : + { + io->mod->s_opt->wim_n_rgrft = atoi(optarg); + break; + } + case 1 : + { + io->mod->s_opt->wim_n_globl = atoi(optarg); + break; + } + case 2 : + { + io->mod->s_opt->wim_max_dist = atoi(optarg); + break; + } + case 3 : + { + io->mod->s_opt->wim_n_optim = atoi(optarg); + break; + } + case 4 : + { + io->mod->s_opt->wim_n_best = atoi(optarg); + break; + } + case 16 : + { + io->mod->s_opt->min_diff_lk_local = atof(optarg); + break; + } + case 17 : + { + io->mod->s_opt->min_diff_lk_global = atof(optarg); + break; + } + case 18 : + { + io->mod->s_opt->steph_spr = NO; + io->mod->s_opt->greedy = YES; + break; + } + case 19 : + { + io->mod->s_opt->brent_it_max = atoi(optarg); + break; + } + case 20 : + { + io->mod->s_opt->random_input_tree = YES; + break; + } + case 21 : + { + io->mod->s_opt->random_input_tree = YES; + io->mod->s_opt->n_rand_starts = atoi(optarg); + if(io->mod->s_opt->n_rand_starts < 1) Exit("\n. Number of random starting trees must be > 0.\n\n"); + } + case 's':case 6: + { + if((!strcmp(optarg,"spr")) || (!strcmp(optarg,"SPR"))) + { + io->mod->s_opt->topo_search = SPR_MOVE; + io->mod->s_opt->greedy = (io->mod->s_opt->steph_spr)?(0):(1); + } + else if((!strcmp(optarg,"nni")) || (!strcmp(optarg,"NNI"))) + { + PhyML_Printf("\n. The NNI option is deprecated. PhyML now uses a mix of SPRs and NNIs."); + io->mod->s_opt->topo_search = NNI_MOVE; + io->mod->s_opt->random_input_tree = 0; + } + else if((!strcmp(optarg,"best")) || (!strcmp(optarg,"BEST"))) + { + PhyML_Printf("\n. The BEST option is deprecated. PhyML now uses a mix of SPRs and NNIs."); + io->mod->s_opt->topo_search = BEST_OF_NNI_AND_SPR; + io->mod->s_opt->greedy = (io->mod->s_opt->steph_spr)?(0):(1); + } + break; + } + + case 'd':case 7: + { + if(!strcmp(optarg,"nt")) + { + io->datatype = NT; + io->mod->ns = 4; +#ifdef M4 + io->mod->m4mod->n_o = 4; +#endif + + if((io->mod->whichmodel == LG) || (io->mod->whichmodel == WAG) || (io->mod->whichmodel == DAYHOFF) || (io->mod->whichmodel == JTT) || @@ -331,19 +804,23 @@ void Read_Command_Line(option *io, int argc, char **argv) (io->mod->whichmodel == MTART) || (io->mod->whichmodel == HIVW) || (io->mod->whichmodel == HIVB) || + (io->mod->whichmodel == AB) || (io->mod->whichmodel == CUSTOMAA) ) { io->mod->whichmodel = HKY85; - strcpy(io->mod->modelname, "HKY85\0"); + strcpy(io->mod->modelname->s, "HKY85\0"); } } else if (!strcmp(optarg,"aa")) - /* else if (atoi(optarg) == AA) */ { - io->mod->datatype = AA; - io->mod->stepsize = 1; - io->mod->ns = 20; + io->datatype = AA; + io->mod->s_opt->opt_kappa = NO; + io->mod->ns = 20; +#ifdef M4 + io->mod->m4mod->n_o = 20; +#endif + if( (io->mod->whichmodel == JC69) || (io->mod->whichmodel == K80) || @@ -356,310 +833,394 @@ void Read_Command_Line(option *io, int argc, char **argv) ) { io->mod->whichmodel = LG; - strcpy(io->mod->modelname, "LG\0"); + strcpy(io->mod->modelname->s, "LG\0"); } } + else if ((!strcmp(optarg,"generic")) || (!strcmp(optarg,"gen"))) + { + io->datatype = GENERIC; + } else { char choix; - printf("\n. Unknown argument to -d option: please use `nt' for DNA or `aa' for Amino-Acids\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); + PhyML_Printf("\n. Unknown argument to -d option: please use `nt' for DNA or `aa' for Amino-Acids\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); Exit("\n"); } break; + } + case 'm': case 5 : + { + if (!isalpha(optarg[0])) + { + if(strchr(optarg,',') == NULL) + { + strcpy(io->mod->custom_mod_string->s,optarg); + if (strlen(io->mod->custom_mod_string->s) != 6) + { + Warn_And_Exit("\n. The custom model string should be of length 6.\n"); + } + + io->datatype = NT; + io->mod->whichmodel = CUSTOM; + strcpy(io->mod->modelname->s, "custom"); + io->mod->s_opt->opt_kappa = NO; + io->mod->s_opt->opt_rr = YES; + } + else + { + phydbl v; + int n_rr; + const char *d = ","; + char *tok = strtok(optarg,d); + + io->datatype = NT; + io->mod->ns = 4; + io->mod->whichmodel = GTR; + io->mod->s_opt->opt_rr = NO; + + io->mod->r_mat = (t_rmat *)Make_Rmat(io->mod->ns); + Init_Rmat(io->mod->r_mat); + Make_Custom_Model(io->mod); + + n_rr = 0; + while(tok && n_rr < 6) + { + v = strtod(tok,NULL); + if (v != 0) + { + io->mod->r_mat->rr->v[n_rr] = v; + io->mod->r_mat->rr_val->v[n_rr] = log(v); + } + else + { + PhyML_Printf("\n. Invalid relative rate parameter value: '%s'.\n", tok); + Exit("\n"); + } + tok = strtok (NULL,d); + n_rr++; + } + assert(n_rr <= 6); + } + } + else + { + char *s = To_Upper_String(optarg); + + if (strcmp(s, "JC69") == 0) + { + io->datatype = NT; + io->mod->ns = 4; + io->mod->whichmodel = JC69; + } + else if(strcmp(s, "K80") == 0) + { + io->datatype = NT; + io->mod->ns = 4; + io->mod->whichmodel = K80; + } + else if(strcmp(s, "F81") == 0) + { + io->datatype = NT; + io->mod->ns = 4; + io->mod->whichmodel = F81; + } + else if (strcmp(s, "HKY85") == 0) + { + io->datatype = NT; + io->mod->ns = 4; + io->mod->whichmodel = HKY85; + } + else if(strcmp(s, "F84") == 0) + { + io->datatype = NT; + io->mod->ns = 4; + io->mod->whichmodel = F84; + } + else if (strcmp(s,"TN93") == 0) + { + io->datatype = NT; + io->mod->ns = 4; + io->mod->whichmodel = TN93; + } + else if(strncmp(s, "GTR", 3) == 0) + { + io->datatype = NT; + io->mod->ns = 4; + io->mod->whichmodel = GTR; + io->mod->s_opt->opt_rr = YES; + } + else if(strcmp(s, "DAYHOFF") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = DAYHOFF; + } + else if(strcmp(s, "JTT") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = JTT; + } + else if(strcmp(s, "MTREV") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = MTREV; + } + else if(strcmp(s, "LG") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = LG; + } + else if(strcmp(s, "WAG") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = WAG; + } + else if(strcmp(s, "DCMUT") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = DCMUT; + } + else if(strcmp(s, "RTREV") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = RTREV; + } + else if(strcmp(s, "CPREV") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = CPREV; + } + else if(strcmp(s, "VT") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = VT; + } + else if(strcmp(s, "BLOSUM62") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = BLOSUM62; + } + else if(strcmp(s, "MTMAM") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = MTMAM; + } + else if (strcmp(s,"MTART") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = MTART; + } + else if (strcmp(s,"HIVW") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = HIVW; + } + else if(strcmp(s, "HIVB") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = HIVB; + } + else if(strcmp(s, "AB") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = AB; + } + else if (strcmp(s, "CUSTOM") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = CUSTOMAA; + } + else if(strcmp(s, "FLU") == 0) + { + io->datatype = AA; + io->mod->ns = 20; + io->mod->whichmodel = FLU; + } + else + { + PhyML_Printf("\n. The model name is incorrect. Please see the documentation.\n"); + Exit("\n"); + } + Free(s); + } + + + Set_Model_Name(io->mod); - case 'm': case 5 : - { - if(!isalpha(optarg[0])) - { - strcpy(io->mod->custom_mod_string,optarg); - - if(strlen(io->mod->custom_mod_string) != 6) - { - Warn_And_Exit("\n. The string should be of length 6.\n"); - } - else - { - Translate_Custom_Mod_String(io->mod); - } - - io->mod->datatype = NT; - io->mod->whichmodel = CUSTOM; - strcpy(io->mod->modelname, "custom"); - io->mod->s_opt->opt_kappa = 0; - io->mod->s_opt->opt_rr = 1; - io->mod->s_opt->opt_num_param = 1; - } - - if (strcmp(optarg, "JC69") == 0) - { - io->mod->datatype = NT; - io->mod->whichmodel = JC69; - strcpy(io->mod->modelname, "JC69"); - io->mod->s_opt->opt_kappa = 0; - } - else if(strcmp(optarg, "K80") == 0) - { - io->mod->datatype = NT; - io->mod->whichmodel = K80; - strcpy(io->mod->modelname, "K80"); - } - else if(strcmp(optarg, "F81") == 0) - { - io->mod->datatype = NT; - io->mod->whichmodel = F81; - strcpy(io->mod->modelname, "F81"); - io->mod->s_opt->opt_kappa = 0; - } - else if (strcmp(optarg, "HKY85") == 0) - { - io->mod->datatype = NT; - io->mod->whichmodel = HKY85; - strcpy(io->mod->modelname, "HKY85"); - } - else if(strcmp(optarg, "F84") == 0) - { - io->mod->datatype = NT; - io->mod->whichmodel = F84; - strcpy(io->mod->modelname, "F84"); - } - else if (strcmp (optarg,"TN93") == 0) - { - io->mod->datatype = NT; - io->mod->whichmodel = TN93; - strcpy(io->mod->modelname, "TN93"); - if(io->mod->s_opt->opt_kappa) - { - io->mod->s_opt->opt_lambda = 1; - } - } - else if(strcmp (optarg, "GTR") == 0) - { - io->mod->datatype = NT; - io->mod->whichmodel = GTR; - strcpy(io->mod->modelname, "GTR"); - io->mod->s_opt->opt_kappa = 0; - } - else if(strcmp(optarg, "Dayhoff") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = DAYHOFF; - strcpy(io->mod->modelname, "Dayhoff"); - } - else if(strcmp (optarg, "JTT") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = JTT; - strcpy(io->mod->modelname, "JTT"); - } - else if(strcmp(optarg, "MtREV") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = MTREV; - strcpy(io->mod->modelname,"MtREV"); - } - else if(strcmp (optarg, "LG") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = LG; - strcpy(io->mod->modelname, "LG"); - } - else if(strcmp (optarg, "WAG") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = WAG; - strcpy(io->mod->modelname, "WAG"); - } - else if(strcmp(optarg, "DCMut") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = DCMUT; - strcpy(io->mod->modelname, "DCMut"); - } - else if(strcmp (optarg, "RtREV") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = RTREV; - strcpy(io->mod->modelname, "RtREV"); - } - else if(strcmp(optarg, "CpREV") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = CPREV; - strcpy(io->mod->modelname, "CpREV"); - } - else if(strcmp(optarg, "VT") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = VT; - strcpy(io->mod->modelname, "VT"); - } - else if(strcmp(optarg, "Blosum62") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = BLOSUM62; - strcpy(io->mod->modelname,"Blosum62"); - } - else if(strcmp(optarg, "MtMam") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = MTMAM; - strcpy(io->mod->modelname, "MtMam"); - } - else if (strcmp(optarg,"MtArt") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = MTART; - strcpy(io->mod->modelname, "MtArt"); - } - else if (strcmp(optarg,"HIVw") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = HIVW; - strcpy(io->mod->modelname, "HIVw"); - } - else if(strcmp(optarg, "HIVb") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = HIVB; - strcpy(io->mod->modelname, "HIVb"); - } - else if (strcmp(optarg, "custom") == 0) - { - io->mod->datatype = AA; - io->mod->whichmodel = CUSTOMAA; - strcpy(io->mod->modelname, "Read from file"); - } - break; - } - - case 'a':case 14 : - { - use_gamma = 1; - if ((strcmp (optarg, "e") == 0) || - (strcmp (optarg, "E") == 0) || - (strcmp (optarg, "estimated") == 0) || - (strcmp (optarg, "ESTIMATED") == 0)) - { - io->mod->s_opt->opt_alpha = 1; - io->mod->s_opt->opt_num_param = 1; - } - else if ((!atof(optarg)) || (atof(optarg) < .0)) - { - char choix; - printf("\n. Alpha must be a positive number\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - else - { - io->mod->alpha = (phydbl)atof(optarg); - io->mod->s_opt->opt_alpha = 0; - } - break; - } - case 'b':case 10: - { - if (atoi(optarg) < -4) + break; + } + + case 'a':case 14 : + { + if ((strcmp (optarg, "e") == 0) || + (strcmp (optarg, "E") == 0) || + (strcmp (optarg, "estimated") == 0) || + (strcmp (optarg, "ESTIMATED") == 0)) + { + io->mod->s_opt->opt_alpha = YES; + } + else if (atof(optarg) < 1.E-10) + { + char choix; + PhyML_Printf("\n. Alpha must be > 1.E-10.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else + { + io->mod->ras->alpha->v = (phydbl)atof(optarg); + io->mod->s_opt->opt_alpha = NO; + } + break; + } + case 'b':case 10: + { + if ((int)String_To_Dbl(optarg) < -5) { char choix; - printf("\n. Branch test value must be a positive integer for bootstrap, or between -1 and -4 for aLRT branch test\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); + PhyML_Printf("\n. Branch test value must be a positive integer for bootstrap, or between -1 and -4 for aLRT branch test\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); Exit("\n"); } else { - if((int)atoi(optarg) > 0) + if((int)String_To_Dbl(optarg) > 0) { - io->ratio_test = 0; - io->mod->bootstrap = (int)atoi(optarg); - io->print_boot_trees = 1; - + io->do_alrt = NO; + io->ratio_test = 0; + io->n_boot_replicates = (int)atoi(optarg); + io->print_boot_trees = 1; + if(io->n_data_sets > 1) { char choix; - printf("\n. Bootstrap option is not allowed with multiple data sets\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); + PhyML_Printf("\n. Bootstrap option is not allowed with multiple data sets\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); Exit("\n"); } } else if (atoi(optarg)==0) { - io->mod->bootstrap = 0; - io->ratio_test = 0; + io->do_alrt = NO; + io->do_tbe = NO; + io->do_boot = NO; + io->ratio_test = 0; } else { - io->mod->bootstrap = 0; - io->ratio_test = -(int)atoi(optarg); + io->do_alrt = YES; + io->do_tbe = NO; + io->do_boot = NO; + io->ratio_test = -(int)atoi(optarg); + } + } + break; + } + case 'c':case 12: + { + if ((!atoi(optarg)) || (atoi(optarg) < 0)) + { + char choix; + PhyML_Printf("\n. Unknown argument to -c option: the number of rate categories must be a positive integer\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else + { + io->mod->ras->n_catg = atoi(optarg); + if(io->mod->ras->n_catg < 1) + { + PhyML_Printf("\n. The number of rate categories must be a positive integer\n"); + Exit("\n"); } } break; } - case 'c':case 12: - { - if ((!atoi(optarg)) || (atoi(optarg) < 0)) - { - char choix; - printf("\n. Unknown argument to -c option: the number of categories must be a positive integer\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - else io->mod->n_catg = atoi(optarg); - break; - } case 'f': { if(!strcmp(optarg,"e")) { - io->mod->s_opt->opt_state_freq = 1; - - if((io->mod->whichmodel == JC69) || - (io->mod->whichmodel == K80)) + if(io->datatype == NT) + io->mod->s_opt->opt_state_freq = NO; + else if (io->datatype == AA) + io->mod->s_opt->opt_state_freq = YES; + else { - char choix; - printf("\n. Invalid model settings (option '-f').\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); + PhyML_Printf("\n. Please define the data type (nt or aa) before setting the -f option\n"); Exit("\n"); } } - else if(!strcmp(optarg,"d")) + else if(!strcmp(optarg,"m")) { - io->mod->s_opt->opt_state_freq = 0; + if (io->datatype == NT) + io->mod->s_opt->opt_state_freq = YES; + else if (io->datatype == AA) + io->mod->s_opt->opt_state_freq = NO; + else + { + PhyML_Printf("\n. Please define the data type (nt or aa) before setting the -f option\n"); + Exit("\n"); + } } else if(!isalpha(optarg[0])) { phydbl sum; + double val1,val2,val3,val4; + + io->mod->e_frq = (t_efrq *)Make_Efrq(4); + Init_Efrq(NULL,io->mod->e_frq); - io->mod->s_opt->opt_state_freq = 0; - io->mod->s_opt->user_state_freq = 1; + io->mod->s_opt->opt_state_freq = NO; + io->mod->e_frq->user_state_freq = YES; + + sscanf(optarg,"%lf,%lf,%lf,%lf",&val1,&val2,&val3,&val4); + io->mod->e_frq->user_b_freq->v[0] = (phydbl)val1; + io->mod->e_frq->user_b_freq->v[1] = (phydbl)val2; + io->mod->e_frq->user_b_freq->v[2] = (phydbl)val3; + io->mod->e_frq->user_b_freq->v[3] = (phydbl)val4; sum = - (io->mod->user_b_freq[0] + - io->mod->user_b_freq[1] + - io->mod->user_b_freq[2] + - io->mod->user_b_freq[3]); - - io->mod->user_b_freq[0] /= sum; - io->mod->user_b_freq[1] /= sum; - io->mod->user_b_freq[2] /= sum; - io->mod->user_b_freq[3] /= sum; - - if(io->mod->user_b_freq[0] < .0 || - io->mod->user_b_freq[1] < .0 || - io->mod->user_b_freq[2] < .0 || - io->mod->user_b_freq[3] < .0 || - io->mod->user_b_freq[0] > 1. || - io->mod->user_b_freq[1] > 1. || - io->mod->user_b_freq[2] > 1. || - io->mod->user_b_freq[3] > 1.) + (io->mod->e_frq->user_b_freq->v[0] + + io->mod->e_frq->user_b_freq->v[1] + + io->mod->e_frq->user_b_freq->v[2] + + io->mod->e_frq->user_b_freq->v[3]); + + io->mod->e_frq->user_b_freq->v[0] /= sum; + io->mod->e_frq->user_b_freq->v[1] /= sum; + io->mod->e_frq->user_b_freq->v[2] /= sum; + io->mod->e_frq->user_b_freq->v[3] /= sum; + + + if(io->mod->e_frq->user_b_freq->v[0] < .0 || + io->mod->e_frq->user_b_freq->v[1] < .0 || + io->mod->e_frq->user_b_freq->v[2] < .0 || + io->mod->e_frq->user_b_freq->v[3] < .0 || + io->mod->e_frq->user_b_freq->v[0] > 1. || + io->mod->e_frq->user_b_freq->v[1] > 1. || + io->mod->e_frq->user_b_freq->v[2] > 1. || + io->mod->e_frq->user_b_freq->v[3] > 1.) { Warn_And_Exit("\n. Invalid base frequencies.\n"); } @@ -667,194 +1228,236 @@ void Read_Command_Line(option *io, int argc, char **argv) break; } - case 'h': + case 'h':case 69: { Usage(); break; } - - case 'i':case 9: - { - char *tmp; - tmp = (char *) mCalloc (T_MAX_FILE, sizeof(char)); - if (strlen (optarg) > T_MAX_FILE -16) - { - char choix; - strcpy (tmp, "\n. The file name'"); - strcat (tmp, optarg); - strcat (tmp, "' is too long.\n"); - printf("%s",tmp); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - else if (!Filexists (optarg)) - { - char choix; - strcpy (tmp, "\n. The file '"); - strcat (tmp, optarg); - strcat (tmp, "' does not exist.\n"); - printf("%s",tmp); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - else - { - strcpy(io->in_seq_file, optarg); - io->fp_in_seq = Openfile(io->in_seq_file,0); - strcpy(io->out_tree_file,optarg); + case 'i':case 9: + { + char *tmp; + tmp = (char *) mCalloc (T_MAX_FILE, sizeof(char)); + if (strlen (optarg) > T_MAX_FILE -16) + { + char choix; + strcpy (tmp, "\n. The file name'"); + strcat (tmp, optarg); + strcat (tmp, "' is too long.\n"); + PhyML_Printf("%s",tmp); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + + else if (!Filexists (optarg)) + { + char choix; + strcpy (tmp, "\n. The file '"); + strcat (tmp, optarg); + strcat (tmp, "' does not exist.\n"); + PhyML_Printf("%s",tmp); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else + { + strcpy(io->in_align_file, optarg); + io->fp_in_align = Openfile(io->in_align_file,0); + + strcpy(io->out_file, optarg); + strcpy(io->out_tree_file,optarg); #ifdef PHYML - strcat(io->out_tree_file,"_phyml_tree.txt"); -#else - strcat(io->out_tree_file,"_mc_tree.txt"); + strcat(io->out_tree_file,"_phyml_tree"); +#elif M4 + strcat(io->out_tree_file,"_m4_tree"); +#elif PHYREX + strcat(io->out_tree_file,"_phyrex_tree"); #endif - io->fp_out_tree = Openfile(io->out_tree_file,1); - strcpy(io->out_stats_file,optarg); + + strcpy(io->out_stats_file,optarg); #ifdef PHYML - strcat(io->out_stats_file,"_phyml_stats.txt"); -#else - strcat(io->out_stats_file,"_mc_stats.txt"); + strcat(io->out_stats_file,"_phyml_stats"); +#elif M4 + strcat(io->out_stats_file,"_m4_stats"); +#elif PHYREX + strcat(io->out_stats_file,"_phyrex_stats"); +#endif + + +#ifdef PHYREX + strcpy(io->out_summary_file,optarg); + strcat(io->out_summary_file,"_phyrex_summary"); #endif - io->fp_out_stats = Openfile(io->out_stats_file,1); - } - Free (tmp); - break; - } + + + } + Free (tmp); + break; + } + + case 't':case 11: + { + if ((io->mod->whichmodel != JC69) && (io->mod->whichmodel != F81) && (io->mod->whichmodel != GTR)) + { + if ((strcmp(optarg, "e") == 0) || + (strcmp(optarg, "E") == 0) || + (strcmp(optarg, "estimated") == 0) || + (strcmp(optarg, "ESTIMATED") == 0)) + { + io->mod->kappa->v = 4.0; + io->mod->s_opt->opt_kappa = YES; + if (io->mod->whichmodel == TN93) + io->mod->s_opt->opt_lambda = YES; + } + else + { + io->mod->s_opt->opt_kappa = NO; + io->mod->s_opt->opt_lambda = NO; + + + // Added the 2 TsTv ratios for TN93 + // lambda is the ratio of both TsTv ratios + // kappa is the mean of both TsTv ratios + if (io->mod->whichmodel == TN93) + { + double TsTvPur, TsTvPyr; + TsTvPur = TsTvPyr = -1.; + if(!isalpha(optarg[0])) + { + sscanf(optarg,"%lf,%lf",&TsTvPur,&TsTvPyr); + } + else + { + PhyML_Fprintf(stderr,"\n. The TN93 model requires two Ts/Tv ratios.\n"); + Exit("\n"); + } + if ( (TsTvPur < .0) || (TsTvPyr < .0) ) + { + PhyML_Fprintf(stderr,"\n. The Ts/Tv ratio must be a positive number.\n"); + Exit("\n"); + } + io->mod->lambda->v = (phydbl)(TsTvPur / TsTvPyr); + io->mod->kappa->v = (phydbl)((TsTvPur + TsTvPyr)/2.); + } + else + { + // -- End TN93 rates for purines & pyrimidines + if (atof(optarg) < .0) + { + char choix; + PhyML_Printf("\n. The Ts/Tv ratio must be a positive number\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else + { + io->mod->kappa->v = (phydbl)atof(optarg); + } + } + } + } + break; + } + case 'n':case 8: + { + if ((!atoi(optarg)) || (atoi(optarg) < 0)) + { + char choix; + PhyML_Printf("\n. The number of alignments must be a positive integer\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else io->n_data_sets = atoi (optarg); + break; + } + case 'q':case 22: + { + io->interleaved = NO; + break; + } + case 'u':case 15: + { + char *tmp; + tmp = (char *)mCalloc(T_MAX_FILE, sizeof(char)); + if(strlen(optarg) > T_MAX_FILE -11) + { + char choix; + strcpy (tmp, "\n. The file name'"); + strcat (tmp, optarg); + strcat (tmp, "' is too long.\n"); + PhyML_Printf("%s",tmp); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else if (! Filexists (optarg)) + { + char choix; + strcpy (tmp, "\n. The file '"); + strcat (tmp, optarg); + strcat (tmp, "' doesn't exist.\n"); + PhyML_Printf("%s",tmp); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else + { + strcpy(io->in_tree_file, optarg); + io->in_tree = 2; + io->fp_in_tree = Openfile(io->in_tree_file,READ); + } + Free(tmp); + break; + } - case 't':case 11: - { - if ((io->mod->whichmodel != JC69) && - (io->mod->whichmodel != F81) && - (io->mod->whichmodel != GTR)) - { - if ((strcmp(optarg, "e") == 0) || - (strcmp(optarg, "E") == 0) || - (strcmp(optarg, "estimated") == 0) || - (strcmp(optarg, "ESTIMATED") == 0)) - { - io->mod->kappa = 4.0; - io->mod->s_opt->opt_num_param = 1; - io->mod->s_opt->opt_kappa = 1; - if (io->mod->whichmodel == TN93) - io->mod->s_opt->opt_lambda = 1; - } - else - { - if ((!atof(optarg)) || (atof(optarg) < .0)) - { - char choix; - printf("\n. The ts/tv ratio must be a positive number\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - else - { - io->mod->kappa = (phydbl)atof(optarg); - io->mod->s_opt->opt_kappa = 0; - io->mod->s_opt->opt_lambda = 0; - } - } - } - break; - } - case 'n':case 8: - { - if ((!atoi(optarg)) || (atoi(optarg) < 0)) - { - char choix; - printf("\n. The number of alignments must be a positive integer\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - else io->n_data_sets = atoi (optarg); - break; - } - case 'q':case 22: - { - io->interleaved = 0; - break; - } - case 'u':case 15: - { - char *tmp; - tmp = (char *)mCalloc(T_MAX_FILE, sizeof(char)); - if (strlen (optarg) > T_MAX_FILE -11) - { - char choix; - strcpy (tmp, "\n. The file name'"); - strcat (tmp, optarg); - strcat (tmp, "' is too long.\n"); - printf("%s",tmp); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - else if (! Filexists (optarg)) - { - char choix; - strcpy (tmp, "\n. The file '"); - strcat (tmp, optarg); - strcat (tmp, "' doesn't exist.\n"); - printf("%s",tmp); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - else - { - strcpy(io->in_tree_file, optarg); - io->in_tree = 1; - io->fp_in_tree = Openfile(io->in_tree_file,0); - } - Free(tmp); - break; - } - - case 'v':case 13: - { - if ((strcmp (optarg, "e") == 0) || - (strcmp (optarg, "E") == 0) || - (strcmp (optarg, "estimated") == 0) || - (strcmp (optarg, "ESTIMATED") == 0)) { - io->mod->s_opt->opt_num_param = 1; - io->mod->s_opt->opt_pinvar = 1; - io->mod->pinvar = 0.2; - io->mod->invar = 1; - } - else if ((atof(optarg) < 0.0) || (atof(optarg) > 1.0)) - { - char choix; - printf("\n. The proportion of invariable site must be a number between 0.0 and 1.0\n"); - printf("\n. Type any key to exit."); - scanf("%c",&choix); - Exit("\n"); - } - else - { - io->mod->pinvar = (phydbl)atof(optarg); - if (io->mod->pinvar > 0.0+MDBL_MIN) - io->mod->invar = 1; - else - io->mod->invar = 0; - io->mod->s_opt->opt_pinvar = 0; - } - break; - } + case 'v':case 13: + { + if ((strcmp (optarg, "e") == 0) || + (strcmp (optarg, "E") == 0) || + (strcmp (optarg, "estimated") == 0) || + (strcmp (optarg, "ESTIMATED") == 0)) + { + io->mod->s_opt->opt_pinvar = YES; + io->mod->ras->invar = YES; + } + + else if ((atof(optarg) < 0.0) || (atof(optarg) > 1.0)) + { + char choix; + PhyML_Printf("\n. The proportion of invariable site must be a number between 0.0 and 1.0\n"); + PhyML_Printf("\n. Type any key to exit."); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + else + { + io->mod->ras->pinvar->v = (phydbl)atof(optarg); + if (io->mod->ras->pinvar->v > 0.0+SMALL) + io->mod->ras->invar = 1; + else + io->mod->ras->invar = 0; + io->mod->s_opt->opt_pinvar = 0; + } + break; + } case 'o': { if(!strcmp(optarg,"tlr")) { - io->mod->s_opt->opt_topo = 1; - io->mod->s_opt->opt_bl = 1; + io->mod->s_opt->opt_topo = YES; + io->mod->s_opt->opt_bl = YES; + io->mod->s_opt->opt_subst_param = YES; } else if(!strcmp(optarg,"tl")) { - io->mod->s_opt->opt_topo = 1; - io->mod->s_opt->opt_bl = 1; + io->mod->s_opt->opt_topo = YES; + io->mod->s_opt->opt_bl = YES; + io->mod->s_opt->opt_subst_param = NO; } else if(!strcmp(optarg,"t")) { @@ -862,145 +1465,261 @@ void Read_Command_Line(option *io, int argc, char **argv) } else if(!strcmp(optarg,"lr")) { - io->mod->s_opt->opt_topo = 0; - io->mod->s_opt->opt_bl = 1; + io->mod->s_opt->opt_topo = NO; + io->mod->s_opt->opt_bl = YES; + io->mod->s_opt->opt_subst_param = YES; } else if(!strcmp(optarg,"l")) { - io->mod->s_opt->opt_topo = 0; - io->mod->s_opt->opt_bl = 1; + io->mod->s_opt->opt_topo = NO; + io->mod->s_opt->opt_bl = YES; + io->mod->s_opt->opt_subst_param = NO; } else if(!strcmp(optarg,"r")) { - io->mod->s_opt->opt_topo = 0; - io->mod->s_opt->opt_bl = 0; + io->mod->s_opt->opt_topo = NO; + io->mod->s_opt->opt_bl = NO; + io->mod->s_opt->opt_subst_param = YES; } else if(!strcmp(optarg,"none") || !strcmp(optarg,"n")) { - io->mod->s_opt->opt_topo = 0; - io->mod->s_opt->opt_bl = 0; + io->mod->s_opt->opt_topo = NO; + io->mod->s_opt->opt_bl = NO; + io->mod->s_opt->opt_subst_param = NO; } else { char choix; - printf ("\n. The optimization parameter must be 'tlr' or 'tl' or 'lr' or 'l' or 'r' or ''."); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); + PhyML_Printf ("\n. The optimization parameter must be 'tlr' or 'tl' or 'lr' or 'l' or 'r' or 'n'."); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); Exit("\n"); } break; } + case '?': - { - char choix; - if (isprint (optopt)) - printf ("\n. Unknown option `-%c'.\n", optopt); - else - printf ("\n. Unknown option character `\\x%x'.\n", optopt); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); + { + Exit("\n"); break; } + case -1: + { + break; + } + default: - Usage(); - } -} - - - if(io->print_site_lnl) - { - strcpy(io->out_lk_file,io->in_seq_file); - strcat(io->out_lk_file, "_phyml_lk.txt"); - io->fp_out_lk = Openfile(io->out_lk_file,1); - } - - if(io->print_trace) - { - strcpy(io->out_trace_file,io->in_seq_file); - strcat(io->out_trace_file,"_phyml_trace.txt"); - io->fp_out_trace = Openfile(io->out_trace_file,1); - } - - if(io->mod->s_opt->random_input_tree) - { - strcpy(io->out_best_tree_file,io->in_seq_file); - strcat(io->out_best_tree_file,"_phyml_best_tree.txt"); - } - - if((io->print_boot_trees) && (io->mod->bootstrap > 0)) - { - strcpy(io->out_boot_tree_file,io->in_seq_file); - strcat(io->out_boot_tree_file,"_phyml_boot_trees.txt"); - io->fp_out_boot_tree = Openfile(io->out_boot_tree_file,1); - - strcpy(io->out_boot_stats_file,io->in_seq_file); - strcat(io->out_boot_stats_file,"_phyml_boot_stats.txt"); - io->fp_out_boot_stats = Openfile(io->out_boot_stats_file,1); - } + { + Usage(); + break; + } + } + }while(c != -1); + + /* if((io->mod->whichmodel == K80) || (io->mod->whichmodel == JC69)) */ + /* { */ + /* if(io->mod->s_opt->opt_state_freq) */ + /* { */ + /* char c; */ + /* PhyML_Printf("\n. WARNING: nucleotide frequencies must be set to 1/4 with this model.\n"); */ + /* PhyML_Printf("\n. Type the enter key to resume the analysis.\n"); */ + /* scanf("%c",&c); */ + /* } */ + /* io->mod->s_opt->opt_state_freq = 0; */ + /* } */ + + + if(io->mod->s_opt->constrained_br_len == YES) + { + io->mod->s_opt->opt_topo = NO; + /* io->mod->s_opt->opt_bl = NO; */ + } + + + if(io->do_tbe == YES) + { + io->do_alrt = NO; + io->do_boot = NO; + } + else + { + if(io->do_alrt == NO && io->n_boot_replicates > 0) io->do_boot = YES; + } + #ifndef PHYML - if((open_ps_file) || (io->m4_model == YES)) - { - strcpy(io->out_ps_file,io->in_seq_file); - strcat(io->out_ps_file, "_mc_tree.ps"); - io->fp_out_ps = Openfile(io->out_ps_file,1); - } + if((open_ps_file) || (io->m4_model == YES)) + { + strcpy(io->out_ps_file,io->in_align_file); + strcat(io->out_ps_file, "_mc_tree.ps"); + io->fp_out_ps = Openfile(io->out_ps_file,WRITE); + } #endif + + + if(io->datatype == UNDEFINED) io->datatype = NT; + + if ((io->datatype == NT) && (io->mod->whichmodel > 10)) + { + char choix; + PhyML_Printf("\n. Err.: model incompatible with the data type. Please use JC69, K80, F81, HKY, F84, TN93 or GTR\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Warn_And_Exit("\n"); + } + else if ((io->datatype == AA) && (io->mod->whichmodel < 11)) + { + char choix; + PhyML_Printf("\n. Err.: model incompatible with the data type. Please use LG, Dayhoff, JTT, MtREV, WAG, DCMut, RtREV, CpREV, VT, Blosum62, MtMam, MtArt, HIVw, HIVb or AB.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + + if(io->mod->use_m4mod == NO) + { + io->mod->s_opt->opt_cov_delta = 0; + io->mod->s_opt->opt_cov_alpha = 0; + io->mod->s_opt->opt_cov_free_rates = 0; + } + + if((io->mod->s_opt->opt_cov_free_rates) && (io->mod->s_opt->opt_cov_alpha)) + { + io->mod->s_opt->opt_cov_free_rates = 1; +#ifdef M4 + io->mod->m4mod->use_cov_alpha = 0; + io->mod->m4mod->use_cov_free = 1; +#endif + } + + if(io->print_site_lnl && io->fp_in_align != NULL) + { + strcpy(io->out_lk_file,io->in_align_file); + strcat(io->out_lk_file, "_phyml_lk"); + if(io->append_run_ID) { strcat(io->out_lk_file,"_"); strcat(io->out_lk_file,io->run_id_string); } + strcat(io->out_lk_file, ".txt"); + io->fp_out_lk = Openfile(io->out_lk_file,1); + } + + if(io->print_trace && io->fp_in_align != NULL) + { + strcpy(io->out_trace_file,io->in_align_file); + strcat(io->out_trace_file,"_phyml_trace"); + if(io->append_run_ID) { strcat(io->out_trace_file,"_"); strcat(io->out_trace_file,io->run_id_string); } + strcat(io->out_trace_file,".txt"); + io->fp_out_trace = Openfile(io->out_trace_file,WRITE); + } + + if(io->print_json_trace && io->fp_in_align != NULL) + { + strcpy(io->out_json_trace_file,io->in_align_file); + strcat(io->out_json_trace_file,"_phyml_trace"); + if(io->append_run_ID) { strcat(io->out_json_trace_file,"_"); strcat(io->out_json_trace_file,io->run_id_string); } + strcat(io->out_json_trace_file,".json"); + io->fp_out_json_trace = Openfile(io->out_json_trace_file,READWRITE); + } + + if(io->mod->s_opt->random_input_tree && io->fp_in_align != NULL) + { + strcpy(io->out_trees_file,io->in_align_file); + strcat(io->out_trees_file,"_phyml_rand_trees"); + if(io->append_run_ID) { strcat(io->out_trees_file,"_"); strcat(io->out_trees_file,io->run_id_string); } + strcat(io->out_trees_file,".txt"); + io->fp_out_trees = Openfile(io->out_trees_file,1); + } + + if((io->print_boot_trees) && (io->do_boot == YES) && (io->fp_in_align != NULL)) + { + strcpy(io->out_boot_tree_file,io->in_align_file); + strcat(io->out_boot_tree_file,"_phyml_boot_trees"); + if(io->append_run_ID) { strcat(io->out_boot_tree_file,"_"); strcat(io->out_boot_tree_file,io->run_id_string); } + strcat(io->out_boot_tree_file,".txt"); + io->fp_out_boot_tree = Openfile(io->out_boot_tree_file,1); + + strcpy(io->out_boot_stats_file,io->in_align_file); + strcat(io->out_boot_stats_file,"_phyml_boot_stats"); + if(io->append_run_ID) { strcat(io->out_boot_stats_file,"_"); strcat(io->out_boot_stats_file,io->run_id_string); } + strcat(io->out_boot_stats_file,".txt"); + io->fp_out_boot_stats = Openfile(io->out_boot_stats_file,1); + } + + if(io->append_run_ID && io->fp_in_align != NULL) + { + strcat(io->out_tree_file,"_"); + strcat(io->out_stats_file,"_"); + strcat(io->out_tree_file,io->run_id_string); + strcat(io->out_stats_file,io->run_id_string); + } + + if(io->fp_in_align != NULL) + { + strcat(io->out_tree_file,".txt"); + strcat(io->out_stats_file,".txt"); + } + + +#ifdef PHYREX + strcat(io->out_summary_file,".txt"); +#endif - if((use_gamma) && (io->mod->n_catg == 1)) - { - io->mod->n_catg = 4; - } - - if((io->mod->s_opt->n_rand_starts) && - (io->mod->s_opt->topo_search != SPR_MOVE) && - (io->mod->s_opt->random_input_tree)) - { - Warn_And_Exit("\n. Random starting tree option is only compatible with a full-SPR search.\n"); - } - - if ((io->mod->datatype == NT) && (io->mod->whichmodel > 10)) - { - char choix; - printf("\n. Err: model incompatible with the data type. Please use JC69, K80, F81, HKY, F84, TN93 or GTR\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Warn_And_Exit("\n"); - } - else if ((io->mod->datatype == AA) && (io->mod->whichmodel < 11)) - { - char choix; - printf("\n. Err: model incompatible with the data type. Please use LG, Dayhoff, JTT, MtREV, WAG, DCMut, RtREV, CpREV, VT, Blosum62, MtMam, MtArt, HIVw or HIVb.\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); - Exit("\n"); - } - - if(io->m4_model == YES) - { - io->mod->ns *= io->mod->m4mod->n_h; - io->mod->use_m4mod = 1; - M4_Make_Complete(io->mod->m4mod->n_h, - io->mod->m4mod->n_o, - io->mod->m4mod); - } - else - { - io->mod->s_opt->opt_cov_delta = 0; - io->mod->s_opt->opt_cov_alpha = 0; - io->mod->s_opt->opt_cov_free_rates = 0; - } - - if((io->mod->s_opt->opt_cov_free_rates) && (io->mod->s_opt->opt_cov_alpha)) - { - io->mod->s_opt->opt_cov_free_rates = 0; - io->mod->m4mod->use_cov_alpha = 0; - io->mod->m4mod->use_cov_free = 1; - } - - return; + + if(io->mod->ras->n_catg == 1) io->mod->s_opt->opt_alpha = 0; + + if(io->mod->s_opt->opt_subst_param == NO) + { + io->mod->s_opt->opt_alpha = NO; + io->mod->s_opt->opt_kappa = NO; + io->mod->s_opt->opt_lambda = NO; + io->mod->s_opt->opt_pinvar = NO; + io->mod->s_opt->opt_rr = NO; + } + + if(io->mod->whichmodel != K80 && + io->mod->whichmodel != HKY85 && + io->mod->whichmodel != F84 && + io->mod->whichmodel != TN93) + { + io->mod->s_opt->opt_kappa = NO; + } + + if(io->datatype == AA && io->mod->whichmodel == CUSTOMAA && !io->mod->fp_aa_rate_mat) + { + PhyML_Printf("\n. Custom model option with amino-acid requires you to specify a rate matrix file through the '--aa_rate_file' option.\n"); + Exit("\n"); + } + +#if !defined(PHYTIME) + // Make sure you don't erase the input file... + if(!strcmp(io->out_tree_file,io->in_align_file) || + !strcmp(io->out_stats_file,io->in_align_file)) + { + PhyML_Fprintf(stderr,"\n. The alignment file '%s' does not seem to exist...",io->in_align_file); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + if(io->fp_in_align != NULL) + { + io->fp_out_tree = Openfile(io->out_tree_file,writemode); + io->fp_out_stats = Openfile(io->out_stats_file,writemode); + } +#endif + +#if defined(PHYREX) + if(io->fp_in_align != NULL) io->fp_out_summary = Openfile(io->out_summary_file,writemode); +#endif + + + if(io->quiet == NO) + { + PhyML_Printf("\n\n. Command line: "); + for(i=0;i #ifndef CL_H #define CL_H -void Read_Command_Line(option *input, int argc, char **argv); +#include +#include +#include "utilities.h" +#include "help.h" +#include "models.h" +#include "free.h" +#include "interface.h" +#include "invitee.h" +#include "date.h" + + +int Read_Command_Line(option *input, int argc, char **argv); #endif diff --git a/phyml/date.c b/phyml/date.c new file mode 100644 index 0000000..e989dbc --- /dev/null +++ b/phyml/date.c @@ -0,0 +1,1408 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + + +/* Routines for molecular dating */ + + +#include "date.h" + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int DATE_Main(int argc, char **argv) +{ + option *io; + + io = Get_Input(argc,argv); + Free(io); + return(0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void DATE_XML(char *xml_filename) +{ + FILE *fp_xml_in; + xml_node *xnd,*xroot; + t_tree *mixt_tree,*tree; + phydbl *res; + int seed; + char *dum_string; + + mixt_tree = XML_Process_Base(xml_filename); + assert(mixt_tree); + + mixt_tree->rates = RATES_Make_Rate_Struct(mixt_tree->n_otu); + RATES_Init_Rate_Struct(mixt_tree->rates,NULL,mixt_tree->n_otu); + + tree = mixt_tree; + do + { + // All rate stuctures point to the same object + tree->rates = mixt_tree->rates; + tree = tree->next; + } + while(tree); + + + fp_xml_in = fopen(xml_filename,"r"); + if(!fp_xml_in) + { + PhyML_Fprintf(stderr,"\n. Could not find the XML file '%s'.\n",xml_filename); + Exit("\n"); + } + + /* xroot = XML_Load_File(fp_xml_in); */ + xroot = mixt_tree->xml_root; + + if(xroot == NULL) + { + PhyML_Fprintf(stderr,"\n. Encountered an issue while loading the XML file.\n"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + xnd = XML_Search_Node_Name("phytime",NO,xroot); + + if(xnd == NULL) + { + PhyML_Fprintf(stderr,"\n. Cound not find the \"root\" of the XML file (it should have \'phytime\' as tag name).\n"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + dum_string = XML_Get_Attribute_Value(xnd,"mcmc.chain.len"); + if(dum_string != NULL) mixt_tree->io->mcmc->chain_len = (int)String_To_Dbl(dum_string); + + dum_string = XML_Get_Attribute_Value(xnd,"mcmc.sample.every"); + if(dum_string != NULL) mixt_tree->io->mcmc->sample_interval = (int)String_To_Dbl(dum_string); + + dum_string = XML_Get_Attribute_Value(xnd,"mcmc.print.every"); + if(dum_string != NULL) mixt_tree->io->mcmc->print_every = (int)String_To_Dbl(dum_string); + + dum_string = XML_Get_Attribute_Value(xnd,"mcmc.burnin"); + if(dum_string != NULL) mixt_tree->io->mcmc->chain_len_burnin = (int)String_To_Dbl(dum_string); + + + dum_string = XML_Get_Attribute_Value(xnd,"ignore.sequences"); + if(dum_string != NULL) mixt_tree->eval_alnL = NO; + + dum_string = XML_Get_Attribute_Value(xnd,"ignore.seq"); + if(dum_string != NULL) mixt_tree->eval_alnL = NO; + + dum_string = XML_Get_Attribute_Value(xnd,"ignore.data"); + if(dum_string != NULL) mixt_tree->eval_alnL = NO; + + + dum_string = XML_Get_Attribute_Value(xnd,"mutmap"); + if(dum_string != NULL) + { + int select = XML_Validate_Attr_Int(dum_string,6, + "true","yes","y", + "false","no","n"); + if(select < 3) mixt_tree->io->mutmap = YES; + else mixt_tree->io->mutmap = NO; + } + + + + + // Looking for XML node with rate-across-lineage info + xnd = XML_Search_Node_Name("lineagerates",YES,xroot); + + + if(xnd == NULL) + { + PhyML_Fprintf(stdout,"\n. The model of rate variation across lineages is not specified."); + PhyML_Fprintf(stdout,"\n. Using the geometric Brownian model (see Guindon, 2012, Syst. Biol.).\n"); + mixt_tree->rates->model = GUINDON; + mixt_tree->mod->gamma_mgf_bl = YES; + strcpy(mixt_tree->rates->model_name,"geometric Brownian"); + } + else + { + char *model_name; + model_name = XML_Get_Attribute_Value(xnd,"model"); + + if(model_name == NULL) + { + PhyML_Fprintf(stderr,"\n. Please specify a model of rate variation across lineages,"); + PhyML_Fprintf(stderr,"\n. e.g., ."); + PhyML_Fprintf(stderr,"\n. See the manual for more options."); + assert(FALSE); + } + else + { + if(!strcmp(model_name,"geometricbrownian")) + { + mixt_tree->rates->model = GUINDON; + mixt_tree->mod->gamma_mgf_bl = YES; + strcpy(mixt_tree->rates->model_name,"geometric Brownian"); + } + else if(!strcmp(model_name,"geometric")) + { + mixt_tree->rates->model = GUINDON; + mixt_tree->mod->gamma_mgf_bl = YES; + strcpy(mixt_tree->rates->model_name,"geometric Brownian"); + } + else if(!strcmp(model_name,"brownian")) + { + mixt_tree->rates->model = GUINDON; + mixt_tree->mod->gamma_mgf_bl = YES; + strcpy(mixt_tree->rates->model_name,"geometric Brownian"); + } + else if(!strcmp(model_name,"geo")) + { + mixt_tree->rates->model = GUINDON; + mixt_tree->mod->gamma_mgf_bl = YES; + strcpy(mixt_tree->rates->model_name,"geometric Brownian"); + } + else if(!strcmp(model_name,"lognormal")) + { + mixt_tree->rates->model = LOGNORMAL; + mixt_tree->mod->gamma_mgf_bl = NO; + strcpy(mixt_tree->rates->model_name,"lognormal (uncorrelated)"); + } + else if(!strcmp(model_name,"normal")) + { + mixt_tree->rates->model = LOGNORMAL; + mixt_tree->mod->gamma_mgf_bl = NO; + strcpy(mixt_tree->rates->model_name,"lognormal (uncorrelated)"); + } + else if(!strcmp(model_name,"strictclock")) + { + mixt_tree->rates->model = STRICTCLOCK; + mixt_tree->mod->gamma_mgf_bl = NO; + strcpy(mixt_tree->rates->model_name,"strict clock"); + } + else if(!strcmp(model_name,"clock")) + { + mixt_tree->rates->model = STRICTCLOCK; + mixt_tree->mod->gamma_mgf_bl = NO; + strcpy(mixt_tree->rates->model_name,"strict clock"); + } + else + { + assert(FALSE); + } + } + } + + + // Looking for calibration info + xnd = XML_Search_Node_Name("calibration",YES,xroot); + + if(xnd == NULL) + { + PhyML_Fprintf(stderr,"\n. No calibration information seems to be provided."); + PhyML_Fprintf(stderr,"\n. Please amend your XML file. \n"); + assert(FALSE); + } + else + { + assert(xnd->child); + if(XML_Search_Node_Name("upper",NO,xnd->child) == NULL && XML_Search_Node_Name("lower",NO,xnd->child) == NULL) + { + PhyML_Fprintf(stderr,"\n. There is no calibration information provided. \n"); + PhyML_Fprintf(stderr,"\n. Please check your data. \n"); + assert(FALSE); + } + } + + + + /* MIXT_Check_Model_Validity(mixt_tree); */ + /* MIXT_Init_Model(mixt_tree); */ + /* Print_Data_Structure(NO,stdout,mixt_tree); */ + /* tree = MIXT_Starting_Tree(mixt_tree); */ + /* Copy_Tree(tree,mixt_tree); */ + /* Free_Tree(tree); */ + /* MIXT_Connect_Cseqs_To_Nodes(mixt_tree); */ + /* MIXT_Init_T_Beg(mixt_tree); */ + /* MIXT_Chain_Edges(mixt_tree); */ + /* MIXT_Chain_Nodes(mixt_tree); */ + /* MIXT_Make_Tree_For_Pars(mixt_tree); */ + /* MIXT_Make_Tree_For_Lk(mixt_tree); */ + /* MIXT_Make_Spr(mixt_tree); */ + /* MIXT_Chain_All(mixt_tree); */ + /* Add_Root(mixt_tree->a_edges[0],mixt_tree); */ + /* MIXT_Check_Edge_Lens_In_All_Elem(mixt_tree); */ + /* MIXT_Turn_Branches_OnOff_In_All_Elem(ON,mixt_tree); */ + /* MIXT_Check_Invar_Struct_In_Each_Partition_Elem(mixt_tree); */ + /* MIXT_Check_RAS_Struct_In_Each_Partition_Elem(mixt_tree); */ + + /* XML_Read_Calibration(xroot,mixt_tree); */ + + /* MIXT_Chain_Cal(mixt_tree); */ + + seed = (mixt_tree->io->r_seed < 0)?(time(NULL)):(mixt_tree->io->r_seed); + srand(seed); + mixt_tree->io->r_seed = seed; + + + MIXT_Check_Model_Validity(mixt_tree); + MIXT_Init_Model(mixt_tree); + Print_Data_Structure(NO,stdout,mixt_tree); + tree = MIXT_Starting_Tree(mixt_tree); + Add_Root(tree->a_edges[0],tree); + Copy_Tree(tree,mixt_tree); + Free_Tree(tree); + MIXT_Connect_Cseqs_To_Nodes(mixt_tree); + MIXT_Init_T_Beg(mixt_tree); + MIXT_Make_Tree_For_Lk(mixt_tree); + MIXT_Make_Tree_For_Pars(mixt_tree); + MIXT_Make_Spr(mixt_tree); + MIXT_Chain_All(mixt_tree); + MIXT_Check_Edge_Lens_In_All_Elem(mixt_tree); + MIXT_Turn_Branches_OnOff_In_All_Elem(ON,mixt_tree); + MIXT_Check_Invar_Struct_In_Each_Partition_Elem(mixt_tree); + MIXT_Check_RAS_Struct_In_Each_Partition_Elem(mixt_tree); + + XML_Read_Calibration(xroot,mixt_tree); + MIXT_Chain_Cal(mixt_tree); + + res = DATE_MCMC(mixt_tree); + + + // Cleaning up... + RATES_Free_Rates(mixt_tree->rates); + RATES_Free_Rates(mixt_tree->extra_tree->rates); + MCMC_Free_MCMC(mixt_tree->mcmc); + MCMC_Free_MCMC(mixt_tree->extra_tree->mcmc); + Free_Mmod(mixt_tree->mmod); + Free_Spr_List_One_Edge(mixt_tree); + Free_Tree_Pars(mixt_tree); + Free_Tree_Lk(mixt_tree); + + if(mixt_tree->io->fp_out_trees) fclose(mixt_tree->io->fp_out_trees); + if(mixt_tree->io->fp_out_tree) fclose(mixt_tree->io->fp_out_tree); + if(mixt_tree->io->fp_out_stats) fclose(mixt_tree->io->fp_out_stats); + if(mixt_tree->io->fp_out_json_trace) fclose(mixt_tree->io->fp_out_json_trace); + Free_Input(mixt_tree->io); + + + tree = mixt_tree; + do + { + Free_Calign(tree->data); + tree = tree->next_mixt; + } + while(tree); + + tree = mixt_tree; + do + { + Free_Optimiz(tree->mod->s_opt); + tree = tree->next; + } + while(tree); + + + Free_Model_Complete(mixt_tree->mod); + Free_Model_Basic(mixt_tree->mod); + Free_Tree(mixt_tree->extra_tree); + Free_Tree(mixt_tree); + Free(res); + XML_Free_XML_Tree(xroot); + fclose(fp_xml_in); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Update t_prior_min and t_prior_max on a given ranked tree +// given (primary and secondary) calibration information. +// Make sure secondary and primary calibration are up-to-date +void DATE_Update_T_Prior_MinMax(t_tree *tree) +{ + int i,j; + + + for(i=0;i<2*tree->n_otu-1;++i) // All nodes + { + tree->rates->t_prior_max[i] = +INFINITY; + tree->rates->t_prior_min[i] = -INFINITY; + + if(tree->a_nodes[i]->n_cal > 0) // Primary calibration found on that node + { + for(j=0;ja_nodes[i]->n_cal;++j) + { + tree->rates->t_prior_max[i] = MIN(tree->rates->t_prior_max[i],tree->a_nodes[i]->cal[j]->upper); + tree->rates->t_prior_min[i] = MAX(tree->rates->t_prior_min[i],tree->a_nodes[i]->cal[j]->lower); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void DATE_Assign_Primary_Calibration(t_tree *tree) +{ + int i,j,idx,node_num; + t_clad *clade; + t_cal *cal; + + clade = NULL; + cal = NULL; + + for(i=0;irates->n_cal;++i) + { + cal = tree->rates->a_cal[i]; + if(cal->clade_list != NULL) + { + clade = cal->clade_list[cal->current_clade_idx]; + clade->target_nd = NULL; + } + } + + for(i=0;i<2*tree->n_otu-1;++i) + for(j=0;ja_nodes[i]->cal[j] = NULL; + tree->a_nodes[i]->n_cal = 0; + } + + for(i=0;irates->n_cal;++i) + { + cal = tree->rates->a_cal[i]; + + if(cal->clade_list != NULL) + { + clade = cal->clade_list[cal->current_clade_idx]; + + node_num = Find_Clade(clade->tax_list, + clade->n_tax, + tree); + + clade->target_nd = tree->a_nodes[node_num]; + + idx = tree->a_nodes[node_num]->n_cal; + tree->a_nodes[node_num]->cal[idx] = tree->rates->a_cal[i]; + tree->a_nodes[node_num]->n_cal++; + + + if(tree->a_nodes[node_num]->n_cal == MAX_N_CAL) + { + PhyML_Fprintf(stderr,"\n. A node cannot have more than %d calibration",MAX_N_CAL); + PhyML_Fprintf(stderr,"\n. constraints attached to it. Feel free to increase the"); + PhyML_Fprintf(stderr,"\n. value of the variable MAX_N_CAL in utilities.h if"); + PhyML_Fprintf(stderr,"\n. necessary."); + Exit("\n"); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Return splitted calibration intervals. Make sure all primary +// and secondary calibration intervals are up-to-date. +phydbl *DATE_Splitted_Calibration(t_tree *tree) +{ + phydbl *minmax,*splitted_cal,buff; + int i,len,done; + + // One t_prior_min and one t_prior_max per internal nodes except root, so + // 2 x # of internal nodes boundaries in total at most. + minmax = (phydbl *)mCalloc(2*(tree->n_otu-2),sizeof(phydbl)); + For(i,2*(tree->n_otu-2)) minmax[i] = +INFINITY; + splitted_cal = (phydbl *)mCalloc((int)(4*tree->n_otu-10),sizeof(phydbl)); + + + len = 0; + for(i = tree->n_otu; i < 2*tree->n_otu-1; i++) + { + if(tree->a_nodes[i] != tree->n_root) + { + minmax[len] = MAX(tree->rates->t_prior_min[i],tree->rates->nd_t[tree->n_root->num]); + minmax[len+1] = tree->rates->t_prior_max[i]; + len+=2; + } + } + + + // Bubble sort of all these times in increasing order + do + { + done = YES; + for(i=0;i minmax[i+1]) + { + buff = minmax[i]; + minmax[i] = minmax[i+1]; + minmax[i+1] = buff; + done = NO; + } + } + } + while(done == NO); + + for(i=0;i minmax[i+1])); + + // Remove ties + for(i=0;i minmax[i+1]) + { + buff = minmax[i]; + minmax[i] = minmax[i+1]; + minmax[i+1] = buff; + done = NO; + } + } + } + while(done == NO); + + splitted_cal[0] = minmax[0]; + len = 1; + for(i = 1; i < 2*(tree->n_otu-2); i++) + { + splitted_cal[len] = minmax[i]; + if(len+1 < 4*tree->n_otu-10) splitted_cal[len+1] = minmax[i]; + len+=2; + } + + /* For(i,4*tree->n_otu-10) PhyML_Printf("\n. split -- %3d %12f",i,splitted_cal[i]); */ + + Free(minmax); + + return splitted_cal; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl DATE_J_Sum_Product(t_tree *tree) +{ + phydbl prod, total,*splitted_cal; + int fact,idx,ans,rk; + + DATE_Assign_Primary_Calibration(tree); + DATE_Update_T_Prior_MinMax(tree); + + splitted_cal = DATE_Splitted_Calibration(tree); + + ans = 0; + total = 0.0; + idx = 0; + rk = 1; + do + { + prod = 1.0; + fact = 1; + ans = DATE_J_Sum_Product_Pre(tree->a_nodes[tree->rates->t_rank[rk]], // Oldest node after root (as rk=1) + idx, + -1, + prod,fact,&total,splitted_cal,rk,tree); + idx+=2; + } + while(ans != 1); + + Free(splitted_cal); + + return(total); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int DATE_J_Sum_Product_Pre(t_node *d, int split_idx_d, int split_idx_a, phydbl prod, int fact, phydbl *total, phydbl *splitted_cal, int rk, t_tree *tree) +{ + int ans,idx; + + ans = DATE_Is_Split_Accessible(d,split_idx_d,splitted_cal,tree); + + switch(ans) + { + case 1 : // split interval is younger than t_prior_max. No need to go further. + { + return ans; + break; + } + case 0 : // split interval is within [t_prior_min,t_prior_max] + { + int local_ans; + + // Calculate J for this time interval + prod *= DATE_J(tree->rates->birth_rate, + tree->rates->death_rate, + FABS(splitted_cal[split_idx_d+1]), + FABS(splitted_cal[split_idx_d])); + + // Remove factorial term from current product + prod *= fact; + + if(split_idx_d == split_idx_a) fact++; + else fact = 1; + + prod /= fact; + + if(tree->rates->t_rank[tree->n_otu-2] == d->num) // Youngest internal node + { + (*total) += prod; + return 0; + } + + idx = split_idx_d; + do + { + local_ans = DATE_J_Sum_Product_Pre(tree->a_nodes[tree->rates->t_rank[rk+1]], + idx, + split_idx_d, + prod,fact,total,splitted_cal,rk+1,tree); + idx+=2; + } + while(local_ans == 0); + + break; + } + case -1 : // split interval is older than t_prior_min. Move forward. + { + int local_ans; + // Advance to younger split intervals and stop once you're in + idx = split_idx_d+2; + do + { + local_ans = DATE_J_Sum_Product_Pre(d, + idx, + idx+1, + prod,fact,total,splitted_cal,rk,tree); + idx+=2; + } + while(local_ans == -1); + break; + } + } + + return ans; +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int DATE_Is_Split_Accessible(t_node *d, int which, phydbl *splitted_cal, t_tree *tree) +{ + phydbl eps; + + assert(d->tax == NO); + + eps = FABS(tree->rates->t_prior_min[d->num]) / 1.E+6; + + assert(eps > MDBL_MIN); + + // Upper and lower bound of splitted calibration interval are equal to zero + if(Are_Equal(splitted_cal[which],0.0,eps) && Are_Equal(splitted_cal[which+1],0.0,eps)) return +1; + + + if(Are_Equal(tree->rates->t_prior_min[d->num],splitted_cal[which],eps) || + Are_Equal(tree->rates->t_prior_max[d->num],splitted_cal[which+1],eps) || + (tree->rates->t_prior_min[d->num] < splitted_cal[which] && + tree->rates->t_prior_max[d->num] > splitted_cal[which+1])) return 0; // splitted interval is within [t_prior_min,t_prior_max] + else if(Are_Equal(tree->rates->t_prior_max[d->num],splitted_cal[which],eps) || + splitted_cal[which] > tree->rates->t_prior_max[d->num]) return +1; // splitted interval is younger than [t_prior_min,t_prior_max] + else if(Are_Equal(tree->rates->t_prior_min[d->num],splitted_cal[which+1],eps) || + splitted_cal[which+1] < tree->rates->t_prior_min[d->num]) return -1; // splitted interval is older than [t_prior_min,t_prior_max] + else + { + PhyML_Printf("\n. d->num: %d d->tax: %d",d->num,d->tax); + PhyML_Printf("\n. t_prior_min: %f t_prior_max: %f", + tree->rates->t_prior_min[d->num], + tree->rates->t_prior_max[d->num]); + PhyML_Printf("\n. splitted_cal_min: %f splitted_cal_max: %f", + splitted_cal[which], + splitted_cal[which+1]); + PhyML_Printf("\n"); + assert(FALSE); // splitted interval cannot be partially overlapping [t_prior_min,t_prior_max] + } + return(0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl DATE_J(phydbl birth_r, phydbl death_r, phydbl t_min, phydbl t_pls) +{ + phydbl d,b,J; + assert(t_pls > t_min); + d = death_r; + b = birth_r; + J = (b-d)*(exp(t_min*d+t_pls*b) - exp(t_min*b+t_pls*d)); + J /= ((b*exp(t_min*b)-d*exp(t_min*d)) * (b*exp(t_pls*b)-d*exp(t_pls*d))); + /* printf(" J : %f",J); */ + return(J); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int DATE_Check_Calibration_Constraints(t_tree *tree) +{ + int i,j; + phydbl lower,upper; + + lower = upper = -1.; + + For(i,2*tree->n_otu-1) + { + if(tree->a_nodes[i]->n_cal > 1) + { + lower = tree->a_nodes[i]->cal[0]->lower; + upper = tree->a_nodes[i]->cal[0]->upper; + for(j=1; j < tree->a_nodes[i]->n_cal; j++) + { + lower = MAX(lower,tree->a_nodes[i]->cal[j]->lower); + upper = MIN(upper,tree->a_nodes[i]->cal[j]->upper); + if(upper < lower) + { + /* PhyML_Printf("\n. Inconsistency detected on node %d",i); */ + return 0; + } + } + } + } + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Check that time constraints are satisfied. Note: it is a +// requirement to verify that the age of the root node is also +// within correct boundaries +int DATE_Check_Time_Constraints(t_tree *tree) +{ + for(int i=0;i<2*tree->n_otu-1;++i) + { + if(tree->a_nodes[i]->tax == NO) + { + if(tree->rates->nd_t[i] > tree->rates->t_prior_max[i] || + tree->rates->nd_t[i] < tree->rates->t_prior_min[i]) + { + /* PhyML_Printf("\n!!! Node %d t: %f min:%f max:%f", */ + /* i, */ + /* tree->rates->nd_t[i], */ + /* tree->rates->t_prior_min[i], */ + /* tree->rates->t_prior_max[i]); */ + return 0; + } + } + } + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl *DATE_MCMC(t_tree *tree) +{ + t_mcmc *mcmc; + char *s_tree; + int move, n_vars, i, j, adjust_len; + phydbl u; + phydbl *res; + FILE *fp_stats,*fp_tree; + int t_beg; + + t_beg = (int)time(NULL); + + fp_stats = tree->io->fp_out_stats; + fp_tree = tree->io->fp_out_tree; + + if(tree->io->mutmap == YES) Make_MutMap(tree); + + TIMES_Randomize_Tree_With_Time_Constraints(tree->rates->a_cal[0],tree); + MIXT_Propagate_Tree_Update(tree); + + + mcmc = MCMC_Make_MCMC_Struct(); + tree->mcmc = mcmc; + MCMC_Init_MCMC_Struct(NULL,NULL,mcmc); + MCMC_Complete_MCMC(mcmc,tree); + + MCMC_Randomize_Birth(tree); + MCMC_Randomize_Death(tree); + MCMC_Randomize_Clock_Rate(tree); + MCMC_Randomize_Rate_Across_Sites(tree); + MCMC_Randomize_Rates(tree); + + + n_vars = 10; + adjust_len = tree->io->mcmc->chain_len_burnin; + mcmc->sample_interval = tree->io->mcmc->sample_interval; + mcmc->print_every = tree->io->mcmc->print_every; + mcmc->chain_len = tree->io->mcmc->chain_len; + mcmc->chain_len_burnin = tree->io->mcmc->chain_len_burnin; + tree->rates->bl_from_rt = YES; + + res = (phydbl *)mCalloc(tree->mcmc->chain_len / tree->mcmc->sample_interval * n_vars,sizeof(phydbl)); + + Set_Both_Sides(YES,tree); + Set_Update_Eigen(YES,tree->mod); + Lk(NULL,tree); + Set_Update_Eigen(NO,tree->mod); + + + RATES_Lk_Rates(tree); + DATE_Assign_Primary_Calibration(tree); + TIMES_Lk_Times(NO,tree); + + /* Time_To_Branch(tree); */ + /* tree->bl_ndigits = 1; */ + /* printf("\n. Random init tree: %s",Write_Tree(tree)); */ + /* tree->bl_ndigits = 7; */ + RATES_Update_Cur_Bl(tree); + + + PhyML_Printf("\n. AVX enabled: %s", +#if defined(__AVX__) + "yes" +#else + "no" +#endif + ); + PhyML_Printf("\n. SSE enabled: %s", +#if defined(__SSE3__) + "yes" +#else + "no" +#endif + ); + + PhyML_Printf("\n\n. Seed: %d",tree->io->r_seed); + PhyML_Printf("\n. Ignore sequences: %s",tree->eval_alnL == YES ? "no" : "yes"); + PhyML_Printf("\n. Model of variation of rates across lineages: %s",tree->rates->model_name); + PhyML_Printf("\n. log(Pr(Seq|Tree)) = %f",tree->c_lnL); + PhyML_Printf("\n. log(Pr(Tree)) = %f",tree->rates->c_lnL_times); + + + tree->extra_tree = Make_Tree_From_Scratch(tree->n_otu,tree->data); + tree->extra_tree->mod = tree->mod; + Copy_Tree(tree,tree->extra_tree); + tree->extra_tree->rates = RATES_Make_Rate_Struct(tree->n_otu); + RATES_Init_Rate_Struct(tree->extra_tree->rates,NULL,tree->n_otu); + RATES_Copy_Rate_Struct(tree->rates,tree->extra_tree->rates,tree->n_otu); + tree->extra_tree->rates->model = LOGNORMAL; + RATES_Duplicate_Calib_Struct(tree,tree->extra_tree); + MIXT_Chain_Cal(tree->extra_tree); + DATE_Assign_Primary_Calibration(tree->extra_tree); + TIMES_Randomize_Tree_With_Time_Constraints(tree->extra_tree->rates->a_cal[0],tree->extra_tree); + + + TIMES_Lk_Times(NO,tree->extra_tree); + PhyML_Printf("\n. log(Pr(extra tree)) = %f",tree->extra_tree->rates->c_lnL_times); + mcmc = MCMC_Make_MCMC_Struct(); + tree->extra_tree->mcmc = mcmc; + MCMC_Init_MCMC_Struct(NULL,NULL,mcmc); + MCMC_Complete_MCMC(mcmc,tree->extra_tree); + + PhyML_Fprintf(fp_stats,"\n%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t", + "sample", + "lnL(posterior)", + "lnL(seq)", + "lnL(times)", + "lnL(rates)", + "birth", + "death", + "clock", + "root", + "tstv", + "nu"); + for(i=0;imod->ras->n_catg;i++) PhyML_Fprintf(fp_stats,"rr%d\t",i); + for(i=0;imod->ras->n_catg;i++) PhyML_Fprintf(fp_stats,"pr%d\t",i); + + + for(i=0;irates->n_cal;++i) + { + t_cal *cal = tree->rates->a_cal[i]; + for(j=0;jclade_list_size;++j) + { + t_clad *clade = cal->clade_list[j]; + PhyML_Fprintf(fp_stats,"t(calib:%s_clade:%s)\t",cal->id,clade->id); + } + } + + for(i=0;irates->n_cal;++i) + { + t_cal *cal = tree->rates->a_cal[i]; + PhyML_Fprintf(fp_stats,"clade(calib:%s)\t",cal->id); + } + + + if(tree->rates->model == THORNE || + tree->rates->model == LOGNORMAL || + tree->rates->model == STRICTCLOCK) + for(i=0;i<2*tree->n_otu-2;++i) PhyML_Fprintf(fp_stats,"br%d\t",i); + else + for(i=0;i<2*tree->n_otu-1;++i) PhyML_Fprintf(fp_stats,"nr%d\t",i); + + for(i=0;i<2*tree->n_otu-1;++i) if(tree->a_nodes[i]->tax == NO) PhyML_Fprintf(fp_stats,"t%d\t",i); + + PhyML_Fprintf(fp_stats,"accRT\t"); + PhyML_Fprintf(fp_stats,"tuneRT\t"); + + PhyML_Fprintf(fp_stats,"accT\t"); + PhyML_Fprintf(fp_stats,"tuneT\t"); + + PhyML_Fprintf(fp_stats,"accClock\t"); + PhyML_Fprintf(fp_stats,"tuneClock\t"); + + PhyML_Fprintf(fp_stats,"accTCr\t"); + PhyML_Fprintf(fp_stats,"tuneTCr\t"); + + PhyML_Fprintf(fp_stats,"accTreeRates\t"); + PhyML_Fprintf(fp_stats,"tuneTreeRates\t"); + + PhyML_Fprintf(fp_stats,"accSprW\t"); + PhyML_Fprintf(fp_stats,"tuneSprW\t"); + + PhyML_Fprintf(fp_stats,"accSpr\t"); + PhyML_Fprintf(fp_stats,"tuneSpr\t"); + + PhyML_Fprintf(fp_stats,"accSprLoc\t"); + PhyML_Fprintf(fp_stats,"tuneSprLoc\t"); + + fflush(NULL); + + PhyML_Printf("\n\n"); + PhyML_Printf("\n. MCMC settings. Chain length: %g steps.",(phydbl)tree->mcmc->chain_len); + PhyML_Printf("\n. MCMC settings. Burnin: %g steps.",(phydbl)tree->mcmc->chain_len_burnin); + PhyML_Printf("\n. MCMC settings. Sample every %g steps.",(phydbl)tree->mcmc->sample_interval); + PhyML_Printf("\n. MCMC settings. Print out every %g steps.",(phydbl)tree->mcmc->print_every); + PhyML_Printf("\n\n"); + + + for(i=0;imcmc->n_moves;i++) tree->mcmc->start_ess[i] = YES; + Set_Both_Sides(NO,tree); + tree->mcmc->always_yes = NO; + move = -1; + + // Get in the range of sensible values for clock_r + i = 0; + do { MCMC_Clock_R(tree); } while(i++ < 100); + + do + { + if(tree->mcmc->run > adjust_len) for(i=0;imcmc->n_moves;i++) tree->mcmc->adjust_tuning[i] = NO; + + if(tree->c_lnL < UNLIKELY + 0.1 && tree->eval_alnL == YES) + { + PhyML_Printf("\n. Move '%s' failed\n",tree->mcmc->move_name[move]); + assert(FALSE); + } + + u = Uni(); + for(move=0;movemcmc->n_moves;move++) if(tree->mcmc->move_weight[move] > u-1.E-10) break; + + assert(!(move == tree->mcmc->n_moves)); + + if(!strcmp(tree->mcmc->move_name[move],"clock")) MCMC_Clock_R(tree); + else if(!strcmp(tree->mcmc->move_name[move],"birth_rate")) MCMC_Birth_Rate(tree); + else if(!strcmp(tree->mcmc->move_name[move],"death_rate")) MCMC_Death_Rate(tree); + else if(!strcmp(tree->mcmc->move_name[move],"birth_death_updown")) MCMC_Birth_Death_Updown(tree); + else if(!strcmp(tree->mcmc->move_name[move],"tree_height")) MCMC_Tree_Height(tree); + else if(!strcmp(tree->mcmc->move_name[move],"times")) MCMC_Times_All(tree); + else if(!strcmp(tree->mcmc->move_name[move],"times_and_rates")) MCMC_Times_And_Rates_All(tree); + + else if(!strcmp(tree->mcmc->move_name[move],"spr")) MCMC_Prune_Regraft(tree); + else if(!strcmp(tree->mcmc->move_name[move],"spr_local")) MCMC_Prune_Regraft_Local(tree); + else if(!strcmp(tree->mcmc->move_name[move],"spr_weighted")) MCMC_Prune_Regraft_Weighted(tree); + + else if(!strcmp(tree->mcmc->move_name[move],"updown_t_cr")) MCMC_Updown_T_Cr(tree); + else if(!strcmp(tree->mcmc->move_name[move],"kappa")) MCMC_Kappa(tree); + else if(!strcmp(tree->mcmc->move_name[move],"ras")) MCMC_Rate_Across_Sites(tree); + else if(!strcmp(tree->mcmc->move_name[move],"nu")) MCMC_Nu(tree); + else if(!strcmp(tree->mcmc->move_name[move],"subtree_height")) MCMC_Subtree_Height(tree); + else if(!strcmp(tree->mcmc->move_name[move],"time_slice")) MCMC_Time_Slice(tree); + else if(!strcmp(tree->mcmc->move_name[move],"br_rate")) MCMC_Rates_All(tree); + else if(!strcmp(tree->mcmc->move_name[move],"tree_rates")) MCMC_Tree_Rates(tree); + else if(!strcmp(tree->mcmc->move_name[move],"clade_change")) MCMC_Clade_Change(tree); + else continue; + + + phydbl cur_lk = tree->c_lnL; + phydbl new_lk = Lk(NULL,tree); + if(Are_Equal(cur_lk,new_lk,1.E-5) == NO) + { + PhyML_Printf("\n. move: %s",tree->mcmc->move_name[move]); + PhyML_Printf("\n. new: %f cur: %f",new_lk,cur_lk); + assert(FALSE); + } + + + if(!RATES_Check_Edge_Length_Consistency(tree)) + { + PhyML_Fprintf(stderr,"\n. Issue detected by RATES_Check_Edge_Length_Consistency(tree)."); + PhyML_Fprintf(stderr,"\n. Move: %s",tree->mcmc->move_name[move]); + if(tree->eval_alnL == YES) assert(FALSE); + } + + if(!TIMES_Check_Node_Height_Ordering(tree)) + { + PhyML_Fprintf(stderr,"\n. Issue detected by TIMES_Check_Node_Height_Ordering(tree)."); + PhyML_Fprintf(stderr,"\n. Move: %s",tree->mcmc->move_name[move]); + assert(FALSE); + } + + + if(!(tree->rates->c_lnL_times > UNLIKELY)) + { + PhyML_Fprintf(stderr,"\n. move: %s",tree->mcmc->move_name[move]); + PhyML_Fprintf(stderr,"\n. glnL=%f",tree->rates->c_lnL_times); + assert(FALSE); + } + + (void)signal(SIGINT,MCMC_Terminate); + + if(!(tree->mcmc->run%tree->mcmc->print_every)) + { + phydbl mean_r,post; + + mean_r = RATES_Average_Substitution_Rate(tree); + post = Get_Lk(tree) + tree->rates->c_lnL_times + tree->rates->c_lnL_rates; + + if(tree->mcmc->run < adjust_len) PhyML_Printf("\nx"); + else PhyML_Printf("\n."); + PhyML_Printf(" %10d lnL: [%12.2f -- %12.2f -- %12.2f -- %12.2f] root age: %12f [time: %7d sec] clock: %15f %20s", + tree->mcmc->run, + post, + Get_Lk(tree), + tree->rates->c_lnL_times, + tree->rates->c_lnL_rates, + fabs(tree->rates->nd_t[tree->n_root->num]), + (int)time(NULL) - t_beg, + mean_r, + tree->mcmc->move_name[move]); + } + + if(!(tree->mcmc->run%tree->mcmc->sample_interval)) + { + phydbl mean_r,post; + + mean_r = RATES_Average_Substitution_Rate(tree); + post = Get_Lk(tree) + tree->rates->c_lnL_times + tree->rates->c_lnL_rates; + + PhyML_Fprintf(fp_stats,"\n%6d\t%9.1f\t%9.1f\t%9.1f\t%9.1f\t%12G\t%12G\t%12G\t%12G\t%12G\t%12G\t", + tree->mcmc->run, + post, + Get_Lk(tree), + tree->rates->c_lnL_times, + tree->rates->c_lnL_rates, + tree->rates->birth_rate, + tree->rates->death_rate, + mean_r, + fabs(tree->rates->nd_t[tree->n_root->num]), + tree->next->mod->kappa->v, + tree->rates->nu); + + for(i=0;imod->ras->n_catg;i++) PhyML_Fprintf(fp_stats,"%G\t",tree->mod->ras->gamma_rr->v[i]); + for(i=0;imod->ras->n_catg;i++) PhyML_Fprintf(fp_stats,"%G\t",tree->mod->ras->gamma_r_proba->v[i]); + + + for(i=0;irates->n_cal;i++) + { + t_cal *cal = tree->rates->a_cal[i]; + for(j=0;jclade_list_size;++j) + { + t_clad *clade = cal->clade_list[j]; + PhyML_Fprintf(fp_stats,"%G\t",fabs(tree->rates->nd_t[clade->target_nd->num])); + } + } + + for(i=0;irates->n_cal;++i) + { + t_cal *cal = tree->rates->a_cal[i]; + PhyML_Fprintf(fp_stats,"%d\t",cal->current_clade_idx); + /* PhyML_Fprintf(fp_stats,"%s\t",cal->clade_list[cal->current_clade_idx]->id); */ + } + + if(tree->rates->model == THORNE || + tree->rates->model == LOGNORMAL || + tree->rates->model == STRICTCLOCK) + for(i=0;i<2*tree->n_otu-2;++i) PhyML_Fprintf(fp_stats,"%G\t",tree->rates->br_r[i]); + else + for(i=0;i<2*tree->n_otu-1;++i) PhyML_Fprintf(fp_stats,"%G\t",tree->rates->nd_r[i]); + + for(i=0;i<2*tree->n_otu-1;++i) if(tree->a_nodes[i]->tax == NO) PhyML_Fprintf(fp_stats,"%G\t",fabs(tree->rates->nd_t[i])); + + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->acc_rate[tree->mcmc->num_move_times_and_rates_root]); + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->tune_move[tree->mcmc->num_move_times_and_rates_root]); + + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->acc_rate[tree->mcmc->num_move_root_time]); + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->tune_move[tree->mcmc->num_move_root_time]); + + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->acc_rate[tree->mcmc->num_move_clock_r]); + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->tune_move[tree->mcmc->num_move_clock_r]); + + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->acc_rate[tree->mcmc->num_move_updown_t_cr]); + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->tune_move[tree->mcmc->num_move_updown_t_cr]); + + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->acc_rate[tree->mcmc->num_move_tree_rates]); + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->tune_move[tree->mcmc->num_move_tree_rates]); + + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->acc_rate[tree->mcmc->num_move_spr_weighted]); + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->tune_move[tree->mcmc->num_move_spr_weighted]); + + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->acc_rate[tree->mcmc->num_move_spr]); + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->tune_move[tree->mcmc->num_move_spr]); + + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->acc_rate[tree->mcmc->num_move_spr_local]); + PhyML_Fprintf(fp_stats,"%G\t",tree->mcmc->tune_move[tree->mcmc->num_move_spr_local]); + + if(tree->mcmc->sample_num == 0) + { + PhyML_Fprintf(fp_tree,"\n#NEXUS"); + PhyML_Fprintf(fp_tree,"\nBEGIN TREES;"); + } + else + { + fseek(fp_tree,-5,SEEK_CUR); + } + + + TIMES_Time_To_Bl(tree); + tree->bl_ndigits = 3; + /* RATES_Update_Cur_Bl(tree); */ + s_tree = Write_Tree(tree); + tree->bl_ndigits = 7; + PhyML_Fprintf(fp_tree,"\ntree %d [&lnP=%f] = [&R] %s",tree->mcmc->sample_num,tree->c_lnL,s_tree); + Free(s_tree); + PhyML_Fprintf(fp_tree,"\nEND;"); + fflush(NULL); + RATES_Update_Cur_Bl(tree); + + + if(tree->mcmc->run > tree->mcmc->chain_len_burnin && + tree->io->mutmap == YES) Sample_Ancestral_Seq(YES,NO,tree); + + tree->mcmc->sample_num++; + } + + tree->mcmc->run++; + MCMC_Get_Acc_Rates(tree->mcmc); + } + while(tree->mcmc->run < tree->mcmc->chain_len); + + + return(res); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Update the list of nodes that are younger than lim +void DATE_List_Of_Nodes_Younger_Than(t_node *a, t_node *d, phydbl lim, t_ll **list, t_tree *tree) +{ + if(tree->rates->nd_t[d->num] > lim) Push_Bottom_Linked_List(d,list,YES); + + if(d->tax == YES) return; + else + { + int i; + + if(d == tree->n_root) + { + DATE_List_Of_Nodes_Younger_Than(d,d->v[1],lim,list,tree); + DATE_List_Of_Nodes_Younger_Than(d,d->v[2],lim,list,tree); + } + else + { + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + DATE_List_Of_Nodes_Younger_Than(d,d->v[i],lim,list,tree); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Update the list of nodes that are younger than lim with direct ancestors +// not younger than lim +void DATE_List_Of_Nodes_And_Ancestors_Younger_Than(t_node *a, t_node *d, phydbl lim, t_ll **list, t_tree *tree) +{ + if(tree->rates->nd_t[d->num] > lim && a != NULL && tree->rates->nd_t[a->num] > lim) Push_Bottom_Linked_List(d,list,YES); + + if(d->tax == YES) return; + else + { + int i; + + if(d == tree->n_root) + { + DATE_List_Of_Nodes_And_Ancestors_Younger_Than(d,d->v[1],lim,list,tree); + DATE_List_Of_Nodes_And_Ancestors_Younger_Than(d,d->v[2],lim,list,tree); + } + else + { + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + DATE_List_Of_Nodes_And_Ancestors_Younger_Than(d,d->v[i],lim,list,tree); + } + } +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// List of valid regraft nodes, taking into account calibration +// constraints. The subtree (defined by prune and prune_daughter +// will be re-attached *on top of* one of the nodes in this list +// (as opposed to *on one of the sister edges below*). +t_ll *DATE_List_Of_Regraft_Nodes(t_node *prune, t_node *prune_daughter, phydbl *t_min, phydbl *t_max, int verbose, t_tree *tree) +{ + t_node *n,*m; + int i,j; + t_ll *out,*in,*ll; + int is_clade_affected; + t_clad *clade; + t_cal *cal; + + cal = NULL; + clade = NULL; + n = NULL; + m = NULL; + *t_min = -INFINITY; + in = NULL; + out = NULL; + is_clade_affected = NO; + + + // Find the oldest LCA of calibrated sets among the nodes between + // prune and root. These clades might see the position of their + // LCA change. + + if(prune != tree->n_root) + { + n = prune; + while(n) + { + for(i=0;irates->n_cal;++i) + { + // That node is the LCA of calibration a_cal[i] + cal = tree->rates->a_cal[i]; + clade = cal->clade_list[cal->current_clade_idx]; + + if(n == clade->target_nd) + { + is_clade_affected = NO; + + for(j=0;jn_tax;++j) + { + m = clade->tip_list[j]; + do + { + if(m == prune_daughter) + { + is_clade_affected = YES; + break; + } + m = m->anc; + } + while(m); + + if(is_clade_affected == YES) break; + } + + + // Maximum of the lower bounds for calibration intervals + /* if(is_clade_affected == YES) *t_min = MAX(*t_min,tree->rates->a_cal[i]->lower); */ + if(is_clade_affected == YES) *t_min = MAX(*t_min,tree->rates->t_prior_min[n->num]); + } + } + n = n->anc; + } + } + + // Find the oldest internal node within intervals defined by + // calibrations affected by the pruning. + n = prune_daughter; + while(n->anc && !(tree->rates->nd_t[n->anc->num] < *t_min)) + { + n = n->anc; + assert(n); + } + + + if(verbose) + { + PhyML_Printf("\n. Apical: %d @ time %f min: %f",n->num,tree->rates->nd_t[n->num],*t_min); + fflush(NULL); + } + + // List all nodes younger than this apical node + DATE_List_Of_Nodes_Younger_Than(n->anc,n,-INFINITY,&in,tree); + + assert(in != NULL); + + if(verbose) + { + ll = in->head; + t_node *x; + do + { + x = (t_node *)ll->v; + PhyML_Printf("\nx Inlist %d @ %f",x->num,tree->rates->nd_t[x->num]); + ll = ll->next; + } + while(ll != NULL); + } + + // Remove from that list the nodes that are too young to be suitable regraft points. + + + n = prune_daughter; + out = NULL; + while(n) + { + for(i=0;irates->n_cal;i++) + { + cal = tree->rates->a_cal[i]; + clade = cal->clade_list[cal->current_clade_idx]; + + if(n->anc && n->anc == clade->target_nd) + { + for(j=0;jn_tax;++j) + { + m = clade->tip_list[j]; + do + { + if(m == prune_daughter) break; + if(m == prune) break; + m = m->anc; + } + while(m); + if(m == prune) break; // Prune-regraft anywhere below calibrated node will not change that node. + } + + if(m != prune) + { + for(j=0;j<3;++j) + { + if(n->anc->v[j] != n->anc->anc && n->anc->b[j] != tree->e_root && n->anc->v[j] != n) + { + DATE_List_Of_Nodes_And_Ancestors_Younger_Than(n->anc, + n->anc->v[j], + tree->rates->a_cal[i]->upper, + &out, + tree); + break; + } + } + } + } + } + n = n->anc; + } + + // Remove nodes that are `strictly' younger than prune_daughter + DATE_List_Of_Nodes_And_Ancestors_Younger_Than(tree->n_root,tree->n_root->v[1],tree->rates->nd_t[prune_daughter->num],&out,tree); + DATE_List_Of_Nodes_And_Ancestors_Younger_Than(tree->n_root,tree->n_root->v[2],tree->rates->nd_t[prune_daughter->num],&out,tree); + + // Remove nodes that are below prune_daughter (prune_daughter included) + DATE_List_Of_Nodes_Younger_Than(prune,prune_daughter,-INFINITY,&out,tree); + + // Add prune node to the list of node that can't be targeted for regraft + Push_Bottom_Linked_List(prune,&out,YES); + + // Add root node as one cannot regraft above it + /* Push_Bottom_Linked_List(tree->n_root,&out); */ + + if(verbose) + { + printf("\nx outlist: %p",(void *)out); fflush(NULL); + ll = out->head; + do + { + t_node *x = (t_node *)ll->v; + PhyML_Printf("\nx Outlist %d @ %f",x->num,tree->rates->nd_t[x->num]); + ll = ll->next; + } + while(ll != NULL); + } + + + /* Print_List(in); */ + ll = out->head; + do + { + if(verbose) + { + t_node *x = (t_node *)ll->v; + printf("\nx Remove %d",x->num); + } + + Remove_From_Linked_List(NULL,ll->v,&in); + + if(verbose) PhyML_Printf("\n. List in (in->head:%p in->tail:%p):",in?in->head:NULL,in?in->tail:NULL); + + /* Print_List(in); */ + ll = ll->next; + } + while(ll != NULL); + + Free_Linked_List(out); + + if(verbose) + { + ll = in->head; + do + { + t_node *x; + x = (t_node *)ll->v; + printf("\n. In1: %d",x->num); fflush(NULL); + ll = ll->next; + } + while(ll != NULL); + } + + return(in); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl DATE_Lk_Calib(t_tree *tree) +{ + phydbl lnL; + int i; + t_cal *cal; + + lnL = 0.0; + for(i=0;irates->n_cal;++i) + { + cal = tree->rates->a_cal[i]; + lnL += LOG(cal->alpha_proba_list[cal->current_clade_idx]); + } + + return lnL; +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + diff --git a/phyml/date.h b/phyml/date.h new file mode 100644 index 0000000..09a1592 --- /dev/null +++ b/phyml/date.h @@ -0,0 +1,45 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef DATE_H +#define DATE_H + +#include "utilities.h" + +int DATE_Main(int argc, char **argv); +void DATE_XML(char *xml_filename); +void DATE_Update_Secondary_Cal(t_tree *tree); +void DATE_Update_Secondary_Cal_Post(t_node *a, t_node *d, t_tree *tree); +void DATE_Update_Secondary_Cal_Pre(t_node *a, t_node *d, t_tree *tree); +phydbl *DATE_Splitted_Calibration(t_tree *tree); +void DATE_Assign_Primary_Calibration(t_tree *tree); +void DATE_Update_T_Prior_MinMax(t_tree *tree); +phydbl DATE_J(phydbl birth_r, phydbl death_r, phydbl t_min, phydbl t_pls); +int DATE_Is_Split_Accessible(t_node *d, int which, phydbl *splitted_cal, t_tree *tree); +phydbl *DATE_Splitted_Calibration(t_tree *tree); +phydbl DATE_J_Sum_Product(t_tree *tree); +int DATE_J_Sum_Product_Pre(t_node *d, int split_idx_d, int split_idx_a, phydbl prod, int fact, phydbl *total, phydbl *splitted_cal, int rk, t_tree *tree); +void DATE_Chain_Cal(t_tree *mixt_tree); +int DATE_Check_Calibration_Constraints(t_tree *tree); +int DATE_Check_Time_Constraints(t_tree *tree); +phydbl *DATE_MCMC(t_tree *tree); +void DATE_List_Of_Nodes_Younger_Than(t_node *a, t_node *d, phydbl lim, t_ll **list, t_tree *tree); +void DATE_List_Of_Nodes_And_Ancestors_Younger_Than(t_node *a, t_node *d, phydbl lim, t_ll **list, t_tree *tree); +t_ll *DATE_List_Of_Regraft_Nodes(t_node *prune, t_node *prune_daughter, phydbl *t_min, phydbl *t_max, int verbose, t_tree *tree); +phydbl DATE_Lk_Calib(t_tree *tree); + + + + +#endif diff --git a/phyml/draw.c b/phyml/draw.c index 0e4cbf1..ea0bbf4 100644 --- a/phyml/draw.c +++ b/phyml/draw.c @@ -10,293 +10,419 @@ the GNU public licence. See http://www.opensource.org for details. */ -#include "utilities.h" #include "draw.h" -/*********************************************************/ +void DR_Draw_Tree(char *file_name, t_tree *tree) +{ + FILE *ps_tree; + + ps_tree = (FILE *)fopen(file_name,"w"); + DR_Print_Postscript_Header(1,ps_tree); + tree->ps_tree = DR_Make_Tdraw_Struct(tree); + DR_Init_Tdraw_Struct(tree->ps_tree); + DR_Get_Tree_Box_Width(tree->ps_tree,tree); + Dist_To_Root(tree); + tree->ps_tree->max_dist_to_root = DR_Get_Max_Dist_To_Root(tree); + DR_Get_X_Coord(NO,tree->ps_tree,tree); + DR_Get_Y_Coord(NO,tree->ps_tree,tree); + DR_Print_Tree_Postscript(1,NO,ps_tree,tree); + DR_Print_Postscript_EOF(ps_tree); + fclose(ps_tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void DR_Get_Tree_Coord(arbre *tree) + +void DR_Get_Tree_Coord(t_tree *tree) { DR_Init_Tdraw_Struct(tree->ps_tree); DR_Get_Tree_Box_Width(tree->ps_tree,tree); if(!tree->n_root) { - printf("\n. Adding root before rendering the tree."); - Add_Root(tree->t_edges[0],tree); + PhyML_Printf("\n. Adding root before rendering the tree."); + Add_Root(tree->a_edges[0],tree); } - else Update_Root_Pos(tree); - DR_Dist_To_Root(tree->n_root,tree); + Dist_To_Root(tree); tree->ps_tree->max_dist_to_root = DR_Get_Max_Dist_To_Root(tree); - DR_Get_X_Coord(tree->ps_tree,tree); - DR_Get_Y_Coord(tree->ps_tree,tree); + DR_Get_X_Coord(NO,tree->ps_tree,tree); + DR_Get_Y_Coord(NO,tree->ps_tree,tree); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void DR_Print_Postscript_Header(int n_pages, FILE *fp) { if(!fp) { - printf("\n. Failed to open the postscript file."); - printf("\n. Did you forget the '--ps' option ?."); - Warn_And_Exit("\n"); + PhyML_Printf("\n== Failed to open the postscript file."); + PhyML_Printf("\n== Did you forget the '--ps' option ?."); + Exit("\n"); } - fprintf(fp,"%%!PS-Adobe-3.0\n"); - fprintf(fp,"%%%%DocumentFonts: Times-Roman Times-Roman\n"); - fprintf(fp,"%%%%Creator: Stephane Guindon\n"); - fprintf(fp,"%%%%Title: tree\n"); - fprintf(fp,"%%%%BeginFeature: *PageSize\n"); - fprintf(fp,"a4\n"); - fprintf(fp,"%%%%EndFeature\n"); - fprintf(fp,"%%%%EndComments\n"); - fprintf(fp,"%%%%Pages: %d\n",n_pages); - - fprintf(fp,"/lt {lineto} bind def\n"); - fprintf(fp,"/mt {moveto} bind def\n"); - fprintf(fp,"/sc {setrgbcolor} bind def\n"); - - fprintf(fp,"/clipbox\n"); - fprintf(fp,"{\n"); - fprintf(fp,"newpath\n"); - fprintf(fp,"40 40 moveto\n"); - fprintf(fp,"560 40 lineto\n"); - fprintf(fp,"560 820 lineto\n"); - fprintf(fp,"40 820 lineto\n"); - fprintf(fp,"40 40 lineto\n"); - fprintf(fp,"closepath\n"); - fprintf(fp,"clip\n"); - fprintf(fp,"} bind def\n"); + PhyML_Fprintf(fp,"%%!PS-Adobe-3.0\n"); + PhyML_Fprintf(fp,"%%%%BoundingBox: 0 0 595.28 841.89\n"); + PhyML_Fprintf(fp,"%%%%DocumentFonts: Times-Roman Times-Roman\n"); + PhyML_Fprintf(fp,"%%%%Creator: Stephane Guindon\n"); + PhyML_Fprintf(fp,"%%%%Title: tree\n"); + PhyML_Fprintf(fp,"%%%%EndComments\n"); + PhyML_Fprintf(fp,"%%%%Pages: %d\n",n_pages); + + PhyML_Fprintf(fp,"/lt {lineto} bind def\n"); + PhyML_Fprintf(fp,"/mt {moveto} bind def\n"); + PhyML_Fprintf(fp,"/sc {setrgbcolor} bind def\n"); + PhyML_Fprintf(fp,"/ct {curveto} bind def\n"); + PhyML_Fprintf(fp,"/np {newpath} bind def\n"); + PhyML_Fprintf(fp,"/cp {closepath} bind def\n"); + PhyML_Fprintf(fp,"/gs {gsave} bind def\n"); + PhyML_Fprintf(fp,"/gr {grestore} bind def\n"); - fprintf(fp,"/Times-Roman findfont\n"); - fprintf(fp,"12 scalefont\n"); - fprintf(fp,"setfont\n"); + PhyML_Fprintf(fp,"/Times-Roman findfont\n"); + PhyML_Fprintf(fp,"12 scalefont\n"); + PhyML_Fprintf(fp,"setfont\n"); + + PhyML_Fprintf(fp,"/clipbox\n"); + PhyML_Fprintf(fp,"{\n"); + PhyML_Fprintf(fp,"newpath\n"); + PhyML_Fprintf(fp,"20 20 mt\n"); + PhyML_Fprintf(fp,"580 20 lt\n"); + PhyML_Fprintf(fp,"580 820 lt\n"); + PhyML_Fprintf(fp,"20 820 lt\n"); + PhyML_Fprintf(fp,"20 20 lt\n"); + PhyML_Fprintf(fp,"closepath\n"); + PhyML_Fprintf(fp,"clip\n"); + PhyML_Fprintf(fp,"} bind def\n"); + + + /* PhyML_Fprintf(fp,"gs\n"); */ + /* PhyML_Fprintf(fp,"newpath\n"); */ + /* PhyML_Fprintf(fp,"20 20 mt\n"); */ + /* PhyML_Fprintf(fp,"580 20 lt\n"); */ + /* PhyML_Fprintf(fp,"580 820 lt\n"); */ + /* PhyML_Fprintf(fp,"20 820 lt\n"); */ + /* PhyML_Fprintf(fp,"20 20 lt\n"); */ + /* PhyML_Fprintf(fp,"closepath\n"); */ + /* PhyML_Fprintf(fp,"stroke\n"); */ + /* PhyML_Fprintf(fp,"gr\n"); */ + /* PhyML_Fprintf(fp,"0 0 0 sc\n"); */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void DR_Print_Postscript_EOF(FILE *fp) { - fprintf(fp,"%%%%Trailer\n"); - fprintf(fp,"%%%%EOF\n"); + PhyML_Fprintf(fp,"%%%%Trailer\n"); + PhyML_Fprintf(fp,"%%%%EOF\n"); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void DR_Print_Tree_Postscript(int page_num, FILE *fp, arbre *tree) + +void DR_Print_Tree_Postscript(int page_num, int render_name, FILE *fp, t_tree *tree) { - int i; tdraw *draw; - node *n_root; + t_node *n_root; draw = tree->ps_tree; - DR_Get_Tree_Coord(tree); +/* DR_Get_Tree_Coord(tree); */ n_root = tree->n_root; - fprintf(fp,"%%%%Page: %d %d\n",page_num,page_num); - fprintf(fp,"clipbox\n"); - fprintf(fp,"stroke\n"); - fprintf(fp,"50 50 translate\n"); - fprintf(fp,"newpath\n"); - -/* if(b_root->prob_sel_regime <= 0.1) */ -/* fprintf(fp,".0 .0 1. sc\n"); */ -/* else if(b_root->prob_sel_regime > 0.1 && b_root->prob_sel_regime <= 0.2) */ -/* fprintf(fp,".0 .5 1. sc\n"); */ -/* else if(b_root->prob_sel_regime > 0.2 && b_root->prob_sel_regime <= 0.3) */ -/* fprintf(fp,".0 1. 1. sc\n"); */ -/* else if(b_root->prob_sel_regime > 0.3 && b_root->prob_sel_regime <= 0.4) */ -/* fprintf(fp,".0 1. .5 sc\n"); */ -/* else if(b_root->prob_sel_regime > 0.4 && b_root->prob_sel_regime <= 0.5) */ -/* fprintf(fp,".0 1. .0 sc\n"); */ -/* else if(b_root->prob_sel_regime > 0.5 && b_root->prob_sel_regime <= 0.6) */ -/* fprintf(fp,".5 1. .0 sc\n"); */ -/* else if(b_root->prob_sel_regime > 0.6 && b_root->prob_sel_regime <= 0.7) */ -/* fprintf(fp,"1. 1. 0. sc\n"); */ -/* else if(b_root->prob_sel_regime > 0.7 && b_root->prob_sel_regime <= 0.8) */ -/* fprintf(fp,"1. .5 0. sc\n"); */ -/* else if(b_root->prob_sel_regime > 0.8 && b_root->prob_sel_regime <= 0.9) */ -/* fprintf(fp,"1. 0. 0. sc\n"); */ -/* else if(b_root->prob_sel_regime > 0.9) */ -/* fprintf(fp,"1. .0 .0 sc\n"); */ - - fprintf(fp,"%d %d mt\n",draw->xcoord[n_root->v[0]->num],draw->ycoord[n_root->v[0]->num]); - fprintf(fp,"%d %d lt\n",0,draw->ycoord[n_root->v[0]->num]); - fprintf(fp,"%d %d lt\n",0,draw->ycoord[n_root->v[1]->num]); - fprintf(fp,"%d %d lt\n",draw->xcoord[n_root->v[1]->num],draw->ycoord[n_root->v[1]->num]); - fprintf(fp,"stroke\n"); - - - fprintf(fp,"%d %d mt\n",draw->xcoord[n_root->v[0]->num],draw->ycoord[n_root->v[0]->num]); - if(n_root->v[0]->tax) fprintf(fp,"(%s) show\n",n_root->v[0]->name); - else - { - For(i,3) - if((n_root->v[0]->v[i]) && (n_root->v[0]->v[i] != n_root->v[1])) - DR_Print_Tree_Postscript_Pre(n_root->v[0],n_root->v[0]->v[i],fp,draw,tree); - } +/* PhyML_Fprintf(fp,"%%%%Page: %d %d\n",page_num,page_num); */ + /* PhyML_Fprintf(fp,"0.001 setlinewidth\n"); */ +/* PhyML_Fprintf(fp,"0.5 0.5 0.4 sc\n"); */ + /* PhyML_Fprintf(fp,"0 0 0 sc\n"); */ +/* PhyML_Fprintf(fp,"clipbox\n"); */ +/* PhyML_Fprintf(fp,"stroke\n"); */ + PhyML_Fprintf(fp,"20 20 translate\n"); + PhyML_Fprintf(fp,"newpath\n"); - fprintf(fp,"%d %d mt\n",draw->xcoord[n_root->v[1]->num],draw->ycoord[n_root->v[1]->num]); - if(n_root->v[1]->tax) fprintf(fp,"(%s) show\n",n_root->v[1]->name); - else - { - For(i,3) - if((n_root->v[1]->v[i]) && (n_root->v[1]->v[i] != n_root->v[0])) - DR_Print_Tree_Postscript_Pre(n_root->v[1],n_root->v[1]->v[i],fp,draw,tree); - } + draw->ycoord[n_root->num] = (draw->ycoord[n_root->v[2]->num] + draw->ycoord[n_root->v[1]->num])/2. + 20; + draw->xcoord[n_root->num] = 0.0; + DR_Print_Tree_Postscript_Pre(n_root,n_root->v[2],n_root->b[2],render_name,fp,draw,tree); + DR_Print_Tree_Postscript_Pre(n_root,n_root->v[1],n_root->b[1],render_name,fp,draw,tree); + - fprintf(fp,"closepath\n"); - fprintf(fp,"stroke\n"); - fprintf(fp,"showpage\n"); + PhyML_Fprintf(fp,"closepath\n"); + PhyML_Fprintf(fp,"0 0 translate\n"); + PhyML_Fprintf(fp,"stroke\n"); + PhyML_Fprintf(fp,"showpage\n"); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void DR_Print_Tree_Postscript_Pre(node *a, node *d, FILE *fp, tdraw *w, arbre *tree) + +void DR_Print_Tree_Postscript_Pre(t_node *a, t_node *d, t_edge *b, int render_name, FILE *fp, tdraw *w, t_tree *tree) { int i; + phydbl R, G, B; + + R = G = B = 0.0; + + PhyML_Fprintf(fp,"gs\n"); + + PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[a->num],w->ycoord[a->num]); + +/* PhyML_Fprintf(fp,"%.1f %.1f lt\n",w->xcoord[a->num],w->ycoord[d->num]); */ +/* PhyML_Fprintf(fp,"%.1f %.1f lt\n",w->xcoord[d->num],w->ycoord[d->num]); */ - fprintf(fp,"gsave\n"); + phydbl min,max,step,val; + + min = 0.0; + max = 5.; - For(i,3) - if(a->v[i] == d) - { -/* if(a->b[i]->prob_sel_regime <= 0.1) */ -/* fprintf(fp,".0 .0 1. sc\n"); */ -/* else if(a->b[i]->prob_sel_regime > 0.1 && a->b[i]->prob_sel_regime <= 0.2) */ -/* fprintf(fp,".0 .5 1. sc\n"); */ -/* else if(a->b[i]->prob_sel_regime > 0.2 && a->b[i]->prob_sel_regime <= 0.3) */ -/* fprintf(fp,".0 1. 1. sc\n"); */ -/* else if(a->b[i]->prob_sel_regime > 0.3 && a->b[i]->prob_sel_regime <= 0.4) */ -/* fprintf(fp,".0 1. .5 sc\n"); */ -/* else if(a->b[i]->prob_sel_regime > 0.4 && a->b[i]->prob_sel_regime <= 0.5) */ -/* fprintf(fp,".0 1. .0 sc\n"); */ -/* else if(a->b[i]->prob_sel_regime > 0.5 && a->b[i]->prob_sel_regime <= 0.6) */ -/* fprintf(fp,".5 1. .0 sc\n"); */ -/* else if(a->b[i]->prob_sel_regime > 0.6 && a->b[i]->prob_sel_regime <= 0.7) */ -/* fprintf(fp,"1. 1. 0. sc\n"); */ -/* else if(a->b[i]->prob_sel_regime > 0.7 && a->b[i]->prob_sel_regime <= 0.8) */ -/* fprintf(fp,"1. .5 0. sc\n"); */ -/* else if(a->b[i]->prob_sel_regime > 0.8 && a->b[i]->prob_sel_regime <= 0.9) */ -/* fprintf(fp,"1. 0. 0. sc\n"); */ -/* else if(a->b[i]->prob_sel_regime > 0.9) */ -/* fprintf(fp,"1. .0 .0 sc\n"); */ - break; - } - - fprintf(fp,"%d %d mt\n",w->xcoord[a->num],w->ycoord[a->num]); - fprintf(fp,"%d %d lt\n",w->xcoord[a->num],w->ycoord[d->num]); - fprintf(fp,"%d %d lt\n",w->xcoord[d->num],w->ycoord[d->num]); + step = (max-min)/13.; + + /* val = tree->rates->mean_r[d->num] / (phydbl)(tree->mcmc->run/tree->mcmc->sample_interval+1.); */ + /* val = tree->rates->mean_r[d->num]; */ + /* val = tree->rates->has_survived[d->num]; */ + /* if(val > 0.5) {R=1.; G=.0; B=0.;} */ + /* val = tree->geo->ldscape[tree->geo->idx_loc[d->num]*tree->geo->n_dim+0] + 2.5; */ + val = tree->geo->coord_loc[tree->geo->idx_loc[d->num]]->lonlat[0] + 2.5; + /* val = 0.; */ + + if(val <= min+1.*step) + {R=.0; G=1.; B=1.;} + else if(val > min+1.*step && val <= min+2.*step) + {R=.0; G=1.; B=.8;} + else if(val > min+2.*step && val <= min+3.*step) + {R=.0; G=1.; B=.5;} + else if(val > min+3.*step && val <= min+4.*step) + {R=.0; G=1.; B=.3;} + else if(val > min+4.*step && val <= min+5.*step) + {R=.0; G=1.; B=.0;} + else if(val > min+5.*step && val <= min+6.*step) + {R=.25; G=1.; B=0.;} + else if(val > min+6.*step && val <= min+7.*step) + {R=.5; G=1.; B=0.;} + else if(val > min+7.*step && val <= min+8.*step) + {R=.75; G=1.; B=.0;} + else if(val > min+8.*step && val <= min+9.*step) + {R=1.; G=1.; B=.0;} + else if(val > min+9.*step && val <= min+10.*step) + {R=1.; G=.75; B=.0;} + else if(val > min+10.*step && val <= min+11.*step) + {R=1.; G=.5; B=.0;} + else if(val > min+11.*step && val <= min+12.*step) + {R=1.; G=.25; B=.0;} + else if(val > min+12.*step) + {R=1.; G=.0; B=0.;} + + + /* R = 0.; G = 0.; B = 0.; */ + + PhyML_Fprintf(fp,"2 setlinewidth\n"); + /* PhyML_Fprintf(fp,"%.1f %.1f lt\n",w->xcoord[a->num],w->ycoord[d->num]); */ + /* PhyML_Fprintf(fp,"%.1f %.1f lt\n",w->xcoord[d->num],w->ycoord[d->num]); */ + + phydbl xa = w->xcoord[a->num]; + phydbl xd = MIN(w->xcoord[a->num] + 5,w->xcoord[d->num]); + phydbl ya = w->ycoord[a->num]; + phydbl yd = w->ycoord[d->num]; + + PhyML_Fprintf(fp,"%.1f %.1f %.1f %.1f %.1f %.1f ct\n", + xa + (xd-xa)/2.,(ya+yd)/2., + xd - (xd-xa)/5.,yd, + xd,yd); + + PhyML_Fprintf(fp,"%.1f %.1f lt\n",w->xcoord[d->num],w->ycoord[d->num]); + + /* PhyML_Fprintf(fp,"%.1f %.1f %.1f %.1f %.1f %.1f ct\n", */ + /* w->xcoord[a->num], */ + /* w->ycoord[d->num], */ + /* w->xcoord[d->num], */ + /* w->ycoord[d->num], */ + /* w->xcoord[d->num], */ + /* w->ycoord[d->num]); */ + + + if(tree->rates && tree->rates->has_survived[d->num] == YES) + { + PhyML_Fprintf(fp," /Helvetica findfont 16 scalefont\n"); + PhyML_Fprintf(fp,"setfont\n"); + PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num]-5,w->ycoord[d->num]); + PhyML_Fprintf(fp,"0 0 0 sc\n"); + PhyML_Fprintf(fp,"(*) show \n"); + } + + PhyML_Fprintf(fp,"%f %f %f sc\n",R,G,B); if(d->tax) { - fprintf(fp,"(%s) show \n",d->name); - fprintf(fp,"stroke\n"); - fprintf(fp,"grestore\n"); + PhyML_Fprintf(fp,"stroke\n"); + PhyML_Fprintf(fp,"0 setgray\n"); + PhyML_Fprintf(fp,"2 setlinewidth\n"); + PhyML_Fprintf(fp,"np %.1f %.1f 1 0 360 arc cp\n",w->xcoord[d->num],w->ycoord[d->num]); + PhyML_Fprintf(fp,"%.1f %.1f %.1f sc fill\n",R,G,B); +/* PhyML_Fprintf(fp,"%f setgray fill\n",greylevel); */ + PhyML_Fprintf(fp,"0 0 0 sc\n"); + + + PhyML_Fprintf(fp," /Helvetica findfont 10 scalefont\n"); + PhyML_Fprintf(fp,"setfont\n"); + PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num]+2,w->ycoord[d->num]-6); + /* PhyML_Fprintf(fp,"(%d) show \n",d->num); */ + /* PhyML_Fprintf(fp,"(%s) show \n",d->name); */ + PhyML_Fprintf(fp," /Helvetica findfont 14 scalefont\n"); + PhyML_Fprintf(fp,"setfont\n"); + + + PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num] - (w->xcoord[d->num] - w->xcoord[a->num])/2.,w->ycoord[d->num]); + PhyML_Fprintf(fp," /Helvetica findfont 10 scalefont\n"); + PhyML_Fprintf(fp,"setfont\n"); + +#if (defined GEO) + /* PhyML_Fprintf(fp,"([%4.4f,%4.4f]) show \n", */ + /* tree->geo->ldscape[tree->geo->loc[d->num]*tree->geo->n_dim+0], */ + /* tree->geo->ldscape[tree->geo->loc[d->num]*tree->geo->n_dim+1]); */ +#endif + + + /* PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num]+5,w->ycoord[d->num]); */ + /* PhyML_Fprintf(fp,"(%.10s) show \n",d->name); */ + + +/* if(render_name) */ +/* { */ +/* if(tree->io->long_tax_names) */ +/* PhyML_Fprintf(fp,"(%s) show \n",tree->io->long_tax_names[d->num]); */ +/* else */ +/* PhyML_Fprintf(fp,"(%s) show \n",d->name); */ +/* } */ + + PhyML_Fprintf(fp,"stroke\n"); + PhyML_Fprintf(fp,"gr\n"); + PhyML_Fprintf(fp,"0 0 0 sc\n"); return; } else { - fprintf(fp,"stroke\n"); - fprintf(fp,"grestore\n"); - For(i,3) - if(d->v[i] != a) DR_Print_Tree_Postscript_Pre(d,d->v[i],fp,w,tree); - } + PhyML_Fprintf(fp,"stroke\n"); + PhyML_Fprintf(fp,"0 setgray\n"); + PhyML_Fprintf(fp,"2 setlinewidth\n"); + PhyML_Fprintf(fp,"np %.1f %.1f 1 0 360 arc cp\n",w->xcoord[d->num],w->ycoord[d->num]); + PhyML_Fprintf(fp,"%.1f %.1f %.1f sc fill\n",R,G,B); +/* PhyML_Fprintf(fp,"%f setgray fill\n",greylevel); */ + PhyML_Fprintf(fp,"0 0 0 sc\n"); + PhyML_Fprintf(fp," /Helvetica findfont 10 scalefont\n"); + PhyML_Fprintf(fp,"setfont\n"); + PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num]+2,w->ycoord[d->num]); - return; -} + /* PhyML_Fprintf(fp,"(%d) show \n",b->num); */ -/*********************************************************/ + PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num],w->ycoord[d->num]); + PhyML_Fprintf(fp," /Helvetica findfont 14 scalefont\n"); + PhyML_Fprintf(fp,"setfont\n"); -void DR_Dist_To_Root_Pre(node *a, node *d, edge *b, arbre *tree) -{ - int i; - if(b) d->dist_to_root = a->dist_to_root + b->l; + PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num] - (w->xcoord[d->num] - w->xcoord[a->num])/2.,w->ycoord[d->num]); + PhyML_Fprintf(fp," /Helvetica findfont 10 scalefont\n"); + PhyML_Fprintf(fp,"setfont\n"); - if(d->tax) return; - else - { - For(i,3) - if((d->v[i] != a) && (d->b[i] != tree->e_root)) - DR_Dist_To_Root_Pre(d,d->v[i],d->b[i],tree); +#if (defined GEO) + /* PhyML_Fprintf(fp,"([%4.4f,%4.4f]) show \n", */ + /* tree->geo->ldscape[tree->geo->loc[d->num]*tree->geo->n_dim+0], */ + /* tree->geo->ldscape[tree->geo->loc[d->num]*tree->geo->n_dim+1]); */ +#endif + + + PhyML_Fprintf(fp,"stroke\n"); + PhyML_Fprintf(fp,"gr\n"); + PhyML_Fprintf(fp,"0 0 0 sc\n"); + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) DR_Print_Tree_Postscript_Pre(d,d->v[i],d->b[i],render_name,fp,w,tree); } -} -/*********************************************************/ -void DR_Dist_To_Root(node *n_root, arbre *tree) -{ - n_root->v[0]->dist_to_root = tree->e_root->l * tree->n_root_pos; - n_root->v[1]->dist_to_root = tree->e_root->l * (1.-tree->n_root_pos); - DR_Dist_To_Root_Pre(n_root,n_root->v[0],NULL,tree); - DR_Dist_To_Root_Pre(n_root,n_root->v[1],NULL,tree); + + + return; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void DR_Get_X_Coord_Pre(node *a, node *d, edge *b, tdraw *w, arbre *tree) + +void DR_Get_X_Coord_Pre(t_node *a, t_node *d, t_edge *b, tdraw *w, int fixed_tips, t_tree *tree) { int i; - if(b) w->xcoord[d->num] = d->dist_to_root * (double)w->tree_box_width/w->max_dist_to_root; + if(!(d->tax && fixed_tips == YES)) w->xcoord[d->num] = d->dist_to_root * (phydbl)w->tree_box_width/w->max_dist_to_root; if(d->tax) return; else { - For(i,3) + for(i=0;i<3;i++) if((d->v[i] != a) && (d->b[i] != tree->e_root)) - DR_Get_X_Coord_Pre(d,d->v[i],d->b[i],w,tree); + DR_Get_X_Coord_Pre(d,d->v[i],d->b[i],w,fixed_tips,tree); } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void DR_Get_X_Coord(tdraw *w, arbre *tree) +void DR_Get_X_Coord(int fixed_tips, tdraw *w, t_tree *tree) { - w->xcoord[tree->n_root->v[0]->num] = tree->n_root->v[0]->dist_to_root * (double)w->tree_box_width/w->max_dist_to_root; - w->xcoord[tree->n_root->v[1]->num] = tree->n_root->v[1]->dist_to_root * (double)w->tree_box_width/w->max_dist_to_root; - DR_Get_X_Coord_Pre(tree->n_root,tree->n_root->v[0],NULL,w,tree); - DR_Get_X_Coord_Pre(tree->n_root,tree->n_root->v[1],NULL,w,tree); + if(!(tree->n_root->v[2]->tax && fixed_tips == YES)) w->xcoord[tree->n_root->v[2]->num] = tree->n_root->v[2]->dist_to_root * (phydbl)w->tree_box_width/w->max_dist_to_root; + if(!(tree->n_root->v[1]->tax && fixed_tips == YES)) w->xcoord[tree->n_root->v[1]->num] = tree->n_root->v[1]->dist_to_root * (phydbl)w->tree_box_width/w->max_dist_to_root; + DR_Get_X_Coord_Pre(tree->n_root,tree->n_root->v[2],NULL,w,fixed_tips,tree); + DR_Get_X_Coord_Pre(tree->n_root,tree->n_root->v[1],NULL,w,fixed_tips,tree); + w->xcoord[tree->n_root->num] = 0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void DR_Get_Y_Coord(tdraw *w, arbre *tree) + +void DR_Get_Y_Coord(int fixed_tips, tdraw *w, t_tree *tree) { int next_y_slot; next_y_slot = 0; - DR_Get_Y_Coord_Post(tree->e_root->left,tree->e_root->rght,tree->e_root,&next_y_slot,w,tree); - DR_Get_Y_Coord_Post(tree->e_root->rght,tree->e_root->left,tree->e_root,&next_y_slot,w,tree); + DR_Get_Y_Coord_Post(tree->n_root,tree->n_root->v[2],NULL,&next_y_slot,fixed_tips,w,tree); + DR_Get_Y_Coord_Post(tree->n_root,tree->n_root->v[1],NULL,&next_y_slot,fixed_tips,w,tree); + w->ycoord[tree->n_root->num] = (int)((w->ycoord[tree->n_root->v[2]->num] + w->ycoord[tree->n_root->v[2]->num]) / 2.) + 20; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void DR_Get_Y_Coord_Post(node *a, node *d, edge *b, int *next_y_slot, tdraw *w, arbre *tree) +void DR_Get_Y_Coord_Post(t_node *a, t_node *d, t_edge *b, int *next_y_slot, int fixed_tips, tdraw *w, t_tree *tree) { int i; if(d->tax) { - w->ycoord[d->num] = *next_y_slot + (int)(w->page_height / (2.*tree->n_otu)); - (*next_y_slot) += (int)(w->page_height / (tree->n_otu)); + if(!fixed_tips) + { +/* w->ycoord[d->num] = *next_y_slot + (int)(w->page_height / (2.*tree->n_otu)); */ + w->ycoord[d->num] = *next_y_slot + 20; + (*next_y_slot) += (int)(w->page_height / (tree->n_otu-1)); + printf("\n. %s %f",d->name,w->ycoord[d->num]); + } } else { int d1, d2; d1 = d2 = -1; - For(i,3) + for(i=0;i<3;i++) { - if(d->v[i] != a) + if(d->v[i] != a && d->b[i] != tree->e_root) { - DR_Get_Y_Coord_Post(d,d->v[i],d->b[i],next_y_slot,w,tree); + DR_Get_Y_Coord_Post(d,d->v[i],d->b[i],next_y_slot,fixed_tips,w,tree); if(d1<0) d1 = i; else d2 = i; } @@ -305,61 +431,190 @@ void DR_Get_Y_Coord_Post(node *a, node *d, edge *b, int *next_y_slot, tdraw *w, } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -tdraw *DR_Make_Tdraw_Struct(arbre *tree) +tdraw *DR_Make_Tdraw_Struct(t_tree *tree) { tdraw *w; w = (tdraw *)mCalloc(1,sizeof(tdraw)); - w->xcoord = (int *)mCalloc(2*tree->n_otu-2,sizeof(int)); - w->ycoord = (int *)mCalloc(2*tree->n_otu-2,sizeof(int)); + w->xcoord = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); + w->ycoord = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); + w->xcoord_s = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); + w->ycoord_s = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); + w->cdf_mat = (int *)mCalloc((2*tree->n_otu-2)*(2*tree->n_otu-2),sizeof(int)); + w->cdf_mat_x = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); + w->cdf_mat_y = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); return w; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void DR_Init_Tdraw_Struct(tdraw *w) { - w->page_width = 510; - w->page_height = 770; + w->page_width = 580-20; + w->page_height = 820-20; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void DR_Get_Tree_Box_Width(tdraw *w, arbre *tree) +void DR_Get_Tree_Box_Width(tdraw *w, t_tree *tree) { int i; int max_name_len, curr_len; max_name_len = curr_len = 0; - For(i,tree->n_otu) + for(i=0;in_otu;i++) { - curr_len = (int)strlen(tree->noeud[i]->name); + curr_len = (int)strlen(tree->a_nodes[i]->name); if(curr_len > max_name_len) max_name_len = curr_len; } w->tree_box_width = w->page_width - max_name_len * 8.66667; + /* w->tree_box_width = w->page_width - max_name_len * 10.; */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -double DR_Get_Max_Dist_To_Root(arbre *tree) +phydbl DR_Get_Max_Dist_To_Root(t_tree *tree) { - double mx; + phydbl mx; int i; mx = .0; - For(i,tree->n_otu) + for(i=0;in_otu;i++) { - if(tree->noeud[i]->dist_to_root > mx) + if(tree->a_nodes[i]->dist_to_root > mx) { - mx = tree->noeud[i]->dist_to_root; + mx = tree->a_nodes[i]->dist_to_root; } } return mx; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void DR_Get_Tree_Coord_Scaled(tdraw *w, t_tree *tree) +{ + int i; + int max_x,min_x; + int max_y,min_y; + + max_x = -INT_MAX; + min_x = INT_MAX; + + For(i,2*tree->n_otu-1) + { + if(w->xcoord[i] > max_x) max_x = w->xcoord[i]; + if(w->xcoord[i] < min_x) min_x = w->xcoord[i]; + } + + max_y = -INT_MAX; + min_y = INT_MAX; + + For(i,2*tree->n_otu-1) + { + if(w->ycoord[i] > max_y) max_y = w->ycoord[i]; + if(w->ycoord[i] < min_y) min_y = w->ycoord[i]; + } + + + For(i,2*tree->n_otu-1) + { + w->xcoord_s[i] = (phydbl)(w->xcoord[i] - min_x) / (max_x - min_x); + w->ycoord_s[i] = (phydbl)(w->ycoord[i] - min_y) / (max_y - min_y); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void DR_Get_Cdf_Mat(t_tree *tree) +{ + int i,j,k; + phydbl min_x,max_x,y; + phydbl x_mat,y_mat; + t_node *d, *a; + phydbl eps; + + eps = 1.E-6; + + For(i,2*tree->n_otu-1) tree->ps_tree->cdf_mat_x[i] = tree->ps_tree->xcoord_s[i]; + For(i,2*tree->n_otu-1) tree->ps_tree->cdf_mat_y[i] = tree->ps_tree->ycoord_s[i]; + + Qksort(tree->ps_tree->cdf_mat_x,NULL,0,2*tree->n_otu-2); + Qksort(tree->ps_tree->cdf_mat_y,NULL,0,2*tree->n_otu-2); + + For(i,2*tree->n_otu-2) /* x coordinates */ + { + For(j,2*tree->n_otu-2) /* y coordinates */ + { + For(k,2*tree->n_otu-2) /* all nodes in the tree */ + { + d = tree->a_nodes[k]; + a = tree->a_nodes[k]->anc; + + min_x = tree->ps_tree->xcoord_s[a->num]; + max_x = tree->ps_tree->xcoord_s[d->num]; + + y = tree->ps_tree->ycoord_s[d->num]; + + x_mat = tree->ps_tree->cdf_mat_x[i]; + y_mat = tree->ps_tree->cdf_mat_y[j]; + +/* printf("\n. x_mat=%.1f ymat=%.1f min=%.1f max=%.1f y=%.1f", */ +/* x_mat,y_mat,min_x,max_x,y); */ + + if((min_x < x_mat + eps) && (max_x > x_mat) && (y > y_mat)) + { + tree->ps_tree->cdf_mat[j*(2*tree->n_otu-2)+i] += 1; +/* PhyML_Printf("\n. Add 1 to [%.1f,%.1f]", */ +/* tree->ps_tree->cdf_mat_x[i], */ +/* tree->ps_tree->cdf_mat_y[j]); */ + } + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + diff --git a/phyml/draw.h b/phyml/draw.h index 40d8cff..471bd80 100644 --- a/phyml/draw.h +++ b/phyml/draw.h @@ -1,21 +1,29 @@ +#include + #ifndef DRAW_H #define DRAW_H -void DR_Dist_To_Root_Pre(node *a, node *d, edge *b, arbre *tree); -void DR_Dist_To_Root(node *n_root, arbre *tree); -void DR_Get_X_Coord_Pre(node *a, node *d, edge *b, tdraw *w, arbre *tree); -void DR_Get_X_Coord(tdraw *w, arbre *tree); -tdraw *DR_Make_Tdraw_Struct(arbre *tree); +#include "utilities.h" + +void DR_Dist_To_Root_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void DR_Dist_To_Root(t_node *n_root, t_tree *tree); +void DR_Get_X_Coord_Pre(t_node *a, t_node *d, t_edge *b, tdraw *w, int fixed_tips, t_tree *tree); +void DR_Get_X_Coord(int fixed_tips, tdraw *w, t_tree *tree); +tdraw *DR_Make_Tdraw_Struct(t_tree *tree); void DR_Init_Tdraw_Struct(tdraw *d); -void DR_Get_Tree_Box_Width(tdraw *w, arbre *tree); -void DR_Get_Y_Coord_Post(node *a, node *d, edge *b, int *next_y_slot, tdraw *w, arbre *tree); -void DR_Get_Y_Coord(tdraw *w, arbre *tree); -void DR_Get_Tree_Coord(arbre *tree); -double DR_Get_Max_Dist_To_Root(arbre *tree); -void DR_Print_Tree_Postscript(int tree_num, FILE *fp, arbre *tree); -void DR_Print_Tree_Postscript_Pre(node *a, node *d, FILE *fp, tdraw *w, arbre *tree); +void DR_Get_Tree_Box_Width(tdraw *w, t_tree *tree); +void DR_Get_Y_Coord_Post(t_node *a, t_node *d, t_edge *b, int *next_y_slot, int fixed_tips, tdraw *w, t_tree *tree); +void DR_Get_Y_Coord(int fixed_tips, tdraw *w, t_tree *tree); +void DR_Get_Tree_Coord(t_tree *tree); +phydbl DR_Get_Max_Dist_To_Root(t_tree *tree); +void DR_Print_Tree_Postscript(int tree_num, int render_name,FILE *fp, t_tree *tree); +void DR_Print_Tree_Postscript_Pre(t_node *a, t_node *d, t_edge *b, int render_name, FILE *fp, tdraw *w, t_tree *tree); void DR_Print_Postscript_EOF(FILE *fp); void DR_Print_Postscript_Header(int n_pages, FILE *fp); +void DR_Get_Tree_Coord_Scaled(tdraw *w, t_tree *tree); +void DR_Get_Cdf_Mat(t_tree *tree); +void DR_Draw_Tree(char *file_name, t_tree *tree); + #endif diff --git a/phyml/eigen.c b/phyml/eigen.c index 44ce785..44dc30d 100644 --- a/phyml/eigen.c +++ b/phyml/eigen.c @@ -1,14 +1,11 @@ - -/* wash. outcommented most of the funciton since redefined in seq-gen eigen.c */ - /*********************************************************** * This eigen() routine works for eigenvalue/vector analysis * for real general square matrix A * A will be destroyed * rr,ri are vectors containing eigenvalues -* vr,vi are matrices containing (right) eigenvectors +* vr,vi are matrices containing (right) real and imaginary eigenvectors * -* A*[vr+vi*i] = [vr+vi*i] * diag{rr+ri*i} +* A * [vr+vi*i] = [vr+vi*i] * diag{rr+ri*i} * * Algorithm: Handbook for Automatic Computation, vol 2 * by Wilkinson and Reinsch, 1971 @@ -23,16 +20,18 @@ * Thu May 6 15:22:31 CDT 1993 ***************************************************************/ -#include "utilities.h" #include "eigen.h" -#include "free.h" + #define BASE 2 /* base of floating point arithmetic */ -#define DIGITS 40 /* no. of digits to the base BASE in the fraction */ -/* -#define DIGITS 53 + +/* no. of digits to the base BASE in the fraction */ +#define DIGITS 40 +/* +#define DIGITS 53 */ -#define MAXITER 30 /* max2. no. of iterations to converge */ + +#define MAXITER 10000 /* max2. no. of iterations to converge */ #define pos(i,j,n) ((i)*(n)+(j)) @@ -41,108 +40,119 @@ /* ri/vi : imaginary part s of eigen values/vectors */ -int Eigen(int job, double *A, int n, double *rr, double *ri, - double *vr, double *vi, double *work) +int Eigen(int job, phydbl *A, int n, phydbl *rr, phydbl *ri, + phydbl *vr, phydbl *vi, phydbl *work) { /* job=0: eigen values only 1: both eigen values and eigen vectors - double w[n*2]: work space + phydbl w[n*2]: work space */ int low,hi,i,j,k, it, istate=0; - double tiny=sqrt(pow((double)BASE,(double)(1-DIGITS))), t; - -/* printf("EIGEN\n"); */ - - bbalance(A,n,&low,&hi,work); - elemhess(job,A,n,low,hi,vr,vi, (int*)(work+n)); + phydbl tiny, t; + + tiny=SQRT(POW((phydbl)BASE,(phydbl)(1-(int)DIGITS))); + /* tiny=FLT_MIN; */ + /* tiny = SMALL; */ + + balance(A,n,&low,&hi,work); + elemhess(job,A,n,low,hi,vr,vi,(int*)(work+n)); if (-1 == realeig(job,A,n,low,hi,rr,ri,vr,vi)) return (-1); if (job) unbalance(n,vr,vi,low,hi,work); - -/* sort, added by Z. Yang */ - for (i=0; itiny) istate=1; - } - - return (istate) ; + + /* sort, added by Z. Yang */ + for (i=0; itiny) istate=1; + } + + return (istate) ; } -/* complex funcctions -*/ +/* complex functions + */ -/* -complex compl (double re,double im) +complex compl (phydbl re,phydbl im) { - complex r; - - r.re = re; - r.im = im; - return(r); + complex r; + + r.re = re; + r.im = im; + return(r); } -*/ + complex _conj (complex a) { - a.im = -a.im; - return(a); + a.im = -a.im; + return(a); } -#define csize(a) (fabs(a.re)+fabs(a.im)) - -/* complex cplus (complex a, complex b) { - complex c; - c.re = a.re+b.re; - c.im = a.im+b.im; - return (c); + complex c; + c.re = a.re+b.re; + c.im = a.im+b.im; + return (c); } complex cminus (complex a, complex b) { - complex c; - c.re = a.re-b.re; - c.im = a.im-b.im; - return (c); + complex c; + c.re = a.re-b.re; + c.im = a.im-b.im; + return (c); } complex cby (complex a, complex b) { - complex c; - c.re = a.re*b.re-a.im*b.im ; - c.im = a.re*b.im+a.im*b.re ; - return (c); + complex c; + c.re = a.re*b.re-a.im*b.im ; + c.im = a.re*b.im+a.im*b.re ; + return (c); } complex cdiv (complex a,complex b) { - double ratio, den; - complex c; - - if (fabs(b.re) <= fabs(b.im)) { - ratio = b.re / b.im; - den = b.im * (1 + ratio * ratio); - c.re = (a.re * ratio + a.im) / den; - c.im = (a.im * ratio - a.re) / den; - } - else { - ratio = b.im / b.re; - den = b.re * (1 + ratio * ratio); - c.re = (a.re + a.im * ratio) / den; - c.im = (a.im - a.re * ratio) / den; - } - return(c); + phydbl ratio, den; + complex c; + + if (fabs(b.re) <= fabs(b.im)) { + ratio = b.re / b.im; + den = b.im * (1 + ratio * ratio); + c.re = (a.re * ratio + a.im) / den; + c.im = (a.im * ratio - a.re) / den; + } + else { + ratio = b.im / b.re; + den = b.re * (1 + ratio * ratio); + c.re = (a.re + a.im * ratio) / den; + c.im = (a.im - a.re * ratio) / den; + } + return(c); } -*/ - /* complex local_cexp (complex a) */ /* { */ /* complex c; */ @@ -152,208 +162,206 @@ complex cdiv (complex a,complex b) /* return (c); */ /* } */ -/* - -complex cfactor (complex x, double a) +complex cfactor (complex x, phydbl a) { - complex c; - c.re = a*x.re; - c.im = a*x.im; - return (c); + complex c; + c.re = a*x.re; + c.im = a*x.im; + return (c); } int cxtoy (complex *x, complex *y, int n) { - int i; - For (i,n) y[i]=x[i]; - return (0); + int i; + For (i,n) y[i]=x[i]; + return (0); } -*/ - - -/* int cmatby (complex *a, complex *b, complex *c, int n,int m,int k) */ -/* /\* a[n*m], b[m*k], c[n*k] ...... c = a*b */ -/* *\/ */ -/* { */ -/* int i,j,i1; */ -/* complex t; */ - -/* For (i,n) For(j,k) { */ -/* for (i1=0,t=compl(0,0); i1=n - int i,j,k, *irow=(int*) space; - double xmaxsize, ee=1e-20; - complex xmax, t,t1; - - For(i,n) { - xmaxsize = 0.; - for (j=i; j=0; i--) { - if (irow[i] == i) continue; - For(j,n) { - t = x[j*m+i]; - x[j*m+i] = x[j*m+irow[i]]; - x[ j*m+irow[i]] = t; - } + int i,j,i1; + complex t; + + For (i,n) for(j=0;j= 0; k--) { - for (j = k; j >= 0; j--) { - for (i = 0; i <= k; i++) { - if (i != j && fabs(mat[pos(j,i,n)]) != 0) break; - } - - if (i > k) { - scale[k] = j; - - if (j != k) { - for (i = 0; i <= k; i++) { - c = mat[pos(i,j,n)]; - mat[pos(i,j,n)] = mat[pos(i,k,n)]; - mat[pos(i,k,n)] = c; - } - - for (i = 0; i < n; i++) { - c = mat[pos(j,i,n)]; - mat[pos(j,i,n)] = mat[pos(k,i,n)]; - mat[pos(k,i,n)] = c; - } - } - break; - } - } - if (j < 0) break; + /* x[n*m] ... m>=n + */ + int i,j,k, *irow=(int*) space; + phydbl xmaxsize, ee=1e-20; + complex t,t1; + + for(i=0;i=0; i--) { + if (irow[i] == i) continue; + for(j=0;j= 0; k--) + { + for (j = k; j >= 0; j--) + { + for (i = 0; i <= k; i++) + { + if (i != j && fabs(mat[pos(j,i,n)]) > SMALL) break; } - if (i > k) { - scale[l] = j; - if (j != l) { - for (i = 0; i <= k; i++) { - c = mat[pos(i,j,n)]; - mat[pos(i,j,n)] = mat[pos(i,l,n)]; - mat[pos(i,l,n)] = c; - } - - for (i = l; i < n; i++) { - c = mat[pos(j,i,n)]; - mat[pos(j,i,n)] = mat[pos(l,i,n)]; - mat[pos(l,i,n)] = c; - } - } - - break; + + if (i > k) { + scale[k] = j; + + if (j != k) { + for (i = 0; i <= k; i++) { + c = mat[pos(i,j,n)]; + mat[pos(i,j,n)] = mat[pos(i,k,n)]; + mat[pos(i,k,n)] = c; + } + + for (i = 0; i < n; i++) { + c = mat[pos(j,i,n)]; + mat[pos(j,i,n)] = mat[pos(k,i,n)]; + mat[pos(k,i,n)] = c; + } } + break; + } } - - if (j > k) break; + if (j < 0) break; } - - *hi = k; - *low = l; - - /* balance the submatrix in rows l through k */ - - for (i = l; i <= k; i++) { - scale[i] = 1; + + /* search for columns isolating an eigenvalue and push them left */ + + for (l = 0; l <= k; l++) { + for (j = l; j <= k; j++) { + for (i = l; i <= k; i++) { + if (i != j && fabs(mat[pos(i,j,n)]) > SMALL) break; + } + if (i > k) { + scale[l] = j; + if (j != l) { + for (i = 0; i <= k; i++) { + c = mat[pos(i,j,n)]; + mat[pos(i,j,n)] = mat[pos(i,l,n)]; + mat[pos(i,l,n)] = c; + } + + for (i = l; i < n; i++) { + c = mat[pos(j,i,n)]; + mat[pos(j,i,n)] = mat[pos(l,i,n)]; + mat[pos(l,i,n)] = c; + } + } + + break; + } } - - do { - for (done = 1,i = l; i <= k; i++) { - for (c = 0,r = 0,j = l; j <= k; j++) { - if (j != i) { - c += fabs(mat[pos(j,i,n)]); - r += fabs(mat[pos(i,j,n)]); - } + + if (j > k) break; + } + + *hi = k; + *low = l; + + /* balance the submatrix in rows l through k */ + + for (i = l; i <= k; i++) { + scale[i] = 1; + } + + do { + for (done = 1,i = l; i <= k; i++) { + for (c = 0,r = 0,j = l; j <= k; j++) { + if (j != i) { + c += fabs(mat[pos(j,i,n)]); + r += fabs(mat[pos(i,j,n)]); + } + } + + /* if (c != 0 && r != 0) { */ + if ((fabs(c) > SMALL || fabs(c) < -SMALL) && (fabs(r) > SMALL || fabs(r) < -SMALL)) + { + g = r / BASE; + f = 1; + s = c + r; + + while (c < g) { + f *= BASE; + c *= BASE * BASE; + } + + g = r * BASE; + + while (c >= g) { + f /= BASE; + c /= BASE * BASE; + } + + if ((c + r) / f < 0.95 * s) { + done = 0; + g = 1 / f; + scale[i] *= f; + + for (j = l; j < n; j++) { + mat[pos(i,j,n)] *= g; } - - if (c != 0 && r != 0) { - g = r / BASE; - f = 1; - s = c + r; - - while (c < g) { - f *= BASE; - c *= BASE * BASE; - } - - g = r * BASE; - - while (c >= g) { - f /= BASE; - c /= BASE * BASE; - } - - if ((c + r) / f < 0.95 * s) { - done = 0; - g = 1 / f; - scale[i] *= f; - - for (j = l; j < n; j++) { - mat[pos(i,j,n)] *= g; - } - - for (j = 0; j <= k; j++) { - mat[pos(j,i,n)] *= f; - } - } + + for (j = 0; j <= k; j++) { + mat[pos(j,i,n)] *= f; } + } } - } while (!done); + } + } while (!done); } @@ -361,487 +369,508 @@ void bbalance(double *mat, int n,int *low, int *hi, double *scale) * Transform back eigenvectors of a balanced matrix * into the eigenvectors of the original matrix */ - -/* -void unbalance(int n,double *vr,double *vi, int low, int hi, double *scale) +void unbalance(int n,phydbl *vr,phydbl *vi, int low, int hi, phydbl *scale) { - int i,j,k; - double tmp; - - for (i = low; i <= hi; i++) { - for (j = 0; j < n; j++) { - vr[pos(i,j,n)] *= scale[i]; - vi[pos(i,j,n)] *= scale[i]; - } + int i,j,k; + phydbl tmp; + + for (i = low; i <= hi; i++) { + for (j = 0; j < n; j++) { + vr[pos(i,j,n)] *= scale[i]; + vi[pos(i,j,n)] *= scale[i]; } - - for (i = low - 1; i >= 0; i--) { - if ((k = (int)scale[i]) != i) { - for (j = 0; j < n; j++) { - tmp = vr[pos(i,j,n)]; - vr[pos(i,j,n)] = vr[pos(k,j,n)]; - vr[pos(k,j,n)] = tmp; - - tmp = vi[pos(i,j,n)]; - vi[pos(i,j,n)] = vi[pos(k,j,n)]; - vi[pos(k,j,n)] = tmp; - } - } + } + + for (i = low - 1; i >= 0; i--) { + if ((k = (int)scale[i]) != i) { + for (j = 0; j < n; j++) { + tmp = vr[pos(i,j,n)]; + vr[pos(i,j,n)] = vr[pos(k,j,n)]; + vr[pos(k,j,n)] = tmp; + + tmp = vi[pos(i,j,n)]; + vi[pos(i,j,n)] = vi[pos(k,j,n)]; + vi[pos(k,j,n)] = tmp; + } } - - for (i = hi + 1; i < n; i++) { - if ((k = (int)scale[i]) != i) { - for (j = 0; j < n; j++) { - tmp = vr[pos(i,j,n)]; - vr[pos(i,j,n)] = vr[pos(k,j,n)]; - vr[pos(k,j,n)] = tmp; - - tmp = vi[pos(i,j,n)]; - vi[pos(i,j,n)] = vi[pos(k,j,n)]; - vi[pos(k,j,n)] = tmp; - } - } + } + + for (i = hi + 1; i < n; i++) { + if ((k = (int)scale[i]) != i) { + for (j = 0; j < n; j++) { + tmp = vr[pos(i,j,n)]; + vr[pos(i,j,n)] = vr[pos(k,j,n)]; + vr[pos(k,j,n)] = tmp; + + tmp = vi[pos(i,j,n)]; + vi[pos(i,j,n)] = vi[pos(k,j,n)]; + vi[pos(k,j,n)] = tmp; + } } + } } -*/ - /* * Reduce the submatrix in rows and columns low through hi of real matrix mat to * Hessenberg form by elementary similarity transformations */ - - /* -void elemhess(int job,double *mat,int n,int low,int hi, double *vr, - double *vi, int *work) +void elemhess(int job,phydbl *mat,int n,int low,int hi, phydbl *vr, + phydbl *vi, int *work) { -// work[n] - int i,j,m; - double x,y; - - for (m = low + 1; m < hi; m++) { - for (x = 0,i = m,j = m; j <= hi; j++) { - if (fabs(mat[pos(j,m-1,n)]) > fabs(x)) { - x = mat[pos(j,m-1,n)]; - i = j; + /* work[n] */ + unsigned int i,j,m; + phydbl x,y; + + for (m = low + 1; m < hi; m++) + { + for (x = 0,i = m,j = m; j <= hi; j++) + { + if(fabs(mat[pos(j,m-1,n)]) > fabs(x)) + { + x = mat[pos(j,m-1,n)]; + i = j; } } - - if ((work[m] = i) != m) { - for (j = m - 1; j < n; j++) { - y = mat[pos(i,j,n)]; - mat[pos(i,j,n)] = mat[pos(m,j,n)]; - mat[pos(m,j,n)] = y; + + if ((work[m] = i) != m) + { + for (j = m - 1; j < n; j++) + { + y = mat[pos(i,j,n)]; + mat[pos(i,j,n)] = mat[pos(m,j,n)]; + mat[pos(m,j,n)] = y; } - - for (j = 0; j <= hi; j++) { - y = mat[pos(j,i,n)]; - mat[pos(j,i,n)] = mat[pos(j,m,n)]; - mat[pos(j,m,n)] = y; + + for (j = 0; j <= hi; j++) + { + y = mat[pos(j,i,n)]; + mat[pos(j,i,n)] = mat[pos(j,m,n)]; + mat[pos(j,m,n)] = y; + } + } + + if (fabs(x) > SMALL) + { + for (i = m + 1; i <= hi; i++) + { + if (fabs(y = mat[pos(i,m-1,n)]) > SMALL) + { + y = mat[pos(i,m-1,n)] = y / x; + + for (j = m; j < n; j++) { + mat[pos(i,j,n)] -= y * mat[pos(m,j,n)]; + } + + for (j = 0; j <= hi; j++) { + mat[pos(j,m,n)] += y * mat[pos(j,i,n)]; + } + } } } + } + + if (job) + { + for (i=0; i low; m--) + { + for (i = m + 1; i <= hi; i++) + { + vr[pos(i,m,n)] = mat[pos(i,m-1,n)]; + } + + if ((i = work[m]) != m) + { + for (j = m; j <= hi; j++) + { + vr[pos(m,j,n)] = vr[pos(i,j,n)]; + vr[pos(i,j,n)] = 0.0; + } + vr[pos(i,m,n)] = 1.0; + } + } + } +} - if (x != 0) { - for (i = m + 1; i <= hi; i++) { - if ((y = mat[pos(i,m-1,n)]) != 0) { - y = mat[pos(i,m-1,n)] = y / x; +/* + * Calculate eigenvalues and eigenvectors of a real upper Hessenberg matrix + * Return 1 if converges successfully and 0 otherwise + */ - for (j = m; j < n; j++) { - mat[pos(i,j,n)] -= y * mat[pos(m,j,n)]; +int realeig(int job,phydbl *mat,int n,int low, int hi, phydbl *valr, + phydbl *vali, phydbl *vr,phydbl *vi) +{ + complex v; + phydbl p=.0,q=.0,r=.0,s=.0,t,w,x,y,z=0,ra,sa,norm,eps; + int niter,en,i,j,k,l,m; + phydbl precision = POW((phydbl)BASE,(phydbl)(1-(int)DIGITS)); // Won't pass testiphy... + /* phydbl precision = SMALL; */ + + + eps = precision; + for (i=0; i hi) valr[i] = mat[pos(i,i,n)]; + } + t = 0; + en = hi; + + while (en >= low) + { + niter = 0; + for (;;) { + + /* look for single small subdiagonal element */ + + for (l = en; l > low; l--) + { + s = fabs(mat[pos(l-1,l-1,n)]) + fabs(mat[pos(l,l,n)]); + if (fabs(s) < SMALL) s = norm; + if (fabs(mat[pos(l,l-1,n)]) <= eps * s) break; + } + + /* form shift */ + + x = mat[pos(en,en,n)]; + + if (l == en) + { /* one root found */ + valr[en] = x + t; + if (job) mat[pos(en,en,n)] = x + t; + en--; + break; + } + + y = mat[pos(en-1,en-1,n)]; + w = mat[pos(en,en-1,n)] * mat[pos(en-1,en,n)]; + + if (l == en - 1) + { /* two roots found */ + p = (y - x) / 2; + q = p * p + w; + z = SQRT(fabs(q)); + x += t; + if (job) + { + mat[pos(en,en,n)] = x; + mat[pos(en-1,en-1,n)] = y + t; + } + if (q < 0) + { /* complex pair */ + valr[en-1] = x+p; + vali[en-1] = z; + valr[en] = x+p; + vali[en] = -z; + } + else + { /* real pair */ + z = (p < 0) ? p - z : p + z; + valr[en-1] = x + z; + valr[en] = (fabs(z) < SMALL) ? x + z : x - w / z; + if (job) { + x = mat[pos(en,en-1,n)]; + s = fabs(x) + fabs(z); + p = x / s; + q = z / s; + r = SQRT(p*p+q*q); + p /= r; + q /= r; + for (j = en - 1; j < n; j++) + { + z = mat[pos(en-1,j,n)]; + mat[pos(en-1,j,n)] = q * z + p * + mat[pos(en,j,n)]; + mat[pos(en,j,n)] = q * mat[pos(en,j,n)] - p*z; } - - for (j = 0; j <= hi; j++) { - mat[pos(j,m,n)] += y * mat[pos(j,i,n)]; + for (i = 0; i <= en; i++) + { + z = mat[pos(i,en-1,n)]; + mat[pos(i,en-1,n)] = q * z + p * mat[pos(i,en,n)]; + mat[pos(i,en,n)] = q * mat[pos(i,en,n)] - p*z; + } + for (i = low; i <= hi; i++) + { + z = vr[pos(i,en-1,n)]; + vr[pos(i,en-1,n)] = q*z + p*vr[pos(i,en,n)]; + vr[pos(i,en,n)] = q*vr[pos(i,en,n)] - p*z; } } + } + en -= 2; + break; + } + if (niter == MAXITER) return(-1); + if (niter != 0 && niter % 10 == 0) { + t += x; + for (i = low; i <= en; i++) mat[pos(i,i,n)] -= x; + s = fabs(mat[pos(en,en-1,n)]) + fabs(mat[pos(en-1,en-2,n)]); + x = y = 0.75 * s; + w = -0.4375 * s * s; + } + niter++; + /* look for two consecutive small subdiagonal elements */ + for (m = en - 2; m >= l; m--) { + z = mat[pos(m,m,n)]; + r = x - z; + s = y - z; + p = (r * s - w) / mat[pos(m+1,m,n)] + mat[pos(m,m+1,n)]; + q = mat[pos(m+1,m+1,n)] - z - r - s; + r = mat[pos(m+2,m+1,n)]; + s = fabs(p) + fabs(q) + fabs(r); + p /= s; + q /= s; + r /= s; + if (m == l || fabs(mat[pos(m,m-1,n)]) * (fabs(q)+fabs(r)) <= + eps * (fabs(mat[pos(m-1,m-1,n)]) + fabs(z) + + fabs(mat[pos(m+1,m+1,n)])) * fabs(p)) break; + } + for (i = m + 2; i <= en; i++) mat[pos(i,i-2,n)] = 0; + for (i = m + 3; i <= en; i++) mat[pos(i,i-3,n)] = 0; + /* phydbl QR step involving rows l to en and columns m to en */ + for (k = m; k < en; k++) { + if (k != m) { + p = mat[pos(k,k-1,n)]; + q = mat[pos(k+1,k-1,n)]; + r = (k == en - 1) ? 0 : mat[pos(k+2,k-1,n)]; + if (fabs(x = fabs(p) + fabs(q) + fabs(r)) < SMALL) continue; + p /= x; + q /= x; + r /= x; + } + s = SQRT(p*p+q*q+r*r); + if (p < 0) s = -s; + if (k != m) { + mat[pos(k,k-1,n)] = -s * x; + } + else if (l != m) { + mat[pos(k,k-1,n)] = -mat[pos(k,k-1,n)]; + } + p += s; + x = p / s; + y = q / s; + z = r / s; + q /= p; + r /= p; + /* row modification */ + for (j = k; j <= (!job ? en : n-1); j++){ + p = mat[pos(k,j,n)] + q * mat[pos(k+1,j,n)]; + if (k != en - 1) { + p += r * mat[pos(k+2,j,n)]; + mat[pos(k+2,j,n)] -= p * z; + } + mat[pos(k+1,j,n)] -= p * y; + mat[pos(k,j,n)] -= p * x; + } + j = MIN(en,k+3); + /* column modification */ + for (i = (!job ? l : 0); i <= j; i++) { + p = x * mat[pos(i,k,n)] + y * mat[pos(i,k+1,n)]; + if (k != en - 1) { + p += z * mat[pos(i,k+2,n)]; + mat[pos(i,k+2,n)] -= p*r; + } + mat[pos(i,k+1,n)] -= p*q; + mat[pos(i,k,n)] -= p; + } + if (job) { /* accumulate transformations */ + for (i = low; i <= hi; i++) { + p = x * vr[pos(i,k,n)] + y * vr[pos(i,k+1,n)]; + if (k != en - 1) { + p += z * vr[pos(i,k+2,n)]; + vr[pos(i,k+2,n)] -= p*r; } + vr[pos(i,k+1,n)] -= p*q; + vr[pos(i,k,n)] -= p; + } } + } } - if (job) { - for (i=0; i SMALL) { + /* back substitute to find vectors of upper triangular form */ + for (en = n-1; en >= 0; en--) { + p = valr[en]; + if ((q = vali[en]) < 0) { /* complex vector */ + m = en - 1; + if (fabs(mat[pos(en,en-1,n)]) > fabs(mat[pos(en-1,en,n)])) { + mat[pos(en-1,en-1,n)] = q / mat[pos(en,en-1,n)]; + mat[pos(en-1,en,n)] = (p - mat[pos(en,en,n)]) / + mat[pos(en,en-1,n)]; + } + else { + v = cdiv(compl(0.0,-mat[pos(en-1,en,n)]), + compl(mat[pos(en-1,en-1,n)]-p,q)); + mat[pos(en-1,en-1,n)] = v.re; + mat[pos(en-1,en,n)] = v.im; + } + mat[pos(en,en-1,n)] = 0; + mat[pos(en,en,n)] = 1; + for (i = en - 2; i >= 0; i--) { + w = mat[pos(i,i,n)] - p; + ra = 0; + sa = mat[pos(i,en,n)]; + for (j = m; j < en; j++) { + ra += mat[pos(i,j,n)] * mat[pos(j,en-1,n)]; + sa += mat[pos(i,j,n)] * mat[pos(j,en,n)]; } - vr[pos(i,i,n)] = 1.0; - } - - for (m = hi - 1; m > low; m--) { - for (i = m + 1; i <= hi; i++) { - vr[pos(i,m,n)] = mat[pos(i,m-1,n)]; + if (vali[i] < 0) { + z = w; + r = ra; + s = sa; } - - if ((i = work[m]) != m) { - for (j = m; j <= hi; j++) { - vr[pos(m,j,n)] = vr[pos(i,j,n)]; - vr[pos(i,j,n)] = 0.0; + else { + m = i; + if (fabs(vali[i]) < SMALL) { + v = cdiv(compl(-ra,-sa),compl(w,q)); + mat[pos(i,en-1,n)] = v.re; + mat[pos(i,en,n)] = v.im; + } + else { /* solve complex equations */ + x = mat[pos(i,i+1,n)]; + y = mat[pos(i+1,i,n)]; + v.re = (valr[i]- p)*(valr[i]-p) + vali[i]*vali[i] - q*q; + v.im = (valr[i] - p)*2*q; + if (fabs(v.re) + fabs(v.im) < SMALL) { + v.re = eps * norm * (fabs(w) + + fabs(q) + fabs(x) + fabs(y) + fabs(z)); + } + v = cdiv(compl(x*r-z*ra+q*sa,x*s-z*sa-q*ra),v); + mat[pos(i,en-1,n)] = v.re; + mat[pos(i,en,n)] = v.im; + if (fabs(x) > fabs(z) + fabs(q)) { + mat[pos(i+1,en-1,n)] = + (-ra - w * mat[pos(i,en-1,n)] + + q * mat[pos(i,en,n)]) / x; + mat[pos(i+1,en,n)] = (-sa - w * mat[pos(i,en,n)] - + q * mat[pos(i,en-1,n)]) / x; + } + else { + v = cdiv(compl(-r-y*mat[pos(i,en-1,n)], + -s-y*mat[pos(i,en,n)]),compl(z,q)); + mat[pos(i+1,en-1,n)] = v.re; + mat[pos(i+1,en,n)] = v.im; + } + } + } + } + } + else if (fabs(q) < SMALL) { /* real vector */ + m = en; + mat[pos(en,en,n)] = 1; + for (i = en - 1; i >= 0; i--) { + w = mat[pos(i,i,n)] - p; + r = mat[pos(i,en,n)]; + for (j = m; j < en; j++) { + r += mat[pos(i,j,n)] * mat[pos(j,en,n)]; + } + if (vali[i] < 0) { + z = w; + s = r; + } + else { + m = i; + if (fabs(vali[i]) < SMALL) { + if (fabs(t = w) < SMALL) t = eps * norm; + mat[pos(i,en,n)] = -r / t; } - vr[pos(i,m,n)] = 1.0; - } + else { /* solve real equations */ + x = mat[pos(i,i+1,n)]; + y = mat[pos(i+1,i,n)]; + q = (valr[i] - p) * (valr[i] - p) + vali[i]*vali[i]; + t = (x * s - z * r) / q; + mat[pos(i,en,n)] = t; + if (fabs(x) <= fabs(z)) { + mat[pos(i+1,en,n)] = (-s - y * t) / z; + } + else { + mat[pos(i+1,en,n)] = (-r - w * t) / x; + } + } + } + } } - } + } + /* vectors of isolated roots */ + for (i = 0; i < n; i++) { + if (i < low || i > hi) { + for (j = i; j < n; j++) { + vr[pos(i,j,n)] = mat[pos(i,j,n)]; + } + } + } + /* multiply by transformation matrix */ + + for (j = n-1; j >= low; j--) { + m = MIN(j,hi); + for (i = low; i <= hi; i++) { + for (z = 0,k = low; k <= m; k++) { + z += vr[pos(i,k,n)] * mat[pos(k,j,n)]; + } + vr[pos(i,j,n)] = z; + } + } + } + /* rearrange complex eigenvectors */ + for (j = 0; j < n; j++) { + if (fabs(vali[j]) > SMALL) { + for (i = 0; i < n; i++) { + vi[pos(i,j,n)] = vr[pos(i,j+1,n)]; + vr[pos(i,j+1,n)] = vr[pos(i,j,n)]; + vi[pos(i,j+1,n)] = -vi[pos(i,j,n)]; + } + j++; + } + } + return(0); } - */ - - -/* - * Calculate eigenvalues and eigenvectors of a real upper Hessenberg matrix - * Return 1 if converges successfully and 0 otherwise - */ - -/* int realeig(int job,double *mat,int n,int low, int hi, double *valr, */ -/* double *vali, double *vr,double *vi) */ -/* { */ -/* complex v; */ -/* double p=0,q=0,r=0,s=0,t,w,x,y,z=0,ra,sa,norm,eps; */ -/* int niter,en,i,j,k,l,m; */ -/* double precision = pow((double)BASE,(double)(1-DIGITS)); */ - -/* eps = precision; */ -/* for (i=0; i hi) valr[i] = mat[pos(i,i,n)]; */ -/* } */ -/* t = 0; */ -/* en = hi; */ - -/* while (en >= low) { */ -/* niter = 0; */ -/* for (;;) { */ - -/* /\* look for single small subdiagonal element *\/ */ - -/* for (l = en; l > low; l--) { */ -/* s = fabs(mat[pos(l-1,l-1,n)]) + fabs(mat[pos(l,l,n)]); */ -/* if (s == 0) s = norm; */ -/* if (fabs(mat[pos(l,l-1,n)]) <= eps * s) break; */ -/* } */ - -/* /\* form shift *\/ */ - -/* x = mat[pos(en,en,n)]; */ - -/* if (l == en) { /\* one root found *\/ */ -/* valr[en] = x + t; */ -/* if (job) mat[pos(en,en,n)] = x + t; */ -/* en--; */ -/* break; */ -/* } */ - -/* y = mat[pos(en-1,en-1,n)]; */ -/* w = mat[pos(en,en-1,n)] * mat[pos(en-1,en,n)]; */ - -/* if (l == en - 1) { /\* two roots found *\/ */ -/* p = (y - x) / 2; */ -/* q = p * p + w; */ -/* z = sqrt(fabs(q)); */ -/* x += t; */ -/* if (job) { */ -/* mat[pos(en,en,n)] = x; */ -/* mat[pos(en-1,en-1,n)] = y + t; */ -/* } */ -/* if (q < 0) { /\* complex pair *\/ */ -/* valr[en-1] = x+p; */ -/* vali[en-1] = z; */ -/* valr[en] = x+p; */ -/* vali[en] = -z; */ -/* } */ -/* else { /\* real pair *\/ */ -/* z = (p < 0) ? p - z : p + z; */ -/* valr[en-1] = x + z; */ -/* valr[en] = (z == 0) ? x + z : x - w / z; */ -/* if (job) { */ -/* x = mat[pos(en,en-1,n)]; */ -/* s = fabs(x) + fabs(z); */ -/* p = x / s; */ -/* q = z / s; */ -/* r = sqrt(p*p+q*q); */ -/* p /= r; */ -/* q /= r; */ -/* for (j = en - 1; j < n; j++) { */ -/* z = mat[pos(en-1,j,n)]; */ -/* mat[pos(en-1,j,n)] = q * z + p * */ -/* mat[pos(en,j,n)]; */ -/* mat[pos(en,j,n)] = q * mat[pos(en,j,n)] - p*z; */ -/* } */ -/* for (i = 0; i <= en; i++) { */ -/* z = mat[pos(i,en-1,n)]; */ -/* mat[pos(i,en-1,n)] = q * z + p * mat[pos(i,en,n)]; */ -/* mat[pos(i,en,n)] = q * mat[pos(i,en,n)] - p*z; */ -/* } */ -/* for (i = low; i <= hi; i++) { */ -/* z = vr[pos(i,en-1,n)]; */ -/* vr[pos(i,en-1,n)] = q*z + p*vr[pos(i,en,n)]; */ -/* vr[pos(i,en,n)] = q*vr[pos(i,en,n)] - p*z; */ -/* } */ -/* } */ -/* } */ -/* en -= 2; */ -/* break; */ -/* } */ -/* if (niter == MAXITER) return(-1); */ -/* if (niter != 0 && niter % 10 == 0) { */ -/* t += x; */ -/* for (i = low; i <= en; i++) mat[pos(i,i,n)] -= x; */ -/* s = fabs(mat[pos(en,en-1,n)]) + fabs(mat[pos(en-1,en-2,n)]); */ -/* x = y = 0.75 * s; */ -/* w = -0.4375 * s * s; */ -/* } */ -/* niter++; */ -/* /\* look for two consecutive small subdiagonal elements *\/ */ -/* for (m = en - 2; m >= l; m--) { */ -/* z = mat[pos(m,m,n)]; */ -/* r = x - z; */ -/* s = y - z; */ -/* p = (r * s - w) / mat[pos(m+1,m,n)] + mat[pos(m,m+1,n)]; */ -/* q = mat[pos(m+1,m+1,n)] - z - r - s; */ -/* r = mat[pos(m+2,m+1,n)]; */ -/* s = fabs(p) + fabs(q) + fabs(r); */ -/* p /= s; */ -/* q /= s; */ -/* r /= s; */ -/* if (m == l || fabs(mat[pos(m,m-1,n)]) * (fabs(q)+fabs(r)) <= */ -/* eps * (fabs(mat[pos(m-1,m-1,n)]) + fabs(z) + */ -/* fabs(mat[pos(m+1,m+1,n)])) * fabs(p)) break; */ -/* } */ -/* for (i = m + 2; i <= en; i++) mat[pos(i,i-2,n)] = 0; */ -/* for (i = m + 3; i <= en; i++) mat[pos(i,i-3,n)] = 0; */ -/* /\* double QR step involving rows l to en and columns m to en *\/ */ -/* for (k = m; k < en; k++) { */ -/* if (k != m) { */ -/* p = mat[pos(k,k-1,n)]; */ -/* q = mat[pos(k+1,k-1,n)]; */ -/* r = (k == en - 1) ? 0 : mat[pos(k+2,k-1,n)]; */ -/* if ((x = fabs(p) + fabs(q) + fabs(r)) == 0) continue; */ -/* p /= x; */ -/* q /= x; */ -/* r /= x; */ -/* } */ -/* s = sqrt(p*p+q*q+r*r); */ -/* if (p < 0) s = -s; */ -/* if (k != m) { */ -/* mat[pos(k,k-1,n)] = -s * x; */ -/* } */ -/* else if (l != m) { */ -/* mat[pos(k,k-1,n)] = -mat[pos(k,k-1,n)]; */ -/* } */ -/* p += s; */ -/* x = p / s; */ -/* y = q / s; */ -/* z = r / s; */ -/* q /= p; */ -/* r /= p; */ -/* /\* row modification *\/ */ -/* for (j = k; j <= (!job ? en : n-1); j++){ */ -/* p = mat[pos(k,j,n)] + q * mat[pos(k+1,j,n)]; */ -/* if (k != en - 1) { */ -/* p += r * mat[pos(k+2,j,n)]; */ -/* mat[pos(k+2,j,n)] -= p * z; */ -/* } */ -/* mat[pos(k+1,j,n)] -= p * y; */ -/* mat[pos(k,j,n)] -= p * x; */ -/* } */ -/* j = MIN(en,k+3); */ -/* /\* column modification *\/ */ -/* for (i = (!job ? l : 0); i <= j; i++) { */ -/* p = x * mat[pos(i,k,n)] + y * mat[pos(i,k+1,n)]; */ -/* if (k != en - 1) { */ -/* p += z * mat[pos(i,k+2,n)]; */ -/* mat[pos(i,k+2,n)] -= p*r; */ -/* } */ -/* mat[pos(i,k+1,n)] -= p*q; */ -/* mat[pos(i,k,n)] -= p; */ -/* } */ -/* if (job) { /\* accumulate transformations *\/ */ -/* for (i = low; i <= hi; i++) { */ -/* p = x * vr[pos(i,k,n)] + y * vr[pos(i,k+1,n)]; */ -/* if (k != en - 1) { */ -/* p += z * vr[pos(i,k+2,n)]; */ -/* vr[pos(i,k+2,n)] -= p*r; */ -/* } */ -/* vr[pos(i,k+1,n)] -= p*q; */ -/* vr[pos(i,k,n)] -= p; */ -/* } */ -/* } */ -/* } */ -/* } */ -/* } */ - -/* if (!job) return(0); */ -/* if (norm != 0) { */ -/* /\* back substitute to find vectors of upper triangular form *\/ */ -/* for (en = n-1; en >= 0; en--) { */ -/* p = valr[en]; */ -/* if ((q = vali[en]) < 0) { /\* complex vector *\/ */ -/* m = en - 1; */ -/* if (fabs(mat[pos(en,en-1,n)]) > fabs(mat[pos(en-1,en,n)])) { */ -/* mat[pos(en-1,en-1,n)] = q / mat[pos(en,en-1,n)]; */ -/* mat[pos(en-1,en,n)] = (p - mat[pos(en,en,n)]) / */ -/* mat[pos(en,en-1,n)]; */ -/* } */ -/* else { */ -/* v = cdiv(compl(0.0,-mat[pos(en-1,en,n)]), */ -/* compl(mat[pos(en-1,en-1,n)]-p,q)); */ -/* mat[pos(en-1,en-1,n)] = v.re; */ -/* mat[pos(en-1,en,n)] = v.im; */ -/* } */ -/* mat[pos(en,en-1,n)] = 0; */ -/* mat[pos(en,en,n)] = 1; */ -/* for (i = en - 2; i >= 0; i--) { */ -/* w = mat[pos(i,i,n)] - p; */ -/* ra = 0; */ -/* sa = mat[pos(i,en,n)]; */ -/* for (j = m; j < en; j++) { */ -/* ra += mat[pos(i,j,n)] * mat[pos(j,en-1,n)]; */ -/* sa += mat[pos(i,j,n)] * mat[pos(j,en,n)]; */ -/* } */ -/* if (vali[i] < 0) { */ -/* z = w; */ -/* r = ra; */ -/* s = sa; */ -/* } */ -/* else { */ -/* m = i; */ -/* if (vali[i] == 0) { */ -/* v = cdiv(compl(-ra,-sa),compl(w,q)); */ -/* mat[pos(i,en-1,n)] = v.re; */ -/* mat[pos(i,en,n)] = v.im; */ -/* } */ -/* else { /\* solve complex equations *\/ */ -/* x = mat[pos(i,i+1,n)]; */ -/* y = mat[pos(i+1,i,n)]; */ -/* v.re = (valr[i]- p)*(valr[i]-p) + vali[i]*vali[i] - q*q; */ -/* v.im = (valr[i] - p)*2*q; */ -/* if ((fabs(v.re) + fabs(v.im)) == 0) { */ -/* v.re = eps * norm * (fabs(w) + */ -/* fabs(q) + fabs(x) + fabs(y) + fabs(z)); */ -/* } */ -/* v = cdiv(compl(x*r-z*ra+q*sa,x*s-z*sa-q*ra),v); */ -/* mat[pos(i,en-1,n)] = v.re; */ -/* mat[pos(i,en,n)] = v.im; */ -/* if (fabs(x) > fabs(z) + fabs(q)) { */ -/* mat[pos(i+1,en-1,n)] = */ -/* (-ra - w * mat[pos(i,en-1,n)] + */ -/* q * mat[pos(i,en,n)]) / x; */ -/* mat[pos(i+1,en,n)] = (-sa - w * mat[pos(i,en,n)] - */ -/* q * mat[pos(i,en-1,n)]) / x; */ -/* } */ -/* else { */ -/* v = cdiv(compl(-r-y*mat[pos(i,en-1,n)], */ -/* -s-y*mat[pos(i,en,n)]),compl(z,q)); */ -/* mat[pos(i+1,en-1,n)] = v.re; */ -/* mat[pos(i+1,en,n)] = v.im; */ -/* } */ -/* } */ -/* } */ -/* } */ -/* } */ -/* else if (q == 0) { /\* real vector *\/ */ -/* m = en; */ -/* mat[pos(en,en,n)] = 1; */ -/* for (i = en - 1; i >= 0; i--) { */ -/* w = mat[pos(i,i,n)] - p; */ -/* r = mat[pos(i,en,n)]; */ -/* for (j = m; j < en; j++) { */ -/* r += mat[pos(i,j,n)] * mat[pos(j,en,n)]; */ -/* } */ -/* if (vali[i] < 0) { */ -/* z = w; */ -/* s = r; */ -/* } */ -/* else { */ -/* m = i; */ -/* if (vali[i] == 0) { */ -/* if ((t = w) == 0) t = eps * norm; */ -/* mat[pos(i,en,n)] = -r / t; */ -/* } */ -/* else { /\* solve real equations *\/ */ -/* x = mat[pos(i,i+1,n)]; */ -/* y = mat[pos(i+1,i,n)]; */ -/* q = (valr[i] - p) * (valr[i] - p) + vali[i]*vali[i]; */ -/* t = (x * s - z * r) / q; */ -/* mat[pos(i,en,n)] = t; */ -/* if (fabs(x) <= fabs(z)) { */ -/* mat[pos(i+1,en,n)] = (-s - y * t) / z; */ -/* } */ -/* else { */ -/* mat[pos(i+1,en,n)] = (-r - w * t) / x; */ -/* } */ -/* } */ -/* } */ -/* } */ -/* } */ -/* } */ -/* /\* vectors of isolated roots *\/ */ -/* for (i = 0; i < n; i++) { */ -/* if (i < low || i > hi) { */ -/* for (j = i; j < n; j++) { */ -/* vr[pos(i,j,n)] = mat[pos(i,j,n)]; */ -/* } */ -/* } */ -/* } */ -/* /\* multiply by transformation matrix *\/ */ - -/* for (j = n-1; j >= low; j--) { */ -/* m = MIN(j,hi); */ -/* for (i = low; i <= hi; i++) { */ -/* for (z = 0,k = low; k <= m; k++) { */ -/* z += vr[pos(i,k,n)] * mat[pos(k,j,n)]; */ -/* } */ -/* vr[pos(i,j,n)] = z; */ -/* } */ -/* } */ -/* } */ -/* /\* rearrange complex eigenvectors *\/ */ -/* for (j = 0; j < n; j++) { */ -/* if (vali[j] != 0) { */ -/* for (i = 0; i < n; i++) { */ -/* vi[pos(i,j,n)] = vr[pos(i,j+1,n)]; */ -/* vr[pos(i,j+1,n)] = vr[pos(i,j,n)]; */ -/* vi[pos(i,j+1,n)] = -vi[pos(i,j,n)]; */ -/* } */ -/* j++; */ -/* } */ -/* } */ -/* return(0); */ -/* } */ - #define LUDCMP_TINY 1.0e-20; -int ludcmp(double **a, int n, double *d) +int ludcmp(phydbl **a, int n, phydbl *d) { - int i,imax,j,k; - double big,dum,sum,temp; - double *vv; - - imax = 0; - vv = (double *)mCalloc(n,sizeof(double)); - - *d=1.0; - for (i=0;i big) big=temp; - if (big == 0.0) Exit("\n. Singular matrix in routine LUDCMP"); - vv[i]=1.0/big; - } - for (j=0;j big) big=temp; + if (fabs(big) < SMALL) Exit("\n. Singular matrix in routine LUDCMP"); + vv[i]=1.0/big; + } + for (j=0;j big) big=temp; + if (fabs(big) < SMALL) Exit("\n. Singular matrix in routine LUDCMP"); + vv[i]=1.0/big; + } + for (j=0;j= big) + { + big=dum; + imax=i; + } + } + if (j != imax) + { + for (k=0;k + #ifndef EIGEN_H #define EIGEN_H -int Eigen(int job, double *A, int n, double *rr, double *ri, - double *vr, double *vi, double *w); +#include "utilities.h" +#include "free.h" + +#ifdef RWRAPPER +#include +#endif + +int ludcmp_1D(phydbl *a, int n, phydbl *d); +void det_1D(phydbl *a, int n, phydbl *d); -/* wash. renamed balance to bbalance due to name clash with SISSI */ -void bbalance(double *mat, int n, int *low, int *hi, double *scale); -void unbalance(int n, double *vr, double *vi, int low, int hi, - double *scale); -int realeig(int job, double *mat, int n,int low, int hi, double *valr, - double *vali, double *vr, double *vi); -void elemhess(int job, double *mat, int n, int low, int hi, - double *vr, double *vi, int *work); +int Eigen(int job, phydbl *A, int n, phydbl *rr, phydbl *ri, + phydbl *vr, phydbl *vi, phydbl *w); +void balance(phydbl *mat, int n, int *low, int *hi, phydbl *scale); +void unbalance(int n, phydbl *vr, phydbl *vi, int low, int hi, + phydbl *scale); +int realeig(int job, phydbl *mat, int n,int low, int hi, phydbl *valr, + phydbl *vali, phydbl *vr, phydbl *vi); +void elemhess(int job, phydbl *mat, int n, int low, int hi, + phydbl *vr, phydbl *vi, int *work); -int ludcmp(double **a, int n, double *d); -void det(double **a, int n, double *d); +int ludcmp(phydbl **a, int n, phydbl *d); +void det(phydbl **a, int n, phydbl *d); /* complex functions */ -typedef struct { double re, im; } complex; -#define csize(a) (fabs(a.re)+fabs(a.im)) +typedef struct { phydbl re, im; } complex; +#define csize(a) (FABS(a.re)+FABS(a.im)) -complex compl (double re,double im); +complex compl (phydbl re,phydbl im); complex _conj (complex a); complex cplus (complex a, complex b); complex cminus (complex a, complex b); complex cby (complex a, complex b); complex cdiv (complex a,complex b); /* complex local_cexp (complex a); */ -complex cfactor (complex x, double a); +complex cfactor (complex x, phydbl a); int cxtoy (complex *x, complex *y, int n); int cmatby (complex *a, complex *b, complex *c, int n,int m,int k); int cmatout (FILE * fout, complex *x, int n, int m); -int cmatinv( complex *x, int n, int m, double *space); +int cmatinv( complex *x, int n, int m, phydbl *space); +phydbl *Cholesky_Decomp(phydbl *A, int dim); #endif diff --git a/phyml/free.c b/phyml/free.c index 01661b5..df24179 100644 --- a/phyml/free.c +++ b/phyml/free.c @@ -1,7 +1,7 @@ /* PHYML : a program that computes maximum likelihood phylogenies from -DNA or AA homologous sequences +DNA or AA homologous sequences Copyright (C) Stephane Guindon. Oct 2003 onward @@ -10,37 +10,132 @@ the GNU public licence. See http://www.opensource.org for details. */ -#include "utilities.h" #include "free.h" -#include "m4.h" -/*********************************************************/ -void Free_All_Nodes_Light(arbre *tree) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Clade(t_clad *this) +{ + Free(this); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_All_Nodes_Light(t_tree *mixt_tree) { int i; - For(i,2*tree->n_otu-2) - Free_Node(tree->noeud[i]); + t_tree *tree; + + tree = mixt_tree; + do + { + for(i=0;i<2*tree->n_otu-1;++i) if(tree->a_nodes[i] != NULL) Free_Node(tree->a_nodes[i]); + Free(tree->a_nodes); + tree = tree->next; + } + while(tree); + } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_All_Edges_Light(arbre *tree) +void Free_All_Edges_Light(t_tree *mixt_tree) { int i; - For(i,2*tree->n_otu-3) - if(tree->t_edges[i]) - Free_Edge(tree->t_edges[i]); + t_tree *tree; + + tree = mixt_tree; + + for(i=0;i<2*tree->n_otu-1;++i) + { + if(tree->a_edges[i] != NULL) + { + Free_Scalar_Dbl(tree->a_edges[i]->l); + Free_Scalar_Dbl(tree->a_edges[i]->l_old); + Free_Scalar_Dbl(tree->a_edges[i]->l_var); + Free_Scalar_Dbl(tree->a_edges[i]->l_var_old); + } + } + + do + { + for(i=0;i<2*tree->n_otu-1;++i) + if(tree->a_edges[i] != NULL) + Free_Edge(tree->a_edges[i]); + Free(tree->a_edges); + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Edge_Length(t_edge *b) +{ + if(b->l) Free_Scalar_Dbl(b->l); + if(b->l_old) Free_Scalar_Dbl(b->l_old); + if(b->l_var) Free_Scalar_Dbl(b->l_var); + if(b->l_var_old) Free_Scalar_Dbl(b->l_var_old); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Edge(t_edge *b) +{ + Free_Label(b->label); + Free_Edge_Core(b); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Edge_Core(t_edge *b) +{ + Free(b); } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Node(t_node *n) +{ + Free(n->b); + Free(n->v); + Free(n->score); + Free(n->s_ingrp); + Free(n->s_outgrp); + Free(n->cal); + Free_Label(n->label); + + if(n->c_seq_anc != NULL) + { + Free(n->c_seq_anc->state); + Free(n->c_seq_anc); + } + + if(n->ori_name) { Free(n->ori_name); n->ori_name = NULL; } + + /* if(n->name) { Free(n->name); n->name = NULL; } */ + /* Don't do that: see Copy_Tax_Names_To_Tip_Labels + tree->a_nodes[i]->ori_name = tree->a_nodes[i]->name; */ -/*********************************************************/ + Free(n); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// void Free_Mat(matrix *mat) { int i; - For(i,mat->n_otu) + for(i=0;in_otu;i++) { Free(mat->P[i]); Free(mat->Q[i]); @@ -53,158 +148,141 @@ void Free_Mat(matrix *mat) Free(mat->dist); Free(mat->name); Free(mat->tip_node); - + Free(mat->on_off); Free(mat); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Partial_Lk(phydbl ****p_lk, int len, int n_catg) -{ - int i,j; - For(i,len) - { - For(j,n_catg) Free((*p_lk)[i][j]); - Free((*p_lk)[i]); - } - Free((*p_lk)); - (*p_lk) = NULL; +void Free_Partial_Lk(phydbl *p_lk, int len, int n_catg) +{ + Free(p_lk); + +/* int i,j; */ +/* for(i=0;in_otu-2) Free(tree->t_dir[i]); - Free(tree->t_dir); - - if(tree->has_bip) + tree = mixt_tree; + do { - For(i,2*tree->n_otu-2) - { - Free(tree->noeud[i]->bip_size); - For(j,3) - { - Free(tree->noeud[i]->bip_node[j]); - For(k,tree->n_otu) Free(tree->noeud[i]->bip_name[j][k]); - Free(tree->noeud[i]->bip_name[j]); - } - Free(tree->noeud[i]->bip_node); - Free(tree->noeud[i]->bip_name); - } + if(tree->mat) Free_Mat(tree->mat); + Free(tree->t_dir); + if(tree->short_l) Free(tree->short_l); + if(tree->mutmap) Free(tree->mutmap); + Free_Bip(tree); + Free(tree->curr_path); + tree = tree->next; } - - Free(tree->curr_path); - - For(i,2*tree->n_otu-3) - { - b = tree->t_edges[i]; - Free_Edge(b); - } - Free(tree->t_edges); + while(tree); + Free_All_Edges_Light(mixt_tree); + Free_All_Nodes_Light(mixt_tree); - For(i,2*tree->n_otu-2) + tree = mixt_tree; + next = mixt_tree->next; + do { - n = tree->noeud[i]; - Free_Node(n); + Free(tree); + tree = next; + if(!tree) break; + next = next->next; } - Free(tree->noeud); + while(tree); - - For(i,tree->n_dead_edges) - Free_Edge(tree->t_dead_edges[i]); - - For(i,tree->n_dead_nodes) - Free_Node(tree->t_dead_nodes[i]); - - Free(tree->t_dead_edges); - Free(tree->t_dead_nodes); - - - Free(tree); -} - -/*********************************************************/ - -void Free_Edge_Labels(edge *b) -{ - int i; - For(i,b->n_labels+b->n_labels%BLOCK_LABELS) Free(b->labels[i]); - Free(b->labels); - b->labels = NULL; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Edge(edge *b) -{ - Free_Edge_Labels(b); - Free(b); -} -/*********************************************************/ - -void Free_Node(node *n) +void Free_Bip(t_tree *tree) { - int i; - - Free(n->b); - Free(n->v); - Free(n->l); - Free(n->score); - Free(n->name); + int i,j; - if(n->list_of_reachable_tips) + if(tree->has_bip) { - For(i,3) Free(n->list_of_reachable_tips[i]); - Free(n->list_of_reachable_tips); - Free(n->n_of_reachable_tips); + For(i,2*tree->n_otu-2) + { + Free(tree->a_nodes[i]->bip_size); + for(j=0;j<3;j++) Free(tree->a_nodes[i]->bip_node[j]); + Free(tree->a_nodes[i]->bip_node); } - - Free(n); + } + tree->has_bip = NO; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Cseq(allseq *data) +void Free_Calign(calign *data) { int i; - + + if(data->io_wght) Free_Scalar_Dbl(data->io_wght); Free(data->invar); Free(data->wght); Free(data->ambigu); - Free(data->b_frq); + Free(data->obs_state_frq); Free(data->sitepatt); - For(i,data->n_otu) + for(i=0;in_otu;i++) { Free(data->c_seq[i]->name); - if(data->c_seq[i]->state) - { - Free(data->c_seq[i]->state); - if(data->c_seq[i]->is_ambigu) Free(data->c_seq[i]->is_ambigu); - } + if(data->c_seq[i]->state) + { + Free(data->c_seq[i]->state); + Free(data->c_seq[i]->d_state); + if(data->c_seq[i]->is_ambigu) Free(data->c_seq[i]->is_ambigu); + } Free(data->c_seq[i]); } - Free(data->c_seq); + + + for(i=0;in_rm;i++) + { + Free(data->c_seq_rm[i]->name); + if(data->c_seq_rm[i]->state) + { + Free(data->c_seq_rm[i]->state); + Free(data->c_seq_rm[i]->d_state); + if(data->c_seq_rm[i]->is_ambigu) Free(data->c_seq_rm[i]->is_ambigu); + } + Free(data->c_seq_rm[i]); + } + + if(data->c_seq_rm != NULL) Free(data->c_seq_rm); + if(data->c_seq != NULL) Free(data->c_seq); + Free(data); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Seq(seq **d, int n_otu) +void Free_Seq(align **d, int n_otu) { int i; - For(i,n_otu) + for(i=0;iname); Free(d[i]->state); + Free(d[i]->d_state); if(d[i]->is_ambigu) Free(d[i]->is_ambigu); Free(d[i]); } @@ -212,267 +290,717 @@ void Free_Seq(seq **d, int n_otu) } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void Free_All(seq **d, allseq *alldata, arbre *tree) +void Free_All(align **d, calign *cdata, t_tree *tree) { - Free_Cseq(alldata); + Free_Calign(cdata); Free_Seq(d,tree->n_otu); Free_Tree(tree); -} +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ -void Free_SubTree(edge *b_fcus, node *a, node *d, arbre *tree) +void Free_SubTree(t_edge *b_fcus, t_node *a, t_node *d, t_tree *tree) { int i; if(d->tax) return; else { - For(i,3) - { - if(d->v[i] != a) - { - Free_SubTree(d->b[i],d,d->v[i],tree); - Free_Edge(d->b[i]); - Free_Node(d->v[i]); - } - } + for(i=0;i<3;i++) + { + if(d->v[i] != a) + { + Free_SubTree(d->b[i],d,d->v[i],tree); + Free_Edge(d->b[i]); + Free_Node(d->v[i]); + } + } } } -/*********************************************************/ -void Free_Tree_Ins_Tar(arbre *tree) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Tree_Ins_Tar(t_tree *tree) { return; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Tree_Pars(arbre *tree) +void Free_Tree_Pars(t_tree *mixt_tree) { int i; - - Free(tree->step_mat); - Free(tree->site_pars); - For(i,2*tree->n_otu-3) - Free_Edge_Pars(tree->t_edges[i],tree); + t_tree *tree; + + tree = mixt_tree; + do + { + Free(tree->step_mat); + Free(tree->site_pars); + + for(i=0;i<2*tree->n_otu-3;++i) + { + Free_Edge_Pars(tree->a_edges[i]); + } + + if(tree->n_root) + { + Free_Edge_Pars_Left(tree->n_root->b[1]); + Free_Edge_Pars_Left(tree->n_root->b[2]); + } + else + { + Free_Edge_Pars(tree->a_edges[2*tree->n_otu-3]); + Free_Edge_Pars(tree->a_edges[2*tree->n_otu-2]); + } + + tree = tree->next; + } + while(tree); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Edge_Pars(edge *b, arbre *tree) +void Free_Edge_Pars_Left(t_edge *b) +{ + if(b->pars_l) Free(b->pars_l); + if(b->ui_l) Free(b->ui_l); + if(b->p_pars_l) Free(b->p_pars_l); + if(b->n_diff_states_l) Free(b->n_diff_states_l); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Edge_Pars_Rght(t_edge *b) +{ + if(b->pars_r) Free(b->pars_r); + if(b->ui_r) Free(b->ui_r); + if(b->p_pars_r) Free(b->p_pars_r); + if(b->n_diff_states_r) Free(b->n_diff_states_r); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Edge_Pars(t_edge *b) +{ + Free_Edge_Pars_Left(b); + Free_Edge_Pars_Rght(b); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Tree_Lk(t_tree *mixt_tree) { int i; + t_tree *tree; - Free(b->pars_l); - Free(b->pars_r); - - For(i,tree->data->crunch_len) + tree = mixt_tree; + do { - Free(b->p_pars_l[i]); - Free(b->p_pars_r[i]); + Free(tree->c_lnL_sorted); + Free(tree->cur_site_lk); + Free(tree->old_site_lk); + Free(tree->site_lk_cat); + Free(tree->fact_sum_scale); + Free(tree->unscaled_site_lk_cat); + Free(tree->expl); + + if(tree->is_mixt_tree == NO) + { + Free(tree->eigen_lr_left); + Free(tree->eigen_lr_rght); + Free(tree->dot_prod); + + for(i=0;i<3;i++) Free(tree->log_lks_aLRT[i]); + Free(tree->log_lks_aLRT); + + Free(tree->div_post_pred_extra_0); + Free(tree->sum_scale_cat_extra_0); + Free(tree->sum_scale_extra_0); + Free(tree->patt_id_extra_0); + Free(tree->p_lk_extra_0); + Free(tree->p_lk_tip_extra_0); + + Free(tree->div_post_pred_extra_1); + Free(tree->sum_scale_cat_extra_1); + Free(tree->sum_scale_extra_1); + Free(tree->patt_id_extra_1); + Free(tree->p_lk_extra_1); + Free(tree->p_lk_tip_extra_1); + + for(i=0;i<2*tree->n_otu-1;++i) Free_NNI(tree->a_edges[i]->nni); + for(i=0;i<2*tree->n_otu-3;++i) Free_Edge_Lk(tree->a_edges[i]); + for(i=0;i<2*tree->n_otu-3;++i) Free_Edge_Loc(tree->a_edges[i]); + + if(tree->n_root != NULL) + { + Free(tree->n_root->b[1]->Pij_rr); + Free(tree->n_root->b[2]->Pij_rr); + Free(tree->n_root->b[1]->tPij_rr); + Free(tree->n_root->b[2]->tPij_rr); + Free_Edge_Lk_Left(tree->n_root->b[1]); + Free_Edge_Lk_Left(tree->n_root->b[2]); + Free_Edge_Loc_Left(tree->n_root->b[1]); + Free_Edge_Loc_Left(tree->n_root->b[2]); + } + else + { + Free_Edge_Lk(tree->a_edges[2*tree->n_otu-3]); + Free_Edge_Lk(tree->a_edges[2*tree->n_otu-2]); + Free_Edge_Loc(tree->a_edges[2*tree->n_otu-3]); + Free_Edge_Loc(tree->a_edges[2*tree->n_otu-2]); + } + } + + tree = tree->next; + } + while(tree); - Free(b->ui_l); - Free(b->ui_r); - Free(b->p_pars_l); - Free(b->p_pars_r); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Tree_Lk(arbre *tree) + +void Free_Node_Lk(t_node *n) { - int i; - edge *b; - node *n; +/* Free(n->n_ex_nodes); */ +} - b = NULL; - n = NULL; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,3) Free(tree->log_lks_aLRT[i]); - Free(tree->log_lks_aLRT); +void Free_Extra_Edge_Lk(t_tree *tree) +{ + if(tree->div_post_pred_extra_0) Free(tree->div_post_pred_extra_0); + if(tree->sum_scale_cat_extra_0) Free(tree->sum_scale_cat_extra_0); + if(tree->sum_scale_extra_0) Free(tree->sum_scale_extra_0); + if(tree->p_lk_extra_0) Free(tree->p_lk_extra_0); + if(tree->p_lk_tip_extra_0) Free(tree->p_lk_tip_extra_0); + if(tree->patt_id_extra_0) Free(tree->patt_id_extra_0); + + if(tree->div_post_pred_extra_1) Free(tree->div_post_pred_extra_1); + if(tree->sum_scale_cat_extra_1) Free(tree->sum_scale_cat_extra_1); + if(tree->sum_scale_extra_1) Free(tree->sum_scale_extra_1); + if(tree->p_lk_extra_1) Free(tree->p_lk_extra_1); + if(tree->p_lk_tip_extra_1) Free(tree->p_lk_tip_extra_1); + if(tree->patt_id_extra_1) Free(tree->patt_id_extra_1); +} - Free(tree->c_lnL_sorted); - Free(tree->site_lk); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,tree->mod->n_catg) Free(tree->log_site_lk_cat[i]); - Free(tree->log_site_lk_cat); - - For(i,2*tree->n_otu-3) +void Free_Edge_Lk_Rght(t_edge *b) +{ + assert(b); + + Free(b->div_post_pred_rght); + + if(b->p_lk_rght) { - b = tree->t_edges[i]; - Free_Edge_Lk(tree,b); + Free(b->p_lk_rght); + if(b->sum_scale_rght) Free(b->sum_scale_rght); } + + if(b->p_lk_tip_r) Free(b->p_lk_tip_r); + if(b->sum_scale_rght_cat) Free(b->sum_scale_rght_cat); + if(b->patt_id_rght) Free(b->patt_id_rght); } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ +void Free_Edge_Lk_Left(t_edge *b) +{ + + Free(b->div_post_pred_left); + if(b->p_lk_left) + { + Free(b->p_lk_left); + if(b->sum_scale_left) Free(b->sum_scale_left); + } -void Free_Node_Lk(node *n) + if(b->p_lk_tip_l) Free(b->p_lk_tip_l); + if(b->sum_scale_left_cat) Free(b->sum_scale_left_cat); + if(b->patt_id_left) Free(b->patt_id_left); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Edge_Lk(t_edge *b) { -/* Free(n->n_ex_nodes); */ + Free(b->tPij_rr); + Free(b->Pij_rr); + + Free_Edge_Lk_Left(b); + Free_Edge_Lk_Rght(b); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Edge_Lk(arbre *tree, edge *b) +void Free_Edge_Loc_Rght(t_edge *b) { - int i,j; + if(b->p_lk_loc_rght) Free(b->p_lk_loc_rght); +} - Free(b->nni); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - Free(b->div_post_pred_left); - Free(b->div_post_pred_rght); +void Free_Edge_Loc_Left(t_edge *b) +{ + if(b->p_lk_loc_left) Free(b->p_lk_loc_left); +} - if(b->p_lk_left) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Edge_Loc(t_edge *b) +{ + Free_Edge_Loc_Left(b); + Free_Edge_Loc_Rght(b); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Model_Complete(t_mod *mixt_mod) +{ + Free_Eigen(mixt_mod->eigen); + Free_Rmat(mixt_mod->r_mat); + Free_Efrq(mixt_mod->e_frq); + Free_Vect_Dbl(mixt_mod->Pij_rr); + mixt_mod->r_mat = NULL; + mixt_mod->e_frq = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Rmat_Weights(t_mod *mixt_mod) +{ + t_mod *mod; + + mod = mixt_mod; + + do { - For(i,tree->data->crunch_len) - { - For(j,tree->mod->n_catg) - { - Free(b->p_lk_left[i][j]); - } - Free(b->p_lk_left[i]); - } - Free(b->p_lk_left); - if(b->sum_scale_f_left) Free(b->sum_scale_f_left); + Free(mod->r_mat_weight); + mod = mod->next_mixt; } + while(mod); + + if(mixt_mod->next) Free_Scalar_Dbl(mixt_mod->next->r_mat_weight); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Efrq_Weights(t_mod *mixt_mod) +{ + t_mod *mod; + + mod = mixt_mod; - if(b->p_lk_tip_l) + do { - For(i,tree->data->crunch_len) - { - Free(b->p_lk_tip_l[i]); - } - Free(b->p_lk_tip_l); + Free(mod->e_frq_weight); + mod = mod->next_mixt; } + while(mod); + if(mixt_mod->next) Free_Scalar_Dbl(mixt_mod->next->e_frq_weight); - if(b->p_lk_rght) +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Model_Basic(t_mod *mixt_mod) +{ + t_mod *mod; + + Free_RAS(mixt_mod->ras); + Free_Scalar_Dbl(mixt_mod->mr); + Free_Scalar_Dbl(mixt_mod->kappa); + Free_Scalar_Dbl(mixt_mod->lambda); + Free_Scalar_Dbl(mixt_mod->br_len_mult); + Free_Scalar_Dbl(mixt_mod->br_len_mult_unscaled); + + Free_Rmat_Weights(mixt_mod); + Free_Efrq_Weights(mixt_mod); + + Free_String(mixt_mod->modelname); + Free_String(mixt_mod->custom_mod_string); + Free_String(mixt_mod->aa_rate_mat_file); + + mod = mixt_mod; + do { - For(i,tree->data->crunch_len) - { - For(j,tree->mod->n_catg) - { - Free(b->p_lk_rght[i][j]); - } - Free(b->p_lk_rght[i]); - } - Free(b->p_lk_rght); - if(b->sum_scale_f_rght) Free(b->sum_scale_f_rght); + if(mod->next) + { + mod = mod->next; + Free(mod->prev); + } + else + { + Free(mod); + break; + } } + while(mod); - if(b->p_lk_tip_r) +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Vect_Dbl(vect_dbl *v) +{ + vect_dbl *next; + + assert(v); + + next = v->next; + do { - For(i,tree->data->crunch_len) - { - Free(b->p_lk_tip_r[i]); - } - Free(b->p_lk_tip_r); + Free(v->v); + Free(v); + + v = next; + if(v) next = v->next; } + while(v); +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,tree->mod->n_catg) +void Free_Vect_Int(vect_int *v) +{ + vect_int *next; + + assert(v); + + next = v->next; + do { - For(j,tree->mod->ns) - { - Free(b->Pij_rr[i][j]); - } - Free(b->Pij_rr[i]); + Free(v->v); + Free(v); + + v = next; + if(v) next = v->next; } - Free(b->Pij_rr); + while(v); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Model(model *mod) +void Free_Scalar_Dbl(scalar_dbl *v) { - int i,j; + scalar_dbl *next; + + assert(v); + + next = v->next; + do + { + Free(v); + v = next; + if(v) next = v->next; + } + while(v); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Scalar_Int(scalar_int *v) +{ + scalar_int *next; + + assert(v); + + next = v->next; + do + { + Free(v); + v = next; + if(v) next = v->next; + } + while(v); +} + - Free(mod->modelname); - Free(mod->custom_mod_string); - Free(mod->user_b_freq); - Free(mod->rr_num); - Free(mod->rr); - Free(mod->rr_val); - Free(mod->n_rr_per_cat); - Free(mod->s_opt); - Free(mod->pi); - Free(mod->pi_unscaled); - Free(mod->gamma_r_proba); - Free(mod->gamma_rr); - Free(mod->qmat); - Free(mod->qmat_buff); - Free_Eigen(mod->eigen); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Linked_List(t_ll *t) +{ + t_ll *next,*ll; - For(i,mod->n_catg) + if(t == NULL) return; + + ll = t->head; + next = ll->next; + do { - For(j,mod->ns) Free(mod->Pij_rr[i][j]); - Free(mod->Pij_rr[i]); + /* t_node *n = ll->v; */ + /* printf("\n. free node %d",n?n->num:-1); */ + /* printf(" ll: %p",ll); */ + /* printf(" hd: %p",ll?ll->head:NULL); fflush(NULL); */ + Free(ll); + ll = next; + if(ll) next = ll->next; + } + while(ll); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_String(t_string *ts) +{ + t_string *next; + + next = ts->next; + do + { + Free(ts->s); + Free(ts); + + ts = next; + if(ts) next = ts->next; } - Free(mod->Pij_rr); + while(ts); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Custom_Model(t_mod *mod) +{ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Efrq(t_efrq *e_frq) +{ + Free(e_frq->pi->v); + Free(e_frq->pi); + + Free(e_frq->pi_unscaled->v); + Free(e_frq->pi_unscaled); + + Free(e_frq->user_b_freq->v); + Free(e_frq->user_b_freq); + + if(e_frq->next) Free_Efrq(e_frq->next); + + Free(e_frq); +} - if(mod->n_rr_branch) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Rmat(t_rmat *r_mat) +{ + + Free(r_mat->rr->v); + Free(r_mat->rr); + + Free(r_mat->rr_num->v); + + Free(r_mat->rr_val->v); + Free(r_mat->rr_val); + + Free(r_mat->n_rr_per_cat->v); + Free(r_mat->n_rr_per_cat); + + Free(r_mat->rr_num); + + Free(r_mat->qmat->v); + Free(r_mat->qmat); + + Free(r_mat->qmat_buff->v); + Free(r_mat->qmat_buff); + + if(r_mat->next) Free_Rmat(r_mat->next); + + Free(r_mat); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_RAS(t_ras *ras) +{ + if(ras->gamma_r_proba->v) { - Free(mod->rr_branch); - Free(mod->p_rr_branch); + Free(ras->gamma_r_proba->v); + Free(ras->gamma_r_proba_unscaled->v); + Free(ras->gamma_rr->v); + Free(ras->gamma_rr_unscaled->v); } - #ifndef PHYML - /* Commented out by wash, we don't use M4 mode, setting PHYML does - not help */ - /* M4_Free_M4_Model(mod->m4mod); */ - #endif - Free(mod); + Free(ras->gamma_r_proba); + Free(ras->skip_rate_cat); + + Free(ras->gamma_r_proba_unscaled); + Free(ras->gamma_rr); + Free(ras->gamma_rr_unscaled); + Free_Scalar_Dbl(ras->pinvar); + Free_Scalar_Dbl(ras->alpha); + Free_Scalar_Dbl(ras->free_rate_mr); + + if(ras->next) Free_RAS(ras->next); + + Free(ras); } -/*********************************************************/ + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Model(t_mod *mod) +{ + Free_Custom_Model(mod); + Free_Model_Complete(mod); + Free_Model_Basic(mod); + /* Free(mod); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// void Free(void *p) { +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 free(p); +#else + _aligned_free(p); +#endif +#else + free(p); +#endif + + p = NULL; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Free_Input(option *io) { - Free(io->in_seq_file); - Free(io->in_tree_file); - Free(io->out_tree_file); - Free(io->out_best_tree_file); - Free(io->out_boot_tree_file); - Free(io->out_boot_stats_file); - Free(io->out_stats_file); - Free(io->out_lk_file); - Free(io->out_ps_file); - Free(io->out_trace_file); - Free(io->nt_or_cd); - Free(io); + int i; + + do + { + RATES_Free_Rates(io->rates); + MCMC_Free_MCMC(io->mcmc); + Free(io->in_align_file); + Free(io->in_tree_file); + Free(io->in_constraint_tree_file); + Free(io->in_coord_file); + Free(io->out_file); + Free(io->out_tree_file); + Free(io->out_trees_file); + Free(io->out_boot_tree_file); + Free(io->out_boot_stats_file); + Free(io->out_stats_file); + Free(io->weight_file); + Free(io->out_lk_file); + Free(io->out_summary_file); + Free(io->out_ps_file); + Free(io->out_trace_file); + Free(io->out_json_trace_file); + Free(io->out_ancestral_seq_file); + Free(io->out_ancestral_tree_file); + Free(io->nt_or_cd); + Free(io->run_id_string); + Free(io->clade_list_file); + for(i=0;ialphabet[i]); + Free(io->alphabet); + if(io->short_tax_names) + { + for(i=0;isize_tax_names;i++) + { + Free(io->short_tax_names[i]); + Free(io->long_tax_names[i]); + } + Free(io->long_tax_names); + Free(io->short_tax_names); + } + Free_Tree_List(io->treelist); + + if(io->lon) Free(io->lon); + if(io->lat) Free(io->lat); + + if(io->next) + { + io = io->next; + Free(io->prev); + } + else + { + Free(io); + break; + } + + }while(1); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_St(superarbre *st) +void Free_Tree_List(t_treelist *list) +{ + Free(list->tree); + Free(list); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Free_St(supert_tree *st) { int i; - For(i,2*st->tree->n_otu-3) - Free(st->tree->t_edges[i]->nni); + For(i,2*st->tree->n_otu-1) + Free_NNI(st->tree->a_edges[i]->nni); - For(i,st->n_gt) Free(st->match_st_node_in_gt[i]); + for(i=0;in_part;i++) Free(st->match_st_node_in_gt[i]); Free(st->match_st_node_in_gt); Free_Tree(st->tree); - + Free(st); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Free_Eigen(eigen *eigen_struct) { @@ -480,108 +1008,110 @@ void Free_Eigen(eigen *eigen_struct) Free(eigen_struct->space); Free(eigen_struct->e_val); Free(eigen_struct->e_val_im); - Free(eigen_struct->r_e_vect); Free(eigen_struct->r_e_vect_im); Free(eigen_struct->l_e_vect); + Free(eigen_struct->r_e_vect); + Free(eigen_struct->dum); Free(eigen_struct->q); + + if(eigen_struct->next) Free_Eigen(eigen_struct->next); + Free(eigen_struct); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_One_Spr(spr *this_spr) + +void Free_One_Spr(t_spr *this_spr) { Free(this_spr->path); - Free(this_spr); + if(this_spr->l0) Free_Scalar_Dbl(this_spr->l0); + if(this_spr->l1) Free_Scalar_Dbl(this_spr->l1); + if(this_spr->l2) Free_Scalar_Dbl(this_spr->l2); + if(this_spr->v0) Free_Scalar_Dbl(this_spr->v0); + if(this_spr->v1) Free_Scalar_Dbl(this_spr->v1); + if(this_spr->v2) Free_Scalar_Dbl(this_spr->v2); + + if(this_spr->init_target_l) Free_Scalar_Dbl(this_spr->init_target_l); + if(this_spr->init_target_v) Free_Scalar_Dbl(this_spr->init_target_v); + + Free(this_spr); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Spr_List(arbre *tree) +void Free_Spr_List_One_Edge(t_tree *mixt_tree) { int i; + t_tree *tree; - For(i,tree->size_spr_list+1) + tree = mixt_tree; + do { - Free_One_Spr(tree->spr_list[i]); + for(i=0;isize_spr_list_one_edge+1;++i) Free_One_Spr(tree->spr_list_one_edge[i]); + Free(tree->spr_list_one_edge); + tree = tree->next; } - Free(tree->spr_list); + while(tree); } -/*********************************************************/ - +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Triplet(ttriplet *t) +void Free_Spr_List_All_Edge(t_tree *mixt_tree) { - int i,j,k; - - Free(t->F_bc); - Free(t->F_cd); - Free(t->F_bd); - Free(t->pi_bc); - Free(t->pi_cd); - Free(t->pi_bd); - - For(k,t->mod->n_catg) - { - For(i,t->size) - { - For(j,t->size) Free(t->core[k][i][j]); - Free(t->core[k][i]); - } - Free(t->core[k]); - } - Free(t->core); - - For(i,t->size) - { - For(j,t->size) Free(t->p_one_site[i][j]); - Free(t->p_one_site[i]); - } - Free(t->p_one_site); + int i; + t_tree *tree; - For(i,t->size) + tree = mixt_tree; + do { - For(j,t->size) Free(t->sum_p_one_site[i][j]); - Free(t->sum_p_one_site[i]); + for(i=0;isize_spr_list_all_edge+1;++i) Free_One_Spr(tree->spr_list_all_edge[i]); + Free(tree->spr_list_all_edge); + tree = tree->next; } - Free(t->sum_p_one_site); + while(tree); - Free_Eigen(t->eigen_struct); - - Free(t); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Actual_CSeq(allseq *data) +void Free_Actual_CSeq(calign *data) { int i; - For(i,data->n_otu) + for(i=0;in_otu;i++) { Free(data->c_seq[i]->state); + Free(data->c_seq[i]->d_state); data->c_seq[i]->state = NULL; } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Free_Prefix_Tree(pnode *n, int size) { int i; - - For(i,size) + + for(i=0;inext[i]) - { - Free_Prefix_Tree(n->next[i],size); - } + { + Free_Prefix_Tree(n->next[i],size); + } } Free_Pnode(n); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Free_Pnode(pnode *n) { @@ -589,21 +1119,400 @@ void Free_Pnode(pnode *n) Free(n); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Optimiz(t_opt *s_opt) +{ + Free(s_opt); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Free_Rates(int n_otu, trate *r) +void Free_Nexus(option *io) +{ + int i,j; + + for(i=0;inex_com_list[i]->nparm) Free_Nexus_Parm(io->nex_com_list[i]->parm[j]); + Free(io->nex_com_list[i]->parm); + Free(io->nex_com_list[i]->name); + Free(io->nex_com_list[i]); + } + Free(io->nex_com_list); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Free_Nexus_Com(nexcom **com) { int i; - Free(r->br_r); - Free(r->lexp); + for(i=0;iparm); + Free(com[i]->name); + Free(com[i]); + } + Free(com); +} - For(i,n_otu) Free(r->mc_mr[i]); - Free(r->mc_mr); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - Free(r); +void Free_Nexus_Parm(nexparm *parm) +{ + Free(parm->value); + Free(parm->name); + Free(parm); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Free_XML_Tree(xml_node *node) +{ + if(!node) return; + if(node->child) XML_Free_XML_Tree(node->child); + if(node->next) XML_Free_XML_Tree(node->next); + XML_Free_XML_Node(node); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Free_XML_Node(xml_node *node) +{ + Free(node->id); + Free(node->name); + Free(node->value); + XML_Free_XML_Ds(node->ds); + XML_Free_XML_Attr(node->attr); + Free(node); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Free_XML_Attr(xml_attr *attr) +{ + if(attr) + { + Free(attr->name); + Free(attr->value); + if(attr->next) XML_Free_XML_Attr(attr->next); + Free(attr); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Free_XML_Ds(t_ds *ds) +{ + if(ds->next) XML_Free_XML_Ds(ds->next); + Free(ds); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Free_MCMC(t_mcmc *mcmc) +{ + int i; + + Free(mcmc->move_type); + Free(mcmc->adjust_tuning); + Free(mcmc->out_filename); + Free(mcmc->move_weight); + Free(mcmc->acc_move); + Free(mcmc->run_move); + Free(mcmc->prev_acc_move); + Free(mcmc->prev_run_move); + Free(mcmc->acc_rate); + Free(mcmc->tune_move); + for(i=0;in_moves;i++) Free(mcmc->move_name[i]); + Free(mcmc->move_name); + Free(mcmc->ess_run); + Free(mcmc->start_ess); + Free(mcmc->ess); + Free(mcmc->sampled_val); + Free(mcmc->mode); + Free(mcmc); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Free_Rates(t_rate *rates) +{ + if(rates->is_allocated == YES) + { + int i; + Free(rates->nd_r); + Free(rates->br_r); + Free(rates->buff_nd_r); + Free(rates->buff_br_r); + Free(rates->true_r); + Free(rates->buff_t); + Free(rates->nd_t); + Free(rates->true_t); + Free(rates->t_prior); + Free(rates->t_mean); + Free(rates->t_prior_min); + Free(rates->t_prior_max); + Free(rates->t_floor); + Free(rates->t_has_prior); + Free(rates->t_rank); + Free(rates->dens); + Free(rates->triplet); + Free(rates->n_jps); + Free(rates->t_jps); + Free(rates->cond_var); + Free(rates->invcov); + Free(rates->ml_l); + Free(rates->cur_l); + Free(rates->u_ml_l); + Free(rates->u_cur_l); + Free(rates->cov_r); + Free(rates->lca); + Free(rates->trip_cond_cov); + Free(rates->trip_reg_coeff); + Free(rates->_2n_vect1); + Free(rates->_2n_vect2); + Free(rates->_2n_vect3); + Free(rates->_2n_vect4); + Free(rates->_2n_vect5); + Free(rates->_2n2n_vect1); + Free(rates->_2n2n_vect2); + Free(rates->cov_l); + Free(rates->mean_l); + Free(rates->mean_r); + Free(rates->mean_t); + Free(rates->grad_l); + Free(rates->reg_coeff); + Free(rates->br_do_updt); + Free(rates->cur_gamma_prior_mean); + Free(rates->cur_gamma_prior_var); + Free(rates->n_tips_below); + Free(rates->time_slice_lims); + Free(rates->n_time_slice_spans); + Free(rates->curr_slice); + Free(rates->has_survived); + Free(rates->survival_rank); + Free(rates->survival_dur); + Free(rates->calib_prob); + Free(rates->t_prior_min_ori); + Free(rates->t_prior_max_ori); + Free(rates->times_partial_proba); + Free(rates->numb_calib_chosen); + for(i=0;in_cal;i++) Free_Calib(rates->a_cal[i]); + Free(rates->a_cal); + Free(rates->model_name); + } + Free(rates); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Calib(t_cal *cal) +{ + if(!cal) return; + else + { + int i; + for(i=0;iclade_list_size;i++) Free(cal->clade_list[i]); + Free(cal->clade_list); + Free(cal->id); + Free(cal->alpha_proba_list); + Free(cal); + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Free_Geo(t_geo *t) +{ + int i; + Free(t->f_mat); + Free(t->r_mat); + Free(t->occup); + Free(t->idx_loc); + Free(t->sorted_nd); + Free(t->cov); + Free(t->idx_loc_beneath); + for(i=0;ildscape_sz;i++) Free_Geo_Coord(t->coord_loc[i]); + Free(t->coord_loc); + Free(t); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Free_Geo_Coord(t_geo_coord *t) +{ + Free(t->cpy->lonlat); + Free(t->cpy->id); + Free(t->cpy); + + Free(t->lonlat); + Free(t->id); + Free(t); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Free_Disk(t_dsk *t) +{ + Free_Geo_Coord(t->centr); + Free(t->ldsk_a); + Free(t->id); + Free(t); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Free_Ldisk(t_ldsk *t) +{ + if(t == NULL) return; + else + { + Free(t->next); + Free_Geo_Coord(t->coord); + if(t->cpy_coord) Free_Geo_Coord(t->cpy_coord); + Free(t); + } + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Poly(t_poly *p) +{ + int i; + for(i=0;in_poly_vert;i++) Free_Geo_Coord(p->poly_vert[i]); + Free(p->poly_vert); + Free(p); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_Mmod(t_phyrex_mod *mmod) +{ + if(mmod == NULL) return; + Free_Geo_Coord(mmod->lim_up); + Free_Geo_Coord(mmod->lim_do); + Free(mmod); } -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void JSON_Free_Array(json_a *a) +{ + if(a->object) JSON_Free_Object(a->object); + Free(a); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void JSON_Free_Object(json_o *o) +{ + if(o->kv) JSON_Free_KeyVal(o->kv); + if(o->next) JSON_Free_Object(o->next); + Free(o); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void JSON_Free_KeyVal(json_kv *kv) +{ + if(kv->key) Free(kv->key); + if(kv->value) Free(kv->value); + if(kv->object) JSON_Free_Object(kv->object); + if(kv->array) JSON_Free_Array(kv->array); + if(kv->next) JSON_Free_KeyVal(kv->next); + Free(kv); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Free_NNI(t_nni *t) +{ + if(t->init_l) Free_Scalar_Dbl(t->init_l); + if(t->init_v) Free_Scalar_Dbl(t->init_v); + + if(t->best_l) Free_Scalar_Dbl(t->best_l); + if(t->best_v) Free_Scalar_Dbl(t->best_v); + + if(t->l0) Free_Scalar_Dbl(t->l0); + if(t->v0) Free_Scalar_Dbl(t->v0); + + if(t->l1) Free_Scalar_Dbl(t->l1); + if(t->v1) Free_Scalar_Dbl(t->v1); + + if(t->l2) Free_Scalar_Dbl(t->l2); + if(t->v2) Free_Scalar_Dbl(t->v2); + + Free(t); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Matrices used in transfer bootstrap computation (tbe.c) */ +void Free_TBE_Matrices(int n_otu, short unsigned*** i_matrix, short unsigned*** c_matrix, + short unsigned*** hamming, short unsigned** min_dist, + short unsigned** min_dist_edge, int** cluster_sizes){ + int i; + int nb_edges = 2*n_otu-3; + for (i=0; ikey); + Free(lab->val); + if(lab->next != NULL) Free_Label(lab->next); + Free(lab); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// diff --git a/phyml/free.h b/phyml/free.h index c36a523..a0096e1 100644 --- a/phyml/free.h +++ b/phyml/free.h @@ -10,41 +10,90 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef FREE_H #define FREE_H -void Free_All_Nodes_Light(arbre *tree); -void Free_All_Edges_Light(arbre *tree); +#include "utilities.h" + +void Free_All_Nodes_Light(t_tree *tree); +void Free_All_Edges_Light(t_tree *tree); void Free_Mat(matrix *mat); -void Free_Partial_Lk(phydbl ****p_lk, int len, int n_catg); -void Free_Tree(arbre *tree); -void Free_Edge(edge *b); -void Free_Node(node *n); -void Free_Cseq(allseq *alldata); -void Free_Seq(seq **d, int n_otu); -void Free_All(seq **d, allseq *alldata, arbre *tree); -void Free_SubTree(edge *b_fcus, node *a, node *d, arbre *tree); -void Free_Tree_Ins_Tar(arbre *tree); -void Free_Tree_Lk(arbre *tree); -void Free_NNI(arbre *tree); -void Free_Edge_P_Lk_Struct(edge *b, arbre *tree); -void Free_Node_Lk(node *n); -void Free_Edge_Lk(arbre *tree, edge *b); -void Free_Model(model *mod); +void Free_Partial_Lk(phydbl *p_lk,int len,int n_catg); +void Free_Tree(t_tree *tree); +void Free_Bip(t_tree *tree); +void Free_Edge(t_edge *b); +void Free_Node(t_node *n); +void Free_Calign(calign *data); +void Free_Seq(align **d,int n_otu); +void Free_All(align **d,calign *cdata,t_tree *tree); +void Free_SubTree(t_edge *b_fcus,t_node *a,t_node *d,t_tree *tree); +void Free_Tree_Ins_Tar(t_tree *tree); +void Free_Tree_Pars(t_tree *tree); +void Free_Edge_Pars(t_edge *b); +void Free_Edge_Pars_Left(t_edge *b); +void Free_Edge_Pars_Rght(t_edge *b); +void Free_Tree_Lk(t_tree *tree); +void Free_Node_Lk(t_node *n); +void Free_Edge_Lk(t_edge *b); +void Free_Model_Complete(t_mod *mod); +void Free_Model_Basic(t_mod *mod); +void Free_Custom_Model(t_mod *mod); +void Free_Efrq(t_efrq *e_frq); +void Free_Rmat(t_rmat *r_mat); +void Free_Model(t_mod *mod); void Free(void *p); -void Free_Input(option *input); -void Free_Reachable(arbre *tree); -void Free_St(superarbre *st); +void Free_Input(option *io); +void Free_Tree_List(t_treelist *list); +void Free_St(supert_tree *st); void Free_Eigen(eigen *eigen_struct); -void Free_Triplet(ttriplet *t); -void Free_Tree_Pars(arbre *tree); -void Free_Edge_Pars(edge *b, arbre *tree); -void Free_One_Spr(spr *this_spr); -void Free_Spr_List(arbre *tree); -void Free_Actual_CSeq(allseq *data); -void Free_Prefix_Tree(pnode *n, int size); +void Free_One_Spr(t_spr *this_spr); +void Free_Spr_List_One_Edge(t_tree *tree); +void Free_Spr_List_All_Edge(t_tree *mixt_tree); +void Free_Actual_CSeq(calign *data); +void Free_Prefix_Tree(pnode *n,int size); void Free_Pnode(pnode *n); -void Free_Edge_Labels(edge *b); -void Free_Rates(int n_otu, trate *r); - +void Free_Optimiz(t_opt *s_opt); +void Free_Nexus(option *io); +void Free_Nexus_Com(nexcom **com); +void Free_Nexus_Parm(nexparm *parm); +void Free_RAS(t_ras *ras); +void XML_Free_XML_Tree(xml_node *node); +void XML_Free_XML_Node(xml_node *node); +void XML_Free_XML_Attr(xml_attr *attr); +void XML_Free_XML_Ds(t_ds *ds); +void Free_String(t_string *ts); +void Free_Vect_Dbl(vect_dbl *v); +void Free_Vect_Int(vect_int *v); +void Free_Scalar_Dbl(scalar_dbl *v); +void Free_Scalar_Int(scalar_int *v); +void Free_Edge_Core(t_edge *b); +void RATES_Free_Rates(t_rate *rates); +void Free_Calib(t_cal *cal); +void Free_Edge_Lk_Left(t_edge *b); +void Free_Edge_Lk_Rght(t_edge *b); +void Free_Geo(t_geo *t); +void Free_Geo_Coord(t_geo_coord *t); +void Free_Disk(t_dsk *t); +void Free_Ldisk(t_ldsk *t); +void Free_Poly(t_poly *p); +void Free_Mmod(t_phyrex_mod *mmod); +void Free_Efrq_Weights(t_mod *mixt_mod); +void Free_Rmat_Weights(t_mod *mixt_mod); +void JSON_Free_KeyVal(json_kv *kv); +void JSON_Free_Object(json_o *o); +void JSON_Free_Array(json_a *a); +void Free_Edge_Loc_Rght(t_edge *b); +void Free_Edge_Loc_Left(t_edge *b); +void Free_Edge_Loc(t_edge *b); +void Free_NNI(t_nni *t); +void Free_Linked_List(t_ll *t); +void Free_TBE_Matrices(int n_otu, short unsigned*** i_matrix, short unsigned*** c_matrix, + short unsigned*** hamming, short unsigned** min_dist, + short unsigned** min_dist_edge, int** cluster_sizes); +void Free_Extra_Edge_Lk(t_tree *tree); +void Free_Edge_Length(t_edge *b); +void Free_Clade(t_clad *this); +void Free_Label(t_label *lab); #endif diff --git a/phyml/geo.c b/phyml/geo.c new file mode 100644 index 0000000..f8fcbf2 --- /dev/null +++ b/phyml/geo.c @@ -0,0 +1,1822 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + + +#include "geo.h" + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int GEO_Main(int argc, char **argv) +{ + /* GEO_Simulate_Estimate(argc,argv); */ + GEO_Estimate(argc,argv); + return(1); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int GEO_Estimate(int argc, char **argv) +{ + t_geo *t; + int seed; + FILE *fp; + t_tree *tree; + phydbl *ldscp; + int *loc_hash; + int i,j; + phydbl *probs; + phydbl sum; + + // geo ./ban + + + seed = getpid(); + /* seed = 28224; */ + /* seed = 21249; */ + /* seed = 21596; */ + + printf("\n. Seed = %d",seed); + srand(seed); + + t = GEO_Make_Geo_Basic(); + GEO_Init_Geo_Struct(t); + + fp = Openfile(argv[1],0); /* Open tree file */ + + tree = Read_Tree_File_Phylip(fp); /* Read it */ + + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + tree->rates = RATES_Make_Rate_Struct(tree->n_otu); + RATES_Init_Rate_Struct(tree->rates,NULL,tree->n_otu); + Branch_To_Time(tree); + + tree->geo = t; + + GEO_Read_In_Landscape(argv[2],t,&ldscp,&loc_hash,tree); + + GEO_Make_Geo_Complete(t->ldscape_sz,t->n_dim,tree->n_otu,t); + + + j = 0; + for(i=0;ildscape_sz;i++) + { + t->coord_loc[i]->lonlat[0] = ldscp[j]; + t->coord_loc[i]->lonlat[1] = ldscp[j+1]; + PhyML_Printf("\n. Location %d: %13f %13f",i+1,t->coord_loc[i]->lonlat[0],t->coord_loc[i]->lonlat[1]); + j+=2; + } + + for(i=0;in_otu;i++) t->idx_loc[i] = loc_hash[i]; + + t->cov[0*t->n_dim+0] = t->sigma; + t->cov[1*t->n_dim+1] = t->sigma; + t->cov[0*t->n_dim+1] = 0.0; + t->cov[1*t->n_dim+0] = 0.0; + + GEO_Get_Sigma_Max(t); + + t->max_sigma = t->sigma_thresh * 2.; + + PhyML_Printf("\n. Sigma max: %f",t->sigma_thresh); + + GEO_Get_Locations_Beneath(t,tree); + + probs = (phydbl *)mCalloc(tree->geo->ldscape_sz,sizeof(phydbl)); + + sum = 0.0; + for(i=0;igeo->ldscape_sz;i++) sum += tree->geo->idx_loc_beneath[tree->n_root->num * tree->geo->ldscape_sz + i]; + for(i=0;igeo->ldscape_sz;i++) probs[i] = tree->geo->idx_loc_beneath[tree->n_root->num * tree->geo->ldscape_sz + i]/sum; + tree->geo->idx_loc[tree->n_root->num] = Sample_i_With_Proba_pi(probs,tree->geo->ldscape_sz); + Free(probs); + + GEO_Randomize_Locations(tree->n_root,t,tree); + + + GEO_Update_Occup(t,tree); + GEO_Lk(t,tree); + + PhyML_Printf("\n. Init loglk: %f",tree->geo->c_lnL); + + /* DR_Draw_Tree("essai.ps",tree); */ + + GEO_MCMC(tree); + + fclose(fp); + Free(ldscp); + Free(loc_hash); + + return(1); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int GEO_Simulate_Estimate(int argc, char **argv) +{ + t_geo *t; + int n_tax; + t_tree *tree,*ori_tree; + int seed; + phydbl *res; + FILE *fp; + int pid; + char *s; + int rand_loc; + phydbl *probs,sum; + int i; + phydbl mantel_p_val; + phydbl rf; + + s = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + strcpy(s,"geo.out"); + pid = getpid(); + sprintf(s+strlen(s),".%d",pid); + + fp = fopen(s,"w"); + + seed = getpid(); + /* seed = 15520; */ + /* seed = 5023; */ + printf("\n. Seed = %d",seed); + srand(seed); + + t = GEO_Make_Geo_Basic(); + GEO_Init_Geo_Struct(t); + + /* t->tau = 3.0; */ + /* t->lbda = 0.02; */ + /* t->sigma = 10.; */ + + + t->ldscape_sz = (int)atoi(argv[1]); + t->n_dim = 2; + n_tax = (int)atoi(argv[2]); + + GEO_Make_Geo_Complete(t->ldscape_sz,t->n_dim,n_tax,t); + + t->cov[0*t->n_dim+0] = t->sigma; + t->cov[1*t->n_dim+1] = t->sigma; + t->cov[0*t->n_dim+1] = 0.0; + t->cov[1*t->n_dim+0] = 0.0; + + GEO_Simulate_Coordinates(t->ldscape_sz,t); + + GEO_Get_Sigma_Max(t); + + t->max_sigma = t->sigma_thresh * 2.; + + PhyML_Printf("\n. sigma max: %f threshold: %f",t->max_sigma,t->sigma_thresh); + + /* t->tau = Uni()*(t->max_tau/100.-t->min_tau*10.) + t->min_tau*10.; */ + /* t->lbda = exp(Uni()*(log(t->max_lbda/100.)-log(t->min_lbda*10.)) + log(t->min_lbda*10.)); */ + /* t->sigma = Uni()*(t->max_sigma-t->min_sigma) + t->min_sigma; */ + + t->lbda = 1.; + t->sigma = 0.3; + t->tau = 1.; + + PhyML_Fprintf(fp,"\n# SigmaTrue\t SigmaThresh\t LbdaTrue\t TauTrue\txTrue\t yTrue\t xRand\t yRand\t RF\t Sigma5\t Sigma50\t Sigma95\t ProbSigmaInfThresh\t Lbda5\t Lbda50\t Lbda95\t ProbLbdaInf1\t Tau5\t Tau50\t Tau95\t X5\t X50\t X95\t Y5\t Y50\t Y95\t RandX5\t RandX50\t RandX95\t RandY5\t RandY50\t RandY95\t Mantel\t"); + PhyML_Fprintf(fp,"\n"); + + tree = GEO_Simulate(t,n_tax); + + ori_tree = Make_Tree_From_Scratch(tree->n_otu,NULL); + Copy_Tree(tree,ori_tree); + + Random_SPRs_On_Rooted_Tree(tree); + + Free_Bip(ori_tree); + Alloc_Bip(ori_tree); + Get_Bip(ori_tree->a_nodes[0],ori_tree->a_nodes[0]->v[0],ori_tree); + + Free_Bip(tree); + Alloc_Bip(tree); + Get_Bip(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + Match_Tip_Numbers(tree,ori_tree); + + rf = (phydbl)Compare_Bip(ori_tree,tree,NO)/(tree->n_otu-3); + PhyML_Printf("\n. rf: %f",rf); + + phydbl scale; + scale = exp(Rnorm(0,0.2)); + PhyML_Printf("\n. Scale: %f",scale); + For(i,2*tree->n_otu-1) tree->rates->nd_t[i] *= scale; + + + phydbl *tree_dist,*geo_dist; + int j; + + Time_To_Branch(tree); + tree_dist = Dist_Btw_Tips(tree); + + geo_dist = (phydbl *)mCalloc(tree->n_otu*tree->n_otu,sizeof(phydbl)); + + for(i=0;in_otu;i++) + { + for(j=0;jn_otu;j++) + { + /* geo_dist[i*tree->n_otu+j] = */ + /* FABS(t->ldscape[t->idx_loc[i]*t->n_dim+0] - */ + /* t->ldscape[t->idx_loc[j]*t->n_dim+0])+ */ + /* FABS(t->ldscape[t->idx_loc[i]*t->n_dim+1] - */ + /* t->ldscape[t->idx_loc[j]*t->n_dim+1]); */ + geo_dist[i*tree->n_otu+j] = + FABS(t->coord_loc[t->idx_loc[i]]->lonlat[0] - + t->coord_loc[t->idx_loc[j]]->lonlat[0])+ + FABS(t->coord_loc[t->idx_loc[i]]->lonlat[1] - + t->coord_loc[t->idx_loc[j]]->lonlat[1]); + + } + } + + printf("\n. tau: %f lbda: %f sigma: %f",t->tau,t->lbda,t->sigma); + mantel_p_val = Mantel(tree_dist,geo_dist,tree->n_otu,tree->n_otu); + printf("\n. Mantel test p-value: %f",mantel_p_val); + + Free(tree_dist); + Free(geo_dist); + + rand_loc = Rand_Int(0,t->ldscape_sz-1); + + PhyML_Printf("\n. sigma: %f\t lbda: %f\t tau:%f\t x:%f\t y:%f rand.x:%f\t rand.y:%f\t", + t->sigma, + t->lbda, + t->tau, + /* t->ldscape[t->idx_loc[tree->n_root->num]*t->n_dim+0], */ + /* t->ldscape[t->idx_loc[tree->n_root->num]*t->n_dim+1], */ + /* t->ldscape[rand_loc*t->n_dim+0], */ + /* t->ldscape[rand_loc*t->n_dim+1]); */ + t->coord_loc[t->idx_loc[tree->n_root->num]]->lonlat[0], + t->coord_loc[t->idx_loc[tree->n_root->num]]->lonlat[1], + t->coord_loc[rand_loc]->lonlat[0], + t->coord_loc[rand_loc]->lonlat[1]); + + PhyML_Fprintf(fp,"%f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t", + t->sigma, + t->sigma_thresh, + t->lbda, + t->tau, + t->coord_loc[t->idx_loc[tree->n_root->num]]->lonlat[0], + t->coord_loc[t->idx_loc[tree->n_root->num]]->lonlat[1], + t->coord_loc[rand_loc]->lonlat[0], + t->coord_loc[rand_loc]->lonlat[1], + rf); + + GEO_Get_Locations_Beneath(t,tree); + + probs = (phydbl *)mCalloc(tree->geo->ldscape_sz,sizeof(phydbl)); + + sum = 0.0; + for(i=0;igeo->ldscape_sz;i++) sum += tree->geo->idx_loc_beneath[tree->n_root->num * tree->geo->ldscape_sz + i]; + for(i=0;igeo->ldscape_sz;i++) probs[i] = tree->geo->idx_loc_beneath[tree->n_root->num * tree->geo->ldscape_sz + i]/sum; + tree->geo->idx_loc[tree->n_root->num] = Sample_i_With_Proba_pi(probs,tree->geo->ldscape_sz); + Free(probs); + GEO_Randomize_Locations(tree->n_root,tree->geo,tree); + + GEO_Update_Occup(t,tree); + GEO_Lk(t,tree); + PhyML_Printf("\n. Init loglk: %f",tree->geo->c_lnL); + + + res = GEO_MCMC(tree); + + PhyML_Fprintf(fp,"%f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f \n", + + /* Sigma5 */ Quantile(res+0*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.025), + /* Sigma50*/ Quantile(res+0*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.50), + /* Sigma95*/ Quantile(res+0*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.975), + + /* ProbInfThesh */ Prob(res+0*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval,t->sigma_thresh), + + /* Lbda5 */ Quantile(res+1*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.025), + /* Lbda50 */ Quantile(res+1*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.50), + /* Lbda95 */ Quantile(res+1*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.975), + + /* ProbInf1 */ Prob(res+1*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval,1.0), + + /* Tau5 */ Quantile(res+2*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.025), + /* Tau50 */ Quantile(res+2*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.50), + /* Tau 95 */ Quantile(res+2*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.975), + + /* X5 */ Quantile(res+4*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.025), + /* X50 */ Quantile(res+4*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.50), + /* X95 */ Quantile(res+4*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.975), + + /* Y5 */ Quantile(res+5*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.025), + /* Y50 */ Quantile(res+5*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.50), + /* Y95 */ Quantile(res+5*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.975), + + /* RandX5 */ Quantile(res+6*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.025), + /* RandX50*/ Quantile(res+6*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.50), + /* RandX95*/ Quantile(res+6*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.975), + + /* RandY5 */ Quantile(res+7*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.025), + /* RandY50*/ Quantile(res+7*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.50), + /* RandY95*/ Quantile(res+7*tree->mcmc->chain_len / tree->mcmc->sample_interval,tree->mcmc->run / tree->mcmc->sample_interval+1,0.975), + + mantel_p_val + ); + fflush(NULL); + + Free(s); + Free(res); + + fclose(fp); + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl *GEO_MCMC(t_tree *tree) +{ + phydbl *res; + int n_vars; + int rand_loc; + t_geo *t; + + t = tree->geo; + + tree->mcmc = MCMC_Make_MCMC_Struct(); + MCMC_Complete_MCMC(tree->mcmc,tree); + + tree->mcmc->io = NULL; + tree->mcmc->is = NO; + tree->mcmc->run = 0; + tree->mcmc->sample_interval = 1E+3; + tree->mcmc->chain_len = 1E+6; + tree->mcmc->chain_len_burnin = 1E+5; + tree->mcmc->randomize = YES; + tree->mcmc->norm_freq = 1E+3; + tree->mcmc->max_tune = 1.E+20; + tree->mcmc->min_tune = 1.E-10; + tree->mcmc->print_every = 2; + tree->mcmc->is_burnin = NO; + tree->mcmc->nd_t_digits = 1; + + t->tau = 1.0; + t->lbda = 1.0; + t->sigma = 1.0; + t->dum = 1.0; + + tree->mcmc->chain_len = 1.E+8; + tree->mcmc->sample_interval = 50; + + MCMC_Complete_MCMC(tree->mcmc,tree); + + GEO_Update_Occup(t,tree); + GEO_Lk(t,tree); + + tree->mcmc->start_ess[tree->mcmc->num_move_geo_sigma] = YES; + tree->mcmc->start_ess[tree->mcmc->num_move_geo_lambda] = YES; + tree->mcmc->start_ess[tree->mcmc->num_move_geo_tau] = YES; + tree->mcmc->start_ess[tree->mcmc->num_move_geo_dum] = YES; + + n_vars = 10; + res = (phydbl *)mCalloc(tree->mcmc->chain_len / tree->mcmc->sample_interval * n_vars,sizeof(phydbl)); + + PhyML_Printf("\n. Run Sigma [ESS] Lambda [ESS] Tau [ESS] Dummy [ESS] LogLk"); + + tree->mcmc->run = 0; + do + { + MCMC_GEO_Lbda(tree); + MCMC_GEO_Tau(tree); + /* MCMC_Geo_Dum(tree); */ + MCMC_GEO_Loc(tree); + + t->update_fmat = YES; + MCMC_GEO_Sigma(tree); + t->update_fmat = NO; + + + /* t->update_fmat = YES; */ + /* MCMC_Geo_Updown_Lbda_Sigma(tree); */ + /* t->update_fmat = NO; */ + + + /* MCMC_Geo_Updown_Tau_Lbda(tree); */ + /* MCMC_Geo_Updown_Tau_Lbda(tree); */ + /* MCMC_Geo_Updown_Tau_Lbda(tree); */ + + + /* printf("\n"); */ + /* int i; */ + /* For(i,2*tree->n_otu-1) */ + /* { */ + /* if(tree->a_nodes[i]->tax == NO) */ + /* { */ + /* printf("%2d ",tree->geo->idx_loc[i]); */ + /* } */ + /* } */ + + + if(tree->mcmc->run%tree->mcmc->sample_interval == 0) + { + MCMC_Copy_To_New_Param_Val(tree->mcmc,tree); + + MCMC_Update_Effective_Sample_Size(tree->mcmc->num_move_geo_lambda,tree->mcmc,tree); + MCMC_Update_Effective_Sample_Size(tree->mcmc->num_move_geo_sigma,tree->mcmc,tree); + MCMC_Update_Effective_Sample_Size(tree->mcmc->num_move_geo_tau,tree->mcmc,tree); + + /* printf("\n. lbda:%f,%f tau:%f,%f sigma:%f,%f", */ + /* tree->mcmc->acc_rate[tree->mcmc->num_move_geo_lambda], */ + /* tree->mcmc->tune_move[tree->mcmc->num_move_geo_lambda], */ + /* tree->mcmc->acc_rate[tree->mcmc->num_move_geo_tau], */ + /* tree->mcmc->tune_move[tree->mcmc->num_move_geo_tau], */ + /* tree->mcmc->acc_rate[tree->mcmc->num_move_geo_sigma], */ + /* tree->mcmc->tune_move[tree->mcmc->num_move_geo_sigma]); */ + + PhyML_Printf("\n. %6d %12f %4.0f %12f %4.0f %12f %4.0f %12f %4.0f %12f", + tree->mcmc->run, + + t->sigma, + tree->mcmc->ess[tree->mcmc->num_move_geo_sigma], + + t->lbda, + tree->mcmc->ess[tree->mcmc->num_move_geo_lambda], + + t->tau, + tree->mcmc->ess[tree->mcmc->num_move_geo_tau], + + t->dum, + tree->mcmc->ess[tree->mcmc->num_move_geo_dum], + + t->c_lnL); + + + /* PhyML_Printf("\n%12f %12f %12f %12f", */ + /* t->sigma, */ + /* t->lbda, */ + /* t->tau, */ + /* t->dum); */ + + + rand_loc = Rand_Int(0,t->ldscape_sz-1); + + res[0 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->sigma; + res[1 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->lbda; + res[2 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->tau; + res[3 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->c_lnL; + + /* res[4 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->ldscape[t->idx_loc[tree->n_root->num]*t->n_dim+0]; */ + /* res[5 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->ldscape[t->idx_loc[tree->n_root->num]*t->n_dim+1]; */ + res[4 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->coord_loc[t->idx_loc[tree->n_root->num]]->lonlat[0]; + res[5 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->coord_loc[t->idx_loc[tree->n_root->num]]->lonlat[1]; + + /* res[6 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->ldscape[rand_loc*t->n_dim+0]; */ + /* res[7 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->ldscape[rand_loc*t->n_dim+1]; */ + res[6 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->coord_loc[rand_loc]->lonlat[0]; + res[7 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = t->coord_loc[rand_loc]->lonlat[1]; + } + + tree->mcmc->run++; + + if(tree->mcmc->ess[tree->mcmc->num_move_geo_sigma] > 200.) tree->mcmc->adjust_tuning[tree->mcmc->num_move_geo_sigma] = NO; + if(tree->mcmc->ess[tree->mcmc->num_move_geo_tau] > 200.) tree->mcmc->adjust_tuning[tree->mcmc->num_move_geo_tau] = NO; + if(tree->mcmc->ess[tree->mcmc->num_move_geo_lambda]> 200.) tree->mcmc->adjust_tuning[tree->mcmc->num_move_geo_lambda] = NO; + + MCMC_Get_Acc_Rates(tree->mcmc); + + if(tree->mcmc->ess[tree->mcmc->num_move_geo_sigma] > 1000. && + tree->mcmc->ess[tree->mcmc->num_move_geo_tau] > 1000. && + tree->mcmc->ess[tree->mcmc->num_move_geo_lambda]> 1000.) break; + } + while(tree->mcmc->run < tree->mcmc->chain_len); + + return(res); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// Update F matrix. Assume a diagonal covariance matrix. +void GEO_Update_Fmat(t_geo *t) +{ + phydbl *loc1, *loc2; + int i,j,k; + int err; + phydbl lognloc; + + for(i=0;in_dim;i++) t->cov[i*t->n_dim+i] = t->sigma; // Diagonal covariance matrix. Same variance in every direction + + lognloc = log(t->ldscape_sz); + + // Fill in F matrix; + for(i=0;ildscape_sz;i++) + { + loc1 = t->coord_loc[i]->lonlat; + + for(j=i;jldscape_sz;j++) + { + loc2 = t->coord_loc[j]->lonlat; + + t->f_mat[i*t->ldscape_sz+j] = .0; + + // Calculate log(f(l_i,l_j)) - log(f(l_i,l_i) - log(m) + for(k=0;kn_dim;k++) t->f_mat[i*t->ldscape_sz+j] += Log_Dnorm(loc2[k],loc1[k],t->cov[k*t->n_dim+k],&err); + t->f_mat[i*t->ldscape_sz+j] -= lognloc; + for(k=0;kn_dim;k++) t->f_mat[i*t->ldscape_sz+j] -= Log_Dnorm(loc1[k],loc1[k],t->cov[k*t->n_dim+k],&err); + + // Take the exponential + t->f_mat[i*t->ldscape_sz+j] = exp(t->f_mat[i*t->ldscape_sz+j]); + + // Matrix is symmetric + t->f_mat[j*t->ldscape_sz+i] = t->f_mat[i*t->ldscape_sz+j]; + + /* printf("\n. f[%d,%d] = %f (1:[%f;%f] 2:[%f;%f]) sigma=%f",i,j,t->f_mat[i*t->ldscape_sz+j],loc1[0],loc1[1],loc2[0],loc2[1],SQRT(t->cov[0*t->n_dim+0])); */ + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// Sort node heights from oldest to youngest age. +void GEO_Update_Sorted_Nd(t_geo *t, t_tree *tree) +{ + int i; + int swap; + t_node *buff; + + buff = NULL; + + For(i,2*tree->n_otu-1) t->sorted_nd[i] = tree->a_nodes[i]; + + // Bubble sort of the node heights + do + { + swap = NO; + For(i,2*tree->n_otu-2) + { + if(tree->rates->nd_t[t->sorted_nd[i+1]->num] < tree->rates->nd_t[t->sorted_nd[i]->num]) + { + buff = t->sorted_nd[i]; + t->sorted_nd[i] = t->sorted_nd[i+1]; + t->sorted_nd[i+1] = buff; + + swap = YES; + } + } + } + while(swap == YES); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// Update the set of vectors of occupation along the tree +void GEO_Update_Occup(t_geo *t, t_tree *tree) +{ + int i,j; + t_node *v1, *v2; + + GEO_Update_Sorted_Nd(t,tree); + + For(i,t->ldscape_sz*(2*tree->n_otu-1)) t->occup[i] = 0; + + t->occup[tree->n_root->num*t->ldscape_sz + t->idx_loc[tree->n_root->num]] = 1; + + for(i=1;i<2*tree->n_otu-1;i++) + { + for(j=0;jldscape_sz;j++) + { + t->occup[t->sorted_nd[i]->num*t->ldscape_sz + j] = + t->occup[t->sorted_nd[i-1]->num*t->ldscape_sz + j]; + } + + + if(t->sorted_nd[i-1]->tax == NO) + { + v1 = v2 = NULL; + if(t->sorted_nd[i-1] == tree->n_root) + { + v1 = tree->n_root->v[1]; + v2 = tree->n_root->v[2]; + } + else + { + for(j=0;j<3;j++) + { + if(t->sorted_nd[i-1]->v[j] != t->sorted_nd[i-1]->anc && + t->sorted_nd[i-1]->b[j] != tree->e_root) + { + if(!v1) v1 = t->sorted_nd[i-1]->v[j]; + else v2 = t->sorted_nd[i-1]->v[j]; + } + } + } + + + if(t->idx_loc[v1->num] != t->idx_loc[t->sorted_nd[i-1]->num]) + { + t->occup[t->sorted_nd[i]->num * t->ldscape_sz + t->idx_loc[v1->num]]++; + } + else + { + t->occup[t->sorted_nd[i]->num * t->ldscape_sz + t->idx_loc[v2->num]]++; + } + } + } + + /* printf("\n"); */ + /* For(i,2*tree->n_otu-1) */ + /* { */ + /* printf("\n. Node %3d: ",t->sorted_nd[i]->num); */ + /* for(j=0;jldscape_sz;j++) */ + /* { */ + /* /\* printf("%3d [%12f;%12f] ", *\/ */ + /* /\* t->occup[t->sorted_nd[i]->num*t->ldscape_sz + j], *\/ */ + /* /\* t->ldscape[j*t->n_dim+0],t->ldscape[j*t->n_dim+1]); *\/ */ + /* /\* printf("%3d ", *\/ */ + /* /\* t->occup[t->sorted_nd[i]->num*t->ldscape_sz + j]); *\/ */ + /* } */ + /* } */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// Calculate R mat at node n +void GEO_Update_Rmat(t_node *n, t_geo *t, t_tree *tree) +{ + int i,j; + phydbl lbda_j; + + for(i=0;ildscape_sz;i++) + { + for(j=0;jldscape_sz;j++) + { + lbda_j = ((t->occup[n->num*t->ldscape_sz + j]==0) ? (1.0) : (t->lbda)); + t->r_mat[i*t->ldscape_sz+j] = t->f_mat[i*t->ldscape_sz+j] * lbda_j * t->tau * t->dum; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl GEO_Lk(t_geo *t, t_tree *tree) +{ + int i,j; + phydbl loglk; + phydbl R; + int dep,arr; // departure and arrival location indices; + t_node *curr_n,*prev_n,*v1,*v2; + phydbl sum; + + GEO_Update_Occup(t,tree); // Same here. + + if(t->update_fmat == YES) GEO_Update_Fmat(t); + + prev_n = NULL; + curr_n = NULL; + loglk = .0; + for(i=1;in_otu-1;i++) // Consider all the time slices, from oldest to youngest. + // Start at first node below root + { + prev_n = t->sorted_nd[i-1]; // node just above + curr_n = t->sorted_nd[i]; // current node + + GEO_Update_Rmat(curr_n,t,tree); // NOTE: don't need to do that every time. Add check later. + + R = GEO_Total_Migration_Rate(curr_n,t); // Total migration rate calculated at node n + + /* if(i < 2) */ + /* { */ + /* printf("\n. t0: %f t1: %f R: %f tau: %f sigma: %f lbda: %f x1: %f y1: %f x2: %f y2: %f log0: %d loc1: %d rij: %G fij: %G", */ + /* tree->rates->nd_t[t->sorted_nd[i-1]->num], */ + /* tree->rates->nd_t[t->sorted_nd[i]->num], */ + /* R, */ + /* t->tau, */ + /* t->lbda, */ + /* t->sigma, */ + /* t->ldscape[t->idx_loc[tree->geo->sorted_nd[i-1]->num]*t->n_dim+0], */ + /* t->ldscape[t->idx_loc[tree->geo->sorted_nd[i-1]->num]*t->n_dim+1], */ + /* t->ldscape[t->idx_loc[tree->geo->sorted_nd[i]->num]*t->n_dim+0], */ + /* t->ldscape[t->idx_loc[tree->geo->sorted_nd[i]->num]*t->n_dim+1], */ + /* t->idx_loc[tree->geo->sorted_nd[i-1]->num], */ + /* t->idx_loc[tree->geo->sorted_nd[i]->num], */ + /* t->r_mat[t->idx_loc[tree->geo->sorted_nd[i-1]->num] * t->ldscape_sz + t->idx_loc[tree->geo->sorted_nd[i]->num]], */ + /* t->f_mat[t->idx_loc[tree->geo->sorted_nd[i-1]->num] * t->ldscape_sz + t->idx_loc[tree->geo->sorted_nd[i]->num]] */ + /* ); */ + + /* printf("\n >> "); */ + /* int j; */ + /* for(j=0;jldscape_sz;j++) */ + /* if(t->occup[t->sorted_nd[i]->num * t->ldscape_sz + j] > 0) */ + /* printf("%f %f -- ", */ + /* t->ldscape[j*t->n_dim+0], */ + /* t->ldscape[j*t->n_dim+1]); */ + /* } */ + + + /* printf("\n. %d %d (%d) %f %p %p \n",i,curr_n->num,curr_n->tax,tree->rates->nd_t[curr_n->num],curr_n->v[1],curr_n->v[2]); */ + + v1 = v2 = NULL; + for(j=0;j<3;j++) + if(curr_n->v[j] != curr_n->anc && curr_n->b[j] != tree->e_root) + { + if(!v1) v1 = curr_n->v[j]; + else v2 = curr_n->v[j]; + } + + dep = t->idx_loc[curr_n->num]; // departure location + arr = // arrival location + (t->idx_loc[v1->num] == t->idx_loc[curr_n->num] ? + t->idx_loc[v2->num] : + t->idx_loc[v1->num]); + + /* printf("\n%f\t%f", */ + /* t->ldscape[arr*t->n_dim+0]-t->ldscape[dep*t->n_dim+0], */ + /* t->ldscape[arr*t->n_dim+1]-t->ldscape[dep*t->n_dim+1]); */ + + loglk -= R * FABS(tree->rates->nd_t[curr_n->num] - tree->rates->nd_t[prev_n->num]); + loglk += log(t->r_mat[dep * t->ldscape_sz + arr]); + + /* printf("\n <> %d %f %f %d %d v1:%d v2:%d anc:%d %d %d %d", */ + /* curr_n->num, */ + /* R * FABS(tree->rates->nd_t[curr_n->num] - tree->rates->nd_t[prev_n->num]), */ + /* log(t->r_mat[dep * t->ldscape_sz + arr]), */ + /* dep,arr,v1->num,v2->num,curr_n->anc->num,curr_n->v[0]->num,curr_n->v[1]->num,curr_n->v[2]->num); */ + + /* if(i<2) */ + /* { */ + /* printf("\n. R = %f r_mat = %f f_mat = %f dt = %f loglk = %f", */ + /* R, */ + /* t->r_mat[dep * t->ldscape_sz + arr], */ + /* t->f_mat[dep * t->ldscape_sz + arr], */ + /* FABS(t->sorted_nd[i] - t->sorted_nd[i-1]),loglk); */ + /* Exit("\n"); */ + /* } */ + + } + + + // Likelihood for the first 'slice' (i.e., the part just below the root down to + // the next node) + GEO_Update_Rmat(tree->n_root,t,tree); + + loglk -= log(t->ldscape_sz); + dep = t->idx_loc[tree->n_root->num]; + arr = + (t->idx_loc[tree->n_root->num] != t->idx_loc[tree->n_root->v[1]->num] ? + t->idx_loc[tree->n_root->v[1]->num] : + t->idx_loc[tree->n_root->v[2]->num]); + + /* printf("\n %f %f",t->ldscape[dep],t->ldscape[arr]); */ + + loglk += log(t->r_mat[dep * t->ldscape_sz + arr]); + + sum = .0; + for(i=0;ildscape_sz;i++) sum += t->r_mat[dep * t->ldscape_sz + i]; + + loglk -= log(sum); + + tree->geo->c_lnL = loglk; + + return loglk; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Init_Tloc_Tips(t_geo *t, t_tree *tree) +{ + int i; + + // TO DO + for(i=0;in_otu;i++) + { + t->idx_loc[i] = i; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// Do not forget to call GEO_Update_Rmat (with node n) before calling this function +phydbl GEO_Total_Migration_Rate(t_node *n, t_geo *t) +{ + phydbl R; + int i,j; + + R = .0; + + for(i=0;ildscape_sz;i++) + { + for(j=0;jldscape_sz;j++) + { + R += + t->r_mat[i * t->ldscape_sz + j] * + t->occup[n->num * t->ldscape_sz + i]; + } + } + + return R; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// Find the arrival location for the migration leaving from n +int GEO_Get_Arrival_Location(t_node *n, t_geo *t, t_tree *tree) +{ + int i; + t_node *v1, *v2; // the two daughters of n + + v1 = v2 = NULL; + + for(i=0;i<3;i++) + { + if(n->v[i] && n->v[i] != n->anc) + { + if(!v1) v1 = n->v[i]; + else v2 = n->v[i]; + } + } + + if(t->idx_loc[v1->num] == t->idx_loc[v2->num]) // Migrated to the same location as that of n + { + if(t->idx_loc[n->num] != t->idx_loc[v1->num]) + { + PhyML_Printf("\n== Error detected in location labeling."); + PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + else + return t->idx_loc[n->num]; + } + else // Migrated to a different spot + { + if((t->idx_loc[v1->num] != t->idx_loc[n->num]) && (t->idx_loc[v2->num] != t->idx_loc[n->num])) + { + PhyML_Printf("\n== Error detected in location labeling."); + PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + else + { + if(t->idx_loc[v1->num] == t->idx_loc[n->num]) return t->idx_loc[v2->num]; // v2 gets the new location, v1 inheritates from n + else return t->idx_loc[v1->num]; // v1 gets the new location, v2 inheritates from n + } + } + return -1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_tree *GEO_Simulate(t_geo *t, int n_otu) +{ + t_tree *tree; + int n_branching_nodes; + t_node **branching_nodes; // vector of nodes available for branching out + phydbl *p_branch; // p_branch[i]: proba that the i-th node in branching_nodes branches out (p_x vector in the article) + phydbl *p_mig; // p_branch[i]: proba of migrating to location i from the location of the edge branching out (q_i vector in the article) + int hit; + phydbl time; + int dep, arr; + int i,j; + phydbl sum; + phydbl R; + int *occup; // occupation vector. Updated as we move down the tree + int nd_idx; + t_node *buff_nd; + phydbl buff_t; + int buff_l; + int swap; + + tree = Make_Tree_From_Scratch(n_otu,NULL); + tree->rates = RATES_Make_Rate_Struct(tree->n_otu); + RATES_Init_Rate_Struct(tree->rates,NULL,tree->n_otu); + tree->n_root = tree->a_nodes[2*tree->n_otu-2]; // Set the root node to the last element in the list of nodes + tree->geo = t; + + + For(i,2*tree->n_otu-2) tree->rates->nd_t[i] = -1.; + + occup = (int *)mCalloc(t->ldscape_sz,sizeof(int)); + + GEO_Update_Fmat(t); + + branching_nodes = (t_node **)mCalloc(tree->n_otu,sizeof(t_node *)); + branching_nodes[0] = tree->n_root; + n_branching_nodes = 1; + nd_idx = 0; + + + p_branch = (phydbl *)mCalloc(tree->n_otu,sizeof(phydbl )); + p_branch[0] = 1.0; + + p_mig = (phydbl *)mCalloc(t->ldscape_sz,sizeof(phydbl )); + + time = 0.0; // Time at the root node (this will be changed afterward) + + // Sample a location uniformly for the root + t->idx_loc[tree->n_root->num] = Rand_Int(0,t->ldscape_sz-1); + + // Update the occupancy vector + occup[t->idx_loc[tree->n_root->num]] = 1; + + dep = arr = -1; + + + // total migration rate + R = 0.0; + for(i=0;ildscape_sz;i++) + { + R += + t->f_mat[t->idx_loc[tree->n_root->num]*t->ldscape_sz+i] * + ((occup[i] == 0) ? (1.0) : (t->lbda)) * + t->tau * t->dum; + } + + do + { + // Select the node that branches out + hit = Sample_i_With_Proba_pi(p_branch,n_branching_nodes); + + /* printf("\n. [%d] Select node %d (location %d)",n_branching_nodes,branching_nodes[hit]->num,t->idx_loc[branching_nodes[hit]->num]); */ + + // Set the time for the branching node + tree->rates->nd_t[branching_nodes[hit]->num] = time; + + + /* printf("\n. Set its time to %f",time); */ + + // Select the destination location + dep = t->idx_loc[branching_nodes[hit]->num]; // Departure point + + sum = .0; + for(i=0;ildscape_sz;i++) // Total rate of migration out of departure point + { + p_mig[i] = + t->f_mat[dep*t->ldscape_sz+i] * + ((occup[i] == 0) ? (1.0) : (t->lbda)) * + t->tau * t->dum; + + sum += p_mig[i]; + } + for(i=0;ildscape_sz;i++) p_mig[i] /= sum; + + arr = Sample_i_With_Proba_pi(p_mig,t->ldscape_sz); + + /* printf("\n. Migrate from %d [%5.2f,%5.2f] to %d [%5.2f,%5.2f]", */ + /* dep, */ + /* t->ldscape[dep*t->n_dim+0], */ + /* t->ldscape[dep*t->n_dim+1], */ + /* arr, */ + /* t->ldscape[arr*t->n_dim+0], */ + /* t->ldscape[arr*t->n_dim+1]); */ + + /* printf("\n%f\t%f", */ + /* t->ldscape[arr*t->n_dim+0]-t->ldscape[dep*t->n_dim+0], */ + /* t->ldscape[arr*t->n_dim+1]-t->ldscape[dep*t->n_dim+1]); */ + + + // Update vector of occupation + occup[arr]++; + + /* printf("\n. Remove %d. Add %d and %d",branching_nodes[hit]->num,tree->a_nodes[nd_idx]->num,tree->a_nodes[nd_idx+1]->num); */ + // Connect two new nodes to the node undergoing a branching event + tree->a_nodes[nd_idx]->v[0] = branching_nodes[hit]; + tree->a_nodes[nd_idx+1]->v[0] = branching_nodes[hit]; + branching_nodes[hit]->v[1] = tree->a_nodes[nd_idx]; + branching_nodes[hit]->v[2] = tree->a_nodes[nd_idx+1]; + + // update branching_nodes vector. Element 'hit' is being replaced so that the corresponding node can no longer branch out + branching_nodes[hit] = tree->a_nodes[nd_idx]; + branching_nodes[n_branching_nodes] = tree->a_nodes[nd_idx+1]; + + // Update t_loc vector. + t->idx_loc[tree->a_nodes[nd_idx]->num] = dep; + t->idx_loc[tree->a_nodes[nd_idx+1]->num] = arr; + + // Update total migration rate + R = .0; + for(i=0;ildscape_sz;i++) + { + if(occup[i] > 0) + { + for(j=0;jldscape_sz;j++) + { + R += + occup[i] * + t->f_mat[i*t->ldscape_sz+j] * + ((occup[j] == 0) ? (1.0) : (t->lbda)) * + t->tau * t->dum; + } + } + } + + // Set the time until next branching event + time = time + Rexp(R); + + // Update p_branch vector + For(i,n_branching_nodes+1) + { + dep = t->idx_loc[branching_nodes[i]->num]; + p_branch[i] = 0.0; + for(j=0;jldscape_sz;j++) + { + p_branch[i] += + t->f_mat[dep*t->ldscape_sz+j] * + ((occup[j] == 0) ? (1.0) : (t->lbda)) * + t->tau * t->dum / R; + + /* printf("\n. %f %f %f %f", */ + /* R, */ + /* t->f_mat[dep*t->ldscape_sz+j], */ + /* ((occup[j]>0) ? (t->lbda) : (1.0)), */ + /* t->tau); */ + } + /* printf("\n. %f ",p_branch[i]); */ + } + + + // Increase the number of branching nodes by one (you just added 2 new and removed 1 old) + n_branching_nodes++; + nd_idx += 2; + + } + while(n_branching_nodes < n_otu); + + + // Set the times at the tips + For(i,2*tree->n_otu-1) if(tree->rates->nd_t[i] < 0.0) tree->rates->nd_t[i] = time; + + // Reverse time scale + For(i,2*tree->n_otu-1) tree->rates->nd_t[i] -= time; + /* For(i,2*tree->n_otu-1) tree->rates->nd_t[i] = FABS(tree->rates->nd_t[i]); */ + + // Bubble sort to put all the tips at the top of the tree->a_nodes array + do + { + swap = NO; + For(i,2*tree->n_otu-2) + { + if(!tree->a_nodes[i+1]->v[1] && tree->a_nodes[i]->v[1]) + { + buff_nd = tree->a_nodes[i+1]; + tree->a_nodes[i+1] = tree->a_nodes[i]; + tree->a_nodes[i] = buff_nd; + + buff_t = tree->rates->nd_t[i+1]; + tree->rates->nd_t[i+1] = tree->rates->nd_t[i]; + tree->rates->nd_t[i] = buff_t; + + buff_l = t->idx_loc[i+1]; + t->idx_loc[i+1] = t->idx_loc[i]; + t->idx_loc[i] = buff_l; + + swap = YES; + } + } + } + while(swap == YES); + + + // The rest below is just bookeeping... + + + For(i,2*tree->n_otu-1) tree->a_nodes[i]->num = i; + For(i,2*tree->n_otu-1) + { + if(i < tree->n_otu) tree->a_nodes[i]->tax = YES; + else tree->a_nodes[i]->tax = NO; + } + + /* printf("\n++++++++++++++++++\n"); */ + /* For(i,2*tree->n_otu-1) */ + /* { */ + /* printf("\n. Node %3d [%p] anc:%3d v1:%3d v2:%3d time: %f", */ + /* tree->a_nodes[i]->num, */ + /* (void *)tree->a_nodes[i], */ + /* tree->a_nodes[i]->v[0] ? tree->a_nodes[i]->v[0]->num : -1, */ + /* tree->a_nodes[i]->v[1] ? tree->a_nodes[i]->v[1]->num : -1, */ + /* tree->a_nodes[i]->v[2] ? tree->a_nodes[i]->v[2]->num : -1, */ + /* tree->rates->nd_t[i]); */ + /* } */ + + + for(i=0;in_otu;i++) + { + if(!tree->a_nodes[i]->name) tree->a_nodes[i]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + strcpy(tree->a_nodes[i]->name,"x"); + sprintf(tree->a_nodes[i]->name+1,"%d",i); + } + + tree->n_root->v[1]->v[0] = tree->n_root->v[2]; + tree->n_root->v[2]->v[0] = tree->n_root->v[1]; + + tree->num_curr_branch_available = 0; + Connect_Edges_To_Nodes_Recur(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + + tree->e_root = tree->n_root->v[1]->b[0]; + + For(i,2*tree->n_otu-3) + { + tree->a_edges[i]->l->v = FABS(tree->rates->nd_t[tree->a_edges[i]->left->num] - + tree->rates->nd_t[tree->a_edges[i]->rght->num]); + } + + tree->e_root->l->v = + FABS(tree->rates->nd_t[tree->n_root->v[1]->num] - + tree->rates->nd_t[tree->n_root->num]) + + FABS(tree->rates->nd_t[tree->n_root->v[2]->num] - + tree->rates->nd_t[tree->n_root->num]); + + tree->n_root->l[1] = FABS(tree->rates->nd_t[tree->n_root->v[1]->num] - + tree->rates->nd_t[tree->n_root->num]); + + tree->n_root->l[2] = FABS(tree->rates->nd_t[tree->n_root->v[2]->num] - + tree->rates->nd_t[tree->n_root->num]); + + tree->n_root_pos = + FABS(tree->rates->nd_t[tree->n_root->v[2]->num] - + tree->rates->nd_t[tree->n_root->num]) / tree->e_root->l->v; + + /* printf("\n. %s ",Write_Tree(tree)); */ + + DR_Draw_Tree("essai.ps",tree); + + /* for(i=0;in_otu;i++) */ + /* printf("\n. %4s %4d [%5.2f %5.2f]",tree->a_nodes[i]->name, */ + /* t->idx_loc[i], */ + /* t->ldscape[t->idx_loc[i]*t->n_dim+0], */ + /* t->ldscape[t->idx_loc[i]*t->n_dim+1]); */ + + + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + + Free(branching_nodes); + Free(p_branch); + Free(p_mig); + + return(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// Simualte n coordinates (in 2D) +void GEO_Simulate_Coordinates(int n, t_geo *t) +{ + int i; + phydbl width; + + width = 5.; + + for(i=0;ildscape[i*t->n_dim+0] = -width/2. + Uni()*width; */ + /* t->ldscape[i*t->n_dim+1] = width/2.; */ + t->coord_loc[i]->lonlat[0] = -width/2. + Uni()*width; + t->coord_loc[i]->lonlat[1] = width/2.; + } + + /* t->ldscape[0*t->n_dim+0] = 0.0; */ + /* t->ldscape[0*t->n_dim+1] = 0.0; */ + + /* t->ldscape[1*t->n_dim+0] = 0.1; */ + /* t->ldscape[1*t->n_dim+1] = 0.1; */ + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Optimize_Sigma(t_geo *t, t_tree *tree) +{ + Generic_Brent_Lk(&(t->sigma), + t->min_sigma, + t->max_sigma, + 1.E-5, + 1000, + NO, + GEO_Wrap_Lk,NULL,tree,NULL,NO); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Optimize_Lambda(t_geo *t, t_tree *tree) +{ + Generic_Brent_Lk(&(t->lbda), + t->min_lbda, + t->max_lbda, + 1.E-5, + 1000, + NO, + GEO_Wrap_Lk,NULL,tree,NULL,NO); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Optimize_Tau(t_geo *t, t_tree *tree) +{ + Generic_Brent_Lk(&(t->tau), + t->min_tau, + t->max_tau, + 1.E-5, + 1000, + NO, + GEO_Wrap_Lk,NULL,tree,NULL,NO); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl GEO_Wrap_Lk(t_edge *b, t_tree *tree, supert_tree *stree) +{ + return GEO_Lk(tree->geo,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Init_Geo_Struct(t_geo *t) +{ + t->c_lnL = UNLIKELY; + + t->sigma = 1.0; + t->min_sigma = 1.E-3; + t->max_sigma = 1.E+3; + t->sigma_thresh = t->max_sigma; + + t->lbda = 1.0; + t->min_lbda = 1.E-3; + t->max_lbda = 1.E+3; + + t->tau = 1.0; + t->min_tau = 1.E-3; + t->max_tau = 1.E+3; + + t->dum = 1.0; + t->min_dum = 1.E-3; + t->max_dum = 1.E+3; + + t->n_dim = 2; + t->ldscape_sz = 1; + + t->update_fmat = YES; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Randomize_Locations(t_node *n, t_geo *t, t_tree *tree) +{ + if(n->tax == YES) return; + else + { + t_node *v1, *v2; + int i; + phydbl *probs; // vector of probability of picking each location + phydbl sum; + phydbl u; + + + probs = (phydbl *)mCalloc(t->ldscape_sz,sizeof(phydbl)); + + v1 = v2 = NULL; + for(i=0;i<3;i++) + { + if(n->v[i] != n->anc && n->b[i] != tree->e_root) + { + if(!v1) v1 = n->v[i]; + else v2 = n->v[i]; + } + } + + if(v1->tax && v2->tax) + { + Free(probs); + return; + } + else if(v1->tax && !v2->tax && t->idx_loc[v1->num] != t->idx_loc[n->num]) + { + t->idx_loc[v2->num] = t->idx_loc[n->num]; + } + else if(v2->tax && !v1->tax && t->idx_loc[v2->num] != t->idx_loc[n->num]) + { + t->idx_loc[v1->num] = t->idx_loc[n->num]; + } + else if(v1->tax && !v2->tax && t->idx_loc[v1->num] == t->idx_loc[n->num]) + { + sum = 0.0; + for(i=0;ildscape_sz;i++) sum += t->idx_loc_beneath[v2->num * t->ldscape_sz + i]; + for(i=0;ildscape_sz;i++) probs[i] = t->idx_loc_beneath[v2->num * t->ldscape_sz + i]/sum; + + t->idx_loc[v2->num] = Sample_i_With_Proba_pi(probs,t->ldscape_sz); + } + else if(v2->tax && !v1->tax && t->idx_loc[v2->num] == t->idx_loc[n->num]) + { + sum = 0.0; + for(i=0;ildscape_sz;i++) sum += t->idx_loc_beneath[v1->num * t->ldscape_sz + i]; + for(i=0;ildscape_sz;i++) probs[i] = t->idx_loc_beneath[v1->num * t->ldscape_sz + i]/sum; + + t->idx_loc[v1->num] = Sample_i_With_Proba_pi(probs,t->ldscape_sz); + } + else + { + int n_v1, n_v2; + phydbl p; + + n_v1 = t->idx_loc_beneath[v1->num * t->ldscape_sz + t->idx_loc[n->num]]; + n_v2 = t->idx_loc_beneath[v2->num * t->ldscape_sz + t->idx_loc[n->num]]; + + if(n_v1 + n_v2 < 1) + { + PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + + p = n_v1 / (n_v1 + n_v2); + + u = Uni(); + + if(u < p) + { + sum = 0.0; + for(i=0;ildscape_sz;i++) sum += t->idx_loc_beneath[v2->num * t->ldscape_sz + i]; + for(i=0;ildscape_sz;i++) probs[i] = t->idx_loc_beneath[v2->num * t->ldscape_sz + i]/sum; + + t->idx_loc[v2->num] = Sample_i_With_Proba_pi(probs,t->ldscape_sz); + t->idx_loc[v1->num] = t->idx_loc[n->num]; + } + else + { + if(t->idx_loc_beneath[v2->num * t->ldscape_sz + t->idx_loc[n->num]] > 0) + { + sum = 0.0; + for(i=0;ildscape_sz;i++) sum += t->idx_loc_beneath[v1->num * t->ldscape_sz + i]; + for(i=0;ildscape_sz;i++) probs[i] = t->idx_loc_beneath[v1->num * t->ldscape_sz + i]/sum; + + t->idx_loc[v1->num] = Sample_i_With_Proba_pi(probs,t->ldscape_sz); + t->idx_loc[v2->num] = t->idx_loc[n->num]; + } + else + { + sum = 0.0; + for(i=0;ildscape_sz;i++) sum += t->idx_loc_beneath[v2->num * t->ldscape_sz + i]; + for(i=0;ildscape_sz;i++) probs[i] = t->idx_loc_beneath[v2->num * t->ldscape_sz + i]/sum; + + t->idx_loc[v2->num] = Sample_i_With_Proba_pi(probs,t->ldscape_sz); + t->idx_loc[v1->num] = t->idx_loc[n->num]; + } + } + + if(t->idx_loc[v1->num] != t->idx_loc[n->num] && t->idx_loc[v2->num] != t->idx_loc[n->num]) + { + PhyML_Printf("\n. %d %d %d",t->idx_loc[v1->num],t->idx_loc[v2->num],t->idx_loc[n->num]); + PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + if(t->idx_loc_beneath[v1->num * t->ldscape_sz + t->idx_loc[v1->num]] < 1) + { + PhyML_Printf("\n. %d %d %d",t->idx_loc[v1->num],t->idx_loc[v2->num],t->idx_loc[n->num]); + PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + if(t->idx_loc_beneath[v2->num * t->ldscape_sz + t->idx_loc[v2->num]] < 1) + { + PhyML_Printf("\n. %d %d %d",t->idx_loc[v1->num],t->idx_loc[v2->num],t->idx_loc[n->num]); + PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + } + + Free(probs); + + for(i=0;i<3;i++) + if(n->v[i] != n->anc && n->b[i] != tree->e_root) + GEO_Randomize_Locations(n->v[i],t,tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Get_Locations_Beneath(t_geo *t, t_tree *tree) +{ + int i; + GEO_Get_Locations_Beneath_Post(tree->n_root,tree->n_root->v[1],t,tree); + GEO_Get_Locations_Beneath_Post(tree->n_root,tree->n_root->v[2],t,tree); + + for(i=0;ildscape_sz;i++) + { + t->idx_loc_beneath[tree->n_root->num*t->ldscape_sz+i] = + t->idx_loc_beneath[tree->n_root->v[1]->num*t->ldscape_sz+i] + + t->idx_loc_beneath[tree->n_root->v[2]->num*t->ldscape_sz+i]; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Get_Locations_Beneath_Post(t_node *a, t_node *d, t_geo *t, t_tree *tree) +{ + + if(d->tax) + { + t->idx_loc_beneath[d->num*t->ldscape_sz+t->idx_loc[d->num]] = 1; + return; + } + else + { + int i; + t_node *v1, *v2; + + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + GEO_Get_Locations_Beneath_Post(d,d->v[i],t,tree); + } + } + + + v1 = v2 = NULL; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(!v1) v1 = d->v[i]; + else v2 = d->v[i]; + } + } + + + for(i=0;ildscape_sz;i++) + { + t->idx_loc_beneath[ d->num*t->ldscape_sz+i] = + t->idx_loc_beneath[v1->num*t->ldscape_sz+i] + + t->idx_loc_beneath[v2->num*t->ldscape_sz+i] ; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Get_Sigma_Max(t_geo *t) +{ + int i,j; + phydbl mean_dist,inv_mean_dist; + phydbl sigma_a, sigma_b, sigma_c; + phydbl overlap_a, overlap_b, overlap_c; + phydbl d_intersect; + phydbl overlap_target; + phydbl eps; + int n_iter,n_iter_max; + + eps = 1.E-6; + overlap_target = 0.95; + n_iter_max = 100; + + mean_dist = -1.; + inv_mean_dist = -1.; + for(i=0;ildscape_sz-1;i++) + { + for(j=i+1;jldscape_sz;j++) + { + /* dist = POW(t->ldscape[i*t->n_dim+0] - t->ldscape[j*t->n_dim+0],1); */ + /* if(dist > mean_dist) mean_dist = dist; */ + /* dist = POW(t->ldscape[i*t->n_dim+1] - t->ldscape[j*t->n_dim+1],1); */ + /* if(dist > mean_dist) mean_dist = dist; */ + /* mean_dist += FABS(t->ldscape[i*t->n_dim+0] - t->ldscape[j*t->n_dim+0]); */ + /* mean_dist += FABS(t->ldscape[i*t->n_dim+1] - t->ldscape[j*t->n_dim+1]); */ + mean_dist += FABS(t->coord_loc[i]->lonlat[0] - t->coord_loc[j]->lonlat[0]); + mean_dist += FABS(t->coord_loc[i]->lonlat[1] - t->coord_loc[j]->lonlat[1]); + } + } + + mean_dist /= t->ldscape_sz*(t->ldscape_sz-1)/2.; + inv_mean_dist = 1./mean_dist; + + PhyML_Printf("\n. Mean distance between locations: %f",mean_dist); + + sigma_a = t->min_sigma; sigma_b = 1.0; sigma_c = t->max_sigma; + /* sigma_a = t->min_sigma; sigma_b = 1.0; sigma_c = 10.; */ + n_iter = 0; + do + { + d_intersect = Inverse_Truncated_Normal(inv_mean_dist,0.0,sigma_a,0.0,mean_dist); + overlap_a = + (Pnorm(mean_dist,0.0,sigma_a) - Pnorm(d_intersect,0.0,sigma_a))/ + (Pnorm(mean_dist,0.0,sigma_a) - Pnorm(0.0,0.0,sigma_a)) + + d_intersect / mean_dist; + /* printf("\n. inter: %f %f [%f]",d_intersect,mean_dist,d_intersect / mean_dist); */ + + d_intersect = Inverse_Truncated_Normal(inv_mean_dist,0.0,sigma_b,0.0,mean_dist); + overlap_b = + (Pnorm(mean_dist,0.0,sigma_b) - Pnorm(d_intersect,0.0,sigma_b))/ + (Pnorm(mean_dist,0.0,sigma_b) - Pnorm(0.0,0.0,sigma_b)) + + d_intersect / mean_dist; + /* printf("\n. inter: %f %f [%f]",d_intersect,mean_dist,d_intersect / mean_dist); */ + + d_intersect = Inverse_Truncated_Normal(inv_mean_dist,0.0,sigma_c,0.0,mean_dist); + overlap_c = + (Pnorm(mean_dist,0.0,sigma_c) - Pnorm(d_intersect,0.0,sigma_c))/ + (Pnorm(mean_dist,0.0,sigma_c) - Pnorm(0.0,0.0,sigma_c)) + + d_intersect / mean_dist; + + /* printf("\n. inter: %f %f [%f]",d_intersect,mean_dist,d_intersect / mean_dist); */ + + /* printf("\n. sigma_a:%f overlap_a:%f sigma_b:%f overlap_b:%f sigma_c:%f overlap_c:%f", */ + /* sigma_a,overlap_a, */ + /* sigma_b,overlap_b, */ + /* sigma_c,overlap_c); */ + + if(overlap_target > overlap_a && overlap_target < overlap_b) + { + sigma_c = sigma_b; + sigma_b = sigma_a + (sigma_c - sigma_a)/2.; + } + else if(overlap_target > overlap_b && overlap_target < overlap_c) + { + sigma_a = sigma_b; + sigma_b = sigma_a + (sigma_c - sigma_a)/2.; + } + else if(overlap_target < overlap_a) + { + sigma_a /= 2.; + } + else if(overlap_target > overlap_c) + { + sigma_c *= 2.; + } + + n_iter++; + + } + while(sigma_c - sigma_a > eps && n_iter < n_iter_max); + + /* if(sigma_c - sigma_a > eps) */ + /* { */ + /* PhyML_Printf("\n== Error detected in getting maximum value of sigma."); */ + /* PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); */ + /* Exit("\n"); */ + /* } */ + /* else */ + /* { */ + /* PhyML_Printf("\n== Threshold for sigma: %f",sigma_b); */ + /* } */ + + t->sigma_thresh = sigma_b; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Geo_Updown_Tau_Lbda(t_tree *tree) +{ + phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL,new_lnL; + phydbl cur_tau,new_tau; + phydbl cur_lbda,new_lbda; + + K = tree->mcmc->tune_move[tree->mcmc->num_move_geo_updown_tau_lbda]; + cur_lnL = tree->geo->c_lnL; + new_lnL = tree->geo->c_lnL; + cur_tau = tree->geo->tau; + new_tau = tree->geo->tau; + cur_lbda = tree->geo->lbda; + new_lbda = tree->geo->lbda; + + u = Uni(); + mult = exp(K*(u-0.5)); + + /* Multiply tau by K */ + new_tau = cur_tau * K; + + /* Divide lbda by same amount */ + new_lbda = cur_lbda / K; + + + if( + new_lbda < tree->geo->min_lbda || new_lbda > tree->geo->max_lbda || + new_tau < tree->geo->min_tau || new_tau > tree->geo->max_tau + ) + { + tree->mcmc->run_move[tree->mcmc->num_move_geo_updown_tau_lbda]++; + return; + } + + tree->geo->tau = new_tau; + tree->geo->lbda = new_lbda; + + if(tree->eval_alnL) new_lnL = GEO_Lk(tree->geo,tree); + + ratio = 0.0; + /* Proposal ratio: 2n-2=> number of multiplications, 1=>number of divisions */ + ratio += 0.0*log(mult); /* (1-1)*log(mult); */ + /* Likelihood density ratio */ + ratio += (new_lnL - cur_lnL); + + /* printf("\n. new_tau: %f new_lbda:%f cur_lnL:%f new_lnL:%f",new_tau,new_lbda,cur_lnL,new_lnL); */ + + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + if(u > alpha) /* Reject */ + { + tree->geo->tau = cur_tau; + tree->geo->lbda = cur_lbda; + tree->geo->c_lnL = cur_lnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_geo_updown_tau_lbda]++; + } + + tree->mcmc->run_move[tree->mcmc->num_move_geo_updown_tau_lbda]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Geo_Updown_Lbda_Sigma(t_tree *tree) +{ + phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL,new_lnL; + phydbl cur_lbda,new_lbda; + phydbl cur_sigma,new_sigma; + + K = tree->mcmc->tune_move[tree->mcmc->num_move_geo_updown_lbda_sigma]; + cur_lnL = tree->geo->c_lnL; + new_lnL = tree->geo->c_lnL; + cur_lbda = tree->geo->lbda; + new_lbda = tree->geo->lbda; + cur_sigma = tree->geo->sigma; + new_sigma = tree->geo->sigma; + + u = Uni(); + mult = exp(K*(u-0.5)); + + /* Multiply lbda by K */ + new_lbda = cur_lbda * K; + + /* Divide sigma by same amount */ + new_sigma = cur_sigma / K; + + + if( + new_sigma < tree->geo->min_sigma || new_sigma > tree->geo->max_sigma || + new_lbda < tree->geo->min_lbda || new_lbda > tree->geo->max_lbda + ) + { + tree->mcmc->run_move[tree->mcmc->num_move_geo_updown_lbda_sigma]++; + return; + } + + tree->geo->lbda = new_lbda; + tree->geo->sigma = new_sigma; + + if(tree->eval_alnL) new_lnL = GEO_Lk(tree->geo,tree); + + ratio = 0.0; + /* Proposal ratio: 2n-2=> number of multiplications, 1=>number of divisions */ + ratio += 0.0*log(mult); /* (1-1)*log(mult); */ + /* Likelihood density ratio */ + ratio += (new_lnL - cur_lnL); + + /* printf("\n. new_lbda: %f new_sigma:%f cur_lnL:%f new_lnL:%f",new_lbda,new_sigma,cur_lnL,new_lnL); */ + + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + if(u > alpha) /* Reject */ + { + tree->geo->lbda = cur_lbda; + tree->geo->sigma = cur_sigma; + tree->geo->c_lnL = cur_lnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_geo_updown_lbda_sigma]++; + } + + tree->mcmc->run_move[tree->mcmc->num_move_geo_updown_lbda_sigma]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Read_In_Landscape(char *file_name, t_geo *t, phydbl **ldscape, int **loc_hash, t_tree *tree) +{ + FILE *fp; + char *s; + phydbl longitude, lattitude; + int tax,loc; + + PhyML_Printf("\n"); + PhyML_Printf("\n. Reading landscape file '%s'.\n",file_name); + + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + (*ldscape) = (phydbl *)mCalloc(10*t->n_dim,sizeof(phydbl)); + (*loc_hash) = (int *)mCalloc(tree->n_otu,sizeof(int)); + + fp = Openfile(file_name,0); + + tax = loc = -1; + + t->ldscape_sz = 0; + + do + { + if(fscanf(fp,"%s",s) == EOF) break; + + if(strlen(s) > 0) for(tax=0;taxn_otu;tax++) if(!strcmp(tree->a_nodes[tax]->name,s)) break; + + if(tax == tree->n_otu) + { + PhyML_Printf("\n== Could not find a taxon with name '%s' in the tree provided.",s); + /* PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); */ + /* Exit("\n"); */ + continue; + } + + /* sscanf(line+pos,"%lf %lf",&longitude,&lattitude); */ + if(fscanf(fp,"%lf",&longitude) == EOF) break; + if(fscanf(fp,"%lf",&lattitude) == EOF) break; + + /* printf("\n. s: %s %f %f",s,longitude,lattitude); */ + + for(loc=0;locldscape_sz;loc++) + { + if(FABS(longitude-(*ldscape)[loc*t->n_dim+0]) < 1.E-10 && + FABS(lattitude-(*ldscape)[loc*t->n_dim+1]) < 1.E-10) + { + break; + } + } + + if(loc == t->ldscape_sz) + { + t->ldscape_sz++; + (*ldscape)[(t->ldscape_sz-1)*t->n_dim+0] = longitude; + (*ldscape)[(t->ldscape_sz-1)*t->n_dim+1] = lattitude; + + if(!(t->ldscape_sz%10)) + { + (*ldscape) = (phydbl *)mRealloc((*ldscape),(t->ldscape_sz+10)*t->n_dim,sizeof(phydbl)); + } + } + + (*loc_hash)[tax] = loc; + + } + while(1); + + for(tax=0;taxn_otu;tax++) + PhyML_Printf("\n. Taxon %30s, longitude: %12f, lattitude: %12f [%4d]", + tree->a_nodes[tax]->name, + (*ldscape)[(*loc_hash)[tax]*t->n_dim+0], + (*ldscape)[(*loc_hash)[tax]*t->n_dim+1], + (*loc_hash)[tax]); + + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + diff --git a/phyml/geo.h b/phyml/geo.h new file mode 100644 index 0000000..7493490 --- /dev/null +++ b/phyml/geo.h @@ -0,0 +1,49 @@ +/* + +PHYML : a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences + +Copyright (C) Stephane Guindon. Oct 2003 onward + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef GEO_H +#define GEO_H + +#include "utilities.h" + +int GEO_Main(int argc, char **argv); +void Free_Geo(t_geo *t); +void GEO_Update_Fmat(t_geo *t); +void GEO_Update_Sorted_Nd(t_geo *t,t_tree *tree); +void GEO_Update_Occup(t_geo *t,t_tree *tree); +void GEO_Update_Rmat(t_node *n,t_geo *t,t_tree *tree); +phydbl GEO_Lk(t_geo *t,t_tree *tree); +void GEO_Init_Tloc_Tips(t_geo *t,t_tree *tree); +phydbl GEO_Total_Migration_Rate(t_node *n,t_geo *t); +int GEO_Get_Arrival_Location(t_node *n,t_geo *t,t_tree *tree); +void GEO_Simulate_Coordinates(int n, t_geo *t); +t_tree *GEO_Simulate(t_geo *t, int n_otu); +void GEO_Optimize_Sigma(t_geo *t, t_tree *tree); +phydbl GEO_Wrap_Lk(t_edge *b, t_tree *tree, supert_tree *stree); +void GEO_Optimize_Lambda(t_geo *t, t_tree *tree); +void GEO_Init_Geo_Struct(t_geo *t); +void GEO_Optimize_Tau(t_geo *t, t_tree *tree); +void GEO_Get_Locations_Beneath(t_geo *t, t_tree *tree); +void GEO_Get_Locations_Beneath_Post(t_node *a, t_node *d, t_geo *t, t_tree *tree); +void GEO_Randomize_Locations_Pre(t_node *n, t_geo *t, t_tree *tree); +void GEO_Randomize_Locations(t_node *n, t_geo *t, t_tree *tree); +void GEO_Get_Sigma_Max(t_geo *t); +void MCMC_Geo_Updown_Tau_Lbda(t_tree *tree); +void MCMC_Geo_Updown_Lbda_Sigma(t_tree *tree); +int GEO_Simulate_Estimate(int argc, char **argv); +void GEO_Read_In_Landscape(char *file_name, t_geo *t, phydbl **ldscape, int **loc_hash, t_tree *tree); +int GEO_Estimate(int argc, char **argv); +phydbl *GEO_MCMC(t_tree *tree); + +#endif diff --git a/phyml/help.c b/phyml/help.c new file mode 100644 index 0000000..1fb29b2 --- /dev/null +++ b/phyml/help.c @@ -0,0 +1,375 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + + +#include "help.h" + + +/* int T_MAX_FILE; */ +/* phydbl SMALL; */ +/* phydbl UNLIKELY; */ + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Usage() +{ + + char *BOLD=(char *)mCalloc(10,sizeof(char)); + char *FLAT=(char *)mCalloc(10,sizeof(char)); + char *LINE=(char *)mCalloc(10,sizeof(char)); + char *cha; + + + cha = getenv("OS"); + + if(cha!=NULL) + { + strcpy(BOLD, ""); + strcpy(FLAT, ""); + strcpy(LINE, ""); + } + else + { + strcpy(BOLD, "\033[00;01m"); + strcpy(FLAT, "\033[00;00m"); + strcpy(LINE, "\033[00;04m"); + } + + #ifdef PHYML + PhyML_Printf("%sNAME\n" + "%s\t- PhyML %s - \n\n" + "%s\t\''A simple, fast, and accurate algorithm to estimate\n" + "%s\tlarge phylogenies by maximum likelihood\''\n\n" + "%s\tStephane Guindon and Olivier Gascuel,\n" + "%s\tSystematic Biology 52(5):696-704, 2003.\n\n" + "%s\tPlease cite this paper if you use this software in your publications.\n",BOLD,FLAT,VERSION,FLAT,FLAT,FLAT,FLAT,FLAT); + #endif + + #ifdef PHYTIME + PhyML_Printf("%sNAME\n" + "%s\t- PhyTime %s - \n\n" + "%s\t'Bayesian estimation of divergence times from large sequence alignments.'\n" + "%s\tStephane Guindon,\n" + "%s\tMolecular Biology and Evolution 27(8):1768-81, 2010.\n\n" + "%s\tPlease cite this paper if you use this software in your publications.\n",BOLD,FLAT,VERSION,FLAT,FLAT,FLAT,FLAT,FLAT); + #endif + + + + #ifdef PHYML + PhyML_Printf("%s\nSYNOPSIS:\n\n" + "%s\tphyml %s[command args]\n",BOLD,BOLD,BOLD); + #endif + #ifdef PHYTIME + PhyML_Printf("%s\nSYNOPSIS:\n\n" + "%s\tphytime %s[command args]\n",BOLD,BOLD,BOLD); + #endif + + #ifdef PHYML + PhyML_Printf("%s\n\tAll the options below are optional (except '%s-i%s' if you want to use the command-line interface).\n\n",FLAT,BOLD,FLAT); + #endif + + #ifdef PHYTIME + PhyML_Printf("%s\n\tAll the options below are optional except '%s-i%s','%s-u%s' and '%s--calibration%s'.\n\n",FLAT,BOLD,FLAT,BOLD,FLAT,BOLD,FLAT); + #endif + + PhyML_Printf("%s\nCommand options:\n%s",BOLD,FLAT); + + PhyML_Printf("\n\t%s-i (or --input) %sseq_file_name%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\t%sseq_file_name%s is the name of the nucleotide or amino-acid sequence file in PHYLIP format.\n",LINE,FLAT); + PhyML_Printf("\n"); + + PhyML_Printf("%s\n\t-d (or --datatype) ""%sdata_type%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\t%sdata_type%s is 'nt' for nucleotide (default), 'aa' for amino-acid sequences, or 'generic',\n",LINE,FLAT); + PhyML_Printf("\t\t(use NEXUS file format and the 'symbols' parameter here).\n"); + PhyML_Printf("\n"); + + + PhyML_Printf("%s\n\t-q (or --sequential)\n",BOLD); + PhyML_Printf("%s\t\tChanges interleaved format (default) to sequential format.\n",FLAT); + PhyML_Printf("\n"); + + + #ifndef PHYTIME + PhyML_Printf("%s\n\t-n (or --multiple) ""%snb_data_sets%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\t%snb_data_sets%s is an integer corresponding to the number of data sets to analyse.\n",LINE,FLAT); + PhyML_Printf("\n"); + #endif + + + #ifndef PHYTIME + PhyML_Printf("%s\n\t-p (or --pars)%s\n",BOLD,FLAT); + PhyML_Printf("%s\t\tUse a minimum parsimony starting tree. This option is taken into account when the '-u' option\n",FLAT); + PhyML_Printf("%s\t\tis absent and when tree topology modifications are to be done.\n",FLAT); + PhyML_Printf("\n"); + #endif + + + #ifndef PHYTIME + PhyML_Printf("%s\n\t-b (or --bootstrap) %sint%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\t%sint%s > 0: %sint%s is the number of bootstrap replicates.\n",LINE,FLAT,LINE,FLAT); + PhyML_Printf("\t\t%sint%s = 0: neither approximate likelihood ratio test nor bootstrap values are computed.\n",LINE,FLAT); + PhyML_Printf("\t\t%sint%s = -1: approximate likelihood ratio test returning aLRT statistics.\n",LINE,FLAT); + PhyML_Printf("\t\t%sint%s = -2: approximate likelihood ratio test returning Chi2-based parametric branch supports.\n",LINE,FLAT); +/* PhyML_Printf("\t\t%sint%s = -3 : minimum of Chi2-based parametric and SH-like branch supports.\n",LINE,FLAT); */ + PhyML_Printf("\t\t%sint%s = -4: SH-like branch supports alone.\n",LINE,FLAT); + PhyML_Printf("\t\t%sint%s = -5: (default) approximate Bayes branch supports.\n",LINE,FLAT); + PhyML_Printf("\n"); + + PhyML_Printf("%s\n\t--tbe%s\n",BOLD,FLAT); + PhyML_Printf("\t\tComputes TBE instead of FBP (standard) bootstrap support\n"); + PhyML_Printf("\t\tHas no effect with -b <= 0\n"); + + #endif + + PhyML_Printf("%s\n\t-m (or --model) %smodel%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tmodel%s : substitution model name.\n",FLAT); + PhyML_Printf("\t\t%s- %sNucleotide%s-based models : %sHKY85%s (default) | %sJC69%s | %sK80%s | %sF81%s | %sF84%s | %sTN93%s | %sGTR%s | %scustom (*)%s\n", + FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT); + PhyML_Printf("\t\t(*) : for the custom option, a string of six digits identifies the model. For instance, 000000\n"); + PhyML_Printf("\t\t corresponds to F81 (or JC69 provided the distribution of nucleotide frequencies is uniform).\n"); + PhyML_Printf("\t\t 012345 corresponds to GTR. This option can be used for encoding any model that is a nested within GTR.\n"); + PhyML_Printf("\n"); + PhyML_Printf("\t\t%s- %sAmino-acid%s based models : %sLG%s (default) | %sWAG%s | %sJTT%s | %sMtREV%s | %sDayhoff%s | %sDCMut%s | %sRtREV%s | %sCpREV%s | %sVT%s | %sAB%s\n",FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT); + PhyML_Printf("\t\t %sBlosum62%s | %sMtMam%s | %sMtArt%s | %sHIVw%s | %sHIVb%s | %scustom%s\n", + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT, + LINE,FLAT); + + PhyML_Printf("\n"); + + PhyML_Printf("%s\n\t--aa_rate_file %sfilename%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\t%sfilename%s is the name of the file that provides the amino acid substitution rate matrix in PAML format.\n",LINE,FLAT); + PhyML_Printf("\t\tIt is compulsory to use this option when analysing amino acid sequences with the `custom' model.\n"); + PhyML_Printf("\n"); + + + #ifndef PHYTIME + PhyML_Printf("%s\n\t-f %se%s, %sm%s, or %sfA,fC,fG,fT%s\n",BOLD,LINE,BOLD,LINE,BOLD,LINE,FLAT); + PhyML_Printf("\t\t%se%s : the character frequencies are determined as follows : \n",LINE,FLAT); + PhyML_Printf("%s\t\t- %sNucleotide%s sequences: (Empirical) the equilibrium base frequencies are estimated by counting\n" + "\t\t the occurence of the different bases in the alignment.\n",FLAT,LINE,FLAT); + PhyML_Printf("%s\t\t- %sAmino-acid%s sequences: (Empirical) the equilibrium amino-acid frequencies are estimated by counting\n" +"\t\t the occurence of the different amino-acids in the alignment.\n",FLAT,LINE,FLAT); + PhyML_Printf("\n"); + PhyML_Printf("\t\t%sm%s : the character frequencies are determined as follows : \n",LINE,FLAT); + PhyML_Printf("%s\t\t- %sNucleotide%s sequences: (ML) the equilibrium base frequencies are estimated using maximum likelihood \n",FLAT,LINE,FLAT); + PhyML_Printf("%s\t\t- %sAmino-acid%s sequences: (Model) the equilibrium amino-acid frequencies are estimated using\n" +"\t\t the frequencies defined by the substitution model.\n",FLAT,LINE,FLAT); + PhyML_Printf("\n"); + PhyML_Printf("\t\t%sfA,fC,fG,fT%s : only valid for nucleotide-based models. fA, fC, fG and fT are floating numbers that \n",LINE,FLAT); + PhyML_Printf("\t\t correspond to the frequencies of A, C, G and T respectively (WARNING: do not use any blank space between\n"); + PhyML_Printf("\t\t your values of nucleotide frequencies, only commas!)\n"); + PhyML_Printf("\n"); + #endif + + #ifdef PHYTIME + PhyML_Printf("%s\n\t--calibration %sfilename%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\t%sfilename%s is the name of the calibration file that provides a priori defined boundaries for node ages.\n",LINE,FLAT); + PhyML_Printf("\t\tPlease read the manual for more information about the format of this file.\n"); + PhyML_Printf("\n"); + #endif + + + PhyML_Printf("%s\n\t-t (or --ts/tv) %sts/tv_ratio%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tts/tv_ratio%s : transition/transversion ratio. DNA sequences only.\n",FLAT); + PhyML_Printf("\t\tCan be a fixed positive value (ex:4.0) or %se%s to get the maximum likelihood estimate.\n",LINE,FLAT); + PhyML_Printf("\n"); + + PhyML_Printf("%s\n\t-v (or --pinv) %sprop_invar%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tprop_invar%s : proportion of invariable sites.\n",FLAT); + PhyML_Printf("\t\tCan be a fixed value in the [0,1] range or %se%s to get the maximum likelihood estimate.\n",LINE,FLAT); + PhyML_Printf("\n"); + + PhyML_Printf("%s\n\t-c (or --nclasses) %snb_subst_cat%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tnb_subst_cat%s : number of relative substitution rate categories. Default : %snb_subst_cat%s=4.\n", + FLAT,LINE,FLAT); + PhyML_Printf("\t\tMust be a positive integer.\n"); + PhyML_Printf("\n"); + + PhyML_Printf("%s\n\t--freerates (or --free_rates or --freerate or --free_rate)\n",BOLD); + PhyML_Printf("\t\t%s FreeRate model of substitution rate variation across sites.\n",FLAT); + PhyML_Printf("\n"); + + + + PhyML_Printf("%s\n\t-a (or --alpha) %sgamma%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tgamma%s : distribution of the gamma distribution shape parameter.\n",FLAT); + PhyML_Printf("\t\tCan be a fixed positive value or %se%s to get the maximum likelihood estimate.\n",LINE,FLAT); + PhyML_Printf("\n"); + + #ifndef PHYTIME + PhyML_Printf("%s\n\t-s (or --search) %smove%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tTree topology search operation option.\n"); + PhyML_Printf("\t\tCan be either %sNNI%s (default, fast) or %sSPR%s (a bit slower than NNI) or %sBEST%s (best of NNI and SPR search).\n",LINE,FLAT,LINE,FLAT,LINE,FLAT); + PhyML_Printf("\n"); + #endif + + + PhyML_Printf("%s\n\t-u (or --inputtree) %suser_tree_file%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tuser_tree_file%s : starting tree filename. The tree must be in Newick format.\n",FLAT); + PhyML_Printf("\n"); + + + #ifndef PHYTIME + PhyML_Printf("%s\n\t-o %sparams%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tThis option focuses on specific parameter optimisation.\n"); + PhyML_Printf("\t\t%sparams%s=tlr : tree topology (t), branch length (l) and rate parameters (r) are optimised.\n",LINE,FLAT); + PhyML_Printf("\t\t%sparams%s=tl : tree topology and branch length are optimised.\n",LINE,FLAT); + PhyML_Printf("\t\t%sparams%s=lr : branch length and rate parameters are optimised.\n",LINE,FLAT); + PhyML_Printf("\t\t%sparams%s=l : branch length are optimised.\n",LINE,FLAT); + PhyML_Printf("\t\t%sparams%s=r : rate parameters are optimised.\n",LINE,FLAT); + PhyML_Printf("\t\t%sparams%s=n : no parameter is optimised.\n",LINE,FLAT); + PhyML_Printf("\n"); + #endif + + + #ifndef PHYTIME + PhyML_Printf("%s\n\t--rand_start%s\n",BOLD,FLAT); + PhyML_Printf("\t\tThis option sets the initial tree to random.\n"); + PhyML_Printf("\t\tIt is only valid if SPR searches are to be performed.\n"); + PhyML_Printf("\n"); + #endif + + #ifndef PHYTIME + PhyML_Printf("%s\n\t--n_rand_starts %snum%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tnum%s is the number of initial random trees to be used.\n",FLAT); + PhyML_Printf("\t\tIt is only valid if SPR searches are to be performed.\n"); + PhyML_Printf("\n"); + #endif + + PhyML_Printf("%s\n\t--r_seed %snum%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tnum%s is the seed used to initiate the random number generator.\n",FLAT); + PhyML_Printf("\t\tMust be an integer.\n"); + PhyML_Printf("\n"); + + #ifndef PHYTIME + PhyML_Printf("%s\n\t--print_site_lnl%s\n",BOLD,FLAT); + PhyML_Printf("\t\t%sPrint the likelihood for each site in file *_phyml_lk.txt.\n",FLAT); + PhyML_Printf("\n"); + #endif + + #ifndef PHYTIME + PhyML_Printf("%s\n\t--print_trace%s\n",BOLD,FLAT); + PhyML_Printf("\t\t%sPrint each phylogeny explored during the tree search process\n",FLAT); + PhyML_Printf("\t\t%sin file *_phyml_trace.txt.\n",FLAT); + PhyML_Printf("\n"); + #endif + + + PhyML_Printf("%s\n\t--run_id %sID_string%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\t%sAppend the string %sID_string%s at the end of each PhyML output file.\n",FLAT,LINE,FLAT); + PhyML_Printf("\t\t%sThis option may be useful when running simulations involving PhyML.\n",FLAT); + PhyML_Printf("\n"); + + PhyML_Printf("%s\n\t--quiet%s\n",BOLD,FLAT); + PhyML_Printf("\t\t%sNo interactive question (for running in batch mode) and quiet output.\n",FLAT); + PhyML_Printf("\n"); + + + PhyML_Printf("%s\n\t--no_memory_check%s\n",BOLD,FLAT); + PhyML_Printf("\t\t%sNo interactive question for memory usage (for running in batch mode). Normal output otherwise.\n",FLAT); + PhyML_Printf("\n"); + +#ifndef PHYTIME + PhyML_Printf("%s\n\t--leave_duplicates%s\n",BOLD,FLAT); + PhyML_Printf("\t\t%sPhyML removes duplicate sequences by default. Use this option to leave them in.\n",FLAT); + PhyML_Printf("\n"); +#endif + +#ifndef PHYTIME + PhyML_Printf("%s\n\t--alias_subpatt%s\n",BOLD,FLAT); + PhyML_Printf("\t\t%sSite aliasing is generalized at the subtree level. Sometimes lead to faster calculations.\n",FLAT); + PhyML_Printf("\t\t%sSee Kosakovsky Pond SL, Muse SV, Sytematic Biology (2004) for an example.\n",FLAT); + PhyML_Printf("\n"); + #endif + + #ifndef PHYTIME + PhyML_Printf("%s\n\t--boot_progress_display %snum%s (default=20)\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\t%snum%s is the frequency at which the bootstrap progress bar will be updated.\n",LINE,FLAT); + PhyML_Printf("\t\tMust be an integer.\n"); + PhyML_Printf("\n"); + #endif + + + #ifdef PHYTIME + PhyML_Printf("%s\n\t--chain_len %snum%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\t%snum%s is the number of generations or runs of the Markov Chain Monte Carlo. Set to 1E+6 by default. \n",LINE,FLAT); + PhyML_Printf("\t\tMust be an integer.\n"); + PhyML_Printf("\n"); + #endif + +/* #ifdef PHYTIME */ +/* PhyML_Printf("%s\n\t--burnin %snum%s\n",BOLD,LINE,FLAT); */ +/* PhyML_Printf("\t\t%snum%s is the number of generations of runs of the Markov Chain Monte Carlo during the 'burnin' period.\n",LINE,FLAT); */ +/* PhyML_Printf("\t\t%sSet to 1E+5 by default. Must be an integer. \n",FLAT); */ +/* PhyML_Printf("\n"); */ +/* #endif */ + + #ifdef PHYTIME + PhyML_Printf("%s\n\t--sample_freq %snum%s\n",BOLD,LINE,FLAT); + PhyML_Printf("\t\tThe chain is sampled every %snum%s generations. Set to 1E+3 by default. \n",LINE,FLAT); + PhyML_Printf("\t\tMust be an integer.\n"); + PhyML_Printf("\n"); + #endif + + + #ifdef PHYTIME + PhyML_Printf("%s\n\t--no_sequences%s\n",BOLD,FLAT); + PhyML_Printf("\t\tUse this option to run the sampler without sequence data.\n"); + PhyML_Printf("\n"); + #endif + + + #ifdef PHYTIME + PhyML_Printf("%s\n\t--fastlk%s\n",BOLD,FLAT); + PhyML_Printf("\t\tUse the multivariate normal approximation to the likelihood and speed up calculations\n"); + PhyML_Printf("\n"); + #endif + + + #ifdef PHYML + PhyML_Printf("%sPHYLIP-LIKE INTERFACE\n""%s\n\tYou can also use PhyML with no argument, in this case change the value of\n",BOLD,FLAT); + PhyML_Printf("%s\ta parameter by typing its corresponding character as shown on screen.\n\n",FLAT); + #endif + + #ifdef PHYML + PhyML_Printf("%sEXAMPLES\n\n" + "%s\tDNA interleaved sequence file, default parameters : ""%s ./phyml -i seqs1" + "%s\n\tAA interleaved sequence file, default parameters : ""%s ./phyml -i seqs2 -d aa" + "%s\n\tAA sequential sequence file, with customization : ""%s ./phyml -i seqs3 -q -d aa -m JTT -c 4 -a e%s\n",BOLD,FLAT,BOLD,FLAT,BOLD,FLAT,BOLD,FLAT); + #endif + + Exit(""); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + + diff --git a/phyml/options.h b/phyml/help.h similarity index 69% rename from phyml/options.h rename to phyml/help.h index 6dfc238..55ba51b 100644 --- a/phyml/options.h +++ b/phyml/help.h @@ -10,12 +10,16 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef OPTIONS_H #define OPTIONS_H +#include "utilities.h" +#include "cl.h" +#include "models.h" +#include "free.h" +#include "interface.h" + void Usage(); -option *Get_Input(int argc, char **argv); -void Init_Optimiz(optimiz *s_opt); -void Get_Input_Interactive(option *input); -void Set_Defaults(option* input); #endif diff --git a/phyml/init.c b/phyml/init.c new file mode 100644 index 0000000..bba1959 --- /dev/null +++ b/phyml/init.c @@ -0,0 +1,3727 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "init.h" +#ifdef BEAGLE +#include "beagle_utils.h" +#endif + +void Init_Eigen_Struct(eigen *this) +{ + this->next = NULL; + this->prev = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Scalar_Dbl(scalar_dbl *p) +{ + p->v = -1.; + p->onoff = ON; + p->next = NULL; + p->prev = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Scalar_Int(scalar_int *p) +{ + p->v = -1.; + p->next = NULL; + p->prev = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Vect_Dbl(int len, vect_dbl *p) +{ + p->len = len; + p->next = NULL; + p->prev = NULL; + p->v = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Vect_Int(int len, vect_int *p) +{ + p->len = len; + p->next = NULL; + p->prev = NULL; + p->v = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_String(t_string *ts) +{ + ts->len = -1.; + ts->next = NULL; + ts->prev = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Efrq(phydbl *b_frq, t_efrq *f) +{ + f->user_state_freq = NO; + f->empirical_state_freq = NO; + f->next = NULL; + f->prev = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Tree(t_tree *tree, int n_otu) +{ + tree->n_otu = n_otu; + tree->mat = NULL; + tree->n_root = NULL; + tree->e_root = NULL; + tree->ps_tree = NULL; + tree->short_l = NULL; + tree->mutmap = NULL; + tree->next = NULL; + tree->prev = NULL; + tree->next = NULL; + tree->prev = NULL; + tree->mixt_tree = NULL; + tree->geo = NULL; + tree->xml_root = NULL; + tree->extra_tree = NULL; + tree->verbose = VL3; + tree->edge_list = NULL; + tree->node_list = NULL; + + tree->is_mixt_tree = NO; + tree->tree_num = 0; + tree->depth_curr_path = 0; + tree->has_bip = NO; + tree->n_moves = 0; + tree->bl_from_node_stamps = 0; + tree->lock_topo = NO; + tree->ps_page_number = 0; + tree->init_lnL = UNLIKELY; + tree->best_lnL = UNLIKELY; + tree->old_lnL = UNLIKELY; + tree->c_lnL = UNLIKELY; + tree->sum_min_sum_scale = .0; + tree->n_swap = 0; + tree->best_pars = 1E+5; + tree->n_pattern = -1; + tree->n_root_pos = -1.; + tree->write_labels = YES; + tree->write_br_lens = YES; + tree->num_curr_branch_available = 0; + tree->tip_order_score = .0; + tree->write_tax_names = YES; + tree->update_alias_subpatt = NO; + tree->bl_ndigits = 8; + tree->n_short_l = 100; + tree->norm_scale = 0.0; + tree->br_len_recorded = NO; + tree->apply_lk_scaling = YES; + tree->dp = 0; + tree->ignore_root = YES; + tree->ignore_mixt_info = NO; + tree->annealing_temp = 0.; + tree->both_sides = NO; + tree->json_num = 0; + tree->update_eigen_lr = NO; + tree->use_eigen_lr = NO; + tree->eval_alnL = YES; + tree->eval_rlnL = YES; + tree->eval_glnL = YES; + tree->scaling_method = SCALE_FAST; + tree->perform_spr_right_away = YES; + tree->tip_root = 0; + tree->n_edges_traversed = 0; + tree->fully_nni_opt = NO; + tree->n_tot_bl_opt = 0; + tree->numerical_warning = NO; + +#ifdef BEAGLE + tree->b_inst = UNINITIALIZED; +#endif +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Edge_Light(t_edge *b, int num) +{ + b->num = num; + b->bip_score = 0; + b->tdist_score = .0; + b->dist_btw_edges = .0; + b->topo_dist_btw_edges = 0; + b->has_zero_br_len = NO; + b->n_jumps = 0; + b->l_var->v = -1.; + b->does_exist = YES; + b->l->v = -1.; + b->bin_cod_num = -1.; + b->l->onoff = ON; + + b->next = NULL; + b->prev = NULL; + b->next_mixt = NULL; + b->prev_mixt = NULL; + + b->p_lk_left = NULL; + b->p_lk_rght = NULL; + b->p_lk_loc_left = NULL; + b->p_lk_loc_rght = NULL; + b->Pij_rr = NULL; + b->label = NULL; + + b->pars_l = NULL; + b->pars_r = NULL; + b->ui_l = NULL; + b->ui_r = NULL; + b->p_pars_l = NULL; + b->p_pars_r = NULL; + b->n_diff_states_l = NULL; + b->n_diff_states_r = NULL; + + b->update_partial_lk_left = YES; + b->update_partial_lk_rght = YES; + +#ifdef BEAGLE + b->p_lk_left_idx = num; + b->p_lk_rght_idx = UNINITIALIZED; //Will be initialized later when the total number of branches is known (i.e. in Make_Tree_From_Scratch()) + b->Pij_rr_idx = num; + b->p_lk_tip_idx = UNINITIALIZED; //Will be initialized later only if this branch is connected to a tip +#endif + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Node_Light(t_node *n, int num) +{ + n->num = num; + n->tax = -1; + n->dist_to_root = .0; + n->common = 1; + n->ext_node = NULL; + n->name = NULL; + n->ori_name = NULL; + n->c_seq = NULL; + n->c_seq_anc = NULL; + n->y_rank = 0.; + n->y_rank_ori = 0.; + n->y_rank_max = 0.; + n->y_rank_min = 0.; + n->anc = NULL; + n->rank = 0; + n->match_node = NULL; + n->id_rank = 0; + n->next = NULL; + n->prev = NULL; + n->n_cal = 0; + n->ldsk = NULL; + n->rk_next = NULL; + n->rk_prev = NULL; + n->label = NULL; + /* n->next = NULL; */ + /* n->prev = NULL; */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_NNI(t_nni *a_nni) +{ + a_nni->left = NULL; + a_nni->rght = NULL; + a_nni->b = NULL; + a_nni->init_l = NULL; + a_nni->init_v = NULL; + a_nni->init_lk = .0; + a_nni->score = +1.0; + a_nni->best_l = NULL; + a_nni->best_v = NULL; + a_nni->swap_node_v1 = NULL; + a_nni->swap_node_v2 = NULL; + a_nni->swap_node_v3 = NULL; + a_nni->swap_node_v4 = NULL; + a_nni->lk0 = UNLIKELY; + a_nni->lk1 = UNLIKELY; + a_nni->lk2 = UNLIKELY; + a_nni->l0 = NULL; + a_nni->l1 = NULL; + a_nni->l2 = NULL; + a_nni->v0 = NULL; + a_nni->v1 = NULL; + a_nni->v2 = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Nexus_Format(nexcom **com) +{ + + /*****************************/ + + strcpy(com[0]->name,"dimensions"); + com[0]->nparm = 2; + com[0]->nxt_token_t = NEXUS_PARM; + com[0]->cur_token_t = NEXUS_COM; + + com[0]->parm[0] = Make_Nexus_Parm(); + strcpy(com[0]->parm[0]->name,"ntax"); + com[0]->parm[0]->fp = Read_Nexus_Dimensions; + com[0]->parm[0]->com = com[0]; + com[0]->parm[0]->nxt_token_t = NEXUS_EQUAL; + com[0]->parm[0]->cur_token_t = NEXUS_PARM; + + com[0]->parm[1] = Make_Nexus_Parm(); + strcpy(com[0]->parm[1]->name,"nchar"); + com[0]->parm[1]->fp = Read_Nexus_Dimensions; + com[0]->parm[1]->com = com[0]; + com[0]->parm[1]->nxt_token_t = NEXUS_EQUAL; + com[0]->parm[1]->cur_token_t = NEXUS_PARM; + + /*****************************/ + + strcpy(com[1]->name,"format"); + com[1]->nparm = 11; + com[1]->nxt_token_t = NEXUS_PARM; + com[1]->cur_token_t = NEXUS_COM; + + com[1]->parm[0] = Make_Nexus_Parm(); + strcpy(com[1]->parm[0]->name,"datatype"); + com[1]->parm[0]->fp = Read_Nexus_Format; + com[1]->parm[0]->com = com[1]; + com[1]->parm[0]->nxt_token_t = NEXUS_EQUAL; + com[1]->parm[0]->cur_token_t = NEXUS_PARM; + + com[1]->parm[1] = Make_Nexus_Parm(); + strcpy(com[1]->parm[1]->name,"respectcase"); + com[1]->parm[1]->fp = Read_Nexus_Format; + com[1]->parm[1]->com = com[1]; + com[1]->parm[1]->nxt_token_t = NEXUS_PARM; + com[1]->parm[1]->cur_token_t = NEXUS_VALUE; + + com[1]->parm[2] = Make_Nexus_Parm(); + strcpy(com[1]->parm[2]->name,"missing"); + com[1]->parm[2]->fp = Read_Nexus_Format; + com[1]->parm[2]->com = com[1]; + com[1]->parm[2]->nxt_token_t = NEXUS_EQUAL; + com[1]->parm[2]->cur_token_t = NEXUS_PARM; + + com[1]->parm[3] = Make_Nexus_Parm(); + strcpy(com[1]->parm[3]->name,"gap"); + com[1]->parm[3]->fp = Read_Nexus_Format; + com[1]->parm[3]->com = com[1]; + com[1]->parm[3]->nxt_token_t = NEXUS_EQUAL; + com[1]->parm[3]->cur_token_t = NEXUS_PARM; + + com[1]->parm[4] = Make_Nexus_Parm(); + strcpy(com[1]->parm[4]->name,"symbols"); + com[1]->parm[4]->fp = Read_Nexus_Format; + com[1]->parm[4]->com = com[1]; + com[1]->parm[4]->nxt_token_t = NEXUS_EQUAL; + com[1]->parm[4]->cur_token_t = NEXUS_PARM; + + com[1]->parm[5] = Make_Nexus_Parm(); + strcpy(com[1]->parm[5]->name,"equate"); + com[1]->parm[5]->fp = Read_Nexus_Format; + com[1]->parm[5]->com = com[1]; + com[1]->parm[5]->nxt_token_t = NEXUS_EQUAL; + com[1]->parm[5]->cur_token_t = NEXUS_PARM; + + com[1]->parm[6] = Make_Nexus_Parm(); + strcpy(com[1]->parm[6]->name,"matchchar"); + com[1]->parm[6]->fp = Read_Nexus_Format; + com[1]->parm[6]->com = com[1]; + com[1]->parm[6]->nxt_token_t = NEXUS_EQUAL; + com[1]->parm[6]->cur_token_t = NEXUS_PARM; + + com[1]->parm[7] = Make_Nexus_Parm(); + strcpy(com[1]->parm[7]->name,"transpose"); + com[1]->parm[7]->fp = Read_Nexus_Format; + com[1]->parm[7]->com = com[1]; + com[1]->parm[7]->nxt_token_t = NEXUS_PARM; + com[1]->parm[7]->cur_token_t = NEXUS_VALUE; + + com[1]->parm[8] = Make_Nexus_Parm(); + strcpy(com[1]->parm[8]->name,"interleave"); + com[1]->parm[8]->fp = Read_Nexus_Format; + com[1]->parm[8]->com = com[1]; + com[1]->parm[8]->nxt_token_t = NEXUS_PARM; + com[1]->parm[8]->cur_token_t = NEXUS_VALUE; + + com[1]->parm[9] = Make_Nexus_Parm(); + strcpy(com[1]->parm[9]->name,"items"); + com[1]->parm[9]->fp = Read_Nexus_Format; + com[1]->parm[9]->com = com[1]; + com[1]->parm[9]->nxt_token_t = NEXUS_EQUAL; + com[1]->parm[9]->cur_token_t = NEXUS_PARM; + + com[1]->parm[10] = Make_Nexus_Parm(); + strcpy(com[1]->parm[10]->name,"statesformat"); + com[1]->parm[10]->fp = Read_Nexus_Format; + com[1]->parm[10]->com = com[1]; + com[1]->parm[10]->nxt_token_t = NEXUS_EQUAL; + com[1]->parm[10]->cur_token_t = NEXUS_PARM; + + /*****************************/ + + strcpy(com[2]->name,"eliminate"); + com[2]->nparm = 0; + com[2]->nxt_token_t = NEXUS_VALUE; + com[2]->cur_token_t = NEXUS_COM; + + /*****************************/ + + strcpy(com[3]->name,"taxlabels"); + com[3]->nparm = 0; + com[3]->nxt_token_t = -1; + com[3]->cur_token_t = -1; + + /*****************************/ + + strcpy(com[4]->name,"charstatelabels"); + com[4]->nparm = 0; + com[4]->nxt_token_t = -1; + com[4]->cur_token_t = -1; + + /*****************************/ + + strcpy(com[5]->name,"charlabels"); + com[5]->nparm = 0; + com[5]->nxt_token_t = -1; + com[5]->cur_token_t = -1; + + /*****************************/ + + strcpy(com[6]->name,"statelabels"); + com[6]->nparm = 0; + com[6]->nxt_token_t = -1; + com[6]->cur_token_t = -1; + + /*****************************/ + + strcpy(com[7]->name,"matrix"); + com[7]->nparm = 1; + com[7]->nxt_token_t = NEXUS_COM; + com[7]->cur_token_t = NEXUS_VALUE; /* This will allow us to skip directly + to the matrix reading function */ + + com[7]->parm[0] = Make_Nexus_Parm(); + strcpy(com[7]->parm[0]->name,"matrix"); + com[7]->parm[0]->fp = Read_Nexus_Matrix; + com[7]->parm[0]->com = com[7]; + com[7]->parm[0]->nxt_token_t = NEXUS_COM; + com[7]->parm[0]->cur_token_t = -1; + + /*****************************/ + + strcpy(com[8]->name,"begin"); + com[8]->nparm = 3; + + com[8]->nxt_token_t = NEXUS_PARM; + com[8]->cur_token_t = NEXUS_COM; + + com[8]->parm[0] = Make_Nexus_Parm(); + strcpy(com[8]->parm[0]->name,"data"); + com[8]->parm[0]->fp = Read_Nexus_Begin; + com[8]->parm[0]->com = com[8]; + com[8]->parm[0]->nxt_token_t = NEXUS_COM; + com[8]->parm[0]->cur_token_t = NEXUS_PARM; + + + com[8]->parm[1] = Make_Nexus_Parm(); + strcpy(com[8]->parm[1]->name,"trees"); + com[8]->parm[1]->fp = Read_Nexus_Begin; + com[8]->parm[1]->com = com[8]; + com[8]->parm[1]->nxt_token_t = NEXUS_COM; + com[8]->parm[1]->cur_token_t = NEXUS_PARM; + + + com[8]->parm[2] = Make_Nexus_Parm(); + strcpy(com[8]->parm[2]->name,"taxa"); + com[8]->parm[2]->fp = Read_Nexus_Taxa; + com[8]->parm[2]->com = com[8]; + com[8]->parm[2]->nxt_token_t = NEXUS_COM; + com[8]->parm[2]->cur_token_t = NEXUS_VALUE; + + + /*****************************/ + + strcpy(com[9]->name,"end"); + com[9]->nparm = 0; + com[9]->nxt_token_t = -1; + com[9]->cur_token_t = -1; + + /*****************************/ + + strcpy(com[10]->name,"translate"); + com[10]->nparm = 1; + com[10]->nxt_token_t = NEXUS_COM; + com[10]->cur_token_t = NEXUS_VALUE; + + com[10]->parm[0] = Make_Nexus_Parm(); + strcpy(com[10]->parm[0]->name,"translate"); + com[10]->parm[0]->fp = Read_Nexus_Translate; + com[10]->parm[0]->com = com[10]; + com[10]->parm[0]->nxt_token_t = NEXUS_COM; + com[10]->parm[0]->cur_token_t = -1; + + /*****************************/ + + strcpy(com[11]->name,"tree"); + com[11]->nparm = 1; + com[11]->nxt_token_t = NEXUS_COM; + com[11]->cur_token_t = NEXUS_VALUE; + + com[11]->parm[0] = Make_Nexus_Parm(); + strcpy(com[11]->parm[0]->name,"tree"); + com[11]->parm[0]->fp = Read_Nexus_Tree; + com[11]->parm[0]->com = com[11]; + com[11]->parm[0]->nxt_token_t = -1; + com[11]->parm[0]->cur_token_t = -1; + + + /*****************************/ + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Mat(matrix *mat, calign *data) +{ + int i; + + mat->n_otu = data->n_otu; + mat->r = mat->n_otu; + mat->curr_int = mat->n_otu; + mat->method = 1; + + for(i=0;in_otu;i++) + { + strcpy(mat->name[i],data->c_seq[i]->name); + mat->on_off[i] = 1; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Set_Defaults_Input(option* io) +{ + io->fp_in_align = NULL; + io->fp_in_tree = NULL; + io->fp_in_constraint_tree = NULL; + io->fp_out_tree = NULL; + io->fp_out_trees = NULL; + io->fp_out_boot_tree = NULL; + io->fp_out_boot_stats = NULL; + io->fp_out_stats = NULL; + io->fp_out_ancestral_seq = NULL; + io->fp_out_ancestral_tree = NULL; + io->fp_in_coord = NULL; + io->fp_out_trace = NULL; + io->fp_weight_file = NULL; + io->fp_out_json_trace = NULL; + io->fp_out_lk = NULL; + io->fp_out_trace = NULL; + io->long_tax_names = NULL; + io->short_tax_names = NULL; + io->lon = NULL; + io->lat = NULL; + io->z_scores = NULL; + io->cstr_tree = NULL; + io->next = NULL; + io->prev = NULL; + io->tree = NULL; + io->mod = NULL; + strcpy(io->nt_or_cd,"nucleotides"); + io->tbe_bootstrap = NO; + io->n_data_sets = 1; + io->interleaved = 1; + io->in_tree = 0; + io->out_tree_file_open_mode = 1; + io->out_stats_file_open_mode = 1; + io->init_len = -1; + io->n_otu = -1; + io->n_data_set_asked = -1; + io->print_boot_trees = 1; + io->n_part = 1; + io->ratio_test = ABAYES; + io->multigene = 0; + io->config_multigene = 0; + io->curr_interface = 0; + io->r_seed = -1; + io->collapse_boot = 0; + io->random_boot_seq_order = YES; + io->print_trace = NO; + io->print_json_trace = NO; + io->print_site_lnl = NO; + io->m4_model = NO; + io->rm_ambigu = NO; + io->append_run_ID = NO; + io->quiet = NO; + io->datatype = NT; + io->colalias = YES; + io->data_file_format = PHYLIP; + io->tree_file_format = PHYLIP; + io->boot_prog_every = 20; + io->mem_question = YES; + io->do_alias_subpatt = NO; + io->lk_approx = EXACT; + io->codpos = -1; + io->mutmap = NO; + io->state_len = 1; + io->ancestral = NO; + io->use_xml = NO; + io->has_io_weights = NO; + io->do_boot = NO; + io->do_alrt = YES; + io->do_tbe = NO; + io->print_node_num = NO; + io->print_support_val = NO; + io->n_boot_replicates = 0; + +#ifdef BEAGLE + io->beagle_resource = 0; +#endif + io->precision = 0; + + MCMC_Init_MCMC_Struct(NULL,io,io->mcmc); + RATES_Init_Rate_Struct(io->rates,NULL,-1); + io->rates->model = LOGNORMAL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Rmat(t_rmat *rmat) +{ + rmat->n_diff_rr = 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Set_Defaults_Model(t_mod *mod) +{ + Set_Defaults_Ras(mod->ras); + + strcpy(mod->modelname->s,"HKY85"); + strcpy(mod->custom_mod_string->s,"000000"); + mod->next = NULL; + mod->prev = NULL; + mod->next_mixt = NULL; + mod->prev_mixt = NULL; + mod->r_mat = NULL; + mod->e_frq = NULL; + mod->whichmodel = HKY85; + mod->n_mixt_classes = 0; + mod->mod_num = 0; + mod->update_eigen = NO; + mod->is_mixt_mod = NO; + + mod->kappa->v = 4.0; + mod->lambda->v = 1.0; + mod->l_var_sigma = 1.E-2; + mod->e_frq_weight->v = 1.0; + mod->r_mat_weight->v = 1.0; + + mod->ns = 4; + mod->use_m4mod = NO; + mod->ras->gamma_median = NO; + mod->m4mod = NULL; + + /* mod->r_mat->n_diff_rr = 0; */ + /* mod->r_mat->rr = NULL; */ + /* mod->r_mat->rr_val = NULL; */ + /* mod->r_mat->n_rr_per_cat = NULL; */ + + mod->io = NULL; + mod->log_l = NO; + mod->gamma_mgf_bl = NO; + mod->br_len_mult->v = 1.0; + + +#if !(defined PHYTIME || defined PHYREX) + mod->l_min = 1.E-8; + mod->l_max = 100.0; +#else + mod->l_min = 1.E-8; + mod->l_max = 1.E+3; +#endif + + mod->l_var_min = mod->l_min; + mod->l_var_max = mod->l_max; + + mod->br_len_mult->v = 1.0; + mod->br_len_mult_unscaled->v = 1.0; + mod->augmented = NO; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Set_Defaults_Ras(t_ras *ras) +{ + ras->n_catg = 4; + ras->normalise_rr = YES; + ras->pinvar->v = 0.0; + ras->alpha->v = 1.0; + ras->invar = NO; + ras->free_mixt_rates = NO; + ras->parent_class_number = 0; + ras->init_r_proba = YES; + ras->init_rr = YES; + ras->sort_rate_classes = NO; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Set_Defaults_Optimiz(t_opt *s_opt) +{ + s_opt->last_opt = YES; + s_opt->opt_subst_param = YES; + s_opt->opt_alpha = YES; + s_opt->opt_kappa = YES; + s_opt->opt_bl = YES; + s_opt->opt_lambda = NO; + s_opt->opt_pinvar = NO; + s_opt->opt_cov_delta = NO; + s_opt->opt_cov_alpha = NO; + s_opt->opt_cov_free_rates = NO; + s_opt->opt_rr = NO; + s_opt->init_lk = UNLIKELY; + s_opt->n_it_max = 1000; + s_opt->opt_topo = YES; + s_opt->topo_search = NNI_MOVE; + s_opt->random_input_tree = 0; + s_opt->n_rand_starts = 5; + s_opt->brent_it_max = BRENT_IT_MAX; + s_opt->steph_spr = YES; + s_opt->opt_br_len_mult = NO; + s_opt->min_n_triple_moves = 20; + s_opt->max_rank_triple_move = 0; + s_opt->n_improvements = 0; + s_opt->max_spr_depth = 0; + s_opt->opt_clock_r = YES; + + s_opt->min_diff_lk_local = 1.E-03; + s_opt->min_diff_lk_global = 1.E-03; + s_opt->min_diff_lk_move = 1.E-03; + + s_opt->p_moves_to_examine = 0.15; + s_opt->fast_nni = NO; + s_opt->greedy = NO; + s_opt->general_pars = NO; + s_opt->tree_size_mult = 1; + s_opt->opt_five_branch = YES; + s_opt->nni_br_len_opt = YES; + + s_opt->pars_thresh = 5; + + s_opt->hybrid_thresh = NO; + s_opt->quickdirty = NO; + s_opt->spr_pars = YES; + s_opt->spr_lnL = NO; + s_opt->min_depth_path = 0; + s_opt->eval_list_regraft = NO; + + s_opt->max_depth_path = 2000; + s_opt->deepest_path = 2000; + s_opt->max_delta_lnL_spr = 2000000.; + s_opt->max_delta_lnL_spr_current = 0.0; + s_opt->worst_lnL_spr = BIG; + + s_opt->br_len_in_spr = 10; + s_opt->opt_free_mixt_rates = YES; + s_opt->constrained_br_len = NO; + s_opt->opt_gamma_br_len = NO; + s_opt->first_opt_free_mixt_rates = YES; + + s_opt->wim_n_rgrft = -1; + s_opt->wim_n_globl = -1; + s_opt->wim_max_dist = -1; + s_opt->wim_n_optim = -1; + s_opt->wim_n_best = -1; + s_opt->wim_inside_opt = 0; + + s_opt->opt_rmat_weight = NO; + s_opt->opt_efrq_weight = NO; + + s_opt->skip_tree_traversal = NO; + s_opt->serial_free_rates = YES; + + s_opt->curr_opt_free_rates = NO; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Init_Attribute(xml_attr *attr) +{ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Init_Node(xml_node *parent, xml_node *new_node, char *name) +{ + if(name) strcpy(new_node->name,name); + + new_node->parent = parent ? parent : NULL; + new_node->next = NULL; + new_node->prev = NULL; + new_node->child = NULL; + new_node->ds->obj = NULL; + new_node->ds->next = NULL; + + if(parent) + { + if(!parent->child) + { + parent->child = new_node; + } + else + { + xml_node *node = parent->child; + while(node->next) node = node->next; + node->next = new_node; + new_node->prev = node; + } + } + + new_node->attr = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Init_Rate_Struct(t_rate *rates, t_rate *existing_rates, int n_otu) +{ + int i; + + if(existing_rates && existing_rates->model != -1) + { + rates->model = existing_rates->model; + } + else + { + rates->model = NONE; + } + + rates->met_within_gibbs = NO; + rates->c_lnL_rates = UNLIKELY; + rates->c_lnL_times = UNLIKELY; + rates->c_lnL_jps = UNLIKELY; + rates->adjust_rates = 0; + rates->use_rates = 1; + rates->lexp = 1.E-3; + rates->norm_fact = 1.0; + rates->inflate_var = 1.0; + rates->nd_t_recorded = NO; + rates->br_r_recorded = NO; + + rates->birth_rate = 1.E-1; + rates->birth_rate_min = 1.E-6; + rates->birth_rate_max = 1.E+0; + rates->birth_rate_pivot = 1.E-1; + + rates->death_rate = 1.E-1; + rates->death_rate_min = 1.E-6; + rates->death_rate_max = 1.E+0; + rates->death_rate_pivot = 1.E-1; + + rates->max_rate = 100.0; + rates->min_rate = 0.001; + + rates->clock_r = 1.E-4; + rates->min_clock = 1.E-10; + rates->max_clock = 1.E+0; + + /* rates->clock_r = 3.E-4; */ + /* rates->max_clock = 1.E-3; */ + /* rates->min_clock = 1.E-5; */ + + rates->nu = 1.0E-1; + rates->min_nu = 0.0; + rates->max_nu = 2.0; + + /* rates->max_nu = 2.0; */ + + /* rates->nu = 1.E-4; */ + /* rates->max_nu = 1.E-1; */ + /* rates->min_nu = 1.E-5; */ + + rates->min_dt = 0.0; + + rates->step_rate = 1.E-4; + rates->approx = 1; + rates->bl_from_rt = NO; + + rates->update_mean_l = NO; + rates->update_cov_l = NO; + rates->n_cal = 0; + + rates->p_max = 0.01; + + rates->true_tree_size = 0.0; + + if(n_otu > 0) + { + for(i=0;i<(2*n_otu-2)*(2*n_otu-2);++i) rates->cov_l[i] = 0.0; + + for(i=0;i<2*n_otu-2;++i) + { + rates->n_jps[i] = -1; + rates->t_jps[i] = -1; + rates->mean_r[i] = 1.0; + rates->mean_l[i] = 0.0; + rates->cur_l[i] = 0.01; + } + + for(i=0;i<2*n_otu-1;++i) + { + rates->nd_r[i] = 1.0; + rates->br_r[i] = 1.0; + + rates->mean_t[i] = 0.0; + rates->nd_t[i] = 0.0; + rates->true_t[i] = 0.0; + if(i < n_otu) + { + rates->t_has_prior[i] = YES; + rates->t_prior_max[i] = 0.0; + rates->t_prior_min[i] = 0.0; + } + else + { + rates->t_has_prior[i] = NO; + rates->t_prior_max[i] = 0.0; + rates->t_prior_min[i] = -BIG; + } + + rates->br_do_updt[i] = YES; + rates->has_survived[i] = NO; + + rates->t_rank[i] = i; + } + } + + rates->update_time_norm_const = NO; + rates->is_asynchronous = NO; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_One_Spr(t_spr *a_spr) +{ + a_spr->lnL = UNLIKELY; + a_spr->pars = 1E+5; + a_spr->depth_path = 0; + a_spr->dist = 0; + a_spr->init_target_l = NULL; + a_spr->init_target_v = NULL; + a_spr->l0 = NULL; + a_spr->l1 = NULL; + a_spr->l2 = NULL; + a_spr->v0 = NULL; + a_spr->v1 = NULL; + a_spr->v2 = NULL; + a_spr->n_link = NULL; + a_spr->n_opp_to_link = NULL; + a_spr->b_opp_to_link = NULL; + a_spr->b_target = NULL; + a_spr->b_init_target = NULL; + a_spr->next = NULL; + a_spr->prev = NULL; + a_spr->next = NULL; + a_spr->prev = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Target_Tip(t_clad *clade, t_tree *tree) +{ + int i,j; + + for(i=0;in_tax;++i) + { + for(j=0;jn_otu;++j) + { + if(!strcmp(tree->a_nodes[j]->name,clade->tax_list[i])) + { + clade->tip_list[i] = tree->a_nodes[j]; + break; + } + } + assert(j != tree->n_otu); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Model(calign *data, t_mod *mod, option *io) +{ + int i,j; + phydbl sum,aux; + int result; + phydbl *dr, *di, *space; + + assert(data); + assert(mod); + assert(io); + +#ifdef BEAGLE + mod->b_inst = UNINITIALIZED; //prevents calling an uninitialized BEAGLE instance (for ex: prevents Update_Eigen(), Update_RAS(), from calling BEAGLE) + mod->optimizing_topology = false; +#endif + + mod->ns = io->mod->ns; + + if(io->datatype == GENERIC) mod->whichmodel = JC69; + + dr = (phydbl *)mCalloc( mod->ns,sizeof(phydbl)); + di = (phydbl *)mCalloc( mod->ns,sizeof(phydbl)); + space = (phydbl *)mCalloc(2*mod->ns,sizeof(phydbl)); + + if(mod->log_l == YES) + { + mod->l_min = log(mod->l_min); + mod->l_max = log(mod->l_max); + } + + // Init unscaled relative rate frequencies + if(mod->ras->init_r_proba == YES) + { + for(i=0;iras->n_catg;i++) mod->ras->gamma_r_proba->v[i] = (phydbl)1./mod->ras->n_catg; + for(i=0;iras->n_catg;i++) mod->ras->gamma_r_proba_unscaled->v[i] = (phydbl)(i+1); + } + else + { + mod->ras->gamma_r_proba_unscaled->v[mod->ras->n_catg-1] = 1.0; + for(i=0;iras->n_catg;i++) + { + sum = 0.0; + For(j,i+1) sum += mod->ras->gamma_r_proba->v[j]; + mod->ras->gamma_r_proba_unscaled->v[i] = sum * mod->ras->gamma_r_proba_unscaled->v[mod->ras->n_catg-1]; + } + } + + // Init unscaled relative rates + if(mod->ras->init_rr == YES) + { + if(mod->ras->n_catg > 1) + { + for(i=0;iras->n_catg;i++) mod->ras->gamma_rr->v[i] = (phydbl)i; + for(i=0;iras->n_catg;i++) mod->ras->gamma_rr_unscaled->v[i] = (phydbl)i; + } + else + { + mod->ras->gamma_rr->v[0] = 1.0; + mod->ras->gamma_rr_unscaled->v[0] = 1.0; + } + } + else + { + for(i=0;iras->n_catg;i++) mod->ras->gamma_rr_unscaled->v[i] = mod->ras->gamma_rr->v[i]; + } + + if(io->datatype == NT) + { + /* Set the substitution parameters to their default values + if they are not fixed by the user */ + + if(mod->s_opt->opt_kappa == YES) + { + mod->kappa->v = 4.0; + mod->lambda->v = 1.0; + } + + + if(mod->whichmodel == CUSTOM) + { + for(i=0;i<6;i++) + { + mod->r_mat->rr_val->v[i] = 0.0; + mod->r_mat->rr->v[i] = 1.0; + } + + /* Condition below is true if custom model corresponds to TN93 or K80 */ + if(mod->r_mat->rr_num->v[AC] == mod->r_mat->rr_num->v[AT] && + mod->r_mat->rr_num->v[AT] == mod->r_mat->rr_num->v[CG] && + mod->r_mat->rr_num->v[CG] == mod->r_mat->rr_num->v[GT] && + mod->r_mat->rr_num->v[AG] != mod->r_mat->rr_num->v[AC] && + mod->r_mat->rr_num->v[CT] != mod->r_mat->rr_num->v[AC]) + { + for(i=1;ir_mat->n_diff_rr;i++) + { + mod->r_mat->rr_val->v[i] = log(2.0); + mod->r_mat->rr->v[i] = 2.0; + } + } + else if(mod->r_mat->n_diff_rr == 6) /* Custom <-> GTR model */ + { + mod->r_mat->rr_val->v[AG] = log(2.0); + mod->r_mat->rr_val->v[CT] = log(2.0); + + mod->r_mat->rr->v[AG] = 2.0; + mod->r_mat->rr->v[CT] = 2.0; + } + } + else if(mod->whichmodel == GTR) + { + if(mod->s_opt->opt_rr == YES) + { + for(i=0;i<6;i++) mod->r_mat->rr_val->v[i] = 0.0; + for(i=0;i<6;i++) mod->r_mat->rr->v[i] = 1.0; + + mod->r_mat->rr_val->v[AG] = log(2.0); + mod->r_mat->rr_val->v[CT] = log(2.0); + + mod->r_mat->rr->v[AG] = 2.0; + mod->r_mat->rr->v[CT] = 2.0; + } + } + } + + if(mod->s_opt->opt_alpha) mod->ras->alpha->v = 1.0; + if(mod->s_opt->opt_pinvar) mod->ras->pinvar->v = 0.2; + + if(io->datatype == NT) /* Nucleotides */ + { + /* init for nucleotides */ + + if(mod->whichmodel == JC69) + { + mod->e_frq->pi->v[0] = mod->e_frq->pi->v[1] = mod->e_frq->pi->v[2] = mod->e_frq->pi->v[3] = .25; + mod->kappa->v = 1.; + mod->s_opt->opt_state_freq = NO; + mod->s_opt->opt_kappa = NO; + mod->s_opt->opt_lambda = NO; + mod->update_eigen = NO; + } + + if(mod->whichmodel == K80) + { + mod->e_frq->pi->v[0] = mod->e_frq->pi->v[1] = mod->e_frq->pi->v[2] = mod->e_frq->pi->v[3] = .25; + mod->s_opt->opt_state_freq = NO; + mod->s_opt->opt_lambda = NO; + mod->update_eigen = NO; + } + + if(mod->whichmodel == F81) + { + if(mod->e_frq->user_state_freq == NO) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + else for(i=0;i<4;i++) mod->e_frq->pi->v[i] = mod->e_frq->user_b_freq->v[i]; + for(i=0;ins;i++) mod->e_frq->pi_unscaled->v[i] = log(mod->e_frq->pi->v[i]); + mod->kappa->v = 1.; + mod->update_eigen = NO; + } + + if(mod->whichmodel == F84) + { + if(mod->e_frq->user_state_freq == NO) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + else for(i=0;i<4;i++) mod->e_frq->pi->v[i] = mod->e_frq->user_b_freq->v[i]; + for(i=0;ins;i++) mod->e_frq->pi_unscaled->v[i] = log(mod->e_frq->pi->v[i]); + aux = ((mod->e_frq->pi->v[0]+mod->e_frq->pi->v[2])-(mod->e_frq->pi->v[1]+mod->e_frq->pi->v[3]))/(2.*mod->kappa->v); + mod->lambda->v = ((mod->e_frq->pi->v[1]+mod->e_frq->pi->v[3]) + aux)/((mod->e_frq->pi->v[0]+mod->e_frq->pi->v[2]) - aux); + mod->update_eigen = NO; + } + + if(mod->whichmodel == TN93) + { + if(mod->e_frq->user_state_freq == NO) + Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + else + for(i=0;i<4;i++) + mod->e_frq->pi->v[i] = mod->e_frq->user_b_freq->v[i]; + for(i=0;ins;i++) + mod->e_frq->pi_unscaled->v[i] = log(mod->e_frq->pi->v[i]); + mod->update_eigen = NO; + if(io->mod->s_opt->opt_kappa) io->mod->s_opt->opt_lambda = YES; + + } + + if(mod->whichmodel == HKY85) + { + if(mod->e_frq->user_state_freq == NO) + Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + else + for(i=0;i<4;i++) + mod->e_frq->pi->v[i] = mod->e_frq->user_b_freq->v[i]; + for(i=0;ins;i++) + mod->e_frq->pi_unscaled->v[i] = log(mod->e_frq->pi->v[i]); + mod->update_eigen = NO; + } + + if(mod->whichmodel == GTR) + { + if (mod->e_frq->user_state_freq == NO) + Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + else + for(i=0;i<4;i++) + mod->e_frq->pi->v[i] = mod->e_frq->user_b_freq->v[i]; + for(i=0;ins;i++) + mod->e_frq->pi_unscaled->v[i] = log(mod->e_frq->pi->v[i]); + mod->kappa->v = 1.; + mod->update_eigen = NO; + } + + if(mod->whichmodel == CUSTOM) + { + if(mod->e_frq->user_state_freq == NO) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + else for(i=0;i<4;i++) mod->e_frq->pi->v[i] = mod->e_frq->user_b_freq->v[i]; + for(i=0;ins;i++) mod->e_frq->pi_unscaled->v[i] = log(mod->e_frq->pi->v[i]); + mod->kappa->v = 1.; + mod->update_eigen = NO; + } + + if(mod->whichmodel == GTR) + { + mod->custom_mod_string->s[0] = '0'; + mod->custom_mod_string->s[1] = '1'; + mod->custom_mod_string->s[2] = '2'; + mod->custom_mod_string->s[3] = '3'; + mod->custom_mod_string->s[4] = '4'; + mod->custom_mod_string->s[5] = '5'; + Translate_Custom_Mod_String(mod); + } + } + else if(mod->io->datatype == AA) + { + + /* init for amino-acids */ + /* see comments of PMat_Empirical for details */ + /* read pi and Q from file */ + + /* These initialisations are needed when analysing multiple + * data sets + */ + For(i,mod->ns*mod->ns) mod->r_mat->qmat->v[i] = .0; + For(i,mod->ns ) mod->e_frq->pi->v[i] = .0; + + switch(mod->whichmodel) + { + case DAYHOFF : + { + Init_Qmat_Dayhoff(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case JTT : + { + Init_Qmat_JTT(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case MTREV : + { + Init_Qmat_MtREV(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case LG : + { + Init_Qmat_LG(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case WAG : + { + Init_Qmat_WAG(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case DCMUT : + { + Init_Qmat_DCMut(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case RTREV : + { + Init_Qmat_RtREV(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case CPREV : + { + Init_Qmat_CpREV(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case VT : + { + Init_Qmat_VT(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case BLOSUM62 : + { + Init_Qmat_Blosum62(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case MTMAM : + { + Init_Qmat_MtMam(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case MTART : + { + Init_Qmat_MtArt(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case HIVW : + { + Init_Qmat_HIVw(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case HIVB : + { + Init_Qmat_HIVb(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case AB : + { + Init_Qmat_AB(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case CUSTOMAA : + { + mod->fp_aa_rate_mat = Openfile(mod->aa_rate_mat_file->s,READ); + Read_Qmat(mod->r_mat->qmat->v,mod->e_frq->pi->v,mod->fp_aa_rate_mat); + fclose(mod->fp_aa_rate_mat); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + case FLU : + { + Init_Qmat_FLU(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + default : + { + Init_Qmat_LG(mod->r_mat->qmat->v,mod->e_frq->pi->v); + if(mod->e_frq->empirical_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + break; + } + } + + if(mod->s_opt->opt_state_freq == YES) Init_Efrqs_Using_Observed_Freqs(mod->e_frq,data->obs_state_frq,mod->ns); + + + // Adjust equilibrium state frequencies if some of them are too close to zero + // in order to avoid numerical precision issues. + int iter = 0; + do + { + for(i=0;ins;i++) if(mod->e_frq->pi->v[i] < E_FRQ_MIN) mod->e_frq->pi->v[i] = E_FRQ_MIN; + sum = 0.0; + for(i=0;ins;i++) sum += fabs(mod->e_frq->pi->v[i]); + for(i=0;ins;i++) mod->e_frq->pi->v[i] /= sum; + iter++; + } + while(iter < 10); + + /* multiply the nth col of Q by the nth term of pi/100 just as in PAML */ + for(i=0;ins;i++) for(j=0;jns;j++) mod->r_mat->qmat->v[i*mod->ns+j] *= mod->e_frq->pi->v[j] / 100.0; + + /* compute diagonal terms of Q and mean rate mr = l/t */ + mod->mr->v= .0; + For (i,mod->ns) + { + sum=.0; + For(j, mod->ns) sum += mod->r_mat->qmat->v[i*mod->ns+j]; + mod->r_mat->qmat->v[i*mod->ns+i] = -sum; + mod->mr->v += mod->e_frq->pi->v[i] * sum; + } + + /* scale instantaneous rate matrix so that mu=1 */ + For (i,mod->ns*mod->ns) mod->r_mat->qmat->v[i] /= mod->mr->v; + + /* compute eigenvectors/values */ + result = 0; + + For(i,mod->ns*mod->ns) mod->r_mat->qmat_buff->v[i] = mod->r_mat->qmat->v[i]; + + if(!Eigen(1,mod->r_mat->qmat_buff->v,mod->eigen->size,mod->eigen->e_val, + mod->eigen->e_val_im,mod->eigen->r_e_vect, + mod->eigen->r_e_vect_im,mod->eigen->space)) + { + /* compute inverse(Vr) into Vi */ + For (i,mod->ns*mod->ns) mod->eigen->l_e_vect[i] = mod->eigen->r_e_vect[i]; + if(!Matinv(mod->eigen->l_e_vect,mod->eigen->size,mod->eigen->size,YES)) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d.",__FILE__,__LINE__); + Exit("\n"); + } + + /* compute the diagonal terms of exp(D) */ + for(i=0;ins;i++) mod->eigen->e_val[i] = (phydbl)exp(mod->eigen->e_val[i]); + } + else + { + if (result==-1) PhyML_Printf("\n. Eigenvalues/vectors computation does not converge : computation cancelled"); + else if (result==1) PhyML_Printf("\n. Complex eigenvalues/vectors : computation cancelled"); + } + } + else if(mod->io->datatype == GENERIC) + { + /* Uniform state frequencies */ + for(i=0;ins;i++) mod->e_frq->pi->v[i] = 1./(phydbl)mod->ns; + mod->kappa->v = 1; + mod->s_opt->opt_state_freq = NO; + mod->s_opt->opt_kappa = NO; + mod->s_opt->opt_lambda = NO; + mod->update_eigen = NO; + for(i=0;ins*(mod->ns-1)/2;i++) mod->r_mat->rr_val->v[i] = 0.0; + for(i=0;ins*(mod->ns-1)/2;i++) mod->r_mat->rr->v[i] = 1.0; + } + else + { + PhyML_Fprintf(stderr,"\n. Datatype not recognized.\n"); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + Init_Eigen_Struct(mod->eigen); + + Set_Model_Parameters(mod); + + free(dr); + free(di); + free(space); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Efrqs_Using_Observed_Freqs(t_efrq *f, phydbl *o, int ns) +{ + int i; + phydbl eps,sum; + + assert(f); + assert(o); + + // To avoid numerical prevision issues + eps = 1.E-50; + + for(i=0;ipi->v[i] = MAX(o[i],eps); + + sum = 0.0; + for(i=0;ipi->v[i]; + + for(i=0;ipi->v[i] /= sum;; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Init_Qmat_Dayhoff(phydbl *daa, phydbl *pi) +{ + /* Dayhoff's model data + * Dayhoff, M.O., Schwartz, R.M., Orcutt, B.C. (1978) + * "A model of evolutionary change in proteins." + * Dayhoff, M.O.(ed.) Atlas of Protein Sequence Structur., Vol5, Suppl3. + * National Biomedical Research Foundation, Washington DC, pp.345-352. + */ + int i,j,naa; + + naa = 20; + +/* PhyML_Printf("\n\n. REMINDER : THIS IS NOT DAYHOFF !!!\n\n"); */ + +/* daa[1*20 + 0] = 0.538903; */ +/* daa[2*20 + 0] = 0.412504; */ +/* daa[2*20 + 1] = 0.736081; */ +/* daa[3*20 + 0] = 0.586915; */ +/* daa[3*20 + 1] = 0.108051; */ +/* daa[3*20 + 2] = 5.446642; */ +/* daa[4*20 + 0] = 2.189718; */ +/* daa[4*20 + 1] = 0.830604; */ +/* daa[4*20 + 2] = 0.573426; */ +/* daa[4*20 + 3] = 0.077565; */ +/* daa[5*20 + 0] = 1.08213; */ +/* daa[5*20 + 1] = 2.950693; */ +/* daa[5*20 + 2] = 1.739514; */ +/* daa[5*20 + 3] = 0.559035; */ +/* daa[5*20 + 4] = 0.111314; */ +/* daa[6*20 + 0] = 1.386865; */ +/* daa[6*20 + 1] = 0.358434; */ +/* daa[6*20 + 2] = 0.541447; */ +/* daa[6*20 + 3] = 5.406871; */ +/* daa[6*20 + 4] = 0.003738; */ +/* daa[6*20 + 5] = 4.124043; */ +/* daa[7*20 + 0] = 2.085747; */ +/* daa[7*20 + 1] = 0.453132; */ +/* daa[7*20 + 2] = 1.815844; */ +/* daa[7*20 + 3] = 1.08647; */ +/* daa[7*20 + 4] = 0.526418; */ +/* daa[7*20 + 5] = 0.347693; */ +/* daa[7*20 + 6] = 0.438476; */ +/* daa[8*20 + 0] = 0.407898; */ +/* daa[8*20 + 1] = 2.689322; */ +/* daa[8*20 + 2] = 5.386808; */ +/* daa[8*20 + 3] = 0.884563; */ +/* daa[8*20 + 4] = 0.658583; */ +/* daa[8*20 + 5] = 4.588358; */ +/* daa[8*20 + 6] = 0.386218; */ +/* daa[8*20 + 7] = 0.368668; */ +/* daa[9*20 + 0] = 0.10177; */ +/* daa[9*20 + 1] = 0.104875; */ +/* daa[9*20 + 2] = 0.16239; */ +/* daa[9*20 + 3] = 0.011698; */ +/* daa[9*20 + 4] = 0.253282; */ +/* daa[9*20 + 5] = 0.083872; */ +/* daa[9*20 + 6] = 0.041767; */ +/* daa[9*20 + 7] = 0.009778; */ +/* daa[9*20 + 8] = 0.1042; */ +/* daa[10*20 + 0] = 0.248202; */ +/* daa[10*20 + 1] = 0.375742; */ +/* daa[10*20 + 2] = 0.093863; */ +/* daa[10*20 + 3] = 0.019241; */ +/* daa[10*20 + 4] = 0.572688; */ +/* daa[10*20 + 5] = 0.703538; */ +/* daa[10*20 + 6] = 0.071961; */ +/* daa[10*20 + 7] = 0.03006; */ +/* daa[10*20 + 8] = 0.418222; */ +/* daa[10*20 + 9] = 3.702051; */ +/* daa[11*20 + 0] = 0.652019; */ +/* daa[11*20 + 1] = 5.940478; */ +/* daa[11*20 + 2] = 2.352253; */ +/* daa[11*20 + 3] = 0.231001; */ +/* daa[11*20 + 4] = 0.027995; */ +/* daa[11*20 + 5] = 3.646743; */ +/* daa[11*20 + 6] = 1.507981; */ +/* daa[11*20 + 7] = 0.331175; */ +/* daa[11*20 + 8] = 0.698362; */ +/* daa[11*20 + 9] = 0.140326; */ +/* daa[11*20 + 10] = 0.171396; */ +/* daa[12*20 + 0] = 0.694226; */ +/* daa[12*20 + 1] = 0.419899; */ +/* daa[12*20 + 2] = 0.326927; */ +/* daa[12*20 + 3] = 0.039488; */ +/* daa[12*20 + 4] = 0.844827; */ +/* daa[12*20 + 5] = 1.394214; */ +/* daa[12*20 + 6] = 0.133235; */ +/* daa[12*20 + 7] = 0.085075; */ +/* daa[12*20 + 8] = 0.347092; */ +/* daa[12*20 + 9] = 4.051255; */ +/* daa[12*20 + 10] = 6.650794; */ +/* daa[12*20 + 11] = 0.617549; */ +/* daa[13*20 + 0] = 0.155206; */ +/* daa[13*20 + 1] = 0.057971; */ +/* daa[13*20 + 2] = 0.09816; */ +/* daa[13*20 + 3] = 0.020441; */ +/* daa[13*20 + 4] = 0.904305; */ +/* daa[13*20 + 5] = 0.052719; */ +/* daa[13*20 + 6] = 0.0219; */ +/* daa[13*20 + 7] = 0.046668; */ +/* daa[13*20 + 8] = 0.890005; */ +/* daa[13*20 + 9] = 0.844963; */ +/* daa[13*20 + 10] = 2.348881; */ +/* daa[13*20 + 11] = 0.028372; */ +/* daa[13*20 + 12] = 1.671635; */ +/* daa[14*20 + 0] = 1.433475; */ +/* daa[14*20 + 1] = 0.328393; */ +/* daa[14*20 + 2] = 0.173181; */ +/* daa[14*20 + 3] = 0.431874; */ +/* daa[14*20 + 4] = 0.09902; */ +/* daa[14*20 + 5] = 0.592324; */ +/* daa[14*20 + 6] = 0.488352; */ +/* daa[14*20 + 7] = 0.23865; */ +/* daa[14*20 + 8] = 0.462856; */ +/* daa[14*20 + 9] = 0.057048; */ +/* daa[14*20 + 10] = 0.233532; */ +/* daa[14*20 + 11] = 0.387808; */ +/* daa[14*20 + 12] = 0.096377; */ +/* daa[14*20 + 13] = 0.079912; */ +/* daa[15*20 + 0] = 4.887126; */ +/* daa[15*20 + 1] = 0.883923; */ +/* daa[15*20 + 2] = 4.627163; */ +/* daa[15*20 + 3] = 1.122164; */ +/* daa[15*20 + 4] = 3.186667; */ +/* daa[15*20 + 5] = 1.085947; */ +/* daa[15*20 + 6] = 0.569339; */ +/* daa[15*20 + 7] = 1.993432; */ +/* daa[15*20 + 8] = 0.867972; */ +/* daa[15*20 + 9] = 0.070512; */ +/* daa[15*20 + 10] = 0.163009; */ +/* daa[15*20 + 11] = 0.718913; */ +/* daa[15*20 + 12] = 0.301103; */ +/* daa[15*20 + 13] = 0.32579; */ +/* daa[15*20 + 14] = 1.449582; */ +/* daa[16*20 + 0] = 2.030538; */ +/* daa[16*20 + 1] = 0.639463; */ +/* daa[16*20 + 2] = 2.076294; */ +/* daa[16*20 + 3] = 0.377239; */ +/* daa[16*20 + 4] = 1.42848; */ +/* daa[16*20 + 5] = 0.979403; */ +/* daa[16*20 + 6] = 0.647562; */ +/* daa[16*20 + 7] = 0.145556; */ +/* daa[16*20 + 8] = 0.493329; */ +/* daa[16*20 + 9] = 0.973405; */ +/* daa[16*20 + 10] = 0.271824; */ +/* daa[16*20 + 11] = 1.20033; */ +/* daa[16*20 + 12] = 1.659187; */ +/* daa[16*20 + 13] = 0.1217; */ +/* daa[16*20 + 14] = 0.571399; */ +/* daa[16*20 + 15] = 6.641034; */ +/* daa[17*20 + 0] = 0.131405; */ +/* daa[17*20 + 1] = 0.552911; */ +/* daa[17*20 + 2] = 0.079985; */ +/* daa[17*20 + 3] = 0.060514; */ +/* daa[17*20 + 4] = 0.633662; */ +/* daa[17*20 + 5] = 0.21823; */ +/* daa[17*20 + 6] = 0.074988; */ +/* daa[17*20 + 7] = 0.169114; */ +/* daa[17*20 + 8] = 0.847725; */ +/* daa[17*20 + 9] = 0.10627; */ +/* daa[17*20 + 10] = 0.622044; */ +/* daa[17*20 + 11] = 0.060755; */ +/* daa[17*20 + 12] = 0.719575; */ +/* daa[17*20 + 13] = 3.14824; */ +/* daa[17*20 + 14] = 0.077123; */ +/* daa[17*20 + 15] = 0.276716; */ +/* daa[17*20 + 16] = 0.148883; */ +/* daa[18*20 + 0] = 0.165179; */ +/* daa[18*20 + 1] = 0.224883; */ +/* daa[18*20 + 2] = 0.528334; */ +/* daa[18*20 + 3] = 0.121252; */ +/* daa[18*20 + 4] = 1.174118; */ +/* daa[18*20 + 5] = 0.177062; */ +/* daa[18*20 + 6] = 0.074715; */ +/* daa[18*20 + 7] = 0.042356; */ +/* daa[18*20 + 8] = 5.911187; */ +/* daa[18*20 + 9] = 0.192481; */ +/* daa[18*20 + 10] = 0.321454; */ +/* daa[18*20 + 11] = 0.090556; */ +/* daa[18*20 + 12] = 0.406415; */ +/* daa[18*20 + 13] = 10.908861; */ +/* daa[18*20 + 14] = 0.070752; */ +/* daa[18*20 + 15] = 0.328483; */ +/* daa[18*20 + 16] = 0.181539; */ +/* daa[18*20 + 17] = 3.823886; */ +/* daa[19*20 + 0] = 1.78517; */ +/* daa[19*20 + 1] = 0.166975; */ +/* daa[19*20 + 2] = 0.106482; */ +/* daa[19*20 + 3] = 0.041707; */ +/* daa[19*20 + 4] = 1.876812; */ +/* daa[19*20 + 5] = 0.22421; */ +/* daa[19*20 + 6] = 0.247356; */ +/* daa[19*20 + 7] = 0.06688; */ +/* daa[19*20 + 8] = 0.1436; */ +/* daa[19*20 + 9] = 9.60184; */ +/* daa[19*20 + 10] = 1.599119; */ +/* daa[19*20 + 11] = 0.17319; */ +/* daa[19*20 + 12] = 1.645134; */ +/* daa[19*20 + 13] = 0.438571; */ +/* daa[19*20 + 14] = 0.252486; */ +/* daa[19*20 + 15] = 0.105536; */ +/* daa[19*20 + 16] = 1.789097; */ +/* daa[19*20 + 17] = 0.147951; */ +/* daa[19*20 + 18] = 0.200571; */ + + + +/* for (i=0; i 2664 (67% of the original 3933 positions) + + The species included in the analysis were: + Harpiosquilla harpax [NCBI_TaxID 287944] + Ixodes uriae [NCBI_TaxID 59655] + Heptathela hangzhouensis [NCBI_TaxID 216259] + Triops longicaudatus [NCBI_TaxID 58777] + Gryllotalpa orientalis [NCBI_TaxID 213494] + lepidopsocid RS-2001 [NCBI_TaxID 159971] + Locusta migratoria [NCBI_TaxID 7004] + Drosophila yakuba [NCBI_TaxID 7245] + Ostrinia furnacalis [NCBI_TaxID 93504] + Megabalanus volcano [NCBI_TaxID 266495] + Periplaneta fuliginosa [NCBI_TaxID 36977] + Thermobia domestica [NCBI_TaxID 89055] + Aleurochiton aceris [NCBI_TaxID 266942] + Schizaphis graminum [NCBI_TaxID 13262] + Pteronarcys princeps [NCBI_TaxID 285953] + Aleurodicus dugesii [NCBI_TaxID 30099] + Pollicipes polymerus [NCBI_TaxID 36137] + Gomphiocephalus hodgsoni [NCBI_TaxID 221270] + Habronattus oregonensis [NCBI_TaxID 130930] + Speleonectes tulumensis [NCBI_TaxID 84346] + Hutchinsoniella macracantha [NCBI_TaxID 84335] + Haemaphysalis flava [NCBI_TaxID 181088] + Scutigera coleoptrata [NCBI_TaxID 29022] + Vargula hilgendorfii [NCBI_TaxID 6674] + Tricholepidion gertschi [NCBI_TaxID 89825] + Varroa destructor [NCBI_TaxID 109461] + Bombyx mandarina [NCBI_TaxID 7092] + Thyropygus sp. [NCBI_TaxID 174155] + Tribolium castaneum [NCBI_TaxID 7070] + Pagurus longicarpus [NCBI_TaxID 111067] + Limulus polyphemus [NCBI_TaxID 6850] + Tetrodontophora bielanensis [NCBI_TaxID 48717] + Penaeus monodon [NCBI_TaxID 6687] + Daphnia pulex [NCBI_TaxID 6669] + Apis mellifera [NCBI_TaxID 7469] + Anopheles gambiae [NCBI_TaxID 7165] + + The topology used for inferring the model was: + (((Daph_pulex,Trio_longi),((((((Aleu_aceri,Aleu_duges),Schi_grami),lepi_RS_20), + ((((Ostr_furna,Bomb_manda),(Dros_yakub,Anop_gambi)),Apis_melli),Trib_casta)), + ((Gryl_orien,Locu_migra),(Pter_princ,Peri_fulig))),(Tric_gerts,Ther_domes)), + (Scut_coleo,Thyr_sp),Varg_hilge,Hutc_macra,((((Ixod_uriae,Haem_flava),Varr_destr), + (Habr_orego,Hept_hangz)),Limu_polyp),(Poll_polym,Mega_volca),(Gomp_hodgs,Tetr_biela), + ((Pagu_longi,Pena_monod),Harp_harpa),Spel_tulum)); + + Note this is not the ML topology but the consensus one (based on morphological data, + phylogenetic reconstruction using nuclear genes, etc). Where relationships are + not clear, a polytomy was introduced (it contains quite a lot of polytomies!). + + The model was estimated using (the great and helpful) Ziheng Yang's Paml software package. + A four-categorized gamma distribution was used to account for heterogeneity (alpha + was estimated to be 0.47821). Sites with ambiguity data were taken into account. + + If you would like the data related to this matrix, please contact fabascal@uvigo.es. + Federico Abascal (c)2005. + */ + + int i,j,naa; + naa = 20; + daa[1*20+ 0] = 0.2; daa[2*20+ 0] = 0.2; daa[2*20+ 1] = 0.2; daa[3*20+ 0] = 0.6; + daa[3*20+ 1] = 4.3; daa[3*20+ 2] = 500.2; daa[4*20+ 0] = 253.5; daa[4*20+ 1] = 35.5; + daa[4*20+ 2] = 98.2; daa[4*20+ 3] = 10.6; daa[5*20+ 0] = 0.2; daa[5*20+ 1] = 154.0; + daa[5*20+ 2] = 261.8; daa[5*20+ 3] = 0.2; daa[5*20+ 4] = 0.2; daa[6*20+ 0] = 0.2; + daa[6*20+ 1] = 0.2; daa[6*20+ 2] = 183.0; daa[6*20+ 3] = 861.8; daa[6*20+ 4] = 0.2; + daa[6*20+ 5] = 261.6; daa[7*20+ 0] = 199.8; daa[7*20+ 1] = 0.2; daa[7*20+ 2] = 120.5; + daa[7*20+ 3] = 12.5; daa[7*20+ 4] = 80.5; daa[7*20+ 5] = 2.6; daa[7*20+ 6] = 43.9; + daa[8*20+ 0] = 0.2; daa[8*20+ 1] = 41.3; daa[8*20+ 2] = 179.5; daa[8*20+ 3] = 0.2; + daa[8*20+ 4] = 12.4; daa[8*20+ 5] = 313.5; daa[8*20+ 6] = 15.2; daa[8*20+ 7] = 0.2; + daa[9*20+ 0] = 25.7; daa[9*20+ 1] = 1.8; daa[9*20+ 2] = 21.3; daa[9*20+ 3] = 6.6; + daa[9*20+ 4] = 63.0; daa[9*20+ 5] = 10.5; daa[9*20+ 6] = 6.8; daa[9*20+ 7] = 2.7; + daa[9*20+ 8] = 0.2; daa[10*20+ 0] = 3.7; daa[10*20+ 1] = 1.8; daa[10*20+ 2] = 12.6; + daa[10*20+ 3] = 1.2; daa[10*20+ 4] = 78.7; daa[10*20+ 5] = 16.3; daa[10*20+ 6] = 1.7; + daa[10*20+ 7] = 1.4; daa[10*20+ 8] = 5.5; daa[10*20+ 9] = 514.5; daa[11*20+ 0] = 0.2; + daa[11*20+ 1] = 208.6; daa[11*20+ 2] = 467.3; daa[11*20+ 3] = 1.7; daa[11*20+ 4] = 0.2; + daa[11*20+ 5] = 349.3; daa[11*20+ 6] = 106.3; daa[11*20+ 7] = 0.2; daa[11*20+ 8] = 0.2; + daa[11*20+ 9] = 3.5; daa[11*20+ 10] = 3.8; daa[12*20+ 0] = 120.6; daa[12*20+ 1] = 5.2; + daa[12*20+ 2] = 78.8; daa[12*20+ 3] = 0.2; daa[12*20+ 4] = 312.3; daa[12*20+ 5] = 67.3; + daa[12*20+ 6] = 0.2; daa[12*20+ 7] = 55.7; daa[12*20+ 8] = 0.2; daa[12*20+ 9] = 514.8; + daa[12*20+ 10] = 885.5; daa[12*20+ 11] = 105.6; daa[13*20+ 0] = 13.1; daa[13*20+ 1] = 4.7; + daa[13*20+ 2] = 19.7; daa[13*20+ 3] = 0.2; daa[13*20+ 4] = 184.1; daa[13*20+ 5] = 0.2; + daa[13*20+ 6] = 0.2; daa[13*20+ 7] = 0.8; daa[13*20+ 8] = 13.8; daa[13*20+ 9] = 117.9; + daa[13*20+ 10] = 262.6; daa[13*20+ 11] = 10.7; daa[13*20+ 12] = 321.6; daa[14*20+ 0] = 49.3; + daa[14*20+ 1] = 0.2; daa[14*20+ 2] = 16.5; daa[14*20+ 3] = 0.2; daa[14*20+ 4] = 0.2; + daa[14*20+ 5] = 39.3; daa[14*20+ 6] = 7.9; daa[14*20+ 7] = 0.2; daa[14*20+ 8] = 0.8; + daa[14*20+ 9] = 0.2; daa[14*20+ 10] = 12.2; daa[14*20+ 11] = 16.8; daa[14*20+ 12] = 5.3; + daa[14*20+ 13] = 14.6; daa[15*20+ 0] = 673.0; daa[15*20+ 1] = 2.7; daa[15*20+ 2] = 398.4; + daa[15*20+ 3] = 44.4; daa[15*20+ 4] = 664.2; daa[15*20+ 5] = 52.4; daa[15*20+ 6] = 31.5; + daa[15*20+ 7] = 226.0; daa[15*20+ 8] = 10.6; daa[15*20+ 9] = 7.2; daa[15*20+ 10] = 8.2; + daa[15*20+ 11] = 144.2; daa[15*20+ 12] = 111.7; daa[15*20+ 13] = 36.1; daa[15*20+ 14] = 86.5; + daa[16*20+ 0] = 243.9; daa[16*20+ 1] = 0.2; daa[16*20+ 2] = 165.9; daa[16*20+ 3] = 0.2; + daa[16*20+ 4] = 182.8; daa[16*20+ 5] = 43.7; daa[16*20+ 6] = 43.4; daa[16*20+ 7] = 0.2; + daa[16*20+ 8] = 18.6; daa[16*20+ 9] = 203.7; daa[16*20+ 10] = 47.8; daa[16*20+ 11] = 69.5; + daa[16*20+ 12] = 288.6; daa[16*20+ 13] = 13.5; daa[16*20+ 14] = 46.8; daa[16*20+ 15] = 660.4; + daa[17*20+ 0] = 0.2; daa[17*20+ 1] = 0.2; daa[17*20+ 2] = 7.7; daa[17*20+ 3] = 0.2; + daa[17*20+ 4] = 21.6; daa[17*20+ 5] = 6.7; daa[17*20+ 6] = 11.0; daa[17*20+ 7] = 1.9; + daa[17*20+ 8] = 0.2; daa[17*20+ 9] = 0.2; daa[17*20+ 10] = 21.1; daa[17*20+ 11] = 16.0; + daa[17*20+ 12] = 70.7; daa[17*20+ 13] = 53.7; daa[17*20+ 14] = 0.2; daa[17*20+ 15] = 2.4; + daa[17*20+ 16] = 0.2; daa[18*20+ 0] = 1.2; daa[18*20+ 1] = 3.9; daa[18*20+ 2] = 251.2; + daa[18*20+ 3] = 0.2; daa[18*20+ 4] = 72.0; daa[18*20+ 5] = 86.7; daa[18*20+ 6] = 7.7; + daa[18*20+ 7] = 8.6; daa[18*20+ 8] = 191.4; daa[18*20+ 9] = 12.3; daa[18*20+ 10] = 19.8; + daa[18*20+ 11] = 117.1; daa[18*20+ 12] = 70.9; daa[18*20+ 13] = 791.6; daa[18*20+ 14] = 18.4; + daa[18*20+ 15] = 30.5; daa[18*20+ 16] = 46.0; daa[18*20+ 17] = 37.7; daa[19*20+ 0] = 339.9; + daa[19*20+ 1] = 0.2; daa[19*20+ 2] = 22.6; daa[19*20+ 3] = 0.2; daa[19*20+ 4] = 350.4; + daa[19*20+ 5] = 0.2; daa[19*20+ 6] = 13.6; daa[19*20+ 7] = 2.6; daa[19*20+ 8] = 0.2; + daa[19*20+ 9] = 1854.5; daa[19*20+ 10] = 84.7; daa[19*20+ 11] = 26.1; daa[19*20+ 12] = 281.3; + daa[19*20+ 13] = 51.9; daa[19*20+ 14] = 31.7; daa[19*20+ 15] = 60.6; daa[19*20+ 16] = 544.1; + daa[19*20+ 17] = 0.2; daa[19*20+ 18] = 1.6; + +/* MtArt.old: esta es la MtArt que hice con 26 secuencias (2 outgroups) con una topologia incorrecta + daa[1*20+ 0] = 0.2; daa[2*20+ 0] = 0.2; daa[2*20+ 1] = 8.0; daa[3*20+ 0] = 0.2; + daa[3*20+ 1] = 0.2; daa[3*20+ 2] = 441.7; daa[4*20+ 0] = 287.9; daa[4*20+ 1] = 48.4; + daa[4*20+ 2] = 82.4; daa[4*20+ 3] = 0.2; daa[5*20+ 0] = 0.2; daa[5*20+ 1] = 149.9; + daa[5*20+ 2] = 278.6; daa[5*20+ 3] = 0.2; daa[5*20+ 4] = 21.7; daa[6*20+ 0] = 6.6; + daa[6*20+ 1] = 0.2; daa[6*20+ 2] = 213.9; daa[6*20+ 3] = 760.8; daa[6*20+ 4] = 0.2; + daa[6*20+ 5] = 292.9; daa[7*20+ 0] = 228.2; daa[7*20+ 1] = 0.2; daa[7*20+ 2] = 97.1; + daa[7*20+ 3] = 10.4; daa[7*20+ 4] = 98.4; daa[7*20+ 5] = 4.0; daa[7*20+ 6] = 48.7; + daa[8*20+ 0] = 0.2; daa[8*20+ 1] = 56.7; daa[8*20+ 2] = 156.4; daa[8*20+ 3] = 24.5; + daa[8*20+ 4] = 15.5; daa[8*20+ 5] = 328.6; daa[8*20+ 6] = 7.0; daa[8*20+ 7] = 8.4; + daa[9*20+ 0] = 26.4; daa[9*20+ 1] = 1.6; daa[9*20+ 2] = 40.1; daa[9*20+ 3] = 0.2; + daa[9*20+ 4] = 22.1; daa[9*20+ 5] = 13.8; daa[9*20+ 6] = 0.2; daa[9*20+ 7] = 3.6; + daa[9*20+ 8] = 0.2; daa[10*20+ 0] = 3.4; daa[10*20+ 1] = 0.6; daa[10*20+ 2] = 13.8; + daa[10*20+ 3] = 0.7; daa[10*20+ 4] = 76.9; daa[10*20+ 5] = 12.1; daa[10*20+ 6] = 5.4; + daa[10*20+ 7] = 2.5; daa[10*20+ 8] = 2.9; daa[10*20+ 9] = 542.6; daa[11*20+ 0] = 0.2; + daa[11*20+ 1] = 240.2; daa[11*20+ 2] = 602.8; daa[11*20+ 3] = 35.5; daa[11*20+ 4] = 0.2; + daa[11*20+ 5] = 357.6; daa[11*20+ 6] = 62.6; daa[11*20+ 7] = 0.2; daa[11*20+ 8] = 3.3; + daa[11*20+ 9] = 0.2; daa[11*20+ 10] = 17.5; daa[12*20+ 0] = 119.0; daa[12*20+ 1] = 0.2; + daa[12*20+ 2] = 91.4; daa[12*20+ 3] = 6.4; daa[12*20+ 4] = 332.3; daa[12*20+ 5] = 65.4; + daa[12*20+ 6] = 0.2; daa[12*20+ 7] = 60.4; daa[12*20+ 8] = 2.4; daa[12*20+ 9] = 492.5; + daa[12*20+ 10] = 815.8; daa[12*20+ 11] = 67.3; daa[13*20+ 0] = 8.2; daa[13*20+ 1] = 6.4; + daa[13*20+ 2] = 31.5; daa[13*20+ 3] = 3.4; daa[13*20+ 4] = 174.4; daa[13*20+ 5] = 5.7; + daa[13*20+ 6] = 5.7; daa[13*20+ 7] = 2.1; daa[13*20+ 8] = 11.0; daa[13*20+ 9] = 94.4; + daa[13*20+ 10] = 243.3; daa[13*20+ 11] = 12.3; daa[13*20+ 12] = 357.8; daa[14*20+ 0] = 62.5; + daa[14*20+ 1] = 0.4; daa[14*20+ 2] = 17.5; daa[14*20+ 3] = 0.2; daa[14*20+ 4] = 0.2; + daa[14*20+ 5] = 48.6; daa[14*20+ 6] = 17.7; daa[14*20+ 7] = 2.7; daa[14*20+ 8] = 0.2; + daa[14*20+ 9] = 0.2; daa[14*20+ 10] = 11.2; daa[14*20+ 11] = 21.7; daa[14*20+ 12] = 5.2; + daa[14*20+ 13] = 12.6; daa[15*20+ 0] = 659.0; daa[15*20+ 1] = 5.2; daa[15*20+ 2] = 469.8; + daa[15*20+ 3] = 52.3; daa[15*20+ 4] = 570.7; daa[15*20+ 5] = 47.8; daa[15*20+ 6] = 37.3; + daa[15*20+ 7] = 227.8; daa[15*20+ 8] = 12.7; daa[15*20+ 9] = 12.3; daa[15*20+ 10] = 7.4; + daa[15*20+ 11] = 189.0; daa[15*20+ 12] = 155.3; daa[15*20+ 13] = 43.8; daa[15*20+ 14] = 103.4; + daa[16*20+ 0] = 276.4; daa[16*20+ 1] = 1.6; daa[16*20+ 2] = 175.6; daa[16*20+ 3] = 0.2; + daa[16*20+ 4] = 96.2; daa[16*20+ 5] = 71.4; daa[16*20+ 6] = 37.4; daa[16*20+ 7] = 0.2; + daa[16*20+ 8] = 14.2; daa[16*20+ 9] = 212.5; daa[16*20+ 10] = 38.5; daa[16*20+ 11] = 97.4; + daa[16*20+ 12] = 254.7; daa[16*20+ 13] = 2.1; daa[16*20+ 14] = 41.6; daa[16*20+ 15] = 670.6; + daa[17*20+ 0] = 6.2; daa[17*20+ 1] = 0.2; daa[17*20+ 2] = 0.2; daa[17*20+ 3] = 5.6; + daa[17*20+ 4] = 0.2; daa[17*20+ 5] = 0.2; daa[17*20+ 6] = 3.1; daa[17*20+ 7] = 0.4; + daa[17*20+ 8] = 0.2; daa[17*20+ 9] = 15.2; daa[17*20+ 10] = 11.5; daa[17*20+ 11] = 32.6; + daa[17*20+ 12] = 82.4; daa[17*20+ 13] = 81.9; daa[17*20+ 14] = 0.2; daa[17*20+ 15] = 9.7; + daa[17*20+ 16] = 0.2; daa[18*20+ 0] = 1.6; daa[18*20+ 1] = 7.7; daa[18*20+ 2] = 242.5; + daa[18*20+ 3] = 0.2; daa[18*20+ 4] = 88.0; daa[18*20+ 5] = 93.1; daa[18*20+ 6] = 0.2; + daa[18*20+ 7] = 6.0; daa[18*20+ 8] = 113.7; daa[18*20+ 9] = 22.1; daa[18*20+ 10] = 17.2; + daa[18*20+ 11] = 138.5; daa[18*20+ 12] = 37.6; daa[18*20+ 13] = 770.2; daa[18*20+ 14] = 5.3; + daa[18*20+ 15] = 25.0; daa[18*20+ 16] = 55.5; daa[18*20+ 17] = 69.3; daa[19*20+ 0] = 307.8; + daa[19*20+ 1] = 2.2; daa[19*20+ 2] = 6.9; daa[19*20+ 3] = 0.2; daa[19*20+ 4] = 405.7; + daa[19*20+ 5] = 0.8; daa[19*20+ 6] = 20.2; daa[19*20+ 7] = 5.7; daa[19*20+ 8] = 0.2; + daa[19*20+ 9] = 1687.9; daa[19*20+ 10] = 49.4; daa[19*20+ 11] = 23.4; daa[19*20+ 12] = 329.9; + daa[19*20+ 13] = 86.3; daa[19*20+ 14] = 27.3; daa[19*20+ 15] = 95.0; daa[19*20+ 16] = 443.0; + daa[19*20+ 17] = 2.4; daa[19*20+ 18] = 0.2; +3*/ + for (i=0; idim = n_dim; + Random_String(t->id,3); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void PHYREX_Init_Disk_Event(t_dsk *t, int n_dim, t_phyrex_mod *mmod) +{ + t->prev = NULL; + t->next = NULL; + t->mmod = NULL; + t->age_fixed = NO; + + Random_String(t->id,3); + GEO_Init_Coord(t->centr,n_dim); + + if(mmod != NULL) t->mmod = mmod; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void PHYREX_Init_Migrep_Mod(t_phyrex_mod *t, int n_dim, phydbl min_lat, phydbl min_lon, phydbl max_lat, phydbl max_lon) +{ + assert(n_dim == 2); + + t->name = PHYREX_NORMAL; + t->n_dim = n_dim; + t->safe_phyrex = NO; + + t->lim_up->lonlat[0] = max_lat; + t->lim_up->lonlat[1] = max_lon; + + t->lim_do->lonlat[0] = min_lat; + t->lim_do->lonlat[1] = min_lon; + + t->lbda = 1.E-2; + t->min_lbda = 1.E-6; + t->max_lbda = 1.E+4; + t->prior_param_lbda = 1.0; + + t->mu = 0.400; + t->min_mu = 0.000; + t->max_mu = 1.000; + t->prior_param_mu = 1.000; + + t->min_rad = 0.0; + t->max_rad = 1.0*((max_lat-min_lat)+(max_lon-min_lon)); + /* t->max_rad = 10.0*((max_lat-min_lat)+(max_lon-min_lon)); */ + t->rad = 0.01*((max_lat-min_lat)+(max_lon-min_lon)); + /* t->prior_param_rad = 1./(0.01*((max_lat-min_lat)+(max_lon-min_lon))); */ + t->prior_param_rad = 1./(0.1*((max_lat-min_lat)+(max_lon-min_lon))); + t->update_rad = NO; + + t->min_sigsq = 0.0; + t->max_sigsq = 1.E+2; + t->sigsq = 1.0; + t->prior_param_sigsq = 10.0; + + + t->c_lnL = UNLIKELY; + t->c_ln_prior_rad = UNLIKELY; + t->c_ln_prior_lbda = UNLIKELY; + t->c_ln_prior_mu = UNLIKELY; + + t->soft_bound_area = 0.1; + + t->samp_area = NULL; + + t->max_num_of_intervals = 1000000; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void PHYREX_Init_Lindisk_Node(t_ldsk *t, t_dsk *disk, int n_dim) +{ + t->disk = disk; + /* disk->ldsk = t; */ + t->prev = NULL; + t->next = NULL; + t->nd = NULL; + t->is_hit = NO; + t->n_next = 0; + GEO_Init_Coord(t->coord, n_dim); + GEO_Init_Coord(t->cpy_coord,n_dim); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Init_MCMC_Struct(char *filename, option *io, t_mcmc *mcmc) +{ + int pid; + + assert(mcmc); + + mcmc->io = io; + mcmc->is = NO; + mcmc->run = 0; + mcmc->sample_interval = 1E+3; + mcmc->chain_len = 1E+7; + mcmc->chain_len_burnin = 1E+4; + mcmc->randomize = YES; + mcmc->norm_freq = 1E+3; + mcmc->max_tune = 1.E+20; + mcmc->min_tune = 1.E-10; + mcmc->print_every = 2; + mcmc->is_burnin = NO; + mcmc->nd_t_digits = 4; + mcmc->always_yes = NO; + mcmc->max_lag = 1000; + mcmc->sample_num = 0; + + if(filename) + { + char *s; + + s = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + strcpy(mcmc->out_filename,filename); + pid = getpid(); + sprintf(mcmc->out_filename+strlen(mcmc->out_filename),".%d",pid); + + strcpy(s,mcmc->io->in_align_file); + strcat(s,"_"); + strcat(s,mcmc->out_filename); + strcat(s,".stats"); + mcmc->out_fp_stats = fopen(s,"w"); + + strcpy(s,mcmc->io->in_align_file); + strcat(s,"_"); + strcat(s,mcmc->out_filename); + strcat(s,".trees"); + mcmc->out_fp_trees = fopen(s,"w"); + + strcpy(s,mcmc->io->in_align_file); + strcat(s,"_"); + strcat(s,mcmc->out_filename); + strcat(s,".constree"); + mcmc->out_fp_constree = fopen(s,"w"); + +/* strcpy(s,tree->mcmc->out_filename); */ +/* strcat(s,".means"); */ +/* tree->mcmc->out_fp_means = fopen(s,"w"); */ + +/* strcpy(s,tree->mcmc->out_filename); */ +/* strcat(s,".lasts"); */ +/* tree->mcmc->out_fp_last = fopen(s,"w"); */ + + Free(s); + } + else + { + mcmc->out_fp_stats = stderr; + mcmc->out_fp_trees = stderr; + /* tree->mcmc->out_fp_means = stderr; */ + /* tree->mcmc->out_fp_last = stderr; */ + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Calibration(t_cal *cal) +{ + cal->next = NULL; + cal->prev = NULL; + cal->lower = -1.; + cal->upper = -1.; + cal->is_primary = FALSE; + cal->alpha_proba_list = NULL; + cal->clade_list = NULL; + cal->clade_list_size = 0; + cal->id = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_All_Calibration(t_tree *tree) +{ + int i; + assert(tree->rates && tree->rates->a_cal); + For(i,2*tree->n_otu-1) Init_Calibration(tree->rates->a_cal[i]); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Sarea(t_sarea *s) +{ + assert(s); + s->n_poly = 0; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Calign(int n_otu, int crunch_len, int init_len, calign *this) +{ + this->obs_pinvar = .0; + this->n_otu = n_otu; + this->clean_len = -1; + this->crunch_len = crunch_len; + this->init_len = init_len; + this->format = 0; + this->io_wght = NULL; + + for(int i=0; ic_seq[i]); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Cseq(align *this) +{ + this->is_duplicate = NO; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Linked_List(t_ll *list) +{ + list->head = list; + list->tail = list; + list->next = NULL; + list->prev = NULL; + list->v = NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_NNI_Score(phydbl val, t_edge *b, t_tree *tree) +{ + b->nni->score = val; + if(tree->is_mixt_tree == YES) MIXT_Init_NNI_Score(val,b,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#ifdef M4 +void M4_Init_Model(m4 *m4mod, calign *data, t_mod *mod) +{ + int i,j,ct; + phydbl fq; + + if(mod->io->datatype == NT) m4mod->n_o = 4; + else if(mod->io->datatype == AA) m4mod->n_o = 20; + else + { + PhyML_Fprintf(stderr,"\n. Not implemented yet."); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + mod->ns = m4mod->n_o * m4mod->n_h; + + for(i=0;in_o;i++) m4mod->o_fq[i] = mod->e_frq->pi->v[i]; /*! At that stage, the mod->pi vector as been initialized + under a standard non covarion type of model. Use these + frequencies as they have been set according to the + nucleotide substitution model chosen (e.g., 1/4 for JC69). !*/ + For(i,(int)(m4mod->n_h)) m4mod->multipl[i] = 1.; + + ct = 0; + for(i=0;in_o-1;i++) + { + for(j=i+1;jn_o;j++) + { + m4mod->o_rr[ct] = MAX(mod->r_mat->qmat->v[i*m4mod->n_o+j],1.E-5); + ct++; + } + } + + For(i,(int)(m4mod->n_h*(m4mod->n_h-1)/2)) m4mod->h_rr[i] = 1.; + fq = (phydbl)(1./m4mod->n_h); + + if(mod->s_opt->opt_cov_delta) m4mod->delta = 1.0; + if(mod->s_opt->opt_cov_alpha) m4mod->alpha = 1.0; + for(i=0;in_h;i++) m4mod->h_fq[i] = fq; + for(i=0;in_h;i++) m4mod->h_fq_unscaled[i] = 1.0; + for(i=0;in_h;i++) m4mod->multipl[i] = (phydbl)i; + for(i=0;in_h;i++) m4mod->multipl_unscaled[i] = (phydbl)i; + + Set_Update_Eigen(YES,mod); + M4_Update_Qmat(m4mod,mod); +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + diff --git a/phyml/init.h b/phyml/init.h new file mode 100644 index 0000000..6a8109c --- /dev/null +++ b/phyml/init.h @@ -0,0 +1,76 @@ +/* + +PHYML : a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences + +Copyright (C) Stephane Guindon. Oct 2003 onward + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef INIT_H +#define INIT_H + +#include "utilities.h" + +void Init_Cseq(align *this); +void Init_Eigen_Struct(eigen *this); +void Init_Scalar_Dbl(scalar_dbl *p); +void Init_Scalar_Int(scalar_int *p); +void Init_Vect_Dbl(int len,vect_dbl *p); +void Init_Vect_Int(int len,vect_int *p); +void Init_Tree(t_tree *tree,int n_otu); +void Init_Edge_Light(t_edge *b,int num); +void Init_Node_Light(t_node *n,int num); +void Init_NNI(t_nni *a_nni); +void Init_Nexus_Format(nexcom **com); +void Init_Mat(matrix *mat,calign *data); +void Set_Defaults_Input(option *io); +void Set_Defaults_Model(t_mod *mod); +void Set_Defaults_Optimiz(t_opt *s_opt); +void XML_Init_Node(xml_node *prev,xml_node *new_node,char *name); +void Init_One_Spr(t_spr *a_spr); +void Init_Model(calign *data,t_mod *mod,option *io); +int Init_Qmat_Dayhoff(phydbl *daa,phydbl *pi); +int Init_Qmat_DCMut(phydbl *daa,phydbl *pi); +int Init_Qmat_MtArt(phydbl *daa,phydbl *pi); +int Init_Qmat_HIVb(phydbl *daa,phydbl *pi); +int Init_Qmat_HIVw(phydbl *daa,phydbl *pi); +int Init_Qmat_JTT(phydbl *daa,phydbl *pi); +int Init_Qmat_MtREV(phydbl *daa,phydbl *pi); +int Init_Qmat_LG(phydbl *daa,phydbl *pi); +int Init_Qmat_WAG(phydbl *daa,phydbl *pi); +int Init_Qmat_RtREV(phydbl *daa,phydbl *pi); +int Init_Qmat_CpREV(phydbl *daa,phydbl *pi); +int Init_Qmat_VT(phydbl *daa,phydbl *pi); +int Init_Qmat_Blosum62(phydbl *daa,phydbl *pi); +int Init_Qmat_MtMam(phydbl *daa,phydbl *pi); +int Init_Qmat_AB(phydbl *daa, phydbl *pi); +void XML_Init_Attribute(xml_attr *attr); +void Init_String(t_string *ts); +void Init_Efrq(phydbl *b_frq, t_efrq *f); +void RATES_Init_Rate_Struct(t_rate *rates, t_rate *existing_rates, int n_otu); +void Init_Rmat(t_rmat *rmat); +void Init_MGF_Bl(t_tree *tree); +int Init_Qmat_FLU(phydbl *daa, phydbl *pi); +void Set_Defaults_Ras(t_ras *ras); +void GEO_Init_Coord(t_geo_coord *t, int n_dim); +void PHYREX_Init_Disk_Event(t_dsk *t, int n_dim, t_phyrex_mod *mod); +void PHYREX_Init_Lindisk_Node(t_ldsk *t, t_dsk *devt, int n_dim); +void PHYREX_Init_Migrep_Mod(t_phyrex_mod *t, int n_dim, phydbl min_lat, phydbl min_lon, phydbl max_lat, phydbl max_lon); +void MCMC_Init_MCMC_Struct(char *filename, option *io, t_mcmc *mcmc); +void Init_Calibration(t_cal *cal); +void Init_All_Calibration(t_tree *tree); +void Init_Sarea(t_sarea *s); +void Init_Efrqs_Using_Observed_Freqs(t_efrq *f, phydbl *o, int ns); +void Init_Calign(int n_otu, int crunch_len, int init_len, calign *this); +void Init_Linked_List(t_ll *list); +void Init_Target_Tip(t_clad *clade, t_tree *tree); +void Init_NNI_Score(phydbl val, t_edge *b, t_tree *tree); +void M4_Init_Model(m4 *m4mod, calign *data, t_mod *mod); + +#endif diff --git a/phyml/interface.c b/phyml/interface.c index e1ad094..5191fdf 100644 --- a/phyml/interface.c +++ b/phyml/interface.c @@ -10,21 +10,14 @@ the GNU public licence. See http://www.opensource.org for details. */ -#include "utilities.h" -#include "options.h" -#include "models.h" -#include "free.h" -#include "options.h" #include "interface.h" -#ifdef MG -#include "multigene.h" -#endif +#include "mg.h" void Launch_Interface(option *io) { Launch_Interface_Input(io); - io->ready_to_go = 0; + io->ready_to_go = 0; do { switch(io->curr_interface) @@ -56,27 +49,175 @@ void Launch_Interface(option *io) } default : { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Printf("\n== Err in file %s at line %d\n\n",__FILE__,__LINE__); Exit(""); break; } } - }while(!io->ready_to_go); + + + if(io->in_tree == 2) + { + PhyML_Printf("\n. Enter the name of the input tree file > "); + Getstring_Stdin(io->in_tree_file); + io->fp_in_tree = Openfile(io->in_tree_file,0); + } + + if((io->mod->whichmodel == CUSTOMAA) && (io->datatype == AA)) + { + char *filename; + + filename = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + fflush(NULL); + PhyML_Printf("\n"); + PhyML_Printf("\n. Enter the rate matrix file name > "); fflush(NULL); + Getstring_Stdin(filename); + io->mod->fp_aa_rate_mat = Openfile(filename,0); + strcpy(io->mod->aa_rate_mat_file->s,filename); + PhyML_Printf("\n"); + Free(filename); + fflush(NULL); + } + + if((io->mod->s_opt->n_rand_starts) && + (io->mod->s_opt->topo_search == NNI_MOVE) && + (io->mod->s_opt->random_input_tree)) + { + Warn_And_Exit("\n. The random starting tree option is only compatible with SPR based search options.\n"); + } + + if ((io->datatype == NT) && (io->mod->whichmodel > 10)) + { + char choix; + PhyML_Printf("\n== Err: model incompatible with the data type. Please use JC69, K80, F81, HKY, F84, TN93 or GTR\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Warn_And_Exit("\n"); + } + else if ((io->datatype == AA) && (io->mod->whichmodel < 11)) + { + char choix; + PhyML_Printf("\n== Err: model incompatible with the data type. Please use LG, Dayhoff, JTT, MtREV, WAG, DCMut, RtREV, CpREV, VT, Blosum62, MtMam, MtArt, HIVw, HIVb or AB.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); + Exit("\n"); + } + + if(io->m4_model == YES) + { +#ifdef M4 + io->mod->ns *= io->mod->m4mod->n_h; + io->mod->use_m4mod = 1; + M4_Make_Complete(io->mod->m4mod->n_h, + io->mod->m4mod->n_o, + io->mod->m4mod); +#endif + } + else + { + io->mod->s_opt->opt_cov_delta = 0; + io->mod->s_opt->opt_cov_alpha = 0; + io->mod->s_opt->opt_cov_free_rates = 0; + } + + if((io->mod->s_opt->opt_cov_free_rates) && (io->mod->s_opt->opt_cov_alpha)) + { + io->mod->s_opt->opt_cov_free_rates = 0; + io->mod->m4mod->use_cov_alpha = 0; + io->mod->m4mod->use_cov_free = 1; + } + + + if(io->print_site_lnl) + { + strcpy(io->out_lk_file,io->in_align_file); + strcat(io->out_lk_file, "_phyml_lk.txt"); + + if(io->append_run_ID) { strcat(io->out_lk_file,"_"); strcat(io->out_lk_file,io->run_id_string); } + io->fp_out_lk = Openfile(io->out_lk_file,1); + } + + if(io->print_trace) + { + strcpy(io->out_trace_file,io->in_align_file); + strcat(io->out_trace_file,"_phyml_trace.txt"); + + if(io->append_run_ID) { strcat(io->out_trace_file,"_"); strcat(io->out_trace_file,io->run_id_string); } + io->fp_out_trace = Openfile(io->out_trace_file,1); + } + + if(io->mod->s_opt->random_input_tree) + { + strcpy(io->out_trees_file,io->in_align_file); + strcat(io->out_trees_file,"_phyml_trees.txt"); + + if(io->append_run_ID) { strcat(io->out_trees_file,"_"); strcat(io->out_trees_file,io->run_id_string); } + io->fp_out_trees = Openfile(io->out_trees_file,1); + } + + if((io->print_boot_trees) && (io->n_boot_replicates > 0)) + { + strcpy(io->out_boot_tree_file,io->in_align_file); + strcat(io->out_boot_tree_file,"_phyml_boot_trees.txt"); + + if(io->append_run_ID) { strcat(io->out_boot_tree_file,"_"); strcat(io->out_boot_tree_file,io->run_id_string); } + io->fp_out_boot_tree = Openfile(io->out_boot_tree_file,1); + + strcpy(io->out_boot_stats_file,io->in_align_file); + strcat(io->out_boot_stats_file,"_phyml_boot_stats.txt"); + + if(io->append_run_ID) { strcat(io->out_boot_stats_file,"_"); strcat(io->out_boot_stats_file,io->run_id_string); } + io->fp_out_boot_stats = Openfile(io->out_boot_stats_file,1); + } + + if(io->append_run_ID) + { + strcat(io->out_tree_file,"_"); + strcat(io->out_stats_file,"_"); + strcat(io->out_tree_file,io->run_id_string); + strcat(io->out_stats_file,io->run_id_string); + } + + if(io->mod->ras->n_catg == 1) io->mod->s_opt->opt_alpha = 0; + + if(io->mod->whichmodel != K80 && + io->mod->whichmodel != HKY85 && + io->mod->whichmodel != F84 && + io->mod->whichmodel != TN93) + { + io->mod->s_opt->opt_kappa = 0; + } + + io->fp_out_tree = Openfile(io->out_tree_file,1); + io->fp_out_stats = Openfile(io->out_stats_file,1); + +// VINCENT: do not necessarily optimize relative rate parameters, they could be set by user + if(io->mod->whichmodel == GTR) + { + if (io->mod->s_opt->opt_subst_param) + io->mod->s_opt->opt_rr = YES; + else + io->mod->s_opt->opt_rr = NO; + } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Clear() { #ifdef WIN32 system("cls"); #elif UNIX - printf("\033[2J\033[H"); + PhyML_Printf("\033[2J\033[H"); #endif } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// void Launch_Interface_Input(option *io) { @@ -91,26 +232,26 @@ void Launch_Interface_Input(option *io) char *n_data_sets; - printf("\n\n"); - printf("\n. Enter the tree file name > "); fflush(NULL); + PhyML_Printf("\n\n"); + PhyML_Printf("\n. Enter the tree file name > "); fflush(NULL); Getstring_Stdin(io->in_tree_file); io->fp_in_tree = Openfile(io->in_tree_file,0); - printf("\n"); + PhyML_Printf("\n"); - printf("\n. Enter the reference sequence file name > "); fflush(NULL); - Getstring_Stdin(io->in_seq_file); - io->fp_in_seq = Openfile(io->in_seq_file,0); - printf("\n"); + PhyML_Printf("\n. Enter the reference sequence file name > "); fflush(NULL); + Getstring_Stdin(io->in_align_file); + io->fp_in_align = Openfile(io->in_align_file,0); + PhyML_Printf("\n"); - printf("\n. Number of data sets > "); + PhyML_Printf("\n. Number of data sets > "); n_data_sets = (char *)mCalloc(10000,sizeof(char)); Getstring_Stdin(n_data_sets); n_trial = 0; while((!atoi(n_data_sets)) || (atoi(n_data_sets) < 0)) { - if(++n_trial > 10) Exit("\n. Err : the number of sets must be a positive integer"); - printf("\n. The number of sets must be a positive integer"); - printf("\n. Enter a new value > "); + if(++n_trial > 10) Exit("\n== Err : the number of sets must be a positive integer"); + PhyML_Printf("\n. The number of sets must be a positive integer"); + PhyML_Printf("\n. Enter a new value > "); Getstring_Stdin(n_data_sets); } io->n_data_set_asked = atoi(n_data_sets); @@ -118,72 +259,60 @@ void Launch_Interface_Input(option *io) #elif OPTIMIZ - printf("\n. Enter the tree file name > "); fflush(NULL); + PhyML_Printf("\n. Enter the tree file name > "); fflush(NULL); Getstring_Stdin(io->in_tree_file); io->fp_in_tree = Openfile(io->in_tree_file,0); - printf("\n"); + PhyML_Printf("\n"); - printf("\n. Enter the reference sequence file name > "); fflush(NULL); - Getstring_Stdin(io->in_seq_file); - io->fp_in_seq = Openfile(io->in_seq_file,0); - printf("\n"); + PhyML_Printf("\n. Enter the reference sequence file name > "); fflush(NULL); + Getstring_Stdin(io->in_align_file); + io->fp_in_align = Openfile(io->in_align_file,0); + PhyML_Printf("\n"); -#elif defined(PHYML) || defined(MG) || defined(PHYML_INSERT) +#elif defined(PHYML) || defined(PART) || defined(PHYML_INSERT) - printf("\n. Enter the sequence file name > "); fflush(NULL); - Getstring_Stdin(io->in_seq_file); - io->fp_in_seq = Openfile(io->in_seq_file,0); + PhyML_Printf("\n. Enter the sequence file name > "); fflush(NULL); + Getstring_Stdin(io->in_align_file); + io->fp_in_align = Openfile(io->in_align_file,0); #endif -#if defined(PHYML) || defined(MG) || defined(PHYML_INSERT) +#if defined(PHYML) || defined(PART) || defined(PHYML_INSERT) - strcpy(io->out_stats_file,io->in_seq_file); - strcat(io->out_stats_file,"_phyml_stats.txt"); + strcpy(io->out_stats_file,io->in_align_file); - strcpy(io->out_tree_file,io->in_seq_file); + strcat(io->out_stats_file,"_phyml_stats.txt"); + strcpy(io->out_tree_file,io->in_align_file); + strcat(io->out_tree_file,"_phyml_tree.txt"); + strcpy(io->out_lk_file,io->in_align_file); - strcpy(io->out_lk_file,io->in_seq_file); strcat(io->out_lk_file,"_phyml_lk.txt"); - - #endif - -#ifdef WIN32 #ifdef EVOLVE if(Filexists("evolve_out.txt")); #elif OPTIMIZ if(Filexists("optimiz_out.txt")) -#elif defined(PHYML) || defined(MG) || defined(PHYML_INSERT) - if(Filexists(io->out_stat_file)) -#endif -#elif UNIX -#ifdef EVOLVE - if(Filexists("evolve_out")); -#elif OPTIMIZ - if(Filexists("optimiz_out")) -#elif defined(PHYML) || defined(MG) || defined(PHYML_INSERT) - if(Filexists(io->out_stats_file)) -#endif +#elif defined(PHYML) || defined(PART) || defined(PHYML_INSERT) + if(Filexists(io->out_stats_file)) #endif { - printf("\n"); + PhyML_Printf("\n"); #ifdef EVOLVE - printf("\n. A file 'evolve_out' already exists"); + PhyML_Printf("\n. A file 'evolve_out' already exists"); #elif OPTIMIZ - printf("\n. A file 'optimiz_out' already exists"); -#elif defined(PHYML) || defined(MG) || defined(PHYML_INSERT) - printf("\n. A file '%s' already exists",io->out_stats_file); + PhyML_Printf("\n. A file 'optimiz_out' already exists"); +#elif defined(PHYML) || defined(PART) || defined(PHYML_INSERT) + PhyML_Printf("\n. A file '%s' already exists",io->out_stats_file); #endif - printf("\n. Do you want to Replace it or Append to it ? "); + PhyML_Printf("\n. Do you want to Replace it or Append to it ? "); n_trial = 0; do { - printf("\n. Please type R or A > "); - scanf("%c",&choix); + PhyML_Printf("\n. Please type R or A > "); + if(!scanf("%c",&choix)) Exit("\n"); if(choix == '\n') choix = 'r'; else getchar(); if(++n_trial>10) Exit("\n"); @@ -194,40 +323,30 @@ void Launch_Interface_Input(option *io) else io->out_stats_file_open_mode = 2; } - io->fp_out_stats = Openfile(io->out_stats_file,io->out_stats_file_open_mode); + /* io->fp_out_stats = Openfile(io->out_stats_file,io->out_stats_file_open_mode); */ -#ifdef WIN32 #ifdef EVOLVE if(Filexists("evolve_seq.txt")) #elif OPTIMIZ if(Filexists("optimiz_tree.txt")) -#elif defined(PHYML) || defined(MG) || defined(PHYML_INSERT) +#elif defined(PHYML) || defined(PART) || defined(PHYML_INSERT) if(Filexists(io->out_tree_file)) -#endif -#elif UNIX -#ifdef EVOLVE - if(Filexists("evolve_seq")) -#elif OPTIMIZ - if(Filexists("optimiz_tree")) -#elif defined(PHYML) || defined(MG) || defined(PHYML_INSERT) - if(Filexists(io->out_tree_file)) -#endif #endif { - printf("\n"); + PhyML_Printf("\n"); #ifdef EVOLVE - printf("\n. A file 'evolve_seq' already exists"); + PhyML_Printf("\n. A file 'evolve_seq' already exists"); #elif OPTIMIZ - printf("\n. A file 'optimiz_tree' already exists"); -#elif defined(PHYML) || defined(MG) || defined(PHYML_INSERT) - printf("\n. A file '%s' already exists",io->out_tree_file); + PhyML_Printf("\n. A file 'optimiz_tree' already exists"); +#elif defined(PHYML) || defined(PART) || defined(PHYML_INSERT) + PhyML_Printf("\n. A file '%s' already exists",io->out_tree_file); #endif - printf("\n. Do you want to Replace it or Append to it ? "); + PhyML_Printf("\n. Do you want to Replace it or Append to it ? "); n_trial = 0; do { - printf("\n. Please type R or A > "); - scanf("%c",&choix); + PhyML_Printf("\n. Please type R or A > "); + if(!scanf("%c",&choix)) Exit("\n"); if(choix == '\n') choix = 'r'; else getchar(); Uppercase(&choix); @@ -237,10 +356,13 @@ void Launch_Interface_Input(option *io) if(choix == 'R') io->out_tree_file_open_mode = 1; else io->out_tree_file_open_mode = 2; } - io->fp_out_tree = Openfile(io->out_tree_file,io->out_tree_file_open_mode); + + /* io->fp_out_tree = Openfile(io->out_tree_file,io->out_tree_file_open_mode); */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Launch_Interface_Data_Type(option *io) { @@ -256,31 +378,34 @@ void Launch_Interface_Data_Type(option *io) buff = (char *)mCalloc(100,sizeof(char)); - printf("\n\n"); + PhyML_Printf("\n\n"); - printf(" ................... \n"); - printf(" Menu : Input Data \n"); - printf(" ......................... \n"); + PhyML_Printf(" ................... \n"); + PhyML_Printf(" Menu : Input Data \n"); + PhyML_Printf(" ......................... \n"); - printf("\n\n"); + PhyML_Printf("\n\n"); - printf(" [+] " + PhyML_Printf(" [+] " ".................................... Next sub-menu\n"); - printf(" [-] " + PhyML_Printf(" [-] " "................................ Previous sub-menu\n"); - printf(" [Y] " + PhyML_Printf(" [Y] " ".............................. Launch the analysis\n"); - printf("\n"); + PhyML_Printf("\n"); - printf(" [D] " - "............................... Data type (DNA/AA) " - " %-15s \n", - (io->mod->datatype)?("AA"):("DNA")); + if(io->datatype == NT) strcpy(s,"DNA"); + else if(io->datatype == AA) strcpy(s,"AA"); + else strcpy(s,"Generic"); + + PhyML_Printf(" [D] " + "....................... Data type (DNA/AA/Generic) " + " %-15s \n",s); - printf(" [I] " + PhyML_Printf(" [I] " "...... Input sequences interleaved (or sequential) " " %-15s \n", (io->interleaved)?("interleaved"):("sequential")); @@ -289,16 +414,22 @@ void Launch_Interface_Data_Type(option *io) sprintf(s," (%d sets)",io->n_data_sets); strcpy(buff,(io->n_data_sets > 1)?("yes"):("no")); buff=strcat(buff,(io->n_data_sets > 1)?(s):("\0")); - printf(" [M] " + PhyML_Printf(" [M] " "....................... Analyze multiple data sets " " %-15s \n",buff); + if(!io->append_run_ID) strcpy(s,"none"); + else strcpy(s,io->run_id_string); + PhyML_Printf(" [R] " + "........................................... Run ID " + " %-15s \n",s); + - printf("\n\n. Are these settings correct ? " + PhyML_Printf("\n\n. Are these settings correct ? " "(type '+', '-', 'Y' or other letter for one to change) "); - scanf("%c",&choix); + if(!scanf("%c",&choix)) Exit("\n"); if(choix != '\n') getchar(); /* \n */ fflush(NULL); @@ -311,36 +442,45 @@ void Launch_Interface_Data_Type(option *io) /* io->curr_interface++; */ /* break; */ /* } */ + case 'R' : + { + io->append_run_ID = (io->append_run_ID)?(0):(1); + PhyML_Printf("\n. Enter a run ID (any string of characters) > "); + Getstring_Stdin(io->run_id_string); + break; + } + + case 'M' : { char *c; int n_trial; - printf("\n. How many data sets > "); + PhyML_Printf("\n. How many data sets > "); c = (char *)mCalloc(100,sizeof(char)); Getstring_Stdin(c); n_trial = 0; while((!atoi(c)) || (atoi(c) < 0)) { - if(++n_trial > 10) Exit("\n. Err : The number of data sets must be a positive integer"); - printf("\n. The number of data sets must be a positive integer"); - printf("\n. Enter a new value > "); + if(++n_trial > 10) Exit("\n== Err : The number of data sets must be a positive integer"); + PhyML_Printf("\n. The number of data sets must be a positive integer"); + PhyML_Printf("\n. Enter a new value > "); Getstring_Stdin(c); } io->n_data_sets = atoi(c); - #ifdef MG + #ifdef PART if(io->n_data_sets > 1) { io->multigene = 1; } #endif - if((io->mod->bootstrap > 1) && (io->n_data_sets > 1)) + if((io->do_boot || io->do_tbe) && (io->n_data_sets > 1)) { - printf("\n. Bootstrap option is not allowed with multiple data sets !\n"); - printf("\n. Type any key to exit."); - scanf("%c",&choix); + PhyML_Printf("\n. Bootstrap option is not allowed with multiple data sets !\n"); + PhyML_Printf("\n. Type any key to exit."); + if(!scanf("%c",&choix)) Exit("\n"); Exit("\n"); } @@ -356,21 +496,27 @@ void Launch_Interface_Data_Type(option *io) } case 'D' : { - if(io->mod->datatype == NT) + if(io->datatype == NT) { - io->mod->datatype = 1; - io->mod->stepsize = 1; - io->mod->ns = 20; - io->mod->whichmodel = LG; - strcpy(io->mod->modelname,"LG"); + io->datatype = AA; + io->mod->ns = 20; + io->mod->s_opt->opt_kappa = 0; + io->mod->whichmodel = LG; + strcpy(io->mod->modelname->s,"LG"); } - else + else if(io->datatype == AA) { - io->mod->datatype = 0; - io->mod->stepsize = 1; - io->mod->ns = 4; - io->mod->whichmodel = HKY85; - strcpy(io->mod->modelname,"HKY85"); + io->datatype = GENERIC; + io->mod->whichmodel = JC69; + strcpy(io->mod->modelname->s,"JC69"); + strcpy(io->nt_or_cd,"natural numbers"); + } + else if(io->datatype == GENERIC) + { + io->datatype = NT; + io->mod->ns = 4; + io->mod->whichmodel = HKY85; + strcpy(io->mod->modelname->s,"HKY85"); strcpy(io->nt_or_cd,"nucleotides"); } break; @@ -399,7 +545,9 @@ void Launch_Interface_Data_Type(option *io) Free(s); Free(buff); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Launch_Interface_Model(option *io) { @@ -413,32 +561,32 @@ void Launch_Interface_Model(option *io) if(io->config_multigene) Print_Data_Set_Number(io,stdout); - printf("\n\n"); + PhyML_Printf("\n\n"); - printf(" ........................... \n"); - printf(" Menu : Substitution Model \n"); - printf(" ................................. \n"); + PhyML_Printf(" ........................... \n"); + PhyML_Printf(" Menu : Substitution Model \n"); + PhyML_Printf(" ................................. \n"); - printf("\n\n"); + PhyML_Printf("\n\n"); - printf(" [+] " + PhyML_Printf(" [+] " ".................................... Next sub-menu\n"); - printf(" [-] " + PhyML_Printf(" [-] " "................................ Previous sub-menu\n"); - printf(" [Y] " + PhyML_Printf(" [Y] " ".............................. Launch the analysis\n"); - printf("\n"); + PhyML_Printf("\n"); - if (io->mod->datatype == NT) + if (io->datatype == NT) { if(!strcmp(io->nt_or_cd,"nucleotides")) { - printf(" [M] " + PhyML_Printf(" [M] " "................. Model of nucleotide substitution " - " %-15s \n", io->mod->modelname); + " %-15s \n", io->mod->modelname->s); if((io->mod->whichmodel == F81) || (io->mod->whichmodel == HKY85) || @@ -447,14 +595,14 @@ void Launch_Interface_Model(option *io) (io->mod->whichmodel == GTR) || (io->mod->whichmodel == CUSTOM)) { -/* printf(" [F] " */ +/* PhyML_Printf(" [F] " */ /* ".......... Base frequency estimates (empirical/ML) " */ /* " %-15s \n", */ /* (io->mod->s_opt->opt_state_freq)?("ML"):("empirical")); */ /* } */ /* else if(io->mod->whichmodel == CUSTOM) */ /* { */ - printf(" [F] " + PhyML_Printf(" [F] " "................. Optimise equilibrium frequencies " " %-15s \n", (io->mod->s_opt->opt_state_freq)?("yes"):("no")); @@ -465,60 +613,67 @@ void Launch_Interface_Model(option *io) { if(!io->mod->s_opt->opt_state_freq) { - printf(" [E] " + PhyML_Printf(" [E] " "......... Equilibrium frequencies (empirical/user) " " %-15s \n", - (io->mod->s_opt->user_state_freq)?("user defined"):("empirical")); + (io->mod->e_frq->user_state_freq)?("user defined"):("empirical")); } - printf(" [K] " + PhyML_Printf(" [K] " "............................. Current custom model " - " %-15s \n", io->mod->custom_mod_string); + " %-15s \n", io->mod->custom_mod_string->s); - printf(" [O] " + PhyML_Printf(" [O] " "................ Optimise relative rate parameters " " %-15s \n",(io->mod->s_opt->opt_rr)?("yes"):("no")); } } } - else + else if(io->datatype == AA) { - printf(" [M] " + PhyML_Printf(" [M] " "................ Model of amino-acids substitution " - " %-15s \n", io->mod->modelname); + " %-15s \n", io->mod->modelname->s); - printf(" [F] " + PhyML_Printf(" [F] " ". Amino acid frequencies (empirical/model defined) " " %-15s \n", (io->mod->s_opt->opt_state_freq)?("empirical"):("model")); } + else if(io->datatype == GENERIC) + { + PhyML_Printf(" [M] " + "................. Model of nucleotide substitution " + " %-15s \n", io->mod->modelname->s); + } - - if ((io->mod->datatype == NT) && + if ((io->datatype == NT) && ((io->mod->whichmodel == K80) || (io->mod->whichmodel == HKY85)|| (io->mod->whichmodel == F84) || (io->mod->whichmodel == TN93))) { strcpy(s,(io->mod->s_opt->opt_kappa)?("estimated"):("fixed")); - (io->mod->s_opt->opt_kappa)?((char *)strcat(s,"")):((char *)strcat(s," (ts/tv = ")); -/* (io->mod->s_opt->opt_kappa)?((char *)strcat(s,"")):((char *)sprintf(s+(int)strlen((char *)s),"%3.2f)",io->mod->kappa)); */ + if(io->mod->s_opt->opt_kappa) strcat(s,""); + else strcat(s," (ts/tv = "); + +/* (io->mod->s_opt->opt_kappa)?((char *)strcat(s,"")):((char *)sprintf(s+(int)strlen((char *)s),"%3.2f)",io->mod->kappa->v)); */ if(io->mod->s_opt->opt_kappa) { strcat((char *)s,""); } else { - sprintf((char *)(s+(int)strlen(s)),"%3.2f)",io->mod->kappa); + sprintf((char *)(s+(int)strlen(s)),"%3.2f)",io->mod->kappa->v); } - printf(" [T] " + PhyML_Printf(" [T] " ".................... Ts/tv ratio (fixed/estimated) " " %-15s \n",s); } - - (io->mod->s_opt->opt_pinvar)?(strcpy(s,"estimated")):(strcpy(s,"fixed")); - (io->mod->s_opt->opt_pinvar)?((char *)strcat(s,"")):((char *)strcat(s," (p-invar = ")); + + strcpy(s,io->mod->s_opt->opt_pinvar?"estimated":"fixed"); + strcat(s,io->mod->s_opt->opt_pinvar?"":" (p-invar = "); if(io->mod->s_opt->opt_pinvar) { @@ -526,31 +681,39 @@ void Launch_Interface_Model(option *io) } else { - sprintf((char *)(s+strlen((char *)s)),"%3.2f)",io->mod->pinvar); + sprintf((char *)(s+strlen((char *)s)),"%3.2f)",io->mod->ras->pinvar->v); } - printf(" [V] " + PhyML_Printf(" [V] " ". Proportion of invariable sites (fixed/estimated)" " %-15s \n",s); - printf(" [R] " + PhyML_Printf(" [R] " "....... One category of substitution rate (yes/no) " " %-15s \n", - (io->mod->n_catg > 1)?("no"):("yes")); + (io->mod->ras->n_catg > 1)?("no"):("yes")); - if(io->mod->n_catg > 1) + if(io->mod->ras->n_catg > 1) { - printf(" [C] " + PhyML_Printf(" [C] " "........... Number of substitution rate categories " " %-15d \n", - io->mod->n_catg); + io->mod->ras->n_catg); + } + + + if(io->mod->ras->n_catg > 1) + { + PhyML_Printf(" [G] " + "............. Gamma distributed rates across sites " + " %-15s \n",(io->mod->ras->free_mixt_rates)?("no"):("yes")); } - if(io->mod->n_catg > 1) + if((io->mod->ras->n_catg > 1) && (io->mod->ras->free_mixt_rates == NO)) { strcpy(s,(io->mod->s_opt->opt_alpha)?("estimated"):("fixed")); - (io->mod->s_opt->opt_alpha)?(strcat(s, "")):(strcat(s," (alpha = ")); + strcat(s,io->mod->s_opt->opt_alpha?"":" (alpha = "); if(io->mod->s_opt->opt_alpha) { @@ -558,19 +721,28 @@ void Launch_Interface_Model(option *io) } else { - sprintf(s+strlen(s),"%3.2f)",io->mod->alpha); + sprintf(s+strlen(s),"%3.2f)",io->mod->ras->alpha->v); } - printf(" [A] " + PhyML_Printf(" [A] " "... Gamma distribution parameter (fixed/estimated) " " %-15s \n",s); + + +/* strcpy(s,(io->mod->ras->gamma_median)?("median"):("mean")); */ + +/* PhyML_Printf(" [G] " */ +/* ".........'Middle' of each rate class (mean/median) " */ +/* " %-15s \n",s); */ + + } - printf("\n\n. Are these settings correct ? " + PhyML_Printf("\n\n. Are these settings correct ? " "(type '+', '-', 'Y' or other letter for one to change) "); - scanf("%c",&choix); + if(!scanf("%c",&choix)) Exit("\n"); if(choix != '\n') getchar(); /* \n */ Uppercase(&choix); @@ -583,6 +755,12 @@ void Launch_Interface_Model(option *io) /* break; */ /* } */ + case 'G' : + { + io->mod->ras->free_mixt_rates = (io->mod->ras->free_mixt_rates)?(NO):(YES); + break; + } + case 'O' : { io->mod->s_opt->opt_rr = (io->mod->s_opt->opt_rr)?(0):(1); @@ -593,46 +771,52 @@ void Launch_Interface_Model(option *io) { int i,j; char **rr_param,*rr; - model *mod; - int curr_param; + t_mod *mod; int n_trial; if(io->mod->whichmodel == CUSTOM) { rr_param = (char **)mCalloc(6,sizeof(char *)); - For(i,6) rr_param[i] = (char *)mCalloc(10,sizeof(char)); + for(i=0;i<6;i++) rr_param[i] = (char *)mCalloc(10,sizeof(char)); rr = (char *)mCalloc(50,sizeof(char)); mod = io->mod; + mod->s_opt->opt_rr = 1; n_trial = 0; do { - printf("\n. Enter a new custom model > "); - Getstring_Stdin(io->mod->custom_mod_string); - if(strlen(io->mod->custom_mod_string) == 6) + PhyML_Printf("\n. Enter a new custom model > "); + Getstring_Stdin(io->mod->custom_mod_string->s); + if(strlen(io->mod->custom_mod_string->s) == 6) { - For(i,6) + for(i=0;i<6;i++) { - while(!isdigit((int)io->mod->custom_mod_string[i])) + while(!isdigit((int)io->mod->custom_mod_string->s[i])) { - if(++n_trial > 10) Exit("\n. Err : this string is not valid !\n"); - printf("\n. This string is not valid\n"); - printf("\n. Enter a new model > "); - Getstring_Stdin(io->mod->custom_mod_string); + if(++n_trial > 10) Exit("\n== Err : this string is not valid !\n"); + PhyML_Printf("\n. This string is not valid\n"); + PhyML_Printf("\n. Enter a new model > "); + Getstring_Stdin(io->mod->custom_mod_string->s); } } if(i == 6) break; } else { - printf("\n. The string should be of length 6\n"); + PhyML_Printf("\n. The string should be of length 6\n"); n_trial++; } }while(n_trial < 10); if(n_trial == 10) Exit(""); - Translate_Custom_Mod_String(io->mod); + if(!mod->r_mat) + { + mod->r_mat = (t_rmat *)Make_Rmat(mod->ns); + Init_Rmat(mod->r_mat); + Make_Custom_Model(mod); + Translate_Custom_Mod_String(io->mod); + } strcpy(rr_param[0],"A<->C"); strcpy(rr_param[1],"A<->G"); @@ -641,22 +825,21 @@ void Launch_Interface_Model(option *io) strcpy(rr_param[4],"C<->T"); strcpy(rr_param[5],"G<->T"); - printf("\n. Set the relative rate values\n"); - curr_param = 0; - For(i,mod->n_diff_rr) + PhyML_Printf("\n. Set the relative rate values\n"); + for(i=0;ir_mat->n_diff_rr;i++) { sprintf(rr,"\n. ["); - For(j,6) + for(j=0;j<6;j++) { - if(mod->rr_num[j] == i) + if(mod->r_mat->rr_num->v[j] == i) { sprintf(rr+strlen(rr),"%s = ",rr_param[j]); } } sprintf(rr+strlen(rr)-3,"]"); - printf("%s",rr); + PhyML_Printf("%s",rr); - printf(" (current=%.2f) > ",mod->rr_val[i]); + PhyML_Printf(" (current=%.2f) > ",mod->r_mat->rr_val->v[i]); Getstring_Stdin(rr); @@ -666,16 +849,16 @@ void Launch_Interface_Model(option *io) while((atof(rr) < .0)) { if(++n_trial > 10) - Exit("\n. Err : the value of this parameter must be a positive number\n"); - printf("\n. The value of this parameter must be a positive number\n"); - printf("\n. Enter a new value > "); + Exit("\n== Err : the value of this parameter must be a positive number\n"); + PhyML_Printf("\n. The value of this parameter must be a positive number\n"); + PhyML_Printf("\n. Enter a new value > "); Getstring_Stdin(rr); } - io->mod->rr_val[i] = (phydbl)atof(rr); + io->mod->r_mat->rr_val->v[i] = (phydbl)atof(rr); } } - For(i,5) Free(rr_param[i]); + for(i=0;i<6;i++) Free(rr_param[i]); Free(rr_param); Free(rr); } @@ -687,9 +870,9 @@ void Launch_Interface_Model(option *io) if(io->mod->whichmodel == CUSTOM) { - io->mod->s_opt->user_state_freq = (io->mod->s_opt->user_state_freq)?(0):(1); + io->mod->e_frq->user_state_freq = (io->mod->e_frq->user_state_freq)?(0):(1); - if(io->mod->s_opt->user_state_freq) + if(io->mod->e_frq->user_state_freq) { if(!io->mod->s_opt->opt_state_freq) { @@ -699,7 +882,7 @@ void Launch_Interface_Model(option *io) int n_trial; bases = (char **)mCalloc(4,sizeof(char *)); - For(i,4) bases[i] = (char *)mCalloc(50,sizeof(char)); + for(i=0;i<4;i++) bases[i] = (char *)mCalloc(50,sizeof(char)); bs = (char *)mCalloc(100,sizeof(char)); strcpy(bases[0],". f(A)> "); @@ -707,41 +890,41 @@ void Launch_Interface_Model(option *io) strcpy(bases[2],". f(G)> "); strcpy(bases[3],". f(T)> "); - printf("\n. Set nucleotide frequencies \n"); + PhyML_Printf("\n. Set nucleotide frequencies \n"); sum = .0; - For(i,4) + for(i=0;i<4;i++) { - printf("%s",bases[i]); + PhyML_Printf("%s",bases[i]); Getstring_Stdin(bs); n_trial = 0; while((atof(bs) < .0001) || (bs[0] == '\0')) { if(++n_trial > 10) - Exit("\n. Err : the value of this parameter must be a positive number\n"); - printf("\n. The value of this parameter must be a positive number\n"); - printf("\n. Enter a new value > "); + Exit("\n== Err : the value of this parameter must be a positive number\n"); + PhyML_Printf("\n. The value of this parameter must be a positive number\n"); + PhyML_Printf("\n. Enter a new value > "); Getstring_Stdin(bs); } - io->mod->user_b_freq[i] = (phydbl)atof(bs); - sum += io->mod->user_b_freq[i]; + io->mod->e_frq->user_b_freq->v[i] = (phydbl)atof(bs); + sum += io->mod->e_frq->user_b_freq->v[i]; } - For(i,4) io->mod->user_b_freq[i] /= sum; + for(i=0;i<4;i++) io->mod->e_frq->user_b_freq->v[i] /= sum; if(sum > 1.0 || sum < 1.0) { - printf("\n. The nucleotide frequencies have to be normalised in order to sum to 1.0.\n"); - printf("\n. The frequencies are now : f(A)=%f, f(C)=%f, f(G)=%f, f(T)=%f.\n", - io->mod->user_b_freq[0], - io->mod->user_b_freq[1], - io->mod->user_b_freq[2], - io->mod->user_b_freq[3]); - printf("\n. Enter any key to continue.\n"); - scanf("%c",bs); + PhyML_Printf("\n. The nucleotide frequencies have to be normalised in order to sum to 1.0.\n"); + PhyML_Printf("\n. The frequencies are now : f(A)=%f, f(C)=%f, f(G)=%f, f(T)=%f.\n", + io->mod->e_frq->user_b_freq->v[0], + io->mod->e_frq->user_b_freq->v[1], + io->mod->e_frq->user_b_freq->v[2], + io->mod->e_frq->user_b_freq->v[3]); + PhyML_Printf("\n. Enter any key to continue.\n"); + if(!scanf("%c",bs)) Exit("\n"); } - For(i,4) Free(bases[i]); + for(i=0;i<4;i++) Free(bases[i]); Free(bases); Free(bs); } @@ -758,20 +941,22 @@ void Launch_Interface_Model(option *io) char answer; int n_trial; + answer = 0; + switch(io->mod->s_opt->opt_alpha) { case 0 : { - printf("\n. Optimise alpha ? [Y/n] "); - scanf("%c",&answer); + PhyML_Printf("\n. Optimise alpha ? [Y/n] "); + if(!scanf("%c",&answer)) Exit("\n"); if(answer == '\n') answer = 'Y'; else getchar(); break; } case 1 : { - printf("\n. Optimise alpha ? [N/y] "); - scanf("%c",&answer); + PhyML_Printf("\n. Optimise alpha ? [N/y] "); + if(!scanf("%c",&answer)) Exit("\n"); if(answer == '\n') answer = 'N'; else getchar(); break; @@ -783,9 +968,9 @@ void Launch_Interface_Model(option *io) while((answer != 'Y') && (answer != 'y') && (answer != 'N') && (answer != 'n')) { - if(++n_trial > 10) Exit("\n. Err : wrong answers !"); - printf("\n. Optimise alpha ? [N/y] "); - scanf("%c",&answer); + if(++n_trial > 10) Exit("\n== Err : wrong answers !"); + PhyML_Printf("\n. Optimise alpha ? [N/y] "); + if(!scanf("%c",&answer)) Exit("\n"); if(answer == '\n') answer = 'N'; else getchar(); } @@ -795,26 +980,26 @@ void Launch_Interface_Model(option *io) case 'Y' : case 'y' : { io->mod->s_opt->opt_alpha = 1; - io->mod->s_opt->opt_num_param = 1; + io->mod->s_opt->opt_subst_param = 1; break; } case 'N' : case 'n' : { char *a; a = (char *)mCalloc(100,sizeof(char)); - io->mod->alpha = 10.0; + io->mod->ras->alpha->v = 10.0; io->mod->s_opt->opt_alpha = 0; - printf("\n. Enter your value of alpha > "); + PhyML_Printf("\n. Enter your value of alpha > "); Getstring_Stdin(a); n_trial = 0; - while((!atof(a)) || (atof(a) < .0)) + while(atof(a) < 1.E-10) { - if(++n_trial > 10) Exit("\n. Err : alpha must be a positive number\n"); - printf("\n. Alpha must be a positive number\n"); - printf("\n. Enter a new value > "); + if(++n_trial > 10) Exit("\n== Err : alpha must be > 1.E-10\n"); + PhyML_Printf("\n. Alpha must be 1.E-10\n"); + PhyML_Printf("\n. Enter a new value > "); Getstring_Stdin(a); } - io->mod->alpha = (phydbl)atof(a); + io->mod->ras->alpha->v = (phydbl)atof(a); Free(a); io->mod->s_opt->opt_alpha = 0; break; @@ -828,25 +1013,25 @@ void Launch_Interface_Model(option *io) char *c; int n_trial; - printf("\n. Enter your number of categories > "); + PhyML_Printf("\n. Enter your number of categories > "); c = (char *)mCalloc(100,sizeof(char)); Getstring_Stdin(c); n_trial = 0; while((!atoi(c)) || (atoi(c) < 0)) { - if(++n_trial > 10) Exit("\n. Err : the number of categories must be a positive integer\n"); - printf("\n. The number of categories must be a positive integer\n"); - printf("\n. Enter a new value > "); + if(++n_trial > 10) Exit("\n== Err : the number of categories must be a positive integer\n"); + PhyML_Printf("\n. The number of categories must be a positive integer\n"); + PhyML_Printf("\n. Enter a new value > "); Getstring_Stdin(c); } - io->mod->n_catg = atoi(c); + io->mod->ras->n_catg = atoi(c); Free(c); break; } case 'R' : { - (io->mod->n_catg == 1)?(io->mod->n_catg = 4):(io->mod->n_catg = 1); + io->mod->ras->n_catg = (io->mod->ras->n_catg == 1)?(4):(1); break; } @@ -854,21 +1039,24 @@ void Launch_Interface_Model(option *io) { char answer; int n_trial; + + answer = 0; switch(io->mod->s_opt->opt_pinvar) { case 0 : { - printf("\n. Optimise p-invar ? [Y/n] "); - scanf("%c", &answer); + PhyML_Printf("\n. Optimise p-invar ? [Y/n] "); + answer = 0; + if(!scanf("%c", &answer)) Exit("\n"); if(answer == '\n') answer = 'Y'; else getchar(); break; } case 1 : { - printf("\n. Optimise p-invar ? [N/y] "); - scanf("%c", &answer); + PhyML_Printf("\n. Optimise p-invar ? [N/y] "); + if(!scanf("%c", &answer)) Exit("\n"); if(answer == '\n') answer = 'N'; else getchar(); break; @@ -880,9 +1068,9 @@ void Launch_Interface_Model(option *io) while((answer != 'Y') && (answer != 'y') && (answer != 'N') && (answer != 'n')) { - if(++n_trial > 10) Exit("\n. Err : wrong answers !"); - printf("\n. Optimise p-invar ? [N/y] "); - scanf("%c", &answer); + if(++n_trial > 10) Exit("\n== Err : wrong answers !"); + PhyML_Printf("\n. Optimise p-invar ? [N/y] "); + if(!scanf("%c", &answer)) Exit("\n"); if(answer == '\n') answer = 'N'; else getchar(); } @@ -891,31 +1079,31 @@ void Launch_Interface_Model(option *io) { case 'Y' : case 'y' : { - io->mod->s_opt->opt_num_param = 1; + io->mod->s_opt->opt_subst_param = 1; io->mod->s_opt->opt_pinvar = 1; - io->mod->pinvar = 0.2; - io->mod->invar = 1; + io->mod->ras->pinvar->v = 0.2; + io->mod->ras->invar = 1; break; } case 'N' : case 'n' : { char *p; p = (char *)mCalloc(100,sizeof(char)); - printf("\n. Enter your value of p-invar > "); + PhyML_Printf("\n. Enter your value of p-invar > "); Getstring_Stdin(p); n_trial = 0; while((atof(p) < 0.0) || (atof(p) > 1.0)) { if(++n_trial > 10) - Exit("\n. Err : the proportion of invariable sites must be a positive number between 0.0 and 1.0"); - printf("\n. The proportion must be a positive number between 0.0 and 1.0\n"); - printf("\n. Enter a new value > "); + Exit("\n== Err : the proportion of invariable sites must be a positive number between 0.0 and 1.0"); + PhyML_Printf("\n. The proportion must be a positive number between 0.0 and 1.0\n"); + PhyML_Printf("\n. Enter a new value > "); Getstring_Stdin(p); } - io->mod->pinvar = (phydbl)atof(p); + io->mod->ras->pinvar->v = (phydbl)atof(p); - if(io->mod->pinvar > 0.0+MDBL_MIN) io->mod->invar = 1; - else io->mod->invar = 0; + if(io->mod->ras->pinvar->v > 0.0+SMALL) io->mod->ras->invar = 1; + else io->mod->ras->invar = 0; Free(p); @@ -930,16 +1118,18 @@ void Launch_Interface_Model(option *io) { char answer; int n_trial; - - if((io->mod->datatype == AA) || + + answer = 0; + + if((io->datatype == AA) || (io->mod->whichmodel == JC69)|| (io->mod->whichmodel == F81) || (io->mod->whichmodel == GTR) || (io->mod->whichmodel == CUSTOM)) { - printf("\n. 'K' is not a valid choice for this model\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); + PhyML_Printf("\n. 'K' is not a valid choice for this model\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); Exit("\n"); } @@ -947,16 +1137,16 @@ void Launch_Interface_Model(option *io) { case 0 : { - printf("\n. Optimise ts/tv ratio ? [Y/n] "); - scanf("%c", &answer); + PhyML_Printf("\n. Optimise ts/tv ratio ? [Y/n] "); + if(!scanf("%c", &answer)) Exit("\n"); if(answer == '\n') answer = 'Y'; else getchar(); break; } case 1 : { - printf("\n. Optimise ts/tv ratio ? [N/y] "); - scanf("%c", &answer); + PhyML_Printf("\n. Optimise ts/tv ratio ? [N/y] "); + if(!scanf("%c", &answer)) Exit("\n"); if(answer == '\n') answer = 'N'; else getchar(); break; @@ -968,9 +1158,9 @@ void Launch_Interface_Model(option *io) while((answer != 'Y') && (answer != 'y') && (answer != 'N') && (answer != 'n')) { - if(++n_trial > 10) Exit("\n. Err : wrong answers !"); - printf("\n. Optimise ts/tv ratio ? [N/y] "); - scanf("%c", &answer); + if(++n_trial > 10) Exit("\n== Err : wrong answers !"); + PhyML_Printf("\n. Optimise ts/tv ratio ? [N/y] "); + if(!scanf("%c", &answer)) Exit("\n"); if(answer == '\n') answer = 'N'; else getchar(); } @@ -979,9 +1169,8 @@ void Launch_Interface_Model(option *io) { case 'Y' : case 'y' : { - io->mod->kappa = 4.0; - io->mod->s_opt->opt_num_param = 1; - io->mod->s_opt->opt_kappa = 1; + io->mod->kappa->v = 4.0; + io->mod->s_opt->opt_subst_param = 1; io->mod->s_opt->opt_kappa = 1; if(io->mod->whichmodel == TN93) io->mod->s_opt->opt_lambda = 1; @@ -992,17 +1181,17 @@ void Launch_Interface_Model(option *io) char *t; t = (char *)mCalloc(100,sizeof(char)); io->mod->s_opt->opt_kappa = 0; - printf("\n. Enter your value of the ts/tv ratio > "); + PhyML_Printf("\n. Enter your value of the ts/tv ratio > "); Getstring_Stdin(t); n_trial = 0; - while((!atof(t)) || (atof(t) < .0)) + while(atof(t) < .0) { - if(++n_trial > 10) Exit("\n. Err : the ts/tv ratio must be a positive number\n"); - printf("\n. The ratio must be a positive number"); - printf("\n. Enter a new value > "); + if(++n_trial > 10) Exit("\n== Err : the ts/tv ratio must be a positive number\n"); + PhyML_Printf("\n. The ratio must be a positive number"); + PhyML_Printf("\n. Enter a new value > "); Getstring_Stdin(t); } - io->mod->kappa = (phydbl)atof(t); + io->mod->kappa->v = (phydbl)atof(t); io->mod->s_opt->opt_kappa = 0; io->mod->s_opt->opt_lambda = 0; Free(t); @@ -1025,121 +1214,117 @@ void Launch_Interface_Model(option *io) case 'M' : { - if(io->mod->datatype == NT) + if(io->datatype == NT) { if(!strcmp(io->nt_or_cd,"nucleotides")) { if(io->mod->whichmodel == JC69) { io->mod->whichmodel = K80; - strcpy(io->mod->modelname,"K80"); } else if(io->mod->whichmodel == K80) { io->mod->whichmodel = F81; - strcpy(io->mod->modelname,"F81"); - io->mod->s_opt->opt_kappa = 0; } else if(io->mod->whichmodel == F81) { io->mod->whichmodel = HKY85; - strcpy(io->mod->modelname,"HKY85"); } else if(io->mod->whichmodel == HKY85) { io->mod->whichmodel = F84; - strcpy(io->mod->modelname,"F84"); } else if(io->mod->whichmodel == F84) { io->mod->whichmodel = TN93; - strcpy(io->mod->modelname,"TN93"); - if(io->mod->s_opt->opt_kappa) io->mod->s_opt->opt_lambda = 1; } else if(io->mod->whichmodel == TN93) { io->mod->whichmodel = GTR; - strcpy(io->mod->modelname,"GTR"); - io->mod->s_opt->opt_kappa = 0; } else if(io->mod->whichmodel == GTR) { io->mod->whichmodel = CUSTOM; - strcpy(io->mod->modelname,"custom"); - io->mod->s_opt->opt_kappa = 0; } else if(io->mod->whichmodel == CUSTOM) { io->mod->whichmodel = JC69; - strcpy(io->mod->modelname,"JC69"); - io->mod->s_opt->opt_kappa = 0; } } } - else + else if(io->datatype == AA) { if(io->mod->whichmodel == LG) { io->mod->whichmodel = WAG; - strcpy(io->mod->modelname,"WAG"); } else if(io->mod->whichmodel == WAG) { io->mod->whichmodel = DAYHOFF; - strcpy(io->mod->modelname,"Dayhoff"); } else if(io->mod->whichmodel == DAYHOFF) { io->mod->whichmodel = JTT; - strcpy(io->mod->modelname,"JTT"); } else if(io->mod->whichmodel == JTT) { io->mod->whichmodel = BLOSUM62; - strcpy(io->mod->modelname,"Blossum62"); } else if(io->mod->whichmodel == BLOSUM62) { io->mod->whichmodel = MTREV; - strcpy(io->mod->modelname,"MtREV"); } else if(io->mod->whichmodel == MTREV) { io->mod->whichmodel = RTREV; - strcpy(io->mod->modelname,"RtREV"); } else if(io->mod->whichmodel == RTREV) { io->mod->whichmodel = CPREV; - strcpy(io->mod->modelname,"CpREV"); } else if(io->mod->whichmodel == CPREV) { io->mod->whichmodel = DCMUT; - strcpy(io->mod->modelname,"DCMut"); } else if(io->mod->whichmodel == DCMUT) { io->mod->whichmodel = VT; - strcpy(io->mod->modelname,"VT"); } else if(io->mod->whichmodel == VT) { io->mod->whichmodel = MTMAM; - strcpy(io->mod->modelname,"MtMam"); } else if(io->mod->whichmodel == MTMAM) + { + io->mod->whichmodel = MTART; + } + else if(io->mod->whichmodel == MTART) + { + io->mod->whichmodel = HIVW; + } + else if(io->mod->whichmodel == HIVW) + { + io->mod->whichmodel = HIVB; + } + else if(io->mod->whichmodel == HIVB) + { + io->mod->whichmodel = AB; + } + else if(io->mod->whichmodel == AB) { io->mod->whichmodel = CUSTOMAA; - strcpy(io->mod->modelname,"Read from file"); } else if(io->mod->whichmodel == CUSTOMAA) { io->mod->whichmodel = LG; - strcpy(io->mod->modelname,"LG"); } } + else if(io->datatype == GENERIC) + { + io->mod->whichmodel = JC69; + } + Set_Model_Name(io->mod); break; } case '-' : @@ -1167,87 +1352,118 @@ void Launch_Interface_Model(option *io) io->mod->s_opt->opt_kappa || io->mod->s_opt->opt_lambda || io->mod->s_opt->opt_pinvar || - io->mod->s_opt->opt_rr) io->mod->s_opt->opt_num_param = 1; - else io->mod->s_opt->opt_num_param = 0; - - - - + io->mod->s_opt->opt_rr) io->mod->s_opt->opt_subst_param = 1; + else io->mod->s_opt->opt_subst_param = 0; Free(s); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Launch_Interface_Topo_Search(option *io) { char choix; + char *s; + + s = (char *)mCalloc(100,sizeof(char)); Clear(); Print_Banner(stdout); - printf("\n\n"); + PhyML_Printf("\n\n"); - printf(" ....................... \n"); - printf(" Menu : Tree Searching \n"); - printf(" ............................. \n"); + PhyML_Printf(" ....................... \n"); + PhyML_Printf(" Menu : Tree Searching \n"); + PhyML_Printf(" ............................. \n"); - printf("\n\n"); + PhyML_Printf("\n\n"); - printf(" [+] " + PhyML_Printf(" [+] " ".................................... Next sub-menu\n"); - printf(" [-] " + PhyML_Printf(" [-] " "................................ Previous sub-menu\n"); - printf(" [Y] " + PhyML_Printf(" [Y] " ".............................. Launch the analysis\n"); - printf("\n"); + PhyML_Printf("\n"); - printf(" [O] " + PhyML_Printf(" [O] " "........................... Optimise tree topology " " %-15s \n", (io->mod->s_opt->opt_topo)?("yes"):("no")); + if(io->mod->s_opt->opt_topo) + { + switch(io->in_tree) + { + case 0: { strcpy(s,"BioNJ"); break; } + case 1: { strcpy(s,"parsimony"); break; } + case 2: { strcpy(s,"user tree"); break; } + } + + PhyML_Printf(" [U] " + "........ Starting tree (BioNJ/parsimony/user tree) " + " %-15s \n",s); + } + else + { + switch(io->in_tree) + { + case 0: { strcpy(s,"BioNJ"); break; } + case 2: { strcpy(s,"user tree"); break; } + } + + PhyML_Printf(" [U] " + "..................... Input tree (BioNJ/user tree) " + " %-15s \n",s); + } + if(io->mod->s_opt->opt_topo) { char *s; s = (char *)mCalloc(T_MAX_OPTION,sizeof(char)); + + io->mod->s_opt->topo_search = SPR_MOVE; + if(io->mod->s_opt->topo_search == NNI_MOVE) { - if(!io->mod->s_opt->spr_step_after_nnis) - { - strcpy(s,"NNI moves (default)\0"); - } - else - { - strcpy(s,"NNI moves plus one SPR step\0"); - } + /* strcpy(s,"NNI moves (fast, approximate)\0"); */ + strcpy(s,"SPR moves\0"); } else if(io->mod->s_opt->topo_search == SPR_MOVE) - strcpy(s,"SPR moves\0"); + { + strcpy(s,"SPR moves\0"); + } + else if(io->mod->s_opt->topo_search == BEST_OF_NNI_AND_SPR) + { + strcpy(s,"SPR moves\0"); + /* strcpy(s,"Best of NNI and SPR \0"); */ + } - printf(" [S] " + PhyML_Printf(" [S] " ".................. Tree topology search operations " " %-15s \n",s); Free(s); - if(io->mod->s_opt->topo_search == SPR_MOVE) + if(io->mod->s_opt->topo_search != NNI_MOVE) { - printf(" [R] " - "......................... Use random starting tree " + PhyML_Printf(" [R] " + "........................ Add random starting trees " " %-15s \n", (io->mod->s_opt->random_input_tree)?("yes"):("no")); if(io->mod->s_opt->random_input_tree) { - printf(" [N] " + PhyML_Printf(" [N] " ".................. Number of random starting trees " " %-15d \n",io->mod->s_opt->n_rand_starts); } @@ -1255,29 +1471,24 @@ void Launch_Interface_Topo_Search(option *io) } else { - printf(" [L] " + PhyML_Printf(" [L] " ".......................... Optimise branch lengths " " %-15s \n", (io->mod->s_opt->opt_bl)?("yes"):("no")); } - if(!io->mod->s_opt->random_input_tree) - { - printf(" [U] " - "..................... Input tree (BioNJ/user tree) " - " %-15s \n", - (!io->in_tree)?("BioNJ"):("user tree")); - } - - printf("\n\n. Are these settings correct ? " + PhyML_Printf("\n\n. Are these settings correct ? " "(type '+', '-', 'Y' or other letter for one to change) "); - scanf("%c",&choix); + if(!scanf("%c",&choix)) Exit("\n"); if(choix != '\n') getchar(); /* \n */ + Free(s); + Uppercase(&choix); + switch(choix) { case '-' : @@ -1295,40 +1506,30 @@ void Launch_Interface_Topo_Search(option *io) io->ready_to_go = 1; break; } - - case 'A' : - { - io->mod->s_opt->spr_step_after_nnis = - (io->mod->s_opt->spr_step_after_nnis)?(0):(1); - break; - } case 'U' : { - if(!io->in_tree) + io->in_tree++; + if(!io->mod->s_opt->opt_topo) { - io->in_tree = 1; - printf("\n. Enter the name of the tree file > "); - Getstring_Stdin(io->in_tree_file); - io->fp_in_tree = Openfile(io->in_tree_file,0); + if(io->in_tree == 1) io->in_tree = 2; } - else io->in_tree = 0; + if(io->in_tree == 3) io->in_tree = 0; break; } - case 'N' : { char *n; int n_trial; - printf("\n. Enter your number of starting trees > "); + PhyML_Printf("\n. Enter your number of starting trees > "); n = (char *)mCalloc(100,sizeof(char)); Getstring_Stdin(n); n_trial = 0; - while((!atoi(n)) || (atoi(n) < 0)) + while(atoi(n) < 1) { - if(++n_trial > 10) Exit("\n. Err : the number of starting trees must be a positive integer\n"); - printf("\n. The number of starting trees must be a positive integer\n"); - printf("\n. Enter a new value > "); + if(++n_trial > 10) Exit("\n== Err : the number of starting trees must be a positive integer\n"); + PhyML_Printf("\n. The number of starting trees must be a positive integer\n"); + PhyML_Printf("\n. Enter a new value > "); Getstring_Stdin(n); } io->mod->s_opt->n_rand_starts = atoi(n); @@ -1355,24 +1556,24 @@ void Launch_Interface_Topo_Search(option *io) { if(io->mod->s_opt->topo_search == NNI_MOVE) { - if(!io->mod->s_opt->spr_step_after_nnis) - io->mod->s_opt->spr_step_after_nnis = 1; - else - { - io->mod->s_opt->topo_search = SPR_MOVE; - io->mod->s_opt->n_rand_starts = 1; - io->mod->s_opt->random_input_tree = 0; - io->mod->s_opt->greedy = 0; - io->mod->s_opt->spr_step_after_nnis = 0; - } + io->mod->s_opt->topo_search = SPR_MOVE; + io->mod->s_opt->n_rand_starts = 1; + io->mod->s_opt->random_input_tree = 0; + io->mod->s_opt->greedy = 0; } else if(io->mod->s_opt->topo_search == SPR_MOVE) { + io->mod->s_opt->topo_search = BEST_OF_NNI_AND_SPR; io->mod->s_opt->n_rand_starts = 1; io->mod->s_opt->random_input_tree = 0; + io->mod->s_opt->greedy = 0; + } + else if(io->mod->s_opt->topo_search == BEST_OF_NNI_AND_SPR) + { io->mod->s_opt->topo_search = NNI_MOVE; + io->mod->s_opt->n_rand_starts = 1; + io->mod->s_opt->random_input_tree = 0; io->mod->s_opt->greedy = 0; - io->mod->s_opt->spr_step_after_nnis = 0; } break; } @@ -1383,12 +1584,12 @@ void Launch_Interface_Topo_Search(option *io) if(io->mod->s_opt->random_input_tree) { if(io->fp_in_tree) fclose(io->fp_in_tree); - io->in_tree = 0; +/* io->in_tree = 0; */ io->n_trees = 1; io->mod->s_opt->n_rand_starts = 5; - strcpy(io->out_best_tree_file,io->in_seq_file); - strcat(io->out_best_tree_file,"_phyml_best_tree.txt"); + strcpy(io->out_trees_file,io->in_align_file); + strcat(io->out_trees_file,"_phyml_trees.txt"); } break; } @@ -1399,7 +1600,9 @@ void Launch_Interface_Topo_Search(option *io) } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Launch_Interface_Branch_Support(option *io) { @@ -1411,33 +1614,34 @@ void Launch_Interface_Branch_Support(option *io) Clear(); Print_Banner(stdout); - printf("\n\n"); + PhyML_Printf("\n\n"); - printf(" ....................... \n"); - printf(" Menu : Branch Support \n"); - printf(" ............................. \n"); + PhyML_Printf(" ....................... \n"); + PhyML_Printf(" Menu : Branch Support \n"); + PhyML_Printf(" ............................. \n"); - printf("\n\n"); + PhyML_Printf("\n\n"); - printf(" [+] " + PhyML_Printf(" [+] " ".................................... Next sub-menu\n"); - printf(" [-] " + PhyML_Printf(" [-] " "................................ Previous sub-menu\n"); - printf(" [Y] " + PhyML_Printf(" [Y] " ".............................. Launch the analysis\n"); - printf("\n"); + PhyML_Printf("\n"); - strcpy(s,(io->mod->bootstrap > 0)?("yes"):("no")); - if(io->mod->bootstrap > 0) sprintf(s+strlen(s)," (%d replicate%s)", - io->mod->bootstrap, - (io->mod->bootstrap>1)?("s"):("")); + strcpy(s,(io->do_boot || io->do_tbe)?("yes"):("no")); + if(io->n_boot_replicates > 0) sprintf(s+strlen(s)," (%d replicate%s%s)", + io->n_boot_replicates, + (io->n_boot_replicates>1)?("s"):(""), + (io->do_tbe)?(", TBE"):("")); - /* printf(" [+] " */ - printf(" [B] " + /* PhyML_Printf(" [+] " */ + PhyML_Printf(" [B] " "................ Non parametric bootstrap analysis " " %-15s \n",s); @@ -1457,22 +1661,26 @@ void Launch_Interface_Branch_Support(option *io) { strcpy(s,"yes / min of SH-like & Chi2-based supports"); } - else + else if(io->ratio_test == 4) { strcpy(s,"yes / SH-like supports"); } + else if(io->ratio_test == 5) + { + strcpy(s,"yes / aBayes supports"); + } - /* printf(" [+] " */ - printf(" [A] " + /* PhyML_Printf(" [+] " */ + PhyML_Printf(" [A] " "................ Approximate likelihood ratio test " " %-15s \n",s); - printf("\n. Are these settings correct ? " + PhyML_Printf("\n. Are these settings correct ? " "(type '+', '-', 'Y' or other letter for one to change) "); - scanf("%c",&choix); + if(!scanf("%c",&choix)) Exit("\n"); if(choix != '\n') getchar(); /* \n */ Uppercase(&choix); @@ -1489,41 +1697,42 @@ void Launch_Interface_Branch_Support(option *io) case 'B' : { - if(io->mod->bootstrap > 0) io->mod->bootstrap = 0; + if(io->n_boot_replicates > 0) io->n_boot_replicates = 0; else { char *r; char answer; int n_trial; + answer = 0; io->ratio_test = 0; if(io->n_data_sets > 1) { - printf("\n. Bootstrap option is not allowed with multiple data sets.\n"); - printf("\n. Type any key to exit.\n"); - scanf("%c",&choix); + PhyML_Printf("\n. Bootstrap option is not allowed with multiple data sets.\n"); + PhyML_Printf("\n. Type any key to exit.\n"); + if(!scanf("%c",&choix)) Exit("\n"); Exit("\n"); } - printf("\n. Number of replicates > "); + PhyML_Printf("\n. Number of replicates > "); r = (char *)mCalloc(T_MAX_OPTION,sizeof(char)); Getstring_Stdin(r); n_trial = 0; while((!atoi(r)) || (atoi(r) < 0)) { - if(++n_trial > 10) Exit("\n. Err : the number of replicates must be a positive integer\n"); - printf("\n. The number of replicates must be a positive integer"); - printf("\n. Enter a new value > "); + if(++n_trial > 10) Exit("\n== Err : the number of replicates must be a positive integer\n"); + PhyML_Printf("\n. The number of replicates must be a positive integer"); + PhyML_Printf("\n. Enter a new value > "); Getstring_Stdin(r); } - io->mod->bootstrap = atoi(r); - - printf("\n. Print bootstrap trees (and statistics) ? (%s) > ", - (io->print_boot_trees)?("Y/n"):("y/N")); + io->n_boot_replicates = atoi(r); - scanf("%c",&answer); + PhyML_Printf("\n. Print bootstrap trees (and statistics) ? (%s) > ", + (io->print_boot_trees)?("Y/n"):("y/N")); + + if(!scanf("%c",&answer)) Exit("\n"); if(answer == '\n') answer = (io->print_boot_trees)?('Y'):('N'); else getchar(); @@ -1533,11 +1742,12 @@ void Launch_Interface_Branch_Support(option *io) { io->print_boot_trees = 1; - strcpy(io->out_boot_tree_file,io->in_seq_file); + strcpy(io->out_boot_tree_file,io->in_align_file); + strcat(io->out_boot_tree_file,"_phyml_boot_trees.txt"); io->fp_out_boot_tree = Openfile(io->out_boot_tree_file,1); + strcpy(io->out_boot_stats_file,io->in_align_file); - strcpy(io->out_boot_stats_file,io->in_seq_file); strcat(io->out_boot_stats_file,"_phyml_boot_stats.txt"); io->fp_out_boot_stats = Openfile(io->out_boot_stats_file,1); @@ -1551,13 +1761,40 @@ void Launch_Interface_Branch_Support(option *io) break; } } + + PhyML_Printf("\n. Compute TBE instead of FBP ? (%s) > ", + (io->do_tbe)?("Y/n"):("y/N")); + + if(!scanf("%c",&answer)) Exit("\n"); + if(answer == '\n') answer = (io->do_tbe)?('Y'):('N'); + else getchar(); + + switch(answer) + { + case 'Y' : case 'y' : + { + io->do_tbe = YES; + io->do_boot = NO; + break; + } + case 'N' : case 'n' : + { + io->do_tbe = NO; + io->do_boot = YES; + break; + } + } Free(r); } break; } case 'A' : { - io->mod->bootstrap = 0; + io->do_boot = NO; + io->do_tbe = NO; + io->do_alrt = YES; + + io->n_boot_replicates = 0; switch(io->ratio_test) { @@ -1573,7 +1810,8 @@ void Launch_Interface_Branch_Support(option *io) } case 2 : { - io->ratio_test = 3; +/* io->ratio_test = 3; */ + io->ratio_test = 4; break; } case 3 : @@ -1582,6 +1820,11 @@ void Launch_Interface_Branch_Support(option *io) break; } case 4 : + { + io->ratio_test = 5; + break; + } + case 5 : { io->ratio_test = 0; break; @@ -1609,46 +1852,47 @@ void Launch_Interface_Branch_Support(option *io) } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// void Launch_Interface_Multigene(option *io) { -#ifdef MG +#ifdef PART if((io->n_data_sets > 1) && (io->multigene)) { int set, n_trial; char choix; - io->n_gt = io->n_data_sets; - io->st = (superarbre *)Mg_Make_Superarbre_Light(io); - io->st->n_gt = io->n_data_sets; + io->n_part = io->n_data_sets; + io->st = (supert_tree *)PART_Make_Supert_tree_Light(io); + io->st->n_part = io->n_data_sets; - For(set,io->n_gt) + for(set=0;setn_part;set++) { io->st->optionlist[set] = Make_Input(); Set_Defaults_Input(io->st->optionlist[set]); Set_Defaults_Model(io->st->optionlist[set]->mod); Set_Defaults_Optimiz(io->st->optionlist[set]->mod->s_opt); io->st->optionlist[set]->curr_gt = set; - printf("\n. Enter the sequence file name [data set %2d] > ",set+1); fflush(NULL); - Getstring_Stdin(io->st->optionlist[set]->in_seq_file); - io->st->optionlist[set]->fp_in_seq = Openfile(io->st->optionlist[set]->in_seq_file,0); + PhyML_Printf("\n. Enter the sequence file name [data set %2d] > ",set+1); fflush(NULL); + Getstring_Stdin(io->st->optionlist[set]->in_align_file); + io->st->optionlist[set]->fp_in_align = Openfile(io->st->optionlist[set]->in_align_file,0); } - printf("\n. Do you want to use your own initial tree ? [N/y] "); - scanf("%c", &choix); + PhyML_Printf("\n. Do you want to use your own initial tree ? [N/y] "); + if(!scanf("%c", &choix)) Exit("\n"); if(choix != '\n') getchar(); n_trial = 0; while((choix != 'Y') && (choix != 'y') && (choix != 'N') && (choix != 'n')) { - if(++n_trial > 10) Exit("\n. Err : wrong answers !"); - printf("\n. Do you want to use your own initial tree ? [N/y] ? "); - scanf("%c", &choix); + if(++n_trial > 10) Exit("\n== Err : wrong answers !"); + PhyML_Printf("\n. Do you want to use your own initial tree ? [N/y] ? "); + if(!scanf("%c", &choix)) Exit("\n"); if(choix == '\n') choix = 'N'; else getchar(); } @@ -1658,8 +1902,8 @@ void Launch_Interface_Multigene(option *io) case '\n' : break; case 'Y' : case 'y' : { - io->in_tree = 1; - printf("\n. Enter the name of the tree file > "); + io->in_tree = 2; + PhyML_Printf("\n. Enter the name of the tree file > "); Getstring_Stdin(io->in_tree_file); io->fp_in_tree = Openfile(io->in_tree_file,0); break; @@ -1693,16 +1937,16 @@ void Launch_Interface_Multigene(option *io) } default : { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Printf("\n== Err in file %s at line %d\n\n",__FILE__,__LINE__); Exit(""); break; } } }while(!io->st->optionlist[io->curr_gt]->ready_to_go); io->curr_gt++; - }while(io->curr_gt < io->n_gt); + }while(io->curr_gt < io->n_part); } io->ready_to_go = 1; - Mg_Fill_Model_Partitions_Table(io->st); + PART_Fill_Model_Partitions_Table(io->st); #endif } diff --git a/phyml/interface.h b/phyml/interface.h index add6ed9..d42730e 100644 --- a/phyml/interface.h +++ b/phyml/interface.h @@ -10,9 +10,18 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef INTERFACE_H #define INTERFACE_H +#include "utilities.h" +#include "help.h" +#include "models.h" +#include "free.h" +#include "help.h" + + void Launch_Interface(option *input); void Clear(); void Launch_Interface_Input(option *input); diff --git a/phyml/invitee.c b/phyml/invitee.c new file mode 100644 index 0000000..736b71b --- /dev/null +++ b/phyml/invitee.c @@ -0,0 +1,2599 @@ +#include "spr.h" +#include "utilities.h" +#include "lk.h" +#include "optimiz.h" +#include "bionj.h" +#include "models.h" +#include "free.h" +#include "help.h" +#include "simu.h" +#include "eigen.h" +#include "pars.h" +#include "alrt.h" +#include "mixt.h" +#include "invitee.h" +#ifdef MPI +#include "mpi_boot.h" +#endif +#include + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void PhyTime_XML(char *xml_file) +{ + + FILE *f; + char **clade, *clade_name, **mon_list; + phydbl low, up; + int i, j, n_taxa, clade_size, node_num, n_mon; //rnd_num + xml_node *n_r, *n_t, *n_m, *n_cur; + t_cal *last_calib; + align **data, **c_seq; + option *io; + calign *cdata; + t_opt *s_opt; + t_mod *mod; + time_t t_beg,t_end; + int r_seed; + char *most_likely_tree; + int user_lk_approx; + t_tree *tree; + t_node **a_nodes; //*node; + m4 *m4mod; + + srand(time(NULL)); + + i = 0; + j = 0; + last_calib = NULL; + mod = NULL; + most_likely_tree = NULL; + n_taxa = 0; + node_num = -1; + + //file can/cannot be open: + if ((f =(FILE *)fopen(xml_file, "r")) == NULL) + { + PhyML_Printf("\n== File '%s' can not be opened...\n",xml_file); + Exit("\n"); + } + + n_r = XML_Load_File(f); + + + //memory allocation for model parameters: + io = (option *)Make_Input(); + mod = (t_mod *)Make_Model_Basic(); + s_opt = (t_opt *)Make_Optimiz(); + m4mod = (m4 *)M4_Make_Light(); + Set_Defaults_Input(io); + Set_Defaults_Model(mod); + Set_Defaults_Optimiz(s_opt); + io -> mod = mod; + mod = io -> mod; + mod -> s_opt = s_opt; + clade_size = -1; + + //////////////////////////////////////////////////////////////////////////// + //////////////////////reading tree topology://////////////////////////////// + + //looking for a node + n_t = XML_Search_Node_Name("topology", YES, n_r); + + //setting tree: + /* tree = (t_tree *)mCalloc(1,sizeof(t_tree)); */ + n_cur = XML_Search_Node_Name("instance", YES, n_t); + if(n_cur != NULL) + { + if(XML_Search_Attribute(n_cur, "user.tree") != NULL) + { + strcpy(io -> out_tree_file, XML_Search_Attribute(n_cur, "user.tree") -> value); + io -> fp_out_tree = Openfile(io -> out_tree_file, 1); + io -> tree = Read_Tree_File_Phylip(io -> fp_in_tree); + } + else + { + PhyML_Printf("\n== No input tree was not found. \n"); + PhyML_Printf("\n== Please specify either a tree file name or enter the whole tree directly in the XML file (in Newick format). \n"); + Exit("\n"); + } + } + else io -> tree = Read_Tree(&n_t -> value); + io -> n_otu = io -> tree -> n_otu; + tree = io -> tree; + + //setting initial values to n_calib: + For(i, 2 * tree -> n_otu - 2) + { + tree -> a_nodes[i] -> n_calib = 0; + //PhyML_Printf("\n. '%d' \n", tree -> a_nodes[i] -> n_calib); + } + + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + //memory for nodes: + a_nodes = (t_node **)mCalloc(2 * io -> n_otu - 1,sizeof(t_node *)); + For(i, 2 * io -> n_otu - 2) a_nodes[i] = (t_node *)mCalloc(1,sizeof(t_node)); + + //setting a model: + tree -> rates = RATES_Make_Rate_Struct(io -> n_otu); + RATES_Init_Rate_Struct(tree -> rates, io -> rates, tree -> n_otu); + + //reading seed: + if(XML_Search_Attribute(n_r, "seed")) io -> r_seed = String_To_Dbl(XML_Search_Attribute(n_r, "seed") -> value); + + //TO DO: check that the tree has a root + Update_Ancestors(io -> tree -> n_root, io -> tree -> n_root -> v[2], io -> tree); + Update_Ancestors(io -> tree -> n_root, io -> tree -> n_root -> v[1], io -> tree); + + + //////////////////////////////////////////////////////////////////////////// + //////////////////////memory allocation for temp parameters///////////////// + + //memory for monitor flag: + io -> mcmc -> monitor = (int *)mCalloc(2 * io -> n_otu - 1,sizeof(int)); + + + //memory for sequences: + n_cur = XML_Search_Node_Name("alignment", YES, n_r); + + data = (align **)mCalloc(io -> n_otu,sizeof(align *)); + For(i, io -> n_otu) + { + data[i] = (align *)mCalloc(1,sizeof(align)); + data[i] -> name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + if(n_cur -> child -> value != NULL) data[i] -> state = (char *)mCalloc(strlen(n_cur -> child -> value) + 1,sizeof(char)); + else data[i] -> state = (char *)mCalloc(T_MAX_SEQ,sizeof(char)); + } + io -> data = data; + //tree -> data = data; + + + //memory for clade: + clade_name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + //memory for list of clades to be monitored + mon_list = (char **)mCalloc(T_MAX_FILE,sizeof(char *)); + For(i, T_MAX_FILE) + { + mon_list[i] = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + } + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + //reading monitor node: + i = 0; + n_m = XML_Search_Node_Name("monitor", YES, n_r); + if(n_m != NULL) + { + do + { + strcpy(mon_list[i], n_m -> child -> attr -> value); + i++; + if(n_m -> child) n_m -> child = n_m -> child -> next; + else break; + } + while(n_m -> child); + n_mon = i; + } + else + { + n_mon = 0; + PhyML_Printf("\n. There is no clade to be monitored. \n"); + } + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + //chekcing for calibration node (upper or lower bound) to exist: + n_cur = XML_Search_Node_Name("calibration", YES, n_r); + + if(n_cur == NULL) + { + PhyML_Printf("\n== There is no calibration information provided. \n"); + PhyML_Printf("\n== Please check your data. \n"); + Exit("\n"); + } + else + { + if(XML_Search_Node_Name("upper", NO, n_cur -> child) == NULL && XML_Search_Node_Name("lower", NO, n_cur -> child) == NULL) + { + PhyML_Printf("\n== There is no calibration information provided. \n"); + PhyML_Printf("\n== Please check your data. \n"); + Exit("\n"); + } + } + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + + n_r = n_r -> child; + tree -> rates -> tot_num_cal = 0; + do + { + if(!strcmp(n_r -> name, "alignment"))//looking for a node . + { + if(!n_r -> attr -> value) + { + PhyML_Printf("\n== Sequence type (nt / aa) must be provided. \n"); + PhyML_Printf("\n== Please, include this information as an attribute of component <%s>. \n", n_r -> name); + Exit("\n"); + } + char *s; + s = To_Upper_String(n_r -> attr -> value); + /* if(!strcmp(To_Upper_String(n_r -> attr -> value), "NT")) */ + if(!strcmp(s, "NT")) + { + io -> datatype = 0; + io -> mod -> ns = 4; + } + /* if(!strcmp(To_Upper_String(n_r -> attr -> value), "AA")) */ + if(!strcmp(s, "AA")) + { + io -> datatype = 1; + io -> mod -> ns = 20; + } + free(s); + n_cur = XML_Search_Node_Name("instance", YES, n_r); + if(n_cur != NULL) + { + if(XML_Search_Attribute(n_cur, "user.alignment") != NULL) + { + strcpy(io -> in_align_file, XML_Search_Attribute(n_cur, "user.alignment") -> value); + io -> fp_in_align = Openfile(io -> in_align_file, 1); + Detect_Align_File_Format(io); + io -> data = Get_Seq(io); + } + } + else + { + char *s; + i = 0; + s = To_Upper_String(n_r -> child -> value); + do + { + strcpy(io -> in_align_file, "invitee"); + strcpy(io -> data[i] -> name, n_r -> child -> attr -> value); + /* strcpy(io -> data[i] -> state, To_Upper_String(n_r -> child -> value)); */ + strcpy(io -> data[i] -> state, s); + i++; + if(n_r -> child -> next) n_r -> child = n_r -> child -> next; + else break; + } + while(n_r -> child); + n_taxa = i; + free(s); + } + + //checking if a sequences of the same lengths: + + i = 1; + For(i, n_taxa) if(strlen(io -> data[0] -> state) != strlen(io -> data[i] -> state)) + { + PhyML_Printf("\n== All the sequences should be of the same length. Please check your data...\n"); + Exit("\n"); + break; + } + + //checking sequence names: + i = 0; + For(i, n_taxa) Check_Sequence_Name(io -> data[i] -> name); + + //check if a number of tips is equal to a number of taxa: + if(n_taxa != io -> n_otu) + { + PhyML_Printf("\n== The number of taxa is not the same as a number of tips. Check your data...\n"); + Exit("\n"); + } + + //deleting '-', etc. from sequences: + io -> data[0] -> len = strlen(io -> data[0] -> state); + Post_Process_Data(io); + n_r = n_r -> next; + } + else if(!strcmp(n_r -> name, "calibration"))//looking for a node . + { + tree -> rates -> tot_num_cal++; + if (tree -> rates -> calib == NULL) tree -> rates -> calib = Make_Calib(tree -> n_otu); + if(last_calib) + { + last_calib -> next = tree -> rates -> calib; + tree -> rates -> calib -> prev = last_calib; + } + last_calib = tree -> rates -> calib; + + low = -BIG; + up = BIG; + n_cur = XML_Search_Node_Name("lower", YES, n_r); + if(n_cur != NULL) low = String_To_Dbl(n_cur -> value); + n_cur = XML_Search_Node_Name("upper", YES, n_r); + if(n_cur != NULL) up = String_To_Dbl(n_cur -> value); + do + { + if(!strcmp("appliesto", n_r -> child -> name)) + { + //case of internal node: + strcpy(clade_name, n_r -> child -> attr -> value);//reached clade names n_r -> child -> attr -> value + if(!strcmp("root", clade_name)) + { + node_num = io -> tree -> n_root -> num; + } + else if(strcmp("NO_CLADE", clade_name) && strcmp("root", clade_name)) + { + xml_node *n_clade, *nd2; + nd2 = n_r -> parent; + n_clade = XML_Search_Node_Generic("clade", "id", clade_name, YES, nd2); + if(n_clade) //found clade with a given name + { + i = 0; + xml_node *nd; + nd = n_clade -> child; + clade = XML_Read_Clade(nd, tree); + clade_size = XML_Number_Of_Taxa_In_Clade(nd); + node_num = Find_Clade(clade, clade_size, io -> tree); + } + else + { + PhyML_Printf("\n== The calibration information for clade [%s] was not found.", clade_name); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + if(strcmp("NO_CLADE", clade_name)) + { + For(j, n_mon) + { + if(!strcmp(clade_name, mon_list[j])) io -> mcmc -> monitor[node_num] = YES; + } + } + + if(strcmp("NO_CLADE", clade_name)) + { + tree -> rates -> calib -> proba[node_num] = String_To_Dbl(n_r -> child -> attr -> next -> value); + + if(!n_r -> child -> attr -> next && n_r -> child -> next == NULL) tree -> rates -> calib -> proba[node_num] = 1.; + if(!n_r -> child -> attr -> next && n_r -> child -> next) + { + PhyML_Printf("\n== You either need to provide information about the probability with which calibration "); + PhyML_Printf("\n== applies to a node or you need to apply calibration only to one node."); + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + tree -> rates -> calib -> all_applies_to[tree -> rates -> calib -> n_all_applies_to] -> num = node_num; + } + else tree -> rates -> calib -> proba[2 * tree -> n_otu - 1] = String_To_Dbl(n_r -> child -> attr -> next -> value); + tree -> rates -> calib -> n_all_applies_to++; + tree -> rates -> calib -> lower = low; + tree -> rates -> calib -> upper = up; + PhyML_Printf("\n. Lower bound: %f.", low); + PhyML_Printf("\n. Upper bound: %f.", up); + + ///////////////////////////////////////////////////////////////////////////////////////////////////// + PhyML_Printf("\n. ......................................................................."); + PhyML_Printf("\n"); + if(strcmp(clade_name, "NO_CLADE")) PhyML_Printf("\n. Clade name: [%s]", clade_name); + else + { + PhyML_Printf("\n. Calibration with:"); + PhyML_Printf("\n. Lower bound set to: %15f time units.", low); + PhyML_Printf("\n. Upper bound set to: %15f time units.", up); + PhyML_Printf("\n. does not apply to any node with probability [%f]", String_To_Dbl(n_r -> child -> attr -> next -> value)); + PhyML_Printf("\n. ......................................................................."); + } + + if(strcmp(clade_name, "root") && strcmp(clade_name, "NO_CLADE")) + { + For(i, clade_size) PhyML_Printf("\n. Taxon name: [%s]", clade[i]); + } + if(strcmp(clade_name, "NO_CLADE")) + { + PhyML_Printf("\n. Node number to which calibration applies to is [%d] with probability [%f]", node_num, String_To_Dbl(n_r -> child -> attr -> next -> value)); + PhyML_Printf("\n. Lower bound set to: %15f time units.", low); + PhyML_Printf("\n. Upper bound set to: %15f time units.", up); + PhyML_Printf("\n. ......................................................................."); + } + ///////////////////////////////////////////////////////////////////////////////////////////////////// + if(n_r -> child -> next) n_r -> child = n_r -> child -> next; + else break; + } + else if(n_r -> child -> next) n_r -> child = n_r -> child -> next; + else break; + } + while(n_r -> child); + + tree -> rates -> calib = tree -> rates -> calib -> next; + n_r = n_r -> next; + } + else if(!strcmp(n_r -> name, "ratematrices"))//initializing rate matrix: + { + if(n_r -> child) + { + Make_Ratematrice_From_XML_Node(n_r -> child, io, mod); + n_r = n_r -> next; + } + else n_r = n_r -> next; + } + else if(!strcmp(n_r -> name, "equfreqs"))//initializing frequencies: + { + if(n_r -> child) + { + Make_Efrq_From_XML_Node(n_r -> child , io, mod); + n_r = n_r -> next; + } + else n_r = n_r -> next; + } + else if(!strcmp(n_r -> name, "siterates"))//initializing site rates: + { + if(n_r -> child) + { + Make_RAS_From_XML_Node(n_r, io -> mod); + n_r = n_r -> next; + } + else n_r = n_r -> next; + } + + else if (n_r -> next) n_r = n_r -> next; + else break; + } + while(1); + + tree -> rates -> calib = last_calib; + while(tree -> rates -> calib -> prev) tree -> rates -> calib = tree -> rates -> calib -> prev; + //////////////////////////////////////////////////////////////////////////////////////////////// + //Check for the sum of probabilities for one calibration add up to one + do + { + phydbl p = 0.0; + for(i = tree -> n_otu; i < 2 * tree -> n_otu; i++) + { + p = p + tree -> rates -> calib -> proba[i]; + /* PhyML_Printf("\n. # applies to %d \n", tree -> rates -> calib -> n_all_applies_to); */ + /* PhyML_Printf("\n. %f \n", tree -> rates -> calib -> proba[i]); */ + } + if(!Are_Equal(p, 1.0, 1.E-10)) + { + PhyML_Printf("\n. ......................................................................."); + PhyML_Printf("\n. WARNING! The sum of the probabilities for the calibration with:"); + PhyML_Printf("\n. Lower bound set to: %15f time units.", tree -> rates -> calib -> lower); + PhyML_Printf("\n. Upper bound set to: %15f time units.", tree -> rates -> calib -> upper); + PhyML_Printf("\n. is not equal to 1."); + PhyML_Printf("\n. The probability that this calibration does not apply to any node is set to [%f].", 1.0 - p); + PhyML_Printf("\n. ......................................................................."); + tree -> rates -> calib -> proba[2 * tree -> n_otu - 1] = 1.0 - p; + tree -> rates -> calib -> n_all_applies_to++; + /* PhyML_Printf("\n==You need to provide proper probabilities for the calibration. \n"); */ + /* PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); */ + /* Exit("\n"); */ + } + if(tree -> rates -> calib -> next) tree -> rates -> calib = tree -> rates -> calib -> next; + else break; + + } + while(tree -> rates -> calib); + while(tree -> rates -> calib -> prev) tree -> rates -> calib = tree -> rates -> calib -> prev; + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //clear memory: + free(clade_name); + For(i, tree -> n_otu) + { + free(clade[i]); + } + free(clade); + For(i, T_MAX_FILE) + { + free(mon_list[i]); + } + free(mon_list); + /* do */ + /* { */ + /* printf("\n %f %f \n", tree -> rates -> calib -> lower, tree -> rates -> calib -> upper); */ + /* printf("\n numb applies to: %d \n", tree -> rates -> calib -> n_all_applies_to); */ + /* For(i, tree -> rates -> calib -> n_all_applies_to) printf("\n Node number %d \n", tree -> rates -> calib -> all_applies_to[i] -> num); */ + /* if(tree -> rates -> calib -> next) tree -> rates -> calib = tree -> rates -> calib -> next; */ + /* else break; */ + + /* } */ + /* while(tree -> rates -> calib); */ + /* while(tree -> rates -> calib -> prev) tree -> rates -> calib = tree -> rates -> calib -> prev; */ + + /* Exit("\n"); */ + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //START analysis: + r_seed = (io -> r_seed < 0)?(time(NULL)):(io -> r_seed); + srand(r_seed); + rand(); + PhyML_Printf("\n. Seed: %d\n", r_seed); + PhyML_Printf("\n. Pid: %d\n",getpid()); + PhyML_Printf("\n. Compressing sequences...\n"); + data = io -> data; + data[0] -> len = strlen(data[0] -> state); + //////////////////////////////////////////////////////////////////////////// + //memory for compressed sequences: + cdata = (calign *)mCalloc(1,sizeof(calign)); + c_seq = (align **)mCalloc(io -> n_otu,sizeof(align *)); + For(i, io -> n_otu) + { + c_seq[i] = (align *)mCalloc(1,sizeof(align)); + c_seq[i] -> name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + c_seq[i] -> state = (char *)mCalloc(data[0] -> len + 1,sizeof(char)); + } + cdata -> c_seq = c_seq; + //////////////////////////////////////////////////////////////////////////// + cdata = Compact_Data(data, io); + Free_Seq(io -> data, cdata -> n_otu); + io -> mod -> io = io; + Check_Ambiguities(cdata, io -> mod -> io -> datatype, io -> state_len); + Make_Model_Complete(mod); + Init_Model(cdata, mod, io); + if(io -> mod -> use_m4mod) M4_Init_Model(mod -> m4mod, cdata, mod); + time(&(t_beg)); + + RATES_Fill_Lca_Table(tree); + + tree -> mod = mod; + tree -> io = io; + tree -> data = cdata; + tree -> n_pattern = tree -> data -> crunch_len / tree -> io -> state_len; + + Set_Both_Sides(YES, tree); + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); + Make_Spr(tree); + + + + //calculate the probabilities of each combination of calibrations: + TIMES_Calib_Partial_Proba(tree); + int cal_numb = 0; + do + { + if(!Are_Equal(tree -> rates -> times_partial_proba[cal_numb], 0.0, 1.E-10)) break; + else cal_numb += 1; + } + while(1); + PhyML_Printf("\n. Calibration number chosen %d.\n", cal_numb); + + + Set_Current_Calibration(cal_numb, tree); + tree -> rates -> numb_calib_chosen[cal_numb]++; + + + int tot_num_comb; + tot_num_comb = Number_Of_Comb(tree -> rates -> calib); + PhyML_Printf("\n. The number of calibration combinations that is going to be considered is %d.\n", tot_num_comb); + /* For(i, tot_num_comb) Set_Current_Calibration(i, tree); */ + /* Exit("\n"); */ + + //set initial value for Hastings ratio for conditional jump: + /* tree -> rates -> c_lnL_Hastings_ratio = 0.0; */ + + TIMES_Set_All_Node_Priors(tree); + + tree -> rates -> cur_comb_numb = cal_numb; + tree -> rates -> log_K_cur = K_Constant_Prior_Times_Log(tree); + + TIMES_Get_Number_Of_Time_Slices(tree); + TIMES_Label_Edges_With_Calibration_Intervals(tree); + + + tree -> write_br_lens = NO; + + PhyML_Printf("\n. Input tree with calibration information ('almost' compatible with MCMCtree).\n"); + + char *t; + t = Write_Tree(tree, YES); + PhyML_Printf("\n. %s \n", t); + free(t); + + tree -> write_br_lens = YES; + + + // Work with log of branch lengths? + if(tree -> mod -> log_l == YES) Log_Br_Len(tree); + + if(io -> mcmc -> use_data == YES) + { + // Force the exact likelihood score + user_lk_approx = tree -> io -> lk_approx; + tree -> io -> lk_approx = EXACT; + + /* MLE for branch lengths */ + /* printf("\n. %s",Write_Tree(tree,NO)); */ + /* printf("\n. alpha %f",tree->mod->ras->alpha->v); */ + /* printf("\n. %f %f %f %f",tree->mod->e_frq->pi->v[0],tree->mod->e_frq->pi->v[1],tree->mod->e_frq->pi->v[2],tree->mod->e_frq->pi->v[3]); */ + /* Lk(NULL,tree); */ + /* printf("\n. %f",tree->c_lnL); */ + /* Exit("\n"); */ + + Round_Optimize(tree, tree -> data, ROUND_MAX); + // Set vector of mean branch lengths for the Normal approximation of the likelihood + RATES_Set_Mean_L(tree); + + // Estimate the matrix of covariance for the Normal approximation of the likelihood + PhyML_Printf("\n"); + PhyML_Printf("\n. Computing Hessian..."); + tree -> rates -> bl_from_rt = 0; + Free(tree -> rates -> cov_l); + tree -> rates -> cov_l = Hessian_Seo(tree); + + // tree->rates->cov_l = Hessian_Log(tree); + For(i, (2 * tree -> n_otu - 3) * (2 * tree -> n_otu - 3)) tree -> rates -> cov_l[i] *= -1.0; + if(!Iter_Matinv(tree -> rates -> cov_l, 2 * tree -> n_otu - 3, 2 * tree -> n_otu - 3, YES)) Exit("\n"); + tree -> rates -> covdet = Matrix_Det(tree -> rates -> cov_l, 2 * tree -> n_otu - 3, YES); + For(i,(2 * tree -> n_otu - 3) * (2 * tree -> n_otu - 3)) tree -> rates -> invcov[i] = tree -> rates -> cov_l[i]; + if(!Iter_Matinv(tree -> rates -> invcov, 2 * tree -> n_otu - 3, 2 * tree -> n_otu - 3, YES)) Exit("\n"); + tree -> rates -> grad_l = Gradient(tree); + + // Pre-calculation of conditional variances to speed up calculations + RATES_Bl_To_Ml(tree); + RATES_Get_Conditional_Variances(tree); + RATES_Get_All_Reg_Coeff(tree); + RATES_Get_Trip_Conditional_Variances(tree); + RATES_Get_All_Trip_Reg_Coeff(tree); + + Lk(NULL, tree); + PhyML_Printf("\n"); + PhyML_Printf("\n. p(data|model) [exact ] ~ %.2f",tree -> c_lnL); + tree -> io -> lk_approx = NORMAL; + For(i,2 * tree -> n_otu - 3) tree -> rates -> u_cur_l[i] = tree -> rates -> mean_l[i] ; + tree -> c_lnL = Lk(NULL,tree); + + PhyML_Printf("\n. p(data|model) [approx] ~ %.2f",tree -> c_lnL); + + tree -> io -> lk_approx = user_lk_approx; + + } + + + tree -> rates -> model = io -> rates -> model; + + PhyML_Printf("\n. Selected model '%s' \n", RATES_Get_Model_Name(io -> rates -> model)); + + if(tree -> rates -> model == GUINDON) tree -> mod -> gamma_mgf_bl = YES; + + tree -> rates -> bl_from_rt = YES; + + if(tree -> io -> cstr_tree) Find_Surviving_Edges_In_Small_Tree(tree, tree -> io -> cstr_tree); + time(&t_beg); + + tree -> mcmc = MCMC_Make_MCMC_Struct(); + + MCMC_Copy_MCMC_Struct(tree -> io -> mcmc, tree -> mcmc, "phytime"); + + tree -> mod -> m4mod = m4mod; + + MCMC_Complete_MCMC(tree -> mcmc, tree); + + tree -> mcmc -> is_burnin = NO; + + MCMC(tree); + PhyML_Printf("\n"); + for(i=0;i<6;i++) printf(" %d ", tree -> rates -> numb_calib_chosen[i]); + PhyML_Printf("\n"); + + MCMC_Close_MCMC(tree -> mcmc); + MCMC_Free_MCMC(tree -> mcmc); + PhyML_Printf("\n"); + + Free_Calib(tree -> rates -> calib); + Add_Root(tree->a_edges[0],tree); + Free_Tree_Pars(tree); + Free_Tree_Lk(tree); + Free_Tree(tree); + Free_Calign(cdata); + Free_Model(mod); + if(io -> fp_in_align) fclose(io -> fp_in_align); + if(io -> fp_in_tree) fclose(io -> fp_in_tree); + if(io -> fp_out_lk) fclose(io -> fp_out_lk); + if(io -> fp_out_tree) fclose(io -> fp_out_tree); + if(io -> fp_out_trees) fclose(io -> fp_out_trees); + if(io -> fp_out_stats) fclose(io -> fp_out_stats); + fclose(f); + Free(most_likely_tree); + Free_Input(io); + time(&t_end); + Print_Time_Info(t_beg,t_end); + +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Calculate the prior probability for node times taking into account the +//probailitis with which each calibration applies to the particular node. +phydbl TIMES_Calib_Cond_Prob(t_tree *tree) +{ + + phydbl times_lk, *Yule_val, *times_partial_proba, times_tot_proba, c, constant, ln_t; + int i, tot_num_comb; + t_cal *calib; + + + times_tot_proba = 0.0; + calib = tree -> rates -> calib; + times_partial_proba = tree -> rates -> times_partial_proba; + + tot_num_comb = Number_Of_Comb(calib); + + + Yule_val = (phydbl *)mCalloc(tot_num_comb, sizeof(phydbl)); + For(i, tot_num_comb) + { + + Set_Current_Calibration(i, tree); + + int result; + result = TRUE; + TIMES_Set_All_Node_Priors_S(&result, tree); + + times_lk = TIMES_Lk_Yule_Order_Root_Cond(tree); + + constant = 0.0; + if(tot_num_comb > 1 && times_lk > -INFINITY && result != FALSE && tree->rates->update_time_norm_const == YES) + + Yule_val[i] = constant + times_lk; + + while(calib -> prev) calib = calib -> prev; + } + + /* Exit("\n"); */ + c = .0; + times_tot_proba = 0.0; + For(i, tot_num_comb) + { + times_tot_proba += times_partial_proba[i] * exp(Yule_val[i] + c); + } + + ln_t = -c + log(times_tot_proba); + + free(Yule_val); + + return(ln_t); +} + + + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//Function calculates the normalizing constant K of the joint distribution Yule_Order. +//Use the fact that density Yule_Order can be used streight forward only in case of the complete +//overlap of the calibration intervals for all of the nodes or in case of no overlap. +phydbl K_Constant_Prior_Times_Log(t_tree *tree) +{ + int i, j, k, f, n_otu, *indic, *n_slice, *slice_numbers; + phydbl buf, chop_bound, *t_prior_min, *t_prior_max, *t_slice, *t_slice_min, *t_slice_max, *g_i_node; + + + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + n_otu = tree -> n_otu; + + t_slice = (phydbl *)mCalloc(2 * (n_otu - 1), sizeof(phydbl)); //the vector of the union of lower and upper bounds, lined up in incresing order. + t_slice_min = (phydbl *)mCalloc(2 * n_otu - 3, sizeof(phydbl)); //vector of the lower bounds of the sliced intervals. + t_slice_max = (phydbl *)mCalloc(2 * n_otu - 3, sizeof(phydbl)); //vector of the upper bounds of the sliced intervals. + indic = (int *)mCalloc((n_otu - 1) * (2 * n_otu - 3), sizeof(int)); //vector of the indicators, columns - node numbers (i + n_otu), rows - the number of the sliced interval. + slice_numbers = (int *)mCalloc((n_otu - 1) * (2 * n_otu - 3), sizeof(int )); //vecor of the slice intervals numbers, columns node numbers (i + n_otu), rows - the number of the sliced interval. + n_slice = (int *)mCalloc(n_otu - 1, sizeof(int)); //vector of the numbers of sliced intervals that apply to one node with number (i + n_otu). + g_i_node = (phydbl *)mCalloc((n_otu - 1) * (2 * n_otu - 3), sizeof(phydbl)); //vector of the values of the function g evaluated for each node. + + i = 0; + /* K = 0; */ + j = n_otu; + //////////////////////////////////////////////////////////////////////////// + //Put prior bounds in one vector t_slice. Excluding tips. + For(i, n_otu - 1) + { + t_slice[i] = t_prior_min[j]; + j++; + } + + j = n_otu; + for(i = n_otu - 1; i < 2 * n_otu - 3; i++) + { + t_slice[i] = t_prior_max[j]; + j++; + } + if(tree -> rates -> nd_t[tree -> n_root -> num] > t_prior_min[tree -> n_root -> num]) chop_bound = MIN(tree -> rates -> nd_t[tree -> n_root -> num], t_prior_max[tree -> n_root -> num]); + else chop_bound = t_prior_min[tree -> n_root -> num]; + t_slice[2 * n_otu - 3] = chop_bound; + + //////////////////////////////////////////////////////////////////////////// + //Get slices in increasing order. Excluding tips. + do + { + f = NO; + For(j, 2 * n_otu - 3) + { + if(t_slice[j] > t_slice[j + 1]) + { + buf = t_slice[j]; + t_slice[j] = t_slice[j + 1]; + t_slice[j + 1] = buf; + f = YES; + } + } + } + while(f); + + for(j = 1; j < 2 * n_otu - 2; j++) t_slice[j] = MAX(chop_bound, t_slice[j]); + //////////////////////////////////////////////////////////////////////////// + //Get the intervals with respect to slices. Total number of t_slice_min(max) - 2 * n_otu - 3. Excluding tips. + i = 0; + For(j, 2 * n_otu - 3) + { + t_slice_min[j] = t_slice[i]; + t_slice_max[j] = t_slice[i + 1]; + i++; + } + + //////////////////////////////////////////////////////////////////////////// + //Getting indicators for the node number [i + n_otu] to have slice. i = i + n_otu is the node number on the tree and j is the slice number, total + //number of intervals is 2 * n_otu - 3. Excluding tips. + For(i, n_otu - 1) + { + For(j, 2 * n_otu - 3) + { + + if(Are_Equal(t_prior_min[i + n_otu], t_slice_min[j], 1.E-10) && t_prior_max[i + n_otu] > t_slice_max[j] && t_prior_min[i + n_otu] < t_slice_max[j] && !Are_Equal(t_slice_max[j], t_slice_min[j], 1.E-10)) indic[i * (2 * n_otu - 3) + j] = 1; + else if(Are_Equal(t_prior_max[i + n_otu], t_slice_max[j], 1.E-10) && t_prior_min[i + n_otu] < t_slice_min[j] && t_prior_max[i + n_otu] > t_slice_min[j] && !Are_Equal(t_slice_max[j], t_slice_min[j], 1.E-10)) indic[i * (2 * n_otu - 3) + j] = 1; + else if(t_prior_min[i + n_otu] < t_slice_min[j] && t_prior_max[i + n_otu] > t_slice_max[j] && !Are_Equal(t_slice_max[j], t_slice_min[j], 1.E-10)) indic[i * (2 * n_otu - 3) + j] = 1; + else if(Are_Equal(t_prior_min[i + n_otu], t_slice_min[j], 1.E-10) && Are_Equal(t_prior_max[i + n_otu], t_slice_max[j], 1.E-10)) indic[i * (2 * n_otu - 3) + j] = 1; + } + } + + + For(i, n_otu - 2) + { + indic[i * (2 * n_otu - 3)] = 0; + } + + for(j = 1; j < 2 * n_otu - 3; j++) + { + indic[(n_otu - 2) * (2 * n_otu - 3) + j] = 0; + } + + /* printf("\n"); */ + /* printf(" ", j); */ + /* For(j, 2 * n_otu - 3) printf(". '%d' ", j); */ + /* printf("\n"); */ + /* For(i, n_otu - 1) */ + /* { */ + /* printf(" ['%d'] ", i + n_otu); */ + /* For(j, 2 * n_otu - 3) */ + /* { */ + /* printf(". '%d' ", indic[i * (2 * n_otu - 3) + j]); */ + /* } */ + /* printf("\n"); */ + /* } */ + + + + //////////////////////////////////////////////////////////////////////////// + //Running through all of the combinations of slices + int *cur_slices, *cur_slices_shr, *cur_slices_cpy, *slices_start_node, shr_num_slices; + phydbl *t_cur_slice_min, *t_cur_slice_max; + phydbl tot_num_comb; + phydbl log_g_i, lmbd; + + lmbd = tree -> rates -> birth_rate; + + tot_num_comb = 1; + + t_cur_slice_min = (phydbl *)mCalloc(n_otu - 1, sizeof(phydbl)); + t_cur_slice_max = (phydbl *)mCalloc(n_otu - 1, sizeof(phydbl)); + cur_slices = (int *)mCalloc(n_otu - 1, sizeof(int)); //the vector of the current slices with repetition. + cur_slices_cpy = (int *)mCalloc(n_otu - 1, sizeof(int)); + slices_start_node = (int *)mCalloc(n_otu - 1, sizeof(int)); + cur_slices_shr = (int *)mCalloc(n_otu - 1, sizeof(int)); //the vector of the current slices without repetition. + + + + //////////////////////////////////////////////////////////////////////////// + //Get the number of slices that can be applied for each node and the vectors of slice numbers for each node. + For(i, n_otu - 1) + { + k = 0; + For(j, 2 * n_otu - 3) + { + if(indic[i * (2 * n_otu - 3) + j] == 1) + { + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + g_i_node[i * (2 * n_otu - 3) + j] = (exp(lmbd * t_slice_max[j]) - exp(lmbd * t_slice_min[j])) / + (exp(lmbd * t_prior_max[i + n_otu]) - exp(lmbd * t_prior_min[i + n_otu])); + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + slice_numbers[i * (2 * n_otu - 3) + k] = j; + n_slice[i]++; + k++; + } + } + } + /* printf("\n"); */ + /* For(i, n_otu - 1) */ + /* { */ + /* printf(" ['%d'] ", i + n_otu); */ + /* For(j, 2 * n_otu - 3) */ + /* { */ + /* printf(". '%f' ", g_i_node[i * (2 * n_otu - 3) + j]); */ + /* } */ + /* printf("\n"); */ + /* } */ + + /* printf("\n"); */ + /* For(i, n_otu - 1) */ + /* { */ + /* printf(" ['%d'] ", i + n_otu); */ + /* For(j, n_slice[i]) */ + /* { */ + /* printf(". '%d' ", slice_numbers[i * (2 * n_otu - 3) + j]); */ + /* } */ + /* printf("\n"); */ + /* } */ + For(i, n_otu - 1) + { + tot_num_comb = tot_num_comb * n_slice[i]; + } + + + int r, numb_unsuc, max_size, comb_numb, *combinations, *max_combination, numb_approx; /* **combinations; */ + phydbl K_total; + phydbl *t_slice_min_f, *t_slice_max_f, *K_val_approx; + int *root_nodes, *dif; + phydbl K_total_cur, max_K_val, scl_const; + + max_size = 1000000; + combinations = (int *)mCalloc(max_size*(n_otu-1), sizeof(int)); + max_combination = (int *)mCalloc((n_otu-1), sizeof(int)); + t_slice_min_f = (phydbl *)mCalloc(n_otu - 1, sizeof(phydbl)); + t_slice_max_f = (phydbl *)mCalloc(n_otu - 1, sizeof(phydbl)); + K_val_approx = (phydbl *)mCalloc(max_size, sizeof(phydbl)); + root_nodes = (int *)mCalloc(n_otu - 1, sizeof(int)); + dif = (int *)mCalloc(n_otu - 1, sizeof(int)); + numb_approx = 0; + max_K_val = 0; + scl_const = 0.0; + /* lmbd = 4.0; */ + numb_unsuc = 0; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////CALCULATING THE MAXIMUM VALUE OF m_i * g_i FOR ONE COMBINATION OF SLICES://////////////////////////////////////////////////////////////// + + comb_numb = 0; + K_total = 0.0; + + do + { + /* printf("\n ____________________________________________________________________________________________________ \n"); */ + + int x = 0, f = FALSE; + + For(i, n_otu - 1) + { + r = rand()%(n_slice[i]); + t_slice_min_f[i] = t_slice_min[slice_numbers[i * (2 * n_otu - 3) + r]]; + t_slice_max_f[i] = t_slice_max[slice_numbers[i * (2 * n_otu - 3) + r]]; + cur_slices[i] = slice_numbers[i * (2 * n_otu - 3) + r]; + } + + For(i, n_otu - 1) + { + cur_slices_cpy[i] = cur_slices[i]; + slices_start_node[i] = cur_slices[i]; + } + + For(i, n_otu - 1) + { + for(j = i + 1; j < n_otu - 1; j++) + { + if(cur_slices[i] == cur_slices[j]) cur_slices[j] = -1; + } + } + //For(i, n_otu - 1) printf(" Slice number'%d' \n", cur_slices[i]); + + shr_num_slices = 0; + For(i, n_otu -1) + { + if(cur_slices[i] >= 0) + { + cur_slices_shr[shr_num_slices] = cur_slices[i]; + shr_num_slices++; + } + } + + int result_1; + int c = 0; + int num_elem; + + + result_1 = TRUE; + + Check_Time_Slices(tree -> n_root, tree -> n_root -> v[1], &result_1, t_slice_min_f, t_slice_max_f, tree); + Check_Time_Slices(tree -> n_root, tree -> n_root -> v[2], &result_1, t_slice_min_f, t_slice_max_f, tree); + + /* printf("\n. [START] Result '%d' \n", result_1); */ + + + K_total_cur = 0.0; + + if(result_1 != TRUE) K_total_cur = 0.0; + else + { + int n_1, n_2; + + num_elem = 0; + + x = 0; + f = FALSE; + + if(comb_numb > 0) + { + For(i, comb_numb) + { + x = 0; + For(j, n_otu - 1) + { + + dif[j] = combinations[i*(n_otu-1) + j] - cur_slices_cpy[j]; + if(dif[j] == 0) x++; + } + if(x == n_otu - 1) f = TRUE; + } + } + if(!f) + { + For(i, n_otu - 1) combinations[comb_numb*(n_otu - 1) + i] = cur_slices_cpy[i]; + + /* printf("\n"); */ + /* printf(" [1][CUR SLICES PROPOSED] "); */ + /* printf(" [COMB NUMBER] = [%d] --- ", comb_numb); */ + /* For(i, n_otu - 1) printf(". [%d] .", combinations[comb_numb*(n_otu - 1) + i]); */ + /* printf("\n"); */ + + + + For(i, shr_num_slices) + { + Search_Root_Node_In_Slice(tree -> n_root, tree -> n_root -> v[1], root_nodes, &num_elem, t_slice_min[cur_slices_shr[i]], t_slice_max[cur_slices_shr[i]], t_slice_min_f, t_slice_max_f, tree); + Search_Root_Node_In_Slice(tree -> n_root, tree -> n_root -> v[2], root_nodes, &num_elem, t_slice_min[cur_slices_shr[i]], t_slice_max[cur_slices_shr[i]], t_slice_min_f, t_slice_max_f, tree); + } + /* for(i = 0; i < n_otu - 2; i++) printf("\n. [START] Node [%d] Slice_min [%f] Slice_max [%f] \n", i + n_otu, t_slice_min_f[i], t_slice_max_f[i]); */ + For(j, num_elem) + { + n_1 = 0; + n_2 = 0; + Number_Of_Nodes_In_Slice(tree -> a_nodes[root_nodes[j] + n_otu], tree -> a_nodes[root_nodes[j] + n_otu] -> v[1], &n_1, t_slice_min_f, t_slice_max_f, tree); + Number_Of_Nodes_In_Slice(tree -> a_nodes[root_nodes[j] + n_otu], tree -> a_nodes[root_nodes[j] + n_otu] -> v[2], &n_2, t_slice_min_f, t_slice_max_f, tree); + /* printf("\n. n_1 [%d] n_2 [%d]\n", n_1, n_2); */ + K_total_cur = K_total_cur + log(1) - log(n_1 + n_2 + 1) - LnGamma(n_1 + 1) - LnGamma(n_2 + 1); + /* printf("\n. K_total_cur [%f] \n", K_total_cur); */ + /* printf("\n. [START] log(m_i) [%f] \n", log(1) - log(n_1 + n_2 + 1) - LnGamma(n_1 + 1) - LnGamma(n_2 + 1)); */ + } + /* printf("\n. [START] log(m_i) [%f] \n", K_total_cur); */ + /* printf("\n. K_total_cur [%f] \n", K_total_cur); */ + + log_g_i = 0.0; + For(i, n_otu - 2) + log_g_i += log_g_i(lmbd, + t_slice_max_f[i], + t_slice_min_f[i], + t_prior_max[i + n_otu], + MAX(t_prior_min[i + n_otu],tree->rates->nd_t[tree->n_root->num])); + + /* printf("\n. [START] log(g_i) [%f] \n", log_g_i); */ + + K_total_cur = exp(K_total_cur + log_g_i + scl_const); + + if(K_total_cur > max_K_val) + { + For(i, n_otu - 1) max_combination[i] = cur_slices_cpy[i]; + max_K_val = K_total_cur; + } + + K_val_approx[numb_approx] = K_total_cur; + numb_approx++; + /* printf("\n. [APPROX] Approximated constant after start (K_total_cur) = [%f] \n", (K_total_cur)); */ + + /* printf("\n. [START] m_i * g_i [%f] \n", K_total_cur); */ + /* printf("\n. [START] sum(m_i * g_i) = m_i * g_i [%f] \n", K_total_cur); */ + /* printf("\n. K of the tree for starting combination of slices [%f] \n", K_total_cur); */ + comb_numb++; + if(comb_numb > max_size) + { + combinations = (int *)mRealloc(combinations, max_size*(n_otu - 1) + (n_otu - 1),sizeof(char)); + max_size = max_size + 1; + } + c++; + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /* printf("\n. ____________________________________________________________________________________________ \n"); */ + phydbl K_part, K_max; + int m, n, count; + + K_max = K_total_cur; + + + /* printf("\n. K_total [%f] \n", K_total); */ + do + { + r = rand()%(n_otu - 1); + + count = 0; + For(m, r) + { + /* printf("\n. NODE NUMBER ['%d'] \n", m + n_otu); */ + For(n, 2 * n_otu - 3) + { + K_part = 0.0; + if(g_i_node[m * (2 * n_otu - 3) + n] > 0) + { + t_slice_min_f[m] = t_slice_min[n]; + t_slice_max_f[m] = t_slice_max[n]; + cur_slices_cpy[m] = n; + + For(i, n_otu - 1) cur_slices[i] = cur_slices_cpy[i]; + For(i, n_otu - 1) + { + for(j = i + 1; j < n_otu - 1; j++) + { + if(cur_slices[i] == cur_slices[j]) cur_slices[j] = -1; + } + } + + shr_num_slices = 0; + For(i, n_otu -1) + { + if(cur_slices[i] >= 0) + { + cur_slices_shr[shr_num_slices] = cur_slices[i]; + shr_num_slices++; + } + } + + result_1 = TRUE; + + Check_Time_Slices(tree -> n_root, tree -> n_root -> v[1], &result_1, t_slice_min_f, t_slice_max_f, tree); + Check_Time_Slices(tree -> n_root, tree -> n_root -> v[2], &result_1, t_slice_min_f, t_slice_max_f, tree); + + if(result_1 != TRUE) K_part = 0.0; + else + { + int n_1, n_2; + + x = 0; + f = FALSE; + + num_elem = 0; + + if(comb_numb > 0) + { + For(i, comb_numb) + { + x = 0; + For(j, n_otu - 1) + { + + dif[j] = combinations[i*(n_otu-1) + j] - cur_slices_cpy[j]; + if(dif[j] == 0) x++; + } + if(x == n_otu - 1) f = TRUE; + } + } + + + if(!f) + { + For(i, n_otu - 1) combinations[comb_numb*(n_otu-1) + i] = cur_slices_cpy[i]; + /* printf("\n"); */ + /* printf(" [2][CUR SLICES PROPOSED] "); */ + /* printf(" [COMB NUMBER] = [%d] --- ", comb_numb); */ + /* For(i, n_otu - 1) printf(". [%d] .", combinations[comb_numb*(n_otu-1) + i]); */ + /* printf("\n"); */ + + + For(i, shr_num_slices) + { + Search_Root_Node_In_Slice(tree -> n_root, tree -> n_root -> v[1], root_nodes, &num_elem, t_slice_min[cur_slices_shr[i]], t_slice_max[cur_slices_shr[i]], t_slice_min_f, t_slice_max_f, tree); + Search_Root_Node_In_Slice(tree -> n_root, tree -> n_root -> v[2], root_nodes, &num_elem, t_slice_min[cur_slices_shr[i]], t_slice_max[cur_slices_shr[i]], t_slice_min_f, t_slice_max_f, tree); + } + For(j, num_elem) + { + n_1 = 0; + n_2 = 0; + + Number_Of_Nodes_In_Slice(tree -> a_nodes[root_nodes[j] + n_otu], tree -> a_nodes[root_nodes[j] + n_otu] -> v[1], &n_1, t_slice_min_f, t_slice_max_f, tree); + Number_Of_Nodes_In_Slice(tree -> a_nodes[root_nodes[j] + n_otu], tree -> a_nodes[root_nodes[j] + n_otu] -> v[2], &n_2, t_slice_min_f, t_slice_max_f, tree); + /* printf("\n. n_1 [%d] n_2 [%d]\n", n_1, n_2); */ + + K_part = K_part + log(1) - log(n_1 + n_2 + 1) - LnGamma(n_1 + 1) - LnGamma(n_2 + 1); + /* printf("\n. [CONT] log(m_i) [%f] \n", log(1) - log(n_1 + n_2 + 1) - LnGamma(n_1 + 1) - LnGamma(n_2 + 1)); */ + } + /* printf("\n. [CONT] log(m_i) [%f] \n", K_part); */ + /* printf("\n. K_part [%f] \n", K_part); */ + + + + if(K_part > max_K_val) + { + For(i, n_otu - 1) max_combination[i] = cur_slices_cpy[i]; + max_K_val = K_part; + } + + log_g_i = 0.0; + For(i, n_otu - 2) + log_g_i += log_g_i(lmbd, + t_slice_max_f[i], + t_slice_min_f[i], + t_prior_max[i + n_otu], + MAX(t_prior_min[i + n_otu],tree->rates->nd_t[tree->n_root->num])); + + /* printf("\n. [START] log(g_i) [%f] \n", log_g_i); */ + + K_part = exp(K_part + log_g_i + scl_const); + + if(K_part > max_K_val) + { + For(i, n_otu - 1) max_combination[i] = cur_slices_cpy[i]; + max_K_val = K_part; + } + + /* printf("\n. [START] m_i * g_i [%f] \n", K_part); */ + + K_val_approx[numb_approx] = K_part; + numb_approx++; + + K_total_cur = K_total_cur + K_part; + /* printf("\n. [APPROX] Approximated constant after one run (K_part) = [%f] \n", (K_part)); */ + /* printf("\n. K_max [%f] K_part [%f] \n", K_max, K_part); */ + /* printf("\n. [CONT] sum(m_i * g_i) [%f] \n", K_total_cur); */ + if(K_max < K_part) + { + K_max = K_part; + /* For(i, n_otu - 1) slices_start_node[i] = cur_slices_cpy[i]; */ + count++; + } + + comb_numb++; + if(comb_numb > max_size) + { + combinations = (int *)mRealloc(combinations, max_size*(n_otu - 1) + (n_otu - 1),sizeof(char)); + max_size = max_size + 1; + } + c++; + + } + } + } + } + } + + + for(m = r; m < n_otu - 1; m++) + { + For(n, 2 * n_otu - 3) + { + + K_part = 0.0; + if(g_i_node[m * (2 * n_otu - 3) + n] > 0) + { + t_slice_min_f[m] = t_slice_min[n]; + t_slice_max_f[m] = t_slice_max[n]; + cur_slices_cpy[m] = n; + + For(i, n_otu - 1) cur_slices[i] = cur_slices_cpy[i]; + For(i, n_otu - 1) + { + for(j = i + 1; j < n_otu - 1; j++) + { + if(cur_slices[i] == cur_slices[j]) cur_slices[j] = -1; + } + } + + shr_num_slices = 0; + For(i, n_otu -1) + { + if(cur_slices[i] >= 0) + { + cur_slices_shr[shr_num_slices] = cur_slices[i]; + shr_num_slices++; + } + } + + result_1 = TRUE; + + Check_Time_Slices(tree -> n_root, tree -> n_root -> v[1], &result_1, t_slice_min_f, t_slice_max_f, tree); + Check_Time_Slices(tree -> n_root, tree -> n_root -> v[2], &result_1, t_slice_min_f, t_slice_max_f, tree); + + if(result_1 != TRUE) K_part = 0.0; + else + { + int n_1, n_2; + + x = 0; + f = FALSE; + + num_elem = 0; + + if(comb_numb > 0) + { + For(i, comb_numb) + { + x = 0; + For(j, n_otu - 1) + { + + dif[j] = combinations[i*(n_otu-1) + j] - cur_slices_cpy[j]; + /* dif[j] = combinations[i][j] - cur_slices_cpy[j]; */ + if(dif[j] == 0) x++; + /* printf(". [%d] ", dif[j]); */ + } + if(x == n_otu - 1) f = TRUE; + } + } + + + if(!f) + { + For(i, n_otu - 1) combinations[comb_numb*(n_otu-1) + i] = cur_slices_cpy[i]; + /* printf("\n"); */ + /* printf(" [2][CUR SLICES PROPOSED] "); */ + /* printf(" [COMB NUMBER] = [%d] --- ", comb_numb); */ + /* For(i, n_otu - 1) printf(". [%d] .", combinations[comb_numb*(n_otu-1) + i]); */ + /* printf("\n"); */ + + + For(i, shr_num_slices) + { + Search_Root_Node_In_Slice(tree -> n_root, tree -> n_root -> v[1], root_nodes, &num_elem, t_slice_min[cur_slices_shr[i]], t_slice_max[cur_slices_shr[i]], t_slice_min_f, t_slice_max_f, tree); + Search_Root_Node_In_Slice(tree -> n_root, tree -> n_root -> v[2], root_nodes, &num_elem, t_slice_min[cur_slices_shr[i]], t_slice_max[cur_slices_shr[i]], t_slice_min_f, t_slice_max_f, tree); + } + For(j, num_elem) + { + n_1 = 0; + n_2 = 0; + + Number_Of_Nodes_In_Slice(tree -> a_nodes[root_nodes[j] + n_otu], tree -> a_nodes[root_nodes[j] + n_otu] -> v[1], &n_1, t_slice_min_f, t_slice_max_f, tree); + Number_Of_Nodes_In_Slice(tree -> a_nodes[root_nodes[j] + n_otu], tree -> a_nodes[root_nodes[j] + n_otu] -> v[2], &n_2, t_slice_min_f, t_slice_max_f, tree); + /* printf("\n. n_1 [%d] n_2 [%d]\n", n_1, n_2); */ + + K_part = K_part + log(1) - log(n_1 + n_2 + 1) - LnGamma(n_1 + 1) - LnGamma(n_2 + 1); + /* printf("\n. [CONT] log(m_i) [%f] \n", log(1) - log(n_1 + n_2 + 1) - LnGamma(n_1 + 1) - LnGamma(n_2 + 1)); */ + } + /* printf("\n. [CONT] log(m_i) [%f] \n", K_part); */ + /* printf("\n. K_part [%f] \n", K_part); */ + + log_g_i = 0.0; + For(i, n_otu - 2) + log_g_i += log_g_i(lmbd, + t_slice_max_f[i], + t_slice_min_f[i], + t_prior_max[i + n_otu], + MAX(t_prior_min[i + n_otu],tree->rates->nd_t[tree->n_root->num])); + /* printf("\n. [START] log(g_i) [%f] \n", log_g_i); */ + + K_part = exp(K_part + log_g_i + scl_const); + + if(K_part > max_K_val) + { + For(i, n_otu - 1) max_combination[i] = cur_slices_cpy[i]; + max_K_val = K_part; + } + + /* printf("\n. [START] m_i * g_i [%f] \n", K_part); */ + + K_val_approx[numb_approx] = K_part; + numb_approx++; + + K_total_cur = K_total_cur + K_part; + + /* printf("\n. [APPROX] Approximated constant after one run (K_part) = [%f] \n", (K_part)); */ + /* printf("\n. K_max [%f] K_part [%f] \n", K_max, K_part); */ + /* printf("\n. [CONT] sum(m_i * g_i) [%f] \n", K_total_cur); */ + if(K_max < K_part) + { + K_max = K_part; + /* For(i, n_otu - 1) slices_start_node[i] = cur_slices_cpy[i]; */ + count++; + } + + comb_numb++; + if(comb_numb > max_size) + { + combinations = (int *)mRealloc(combinations, max_size*(n_otu - 1) + (n_otu - 1),sizeof(char)); + max_size = max_size + 1; + } + c++; + } + } + } + } + } + if(Are_Equal(count, 0, 1.E-10)) break; + } + while(1); + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + For(m, n_otu - 1) + { + For(i, n_otu - 1) cur_slices_cpy[i] = max_combination[i]; + For(i, n_otu - 1) + { + t_slice_min_f[i] = t_slice_min[cur_slices_cpy[i]]; + t_slice_max_f[i] = t_slice_max[cur_slices_cpy[i]]; + } + For(n, 2 * n_otu - 3) + { + + K_part = 0.0; + if(g_i_node[m * (2 * n_otu - 3) + n] > 0) + { + t_slice_min_f[m] = t_slice_min[n]; + t_slice_max_f[m] = t_slice_max[n]; + cur_slices_cpy[m] = n; + + For(i, n_otu - 1) cur_slices[i] = cur_slices_cpy[i]; + For(i, n_otu - 1) + { + for(j = i + 1; j < n_otu - 1; j++) + { + if(cur_slices[i] == cur_slices[j]) cur_slices[j] = -1; + } + } + + shr_num_slices = 0; + For(i, n_otu -1) + { + if(cur_slices[i] >= 0) + { + cur_slices_shr[shr_num_slices] = cur_slices[i]; + shr_num_slices++; + } + } + + result_1 = TRUE; + + Check_Time_Slices(tree -> n_root, tree -> n_root -> v[1], &result_1, t_slice_min_f, t_slice_max_f, tree); + Check_Time_Slices(tree -> n_root, tree -> n_root -> v[2], &result_1, t_slice_min_f, t_slice_max_f, tree); + + if(result_1 != TRUE) K_part = 0.0; + else + { + int n_1, n_2; + + x = 0; + f = FALSE; + + num_elem = 0; + + if(comb_numb > 0) + { + For(i, comb_numb) + { + x = 0; + For(j, n_otu - 1) + { + + dif[j] = combinations[i*(n_otu-1) + j] - cur_slices_cpy[j]; + /* dif[j] = combinations[i][j] - cur_slices_cpy[j]; */ + if(dif[j] == 0) x++; + /* printf(". [%d] ", dif[j]); */ + } + if(x == n_otu - 1) f = TRUE; + } + } + + + if(!f) + { + For(i, n_otu - 1) combinations[comb_numb*(n_otu-1) + i] = cur_slices_cpy[i]; + /* printf("\n"); */ + /* printf(" [2][CUR SLICES PROPOSED] "); */ + /* printf(" [COMB NUMBER] = [%d] --- ", comb_numb); */ + /* For(i, n_otu - 1) printf(". [%d] .", combinations[comb_numb*(n_otu-1) + i]); */ + /* printf("\n"); */ + + + For(i, shr_num_slices) + { + Search_Root_Node_In_Slice(tree -> n_root, tree -> n_root -> v[1], root_nodes, &num_elem, t_slice_min[cur_slices_shr[i]], t_slice_max[cur_slices_shr[i]], t_slice_min_f, t_slice_max_f, tree); + Search_Root_Node_In_Slice(tree -> n_root, tree -> n_root -> v[2], root_nodes, &num_elem, t_slice_min[cur_slices_shr[i]], t_slice_max[cur_slices_shr[i]], t_slice_min_f, t_slice_max_f, tree); + } + For(j, num_elem) + { + n_1 = 0; + n_2 = 0; + + Number_Of_Nodes_In_Slice(tree -> a_nodes[root_nodes[j] + n_otu], tree -> a_nodes[root_nodes[j] + n_otu] -> v[1], &n_1, t_slice_min_f, t_slice_max_f, tree); + Number_Of_Nodes_In_Slice(tree -> a_nodes[root_nodes[j] + n_otu], tree -> a_nodes[root_nodes[j] + n_otu] -> v[2], &n_2, t_slice_min_f, t_slice_max_f, tree); + /* printf("\n. n_1 [%d] n_2 [%d]\n", n_1, n_2); */ + + K_part = K_part + log(1) - log(n_1 + n_2 + 1) - LnGamma(n_1 + 1) - LnGamma(n_2 + 1); + /* printf("\n. [CONT] log(m_i) [%f] \n", log(1) - log(n_1 + n_2 + 1) - LnGamma(n_1 + 1) - LnGamma(n_2 + 1)); */ + } + /* printf("\n. [CONT] log(m_i) [%f] \n", K_part); */ + /* printf("\n. K_part [%f] \n", K_part); */ + + log_g_i = 0.0; + For(i, n_otu - 2) + log_g_i += log_g_i(lmbd, + t_slice_max_f[i], + t_slice_min_f[i], + t_prior_max[i + n_otu], + MAX(t_prior_min[i + n_otu],tree->rates->nd_t[tree->n_root->num])); + /* printf("\n. [START] log(g_i) [%f] \n", log_g_i); */ + + K_part = exp(K_part + log_g_i + scl_const); + + if(K_part > max_K_val) + { + For(i, n_otu - 1) max_combination[i] = cur_slices_cpy[i]; + max_K_val = K_part; + } + + /* printf("\n. [START] m_i * g_i [%f] \n", K_part); */ + + K_val_approx[numb_approx] = K_part; + numb_approx++; + + K_total_cur = K_total_cur + K_part; + + comb_numb++; + if(comb_numb > max_size) + { + combinations = (int *)mRealloc(combinations, max_size*(n_otu - 1) + (n_otu - 1),sizeof(char)); + max_size = max_size + 1; + } + c++; + } + } + } + } + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + K_total = K_total + K_total_cur; + /* printf("\n. [APPROX TOTAL] Approximated constant (K_total) = [%f] \n", (K_total)); */ + /* printf("\n%G %d", K_total, c); */ + if(Are_Equal(c, 0, 1.E-10)) numb_unsuc++; + else numb_unsuc = 0; + } + while(numb_unsuc < 100); + + /* printf("\n"); */ + /* printf("\n. [APPROX TOTAL] log(K_total) = [%f] \n", log(K_total)); */ + /* printf("\n. [APPROX TOTAL] log(Constant) = scl_const - log(K_total) = [%f] \n", scl_const - log(K_total)); */ + /* printf("\n. [APPROX TOTAL] Approximated constant 1 / (K_total) = [%f] \n", 1 / (K_total)); */ + /* printf("\n ____________________________________________________________________________________________________ \n"); */ + /* printf("\n. [APPROX TOTAL] Numb_approx = [%d] \n", numb_approx); */ + /* printf("\n"); */ + /* } */ + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + free(combinations); + free(max_combination); + free(dif); + + free(t_cur_slice_min); + free(t_cur_slice_max); + free(cur_slices); + free(cur_slices_cpy); + free(slices_start_node); + free(cur_slices_shr); + free(t_slice); + free(t_slice_min); + free(t_slice_max); + free(t_slice_min_f); + free(t_slice_max_f); + free(indic); + free(slice_numbers); + free(root_nodes); + free(n_slice); + free(g_i_node); + free(K_val_approx); + + return(-log(K_total)); +} + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +int Number_Of_Comb_Slices(int m, int num_elem, int *n_slice) +{ + int i, num_comb; + + i = 0; + num_comb = 1; + + for(i = m; i < num_elem; i++) num_comb = num_comb * n_slice[i]; + + return(num_comb); +} + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Check the combination of the time slices to be set correctly. +void Check_Time_Slices(t_node *a, t_node *d, int *result, phydbl *t_cur_slice_min, phydbl *t_cur_slice_max, t_tree *tree) +{ + int n_otu; + + n_otu = tree -> n_otu; + + + d -> anc = a; + if(d -> tax) return; + else + { + if(t_cur_slice_max[d -> num - n_otu] < t_cur_slice_max[a -> num - n_otu]) + { + *result = FALSE; + } + + int i; + for(i=0;i<3;i++) + if((d -> v[i] != d -> anc) && (d -> b[i] != tree -> e_root)) + Check_Time_Slices(d, d -> v[i], result, t_cur_slice_min, t_cur_slice_max, tree); + } +} + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//Getting the number of nodes on both sides from the node d_start, that are in the slice of that node. +void Number_Of_Nodes_In_Slice(t_node *d_start, t_node *d, int *n, phydbl *t_cur_slice_min, phydbl *t_cur_slice_max, t_tree *tree) +{ + int n_otu; + + n_otu = tree -> n_otu; + + + if(d -> tax) return; + else + { + if(Are_Equal(t_cur_slice_max[d_start -> num - n_otu], t_cur_slice_max[d -> num - n_otu], 1.E-10) && Are_Equal(t_cur_slice_min[d_start -> num - n_otu], t_cur_slice_min[d -> num - n_otu], 1.E-10)) + { + (*n)++; + int i; + for(i=0;i<3;i++) + if((d -> v[i] != d -> anc) && (d -> b[i] != tree -> e_root)) + Number_Of_Nodes_In_Slice(d_start, d -> v[i], n, t_cur_slice_min, t_cur_slice_max, tree); + } + } +} + + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//Returnig the root node in the given slice. +void Search_Root_Node_In_Slice(t_node *d_start, t_node *d, int *root_nodes, int *num_elem, phydbl t_slice_min, phydbl t_slice_max, phydbl *t_cur_slice_min, phydbl *t_cur_slice_max, t_tree *tree) +{ + int j, n_otu, f; + j = 0; + f = FALSE; + n_otu = tree -> n_otu; + + if(Are_Equal(t_cur_slice_max[d_start -> num - n_otu], t_slice_max, 1.E-10) && Are_Equal(t_cur_slice_min[d_start -> num - n_otu], t_slice_min, 1.E-10)) + { + For(j, *num_elem) if(d_start -> num - n_otu == (root_nodes[j])) f = TRUE; + if(f != TRUE) + { + (root_nodes[(*num_elem)]) = d_start -> num - n_otu; + (*num_elem)++; + return; + } + + } + else + { + d -> anc = d_start; + if(d -> tax) return; + else + { + if(Are_Equal(t_cur_slice_max[d -> num - n_otu], t_slice_max, 1.E-10) && Are_Equal(t_cur_slice_min[d -> num - n_otu], t_slice_min, 1.E-10)) + { + (root_nodes[*num_elem]) = d -> num - n_otu; + (*num_elem)++; + return; + } + + int i; + for(i=0;i<3;i++) + if((d -> v[i] != d -> anc) && (d -> b[i] != tree -> e_root)) + Search_Root_Node_In_Slice(d, d -> v[i], root_nodes, num_elem, t_slice_min, t_slice_max, t_cur_slice_min, t_cur_slice_max, tree); + } + } +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +int Factorial(int base) +{ + if(base == 0) return(1); + if(base == 1) return(1); + return(base * Factorial(base-1)); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Calculate the vector of the norm.constants for prior on node times. +//The length of the vector is the total number of combinations of calibrations. +phydbl *Norm_Constant_Prior_Times(t_tree *tree) +{ + + phydbl *log_K_val; + int i, tot_num_comb; + t_cal *calib; + + calib = tree -> rates -> calib; + + tot_num_comb = Number_Of_Comb(calib); + + + log_K_val = (phydbl *)mCalloc(tot_num_comb, sizeof(phydbl)); + + For(i, tot_num_comb) + { + + Set_Current_Calibration(i, tree); + + int result = TRUE; + + TIMES_Set_All_Node_Priors_S(&result, tree); + + if(result == TRUE) log_K_val[i] = K_Constant_Prior_Times_Log(tree); + + while(calib -> prev) calib = calib -> prev; + } + return(log_K_val); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Sets a vector of the partial probabilities for each combination of calibrations +void TIMES_Calib_Partial_Proba(t_tree *tree) +{ + + phydbl *times_partial_proba, proba, *t_prior_min, *t_prior_max; + int i, j, k, tot_num_comb; + t_cal *calib; + short int *t_has_prior; + + proba = 0.0; + + times_partial_proba = tree -> rates -> times_partial_proba; + calib = tree -> rates -> calib; + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + t_has_prior = tree -> rates -> t_has_prior; + + tot_num_comb = Number_Of_Comb(calib); + + For(i, tot_num_comb) + { + times_partial_proba[i] = 1.0; + for(j = tree -> n_otu; j < 2 * tree -> n_otu - 1; j++) + { + t_prior_min[j] = -BIG; + t_prior_max[j] = BIG; + t_has_prior[j] = NO; + } + do + { + k = (i % Number_Of_Comb(calib)) / Number_Of_Comb(calib -> next); + if(calib -> all_applies_to[k] -> num) + { + t_prior_min[calib -> all_applies_to[k] -> num] = MAX(t_prior_min[calib -> all_applies_to[k] -> num], calib -> lower); + t_prior_max[calib -> all_applies_to[k] -> num] = MIN(t_prior_max[calib -> all_applies_to[k] -> num], calib -> upper); + t_has_prior[calib -> all_applies_to[k] -> num] = YES; + proba = calib -> proba[calib -> all_applies_to[k] -> num]; + times_partial_proba[i] *= proba; + } + else + { + proba = calib -> proba[2 * tree -> n_otu - 1]; + times_partial_proba[i] *= proba; + + } + + if(calib -> next) calib = calib -> next; + else break; + } + while(calib); + + int result; + + result = TRUE; + + TIMES_Set_All_Node_Priors_S(&result, tree); + + if(result != TRUE) times_partial_proba[i] = 0; /* printf("\n. [4] Partial Proba [%f] \n", times_partial_proba[i]); */ + + while(calib -> prev) calib = calib -> prev; + + } + + phydbl sum_proba; + sum_proba = 0.0; + + For(i, tot_num_comb) sum_proba += times_partial_proba[i]; + if(!Are_Equal(sum_proba, 1.0, 1.E-10)) + { + For(i, tot_num_comb) times_partial_proba[i] = times_partial_proba[i] / sum_proba; + } + +} + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Function checks if the randomized node times are within the +//upper and lower time limits, taken into account the times of +//the ancestor and descendent. +void Check_Node_Time(t_node *a, t_node *d, int *result, t_tree *tree) +{ + phydbl t_low, t_up; + phydbl *t_prior_min, *t_prior_max, *nd_t; + + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + nd_t = tree -> rates -> nd_t; + + if((a == tree -> n_root) && + ((nd_t[a -> num] > MIN(t_prior_max[a -> num], MIN(nd_t[a -> v[1] -> num], nd_t[a -> v[2] -> num]))) || + (nd_t[a -> num] < t_prior_min[a -> num]))) + + { + *result = FALSE; + return; + } + + if(d -> tax) return; + else + { + t_low = MAX(t_prior_min[d -> num], nd_t[d -> anc -> num]); + t_up = MIN(t_prior_max[d -> num], MIN(nd_t[d -> v[1] -> num], nd_t[d -> v[2] -> num])); + /* printf("\n. CHECK: %d t:%f u:%f d:%f",d->num,nd_t[d->num],t_up,t_low); */ + if(nd_t[d -> num] < t_low || nd_t[d -> num] > t_up) + { + *result = FALSE; + return; + } + + int i; + for(i=0;i<3;i++) + if((d -> v[i] != d -> anc) && (d -> b[i] != tree -> e_root)) + Check_Node_Time(d, d -> v[i], result, tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Function calculates the TOTAL number of calibration combinations, +//given the number of nodes to which each calibartion applies to. +int Number_Of_Comb(t_cal *calib) +{ + + int num_comb; + + if(!calib) return(1); + num_comb = 1; + do + { + num_comb *= calib -> n_all_applies_to; + if(calib -> next) calib = calib -> next; + else break; + } + while(calib); + return(num_comb); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Function calculates the TOTAL number of calibration combinations, +//given the number of nodes to which each calibartion applies to. +int Number_Of_Calib(t_cal *calib) +{ + + int num_calib; + + + num_calib = 0; + do + { + num_calib++; + if(calib -> next) calib = calib -> next; + else break; + } + while(calib); + return(num_calib); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Function sets current calibration in the following way: +// Suppose we have a vector of calibrations C=(C1, C2, C3), each calibration +// applies to a set of nodes. We can reach each node number through the indexes (corresponds +// to the number the information was read). C1={0,1,2}, C2={0,1}, C3={0}; +// The total number of combinations is 3*2*1=6. The first combination with row number 0 +// will be {0,0,0}, the second row will be {0,1,0} and so on. Calling the node numbers with +// the above indexes will return current calibration. Also sets the vector of probabilities +// for current calibration combination. +void Set_Current_Calibration(int row, t_tree *tree) +{ + t_cal *calib; + phydbl *t_prior_min, *t_prior_max; + short int *t_has_prior; + int k, i, j, *curr_nd_for_cal; + + calib = tree -> rates -> calib; + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + t_has_prior = tree -> rates -> t_has_prior; + curr_nd_for_cal = tree -> rates -> curr_nd_for_cal; + /* printf("\n COMBINATION NUMBER [%d] \n", row); */ + for(j = tree -> n_otu; j < 2 * tree -> n_otu - 1; j++) + { + t_prior_min[j] = -BIG; + t_prior_max[j] = BIG; + t_has_prior[j] = NO; + } + + k = -1; + i = 0; + do + { + k = (row % Number_Of_Comb(calib)) / Number_Of_Comb(calib -> next); + if(calib -> all_applies_to[k] -> num) + { + /* printf("\n"); */ + /* printf(" %f %f %f %f ", calib -> lower, calib -> upper, t_prior_min[calib -> all_applies_to[k] -> num], t_prior_max[calib -> all_applies_to[k] -> num]); */ + /* printf("\n"); */ + /* printf("\n"); */ + /* printf(" Node number [%d] ", calib -> all_applies_to[k] -> num); */ + /* printf("\n"); */ + t_prior_min[calib -> all_applies_to[k] -> num] = MAX(t_prior_min[calib -> all_applies_to[k] -> num], calib -> lower); /* printf("\n Prior min [%f] \n", t_prior_min[calib -> all_applies_to[k] -> num]); */ + t_prior_max[calib -> all_applies_to[k] -> num] = MIN(t_prior_max[calib -> all_applies_to[k] -> num], calib -> upper); /* printf("\n Prior max [%f] \n", t_prior_max[calib -> all_applies_to[k] -> num]); */ + t_has_prior[calib -> all_applies_to[k] -> num] = YES; + curr_nd_for_cal[i] = calib -> all_applies_to[k] -> num; + i++; + } + if(calib->next) calib = calib->next; + else break; + } + while(calib); + while(calib -> prev) calib = calib -> prev; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Randomly choose a combination of calibrations drawing an index of calibration combination, +//used function Set_Cur_Calibration. +void Random_Calibration(t_tree *tree) +{ + int rnd, num_comb; + t_cal *calib; + + calib = tree -> rates -> calib; + + num_comb = Number_Of_Comb(calib); + + srand(time(NULL)); + rnd = rand()%(num_comb); + + Set_Current_Calibration(rnd, tree); + TIMES_Set_All_Node_Priors(tree); + +} + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Variable curr_nd_for_cal is a vector of node numbers, the length of that vector is a number of calibrations. +//Function randomly updates that vector by randomly changing one node and setting times limits with respect +//to a new vector. +int RND_Calibration_And_Node_Number(t_tree *tree) +{ + int i, j, tot_num_cal, cal_num, node_ind, node_num, *curr_nd_for_cal; + phydbl *t_prior_min, *t_prior_max; //*times_partial_proba; + short int *t_has_prior; + t_cal *cal; + + tot_num_cal = tree -> rates -> tot_num_cal; + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + t_has_prior = tree -> rates -> t_has_prior; + curr_nd_for_cal = tree -> rates -> curr_nd_for_cal; + cal = tree -> rates -> calib; + + cal_num = rand()%(tot_num_cal - 1); + + i = 0; + while (i != cal_num) + { + cal = cal -> next; + i++; + } + + node_ind = rand()%(cal -> n_all_applies_to); + node_num = cal -> all_applies_to[node_ind] -> num; + + curr_nd_for_cal[cal_num] = node_num; + + for(j = tree -> n_otu; j < 2 * tree -> n_otu - 1; j++) + { + t_prior_min[j] = -BIG; + t_prior_max[j] = BIG; + t_has_prior[j] = NO; + } + + while(cal -> prev) cal = cal -> prev; + + i = 0; + do + { + t_prior_min[curr_nd_for_cal[i]] = cal -> lower; + t_prior_max[curr_nd_for_cal[i]] = cal -> upper; + t_has_prior[curr_nd_for_cal[i]] = YES; + i++; + if(cal->next) cal = cal -> next; + else break; + } + while(cal); + + while(cal -> prev) cal = cal -> prev; + + TIMES_Set_All_Node_Priors(tree); + + return(node_num); +} + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Return the value uniformly distributed between two values. +phydbl Randomize_One_Node_Time(phydbl min, phydbl max) +{ + phydbl u; + + u = Uni(); + u *= (max - min); + u += min; + + return(u); +} + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Calculates the Hastings ratio for the analysis. Used in case of +//calibration conditional jump. NOT THE RIGHT ONE TO USE! +void Lk_Hastings_Ratio_Times(t_node *a, t_node *d, phydbl *tot_prob, t_tree *tree) +{ + phydbl t_low, t_up; + phydbl *t_prior_min, *t_prior_max, *nd_t; + + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + nd_t = tree -> rates -> nd_t; + + if(d -> tax) return; + else + { + t_low = MAX(t_prior_min[d -> num], nd_t[d -> anc -> num]); + t_up = MIN(t_prior_max[d -> num], MIN(nd_t[d -> v[1] -> num], nd_t[d -> v[2] -> num])); + + (*tot_prob) += log(1) - log(t_up - t_low); + + int i; + for(i=0;i<3;i++) + if((d -> v[i] != d -> anc) && (d -> b[i] != tree -> e_root)) + { + Lk_Hastings_Ratio_Times(d, d -> v[i], tot_prob, tree); + } + } +} + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Updates nodes which are below a randomized node in case if new proposed time +//for that node is below the current value. +void Update_Descendent_Cond_Jump(t_node *a, t_node *d, phydbl *L_Hast_ratio, t_tree *tree) +{ + int result = TRUE; + phydbl t_low, t_up; + phydbl *t_prior_min, *t_prior_max, *nd_t; + + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + nd_t = tree -> rates -> nd_t; + + Check_Node_Time(tree -> n_root, tree -> n_root -> v[1], &result, tree); + Check_Node_Time(tree -> n_root, tree -> n_root -> v[2], &result, tree); + + if(d -> tax) return; + else + { + if(result != TRUE) + { + int i; + t_low = MAX(nd_t[a -> num], t_prior_min[d -> num]); + if(t_low < MIN(nd_t[d -> v[1] -> num], nd_t[d -> v[2] -> num])) t_up = MIN(t_prior_max[d -> num], MIN(nd_t[d -> v[1] -> num], nd_t[d -> v[2] -> num])); + else t_up = t_prior_max[d -> num]; + nd_t[d -> num] = Randomize_One_Node_Time(t_low, t_up); + (*L_Hast_ratio) += log(1) - log(t_up - t_low); + for(i=0;i<3;i++) + if((d -> v[i] != d -> anc) && (d -> b[i] != tree -> e_root)) + Update_Descendent_Cond_Jump(d, d -> v[i], L_Hast_ratio, tree); + } + else return; + } +} + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//Updates nodes which are above a randomized node in case if new proposed time +//for that node is above the current value. +void Update_Ancestor_Cond_Jump(t_node *d, phydbl *L_Hast_ratio, t_tree *tree) +{ + int result = TRUE; + phydbl t_low, t_up; + phydbl *t_prior_min, *t_prior_max, *nd_t; + + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + nd_t = tree -> rates -> nd_t; + + Check_Node_Time(tree -> n_root, tree -> n_root -> v[1], &result, tree); + Check_Node_Time(tree -> n_root, tree -> n_root -> v[2], &result, tree); + + if(result != TRUE) + { + if(d == tree -> n_root) + { + + t_low = t_prior_min[d -> num]; + t_up = MIN(t_prior_max[d -> num], MIN(nd_t[d -> v[1] -> num], nd_t[d -> v[2] -> num])); + nd_t[d -> num] = Randomize_One_Node_Time(t_low, t_up); + (*L_Hast_ratio) += log(1) - log(t_up - t_low); + return; + } + else + { + t_up = MIN(t_prior_max[d -> num], MIN(nd_t[d -> v[1] -> num], nd_t[d -> v[2] -> num])); + if(nd_t[d -> anc -> num] > t_up) t_low = t_prior_min[d -> num]; + else t_low = MAX(t_prior_min[d -> num], nd_t[d -> anc -> num]); + nd_t[d -> num] = Randomize_One_Node_Time(t_low, t_up); + (*L_Hast_ratio) += log(1) - log(t_up - t_low); + Update_Ancestor_Cond_Jump(d -> anc, L_Hast_ratio, tree); + } + + } + else return; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//when made a calibration conditional jump, updates node times +//with respect to the new calibration which was made with respect +//to the randomly chosen node, the root is fixed. Updates only those nodes +//that are not within new intervals. Traverse up and down. +void Update_Times_RND_Node_Ancestor_Descendant(int rnd_node, phydbl *L_Hast_ratio, t_tree *tree) +{ + int i; + phydbl *t_prior_min, *t_prior_max, *nd_t; + phydbl new_time_rnd_node = 0.0; + + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + nd_t = tree -> rates -> nd_t; + + new_time_rnd_node = Randomize_One_Node_Time(t_prior_min[rnd_node], t_prior_max[rnd_node]); + + nd_t[rnd_node] = new_time_rnd_node; + + Update_Ancestor_Cond_Jump(tree -> a_nodes[rnd_node] -> anc, L_Hast_ratio, tree); + for(i=0;i<3;i++) + if((tree -> a_nodes[rnd_node] -> v[i] != tree -> a_nodes[rnd_node] -> anc) && (tree -> a_nodes[rnd_node] -> b[i] != tree -> e_root)) + Update_Descendent_Cond_Jump(tree -> a_nodes[rnd_node], tree -> a_nodes[rnd_node] -> v[i], L_Hast_ratio, tree); + +} + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +//when made a calibration conditional jump, updates node times +//with respect to the new calibration which was made with respect +//to the randomly chosen node, starting from the root down to the tips. +//Updates only those nodes that are not within new intervals. +void Update_Times_Down_Tree(t_node *a, t_node *d, phydbl *L_Hastings_ratio, t_tree *tree) +{ + int i; + phydbl *t_prior_min, *t_prior_max, *nd_t, t_low, t_up; + + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + nd_t = tree -> rates -> nd_t; + + + t_low = MAX(t_prior_min[d -> num], nd_t[a -> num]); + t_up = t_prior_max[d -> num]; + + //printf("\n. [1] Node number: [%d] \n", d -> num); + if(d -> tax) return; + else + { + if(nd_t[d -> num] > t_up || nd_t[d -> num] < t_low) + { + //printf("\n. [2] Node number: [%d] \n", d -> num); + //(*L_Hastings_ratio) += (log(1) - log(t_up - t_low)); + (*L_Hastings_ratio) += (- log(t_up - t_low)); + nd_t[d -> num] = Randomize_One_Node_Time(t_low, t_up); + /* t_prior_min[d -> num] = t_low; */ + /* t_prior_max[d -> num] = t_up; */ + } + + for(i=0;i<3;i++) + if((d -> v[i] != d -> anc) && (d -> b[i] != tree -> e_root)) + Update_Times_Down_Tree(d, d -> v[i], L_Hastings_ratio, tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +xml_node *XML_Search_Node_Attribute_Value_Clade(char *attr_name, char *value, int skip, xml_node *node) +{ + xml_node *match; + + //printf("\n. Node name [%s] Attr name [%s] Attr value [%s] \n", node -> name, attr_name, value); + if(!node) + { + PhyML_Printf("\n== node: %p attr: %p",node,node?node->attr:NULL); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + match = NULL; + if(skip == NO && node -> attr) + { + xml_attr *attr; + attr = node -> attr; + do + { + if(!strcmp(attr -> name, attr_name) && !strcmp(attr -> value, value)) + { + match = node; + break; + } + attr = attr->next; + if(!attr) break; + } + while(1); + } + if(match) return(match); + if(node -> next && !match) + { + match = XML_Search_Node_Attribute_Value_Clade(attr_name, value, NO, node -> next); + return match; + } + return NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +void TIMES_Set_All_Node_Priors_S(int *result, t_tree *tree) +{ + int i; + phydbl min_prior; + + + /* Set all t_prior_max values */ + TIMES_Set_All_Node_Priors_Bottom_Up_S(tree->n_root,tree->n_root->v[2], result, tree); + TIMES_Set_All_Node_Priors_Bottom_Up_S(tree->n_root,tree->n_root->v[1], result, tree); + + tree->rates->t_prior_max[tree->n_root->num] = + MIN(tree->rates->t_prior_max[tree->n_root->num], + MIN(tree->rates->t_prior_max[tree->n_root->v[2]->num], + tree->rates->t_prior_max[tree->n_root->v[1]->num])); + + + /* Set all t_prior_min values */ + if(!tree->rates->t_has_prior[tree->n_root->num]) + { + min_prior = 1.E+10; + For(i,2*tree->n_otu-2) + { + if(tree->rates->t_has_prior[i]) + { + if(tree->rates->t_prior_min[i] < min_prior) + min_prior = tree->rates->t_prior_min[i]; + } + } + tree->rates->t_prior_min[tree->n_root->num] = 2.0 * min_prior; + } + + if(tree->rates->t_prior_min[tree->n_root->num] > 0.0) + { + *result = FALSE; + } + + + TIMES_Set_All_Node_Priors_Top_Down_S(tree->n_root,tree->n_root->v[2], result, tree); + TIMES_Set_All_Node_Priors_Top_Down_S(tree->n_root,tree->n_root->v[1], result, tree); + + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Set_All_Node_Priors_Bottom_Up_S(t_node *a, t_node *d, int *result, t_tree *tree) +{ + int i; + phydbl t_sup; + + if(d->tax) return; + else + { + t_node *v1, *v2; /* the two sons of d */ + + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + TIMES_Set_All_Node_Priors_Bottom_Up_S(d,d->v[i], result, tree); + } + } + + v1 = v2 = NULL; + for(i=0;i<3;i++) if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(!v1) v1 = d->v[i]; + else v2 = d->v[i]; + } + + if(tree->rates->t_has_prior[d->num] == YES) + { + t_sup = MIN(tree->rates->t_prior_max[d->num], + MIN(tree->rates->t_prior_max[v1->num], + tree->rates->t_prior_max[v2->num])); + + tree->rates->t_prior_max[d->num] = t_sup; + + + if(tree->rates->t_prior_max[d->num] < tree->rates->t_prior_min[d->num]) + { + + *result = FALSE; + + } + } + else + { + tree->rates->t_prior_max[d->num] = + MIN(tree->rates->t_prior_max[v1->num], + tree->rates->t_prior_max[v2->num]); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Set_All_Node_Priors_Top_Down_S(t_node *a, t_node *d, int *result, t_tree *tree) +{ + if(d->tax) return; + else + { + int i; + + if(tree->rates->t_has_prior[d->num] == YES) + { + tree->rates->t_prior_min[d->num] = MAX(tree->rates->t_prior_min[d->num],tree->rates->t_prior_min[a->num]); + + + if(tree->rates->t_prior_max[d->num] < tree->rates->t_prior_min[d->num]) + { + + *result = FALSE; + + } + } + else + { + tree->rates->t_prior_min[d->num] = tree->rates->t_prior_min[a->num]; + } + + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + TIMES_Set_All_Node_Priors_Top_Down_S(d,d->v[i], result, tree); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl log_g_i(phydbl lmbd, phydbl t_slice_max, phydbl t_slice_min, phydbl t_prior_max, phydbl t_prior_min) +{ + phydbl result = 0.0; + + + if(lmbd * t_prior_min < -10.0) + { + phydbl K; + K = -10.0 - lmbd * t_prior_min; + /* printf("\n. K = [%f] \n", K); */ + if(lmbd * t_prior_max + K > 700.0) + { + PhyML_Printf("\n. Please scale your calibration intervals. \n"); + PhyML_Printf("\n. Cannot calculate exp(-lmbd * t_prior_max). \n"); + PhyML_Printf("\n. Err. in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit("\n"); + } + else + { + result = log(exp(lmbd * t_slice_max + K) - exp(lmbd * t_slice_min + K)) - log(exp(lmbd * t_prior_max + K) - exp(lmbd * t_prior_min + K)); + } + } + else + { + result = log(exp(lmbd * t_slice_max) - exp(lmbd * t_slice_min)) - log(exp(lmbd * t_prior_max) - exp(lmbd * t_prior_min)); + } + return(result); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int CombineInt(int int1, int int2) +{ + int mem; + + mem = 500 * 2; + + char cResult[mem]; + + sprintf(cResult, "%d%d", int1, int2); + return atoi(cResult); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Jump_Calibration_Move_Pre(t_node *a, t_node *d, phydbl old_ta, phydbl *log_hastings_ratio, t_tree *tree) +{ + int i; + phydbl *t_prior_min_new, *t_prior_max_new, t_low_new, t_up_new; + phydbl *t_prior_min_old, *t_prior_max_old, t_low_old, t_up_old; + phydbl *nd_t, old_t; + phydbl eps = DBL_MIN; + int move_anyway; + + t_prior_min_new = tree -> rates -> t_prior_min; + t_prior_max_new = tree -> rates -> t_prior_max; + + t_prior_min_old = tree -> rates -> t_prior_min_ori; + t_prior_max_old = tree -> rates -> t_prior_max_ori; + + nd_t = tree -> rates -> nd_t; + + t_low_new = MAX(t_prior_min_new[d -> num], nd_t[a -> num]); + t_up_new = t_prior_max_new[d -> num]; + + t_low_old = MAX(t_prior_min_old[d -> num], old_ta); + t_up_old = t_prior_max_old[d -> num]; + + old_t = nd_t[d -> num]; + + /* move_anyway = NO; */ + /* if(Uni() < .5) move_anyway = YES; */ + move_anyway = YES; + + + if(d -> tax) return; + else + { + if((nd_t[d -> num] > t_up_new || nd_t[d -> num] < t_low_new) || (move_anyway == YES)) /* Hastings ratio */ + { + (*log_hastings_ratio) += log(t_up_new - t_low_new + eps); + } + + if((nd_t[d -> num] > t_up_new || nd_t[d -> num] < t_low_new) || (move_anyway == YES)) /* Do the jump */ + { + nd_t[d -> num] = Uni()*(t_up_new - t_low_new) + t_low_new; + } + + + if((nd_t[d -> num] > t_up_old || nd_t[d -> num] < t_low_old) || (move_anyway == YES)) /* Hastings ratio */ + { + (*log_hastings_ratio) -= log(t_up_old - t_low_old + eps); + } + + + for(i=0;i<3;i++) + if((d -> v[i] != d -> anc) && (d -> b[i] != tree -> e_root)) + Jump_Calibration_Move_Pre(d, d -> v[i], old_t, log_hastings_ratio, tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Multiple_Time_Proposal_Density(t_node *a, t_node *d, phydbl *time_proposal_density, t_tree *tree) +{ + int i; + phydbl *t_prior_min, *t_prior_max, *nd_t, t_low, t_up; + + t_prior_min = tree -> rates -> t_prior_min; + t_prior_max = tree -> rates -> t_prior_max; + nd_t = tree -> rates -> nd_t; + + + //printf("\n. [1] Node number: [%d] \n", d -> num); + if(d -> tax) return; + else + { + + t_low = MAX(t_prior_min[d -> num], nd_t[a -> num]); + t_up = t_prior_max[d -> num]; + /* t_up = MIN(t_prior_max[d -> num], MIN(nd_t[d -> v[1] -> num], nd_t[d -> v[2] -> num])); */ + /* printf("\n. Low [%f] Up [%f] \n", t_low, t_up); */ + + (*time_proposal_density) += (- log(t_up - t_low)); + + for(i=0;i<3;i++) + if((d -> v[i] != d -> anc) && (d -> b[i] != tree -> e_root)) + Multiple_Time_Proposal_Density(d, d -> v[i], time_proposal_density, tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + diff --git a/phyml/invitee.h b/phyml/invitee.h new file mode 100644 index 0000000..afc292a --- /dev/null +++ b/phyml/invitee.h @@ -0,0 +1,43 @@ +#ifndef INVITEE_H +#define INVITEE_H + +#include "utilities.h" + +int My_Function(int argc, char **argv); +int My_main(int argc, char **argv); +void PhyTime_XML(char *xml_file); +phydbl TIMES_Calib_Cond_Prob(t_tree *tree); +int Number_Of_Comb(t_cal *calib); +int Number_Of_Calib(t_cal *calib); +void Check_Node_Time(t_node *a, t_node *d, int *result, t_tree *tree); +void Set_Current_Calibration(int row, t_tree *tree); +void Random_Calibration(t_tree *tree); +int RND_Calibration_And_Node_Number(t_tree *tree); +phydbl Randomize_One_Node_Time(phydbl min, phydbl max); +void Lk_Hastings_Ratio_Times(t_node *a, t_node *d, phydbl *tot_prob, t_tree *tree); +void Update_Descendent_Cond_Jump(t_node *a, t_node *d, phydbl *L_Hast_ratio, t_tree *tree); +void Update_Ancestor_Cond_Jump(t_node *d, phydbl *L_Hast_ratio, t_tree *tree); +void Update_Times_RND_Node_Ancestor_Descendant(int rnd_node, phydbl *L_Hast_ratio, t_tree *tree); +void Update_Times_Down_Tree(t_node *a, t_node *d, phydbl *L_Hastings_ratio, t_tree *tree); +phydbl K_Constant_Prior_Times_Log(t_tree *tree); +int Number_Of_Comb_Slices(int m, int num_elem, int *n_slice); +void Check_Time_Slices(t_node *a, t_node *d, int *result, phydbl *t_cur_slice_min, phydbl *t_cur_slice_max, t_tree *tree); +void Number_Of_Nodes_In_Slice(t_node *d_start, t_node *d, int *n, phydbl *t_cur_slice_min, phydbl *t_cur_slice_max, t_tree *tree); +void Search_Root_Node_In_Slice(t_node *d_start, t_node *d, int *root_nodes, int *num_elem, phydbl t_slice_min, phydbl t_slice_max, phydbl *t_cur_slice_min, phydbl *t_cur_slice_max, t_tree *tree); +int Factorial(int base); +phydbl *Norm_Constant_Prior_Times(t_tree *tree); +void TIMES_Calib_Partial_Proba(t_tree *tree); +xml_node *XML_Search_Node_Attribute_Value_Clade(char *attr_name, char *value, int skip, xml_node *node); +char **XML_Read_Clade(xml_node *n_clade, t_tree *tree); +int XML_Number_Of_Taxa_In_Clade(xml_node *n_clade); +void TIMES_Set_All_Node_Priors_S(int *result, t_tree *tree); +void TIMES_Set_All_Node_Priors_Bottom_Up_S(t_node *a, t_node *d, int *result, t_tree *tree); +void TIMES_Set_All_Node_Priors_Top_Down_S(t_node *a, t_node *d, int *result, t_tree *tree); +phydbl LOG_g_i(phydbl lmbd, phydbl t_slice_max, phydbl t_slice_min, phydbl t_prior_max, phydbl t_prior_min); +int CombineInt(int int1, int int2); +void Update_Current_Times_Down_Tree(t_node *a, t_node *d, t_tree *tree); +void Multiple_Time_Proposal_Density(t_node *a, t_node *d, phydbl *time_proposal_density, t_tree *tree); +void Jump_Calibration_Move_Pre(t_node *a, t_node *d, phydbl old_ta, phydbl *log_hastings_ratio, t_tree *tree); + +#endif + diff --git a/phyml/io.c b/phyml/io.c new file mode 100644 index 0000000..a92d8ab --- /dev/null +++ b/phyml/io.c @@ -0,0 +1,6405 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "io.h" +#include "assert.h" + +#ifdef BEAGLE +#include "libhmsbeagle/beagle.h" +#endif + + +/* Tree parser function. We need to pass a pointer to the string of characters + since this string might be freed and then re-allocated by that function (i.e., + its address in memory might change) +*/ +t_tree *Read_Tree(char **s_tree) +{ + char **subs; + int i,n_ext,n_int,n_otu; + t_tree *tree; + int degree,len; + t_node *root_node; + + n_int = n_ext = 0; + + n_otu=0; + for(i=0;i<(int)strlen((*s_tree));++i) + { + if((*s_tree)[i] == '[') do ++i; while((*s_tree)[i] != ']'); // Skip labels + if((*s_tree)[i] == ',') n_otu++; + } + n_otu+=1; + + + + tree = Make_Tree_From_Scratch(n_otu,NULL); + subs = Sub_Trees((*s_tree),°ree); + Clean_Multifurcation(subs,degree,3); + + if(degree == 2) + { + /* Unroot_Tree(subs); */ + /* degree = 3; */ + /* root_node = tree->a_nodes[n_otu]; */ + + root_node = tree->a_nodes[2*n_otu-2]; + root_node->num = 2*n_otu-2; + tree->n_root = root_node; + n_int -= 1; + } + else + { + root_node = tree->a_nodes[n_otu]; + root_node->num = n_otu; + tree->n_root = NULL; + } + + if(degree > 3) /* Multifurcation at the root. Need to re-assemble the subtrees + since Clean_Multifurcation added sets of parenthesis and + the corresponding NULL edges */ + { + degree = 3; + Free((*s_tree)); + len = 0; + for(i=0;itax = 0; + + tree->has_branch_lengths = 0; + tree->num_curr_branch_available = tree->n_otu; + for(i=0;in_root) + { + + if(tree->n_root->v[1]->tax == NO && tree->n_root->v[2]->tax == NO) + { + tree->e_root = tree->a_edges[tree->num_curr_branch_available]; + tree->n_root->b[1] = tree->a_edges[tree->num_curr_branch_available+1]; + tree->n_root->b[2] = tree->a_edges[tree->num_curr_branch_available+2]; + } + else + { + for(i=0;in_otu;++i) if(tree->a_edges[i]->left == NULL && tree->a_edges[i]->rght == NULL) break; + assert(i != tree->n_otu); + tree->e_root = tree->a_edges[i]; + + tree->n_root->b[1] = tree->a_edges[tree->num_curr_branch_available]; + tree->n_root->b[2] = tree->a_edges[tree->num_curr_branch_available+1]; + } + + tree->n_root->v[2]->v[0] = tree->n_root->v[1]; + tree->n_root->v[1]->v[0] = tree->n_root->v[2]; + + // Reading edge lengths + subs = Sub_Trees((*s_tree),°ree); + Read_Branch_Length(subs[0],(*s_tree),tree->n_root->b[1],tree); + Read_Branch_Length(subs[1],(*s_tree),tree->n_root->b[2],tree); + Free(subs); + + Connect_One_Edge_To_Two_Nodes(tree->n_root->v[2], + tree->n_root->v[1], + tree->e_root, + tree); + + tree->e_root->l->v = tree->n_root->b[2]->l->v + tree->n_root->b[1]->l->v; + if(tree->e_root->l->v > 0.0) + tree->n_root_pos = tree->n_root->b[2]->l->v / tree->e_root->l->v; + else + tree->n_root_pos = .5; + + + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + + } + + return tree; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* 'a' in t_node a stands for ancestor. 'd' stands for descendant */ +void R_rtree(char *s_tree_a, char *s_tree_d, t_node *a, t_tree *tree, int *n_int, int *n_ext) +{ + int i; + t_node *d; + int n_otu = tree->n_otu; + + + if(strstr(s_tree_a," ")) + { + PhyML_Fprintf(stderr,"\n. [%s]",s_tree_a); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + // Internal edge + if(s_tree_d[0] == '(') + { + char **subs; + int degree; + t_edge *b; + + (*n_int)+=1; + + if((*n_int + n_otu) == (2*n_otu-1)) + { + PhyML_Fprintf(stderr,"\n. The number of internal nodes in the tree exceeds the number of taxa minus one."); + PhyML_Fprintf(stderr,"\n. There probably is a formating problem in the input tree."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + d = tree->a_nodes[n_otu+*n_int]; + d->num = n_otu + *n_int; + d->tax = 0; + b = tree->a_edges[tree->num_curr_branch_available]; + + Read_Branch_Support(s_tree_d,s_tree_a,b,tree); + Read_Branch_Length(s_tree_d,s_tree_a,b,tree); + Read_Node_Label(s_tree_d,s_tree_a,d); + + if(tree->n_root && a == tree->n_root) + { + if(!a->v[1]) a->v[1] = d; + else a->v[2] = d; + } + else + { + for(i=0;i<3;i++) + { + if(!a->v[i]) + { + a->v[i] = d; + break; + } + } + } + d->v[0]=a; + + if(!(tree->n_root && a == tree->n_root)) Connect_One_Edge_To_Two_Nodes(a,d,tree->a_edges[tree->num_curr_branch_available],tree); + + subs=Sub_Trees(s_tree_d,°ree); + + + if(degree < 2) + { + PhyML_Fprintf(stderr,"\n. A problem was detected in the following subtree:"); + PhyML_Fprintf(stderr,"\n. %s",s_tree_d); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + if(degree > 2) + { + Clean_Multifurcation(subs,degree,2); + + Free(s_tree_d); + + s_tree_d = (char *)mCalloc(strlen(subs[0])+strlen(subs[1])+5,sizeof(char)); + + i = 0; + while(subs[i] != NULL) Free(subs[i++]); + Free(subs); + + subs=Sub_Trees(s_tree_d,°ree); + } + + R_rtree(s_tree_d,subs[0],d,tree,n_int,n_ext); + R_rtree(s_tree_d,subs[1],d,tree,n_int,n_ext); + + i = 2; + while(subs[i] != NULL) Free(subs[i++]); + Free(subs); + } + + // External edge + else + { + int i; + + d = tree->a_nodes[*n_ext]; + d->tax = 1; + + Read_Node_Name(d,s_tree_d,tree->a_edges[*n_ext],tree); + Read_Branch_Length(s_tree_d,s_tree_a,tree->a_edges[*n_ext],tree); + Read_Node_Label(s_tree_d,s_tree_a,d); + + if(tree->n_root && a == tree->n_root) + { + if(!a->v[1]) a->v[1] = d; + else a->v[2] = d; + } + else + { + for(i=0;i<3;i++) + { + if(!a->v[i]) + { + a->v[i]=d; + break; + } + } + } + d->v[0]=a; + + if(!(tree->n_root && a == tree->n_root)) + { + Connect_One_Edge_To_Two_Nodes(a,d,tree->a_edges[*n_ext],tree); + } + + d->num=*n_ext; + (*n_ext)+=1; + } + + Free(s_tree_d); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Read_Node_Name(t_node *d, char *s_tree_d, t_edge *b, t_tree *tree) +{ + d->name = (char *)mCalloc(strlen(s_tree_d)+1,sizeof(char )); + strcpy(d->name,s_tree_d); + d->ori_name = d->name; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Read_Branch_Support(char *s_d, char *s_a, t_edge *b, t_tree *tree) +{ + char *sub_tp; + char *p; + + if(s_d[0] != '(') return; // b is an external edge -> no edge support on it + + sub_tp = (char *)mCalloc(10+strlen(s_d)+1,sizeof(char)); + + sub_tp[0] = '('; + sub_tp[1] = '\0'; + strcat(sub_tp,s_d); + p = strstr(s_a,sub_tp); + + if(!p) + { + sub_tp[0] = ','; + sub_tp[1] = '\0'; + strcat(sub_tp,s_d); + p = strstr(s_a,sub_tp); + } + + + if(p) + { + b->support_val = atof((char *)p+(int)strlen(sub_tp)); + + p = p + strlen(sub_tp); + if(p[0] == '[') { while(p[0] != ']') p++; p++; } // Skip label + b->support_val = atof((char *)p); + + /* PhyML_Printf("\n. READ SUPPORT for s_d: %s b: %f",s_d,b->support_val); */ + + } + + Free(sub_tp); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Read_Branch_Length(char *s_d, char *s_a, t_edge *b, t_tree *tree) +{ + char *sub_tp; + char *p; + + sub_tp = (char *)mCalloc(10+strlen(s_d)+1,sizeof(char)); + + sub_tp[0] = '('; + sub_tp[1] = '\0'; + strcat(sub_tp,s_d); + p = strstr(s_a,sub_tp); + + if(!p) + { + sub_tp[0] = ','; + sub_tp[1] = '\0'; + strcat(sub_tp,s_d); + p = strstr(s_a,sub_tp); + } + + + if(p) + { + p = p + strlen(sub_tp); + while(p[0] != ':' && p[0] != '\0') p++; + if(p[0] == ':') + { + p++; + b->l->v = atof((char *)p); + /* PhyML_Printf("\n. READ LENGTH for s_d: %s b: %f",s_d,b->l->v); */ + tree->has_branch_lengths = YES; + b->does_exist = YES; + } + else + { + b->l->v = -1.; + } + } + else + { + b->l->v = -1.; + } + + Free(sub_tp); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Read_Node_Label(char *s_d, char *s_a, t_node *n) +{ + char *sub_tp,*s_lab; + char *p; + + sub_tp = (char *)mCalloc(3+(int)strlen(s_d)+1,sizeof(char)); + s_lab = (char *)mCalloc(strlen(s_a)+1,sizeof(char)); + + + sub_tp[0] = '('; + sub_tp[1] = '\0'; + strcat(sub_tp,s_d); + strcat(sub_tp,"[\0"); + p = strstr(s_a,sub_tp); + + if(!p) + { + sub_tp[0] = ','; + sub_tp[1] = '\0'; + strcat(sub_tp,s_d); + strcat(sub_tp,"[\0"); + p = strstr(s_a,sub_tp); + } + + if(p) + { + p = p+strlen(sub_tp)-1; + assert(p[0]=='['); + + s_lab[0]='['; + if(sscanf(p,"[%[^]]]",s_lab+1) != 1) + { + PhyML_Fprintf(stderr,"\n. Label is in wrong format. A proper label should"); + PhyML_Fprintf(stderr,"\n. look as follows: \"[xxx={yyy},xxxx={yy},...]\""); + assert(FALSE); + } + + s_lab[strlen(s_lab)]=']'; + s_lab[strlen(s_lab)]='\0'; + + /* PhyML_Printf("\n. READ LABEL for s_d: %s b: %s",s_d,s_lab); */ + + n->label = Read_Labels(s_lab); + } + + Free(sub_tp); + Free(s_lab); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Clean_Multifurcation(char **subtrees, int current_deg, int end_deg) +{ + + if(current_deg <= end_deg) return; + else + { + char *s_tmp; + int i; + + /* s_tmp = (char *)mCalloc(T_MAX_LINE,sizeof(char)); */ + s_tmp = (char *)mCalloc(10+ + (int)strlen(subtrees[0])+1+ + (int)strlen(subtrees[1])+1, + sizeof(char)); + + strcat(s_tmp,"(\0"); + strcat(s_tmp,subtrees[0]); + strcat(s_tmp,",\0"); + strcat(s_tmp,subtrees[1]); + strcat(s_tmp,")#NULL\0"); /* Add the label 'NULL' to identify a non-existing edge */ + Free(subtrees[0]); + subtrees[0] = s_tmp; + + for(i=1;in_otu;++i) PhyML_Fprintf(fp,"\t%3d\t%s,\n",i+1,tree->a_nodes[i]->name); + PhyML_Fprintf(fp,"\tUTREE PAUP_1=\n"); + PhyML_Fprintf(fp,"%s\n",s_tree); + PhyML_Fprintf(fp,"ENDBLOCK;"); + } + Free(s_tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +char *Write_Tree(t_tree *tree) +{ + char *s; + int i,available; + +#ifndef MPI + int init_len; + init_len = 3*(int)T_MAX_NAME; + s=(char *)mCalloc(init_len,sizeof(char)); + available = init_len; +#elif defined MPI + s=(char *)mCalloc(T_MAX_LINE,sizeof(char)); +#endif + + i = -1; + s[0]='('; + + if(tree->n_root == NULL) + { + i = 0; + while((!tree->a_nodes[tree->n_otu+i]->v[0]) || + (!tree->a_nodes[tree->n_otu+i]->v[1]) || + (!tree->a_nodes[tree->n_otu+i]->v[2])) i++; + + R_wtree(tree->a_nodes[tree->n_otu+i],tree->a_nodes[tree->n_otu+i]->v[0],tree->a_nodes[tree->n_otu+i]->b[0],&available,&s,tree); + R_wtree(tree->a_nodes[tree->n_otu+i],tree->a_nodes[tree->n_otu+i]->v[1],tree->a_nodes[tree->n_otu+i]->b[1],&available,&s,tree); + R_wtree(tree->a_nodes[tree->n_otu+i],tree->a_nodes[tree->n_otu+i]->v[2],tree->a_nodes[tree->n_otu+i]->b[2],&available,&s,tree); + } + else + { + R_wtree(tree->n_root,tree->n_root->v[1],tree->n_root->b[1],&available,&s,tree); + R_wtree(tree->n_root,tree->n_root->v[2],tree->n_root->b[2],&available,&s,tree); + } + + s[(int)strlen(s)-1]=')'; + + if(tree->n_root != NULL) Print_Labels(NULL,s+(int)strlen(s),tree->n_root->label); + + if(tree->io && tree->io->print_node_num == YES) + { + if(!tree->n_root) + sprintf(s+(int)strlen(s),"%d",tree->a_nodes[tree->n_otu+i]->num); + else + sprintf(s+(int)strlen(s),"%d",tree->n_root->num); + } + s[(int)strlen(s)]=';'; + + return s; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void R_wtree(t_node *pere, t_node *fils, t_edge *b, int *available, char **s_tree, t_tree *tree) +{ + int i,p; + char *format; + int last_len; + phydbl mean_len; + + format = (char *)mCalloc(100,sizeof(char)); + + sprintf(format,"%%.%df",tree->bl_ndigits); + + p = -1; + if(fils->tax == YES) // Tip node + { + last_len = (int)strlen(*s_tree); + + if(OUTPUT_TREE_FORMAT == NEWICK) + { + if(tree->write_tax_names == YES) + { + if(tree->io && tree->io->long_tax_names) + { + strcat(*s_tree,tree->io->long_tax_names[fils->num]); + } + else + { + if(fils->name && strlen(fils->name) > 0) + strcat(*s_tree,fils->name); + else + sprintf(*s_tree+(int)strlen(*s_tree),"%d",fils->num+1); + } + } + else if(tree->write_tax_names == NO) + { + sprintf(*s_tree+(int)strlen(*s_tree),"%d",fils->num+1); + } + } + else if(OUTPUT_TREE_FORMAT == NEXUS) + { + sprintf(*s_tree+(int)strlen(*s_tree),"%d",fils->num+1); + } + else + { + PhyML_Printf("\n. Unknown tree format."); + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Printf("\n. s=%s\n",*s_tree); + } + + if((fils->b) && (fils->b[0]) && (tree->write_br_lens == YES)) + { + Print_Labels(NULL,*s_tree+(int)strlen(*s_tree),fils->label); + + (*s_tree)[(int)strlen(*s_tree)] = ':'; + + Print_Labels(NULL,*s_tree+(int)strlen(*s_tree),b->label); + + if(tree->is_mixt_tree == NO) mean_len = b->l->v; + else mean_len = MIXT_Get_Mean_Edge_Len(b,tree); + sprintf(*s_tree+(int)strlen(*s_tree),format,MAX(0.0,mean_len)); + } + + (*s_tree)[(int)strlen(*s_tree)] = ','; + + +#ifndef MPI + (*available) -= ((int)strlen(*s_tree) - last_len); + + /* printf("\n0 Available = %d [%d %d]",(*available),(int)strlen(*s_tree),last_len); */ + /* printf("\n0 %s [%d,%d]",*s_tree,(int)(int)strlen(*s_tree),*available); */ + + if(*available < 0) + { + PhyML_Fprintf(stderr,"\n. s=%s\n",*s_tree); + PhyML_Fprintf(stderr,"\n. len=%d\n",(int)strlen(*s_tree)); + PhyML_Fprintf(stderr,"\n. The sequence names in your input file might be too long."); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if(*available < (int)T_MAX_NAME) + { + (*s_tree) = (char *)mRealloc(*s_tree,(int)strlen(*s_tree)+3*(int)T_MAX_NAME,sizeof(char)); + for(i=0;i<3*(int)T_MAX_NAME;++i) (*s_tree)[(int)strlen(*s_tree)+i] = '\0'; + (*available) = 3*(int)T_MAX_NAME; + } +#endif + + } + else // Internal node + { + (*s_tree)[(int)strlen(*s_tree)]='('; + +#ifndef MPI + (*available) -= 1; + + + if(*available < (int)T_MAX_NAME) + { + (*s_tree) = (char *)mRealloc(*s_tree,(int)strlen(*s_tree)+3*(int)T_MAX_NAME,sizeof(char)); + for(i=0;i<3*(int)T_MAX_NAME;++i) (*s_tree)[(int)strlen(*s_tree)+i] = '\0'; + (*available) = 3*(int)T_MAX_NAME; + } +#endif + + + for(i=0;i<3;i++) + { + if((fils->v[i] != pere) && (fils->b[i] != tree->e_root)) + R_wtree(fils,fils->v[i],fils->b[i],available,s_tree,tree); + else p=i; + } + + if(p < 0) + { + PhyML_Fprintf(stderr,"\n. pere: %d fils=%d root=%d root->v[2]=%d root->v[1]=%d",pere->num,fils->num,tree->n_root->num,tree->n_root->v[2]->num,tree->n_root->v[1]->num); + PhyML_Fprintf(stderr,"\n. fils=%d root=%d root->v[2]=%d root->v[1]=%d",fils->num,tree->n_root->num,tree->n_root->v[2]->num,tree->n_root->v[1]->num); + PhyML_Fprintf(stderr,"\n. tree->e_root=%d fils->b[0]=%d fils->b[1]=%d fils->b[2]=%d",tree->e_root->num,fils->b[0]->num,fils->b[1]->num,fils->b[2]->num); + assert(false); + } + + last_len = (int)strlen(*s_tree); + + (*s_tree)[last_len-1] = ')'; + + + if((fils->b) && (tree->write_br_lens == YES)) + { + Print_Labels(NULL,*s_tree+(int)strlen(*s_tree),fils->label); + + if(tree->io && tree->io->print_support_val == YES) + { + if(tree->io->do_boot == YES) + { + sprintf(*s_tree+(int)strlen(*s_tree),"%.0f",fils->b[p]->support_val); + } + else + { + sprintf(*s_tree+(int)strlen(*s_tree),"%f",fils->b[p]->support_val); + } + } + if(tree->io && tree->io->print_node_num == YES) + { + sprintf(*s_tree+(int)strlen(*s_tree),"%d",fils->num); + } + + + fflush(NULL); + + (*s_tree)[(int)strlen(*s_tree)] = ':'; + + Print_Labels(NULL,*s_tree+(int)strlen(*s_tree),b->label); + + if(tree->is_mixt_tree == NO) mean_len = b->l->v; + else mean_len = MIXT_Get_Mean_Edge_Len(b,tree); + sprintf(*s_tree+(int)strlen(*s_tree),format,MAX(0.0,mean_len)); + } + + (*s_tree)[(int)strlen(*s_tree)] = ','; + +#ifndef MPI + (*available) -= ((int)strlen(*s_tree) - last_len); + + + if(*available < 0) + { + PhyML_Fprintf(stderr,"\n. available = %d",*available); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if(*available < (int)T_MAX_NAME) + { + (*s_tree) = (char *)mRealloc(*s_tree,(int)strlen(*s_tree)+3*(int)T_MAX_NAME,sizeof(char)); + for(i=0;i<3*(int)T_MAX_NAME;++i) (*s_tree)[(int)strlen(*s_tree)+i] = '\0'; + (*available) = 3*(int)T_MAX_NAME; + } +#endif + + } + + Free(format); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Detect_Align_File_Format(option *io) +{ + int c; + fpos_t curr_pos; + + fgetpos(io->fp_in_align,&curr_pos); + + errno = 0; + + while((c=fgetc(io->fp_in_align)) != EOF) + { + if(errno) io->data_file_format = PHYLIP; + else if(c == '#') + { + char s[10],t[6]="NEXUS"; + if(!fgets(s,6,io->fp_in_align)) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + if(!strcmp(t,s)) + { + fsetpos(io->fp_in_align,&curr_pos); + io->data_file_format = NEXUS; + return; + } + } + } + fsetpos(io->fp_in_align,&curr_pos); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Detect_Tree_File_Format(option *io) +{ + int c; + fpos_t curr_pos; + + fgetpos(io->fp_in_tree,&curr_pos); + + errno = 0; + + while((c=fgetc(io->fp_in_tree)) != EOF) + { + if(errno) + { + io->tree_file_format = PHYLIP; + PhyML_Printf("\n. Detected PHYLIP tree file format."); + } + else if(c == '#') + { + char s[10],t[6]="NEXUS"; + if(!fgets(s,6,io->fp_in_tree)) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + if(!strcmp(t,s)) + { + fsetpos(io->fp_in_tree,&curr_pos); + io->tree_file_format = NEXUS; + PhyML_Printf("\n. Detected NEXUS tree file format."); + return; + } + } + } + + fsetpos(io->fp_in_tree,&curr_pos); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +align **Get_Seq(option *io) +{ + io->data = NULL; + + if(!io->fp_in_align) + { + PhyML_Fprintf(stderr,"\n. Filehandle to '%s' seems to be closed.",io->in_align_file); + Exit("\n"); + } + + Detect_Align_File_Format(io); + + switch(io->data_file_format) + { + case PHYLIP: + { + io->data = Get_Seq_Phylip(io); + break; + } + case NEXUS: + { + io->nex_com_list = Make_Nexus_Com(); + Init_Nexus_Format(io->nex_com_list); + Get_Nexus_Data(io->fp_in_align,io); + Free_Nexus(io); + break; + } + default: + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s')\n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + break; + } + } + + if(!io->data) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s')\n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } + else + { + Post_Process_Data(io); + } + + if(io->n_otu < 3) + { + PhyML_Fprintf(stderr,"\n. PhyML needs at least three sequences to perform an analysis."); + assert(FALSE); + } + + return io->data; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Post_Process_Data(option *io) +{ + int i,j,swap; + align *data_buff; + + for(i=0;idata[0]->len;++i) + { + for(j=0;jn_otu;++j) + { + if((io->data[j]->state[i] == '*') || (io->data[j]->state[i] == '?') || (io->data[j]->state[i] == '-')) io->data[j]->state[i] = 'X'; + if((io->datatype == NT) && (io->data[j]->state[i] == 'N')) io->data[j]->state[i] = 'X'; + if(io->data[j]->state[i] == 'U') io->data[j]->state[i] = 'T'; + } + } + + for(i=0;in_otu;++i) io->data[i]->len = io->data[0]->len; + + /* Sequences are ordered alphabetically */ + data_buff = NULL; + swap = TRUE; + /* swap = FALSE; */ + while(swap == TRUE) + { + swap = FALSE; + for(i=0;in_otu-1;i++) + { + for(j=i+1;jn_otu;j++) + { + if(strcmp(io->data[i]->name,io->data[j]->name) < 0) + { + swap = TRUE; + data_buff = io->data[i]; + io->data[i] = io->data[j]; + io->data[j] = data_buff; + } + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* align **Get_Seq_Nexus(option *io) */ +/* { */ +/* char *s,*ori_s; */ +/* char *token; */ +/* int in_comment; */ +/* nexcom *curr_com; */ +/* nexparm *curr_parm; */ +/* int nxt_token_t,cur_token_t; */ + +/* s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); */ +/* token = (char *)mCalloc(T_MAX_TOKEN,sizeof(char)); */ + +/* ori_s = s; */ +/* in_comment = NO; */ +/* curr_com = NULL; */ +/* curr_parm = NULL; */ +/* nxt_token_t = NEXUS_COM; */ +/* cur_token_t = -1; */ + +/* while(fgets(s,T_MAX_LINE,io->fp_in_align)) */ +/* { */ +/* do */ +/* { */ +/* Get_Token(&s,token); */ + +/* /\* PhyML_Printf("\n. Token: '%s' next_token=%d cur_token=%d",token,nxt_token_t,cur_token_t); *\/ */ + +/* if(token[0] == '\0') break; */ + +/* if(token[0] == ';') */ +/* { */ +/* curr_com = NULL; */ +/* curr_parm = NULL; */ +/* nxt_token_t = NEXUS_COM; */ +/* cur_token_t = -1; */ +/* break; /\* End of command *\/ */ +/* } */ + +/* if(nxt_token_t == NEXUS_EQUAL) */ +/* { */ +/* cur_token_t = NEXUS_VALUE; */ +/* nxt_token_t = NEXUS_PARM; */ +/* continue; */ +/* } */ + +/* if((nxt_token_t == NEXUS_COM) && (cur_token_t != NEXUS_VALUE)) */ +/* { */ +/* Find_Nexus_Com(token,&curr_com,&curr_parm,io->nex_com_list); */ +/* if(curr_com) */ +/* { */ +/* nxt_token_t = curr_com->nxt_token_t; */ +/* cur_token_t = curr_com->cur_token_t; */ +/* } */ +/* if(cur_token_t != NEXUS_VALUE) continue; */ +/* } */ + +/* if((nxt_token_t == NEXUS_PARM) && (cur_token_t != NEXUS_VALUE)) */ +/* { */ +/* Find_Nexus_Parm(token,&curr_parm,curr_com); */ +/* if(curr_parm) */ +/* { */ +/* nxt_token_t = curr_parm->nxt_token_t; */ +/* cur_token_t = curr_parm->cur_token_t; */ +/* } */ +/* if(cur_token_t != NEXUS_VALUE) continue; */ +/* } */ + +/* if(cur_token_t == NEXUS_VALUE) */ +/* { */ +/* if((curr_parm->fp)(token,curr_parm,io)) /\* Read in parameter value *\/ */ +/* { */ +/* nxt_token_t = NEXUS_PARM; */ +/* cur_token_t = -1; */ +/* } */ +/* } */ +/* } */ +/* while(strlen(token) > 0); */ +/* } */ + +/* Free(ori_s); */ +/* Free(token); */ + +/* return io->data; */ +/* } */ + +/* /\*********************************************************\/ */ + +void Get_Nexus_Data(FILE *fp, option *io) +{ + char *token; + nexcom *curr_com; + nexparm *curr_parm; + int nxt_token_t,cur_token_t; + + token = (char *)mCalloc(T_MAX_TOKEN,sizeof(char)); + + curr_com = NULL; + curr_parm = NULL; + nxt_token_t = NEXUS_COM; + cur_token_t = -1; + + do + { + if(!Get_Token(fp,token)) break; + + /* PhyML_Printf("\n+ Token: '%s' next_token=%d cur_token=%d",token,nxt_token_t,cur_token_t); */ + + if(token[0] == ';') + { + curr_com = NULL; + curr_parm = NULL; + nxt_token_t = NEXUS_COM; + cur_token_t = -1; + } + + if(nxt_token_t == NEXUS_EQUAL) + { + cur_token_t = NEXUS_VALUE; + nxt_token_t = NEXUS_PARM; + continue; + } + + if((nxt_token_t == NEXUS_COM) && (cur_token_t != NEXUS_VALUE)) + { + Find_Nexus_Com(token,&curr_com,&curr_parm,io->nex_com_list); + if(curr_com) + { + nxt_token_t = curr_com->nxt_token_t; + cur_token_t = curr_com->cur_token_t; + } + if(cur_token_t != NEXUS_VALUE) continue; + } + + if((nxt_token_t == NEXUS_PARM) && (cur_token_t != NEXUS_VALUE)) + { + Find_Nexus_Parm(token,&curr_parm,curr_com); + if(curr_parm) + { + nxt_token_t = curr_parm->nxt_token_t; + cur_token_t = curr_parm->cur_token_t; + } + if(cur_token_t != NEXUS_VALUE) continue; + } + + if(cur_token_t == NEXUS_VALUE) + { + if((curr_parm->fp)(token,curr_parm,io)) /* Read in parameter value */ + { + nxt_token_t = NEXUS_PARM; + cur_token_t = -1; + } + } + } + while(strlen(token) > 0); + + Free(token); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Get_Token(FILE *fp, char *token) +{ + char c; + + c = ' '; + + while(c == ' ' || c == '\t' || c == '\n' || c == '\r') + { + c = fgetc(fp); + if(c == EOF) return 0; + } + + if(c == '"') + { + do + { + *token = c; + token++; + c = fgetc(fp); + if(c == EOF) return 0; + } + while(c != '"'); + *token = c; + /* c = fgetc(fp); */ + if(c == EOF) return 0; + *(token+1) = '\0'; + return 1; + } + + if(c == '[') + { + Skip_Comment(fp); + c = fgetc(fp); + *token = c; + token++; + if(c == EOF) return 0; + return 1; + } + + if(c == '#') { *token = c; token++; } + else if(c == ';') { *token = c; token++; } + else if(c == ',') { *token = c; token++; } + else if(c == '.') { *token = c; token++; } + else if(c == '=') { *token = c; token++; } + else if(c == '(') { *token = c; token++; } + else if(c == ')') { *token = c; token++; } + else if(c == '{') { *token = c; token++; } + else if(c == '}') { *token = c; token++; } + else if(c == '?') { *token = c; token++; } + else if(c == '-') { *token = c; token++; } + else + { + while(isgraph(c) && c != ';' && c != '-' && c != ',' && c != '=') + { + *(token++) = c; + c = fgetc(fp); + if(c == EOF) return 0; + } + + fseek(fp,-1*sizeof(char),SEEK_CUR); + + } + *token = '\0'; + return 1; +} + + +/* void Get_Token(char *line, char *token) */ +/* { */ +/* while(**line == ' ' || **line == '\t') (*line)++; */ + + +/* if(**line == '"') */ +/* { */ +/* do { *token = **line; (*line)++; token++; } while(**line != '"'); */ +/* *token = **line; */ +/* (*line)++; */ +/* *(token+1) = '\0'; */ +/* return; */ +/* } */ + +/* if(**line == '[') */ +/* { */ +/* int in_comment; */ + +/* in_comment = 1; */ +/* do */ +/* { */ +/* (*line)++; */ +/* if(**line == '[') */ +/* { */ +/* in_comment++; */ +/* } */ +/* else if(**line == ']') in_comment--; */ +/* } */ +/* while(in_comment); */ +/* (*line)++; */ +/* return; */ +/* } */ + + +/* if(**line == '#') {*token = **line; (*line)++; token++; } */ +/* else if(**line == ';') {*token = **line; (*line)++; token++; } */ +/* else if(**line == ',') {*token = **line; (*line)++; token++; } */ +/* else if(**line == '.') {*token = **line; (*line)++; token++; } */ +/* else if(**line == '=') {*token = **line; (*line)++; token++; } */ +/* else if(**line == '(') {*token = **line; (*line)++; token++; } */ +/* else if(**line == ')') {*token = **line; (*line)++; token++; } */ +/* else if(**line == '{') {*token = **line; (*line)++; token++; } */ +/* else if(**line == '}') {*token = **line; (*line)++; token++; } */ +/* else if(**line == '?') {*token = **line; (*line)++; token++; } */ +/* else if(**line == '-') {*token = **line; (*line)++; token++; } */ +/* else */ +/* { */ +/* while(isgraph(**line) && **line != ';' && **line != '=' && **line != ',') */ +/* { */ +/* *(token++) = **line; */ +/* (*line)++; */ +/* } */ +/* } */ +/* *token = '\0'; */ +/* } */ + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +align **Get_Seq_Phylip(option *io) +{ + Read_Ntax_Len_Phylip(io->fp_in_align,&io->n_otu,&io->init_len); + + if(io->n_otu > N_MAX_OTU) + { + PhyML_Fprintf(stderr,"\n. The number of taxa should not exceed %d",N_MAX_OTU); + assert(FALSE); + } + + if(io->interleaved == YES) io->data = Read_Seq_Interleaved(io); + else io->data = Read_Seq_Sequential(io); + + + return io->data; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Read_Ntax_Len_Phylip(FILE *fp ,int *n_otu, int *n_tax) +{ + char *line; + int readok; + + line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + + readok = 0; + do + { + if(fscanf(fp,"%s",line) == EOF) + { + Free(line); + PhyML_Fprintf(stderr,"\n. PhyML can't read in this alignment."); + PhyML_Fprintf(stderr,"\n. Could it be that sequence file is empty?"); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + else + { + if(strcmp(line,"\n") && strcmp(line,"\r") && strcmp(line,"\t")) + { + sscanf(line,"%d",n_otu); + if(*n_otu <= 0) Warn_And_Exit("\n. The number of taxa cannot be negative.\n"); + + if(!fscanf(fp,"%s",line)) Exit("\n"); + sscanf(line,"%d",n_tax); + if(*n_tax <= 0) Warn_And_Exit("\n. The sequence length cannot be negative.\n"); + else readok = 1; + } + } + }while(!readok); + + Free(line); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +align **Read_Seq_Sequential(option *io) +{ + int i; + char *line; + align **data; +/* char c; */ + char *format; + + format = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + data = (align **)mCalloc(io->n_otu,sizeof(align *)); + +/* while((c=fgetc(in))!='\n'); */ + /* while(((c=fgetc(io->fp_in_align))!='\n') && (c != ' ') && (c != '\r') && (c != '\t')); */ + + sprintf(format, "%%%ds", T_MAX_NAME); + + + for(i=0;in_otu;i++) + { + data[i] = (align *)mCalloc(1,sizeof(align)); + data[i]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + data[i]->state = (char *)mCalloc(io->init_len*io->state_len+1,sizeof(char)); + + data[i]->is_ambigu = NULL; + data[i]->len = 0; + + if(!fscanf(io->fp_in_align,format,data[i]->name)) Exit("\n"); + + Check_Sequence_Name(data[i]->name); + + while(data[i]->len < io->init_len * io->state_len) assert(Read_One_Line_Seq(&data,i,io->fp_in_align)); + + if(data[i]->len != io->init_len * io->state_len) + { + PhyML_Fprintf(stderr,"\n. Err. Problem with species %s's sequence (check the format).\n",data[i]->name); + PhyML_Fprintf(stderr,"\n. Observed sequence length: %d, expected length: %d\n",data[i]->len, io->init_len * io->state_len); + Warn_And_Exit(""); + } + } + + for(i=0;in_otu;i++) data[i]->state[data[i]->len] = '\0'; + + Restrict_To_Coding_Position(data,io); + + Free(format); + Free(line); + + return data; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +align **Read_Seq_Interleaved(option *io) +{ + int i,end,num_block; + char *line; + align **data; +/* char c; */ + char *format; + fpos_t curr_pos; + + line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + format = (char *)mCalloc(T_MAX_NAME, sizeof(char)); + data = (align **)mCalloc(io->n_otu,sizeof(align *)); + +/* while(((c=fgetc(io->fp_in_align))!='\n') && (c != ' ') && (c != '\r') && (c != '\t')); */ + + sprintf(format, "%%%ds", T_MAX_NAME); + + end = 0; + for(i=0;in_otu;i++) + { + data[i] = (align *)mCalloc(1,sizeof(align)); + data[i]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + data[i]->state = (char *)mCalloc(io->init_len*io->state_len+1,sizeof(char)); + + data[i]->len = 0; + data[i]->is_ambigu = NULL; + + if(!fscanf(io->fp_in_align,format,data[i]->name)) Exit("\n"); + + Check_Sequence_Name(data[i]->name); + + if(!Read_One_Line_Seq(&data,i,io->fp_in_align)) + { + end = 1; + if((i != io->n_otu) && (i != io->n_otu-1)) + { + PhyML_Fprintf(stderr,"\n. Err.: problem with species %s's sequence.\n",data[i]->name); + PhyML_Fprintf(stderr,"\n. Observed sequence length: %d, expected length: %d\n",data[i]->len, io->init_len * io->state_len); + Exit(""); + } + break; + } + } + + if(data[0]->len == io->init_len * io->state_len) end = 1; + +/* if(end) printf("\n. finished yet '%c'\n",fgetc(io->fp_in_align)); */ + if(!end) + { + end = 0; + num_block = 1; + do + { + num_block++; + + /* interblock */ + if(!fgets(line,T_MAX_LINE,io->fp_in_align)) break; + + if(line[0] != 13 && line[0] != 10) + { + PhyML_Fprintf(stderr,"\n. Err.: one or more missing sequences in block %d.\n",num_block-1); + Exit(""); + } + + for(i=0;in_otu;i++) if(data[i]->len != io->init_len * io->state_len) break; + + if(i == io->n_otu) break; + + for(i=0;in_otu;i++) + { + /* Skip the taxon name, if any, in this interleaved block */ + fgetpos(io->fp_in_align,&curr_pos); + if(!fscanf(io->fp_in_align,format,line)) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + if(line && strcmp(line,data[i]->name)) fsetpos(io->fp_in_align,&curr_pos); + + if(data[i]->len > io->init_len * io->state_len) + { + PhyML_Fprintf(stderr,"\n. Observed sequence length=%d expected length=%d.\n",data[i]->len,io->init_len * io->state_len); + PhyML_Fprintf(stderr,"\n. Err.: Problem with species %s's sequence.\n",data[i]->name); + Exit(""); + } + else if(!Read_One_Line_Seq(&data,i,io->fp_in_align)) + { + end = 1; + if((i != io->n_otu) && (i != io->n_otu-1)) + { + PhyML_Fprintf(stderr,"\n. Err.: Problem with species %s's sequence.\n",data[i]->name); + PhyML_Fprintf(stderr,"\n. Observed sequence length: %d, expected length: %d.\n",data[i]->len, io->init_len * io->state_len); + Exit(""); + } + break; + } + } + }while(!end); + } + + for(i=0;in_otu;i++) data[i]->state[data[i]->len] = '\0'; + + for(i=0;in_otu;i++) + { + if(data[i]->len != io->init_len * io->state_len) + { + PhyML_Fprintf(stderr,"\n. Check sequence '%s' length (expected length: %d, observed length: %d) [OTU %d].\n",data[i]->name,io->init_len,data[i]->len,i+1); + Exit(""); + } + } + + Restrict_To_Coding_Position(data,io); + + Free(format); + Free(line); + + return data; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Read_One_Line_Seq(align ***data, int num_otu, FILE *in) +{ + char c = ' '; + int nchar = 0; + + while(1) + { +/* if((c == EOF) || (c == '\n') || (c == '\r')) break; */ + + if((c == 13) || (c == 10)) + { + /* PhyML_Printf("[%d %d]\n",c,nchar); fflush(NULL); */ + if(!nchar) + { + c=(char)fgetc(in); + continue; + } + else + { + /* PhyML_Printf("break\n"); */ + break; + } + } + else if(c == EOF) + { + /* PhyML_Printf("EOL\n"); */ + break; + } + else if((c == ' ') || (c == '\t') || (c == 32)) + { + /* PhyML_Printf("[%d]",c); */ + c=(char)fgetc(in); + continue; + } + + nchar++; + Uppercase(&c); + + if(c == '.') + { + c = (*data)[0]->state[(*data)[num_otu]->len]; + if(!num_otu) + Warn_And_Exit("\n. Err: Symbol \".\" should not appear in the first sequence\n"); + } + (*data)[num_otu]->state[(*data)[num_otu]->len]=c; + (*data)[num_otu]->len++; + c = (char)fgetc(in); + /* PhyML_Printf("[%c %d]",c,c); fflush(NULL); */ + if(c == ';') break; + } + + /* printf("\n. Exit nchar: %d [%d]\n",nchar,c==EOF); */ + if(c == EOF) return 0; + else return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +scalar_dbl *Read_Io_Weights(option *io) +{ + scalar_dbl *w,*ori,*prev = NULL; + double val; + + assert(io->weight_file); + + io->fp_weight_file = Openfile(io->weight_file,READ); + + w = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + ori = w; + + do + { + if(fscanf(io->fp_weight_file,"%lf,",&val) == EOF) break; + w->v = (phydbl)val; + w->next = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + prev = w; + w = w->next; + } + while(1); + + /* Remove the last allocated and empty element of the list */ + if(prev !=NULL && prev->next != NULL) + { + Free(prev->next); + prev->next=NULL; + } + + fclose(io->fp_weight_file); + + return(ori); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +char *Return_Tree_String_Phylip(FILE *fp_input_tree) +{ + char *line; + int i; + char c; + int open,maxopen; + + if(fp_input_tree == NULL) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + do + { + c=fgetc(fp_input_tree); + } + while((c != '(') && (c != EOF)); + + + if(c==EOF) return NULL; + + line = (char *)mCalloc(1,sizeof(char)); + open = 1; + maxopen = open; + + i=0; + for(;;) + { + if((c == ' ') || (c == '\n')) + { + c=fgetc(fp_input_tree); + if(c == EOF || c == ';') break; + else continue; + } + + /* if(c == '[') */ + /* { */ + /* Skip_Comment(fp_input_tree); */ + /* c = fgetc(fp_input_tree); */ + /* if(c == EOF || c == ';') break; */ + /* } */ + + line = (char *)mRealloc(line,i+2,sizeof(char)); + + line[i]=c; + i++; + c=fgetc(fp_input_tree); + if(c==EOF || c==';') break; + if(c=='(') open++; + if(c==')') open--; + if(open>maxopen) maxopen = open; + } + line[i] = '\0'; + + /* if(maxopen == 1) return NULL; */ + return line; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_tree *Read_Tree_File_Phylip(FILE *fp_input_tree) +{ + char *line; + t_tree *tree; + + line = Return_Tree_String_Phylip(fp_input_tree); + tree = Read_Tree(&line); + Free(line); + + return tree; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Site(calign *cdata, int num, int n_otu, char *sep, int stepsize, FILE *fp) +{ + int i,j; + PhyML_Fprintf(fp,"\n"); + for(i=0;ic_seq[i]->name); + for(j=0;jc_seq[i]->state[num+j]); + PhyML_Fprintf(fp,"%s",sep); + } + PhyML_Fprintf(fp,"%s",sep); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Site_Lk(t_tree *tree, FILE *fp) +{ + int site; + int catg; + char *s; + phydbl postmean,sum; + + assert(fp); + rewind(fp); + + if(tree->is_mixt_tree == YES) + { + MIXT_Print_Site_Lk(tree,fp); + return; + } + + assert(tree->io->print_site_lnl == YES); + + if(!tree->io->print_trace) + { + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + + PhyML_Fprintf(fp,"Note : P(D|M) is the probability of site D given the model M (i.e., the site likelihood)\n"); + if(tree->mod->ras->n_catg > 1 || tree->mod->ras->invar) + { + PhyML_Fprintf(fp,"P*(D|M,rr[x]) is the scaled probability of site D given the model M and the relative rate\n"); + PhyML_Fprintf(fp,"of evolution rr[x], where x is the class of rate to be considered.\n"); + PhyML_Fprintf(fp,"The actual conditional probability is given by P*(D|M,rr[x])/2^F, where\n"); + PhyML_Fprintf(fp,"F is the scaling factor (see column 'Scaler').\n"); + PhyML_Fprintf(fp,"For invariant sites, P(D|M,rr[0]=0) is the actual conditional probability\n"); + PhyML_Fprintf(fp,"(i.e., it is not scaled).\n"); + } + + PhyML_Fprintf(fp,"\n\n"); + + sprintf(s,"Site"); + PhyML_Fprintf(fp, "%-12s",s); + + sprintf(s,"P(D|M)"); + PhyML_Fprintf(fp,"%-15s",s); + + sprintf(s,"Scaler"); + PhyML_Fprintf(fp,"%-7s",s); + + sprintf(s,"Pattern"); + PhyML_Fprintf(fp, "%-9s",s); + + if(tree->mod->ras->n_catg > 1) + { + for(catg=0;catgmod->ras->n_catg;catg++) + { + sprintf(s,"P*(D|M,rr[%d]=%5.4f)",catg+1,tree->mod->ras->gamma_rr->v[catg]); + PhyML_Fprintf(fp,"%-23s",s); + } + + sprintf(s,"Posterior mean"); + PhyML_Fprintf(fp,"%-22s",s); + } + + + if(tree->mod->ras->invar) + { + sprintf(s,"P(D|M,rr[0]=0)"); + PhyML_Fprintf(fp,"%-16s",s); + } + + sprintf(s,"NDistinctStates"); + PhyML_Fprintf(fp,"%-16s",s); + + PhyML_Fprintf(fp,"\n"); + + Init_Ui_Tips(tree); + + for(site=0;sitedata->init_len;site++) + { + PhyML_Fprintf(fp,"%-12d",site+1); + + PhyML_Fprintf(fp,"%-15g",tree->cur_site_lk[tree->data->sitepatt[site]]); + + PhyML_Fprintf(fp,"%-7d",tree->fact_sum_scale[tree->data->sitepatt[site]]); + + PhyML_Fprintf(fp,"%-9d",tree->data->sitepatt[site]); + + if(tree->mod->ras->n_catg > 1) + { + for(catg=0;catgmod->ras->n_catg;catg++) + { + PhyML_Fprintf(fp,"%-23g",tree->unscaled_site_lk_cat[tree->data->sitepatt[site]*tree->mod->ras->n_catg + catg]); + } + + postmean = .0; + for(catg=0;catgmod->ras->n_catg;catg++) + postmean += + tree->mod->ras->gamma_rr->v[catg] * + tree->unscaled_site_lk_cat[tree->data->sitepatt[site]*tree->mod->ras->n_catg + catg] * + tree->mod->ras->gamma_r_proba->v[catg]; + + sum = .0; + for(catg=0;catgmod->ras->n_catg;catg++) + { + sum += + tree->unscaled_site_lk_cat[tree->data->sitepatt[site]*tree->mod->ras->n_catg + catg] * + tree->mod->ras->gamma_r_proba->v[catg]; + } + + postmean /= sum; + + PhyML_Fprintf(fp,"%-22g",postmean); + } + + if(tree->mod->ras->invar) + { + if((phydbl)tree->data->invar[tree->data->sitepatt[site]] > -0.5) + PhyML_Fprintf(fp,"%-16g",tree->mod->e_frq->pi->v[tree->data->invar[tree->data->sitepatt[site]]]); + else + PhyML_Fprintf(fp,"%-16g",0.0); + } + + + PhyML_Fprintf(fp,"%-16d",Number_Of_Diff_States_One_Site(tree->data->sitepatt[site],tree)); + + PhyML_Fprintf(fp,"\n"); + } + Free(s); + + } + else + { + for(site=0;sitedata->init_len;site++) + PhyML_Fprintf(fp,"%.2f\t",log(tree->cur_site_lk[tree->data->sitepatt[site]])); + PhyML_Fprintf(fp,"\n"); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Seq(FILE *fp, align **data, int n_otu) +{ + int i,j; + + PhyML_Fprintf(fp,"%d\t%d\n",n_otu,data[0]->len); + for(i=0;iname); + /* for(j=0;j<20;j++) */ + /* { */ + /* if(j<(int)strlen(data[i]->name)) */ + /* fputc(data[i]->name[j],fp); */ + /* else fputc(' ',fp); */ + /* } */ + /* PhyML_Printf("%10d ",i); */ + For(j,data[i]->len) + { + PhyML_Fprintf(fp,"%c",data[i]->state[j]); + } + PhyML_Fprintf(fp,"\n"); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_CSeq(FILE *fp, int compressed, calign *cdata, t_tree *tree) +{ + int i,j; + int n_otu; + + n_otu = cdata->n_otu; + if(cdata->format == PHYLIP) + { + PhyML_Fprintf(fp,"%d\t%d\n",n_otu,cdata->init_len); + } + else if(cdata->format == NEXUS) + { + PhyML_Fprintf(fp,"#NEXUS\n"); + PhyML_Fprintf(fp,"begin data\n"); + PhyML_Fprintf(fp,"dimensions ntax=%d nchar=%d;\n",n_otu,cdata->init_len); + PhyML_Fprintf(fp,"format sequential datatype=dna;\n"); + PhyML_Fprintf(fp,"matrix\n"); + } + else + { + PhyML_Fprintf(fp,"This sample file is to be processed by IBDSim (http://www1.montpellier.inra.fr/CBGP/software/ibdsim/)"); + } + + if(cdata->format == PHYLIP || cdata->format == NEXUS) + { + for(i=0;ic_seq[i]->name)) + fputc(cdata->c_seq[i]->name[j],fp); + else fputc(' ',fp); + } + + if(compressed == YES) /* Print out compressed sequences */ + PhyML_Fprintf(fp,"%s",cdata->c_seq[i]->state); + else /* Print out uncompressed sequences */ + { + for(j=0;jinit_len;j++) + { + PhyML_Fprintf(fp,"%c",cdata->c_seq[i]->state[cdata->sitepatt[j]]); + } + } + PhyML_Fprintf(fp,"\n"); + } + PhyML_Fprintf(fp,"\n"); + + if(cdata->format == NEXUS) + { + PhyML_Fprintf(fp,";\n"); + PhyML_Fprintf(fp,"END;\n"); + } + } + else if(cdata->format == IBDSIM) + { + for(i=0;iinit_len;i++) PhyML_Fprintf(fp,"\nlocus %6d",i); + for(i=0;ia_nodes[i]->coord->lonlat[0], + tree->a_nodes[i]->coord->lonlat[1]); + for(j=0;jinit_len;j++) + { + switch(tree->a_nodes[i]->c_seq->state[j]) + { + case 'A' : + { + PhyML_Fprintf(fp,"001 "); + break; + } + case 'C' : + { + PhyML_Fprintf(fp,"002 "); + break; + } + case 'G' : + { + PhyML_Fprintf(fp,"003 "); + break; + } + case 'T' : + { + PhyML_Fprintf(fp,"004 "); + break; + } + } + } + } + } + /* PhyML_Printf("\t"); */ + /* for(j=0;jcrunch_len;j++) */ + /* PhyML_Printf("%.0f ",cdata->wght[j]); */ + /* PhyML_Printf("\n"); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_CSeq_Select(FILE *fp, int compressed, calign *cdata, t_tree *tree) +{ + int i,j; + int n_otu; + phydbl eps; + + int slice = 14; + + eps = 1.E-6; + n_otu = 0; + for(i=0;in_otu;i++) + if(tree->rates->nd_t[i] < tree->rates->time_slice_lims[slice] + eps) + n_otu++; + + PhyML_Fprintf(fp,"%d\t%d\n",n_otu,cdata->init_len); + + n_otu = cdata->n_otu; + + for(i=0;irates->nd_t[i] < tree->rates->time_slice_lims[slice] + eps) + { + for(j=0;j<50;j++) + { + if(j<(int)strlen(cdata->c_seq[i]->name)) + fputc(cdata->c_seq[i]->name[j],fp); + else fputc(' ',fp); + } + + if(compressed == YES) /* Print out compressed sequences */ + PhyML_Fprintf(fp,"%s",cdata->c_seq[i]->state); + else /* Print out uncompressed sequences */ + { + for(j=0;jinit_len;j++) + { + PhyML_Fprintf(fp,"%c",cdata->c_seq[i]->state[cdata->sitepatt[j]]); + } + } + PhyML_Fprintf(fp,"\n"); + } + } + + if(cdata->format == 1) + { + PhyML_Fprintf(fp,";\n"); + PhyML_Fprintf(fp,"END;\n"); + } + + +/* PhyML_Printf("\t"); */ +/* for(j=0;jcrunch_len;j++) */ +/* PhyML_Printf("%.0f ",cdata->wght[j]); */ +/* PhyML_Printf("\n"); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Dist(matrix *mat) +{ + int i,j; + + for(i=0;in_otu;i++) + { + PhyML_Printf("%s ",mat->name[i]); + + for(j=0;jn_otu;j++) + PhyML_Printf("%9.6f ",mat->dist[i][j]); + PhyML_Printf("\n"); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Node(t_node *a, t_node *d, t_tree *tree) +{ + int i; + int dir; + dir = -1; + for(i=0;i<3;i++) if(a->v[i] == d) {dir = i; break;} + PhyML_Printf("Node nums: %3d %3d (dir:%3d) (a->anc:%3d) (d->anc:%3d) ta:%8.4f td:%8.4f t_min:%6.2f t_max:%6.2f", + a->num,d->num,dir,a->anc?a->anc->num:(-1), + d->anc?d->anc->num:(-1), + tree->rates?tree->rates->nd_t[a->num]:-1., + tree->rates?tree->rates->nd_t[d->num]:-1., + tree->rates?tree->rates->t_prior_min[a->num]:-1., + tree->rates?tree->rates->t_prior_max[a->num]:-1.); + + PhyML_Printf(" names = '%10s' '%10s' ; ",a->name,d->name); + for(i=0;i<3;i++) if(a->v[i] == d) + { + if(a->b[i]) + { + PhyML_Printf("Branch num = %3d%c (%3d %3d) %f", + a->b[i]->num,a->b[i]==tree->e_root?'*':' ',a->b[i]->left->num, + a->b[i]->rght->num,a->b[i]->l->v); + if(a->b[i]->left->tax) PhyML_Printf(" WARNING LEFT->TAX!"); + break; + } + } + PhyML_Printf("\n"); + + if(d->tax) return; + else + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) Print_Node(d,d->v[i],tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Node_Brief(t_node *a, t_node *d, t_tree *tree, FILE *fp) +{ + int i; + int dir; + + dir = -1; + for(i=0;i<3;i++) if(a->v[i] == d) {dir = i; break;} + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"Node nums: %3d %3d (dir:%3d)", + a->num,d->num,dir); + + PhyML_Fprintf(fp,"\tnames = '%10s' '%10s' ; ",a->name,d->name); + for(i=0;i<3;i++) if(a->v[i] == d) + { + if(a->b[i]) + { + PhyML_Fprintf(fp,"Branch num = %3d%c (%3d %3d) length:%10f", + a->b[i]->num,a->b[i]==tree->e_root?'*':' ',a->b[i]->left->num, + a->b[i]->rght->num,a->b[i]->l->v); + if(a->b[i]->left->tax) PhyML_Printf(" WARNING LEFT->TAX!"); + break; + } + } + + if(d->tax) return; + else + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) Print_Node_Brief(d,d->v[i],tree,fp); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Model(t_mod *mod) +{ + int i,j,k; + + PhyML_Printf("\n. name=%s",mod->modelname->s); + PhyML_Printf("\n. string=%s",mod->custom_mod_string); + PhyML_Printf("\n. mod_num=%d",mod->mod_num); + PhyML_Printf("\n. ns=%d",mod->ns); + PhyML_Printf("\n. n_catg=%d",mod->ras->n_catg); + PhyML_Printf("\n. kappa=%f",mod->kappa->v); + PhyML_Printf("\n. alpha=%f",mod->ras->alpha->v); + PhyML_Printf("\n. lambda=%f",mod->lambda->v); + PhyML_Printf("\n. pinvar=%f",mod->ras->pinvar->v); + PhyML_Printf("\n. br_len_mult=%f",mod->br_len_mult->v); + PhyML_Printf("\n. whichmodel=%d",mod->whichmodel); + PhyML_Printf("\n. update_eigen=%d",mod->update_eigen); + PhyML_Printf("\n. bootstrap=%d",mod->io->n_boot_replicates); + PhyML_Printf("\n. n_diff_rr=%d",mod->r_mat->n_diff_rr); + PhyML_Printf("\n. invar=%d",mod->ras->invar); + PhyML_Printf("\n. use_m4mod=%d",mod->use_m4mod); + PhyML_Printf("\n. gamma_median=%d",mod->ras->gamma_median); + PhyML_Printf("\n. state_len=%d",mod->io->state_len); + PhyML_Printf("\n. log_l=%d",mod->log_l); + PhyML_Printf("\n. l_min=%f",mod->l_min); + PhyML_Printf("\n. l_max=%f",mod->l_max); + PhyML_Printf("\n. free_mixt_rates=%d",mod->ras->free_mixt_rates); + PhyML_Printf("\n. gamma_mgf_bl=%d",mod->gamma_mgf_bl); + + PhyML_Printf("\n. Pi\n"); + for(i=0;ins;i++) PhyML_Printf(" %f ",mod->e_frq->pi->v[i]); + PhyML_Printf("\n"); + for(i=0;ins;i++) PhyML_Printf(" %f ",mod->e_frq->pi_unscaled->v[i]); + + PhyML_Printf("\n. Rates\n"); + for(i=0;iras->n_catg;i++) PhyML_Printf(" %f ",mod->ras->gamma_r_proba->v[i]); + PhyML_Printf("\n"); + for(i=0;iras->n_catg;i++) PhyML_Printf(" %f ",mod->ras->gamma_r_proba_unscaled->v[i]); + PhyML_Printf("\n"); + for(i=0;iras->n_catg;i++) PhyML_Printf(" %f ",mod->ras->gamma_rr->v[i]); + PhyML_Printf("\n"); + for(i=0;iras->n_catg;i++) PhyML_Printf(" %f ",mod->ras->gamma_rr_unscaled->v[i]); + + + + PhyML_Printf("\n. Qmat \n"); + if(mod->whichmodel == CUSTOM) + { + fflush(NULL); + for(i=0;i<6;i++) {PhyML_Printf(" %12f ",mod->r_mat->rr->v[i]); fflush(NULL);} + for(i=0;i<6;i++) {PhyML_Printf(" %12f ",mod->r_mat->rr_val->v[i]); fflush(NULL);} + for(i=0;i<6;i++) {PhyML_Printf(" %12d ",mod->r_mat->rr_num->v[i]); fflush(NULL);} + for(i=0;i<6;i++) {PhyML_Printf(" %12d ",mod->r_mat->n_rr_per_cat->v[i]); fflush(NULL);} + } + for(i=0;ins;i++) + { + PhyML_Printf(" "); + for(j=0;j<4;j++) + PhyML_Printf("%8.5f ",mod->r_mat->qmat->v[i*4+j]); + PhyML_Printf("\n"); + } + + PhyML_Printf("\n. Freqs"); + PhyML_Printf("\n"); + for(i=0;ins;i++) PhyML_Printf(" %12f ",mod->e_frq->user_b_freq->v[i]); + PhyML_Printf("\n"); + for(i=0;ins;i++) PhyML_Printf(" %12f ",mod->e_frq->pi->v[i]); + PhyML_Printf("\n"); + for(i=0;ins;i++) PhyML_Printf(" %12f ",mod->e_frq->pi_unscaled->v[i]); + + PhyML_Printf("\n. Eigen\n"); + For(i,2*mod->ns) PhyML_Printf(" %f ",mod->eigen->space[i]); + /* PhyML_Printf("\n"); */ + /* For(i,2*mod->ns) PhyML_Printf(" %f ",mod->eigen->space_int[i]); */ + PhyML_Printf("\n"); + for(i=0;ins;i++) PhyML_Printf(" %f ",mod->eigen->e_val[i]); + PhyML_Printf("\n"); + for(i=0;ins;i++) PhyML_Printf(" %f ",mod->eigen->e_val_im[i]); + PhyML_Printf("\n"); + For(i,mod->ns*mod->ns) PhyML_Printf(" %f ",mod->eigen->r_e_vect[i]); + PhyML_Printf("\n"); + For(i,mod->ns*mod->ns) PhyML_Printf(" %f ",mod->eigen->r_e_vect_im[i]); + PhyML_Printf("\n"); + For(i,mod->ns*mod->ns) PhyML_Printf(" %f ",mod->eigen->l_e_vect[i]); + PhyML_Printf("\n"); + For(i,mod->ns*mod->ns) PhyML_Printf(" %f ",mod->eigen->q[i]); + PhyML_Printf("\n"); + + PhyML_Printf("\n. Pij"); + for(k=0;kras->n_catg;k++) + { + PMat(0.01*mod->ras->gamma_rr->v[k],mod,mod->ns*mod->ns*k,mod->Pij_rr->v,NULL); + PhyML_Printf("\n. l=%f\n",0.01*mod->ras->gamma_rr->v[k]); + for(i=0;ins;i++) + { + PhyML_Printf(" "); + for(j=0;jns;j++) + PhyML_Printf("%8.5f ",mod->Pij_rr->v[k*mod->ns*mod->ns+i*mod->ns+j]); + PhyML_Printf("\n"); + } + } + + PhyML_Printf("\n"); + + fflush(NULL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Mat(matrix *mat) +{ + int i,j; + + PhyML_Printf("%d",mat->n_otu); + PhyML_Printf("\n"); + + for(i=0;in_otu;i++) + { + for(j=0;j<13;j++) + { + if(j>=(int)strlen(mat->name[i])) putchar(' '); + else putchar(mat->name[i][j]); + } + + for(j=0;jn_otu;j++) + { + char s[2]="-"; + if(mat->dist[i][j] < .0) + PhyML_Printf("%12s",s); + else + PhyML_Printf("%12f",mat->dist[i][j]); + } + PhyML_Printf("\n"); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +FILE *Openfile(char *filename, int mode) +{ + FILE *fp; + char *s; + int open_test=0; + + s = filename; + + fp = NULL; + + switch(mode) + { + case READ : + { + while(!(fp = (FILE *)fopen(s,"r")) && ++open_test<10) + { + PhyML_Printf("\n. Can't open file '%s', enter a new name : ",s); + Getstring_Stdin(s); + } + break; + } + case WRITE : + { + fp = (FILE *)fopen(s,"w"); + break; + } + case APPEND : + { + fp = (FILE *)fopen(s,"a"); + break; + } + case READWRITE : + { + fp = (FILE *)fopen(s,"w+"); + break; + } + + default : break; + + } + +/* Free(s); */ + + return fp; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Fp_Out(FILE *fp_out, time_t t_beg, time_t t_end, t_tree *tree, option *io, int n_data_set, int num_tree, int add_citation, int precision) +{ + char *s; + char format[8]; + div_t hour,min; + int i, j; + + if (precision > 0) snprintf (format, 8, "%%.%df", precision); + + if(n_data_set == 1) + { + rewind(fp_out); + Print_Banner_Small(fp_out); + } + + PhyML_Fprintf(fp_out,"\n. Sequence filename: \t\t\t%s", Basename(io->in_align_file)); + PhyML_Fprintf(fp_out,"\n. Data set: \t\t\t\t#%d",n_data_set); + + if(io->mod->s_opt->random_input_tree) PhyML_Fprintf(fp_out,"\n. Random init tree: \t\t\t#%d",num_tree+1); + else if(io->n_trees > 1) PhyML_Fprintf(fp_out,"\n. Starting tree number: \t\t#%d",num_tree+1); + + /* if(io->mod->s_opt->opt_topo) */ + /* PhyML_Fprintf(fp_out,"\n. Tree topology search: \t\tSPRs"); */ + /* else */ + /* PhyML_Fprintf(fp_out,"\n. Tree topology: \t\t\tfixed"); */ + + /* was after Sequence file ; moved here FLT */ + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + if(io->in_tree == 2) + { + strcat(strcat(strcat(s,"user tree ("),io->in_tree_file),")"); + } + else + { + if(!io->mod->s_opt->random_input_tree) + { + if(io->in_tree == 0) strcat(s,"BioNJ"); + if(io->in_tree == 1) strcat(s,"parsimony"); + } + else + strcat(s,"random tree"); + } + + PhyML_Fprintf(fp_out,"\n. Initial tree: \t\t\t%s",s); + Free(s); + + if(tree->io->datatype == NT) + { + PhyML_Fprintf(fp_out,"\n. Model of nucleotides substitution: \t%s",tree->mod->modelname->s); + if(io->mod->whichmodel == CUSTOM) + PhyML_Fprintf(fp_out," (%s)",io->mod->custom_mod_string); + } + else if(tree->io->datatype == AA) + { + PhyML_Fprintf(fp_out,"\n. Model of amino acids substitution: \t%s",tree->mod->modelname->s); + if(io->mod->whichmodel == CUSTOMAA) PhyML_Fprintf(fp_out," (%s)",tree->mod->aa_rate_mat_file->s); + } + else + { + fprintf(fp_out,"\n. Substitution model: \t\t\t%s",tree->mod->modelname->s); + } + + PhyML_Fprintf(fp_out,"\n. Number of taxa: \t\t\t%d",tree->n_otu);/*added FLT*/ + + PhyML_Fprintf(fp_out,"\n. Log-likelihood: \t\t\t%.5f",tree->c_lnL);/*was last ; moved here FLT*/ + + Unconstraint_Lk(tree); + PhyML_Fprintf(fp_out,"\n. Unconstrained log-likelihood: \t%.5f",tree->unconstraint_lk); + + Composite_Lk(tree); + PhyML_Fprintf(fp_out,"\n. Composite log-likelihood: \t\t%.5f",tree->composite_lk); + + PhyML_Fprintf(fp_out,"\n. Parsimony: \t\t\t\t%d",tree->c_pars); + + PhyML_Fprintf(fp_out,"\n. Tree size: \t\t\t\t%.5f",Get_Tree_Size(tree)); + + /* if(tree->mod->ras->n_catg > 1 && tree->mod->ras->free_mixt_rates == NO) */ + if(tree->mod->ras->free_mixt_rates == NO) + { + PhyML_Fprintf(fp_out,"\n. Discrete gamma model: \t\t%s","Yes"); + PhyML_Fprintf(fp_out,"\n - Number of classes: \t\t\t%d",tree->mod->ras->n_catg); + PhyML_Fprintf(fp_out,"\n - Gamma shape parameter: \t\t%.3f",tree->mod->ras->alpha->v); + for(i=0;imod->ras->n_catg;i++) + { + PhyML_Fprintf(fp_out,"\n - Relative rate in class %d: \t\t%.5f [freq=%4f] \t\t",i+1,tree->mod->ras->gamma_rr->v[i],tree->mod->ras->gamma_r_proba->v[i]); + } + } + else if(tree->mod->ras->free_mixt_rates == YES) + { + int *rk; + rk = Ranks(tree->mod->ras->gamma_rr->v,tree->mod->ras->n_catg); + PhyML_Fprintf(fp_out,"\n. FreeRate model: \t\t\t%s","Yes"); + PhyML_Fprintf(fp_out,"\n - Number of classes: \t\t\t%d",tree->mod->ras->n_catg); + for(i=0;imod->ras->n_catg;i++) + { + PhyML_Fprintf(fp_out,"\n - Relative rate in class %d: \t\t%.5f [freq=%4f] \t\t",i+1,tree->mod->ras->gamma_rr->v[rk[i]],tree->mod->ras->gamma_r_proba->v[rk[i]]); + } + Free(rk); + } + + if(tree->mod->ras->invar) PhyML_Fprintf(fp_out,"\n. Proportion of invariant: \t\t%.3f",tree->mod->ras->pinvar->v); + + if(tree->mod->gamma_mgf_bl == YES) PhyML_Fprintf(fp_out,"\n. Variance of branch lengths: \t\t%f",tree->mod->l_var_sigma); + + + /*was before Discrete gamma model ; moved here FLT*/ + if((tree->mod->whichmodel == K80) || + (tree->mod->whichmodel == HKY85) || + (tree->mod->whichmodel == F84)) + { + PhyML_Fprintf(fp_out,"\n. Transition/transversion ratio: \t"); + if (precision > 0) + PhyML_Fprintf(fp_out,format,tree->mod->kappa->v); + else + PhyML_Fprintf(fp_out,"%f",tree->mod->kappa->v); + } + else if(tree->mod->whichmodel == TN93) + { + PhyML_Fprintf(fp_out,"\n. Transition/transversion ratio for purines: \t\t"); + if (precision > 0) + PhyML_Fprintf(fp_out,format,tree->mod->kappa->v*2.*tree->mod->lambda->v/(1.+tree->mod->lambda->v)); + else + PhyML_Fprintf(fp_out,"%f",tree->mod->kappa->v*2.*tree->mod->lambda->v/(1.+tree->mod->lambda->v)); + + PhyML_Fprintf(fp_out,"\n. Transition/transversion ratio for pyrimidines: \t"); + if (precision > 0) + PhyML_Fprintf(fp_out,format,tree->mod->kappa->v*2./(1.+tree->mod->lambda->v)); + else + PhyML_Fprintf(fp_out,"%f",tree->mod->kappa->v*2./(1.+tree->mod->lambda->v)); + } + + if(tree->io->datatype == NT) + { + PhyML_Fprintf(fp_out,"\n. Nucleotides frequencies:"); + if (precision > 0) + { + PhyML_Fprintf(fp_out,"\n - f(A)= "); + PhyML_Fprintf(fp_out,format,tree->mod->e_frq->pi->v[0]); + PhyML_Fprintf(fp_out,"\n - f(C)= "); + PhyML_Fprintf(fp_out,format,tree->mod->e_frq->pi->v[1]); + PhyML_Fprintf(fp_out,"\n - f(G)= "); + PhyML_Fprintf(fp_out,format,tree->mod->e_frq->pi->v[2]); + PhyML_Fprintf(fp_out,"\n - f(T)= "); + PhyML_Fprintf(fp_out,format,tree->mod->e_frq->pi->v[3]); + } + else + { + PhyML_Fprintf(fp_out,"\n - f(A)= %8.5f",tree->mod->e_frq->pi->v[0]); + PhyML_Fprintf(fp_out,"\n - f(C)= %8.5f",tree->mod->e_frq->pi->v[1]); + PhyML_Fprintf(fp_out,"\n - f(G)= %8.5f",tree->mod->e_frq->pi->v[2]); + PhyML_Fprintf(fp_out,"\n - f(T)= %8.5f",tree->mod->e_frq->pi->v[3]); + } + } + + /*****************************************/ + if((tree->mod->whichmodel == GTR) || + (tree->mod->whichmodel == CUSTOM)) + { + Update_Qmat_GTR(tree->mod->r_mat->rr->v, + tree->mod->r_mat->rr_val->v, + tree->mod->r_mat->rr_num->v, + tree->mod->e_frq->pi->v, + tree->mod->r_mat->qmat->v, + tree->mod->s_opt->opt_rr); + + PhyML_Fprintf(fp_out,"\n"); + PhyML_Fprintf(fp_out,". GTR relative rate parameters :"); + if (precision > 0) + { + PhyML_Fprintf(fp_out,"\n A <-> C "); + if (tree->mod->r_mat->rr->v[0] < 10) + PhyML_Fprintf(fp_out," "); + PhyML_Fprintf(fp_out,format, tree->mod->r_mat->rr->v[0]); + PhyML_Fprintf(fp_out,"\n A <-> G "); + if (tree->mod->r_mat->rr->v[1] < 10) + PhyML_Fprintf(fp_out," "); + PhyML_Fprintf(fp_out,format, tree->mod->r_mat->rr->v[1]); + PhyML_Fprintf(fp_out,"\n A <-> T "); + if (tree->mod->r_mat->rr->v[2] < 10) + PhyML_Fprintf(fp_out," "); + PhyML_Fprintf(fp_out,format, tree->mod->r_mat->rr->v[2]); + PhyML_Fprintf(fp_out,"\n C <-> G "); + if (tree->mod->r_mat->rr->v[3] < 10) + PhyML_Fprintf(fp_out," "); + PhyML_Fprintf(fp_out,format, tree->mod->r_mat->rr->v[3]); + PhyML_Fprintf(fp_out,"\n C <-> T "); + if (tree->mod->r_mat->rr->v[4] < 10) + PhyML_Fprintf(fp_out," "); + PhyML_Fprintf(fp_out,format, tree->mod->r_mat->rr->v[4]); + PhyML_Fprintf(fp_out,"\n G <-> T "); + if (tree->mod->r_mat->rr->v[5] < 10) + PhyML_Fprintf(fp_out," "); + PhyML_Fprintf(fp_out,format, tree->mod->r_mat->rr->v[5]); + } + else + { + PhyML_Fprintf(fp_out,"\n A <-> C %8.5f", tree->mod->r_mat->rr->v[0]); + PhyML_Fprintf(fp_out,"\n A <-> G %8.5f", tree->mod->r_mat->rr->v[1]); + PhyML_Fprintf(fp_out,"\n A <-> T %8.5f", tree->mod->r_mat->rr->v[2]); + PhyML_Fprintf(fp_out,"\n C <-> G %8.5f", tree->mod->r_mat->rr->v[3]); + PhyML_Fprintf(fp_out,"\n C <-> T %8.5f", tree->mod->r_mat->rr->v[4]); + PhyML_Fprintf(fp_out,"\n G <-> T %8.5f", tree->mod->r_mat->rr->v[5]); + } + + PhyML_Fprintf(fp_out,"\n. Instantaneous rate matrix : "); + if (precision > 0) + { + PhyML_Fprintf(fp_out,"\n [A"); + for(i=0;imod->r_mat->qmat->v[i*4+j]); + } + PhyML_Fprintf(fp_out,"\n"); + } + } + else + { + PhyML_Fprintf(fp_out,"\n [A---------C---------G---------T------]\n"); + for(i=0;i<4;i++) + { + PhyML_Fprintf(fp_out," "); + for(j=0;j<4;j++) + PhyML_Fprintf(fp_out,"%8.5f ",tree->mod->r_mat->qmat->v[i*4+j]); + PhyML_Fprintf(fp_out,"\n"); + } + } + //PhyML_Fprintf(fp_out,"\n"); + } + + /*****************************************/ + if(io->ratio_test == 1) + { + PhyML_Fprintf(fp_out,". aLRT statistics to test branches"); + } + else if(io->ratio_test == 2) + { + PhyML_Fprintf(fp_out,". aLRT branch supports (cubic approximation, mixture of Chi2s distribution)"); + } + + PhyML_Fprintf(fp_out,"\n"); + PhyML_Fprintf(fp_out,"\n. Run ID:\t\t\t\t%s", (io->append_run_ID) ? (io->run_id_string): ("none")); + PhyML_Fprintf(fp_out,"\n. Random seed:\t\t\t\t%d", io->r_seed); + PhyML_Fprintf(fp_out,"\n. Subtree patterns aliasing:\t\t%s",io->do_alias_subpatt?"yes":"no"); + PhyML_Fprintf(fp_out,"\n. Version:\t\t\t\t%s", VERSION); + + hour = div(t_end-t_beg,3600); + min = div(t_end-t_beg,60 ); + min.quot -= hour.quot*60; + + PhyML_Fprintf(fp_out,"\n. Time used:\t\t\t\t%dh%dm%ds (%d seconds)", hour.quot,min.quot,(int)(t_end-t_beg)%60,(int)(t_end-t_beg)); + + if(add_citation == YES) + { + PhyML_Fprintf(fp_out,"\n\n"); + PhyML_Fprintf(fp_out," oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); + PhyML_Fprintf(fp_out," Suggested citations:\n"); + PhyML_Fprintf(fp_out," S. Guindon, JF. Dufayard, V. Lefort, M. Anisimova, W. Hordijk, O. Gascuel\n"); + PhyML_Fprintf(fp_out," \"New algorithms and methods to estimate maximum-likelihood phylogenies: assessing the performance of PhyML 3.0.\"\n"); + PhyML_Fprintf(fp_out," Systematic Biology. 2010. 59(3):307-321.\n"); + PhyML_Fprintf(fp_out,"\n"); + PhyML_Fprintf(fp_out," S. Guindon & O. Gascuel\n"); + PhyML_Fprintf(fp_out," \"A simple, fast, and accurate algorithm to estimate large phylogenies by maximum likelihood\"\n"); + PhyML_Fprintf(fp_out," Systematic Biology. 2003. 52(5):696-704.\n"); + PhyML_Fprintf(fp_out," oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); + } + else + { + PhyML_Fprintf(fp_out,"\n\n"); + PhyML_Fprintf(fp_out," oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); + PhyML_Fprintf(fp_out,"\n"); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/*FLT wrote this function*/ +void Print_Fp_Out_Lines(FILE *fp_out, time_t t_beg, time_t t_end, t_tree *tree, option *io, int n_data_set) +{ + char *s; + /*div_t hour,min;*/ + + if (n_data_set==1) + { + + PhyML_Fprintf(fp_out,". Sequence file : [%s]\n\n", Basename(io->in_align_file)); + + if((tree->io->datatype == NT) || (tree->io->datatype == AA)) + { + (tree->io->datatype == NT)? + (PhyML_Fprintf(fp_out,". Model of nucleotides substitution : %s\n\n",io->mod->modelname->s)): + (PhyML_Fprintf(fp_out,". Model of amino acids substitution : %s\n\n",io->mod->modelname->s)); + } + + s = (char *)mCalloc(100,sizeof(char)); + + switch(io->in_tree) + { + case 0: { strcpy(s,"BioNJ"); break; } + case 1: { strcpy(s,"parsimony"); break; } + case 2: { strcpy(s,"user tree ("); + strcat(s,io->in_tree_file); + strcat(s,")"); break; } + } + + PhyML_Fprintf(fp_out,". Initial tree : [%s]\n\n",s); + + Free(s); + + PhyML_Fprintf(fp_out,"\n"); + + /*headline 1*/ + PhyML_Fprintf(fp_out, ". Data\t"); + + PhyML_Fprintf(fp_out,"Nb of \t"); + + PhyML_Fprintf(fp_out,"Likelihood\t"); + + PhyML_Fprintf(fp_out, "Discrete \t"); + + if(tree->mod->ras->n_catg > 1) + PhyML_Fprintf(fp_out, "Number of \tGamma shape\t"); + + PhyML_Fprintf(fp_out,"Proportion of\t"); + + if(tree->mod->whichmodel <= 6) + PhyML_Fprintf(fp_out,"Transition/ \t"); + + PhyML_Fprintf(fp_out,"Nucleotides frequencies \t"); + + if((tree->mod->whichmodel == GTR) || + (tree->mod->whichmodel == CUSTOM)) + PhyML_Fprintf(fp_out,"Instantaneous rate matrix \t"); + + /* PhyML_Fprintf(fp_out,"Time\t");*/ + + PhyML_Fprintf(fp_out, "\n"); + + + /*headline 2*/ + PhyML_Fprintf(fp_out, " set\t"); + + PhyML_Fprintf(fp_out,"taxa\t"); + + PhyML_Fprintf(fp_out,"loglk \t"); + + PhyML_Fprintf(fp_out, "gamma model\t"); + + if(tree->mod->ras->n_catg > 1) + PhyML_Fprintf(fp_out, "categories\tparameter \t"); + + PhyML_Fprintf(fp_out,"invariant \t"); + + if(tree->mod->whichmodel <= 6) + PhyML_Fprintf(fp_out,"transversion\t"); + + PhyML_Fprintf(fp_out,"f(A) f(C) f(G) f(T) \t"); + + if((tree->mod->whichmodel == GTR) || + (tree->mod->whichmodel == CUSTOM)) + PhyML_Fprintf(fp_out,"[A---------C---------G---------T------]\t"); + + /* PhyML_PhyML_Fprintf(fp_out,"used\t");*/ + + PhyML_Fprintf(fp_out, "\n"); + + + /*headline 3*/ + if(tree->mod->whichmodel == TN93) + { + PhyML_Fprintf(fp_out," \t \t \t \t"); + if(tree->mod->ras->n_catg > 1) PhyML_Fprintf(fp_out," \t \t"); + PhyML_Fprintf(fp_out," \t"); + PhyML_Fprintf(fp_out,"purines pyrimid.\t"); + PhyML_Fprintf(fp_out, "\n"); + } + + PhyML_Fprintf(fp_out, "\n"); + } + + + /*line items*/ + + PhyML_Fprintf(fp_out," #%d\t",n_data_set); + + PhyML_Fprintf(fp_out,"%d \t",tree->n_otu); + + PhyML_Fprintf(fp_out,"%.5f\t",tree->c_lnL); + + PhyML_Fprintf(fp_out,"%s \t", + (tree->mod->ras->n_catg>1)?("Yes"):("No ")); + if(tree->mod->ras->n_catg > 1) + { + PhyML_Fprintf(fp_out,"%d \t",tree->mod->ras->n_catg); + PhyML_Fprintf(fp_out,"%.3f \t",tree->mod->ras->alpha->v); + } + + /*if(tree->mod->ras->invar)*/ + PhyML_Fprintf(fp_out,"%.3f \t",tree->mod->ras->pinvar->v); + + if(tree->mod->whichmodel <= 5) + { + PhyML_Fprintf(fp_out,"%.3f \t",tree->mod->kappa->v); + } + else if(tree->mod->whichmodel == TN93) + { + PhyML_Fprintf(fp_out,"%.3f ", + tree->mod->kappa->v*2.*tree->mod->lambda->v/(1.+tree->mod->lambda->v)); + PhyML_Fprintf(fp_out,"%.3f\t", + tree->mod->kappa->v*2./(1.+tree->mod->lambda->v)); + } + + + if(tree->io->datatype == NT) + { + PhyML_Fprintf(fp_out,"%8.5f ",tree->mod->e_frq->pi->v[0]); + PhyML_Fprintf(fp_out,"%8.5f ",tree->mod->e_frq->pi->v[1]); + PhyML_Fprintf(fp_out,"%8.5f ",tree->mod->e_frq->pi->v[2]); + PhyML_Fprintf(fp_out,"%8.5f\t",tree->mod->e_frq->pi->v[3]); + } + /* + hour = div(t_end-t_beg,3600); + min = div(t_end-t_beg,60 ); + + min.quot -= hour.quot*60; + + PhyML_Fprintf(fp_out,"%dh%dm%ds\t", hour.quot,min.quot,(int)(t_end-t_beg)%60); + if(t_end-t_beg > 60) + PhyML_Fprintf(fp_out,". -> %d seconds\t",(int)(t_end-t_beg)); + */ + + /*****************************************/ + if((tree->mod->whichmodel == GTR) || (tree->mod->whichmodel == CUSTOM)) + { + int i,j; + + for(i=0;i<4;i++) + { + if (i!=0) { + /*format*/ + PhyML_Fprintf(fp_out," \t \t \t \t"); + if(tree->mod->ras->n_catg > 1) PhyML_Fprintf(fp_out," \t \t"); + PhyML_Fprintf(fp_out," \t \t"); + } + for(j=0;j<4;j++) + PhyML_Fprintf(fp_out,"%8.5f ",tree->mod->r_mat->qmat->v[i*4+j]); + if (i<3) PhyML_Fprintf(fp_out,"\n"); + } + } + /*****************************************/ + + PhyML_Fprintf(fp_out, "\n\n"); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Print_Freq(t_tree *tree) +{ + + switch(tree->io->datatype) + { + case NT: + { + PhyML_Printf("A : %f\n",tree->mod->e_frq->pi->v[0]); + PhyML_Printf("C : %f\n",tree->mod->e_frq->pi->v[1]); + PhyML_Printf("G : %f\n",tree->mod->e_frq->pi->v[2]); + PhyML_Printf("T : %f\n",tree->mod->e_frq->pi->v[3]); + break; + } + case AA: + { + PhyML_Printf("A : %f\n",tree->mod->e_frq->pi->v[0]); + PhyML_Printf("R : %f\n",tree->mod->e_frq->pi->v[1]); + PhyML_Printf("N : %f\n",tree->mod->e_frq->pi->v[2]); + PhyML_Printf("D : %f\n",tree->mod->e_frq->pi->v[3]); + PhyML_Printf("C : %f\n",tree->mod->e_frq->pi->v[4]); + PhyML_Printf("Q : %f\n",tree->mod->e_frq->pi->v[5]); + PhyML_Printf("E : %f\n",tree->mod->e_frq->pi->v[6]); + PhyML_Printf("G : %f\n",tree->mod->e_frq->pi->v[7]); + PhyML_Printf("H : %f\n",tree->mod->e_frq->pi->v[8]); + PhyML_Printf("I : %f\n",tree->mod->e_frq->pi->v[9]); + PhyML_Printf("L : %f\n",tree->mod->e_frq->pi->v[10]); + PhyML_Printf("K : %f\n",tree->mod->e_frq->pi->v[11]); + PhyML_Printf("M : %f\n",tree->mod->e_frq->pi->v[12]); + PhyML_Printf("F : %f\n",tree->mod->e_frq->pi->v[13]); + PhyML_Printf("P : %f\n",tree->mod->e_frq->pi->v[14]); + PhyML_Printf("S : %f\n",tree->mod->e_frq->pi->v[15]); + PhyML_Printf("T : %f\n",tree->mod->e_frq->pi->v[16]); + PhyML_Printf("W : %f\n",tree->mod->e_frq->pi->v[17]); + PhyML_Printf("Y : %f\n",tree->mod->e_frq->pi->v[18]); + PhyML_Printf("V : %f\n",tree->mod->e_frq->pi->v[19]); + PhyML_Printf("N : %f\n",tree->mod->e_frq->pi->v[20]); + break; + } + default : {break;} + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Print_Settings(option *io) +{ + int answer; + char *s; + + s = (char *)mCalloc(100,sizeof(char)); + + PhyML_Printf("\n\n\n"); + PhyML_Printf("\n\n"); + + + PhyML_Printf("\n ////////////////////////////////////.\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"); + PhyML_Printf("\n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\.//////////////////////////////////////////\n"); + + PhyML_Printf("\n . Sequence filename:\t\t\t\t %s", Basename(io->in_align_file)); + + if(io->datatype == NT) strcpy(s,"dna"); + else if(io->datatype == AA) strcpy(s,"aa"); + else strcpy(s,"generic"); + + PhyML_Printf("\n . Data type:\t\t\t\t\t %s",s); + PhyML_Printf("\n . Alphabet size:\t\t\t\t %d",io->mod->ns); + + PhyML_Printf("\n . Sequence format:\t\t\t\t %s", io->interleaved ? "interleaved": "sequential"); + PhyML_Printf("\n . Number of data sets:\t\t\t\t %d", io->n_data_sets); + + PhyML_Printf("\n . Nb of bootstrapped data sets:\t\t\t %d", io->n_boot_replicates); + + if (io->n_boot_replicates > 0) + PhyML_Printf("\n . Compute approximate likelihood ratio test:\t no"); + else + { + if(io->ratio_test == 1) + PhyML_Printf("\n . Compute approximate likelihood ratio test:\t yes (aLRT statistics)"); + else if(io->ratio_test == 2) + PhyML_Printf("\n . Compute approximate likelihood ratio test:\t yes (Chi2-based parametric branch supports)"); + else if(io->ratio_test == 3) + PhyML_Printf("\n . Compute approximate likelihood ratio test:\t yes (Minimum of SH-like and Chi2-based branch supports)"); + else if(io->ratio_test == 4) + PhyML_Printf("\n . Compute approximate likelihood ratio test:\t yes (SH-like branch supports)"); + else if(io->ratio_test == 5) + PhyML_Printf("\n . Compute approximate likelihood ratio test:\t yes (aBayes branch supports)"); + } + + PhyML_Printf("\n . Model name:\t\t\t\t\t %s", io->mod->modelname->s); + + if(io->datatype == AA && io->mod->whichmodel == CUSTOMAA) PhyML_Printf(" (%s)",io->mod->aa_rate_mat_file->s); + + if (io->datatype == NT) + { + if ((io->mod->whichmodel == K80) || + (io->mod->whichmodel == HKY85)|| + (io->mod->whichmodel == F84) || + (io->mod->whichmodel == TN93)) + { + if(io->mod->s_opt && io->mod->s_opt->opt_kappa) + PhyML_Printf("\n . Ts/tv ratio:\t\t\t\t\t estimated"); + else + PhyML_Printf("\n . Ts/tv ratio:\t\t\t\t\t %f", io->mod->kappa->v); + } + } + + if(io->mod->s_opt && io->mod->s_opt->opt_pinvar) + PhyML_Printf("\n . Proportion of invariable sites:\t\t estimated"); + else + PhyML_Printf("\n . Proportion of invariable sites:\t\t %f", io->mod->ras->pinvar->v); + + + if(io->mod->ras->free_mixt_rates == NO) + PhyML_Printf("\n . RAS model:\t\t\t\t\t discrete Gamma"); + else + PhyML_Printf("\n . RAS model:\t\t\t\t\t FreeRate"); + + PhyML_Printf("\n . Number of subst. rate catgs:\t\t\t %d", io->mod->ras->n_catg); + + if(io->mod->ras->n_catg > 1) + { + + if(io->mod->ras->free_mixt_rates == NO) + { + if(io->mod->s_opt && io->mod->s_opt->opt_alpha) + PhyML_Printf("\n . Gamma distribution parameter:\t\t\t estimated"); + else + PhyML_Printf("\n . Gamma distribution parameter:\t\t\t %f", io->mod->ras->alpha->v); + PhyML_Printf("\n . 'Middle' of each rate class:\t\t\t %s",(io->mod->ras->gamma_median)?("median"):("mean")); + } + } + + + if(io->datatype == AA) + PhyML_Printf("\n . Amino acid equilibrium frequencies:\t\t %s", (io->mod->s_opt->opt_state_freq) ? ("empirical"):("model")); + else if(io->datatype == NT) + { + if((io->mod->whichmodel != JC69) && + (io->mod->whichmodel != K80) && + (io->mod->whichmodel != F81)) + { + if(io->mod->s_opt && !io->mod->e_frq->user_state_freq) + { + PhyML_Printf("\n . Nucleotide equilibrium frequencies:\t\t %s", (io->mod->s_opt->opt_state_freq) ? ("ML"):("empirical")); + } + else + { + PhyML_Printf("\n . Nucleotide equilibrium frequencies:\t\t %s","user-defined"); + } + } + } + + PhyML_Printf("\n . Optimise tree topology:\t\t\t %s", (io->mod->s_opt && io->mod->s_opt->opt_topo) ? "yes": "no"); + + switch(io->in_tree) + { + case 0: { strcpy(s,"BioNJ"); break; } + case 1: { strcpy(s,"parsimony"); break; } + case 2: { strcpy(s,"user tree ("); + strcat(s,Basename(io->in_tree_file)); + strcat(s,")"); break; } + } + + if(io->mod->s_opt && io->mod->s_opt->opt_topo) + { + /* if(io->mod->s_opt->topo_search == NNI_MOVE) PhyML_Printf("\n . Tree topology search:\t\t\t\t NNIs"); */ + /* else if(io->mod->s_opt->topo_search == SPR_MOVE) PhyML_Printf("\n . Tree topology search:\t\t\t\t SPRs"); */ + /* else if(io->mod->s_opt->topo_search == BEST_OF_NNI_AND_SPR) PhyML_Printf("\n . Tree topology search:\t\t\t\t Best of NNIs and SPRs"); */ + + PhyML_Printf("\n . Starting tree:\t\t\t\t %s",s); + + PhyML_Printf("\n . Add random input tree:\t\t\t %s", (io->mod->s_opt->random_input_tree) ? "yes": "no"); + if(io->mod->s_opt->random_input_tree) + PhyML_Printf("\n . Number of random starting trees:\t\t %d", io->mod->s_opt->n_rand_starts); + } + else + if(io->mod->s_opt && !io->mod->s_opt->random_input_tree) + PhyML_Printf("\n . Evaluated tree:\t\t\t\t \"%s\"",s); + + PhyML_Printf("\n . Optimise branch lengths:\t\t\t %s", (io->mod->s_opt && io->mod->s_opt->opt_bl) ? "yes": "no"); + + PhyML_Printf("\n . Minimum length of an edge:\t\t\t %g",io->mod->l_min); + + answer = 0; + if(io->mod->s_opt && + (io->mod->s_opt->opt_alpha || + io->mod->s_opt->opt_kappa || + io->mod->s_opt->opt_lambda || + io->mod->s_opt->opt_pinvar || + io->mod->s_opt->opt_rr)) answer = 1; + + PhyML_Printf("\n . Optimise substitution model parameters:\t %s", (answer) ? "yes": "no"); + + PhyML_Printf("\n . Run ID:\t\t\t\t\t %s", (io->append_run_ID) ? (io->run_id_string): ("none")); + PhyML_Printf("\n . Random seed:\t\t\t\t\t %d", io->r_seed); + PhyML_Printf("\n . Subtree patterns aliasing:\t\t\t %s",io->do_alias_subpatt?"yes":"no"); + PhyML_Printf("\n . Version:\t\t\t\t\t %s", VERSION); + PhyML_Printf("\n . Byte alignment:\t\t\t\t %d",BYTE_ALIGN); + PhyML_Printf("\n . AVX enabled:\t\t\t\t\t %s", +#if defined(__AVX__) + "yes" +#else + "no" +#endif + ); + PhyML_Printf("\n . SSE enabled:\t\t\t\t\t %s", +#if defined(__SSE3__) + "yes" +#else + "no" +#endif + ); + + + /* PhyML_Printf("\n\n \u205C \u205C \u205C \u205C \u205C \u205C \u205C \u205C \u205C \u205C \u205C \u205C \n"); */ + + PhyML_Printf("\n"); + PhyML_Printf("\n ////////////////////////////////////.\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"); + PhyML_Printf("\n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\.//////////////////////////////////////////\n"); + + + PhyML_Printf("\n\n"); + fflush(NULL); + + Free(s); +} + +void Print_Banner(FILE *fp) +{ + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp," oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); + PhyML_Fprintf(fp," \n"); + PhyML_Fprintf(fp," --- PhyML %s --- \n",VERSION); + PhyML_Fprintf(fp," \n"); + PhyML_Fprintf(fp," A simple, fast, and accurate algorithm to estimate large phylogenies by maximum likelihood \n"); + PhyML_Fprintf(fp," Stephane Guindon & Olivier Gascuel \n"); + PhyML_Fprintf(fp," \n"); + PhyML_Fprintf(fp," http://www.atgc-montpellier.fr/phyml \n"); + PhyML_Fprintf(fp," \n"); + PhyML_Fprintf(fp," Copyright CNRS - Universite Montpellier \n"); + PhyML_Fprintf(fp," \n"); + PhyML_Fprintf(fp," oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Print_Banner_Small(FILE *fp) +{ + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp," oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); + PhyML_Fprintf(fp," --- PhyML %s --- \n",VERSION); + PhyML_Fprintf(fp," http://www.atgc-montpellier.fr/phyml \n"); + PhyML_Fprintf(fp," Copyright CNRS - Universite Montpellier \n"); + PhyML_Fprintf(fp," oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + + +void Print_Data_Set_Number(option *io, FILE *fp) +{ + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp," \n"); + PhyML_Fprintf(fp," [ Data set number %3d ] \n",io->curr_gt+1); + PhyML_Fprintf(fp," \n"); +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Lk(t_tree *tree, char *string) +{ + t_tree *loc_tree; + + loc_tree = tree; + /*! Rewind back to the first mixt_tree */ + while(loc_tree->prev) loc_tree = loc_tree->prev; + + time(&(loc_tree->t_current)); + PhyML_Printf("\n. (%5d sec) [%15.4f] %s", + (int)(loc_tree->t_current-loc_tree->t_beg),Get_Lk(tree), + string); +#ifndef QUIET + fflush(NULL); +#endif +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_List(t_ll *list) +{ + t_ll *ll; + ll = list->head; + do + { + t_node *n; + n = (t_node *)ll->v; + PhyML_Printf("\n. list elem: %p next: %p prev: %p [%d] %p %p",(void *)ll,(void *)ll->next,(void *)ll->prev,n->num,(void *)ll->head,(void *)ll->tail); + ll = ll->next; + } + while(ll != NULL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Pars(t_tree *tree) +{ + time(&(tree->t_current)); + PhyML_Printf("\n. (%5d sec) [%5d]",(int)(tree->t_current-tree->t_beg),tree->c_pars); +#ifndef QUIET + fflush(NULL); +#endif +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Lk_And_Pars(t_tree *tree) +{ + time(&(tree->t_current)); + + PhyML_Printf("\n. (%5d sec) [%15.4f] [%5d]", + (int)(tree->t_current-tree->t_beg), + tree->c_lnL,tree->c_pars); + +#ifndef QUIET + fflush(NULL); +#endif +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Read_Qmat(phydbl *daa, phydbl *pi, FILE *fp) +{ + int i,j; + phydbl sum; + double val; + + assert(fp); + rewind(fp); + + for(i=1;i<20;i++) + { + for(j=0;j<19;j++) + { + /* if(!fscanf(fp,"%lf",&(daa[i*20+j]))) Exit("\n"); */ + if(!fscanf(fp,"%lf",&val)) + { + PhyML_Fprintf(stderr,"\n. Rate matrix file does not appear to have a proper format. Please refer to the documentation."); + Exit("\n"); + } + daa[i*20+j] = (phydbl)val; + daa[j*20+i] = daa[i*20+j]; + if(j == i-1) break; + } + } + + + for(i=0;i<20;i++) + { + if(!fscanf(fp,"%lf",&val)) Exit("\n"); + pi[i] = (phydbl)val; + } + sum = .0; + for(i=0;i<20;i++) sum += pi[i]; + if(FABS(sum - 1.) > 1.E-06) + { + PhyML_Printf("\n. Sum of amino-acid frequencies: %f",sum); + PhyML_Printf("\n. Scaling amino-acid frequencies...\n"); + for(i=0;i<20;i++) pi[i] /= sum; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Print_Qmat_AA(phydbl *daa, phydbl *pi) +{ + int i,j,cpt; + + cpt = 0; + for(i=0;i<20;i++) + { + for(j=0;ja_nodes[0], + tree->a_nodes[0]->v[0], + tree->a_nodes[0]->b[0], + fp, + tree); + +/* mean_div_left = .0; */ +/* for(k=0;ka_edges[j]->div_post_pred_left[k]; */ +/* } */ +/* mean_div_rght = .0; */ +/* for(k=0;ka_edges[j]->div_post_pred_rght[k]; */ + +/* mean_div_left /= (phydbl)tree->data->init_len; */ +/* mean_div_rght /= (phydbl)tree->data->init_len; */ + +/* PhyML_Fprintf(fp,"%4d 0 %f\n",j,mean_div_left); */ +/* PhyML_Fprintf(fp,"%4d 1 %f\n",j,mean_div_rght); */ + + +/* mean_div_left = .0; */ +/* for(k=0;ka_edges[j]->div_post_pred_left[k]; */ + +/* mean_div_rght = .0; */ +/* for(k=0;ka_edges[j]->div_post_pred_rght[k]; */ +/* } */ + +/* if((mean_div_left != tree->data->init_len) || (mean_div_rght != tree->data->init_len)) */ +/* { */ +/* PhyML_Printf("\n. mean_div_left = %f mean_div_rght = %f init_len = %d", */ +/* mean_div_left,mean_div_rght,tree->data->init_len); */ +/* PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); */ +/* Warn_And_Exit(""); */ +/* } */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Diversity_Pre(t_node *a, t_node *d, t_edge *b, FILE *fp, t_tree *tree) +{ + int k,ns; + + ns = -1; + + if(d->tax) return; + else + { + + if(tree->io->datatype == NT) ns = 4; + else if(tree->io->datatype == AA) ns = 20; + + if(d == b->left) for(k=0;knum,k,b->div_post_pred_left[k]); + else for(k=0;knum,k,b->div_post_pred_rght[k]); + + for(k=0;k<3;k++) if(d->v[k] != a) Print_Diversity_Pre(d,d->v[k],d->b[k],fp,tree); + } + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Tip_Partials(t_tree* tree, t_node* d) +{ + if(!d->tax) + { + fprintf(stdout,"Node %d is not a Taxa\n",d->num);fflush(stdout); + return; + } + + assert(d->b[0]->rght == d); + assert(d->b[0]->rght->tax); + fprintf(stdout,"Taxa/Node %d\n",d->num); + int site, i; + for(site=0;siten_pattern;++site) + { + fprintf(stdout,"[%d: ",site); + for(i=0;imod->ns;++i) + { + int tip_partial = d->b[0]->p_lk_tip_r[site*tree->mod->ns + i]; + fprintf(stdout,"%d",tip_partial);fflush(stdout); + } + fprintf(stdout,"] ");fflush(stdout); + } + fprintf(stdout,"\n");fflush(stdout); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Edge_PMats(t_tree* tree, t_edge* b) +{ + phydbl *Pij; +#ifdef BEAGLE + Pij = (phydbl*)malloc(tree->mod->ns * tree->mod->ns * tree->mod->ras->n_catg * sizeof(phydbl)); if (NULL==Pij) Warn_And_Exit(__PRETTY_FUNCTION__); + int ret = beagleGetTransitionMatrix(tree->b_inst, b->Pij_rr_idx, Pij); + if(ret<0){ + fprintf(stderr, "beagleGetTransitionMatrix() on instance %i failed:%i\n\n",tree->b_inst,ret); + Free(Pij); + Exit(""); + } +#else + Pij = b->Pij_rr; +#endif + fprintf(stdout,"\nflattened P-Matrices (for each rate category) state*state*num_rates[%d*%d*%d] for branch num:%i\n",tree->mod->ns,tree->mod->ns,tree->mod->ras->n_catg, b->num); + int i; + for(i=0;imod->ns * tree->mod->ns * tree->mod->ras->n_catg;++i){ + fprintf(stdout,"%f,",Pij[i]); + fflush(stdout); + } + fprintf(stdout,"\n"); + fflush(stdout); +#ifdef BEAGLE + Free(Pij); +#endif +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_All_Edge_PMats(t_tree* tree) +{ + int i; + for(i=0;i < 2*tree->n_otu-3;++i) Print_Edge_PMats(tree, tree->a_edges[i]); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Edge_Likelihoods(t_tree* tree, t_edge* b, bool scientific/*Print in scientific notation?*/) +{ + int catg, site, j; + char* fmt = scientific ? "[%d,%d,%d]%e ":"[%d,%d,%d]%f "; //rate category, site, state, likelihood + + phydbl* lk_left = b->p_lk_left; + phydbl* lk_right = b->p_lk_rght; + + fprintf(stdout,"\n");fflush(stdout); + if(NULL!=lk_left)//not a tip? + { + fprintf(stdout,"Partial Likelihoods on LEFT subtree of Branch %d [rate,site,state]:\n",b->num); + for(catg=0;catgmod->ras->n_catg;++catg) + for(site=0;siten_pattern;++site) + for(j=0;jmod->ns;++j) +#ifdef BEAGLE + fprintf(stdout,fmt,catg,site,j,lk_left[catg*tree->n_pattern*tree->mod->ns + site*tree->mod->ns + j]); +#else + fprintf(stdout,fmt,catg,site,j,lk_left[catg*tree->mod->ns + site*tree->mod->ras->n_catg*tree->mod->ns + j]); +#endif + fflush(stdout); + } + else //is a tip + { + fprintf(stdout,"Likelihoods on LEFT tip of Branch %d [site,state]:\n",b->num); + for(site=0;siten_pattern;++site) + for(j=0;jmod->ns;++j) + fprintf(stdout,"[%d,%d]%.1f ",site,j,b->p_lk_tip_l[site*tree->mod->ns + j]); + fflush(stdout); + } + fprintf(stdout,"\n");fflush(stdout); + if(NULL!=lk_right)//not a tip? + { + fprintf(stdout,"Partial Likelihoods on RIGHT subtree of Branch %d [rate,site,state]:\n",b->num); + for(catg=0;catgmod->ras->n_catg;++catg) + for(site=0;siten_pattern;++site) + for(j=0;jmod->ns;++j) +#ifdef BEAGLE + fprintf(stdout,fmt,catg,site,j,lk_right[catg*tree->n_pattern*tree->mod->ns + site*tree->mod->ns + j]); +#else + fprintf(stdout,fmt,catg,site,j,lk_right[catg*tree->mod->ns + site*tree->mod->ras->n_catg*tree->mod->ns + j]); +#endif + fflush(stdout); + } + else //is a tip + { + fprintf(stdout,"Likelihoods on RIGHT tip of Branch %d [site,state]:\n",b->num); + for(site=0;siten_pattern;++site) + for(j=0;jmod->ns;++j) + fprintf(stdout,"[%d,%d]%.1f ",site,j,b->p_lk_tip_r[site*tree->mod->ns + j]); + fflush(stdout); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_All_Edge_Likelihoods(t_tree* tree) +{ + int i; + for(i=0;i < 2*tree->n_otu-3; ++i) Print_Edge_Likelihoods(tree, tree->a_edges[i],false); + fflush(NULL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Dump_Arr_S(short int* arr, int num) +{ + int i; + + if(NULL==arr) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s')\n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n. Trying to print NULL array"); + return; + } + fprintf(stdout,"["); + for(i=0;in_otu); + + for(i=0; i<2*tree->n_otu-1; ++i) + { + if(tree->a_edges[i]) + PhyML_Fprintf(stdout,"\n. Edge %p %3d, Length: %f LeftNode %3d [%s], RightNode %3d [%s]", + tree->a_edges[i], + tree->a_edges[i]->num, + tree->a_edges[i]->l->v, + tree->a_edges[i]->left ? tree->a_edges[i]->left->num : -1, + tree->a_edges[i]->left ? tree->a_edges[i]->left->tax ? tree->a_edges[i]->left->name : "" : "", + tree->a_edges[i]->rght ? tree->a_edges[i]->rght->num : -1, + tree->a_edges[i]->left ? tree->a_edges[i]->rght->tax ? tree->a_edges[i]->rght->name : "" : ""); + else PhyML_Fprintf(stdout,"\n. NULL"); + } + + for(i=0; i<2*tree->n_otu-1; ++i) + { + if(tree->a_nodes[i]) + PhyML_Fprintf(stdout,"\n. Node %p %3d v0: %3d v1: %3d v2: %3d b0: %3d b1: %3d b2: %3d", + tree->a_nodes[i], + tree->a_nodes[i]->num, + tree->a_nodes[i]->v[0] ? tree->a_nodes[i]->v[0]->num : -1, + tree->a_nodes[i]->v[1] ? tree->a_nodes[i]->v[1]->num : -1, + tree->a_nodes[i]->v[2] ? tree->a_nodes[i]->v[2]->num : -1, + tree->a_nodes[i]->v[0] ? tree->a_nodes[i]->b[0]->num : -1, + tree->a_nodes[i]->v[1] ? tree->a_nodes[i]->b[1]->num : -1, + tree->a_nodes[i]->v[2] ? tree->a_nodes[i]->b[2]->num : -1); + else PhyML_Fprintf(stdout,"\n. NULL"); + } +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_tree *Read_User_Tree(calign *cdata, t_mod *mod, option *io) +{ + t_tree *tree; + + PhyML_Printf("\n. Reading tree..."); fflush(NULL); + if(io->n_trees == 1) rewind(io->fp_in_tree); + tree = Read_Tree_File_Phylip(io->fp_in_tree); + /* fclose(io->fp_in_tree); */ + /* io->fp_in_tree = NULL; */ + if(tree == NULL) Exit("\n. Input tree not found..."); + /* Add branch lengths if necessary */ + if(tree->has_branch_lengths == NO) Add_BioNJ_Branch_Lengths(tree,cdata,mod,NULL); + return tree; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Print_Time_Info(time_t t_beg, time_t t_end) +{ + div_t hour,min; + + hour = div(t_end-t_beg,3600); + min = div(t_end-t_beg,60 ); + min.quot -= hour.quot*60; + + PhyML_Printf("\n\n. Time used %dh%dm%ds\n", hour.quot,min.quot,(int)(t_end-t_beg)%60); + PhyML_Printf("\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Time_Info_Brief(time_t t_beg, time_t t_end) +{ + div_t hour,min; + + hour = div(t_end-t_beg,3600); + min = div(t_end-t_beg,60 ); + min.quot -= hour.quot*60; + + PhyML_Printf("\n. Time used %dh%dm%ds\n", hour.quot,min.quot,(int)(t_end-t_beg)%60); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void PhyML_Printf(char *format, ...) +{ + va_list ptr; + +#ifdef MPI + if(Global_myRank == 0) + { + va_start (ptr, format); + vprintf (format, ptr); + va_end(ptr); + } +#else + va_start (ptr, format); + vprintf (format, ptr); + va_end(ptr); +#endif + + fflush (NULL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void PhyML_Fprintf(FILE *fp, char *format, ...) +{ + va_list ptr; + +#ifdef MPI + if(Global_myRank == 0) + { + va_start (ptr, format); + vfprintf (fp,format, ptr); + va_end(ptr); + } +#else + va_start (ptr, format); + vfprintf (fp,format, ptr); + va_end(ptr); +#endif + + fflush (NULL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int PhyML_Fscanf(FILE *fp, char *format, ...) +{ + va_list ptr; + int rv; + + rv = -1; + +#ifdef MPI + if(Global_myRank == 0) + { + va_start (ptr, format); + rv = vfscanf(fp,format,ptr); + if(!rv) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + va_end(ptr); + } +#else + va_start (ptr, format); + rv = vfscanf(fp,format,ptr); + if(!rv) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + va_end(ptr); +#endif + + return(rv); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Read_Clade_Priors(char *file_name, t_tree *tree) +{ + FILE *fp; + char *s,*line; + int n_clade_priors; + int clade_size; + char **clade_list; + int i,pos; + phydbl prior_low,prior_up; + int node_num; + + PhyML_Printf("\n"); + PhyML_Printf("\n. Reading prior on node ages.\n"); + + line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + + clade_list = (char **)mCalloc(tree->n_otu,sizeof(char *)); + for(i=0;in_otu;i++) clade_list[i] = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + fp = Openfile(file_name,0); + + n_clade_priors = 0; + do + { + if(!fgets(line,T_MAX_LINE,fp)) break; + + clade_size = 0; + pos = 0; + do + { + i = 0; + + while(line[pos] == ' ') pos++; + + while((line[pos] != ' ') && (line[pos] != '\n') && line[pos] != '#') + { + s[i] = line[pos]; + i++; + pos++; + } + s[i] = '\0'; + + /* PhyML_Printf("\n. s = %s\n",s); */ + + if(line[pos] == '\n' || line[pos] == '#') break; + pos++; + + if(strcmp(s,"|")) + { + strcpy(clade_list[clade_size],s); + clade_size++; + } + else + break; + } + while(1); + + + if(line[pos] != '#' && line[pos] != '\n') + { + phydbl val1, val2; +/* sscanf(line+pos,"%lf %lf",&prior_up,&prior_low); */ + sscanf(line+pos,"%lf %lf",&val1,&val2); + prior_up = (phydbl)val1; + prior_low = (phydbl)val2; + node_num = -1; + if(!strcmp("@root@",clade_list[0])) node_num = tree->n_root->num; + else node_num = Find_Clade(clade_list, clade_size, tree); + + n_clade_priors++; + + if(node_num < 0) + { + PhyML_Printf("\n"); + PhyML_Printf("\n"); + PhyML_Printf("\n. ................................................................."); + PhyML_Printf("\n. WARNING: could not find any clade in the tree referred to with the following taxon names:"); + for(i=0;irates->t_has_prior[node_num] = YES; + + tree->rates->t_prior_min[node_num] = -MAX(prior_low,prior_up); + tree->rates->t_prior_max[node_num] = -MIN(prior_low,prior_up); + + if(fabs(prior_low - prior_up) < 1.E-6 && tree->a_nodes[node_num]->tax == YES) + tree->rates->nd_t[node_num] = prior_low; + + PhyML_Printf("\n"); + PhyML_Printf("\n. [%3d]..................................................................",n_clade_priors); + PhyML_Printf("\n. Node %4d matches the clade referred to with the following taxon names:",node_num); + for(i=0;i 1 ? "clades":"clade"); + + if(!n_clade_priors) + { + PhyML_Fprintf(stderr,"\n. PhyTime could not find any prior on node age."); + PhyML_Fprintf(stderr,"\n. This is likely due to a problem in the calibration "); + PhyML_Fprintf(stderr,"\n. file format. Make sure, for instance, that there is "); + PhyML_Fprintf(stderr,"\n. a blank character between the end of the last name"); + PhyML_Fprintf(stderr,"\n. of each clade and the character `|'. Otherwise, "); + PhyML_Fprintf(stderr,"\n. please refer to the example file.\n"); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s')\n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit(""); + } + + for(i=0;in_otu;i++) Free(clade_list[i]); + Free(clade_list); + Free(line); + Free(s); + fclose(fp); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +option *Get_Input(int argc, char **argv) +{ + option *io; + t_mod *mod; + t_opt *s_opt; + int rv; + + rv = 1; + + io = (option *)Make_Input(); + mod = (t_mod *)Make_Model_Basic(); + s_opt = (t_opt *)Make_Optimiz(); + + Set_Defaults_Input(io); + Set_Defaults_Model(mod); + Set_Defaults_Optimiz(s_opt); + + io->mod = mod; + mod->io = io; + mod->s_opt = s_opt; + +#ifdef MPI + rv = Read_Command_Line(io,argc,argv); +#elif (defined PHYTIME || defined INVITEE || defined PHYREX || defined TEST) + rv = Read_Command_Line(io,argc,argv); +#else + switch (argc) + { + case 1: + { + Launch_Interface(io); + break; + } + default: + { + rv = Read_Command_Line(io,argc,argv); + } + } +#endif + + + if(rv) return io; + else return NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Set_Whichmodel(int select) +{ + int wm; + + wm = -1; + + switch(select) + { + case 1: + { + wm = JC69; + break; + } + case 2: + { + wm = K80; + break; + } + case 3: + { + wm = F81; + break; + } + case 4: + { + wm = HKY85; + break; + } + case 5: + { + wm = F84; + break; + } + case 6: + { + wm = TN93; + break; + } + case 7: + { + wm = GTR; + break; + } + case 8: + { + wm = CUSTOM; + break; + } + case 11: + { + wm = WAG; + break; + } + case 12: + { + wm = DAYHOFF; + break; + } + case 13: + { + wm = JTT; + break; + } + case 14: + { + wm = BLOSUM62; + break; + } + case 15: + { + wm = MTREV; + break; + } + case 16: + { + wm = RTREV; + break; + } + case 17: + { + wm = CPREV; + break; + } + case 18: + { + wm = DCMUT; + break; + } + case 19: + { + wm = VT; + break; + } + case 20: + { + wm = MTMAM; + break; + } + case 21: + { + wm = MTART; + break; + } + case 22: + { + wm = HIVW; + break; + } + case 23: + { + wm = HIVB; + break; + } + case 24: + { + wm = FLU; + break; + } + case 25: + { + wm = CUSTOMAA; + break; + } + case 26: + { + wm = LG; + break; + } + case 27: + { + wm = AB; + break; + } + default: + { + PhyML_Fprintf(stderr,"\n. Model number %d is unknown. Please use a valid model name",select); + Exit("\n"); + break; + } + } + + return wm; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Print_Data_Structure(int final, FILE *fp, t_tree *mixt_tree) +{ + int n_partition_elem; + char *s; + t_tree *tree,*cpy_mixt_tree; + int c,cc,cc_efrq,cc_rmat,cc_lens; + char *param; + int *link_efrq,*link_rmat,*link_lens; + phydbl r_mat_weight_sum, e_frq_weight_sum; + + + PhyML_Fprintf(fp,"\n. Starting tree: %s", + mixt_tree->io->in_tree == 2?mixt_tree->io->in_tree_file:"BioNJ"); + + cpy_mixt_tree = mixt_tree; + + n_partition_elem = 1; + tree = mixt_tree; + do + { + tree = tree->next_mixt; + if(!tree) break; + n_partition_elem++; + } + while(1); + + s = (char *)mCalloc(2,sizeof(char)); + s[0] = ' '; + s[1] = '\0'; + tree = mixt_tree; + do + { + s = (char *)mRealloc(s,(int)(strlen(s)+strlen(tree->io->in_align_file)+2+2),sizeof(char)); + strcat(s,tree->io->in_align_file); + strcat(s,", "); + tree = tree->next_mixt; + if(!tree) break; + } + while(1); + s[(int)strlen(s)-2]=' '; + s[(int)strlen(s)-1]='\0'; + + if(final == NO) PhyML_Fprintf(fp,"\n\n. Processing %d data %s (%s)",n_partition_elem,n_partition_elem>1?"sets":"set",s); + if(final == YES) PhyML_Fprintf(fp,"\n\n. Processed %d data %s (%s)",n_partition_elem,n_partition_elem>1?"sets":"set",s); + Free(s); + + if(final == YES) + PhyML_Fprintf(fp,"\n\n. Final log-likelihood: %f",mixt_tree->c_lnL); + + r_mat_weight_sum = MIXT_Get_Sum_Chained_Scalar_Dbl(mixt_tree->next->mod->r_mat_weight); + e_frq_weight_sum = MIXT_Get_Sum_Chained_Scalar_Dbl(mixt_tree->next->mod->e_frq_weight); + + do + { + int class = 0; + + PhyML_Fprintf(fp,"\n\n"); + PhyML_Fprintf(fp,"\n _______________________________________________________________________ "); + PhyML_Fprintf(fp,"\n| |"); + PhyML_Fprintf(fp,"\n| %40s (partition element %2d) |",mixt_tree->io->in_align_file,mixt_tree->dp); + PhyML_Fprintf(fp,"\n|_______________________________________________________________________|"); + PhyML_Fprintf(fp,"\n"); + + PhyML_Fprintf(fp,"\n. Number of rate classes:\t\t%20d",mixt_tree->mod->ras->n_catg+(mixt_tree->mod->ras->invar ?1:0)); + if(mixt_tree->mod->ras->n_catg > 1) + { + PhyML_Fprintf(fp,"\n. Model of rate variation:\t\t%20s", + mixt_tree->mod->ras->free_mixt_rates?"FreeRates": + mixt_tree->mod->ras->invar?"Gamma+Inv":"Gamma"); + if(mixt_tree->mod->ras->free_mixt_rates == NO) + { + PhyML_Fprintf(fp,"\n. Gamma shape parameter value:\t\t%20.2f",mixt_tree->mod->ras->alpha->v); + PhyML_Fprintf(fp,"\n Optimise: \t\t\t\t%20s",mixt_tree->mod->s_opt->opt_alpha==YES?"yes":"no"); + } + if(mixt_tree->mod->ras->invar == YES) + { + PhyML_Fprintf(fp,"\n. Proportion of invariable sites:\t%20.2f",mixt_tree->mod->ras->pinvar->v); + PhyML_Fprintf(fp,"\n Optimise: \t\t\t\t%20s",mixt_tree->mod->s_opt->opt_pinvar==YES?"yes":"no"); + } + } + PhyML_Fprintf(fp,"\n. Relative average rate:\t\t%20f",mixt_tree->mod->br_len_mult->v); + + + tree = mixt_tree; + do + { + if(tree->is_mixt_tree) tree = tree->next; + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n. Mixture class %d",class+1); + + if(mixt_tree->mod->ras->n_catg > 1) + { + if(tree->mod->ras->invar == NO) + { + PhyML_Fprintf(fp,"\n Relative substitution rate:\t%20f",mixt_tree->mod->ras->gamma_rr->v[tree->mod->ras->parent_class_number]); + PhyML_Fprintf(fp,"\n Rel. rate freq. (> 0 rates):\t%20f",mixt_tree->mod->ras->gamma_r_proba->v[tree->mod->ras->parent_class_number]); + PhyML_Fprintf(fp,"\n Rate class number:\t\t%20d",tree->mod->ras->parent_class_number); + } + else + { + PhyML_Fprintf(fp,"\n Relative substitution rate:\t%20f",0.0); + PhyML_Fprintf(fp,"\n Relative rate freq.:\t\t%20f",mixt_tree->mod->ras->pinvar->v); + } + } + + PhyML_Fprintf(fp,"\n Substitution model:\t\t%20s",tree->mod->modelname->s); + + if(tree->mod->whichmodel == CUSTOM) + PhyML_Fprintf(fp,"\n Substitution model code:\t%20s",tree->mod->custom_mod_string->s); + + if(tree->mod->whichmodel == CUSTOMAA) + PhyML_Fprintf(fp,"\n Rate matrix file name:\t%20s",tree->mod->aa_rate_mat_file->s); + + if(tree->mod->whichmodel == K80 || + tree->mod->whichmodel == HKY85 || + tree->mod->whichmodel == TN93) + { + PhyML_Fprintf(fp,"\n Value of the ts/tv ratio:\t%20f",tree->mod->kappa->v); + PhyML_Fprintf(fp,"\n Optimise ts/tv ratio:\t%20s",tree->mod->s_opt->opt_kappa?"yes":"no"); + } + else if(tree->mod->whichmodel == GTR || + tree->mod->whichmodel == CUSTOM) + { + PhyML_Fprintf(fp,"\n Optimise subst. rates:\t%20s",tree->mod->s_opt->opt_rr?"yes":"no"); + if(final == YES) + { + PhyML_Fprintf(fp,"\n Subst. rate A<->C:\t\t%20.2f",tree->mod->r_mat->rr->v[0]); + PhyML_Fprintf(fp,"\n Subst. rate A<->G:\t\t%20.2f",tree->mod->r_mat->rr->v[1]); + PhyML_Fprintf(fp,"\n Subst. rate A<->T:\t\t%20.2f",tree->mod->r_mat->rr->v[2]); + PhyML_Fprintf(fp,"\n Subst. rate C<->G:\t\t%20.2f",tree->mod->r_mat->rr->v[3]); + PhyML_Fprintf(fp,"\n Subst. rate C<->T:\t\t%20.2f",tree->mod->r_mat->rr->v[4]); + PhyML_Fprintf(fp,"\n Subst. rate G<->T:\t\t%20.2f",tree->mod->r_mat->rr->v[5]); + } + } + + PhyML_Fprintf(fp,"\n Rate matrix weight:\t\t%20f",tree->mod->r_mat_weight->v / r_mat_weight_sum); + + if(tree->io->datatype == NT && + tree->mod->whichmodel != JC69 && + tree->mod->whichmodel != K80) + { + PhyML_Fprintf(fp,"\n Optimise nucleotide freq.:\t%20s",tree->mod->s_opt->opt_state_freq?"yes":"no"); + if(final == YES) + { + PhyML_Fprintf(fp,"\n Freq(A):\t\t\t%20.2f",tree->mod->e_frq->pi->v[0]); + PhyML_Fprintf(fp,"\n Freq(C):\t\t\t%20.2f",tree->mod->e_frq->pi->v[1]); + PhyML_Fprintf(fp,"\n Freq(G):\t\t\t%20.2f",tree->mod->e_frq->pi->v[2]); + PhyML_Fprintf(fp,"\n Freq(T):\t\t\t%20.2f",tree->mod->e_frq->pi->v[3]); + } + } + else if(tree->io->datatype == AA) + { + char *s; + + s = (char *)mCalloc(50,sizeof(char)); + + if(tree->mod->s_opt->opt_state_freq == YES) + { + strcpy(s,"Empirical"); + } + else + { + strcpy(s,"Model"); + } + + PhyML_Fprintf(fp,"\n Amino-acid freq.:\t\t%20s",s); + + Free(s); + } + + + PhyML_Fprintf(fp,"\n Equ. freq. weight:\t\t%20f",tree->mod->e_frq_weight->v / e_frq_weight_sum); + + class++; + + tree = tree->next; + + if(tree && tree->is_mixt_tree == YES) break; + } + while(tree); + + mixt_tree = mixt_tree->next_mixt; + if(!mixt_tree) break; + } + while(1); + + + tree = cpy_mixt_tree; + c = 0; + do + { + if(tree->is_mixt_tree) tree = tree->next; + c++; + tree = tree->next; + } + while(tree); + + link_efrq = (int *)mCalloc(c,sizeof(int)); + link_lens = (int *)mCalloc(c,sizeof(int)); + link_rmat = (int *)mCalloc(c,sizeof(int)); + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n _______________________________________________________________________ "); + PhyML_Fprintf(fp,"\n| |"); + PhyML_Fprintf(fp,"\n| Model summary table |"); + PhyML_Fprintf(fp,"\n|_______________________________________________________________________|"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + /* PhyML_Fprintf(fp," "); */ + PhyML_Fprintf(fp," ------------------"); + tree = cpy_mixt_tree; + c = 0; + do + { + if(tree->is_mixt_tree) tree = tree->next; + PhyML_Fprintf(fp,"---"); + tree = tree->next; + } + while(tree); + + param = (char *)mCalloc(30,sizeof(char)); + PhyML_Fprintf(fp,"\n"); + strcpy(param,"Partition element "); + PhyML_Fprintf(fp," %18s",param); + tree = cpy_mixt_tree; + c = 0; + do + { + if(tree->is_mixt_tree) tree = tree->next; + PhyML_Fprintf(fp,"%2d ",tree->mixt_tree->dp); + tree = tree->next; + } + while(tree); + + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp," ------------------"); + tree = cpy_mixt_tree; + c = 0; + do + { + if(tree->is_mixt_tree) tree = tree->next; + PhyML_Fprintf(fp,"---"); + tree = tree->next; + } + while(tree); + + + tree = cpy_mixt_tree; + c = 0; + do + { + if(tree->is_mixt_tree) tree = tree->next; + link_rmat[c] = -1; + link_lens[c] = -1; + link_efrq[c] = -1; + tree = tree->next; + c++; + } + while(tree); + + mixt_tree = cpy_mixt_tree; + cc_efrq = 97; + cc_rmat = 97; + cc_lens = 97; + cc = 0; + do + { + if(mixt_tree->is_mixt_tree) mixt_tree = mixt_tree->next; + + if(link_efrq[cc] < 0) + { + link_efrq[cc] = cc_efrq; + tree = mixt_tree->next; + c = cc+1; + if(tree) + { + do + { + if(tree->is_mixt_tree) tree = tree->next; + + if(mixt_tree->mod->e_frq == tree->mod->e_frq) link_efrq[c] = cc_efrq; + + tree = tree->next; + c++; + } + while(tree); + } + cc_efrq++; + } + + if(link_lens[cc] < 0) + { + link_lens[cc] = cc_lens; + tree = mixt_tree->next; + c = cc+1; + if(tree) + { + do + { + if(tree->is_mixt_tree) tree = tree->next; + + if(mixt_tree->a_edges[0]->l == tree->a_edges[0]->l) link_lens[c] = cc_lens; + + tree = tree->next; + c++; + } + while(tree); + } + cc_lens++; + } + + if(link_rmat[cc] < 0) + { + link_rmat[cc] = cc_rmat; + tree = mixt_tree->next; + c = cc+1; + if(tree) + { + do + { + if(tree->is_mixt_tree) tree = tree->next; + + if(mixt_tree->mod->r_mat == tree->mod->r_mat && + mixt_tree->mod->whichmodel == tree->mod->whichmodel && + !strcmp(mixt_tree->mod->custom_mod_string->s, + tree->mod->custom_mod_string->s) && + !strcmp(mixt_tree->mod->aa_rate_mat_file->s, + tree->mod->aa_rate_mat_file->s)) link_rmat[c] = cc_rmat; + + tree = tree->next; + c++; + } + while(tree); + } + cc_rmat++; + } + + cc++; + mixt_tree = mixt_tree->next; + } + while(mixt_tree); + + PhyML_Fprintf(fp,"\n"); + strcpy(param,"State frequencies "); + PhyML_Fprintf(fp," %18s",param); + + tree = cpy_mixt_tree; + c = 0; + do + { + if(tree->is_mixt_tree) tree = tree->next; + PhyML_Fprintf(fp,"%2c ",link_efrq[c]); + tree = tree->next; + c++; + } + while(tree); + + + PhyML_Fprintf(fp,"\n"); + strcpy(param,"Branch lengths "); + PhyML_Fprintf(fp," %18s",param); + + tree = cpy_mixt_tree; + c = 0; + do + { + if(tree->is_mixt_tree) tree = tree->next; + PhyML_Fprintf(fp,"%2c ",link_lens[c]); + tree = tree->next; + c++; + } + while(tree); + + PhyML_Fprintf(fp,"\n"); + strcpy(param,"Rate matrix "); + PhyML_Fprintf(fp," %18s",param); + + tree = cpy_mixt_tree; + c = 0; + do + { + if(tree->is_mixt_tree) tree = tree->next; + PhyML_Fprintf(fp,"%2c ",link_rmat[c]); + tree = tree->next; + c++; + } + while(tree); + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp," ------------------"); + tree = cpy_mixt_tree; + c = 0; + do + { + if(tree->is_mixt_tree) tree = tree->next; + PhyML_Fprintf(fp,"---"); + tree = tree->next; + } + while(tree); + PhyML_Fprintf(fp,"\n"); + + if(final == YES) + { + tree = cpy_mixt_tree; + c = 0; + do + { + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n. Tree estimated from data partition %d",c++); + Br_Len_Involving_Invar(tree->next); + Rescale_Br_Len_Multiplier_Tree(tree->next); + s = Write_Tree(tree->next); /*! tree->next is not a mixt_tree so edge lengths + are not averaged over when writing the tree out. */ + PhyML_Fprintf(fp,"\n %s",s); + Br_Len_Not_Involving_Invar(tree->next); + Unscale_Br_Len_Multiplier_Tree(tree->next); + Free(s); + tree = tree->next_mixt; + } + while(tree); + } + + Free(param); + Free(link_efrq); + Free(link_rmat); + Free(link_lens); + + mixt_tree = cpy_mixt_tree; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +option *PhyML_XML(char *xml_filename) +{ + char *most_likely_tree; + phydbl best_lnL; + int num_rand_tree; + t_tree *mixt_tree,*tree; + option *io,*dum; + xml_node *xml_root; + + mixt_tree = XML_Process_Base(xml_filename); + io = mixt_tree->io; + most_likely_tree = NULL; + xml_root = mixt_tree->xml_root; + best_lnL = UNLIKELY; + dum = NULL; + + dum = (option *)mCalloc(1,sizeof(option)); + dum->use_xml = YES; + + for(num_rand_tree=0;num_rand_treemod->s_opt->n_rand_starts;num_rand_tree++) + { + MIXT_Check_Model_Validity(mixt_tree); + MIXT_Init_Model(mixt_tree); + Print_Data_Structure(NO,stdout,mixt_tree); + tree = MIXT_Starting_Tree(mixt_tree); + Copy_Tree(tree,mixt_tree); + Free_Tree(tree); + + if(mixt_tree->io->mod->s_opt->random_input_tree) + { + PhyML_Printf("\n\n. [%3d/%3d]",num_rand_tree+1,mixt_tree->io->mod->s_opt->n_rand_starts); + Random_Tree(mixt_tree); + } + + MIXT_Connect_Cseqs_To_Nodes(mixt_tree); + MIXT_Init_T_Beg(mixt_tree); + + MIXT_Make_Tree_For_Pars(mixt_tree); + MIXT_Make_Tree_For_Lk(mixt_tree); + MIXT_Make_Spr(mixt_tree); + + MIXT_Chain_All(mixt_tree); + MIXT_Check_Edge_Lens_In_All_Elem(mixt_tree); + MIXT_Turn_Branches_OnOff_In_All_Elem(ON,mixt_tree); + MIXT_Check_Invar_Struct_In_Each_Partition_Elem(mixt_tree); + MIXT_Check_RAS_Struct_In_Each_Partition_Elem(mixt_tree); + Br_Len_Not_Involving_Invar(mixt_tree); + Unscale_Br_Len_Multiplier_Tree(mixt_tree); + Set_Both_Sides(YES,mixt_tree); + + Set_Update_Eigen(YES,mixt_tree->mod); + Lk(NULL,mixt_tree); + Set_Update_Eigen(NO,mixt_tree->mod); + + + if(mixt_tree->mod->s_opt->opt_topo) + { + Global_Spr_Search(mixt_tree); + } + else + { + Round_Optimize(mixt_tree,ROUND_MAX); + } + + + PhyML_Printf("\n\n. Log-likelihood = %f",mixt_tree->c_lnL); + + if((num_rand_tree == io->mod->s_opt->n_rand_starts-1) && (io->mod->s_opt->random_input_tree)) + { + num_rand_tree--; + io->mod->s_opt->random_input_tree = NO; + } + + Br_Len_Involving_Invar(mixt_tree); + Rescale_Br_Len_Multiplier_Tree(mixt_tree); + + /*! Print the tree estimated using the current random (or BioNJ) starting tree */ + if(io->mod->s_opt->n_rand_starts > 1) + { + Print_Tree(io->fp_out_trees,mixt_tree); + fflush(NULL); + } + + if(mixt_tree->c_lnL > best_lnL) + { + best_lnL = mixt_tree->c_lnL; + if(most_likely_tree) Free(most_likely_tree); + if(io->ratio_test) aLRT(mixt_tree); + most_likely_tree = Write_Tree(mixt_tree); + mixt_tree->lock_topo = NO; + } + + tree = mixt_tree; + do + { + if(tree->io->print_site_lnl == YES) Print_Site_Lk(tree,tree->io->fp_out_lk); + tree = tree->next_mixt; + } + while(tree); + + MIXT_Init_T_End(mixt_tree); + Print_Data_Structure(YES,mixt_tree->io->fp_out_stats,mixt_tree); + + Free_Spr_List_One_Edge(mixt_tree); + Free_Tree_Pars(mixt_tree); + Free_Tree_Lk(mixt_tree); + } + + /*! Print the most likely tree in the output file */ + if(!mixt_tree->io->quiet) PhyML_Printf("\n\n. Printing the most likely tree in file '%s'...\n", Basename(mixt_tree->io->out_tree_file)); + PhyML_Fprintf(mixt_tree->io->fp_out_tree,"%s\n",most_likely_tree); + + /*! Bootstrap analysis */ + MIXT_Bootstrap(most_likely_tree,xml_root); + + while(io->prev != NULL) io = io->prev; + + Free(most_likely_tree); + + tree = mixt_tree; + do + { + Free_Calign(tree->data); + tree = tree->next_mixt; + } + while(tree); + + tree = mixt_tree; + do + { + Free_Optimiz(tree->mod->s_opt); + tree = tree->next; + } + while(tree); + + Free_Model_Complete(mixt_tree->mod); + Free_Model_Basic(mixt_tree->mod); + Free_Tree(mixt_tree); + + if(io->fp_out_trees) fclose(io->fp_out_trees); + if(io->fp_out_tree) fclose(io->fp_out_tree); + if(io->fp_out_stats) fclose(io->fp_out_stats); + if(io->fp_out_json_trace) fclose(io->fp_out_json_trace); + Free_Input(io); + + XML_Free_XML_Tree(xml_root); + + return(dum); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/*! Check that the same nodes in the different mixt_trees are + connected to the same taxa +*/ +void Check_Taxa_Sets(t_tree *mixt_tree) +{ + t_tree *tree; + int i; + + tree = mixt_tree; + do + { + if(tree->next) + { + for(i=0;in_otu;i++) + { + if(strcmp(tree->a_nodes[i]->name,tree->next->a_nodes[i]->name)) + { + PhyML_Fprintf(stderr,"\n. There seems to be a problem in one (or more) of your"); + PhyML_Fprintf(stderr,"\n. sequence alignments. PhyML could not match taxon"); + PhyML_Fprintf(stderr,"\n. '%s' found in file '%s' with any of the taxa",tree->a_nodes[i]->name,tree->io->in_align_file); + PhyML_Fprintf(stderr,"\n. listed in file '%s'.",tree->next->io->in_align_file); + Exit("\n"); + } + } + } + tree = tree->next; + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Ratematrix_From_XML_Node(xml_node *instance, option *io, t_mod *mod) +{ + char *model = NULL; + int select; + + model = XML_Get_Attribute_Value(instance,"model"); + + if(model == NULL) + { + PhyML_Fprintf(stderr,"\n. Poorly formated XML file."); + PhyML_Fprintf(stderr,"\n. Attribute 'model' is mandatory in a node."); + Exit("\n"); + } + + select = XML_Validate_Attr_Int(model,27, + "xxxxx", //0 + "JC69", //1 + "K80", //2 + "F81", //3 + "HKY85", //4 + "F84", //5 + "TN93", //6 + "GTR", //7 + "CUSTOM", //8 + "xxxxx", //9 + "xxxxx", //10 + "WAG", //11 + "DAYHOFF", //12 + "JTT", //13 + "BLOSUM62", //14 + "MTREV", //15 + "RTREV", //16 + "CPREV", //17 + "DCMUT", //18 + "VT", //19 + "MTMAM", //20 + "MTART", //21 + "HIVW", //22 + "HIVB", //23 + "FLU", //24 + "CUSTOMAA", //25 + "LG", //26 + "AB" ); //27 + + if(select < 9) + { + if(io->datatype != NT) + { + PhyML_Fprintf(stderr,"\n. Data type and selected model are incompatible"); + Exit("\n"); + } + } + else + { + if(io->datatype != AA) + { + PhyML_Fprintf(stderr,"\n. Data type and selected model are incompatible"); + Exit("\n"); + } + } + + mod->r_mat = (t_rmat *)Make_Rmat(mod->ns); + Init_Rmat(mod->r_mat); + + /*! Set model number & name */ + mod->whichmodel = Set_Whichmodel(select); + Set_Model_Name(mod); + + if(mod->whichmodel == K80 || + mod->whichmodel == HKY85 || + mod->whichmodel == TN93) + { + char *tstv,*opt_tstv; + + tstv = XML_Get_Attribute_Value(instance,"tstv"); + + if(tstv) + { + mod->s_opt->opt_kappa = NO; + mod->kappa->v = String_To_Dbl(tstv); + } + else + { + mod->s_opt->opt_kappa = YES; + } + + opt_tstv = XML_Get_Attribute_Value(instance,"optimise.tstv"); + + if(opt_tstv) + { + if(!strcmp(opt_tstv,"true") || !strcmp(opt_tstv,"yes")) + { + mod->s_opt->opt_kappa = YES; + mod->s_opt->opt_subst_param = YES; + } + else + { + mod->s_opt->opt_kappa = NO; + mod->s_opt->opt_subst_param = NO; + } + } + } + else + { + mod->s_opt->opt_kappa = NO; + } + + if(mod->whichmodel == GTR || mod->whichmodel == CUSTOM) + { + char *opt_rr; + + opt_rr = XML_Get_Attribute_Value(instance,"optimise.rr"); + + + if(opt_rr) + { + if(!strcmp(opt_rr,"yes") || !strcmp(opt_rr,"true")) + { + mod->s_opt->opt_rr = YES; + mod->s_opt->opt_subst_param = YES; + } + else + { + mod->s_opt->opt_rr = NO; + mod->s_opt->opt_subst_param = NO; + } + } + } + + if(mod->whichmodel == GTR || mod->whichmodel == CUSTOM) + { + xml_node *rr; + char *val; + phydbl v; + + rr = XML_Search_Node_Name("rr",YES,instance); + + if(rr != NULL) + { + mod->r_mat = (t_rmat *)Make_Rmat(mod->ns); + Init_Rmat(mod->r_mat); + Make_Custom_Model(mod); + + + // A<->C + val = XML_Get_Attribute_Value(rr,"AC"); + if(val == NULL) + { + PhyML_Printf("\n. Please specify the relative rate of substitution between A and T"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + else + { + v = strtod(val,NULL); + if(v != 0 && v > 0.0) + { + mod->r_mat->rr->v[0] = v; + mod->r_mat->rr_val->v[0] = log(v); + } + else + { + PhyML_Printf("\n. Invalid relative rate parameter value: '%s'.\n", val); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + + // A<->G + val = XML_Get_Attribute_Value(rr,"AG"); + if(val == NULL) + { + PhyML_Printf("\n. Please specify the relative rate of substitution between A and T"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + else + { + v = strtod(val,NULL); + if(v != 0 && v > 0.0) + { + mod->r_mat->rr->v[1] = v; + mod->r_mat->rr_val->v[1] = log(v); + } + else + { + PhyML_Printf("\n. Invalid relative rate parameter value: '%s'.\n", val); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + + // A<->T + val = XML_Get_Attribute_Value(rr,"AT"); + if(val == NULL) + { + PhyML_Printf("\n. Please specify the relative rate of substitution between A and T"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + else + { + v = strtod(val,NULL); + if(v != 0 && v > 0.0) + { + mod->r_mat->rr->v[2] = v; + mod->r_mat->rr_val->v[2] = log(v); + } + else + { + PhyML_Printf("\n. Invalid relative rate parameter value: '%s'.\n", val); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + + // C<->G + val = XML_Get_Attribute_Value(rr,"CG"); + if(val == NULL) + { + PhyML_Printf("\n. Please specify the relative rate of substitution between A and T"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + else + { + v = strtod(val,NULL); + if(v != 0 && v > 0.0) + { + mod->r_mat->rr->v[3] = v; + mod->r_mat->rr_val->v[3] = log(v); + } + else + { + PhyML_Printf("\n. Invalid relative rate parameter value: '%s'.\n", val); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + + + // C<->T + val = XML_Get_Attribute_Value(rr,"CT"); + if(val == NULL) + { + PhyML_Printf("\n. Please specify the relative rate of substitution between A and T"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + else + { + v = strtod(val,NULL); + if(v != 0 && v > 0.0) + { + mod->r_mat->rr->v[4] = v; + mod->r_mat->rr_val->v[4] = log(v); + } + else + { + PhyML_Printf("\n. Invalid relative rate parameter value: '%s'.\n", val); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + + // G<->T + val = XML_Get_Attribute_Value(rr,"GT"); + + if(val != NULL) + { + v = strtod(val,NULL); + if(v != 0 && v > 0.0) + { + mod->r_mat->rr->v[5] = v; + mod->r_mat->rr_val->v[5] = log(v); + } + else + { + PhyML_Printf("\n. Invalid relative rate parameter value: '%s'.\n", val); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + } + } + + + /*! Custom model for nucleotide sequences. Read the corresponding + code. */ + if(mod->whichmodel == CUSTOM) + { + char *model_code = NULL; + + model_code = XML_Get_Attribute_Value(instance,"model.code"); + + if(!model_code) + { + PhyML_Fprintf(stderr,"\n. No valid 'model.code' attribute could be found.\n"); + PhyML_Fprintf(stderr,"\n. Please fix your XML file.\n"); + Exit("\n"); + } + else + { + strcpy(mod->custom_mod_string->s,model_code); + } + } + + + /*! Custom model for amino-acids. Read in the rate matrix file */ + if(mod->whichmodel == CUSTOMAA) + { + char *r_mat_file; + + r_mat_file = XML_Get_Attribute_Value(instance,"ratematrix.file"); + + if(!r_mat_file) + { + PhyML_Fprintf(stderr,"\n. No valid 'ratematrix.file' attribute could be found."); + PhyML_Fprintf(stderr,"\n. Please fix your XML file.\n"); + Exit("\n"); + } + else + { + strcpy(mod->aa_rate_mat_file->s,r_mat_file); + } + + /* Free(r_mat_file); */ + } + + char *buff; + + buff = XML_Get_Attribute_Value(instance->parent,"optimise.weights"); + if(buff && (!strcmp(buff,"yes") || !strcmp(buff,"true"))) + { + mod->s_opt->opt_rmat_weight = YES; + } + else + { + mod->s_opt->opt_rmat_weight = NO; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Efrq_From_XML_Node(xml_node *instance, option *io, t_mod *mod) +{ + char *buff; + + mod->e_frq = (t_efrq *)Make_Efrq(mod->ns); + Init_Efrq(NULL,mod->e_frq); + + buff = XML_Get_Attribute_Value(instance,"optimise.freqs"); + + if(buff) + { + if(!strcmp(buff,"yes") || !strcmp(buff,"true")) + { + if(io->datatype == AA) + { + PhyML_Fprintf(stderr,"\n. Option 'optimise.freqs' set to 'yes' (or 'true')"); + PhyML_Fprintf(stderr,"\n. is not allowed with amino-acid data."); + Exit("\n"); + } + mod->s_opt->opt_state_freq = YES; + } + } + + buff = XML_Get_Attribute_Value(instance,"aa.freqs"); + + if(buff) + { + if(!strcmp(buff,"empirical")) + { + if(io->datatype == AA) + { + mod->s_opt->opt_state_freq = YES; + mod->e_frq->empirical_state_freq = YES; + } + else if(io->datatype == NT) + { + mod->s_opt->opt_state_freq = NO; + } + } + } + + + buff = XML_Get_Attribute_Value(instance,"base.freqs"); + + if(buff) + { + if(io->datatype == AA) + { + PhyML_Fprintf(stderr,"\n. Option 'base.freqs' is not allowed with amino-acid data."); + Exit("\n"); + } + else + { + phydbl A,C,G,T; + sscanf(buff,"%lf,%lf,%lf,%lf",&A,&C,&G,&T); + mod->e_frq->user_b_freq->v[0] = (phydbl)A; + mod->e_frq->user_b_freq->v[1] = (phydbl)C; + mod->e_frq->user_b_freq->v[2] = (phydbl)G; + mod->e_frq->user_b_freq->v[3] = (phydbl)T; + mod->e_frq->user_state_freq = YES; + mod->s_opt->opt_state_freq = NO; + } + } + + + buff = XML_Get_Attribute_Value(instance->parent,"optimise.weights"); + if(buff && (!strcmp(buff,"yes") || !strcmp(buff,"true"))) + { + mod->s_opt->opt_efrq_weight = YES; + } + else + { + mod->s_opt->opt_efrq_weight = NO; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Topology_From_XML_Node(xml_node *instance, option *io, t_mod *mod) +{ + // Starting tree + char *init_tree; + + init_tree = XML_Get_Attribute_Value(instance,"init.tree"); + + if(!init_tree) + { + PhyML_Fprintf(stderr,"\n. Attribute 'init.tree=bionj|user|random' is mandatory"); + PhyML_Fprintf(stderr,"\n. Please amend your XML file accordingly."); + Exit("\n"); + } + + if(!strcmp(init_tree,"user") || + !strcmp(init_tree,"User")) + { + char *starting_tree = NULL; + starting_tree = XML_Get_Attribute_Value(instance,"file.name"); + + if(!Filexists(starting_tree)) + { + PhyML_Fprintf(stderr,"\n. The tree file '%s' could not be found.",starting_tree); + Exit("\n"); + } + else + { + strcpy(io->in_tree_file,starting_tree); + io->in_tree = 2; + io->fp_in_tree = Openfile(io->in_tree_file,0); + } + } + else if(!strcmp(init_tree,"random") || + !strcmp(init_tree,"Random")) + { + char *n_rand_starts = NULL; + + io->mod->s_opt->random_input_tree = YES; + + n_rand_starts = XML_Get_Attribute_Value(instance,"n.rand.starts"); + + if(n_rand_starts) + { + mod->s_opt->n_rand_starts = atoi(n_rand_starts); + if(mod->s_opt->n_rand_starts < 1) Exit("\n. Number of random starting trees must be > 0.\n\n"); + } + + strcpy(io->out_trees_file,io->in_align_file); + strcat(io->out_trees_file,"_phyml_rand_trees"); + if(io->append_run_ID) { strcat(io->out_trees_file,"_"); strcat(io->out_trees_file,io->run_id_string); } + strcat(io->out_trees_file,".txt"); + io->fp_out_trees = Openfile(io->out_trees_file,1); + } + else if(!strcmp(init_tree,"parsimony") || + !strcmp(init_tree,"Parsimony")) + { + io->in_tree = 1; + } + + // Estimate tree topology + char *optimise = NULL; + + optimise = XML_Get_Attribute_Value(instance,"optimise.tree"); + + if(optimise) + { + int select; + + select = XML_Validate_Attr_Int(optimise,6, + "true","yes","y", + "false","no","n"); + + if(select > 2) io->mod->s_opt->opt_topo = NO; + else + { + char *search; + int select; + + search = XML_Get_Attribute_Value(instance,"search"); + + if(search == NULL) + { + io->mod->s_opt->topo_search = SPR_MOVE; + io->mod->s_opt->opt_topo = YES; + } + else + { + select = XML_Validate_Attr_Int(search,4,"spr","nni","best","none"); + + switch(select) + { + case 0: + { + io->mod->s_opt->topo_search = SPR_MOVE; + io->mod->s_opt->opt_topo = YES; + break; + } + case 1: + { + io->mod->s_opt->topo_search = NNI_MOVE; + io->mod->s_opt->opt_topo = YES; + break; + } + case 2: + { + io->mod->s_opt->topo_search = BEST_OF_NNI_AND_SPR; + io->mod->s_opt->opt_topo = YES; + break; + } + case 3: + { + io->mod->s_opt->opt_topo = NO; + break; + } + default: + { + PhyML_Fprintf(stderr,"\n. Topology search option '%s' is not valid.",search); + Exit("\n"); + break; + } + } + } + } + } +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_RAS_From_XML_Node(xml_node *parent, t_mod *mod) +{ + xml_node *w; + char *family; + int select; + + family = NULL; + mod->ras->n_catg = 0; + + XML_Check_Siterates_Node(parent); + + w = XML_Search_Node_Name("weights",YES,parent); + if(w) + { + family = XML_Get_Attribute_Value(w,"family"); + if(family == NULL) select = -1; + else select = XML_Validate_Attr_Int(family,3,"gamma","gamma+inv","freerates"); + switch(select) + { + case 0:// Gamma model + { + char *alpha,*alpha_opt; + + mod->s_opt->opt_pinvar = NO; + mod->ras->invar = NO; + + alpha = XML_Get_Attribute_Value(w,"alpha"); + + if(alpha) + { + if(!strcmp(alpha,"estimate") || !strcmp(alpha,"estimated") || + !strcmp(alpha,"optimise") || !strcmp(alpha,"optimised")) + { + mod->s_opt->opt_alpha = YES; + } + else + { + mod->s_opt->opt_alpha = NO; + mod->ras->alpha->v = String_To_Dbl(alpha); + } + } + + alpha_opt = XML_Get_Attribute_Value(w,"optimise.alpha"); + + if(alpha_opt) + { + if(!strcmp(alpha_opt,"yes") || !strcmp(alpha_opt,"true")) + { + mod->s_opt->opt_alpha = YES; + } + else + { + mod->s_opt->opt_alpha = NO; + } + } + + mod->ras->n_catg = XML_Get_Number_Of_Classes_Siterates(parent); + + Make_RAS_Complete(mod->ras); + + break; + } + case 1: // Gamma+Inv model + { + char *alpha,*pinv,*alpha_opt,*pinv_opt; + + mod->ras->invar = YES; + mod->s_opt->opt_pinvar = YES; + + alpha = XML_Get_Attribute_Value(w,"alpha"); + + if(alpha) + { + if(!strcmp(alpha,"estimate") || !strcmp(alpha,"estimated") || + !strcmp(alpha,"optimise") || !strcmp(alpha,"optimised")) + { + mod->s_opt->opt_alpha = YES; + } + else + { + mod->s_opt->opt_alpha = NO; + mod->ras->alpha->v = String_To_Dbl(alpha);; + } + } + + alpha_opt = XML_Get_Attribute_Value(w,"optimise.alpha"); + + if(alpha_opt) + { + if(!strcmp(alpha_opt,"yes") || !strcmp(alpha_opt,"true")) + { + mod->s_opt->opt_alpha = YES; + } + else + { + mod->s_opt->opt_alpha = NO; + } + } + + + pinv = XML_Get_Attribute_Value(w,"pinv"); + + if(pinv) + { + if(!strcmp(pinv,"estimate") || !strcmp(pinv,"estimated") || + !strcmp(pinv,"optimise") || !strcmp(pinv,"optimised")) + { + mod->s_opt->opt_pinvar = YES; + } + else + { + mod->s_opt->opt_pinvar = NO; + mod->ras->pinvar->v = String_To_Dbl(pinv);; + } + } + + pinv_opt = XML_Get_Attribute_Value(w,"optimise.pinv"); + + if(pinv_opt) + { + if(!strcmp(pinv_opt,"yes") || !strcmp(pinv_opt,"true")) + { + mod->s_opt->opt_pinvar = YES; + } + else + { + mod->s_opt->opt_pinvar = NO; + } + } + + mod->ras->n_catg = XML_Get_Number_Of_Classes_Siterates(parent); + break; + } + case 2: // FreeRate model + { + char *opt_freerates; + + mod->ras->free_mixt_rates = YES; + + mod->s_opt->opt_free_mixt_rates = YES; + + opt_freerates = XML_Get_Attribute_Value(w,"optimise.freerates"); + + if(opt_freerates) + { + if(!strcmp(opt_freerates,"yes") || !strcmp(opt_freerates,"true")) + { + mod->s_opt->opt_free_mixt_rates = YES; + } + else + { + mod->s_opt->opt_free_mixt_rates = NO; + } + } + + mod->ras->n_catg = XML_Get_Number_Of_Classes_Siterates(parent); + break; + } + default: + { + if(family != NULL) PhyML_Printf("\n. family: %s",family); + else + { + PhyML_Printf("\n. Please specify a model family (\"gamma\", \"gamma+inv\" or \"freerate\")"); + PhyML_Printf("\n. for every 'weights' element in every 'siterate' element. Note that " ); + PhyML_Printf("\n. a \"gamma\" or a \"freerate\" model with a single rate class amounts"); + PhyML_Printf("\n. to no variation of rates across sites, if this is the model you'd"); + PhyML_Printf("\n. like to implement..."); + } + + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + } + + int nc = XML_Get_Number_Of_Classes_Siterates(parent); + + if(w && nc != mod->ras->n_catg) + { + PhyML_Printf("\n. component '%s'. The number of classes ",parent->id); + PhyML_Printf("\n. specified in the component should be "); + PhyML_Printf("\n. the same as that of nodes. Please fix"); + PhyML_Printf("\n. your XML file accordingly."); + Exit("\n"); + } + + if(!w) mod->ras->n_catg = nc; + + Make_RAS_Complete(mod->ras); + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Generic_Exit(const char *file, int line, const char *function) +{ + PhyML_Fprintf(stderr,"\n. Err. in file '%s' (line %d)",file,line); + if(function != NULL) PhyML_Printf(", function '%s'",function); + +# if defined(PHYTIME) + PhyML_Fprintf(stderr,"\n. PhyTime finished prematurely."); +# elif defined(PHYREX) + PhyML_Fprintf(stderr,"\n. PhyREX finished prematurely."); +# elif defined(PHYML) + PhyML_Fprintf(stderr,"\n. PhyML finished prematurely."); +#else + PhyML_Fprintf(stderr,"\n. The execution finished prematurely."); +#endif + + Exit("\n"); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void JSON_Write_Object(json_o *obj, FILE *where) +{ + json_kv *kv; + + assert(obj); + assert(where); + + kv = obj->kv; + assert(kv); + + PhyML_Fprintf(where,"{"); + + do + { + PhyML_Fprintf(where,"\"%s\":",kv->key); + if(kv->value != NULL) PhyML_Fprintf(where,"\"%s\"",kv->value); + else if(kv->array != NULL) JSON_Write_Array(kv->array,where); + else if(kv->object != NULL) JSON_Write_Object(kv->object,where); + kv = kv->next; + if(kv) PhyML_Fprintf(where,","); + } + while(kv); + + PhyML_Fprintf(where,"}"); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void JSON_Write_Array(json_a *array, FILE *where) +{ + json_o *o; + + assert(where); + assert(array); + + o = array->object; + + assert(o); + + PhyML_Fprintf(where,"["); + + do + { + JSON_Write_Object(o,where); + o = o->next; + if(o) PhyML_Fprintf(where,","); + } + while(o); + + PhyML_Fprintf(where,"]\n"); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void JSON_Write_All(json_a *array, FILE *where) +{ + JSON_Write_Array(array,where); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +json_o *JSON_Tree_To_Object(t_tree *mixt_tree) +{ + t_tree *tree; + json_kv *state,*kv; + json_o *ret,*o; + json_a *a; + int string_len; + char *s; + time_t t_end; + + string_len = 20; + + ret = (json_o *)mCalloc(1,sizeof(json_o)); + ret->next = NULL; + + state = (json_kv *)mCalloc(1,sizeof(json_kv)); + ret->kv = state; + + state->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(state->key,"state"); + + state->value = NULL; state->array = NULL; state->object = NULL; state->next = NULL; + + state->array = (json_a *)mCalloc(1,sizeof(json_a)); + a = state->array; + + a->object = (json_o *)mCalloc(1,sizeof(json_o)); + o = a->object; + + // State num + o->kv = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = o->kv; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"type"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"t_num"); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"id"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"state_num"); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"value"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + sprintf(kv->value,"%d",mixt_tree->json_num); + mixt_tree->json_num++; + + kv->next = NULL; + + + + + // Time + o->next = (json_o *)mCalloc(1,sizeof(json_o)); + o = o->next; + + o->kv = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = o->kv; + + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"type"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"t_time"); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"id"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"time"); + + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"value"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + time(&t_end); + sprintf(kv->value,"%d",(int)(t_end-mixt_tree->t_beg)); + + kv->next = NULL; + + + // Tree + o->next = (json_o *)mCalloc(1,sizeof(json_o)); + o = o->next; + + o->kv = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = o->kv; + + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"type"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"t_tree"); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"id"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"tree"); + + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"value"); + s = Write_Tree(mixt_tree); + kv->value = (char *)mCalloc((int)strlen(s)+1,sizeof(char)); + sprintf(kv->value,"%s",s); + Free(s); + + kv->next = NULL; + + + + // Likelihood + o->next = (json_o *)mCalloc(1,sizeof(json_o)); + o = o->next; + + o->kv = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = o->kv; + + kv->value = NULL; kv->array = NULL; kv->object = NULL; o->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"type"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"t_param"); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"id"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"likelihood"); + + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"value"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + sprintf(kv->value,"%G",mixt_tree->c_lnL); + + kv->next = NULL; + + + + // TsTv + { + int n_tstv,i; + scalar_dbl **tstv; + + n_tstv = 0; + tstv = NULL; + tree = mixt_tree; + + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + + for(i=0;imod->kappa == tstv[i]) break; + + if(i == n_tstv) + { + if(!tstv) tstv = (scalar_dbl **)mCalloc(1,sizeof(scalar_dbl *)); + else tstv = (scalar_dbl **)mRealloc(tstv,n_tstv+1,sizeof(scalar_dbl *)); + tstv[n_tstv] = tree->mod->kappa; + n_tstv++; + + if(tree->mod->s_opt->opt_kappa == YES) + { + o->next = (json_o *)mCalloc(1,sizeof(json_o)); + o = o->next; + + o->kv = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = o->kv; + + kv->value = NULL; kv->array = NULL; kv->object = NULL; o->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"type"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"t_param"); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"id"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"tstv"); + sprintf(kv->value+strlen(kv->value),"%d",n_tstv); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"value"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + sprintf(kv->value,"%G",tree->mod->kappa->v); + + kv->next = NULL; + + } + } + tree = tree->next; + } + while(tree); + + if(tstv) Free(tstv); + } + + + + // Alpha + { + int n_alpha,i; + scalar_dbl **alpha; + + n_alpha = 0; + alpha = NULL; + tree = mixt_tree; + + do + { + + for(i=0;imod->ras->alpha == alpha[i]) break; + + if(i == n_alpha) + { + if(!alpha) alpha = (scalar_dbl **)mCalloc(1,sizeof(scalar_dbl *)); + else alpha = (scalar_dbl **)mRealloc(alpha,n_alpha+1,sizeof(scalar_dbl *)); + alpha[n_alpha] = tree->mod->ras->alpha; + n_alpha++; + + if(tree->mod->s_opt->opt_alpha == YES) + { + o->next = (json_o *)mCalloc(1,sizeof(json_o)); + o = o->next; + + o->kv = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = o->kv; + + kv->value = NULL; kv->array = NULL; kv->object = NULL; o->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"type"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"t_param"); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"id"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"alpha"); + sprintf(kv->value+strlen(kv->value),"%d",n_alpha); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"value"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + sprintf(kv->value,"%G",tree->mod->ras->alpha->v); + + kv->next = NULL; + + } + } + tree = tree->next_mixt; + } + while(tree); + + if(alpha) Free(alpha); + } + + + + // Tree size + { + tree = mixt_tree; + int tree_num = 1; + do + { + o->next = (json_o *)mCalloc(1,sizeof(json_o)); + o = o->next; + + o->kv = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = o->kv; + + kv->value = NULL; kv->array = NULL; kv->object = NULL; o->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"type"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"t_param"); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"id"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->value,"tree_size"); + sprintf(kv->value+strlen(kv->value),"%d",tree_num); + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"value"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + sprintf(kv->value,"%G",Get_Tree_Size(tree)); + + kv->next = NULL; + + tree = tree->next_mixt; + } + while(tree); + + } + + return(ret); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + + +json_o *JSON_Tree_To_Object_Light(t_tree *mixt_tree) +{ + t_tree *tree; + json_kv *state,*kv; + json_o *ret,*o; + int string_len; + char *s; + time_t t_end; + + string_len = 20; + + ret = (json_o *)mCalloc(1,sizeof(json_o)); + ret->next = NULL; + + state = (json_kv *)mCalloc(1,sizeof(json_kv)); + ret->kv = state; + + state->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(state->key,"state"); + + state->value = NULL; state->array = NULL; state->object = NULL; state->next = NULL; + + state->object = (json_o *)mCalloc(1,sizeof(json_o)); + o = state->object; + + + o->kv = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = o->kv; + + + // State num + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"state_num"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + sprintf(kv->value,"%d",mixt_tree->json_num); + + + + // Time + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"time"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + time(&t_end); + sprintf(kv->value,"%d",(int)(t_end-mixt_tree->t_beg)); + + + + + // Tree + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + + kv->value = NULL; kv->array = NULL; kv->object = NULL; kv->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"tree"); + s = Write_Tree(mixt_tree); + kv->value = (char *)mCalloc((int)strlen(s)+1,sizeof(char)); + sprintf(kv->value,"%s",s); + Free(s); + + + + + + // Likelihood + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; o->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"likelihood"); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + sprintf(kv->value,"%G",mixt_tree->c_lnL); + + + + + // TsTv + { + int n_tstv,i; + scalar_dbl **tstv; + + n_tstv = 0; + tstv = NULL; + tree = mixt_tree; + + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + + for(i=0;imod->kappa == tstv[i]) break; + + if(i == n_tstv) + { + if(!tstv) tstv = (scalar_dbl **)mCalloc(1,sizeof(scalar_dbl *)); + else tstv = (scalar_dbl **)mRealloc(tstv,n_tstv+1,sizeof(scalar_dbl *)); + tstv[n_tstv] = tree->mod->kappa; + n_tstv++; + + if(tree->mod->s_opt->opt_kappa == YES) + { + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; o->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"tstv"); + sprintf(kv->key+strlen(kv->key),"%d",n_tstv); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + sprintf(kv->value,"%G",tree->mod->kappa->v); + } + } + tree = tree->next; + } + while(tree); + + if(tstv) Free(tstv); + } + + + + // Alpha + { + int n_alpha,i; + scalar_dbl **alpha; + + n_alpha = 0; + alpha = NULL; + tree = mixt_tree; + + do + { + + for(i=0;imod->ras->alpha == alpha[i]) break; + + if(i == n_alpha) + { + if(!alpha) alpha = (scalar_dbl **)mCalloc(1,sizeof(scalar_dbl *)); + else alpha = (scalar_dbl **)mRealloc(alpha,n_alpha+1,sizeof(scalar_dbl *)); + alpha[n_alpha] = tree->mod->ras->alpha; + n_alpha++; + + if(tree->mod->s_opt->opt_alpha == YES) + { + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + kv->value = NULL; kv->array = NULL; kv->object = NULL; o->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"alpha"); + sprintf(kv->key+strlen(kv->key),"%d",n_alpha); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + sprintf(kv->value,"%G",tree->mod->ras->alpha->v); + } + } + tree = tree->next_mixt; + } + while(tree); + + if(alpha) Free(alpha); + } + + + + // Tree size + { + tree = mixt_tree; + int tree_num = 1; + do + { + + kv->next = (json_kv *)mCalloc(1,sizeof(json_kv)); + kv = kv->next; + + kv->value = NULL; kv->array = NULL; kv->object = NULL; o->next = NULL; + kv->key = (char *)mCalloc(string_len,sizeof(char)); + strcpy(kv->key,"tree_size"); + sprintf(kv->key+strlen(kv->key),"%d",tree_num); + kv->value = (char *)mCalloc(string_len,sizeof(char)); + sprintf(kv->value,"%G",Get_Tree_Size(tree)); + + tree = tree->next_mixt; + } + while(tree); + + } + + kv->next = NULL; + + return(ret); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void JSON_Tree_Io(t_tree *tree, FILE *where) +{ + // Append + json_o *o; + fpos_t pos; + char c; + + fgetpos(where,&pos); + + rewind(where); + c = fgetc(where); + + if(c != '[') + { + PhyML_Fprintf(where,"["); + } + else + { + fsetpos(where,&pos); + fseek(where,-1,SEEK_CUR); + PhyML_Fprintf(where,","); + } + + PhyML_Fprintf(where,"\n"); + /* o = JSON_Tree_To_Object(tree); */ + o = JSON_Tree_To_Object_Light(tree); + JSON_Write_Object(o,where); + JSON_Free_Object(o); + PhyML_Fprintf(where,"]"); + fflush(where); + + + // Print out latest tree + info + /* json_o *o; */ + + /* rewind(where); */ + /* /\* PhyML_Fprintf(where,"["); *\/ */ + /* o = JSON_Tree_To_Object(tree); */ + /* JSON_Write_Object(o,where); */ + /* JSON_Free_Object(o); */ + /* /\* PhyML_Fprintf(where,"]"); *\/ */ + /* fflush(where); */ + + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Print_Lk_Given_Edge_Recurr(t_node *a, t_node *d, t_edge *b, t_tree *tree) +{ + PhyML_Printf("\n___ Edge %3d (left=%3d rght=%3d) lnL=%f", + b->num, + b->left->num, + b->rght->num, + Lk(b,tree)); + + if(d->tax) return; + else + { + int i; + for(i=0;i<3;i++) + if(d->v[i] != a) + Print_Lk_Given_Edge_Recurr(d,d->v[i],d->b[i],tree); + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Collect_Edge_Support_Values(t_tree *tree) +{ + int i; + + for(i=0;i<2*tree->n_otu-3;++i) + { + if(tree->io->do_boot == YES) + { + tree->a_edges[i]->support_val = tree->a_edges[i]->bip_score; + } + else if(tree->io->do_tbe == YES) + { + int pminus1=MIN(tree->a_edges[i]->left->bip_size[tree->a_edges[i]->l_r], tree->a_edges[i]->rght->bip_size[tree->a_edges[i]->r_l])-1; + tree->a_edges[i]->support_val = 1-((tree->a_edges[i]->tdist_score)/(tree->io->n_boot_replicates*1.0))/pminus1; + } + else if(tree->io->do_alrt == YES) + { + tree->a_edges[i]->support_val = tree->a_edges[i]->ratio_test; + } + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + + +#if defined (PHYREX) +void PHYREX_Output_Tree_Structure(FILE *fp, t_tree *tree) +{ + char *s; + s = PHYREX_Print_Tree_Structure(tree); + PhyML_Fprintf(fp,"%s",s); + Free(s); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#if defined (PHYREX) +char *PHYREX_Print_Tree_Structure(t_tree *tree) +{ + t_dsk *disk; + char *s,*buff; + FILE *fp; + fpos_t pos; + + fp = tmpfile(); + assert(fp); + + buff = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + + disk = tree->young_disk; + while(disk->prev != NULL) disk = disk->prev; + + assert(disk->ldsk); + assert(disk->ldsk->n_next > 0); + + fgetpos(fp,&pos); + PhyML_Fprintf(fp,"begin\n"); + fsetpos(fp,&pos); + if(fgets(buff,T_MAX_LINE,fp) == NULL) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + s = (char *)mCalloc((int)strlen(buff)+1,sizeof(char)); + sprintf(s+strlen(s),"%s",buff); + + fgetpos(fp,&pos); + PhyML_Fprintf(fp,"%d %d\n",tree->n_otu,tree->mmod->n_dim); + fsetpos(fp,&pos); + if(fgets(buff,T_MAX_LINE,fp) == NULL) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + s = (char *)mRealloc(s,(int)(strlen(s)+strlen(buff)+1),sizeof(char)); + sprintf(s+strlen(s),"%s",buff); + + + do + { + fgetpos(fp,&pos); + PhyML_Fprintf(fp,"%s ",disk->id); + PhyML_Fprintf(fp,"%f ",disk->time); + PhyML_Fprintf(fp,"%f %f ",disk->centr->lonlat[0],disk->centr->lonlat[1]); + + if(disk->ldsk != NULL) + { + s = (char *)mRealloc(s,(int)strlen(s)+9,sizeof(char)); + PhyML_Fprintf(fp,"*%s ",disk->ldsk->coord->id); + PhyML_Fprintf(fp,"%f %f ",disk->ldsk->coord->lonlat[0],disk->ldsk->coord->lonlat[1]); + } + for(int i=0;in_ldsk_a;++i) + { + PhyML_Fprintf(fp,"%s ",disk->ldsk_a[i]->coord->id); + } + PhyML_Fprintf(fp,"\n"); + + fsetpos(fp,&pos); + if(fgets(buff,T_MAX_LINE,fp) == NULL) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + s = (char *)mRealloc(s,(int)(strlen(s)+strlen(buff)+1),sizeof(char)); + sprintf(s+strlen(s),"%s",buff); + + disk = disk->next; + } + while(disk); + + fgetpos(fp,&pos); + PhyML_Fprintf(fp,"end"); + fsetpos(fp,&pos); + if(fgets(buff,T_MAX_LINE,fp) == NULL) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + s = (char *)mRealloc(s,(int)(strlen(s)+strlen(buff)+1),sizeof(char)); + sprintf(s+strlen(s),"%s",buff); + + fclose(fp); + + Free(buff); + + return(s); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#if defined (PHYREX) +void PHYREX_Check_Point(FILE *fp, t_tree *tree) +{ + xml_node *n; + char *s; + + if(XML_Search_Node_Attribute_Value("add","true",NO,tree->xml_root) == NULL) + { + XML_Add_Attribute(tree->xml_root,"add","true"); + } + + n = XML_Search_Node_Name("slfv",YES,tree->xml_root); + if(n == NULL) + { + n = XML_Add_Node(tree->xml_root,"slfv"); + XML_Set_Node_Id(n,"SLFV1"); + } + + s = PHYREX_Print_Tree_Structure(tree); + XML_Set_Node_Value(n,s); + XML_Update_XML_Struct_Given_Model_Params(tree); + /* XML_Update_XML_Struct_Given_MCMC_Params(tree); */ + XML_Write_XML_Graph(fp,tree->xml_root); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#if defined (PHYREX) +void PHYREX_Input_Tree_Structure(FILE *fp) +{ + char *tk,*s,delim[4]="\n\r "; + int n_otu,n_dim,idx; + t_dsk *disk; + t_ldsk *new_ldsk,*root_ldsk,*ldsk; + + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + + do + { + if(fgets(s,T_MAX_LINE,fp) == NULL) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + while(strstr(s,"begin") == NULL); + + if(fgets(s,T_MAX_LINE,fp) == NULL) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + tk = strtok(s,delim); + n_otu = strtod(tk,NULL); + + tk = strtok(NULL,delim); + n_dim = strtod(tk,NULL); + + + root_ldsk = NULL; + new_ldsk = NULL; + while(fgets(s,T_MAX_LINE,fp) != NULL) + { + tk = strtok(s,delim); + if(strcmp(tk,"end") && tk != NULL) + { + disk = PHYREX_Make_Disk_Event(n_dim,n_otu); + strcpy(disk->id,tk); + + tk = strtok(NULL,delim); + disk->time = strtold(tk,NULL); + + tk = strtok(NULL,delim); + disk->centr->lonlat[0] = strtold(tk,NULL); + tk = strtok(NULL,delim); + disk->centr->lonlat[1] = strtold(tk,NULL); + + + tk = strtok(NULL,delim); + if(tk[0] == '*') // disk has ldsk on it + { + if(root_ldsk == NULL) + { + disk->ldsk = PHYREX_Make_Lindisk_Node(n_dim); + disk->ldsk->disk = disk; + root_ldsk = disk->ldsk; + } + else + { + disk->ldsk = PHYREX_Find_Ldsk_From_Id(tk+1,root_ldsk); + assert(disk->ldsk != NULL); + } + + strcpy(disk->ldsk->coord->id,tk+1); + + tk = strtok(NULL,delim); + disk->ldsk->coord->lonlat[0] = strtold(tk,NULL); + tk = strtok(NULL,delim); + disk->ldsk->coord->lonlat[1] = strtold(tk,NULL); + + + do + { + tk = strtok(NULL,delim); + if(tk == NULL) break; + new_ldsk = PHYREX_Make_Lindisk_Node(n_dim); + strcpy(new_ldsk->coord->id,tk); + PHYREX_Make_Lindisk_Next(disk->ldsk); + disk->ldsk->next[disk->ldsk->n_next-1] = new_ldsk; + disk->ldsk_a[disk->ldsk->n_next-1] = new_ldsk; + new_ldsk->prev = disk->ldsk; + } + while(tk); + } + else + { + idx = 0; + do + { + tk = strtok(NULL,delim); + if(tk == NULL) break; + ldsk = PHYREX_Find_Ldsk_From_Id(tk,root_ldsk); + assert(ldsk); + disk->ldsk_a[idx] = ldsk; + idx++; + } + while(tk); + + } + } + } + + Free(s); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Output_Scalar_Dbl(scalar_dbl *t, char *sep, FILE *fp) +{ + scalar_dbl *l; + l = t; + do + { + PhyML_Fprintf(fp,"%g%s",l->v,sep); + l = l->next; + } + while(l); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +// s should look like that: "xxx={yyy},xxxx={yy},..." +t_label *Read_Labels(char *s) +{ + t_label *lab,*init_lab; + char *s_cpy,*s_big,*s_small; + char *label; + char *key,*val; + + if(s[0] != '[' || s[(int)strlen(s)-1] != ']') + { + PhyML_Fprintf(stderr,"\n. Label is in wrong format. A proper label should"); + PhyML_Fprintf(stderr,"\n. look as follows: \"[xxx={yyy},xxxx={yy},...]\""); + assert(FALSE); + } + + lab = Make_Label(); + init_lab = lab; + + s_cpy = (char *)mCalloc((int)strlen(s)-1,sizeof(char)); + strncpy(s_cpy,s+1,(strlen(s)-2)*sizeof(char)); + s_cpy[strlen(s)-2]='\0'; + + + label = strtok_r(s_cpy,",",&s_big); + + while(label != NULL) + { + + key=strtok_r(label,"=",&s_small); + val=strtok_r(NULL,"=",&s_small); + + Free(lab->key); + lab->key = (char *)mCalloc(strlen(key)+1,sizeof(char)); + strcpy(lab->key,key); + + Free(lab->val); + lab->val = (char *)mCalloc(strlen(val)+1,sizeof(char)); + strcpy(lab->val,val); + + label = strtok_r(NULL,",",&s_big); + + if(label != NULL) + { + lab->sep=','; + lab->next = Make_Label(); + lab = lab->next; + } + } + + lab = init_lab; + + return(lab); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Print_Labels(FILE *fp_where, char *s_where, t_label *label) +{ + if(label == NULL) return; + else + { + t_label *lab; + + lab = label; + + if(fp_where != NULL) + { + PhyML_Fprintf(fp_where,"["); + } + else + { + sprintf(s_where+(int)strlen(s_where),"["); + } + + + while(lab) + { + if(fp_where != NULL) + { + PhyML_Fprintf(fp_where,"%s=%s",lab->key,lab->val); + if(lab->next != NULL) PhyML_Fprintf(fp_where,","); + } + else + { + sprintf(s_where+(int)strlen(s_where),"%s=%s",lab->key,lab->val); + if(lab->next != NULL) sprintf(s_where+(int)strlen(s_where),","); + } + + lab = lab->next; + } + + if(fp_where != NULL) + { + PhyML_Fprintf(fp_where,"]"); + } + else + { + sprintf(s_where+(int)strlen(s_where),"]"); + } + } +} + + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ diff --git a/phyml/io.h b/phyml/io.h new file mode 100644 index 0000000..f9094d1 --- /dev/null +++ b/phyml/io.h @@ -0,0 +1,118 @@ +/* + +PHYML : a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences + +Copyright (C) Stephane Guindon. Oct 2003 onward + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef IO_H +#define IO_H + +#include "utilities.h" + +t_tree *Read_Tree(char **s_tree); +void R_rtree(char *s_tree_a,char *s_tree_d,t_node *a,t_tree *tree,int *n_int,int *n_ext); +void Read_Node_Label(char *s_d, char *s_a, t_node *n); +void Read_Branch_Length(char *s_d, char *s_a, t_edge *b, t_tree *tree); +void Read_Node_Name(t_node *d, char *s_tree_d, t_edge *b, t_tree *tree); +void Clean_Multifurcation(char **subtrees,int current_deg,int end_deg); +char **Sub_Trees(char *tree,int *degree); +int Next_Par(char *s,int pos); +void Print_List(t_ll *list); +void Print_Tree(FILE *fp,t_tree *tree); +char *Write_Tree(t_tree *tree); +void R_wtree_Custom(t_node *pere,t_node *fils,int *available,char **s_tree,int *pos,t_tree *tree); +void Detect_Align_File_Format(option *io); +void Detect_Tree_File_Format(option *io); +align **Get_Seq(option *io); +void Get_Nexus_Data(FILE *fp,option *io); +int Get_Token(FILE *fp,char *token); +align **Get_Seq_Phylip(option *io); +void Read_Ntax_Len_Phylip(FILE *fp,int *n_otu,int *n_tax); +align **Read_Seq_Sequential(option *io); +align **Read_Seq_Interleaved(option *io); +int Read_One_Line_Seq(align ***data,int num_otu,FILE *in); +char *Return_Tree_String_Phylip(FILE *fp_input_tree); +t_tree *Read_Tree_File_Phylip(FILE *fp_input_tree); +void Print_Site_Lk(t_tree *tree,FILE *fp); +void Print_Seq(FILE *fp, align **data, int n_otu); +void Print_CSeq(FILE *fp,int compressed,calign *cdata,t_tree *tree); +void Print_CSeq_Select(FILE *fp,int compressed,calign *cdata,t_tree *tree); +void Print_Dist(matrix *mat); +void Print_Node(t_node *a,t_node *d,t_tree *tree); +void Print_Model(t_mod *mod); +void Print_Mat(matrix *mat); +FILE *Openfile(char *filename,int mode); +//void Print_Fp_Out(FILE *fp_out,time_t t_beg,time_t t_end,t_tree *tree,option *io,int n_data_set,int num_tree, int add_citation); +void Print_Fp_Out(FILE *fp_out,time_t t_beg,time_t t_end,t_tree *tree,option *io,int n_data_set,int num_tree, int add_citation, int precision); +void Print_Fp_Out_Lines(FILE *fp_out,time_t t_beg,time_t t_end,t_tree *tree,option *io,int n_data_set); +void Print_Freq(t_tree *tree); +void Print_Settings(option *io); +void Print_Banner(FILE *fp); +void Print_Banner_Small(FILE *fp); +void Print_Data_Set_Number(option *io,FILE *fp); +void Print_Lk(t_tree *tree,char *string); +void Print_Pars(t_tree *tree); +void Print_Lk_And_Pars(t_tree *tree); +void Read_Qmat(phydbl *daa,phydbl *pi,FILE *fp); +void Print_Qmat_AA(phydbl *daa,phydbl *pi); +void Print_Square_Matrix_Generic(int n,phydbl *mat); +void Print_Diversity(FILE *fp,t_tree *tree); +void Print_Diversity_Pre(t_node *a,t_node *d,t_edge *b,FILE *fp,t_tree *tree); +t_tree *Read_User_Tree(calign *cdata,t_mod *mod,option *io); +void Print_Time_Info(time_t t_beg,time_t t_end); +void Print_Time_Info_Brief(time_t t_beg,time_t t_end); +void PhyML_Printf(char *format,...); +void PhyML_Fprintf(FILE *fp,char *format,...); +void Read_Clade_Priors(char *file_name,t_tree *tree); +option *Get_Input(int argc,char **argv); +void Print_Data_Structure(int final, FILE *fp, t_tree *root); +int Set_Whichmodel(int select); +void Print_Site(calign *cdata, int num, int n_otu, char *sep, int stepsize, FILE *fp); +option *PhyML_XML(char *xml_filename); +void Check_Taxa_Sets(t_tree *mixt_tree); +void Make_Ratematrix_From_XML_Node(xml_node *instance, option *io, t_mod *mod); +void Make_Efrq_From_XML_Node(xml_node *instance, option *io, t_mod *mod); +void Make_Topology_From_XML_Node(xml_node *instance, option *io, t_mod *mod); +void Make_RAS_From_XML_Node(xml_node *parent, t_mod *mod); +void Post_Process_Data(option *io); +int *Return_Int(int in); +void Print_All_Edge_PMats(t_tree* tree); +void Print_All_Edge_Likelihoods(t_tree* tree); +void Print_Edge_Likelihoods(t_tree* tree, t_edge* b, bool scientific); +void Print_Edge_PMats(t_tree* tree, t_edge* b); +void Print_Tip_Partials(t_tree* tree, t_node* d); +void Dump_Arr_D(phydbl* arr, int num); +void Dump_Arr_S(short int* arr, int num); +void Dump_Arr_I(int* arr, int num); +void Print_Tree_Structure(t_tree* tree); +void Print_Node_Brief(t_node *a, t_node *d, t_tree *tree, FILE *fp); +void Generic_Exit(const char *file, int line, const char *function); +void JSON_Write_Object(json_o *obj, FILE *where); +void JSON_Write_Array(json_a *array, FILE *where); +void JSON_Write_All(json_a *array, FILE *where); +void JSON_Tree_Io(t_tree *tree, FILE *where); +json_o *JSON_Tree_To_Object(t_tree *tree); +json_o *JSON_Tree_To_Object_Light(t_tree *mixt_tree); +scalar_dbl *Read_Io_Weights(option *io); +void Print_Lk_Given_Edge_Recurr(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void R_wtree(t_node *pere, t_node *fils, t_edge *b, int *available, char **s_tree, t_tree *tree); +void Read_Branch_Support(char *s_d, char *s_a, t_edge *b, t_tree *tree); +void Collect_Edge_Support_Values(t_tree *tree); +void PHYREX_Output_Tree_Structure(FILE *fp, t_tree *tree); +void PHYREX_Input_Tree_Structure(FILE *fp); +int PhyML_Fscanf(FILE *fp, char *format, ...); +char *PHYREX_Print_Tree_Structure(t_tree *tree); +void PHYREX_Check_Point(FILE *fp, t_tree *tree); +void Output_Scalar_Dbl(scalar_dbl *t, char *sep, FILE *fp); +t_label *Read_Labels(char *s); +void Print_Labels(FILE *fp_where, char *s_where, t_label *label); + +#endif diff --git a/phyml/lk.c b/phyml/lk.c index 268bc5f..3201b02 100644 --- a/phyml/lk.c +++ b/phyml/lk.c @@ -10,1592 +10,3290 @@ the GNU public licence. See http://www.opensource.org for details. */ -#include "utilities.h" +#include "assert.h" #include "lk.h" -#include "optimiz.h" -#include "models.h" -#include "free.h" -#include "m4.h" -#include "mc.h" +#ifdef BEAGLE +#include "beagle_utils.h" +#endif +#include + -/* int LIM_SCALE; */ -/* phydbl LIM_SCALE_VAL; */ -/* phydbl MDBL_MAX; */ -/* phydbl MDBL_MIN; */ -/*********************************************************/ -void Init_Tips_At_One_Site_Nucleotides_Float(char state, phydbl *p_lk) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Init_Tips_At_One_Site_Nucleotides_Float(char state, int pos, phydbl *p_lk) { switch(state) { - case 'A' : p_lk[0]=1.; p_lk[1]=p_lk[2]=p_lk[3]=.0; + case 'A' : p_lk[pos+0]=1.; p_lk[pos+1]=p_lk[pos+2]=p_lk[pos+3]=.0; break; - case 'C' : p_lk[1]=1.; p_lk[0]=p_lk[2]=p_lk[3]=.0; + case 'C' : p_lk[pos+1]=1.; p_lk[pos+0]=p_lk[pos+2]=p_lk[pos+3]=.0; break; - case 'G' : p_lk[2]=1.; p_lk[1]=p_lk[0]=p_lk[3]=.0; + case 'G' : p_lk[pos+2]=1.; p_lk[pos+1]=p_lk[pos+0]=p_lk[pos+3]=.0; break; - case 'T' : p_lk[3]=1.; p_lk[1]=p_lk[2]=p_lk[0]=.0; + case 'T' : p_lk[pos+3]=1.; p_lk[pos+1]=p_lk[pos+2]=p_lk[pos+0]=.0; break; - case 'U' : p_lk[3]=1.; p_lk[1]=p_lk[2]=p_lk[0]=.0; + case 'U' : p_lk[pos+3]=1.; p_lk[pos+1]=p_lk[pos+2]=p_lk[pos+0]=.0; break; - case 'M' : p_lk[0]=p_lk[1]=1.; p_lk[2]=p_lk[3]=.0; + case 'M' : p_lk[pos+0]=p_lk[pos+1]=1.; p_lk[pos+2]=p_lk[pos+3]=.0; break; - case 'R' : p_lk[0]=p_lk[2]=1.; p_lk[1]=p_lk[3]=.0; + case 'R' : p_lk[pos+0]=p_lk[pos+2]=1.; p_lk[pos+1]=p_lk[pos+3]=.0; break; - case 'W' : p_lk[0]=p_lk[3]=1.; p_lk[1]=p_lk[2]=.0; + case 'W' : p_lk[pos+0]=p_lk[pos+3]=1.; p_lk[pos+1]=p_lk[pos+2]=.0; break; - case 'S' : p_lk[1]=p_lk[2]=1.; p_lk[0]=p_lk[3]=.0; + case 'S' : p_lk[pos+1]=p_lk[pos+2]=1.; p_lk[pos+0]=p_lk[pos+3]=.0; break; - case 'Y' : p_lk[1]=p_lk[3]=1.; p_lk[0]=p_lk[2]=.0; + case 'Y' : p_lk[pos+1]=p_lk[pos+3]=1.; p_lk[pos+0]=p_lk[pos+2]=.0; break; - case 'K' : p_lk[2]=p_lk[3]=1.; p_lk[0]=p_lk[1]=.0; + case 'K' : p_lk[pos+2]=p_lk[pos+3]=1.; p_lk[pos+0]=p_lk[pos+1]=.0; break; - case 'B' : p_lk[1]=p_lk[2]=p_lk[3]=1.; p_lk[0]=.0; + case 'B' : p_lk[pos+1]=p_lk[pos+2]=p_lk[pos+3]=1.; p_lk[pos+0]=.0; break; - case 'D' : p_lk[0]=p_lk[2]=p_lk[3]=1.; p_lk[1]=.0; + case 'D' : p_lk[pos+0]=p_lk[pos+2]=p_lk[pos+3]=1.; p_lk[pos+1]=.0; break; - case 'H' : p_lk[0]=p_lk[1]=p_lk[3]=1.; p_lk[2]=.0; + case 'H' : p_lk[pos+0]=p_lk[pos+1]=p_lk[pos+3]=1.; p_lk[pos+2]=.0; break; - case 'V' : p_lk[0]=p_lk[1]=p_lk[2]=1.; p_lk[3]=.0; + case 'V' : p_lk[pos+0]=p_lk[pos+1]=p_lk[pos+2]=1.; p_lk[pos+3]=.0; break; case 'N' : case 'X' : case '?' : case 'O' : case '-' : - p_lk[0]=p_lk[1]=p_lk[2]=p_lk[3]=1.;break; + p_lk[pos+0]=p_lk[pos+1]=p_lk[pos+2]=p_lk[pos+3]=1.;break; default : { - printf("\n. Unknown character state : %c\n",state); - Exit("\n. Init failed (check the data type)\n"); - break; + PhyML_Fprintf(stderr,"\n. Unknown character state : '%c'.\n",state); + Exit("\n. Init failed (data type supposed to be DNA)\n"); + break; } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Init_Tips_At_One_Site_Nucleotides_Int(char state, short int *p_pars) +void Init_Tips_At_One_Site_Nucleotides_Int(char state, int pos, short int *p_pars) { switch(state) { - case 'A' : p_pars[0]=1; p_pars[1]=p_pars[2]=p_pars[3]=0; + case 'A' : p_pars[pos+0]=1; p_pars[pos+1]=p_pars[pos+2]=p_pars[pos+3]=0; break; - case 'C' : p_pars[1]=1; p_pars[0]=p_pars[2]=p_pars[3]=0; + case 'C' : p_pars[pos+1]=1; p_pars[pos+0]=p_pars[pos+2]=p_pars[pos+3]=0; break; - case 'G' : p_pars[2]=1; p_pars[1]=p_pars[0]=p_pars[3]=0; + case 'G' : p_pars[pos+2]=1; p_pars[pos+1]=p_pars[pos+0]=p_pars[pos+3]=0; break; - case 'T' : p_pars[3]=1; p_pars[1]=p_pars[2]=p_pars[0]=0; + case 'T' : p_pars[pos+3]=1; p_pars[pos+1]=p_pars[pos+2]=p_pars[pos+0]=0; break; - case 'U' : p_pars[3]=1; p_pars[1]=p_pars[2]=p_pars[0]=0; + case 'U' : p_pars[pos+3]=1; p_pars[pos+1]=p_pars[pos+2]=p_pars[pos+0]=0; break; - case 'M' : p_pars[0]=p_pars[1]=1; p_pars[2]=p_pars[3]=0; + case 'M' : p_pars[pos+0]=p_pars[pos+1]=1; p_pars[pos+2]=p_pars[pos+3]=0; break; - case 'R' : p_pars[0]=p_pars[2]=1; p_pars[1]=p_pars[3]=0; + case 'R' : p_pars[pos+0]=p_pars[pos+2]=1; p_pars[pos+1]=p_pars[pos+3]=0; break; - case 'W' : p_pars[0]=p_pars[3]=1; p_pars[1]=p_pars[2]=0; + case 'W' : p_pars[pos+0]=p_pars[pos+3]=1; p_pars[pos+1]=p_pars[pos+2]=0; break; - case 'S' : p_pars[1]=p_pars[2]=1; p_pars[0]=p_pars[3]=0; + case 'S' : p_pars[pos+1]=p_pars[pos+2]=1; p_pars[pos+0]=p_pars[pos+3]=0; break; - case 'Y' : p_pars[1]=p_pars[3]=1; p_pars[0]=p_pars[2]=0; + case 'Y' : p_pars[pos+1]=p_pars[pos+3]=1; p_pars[pos+0]=p_pars[pos+2]=0; break; - case 'K' : p_pars[2]=p_pars[3]=1; p_pars[0]=p_pars[1]=0; + case 'K' : p_pars[pos+2]=p_pars[pos+3]=1; p_pars[pos+0]=p_pars[pos+1]=0; break; - case 'B' : p_pars[1]=p_pars[2]=p_pars[3]=1; p_pars[0]=0; + case 'B' : p_pars[pos+1]=p_pars[pos+2]=p_pars[pos+3]=1; p_pars[pos+0]=0; break; - case 'D' : p_pars[0]=p_pars[2]=p_pars[3]=1; p_pars[1]=0; + case 'D' : p_pars[pos+0]=p_pars[pos+2]=p_pars[pos+3]=1; p_pars[pos+1]=0; break; - case 'H' : p_pars[0]=p_pars[1]=p_pars[3]=1; p_pars[2]=0; + case 'H' : p_pars[pos+0]=p_pars[pos+1]=p_pars[pos+3]=1; p_pars[pos+2]=0; break; - case 'V' : p_pars[0]=p_pars[1]=p_pars[2]=1; p_pars[3]=0; + case 'V' : p_pars[pos+0]=p_pars[pos+1]=p_pars[pos+2]=1; p_pars[pos+3]=0; break; case 'N' : case 'X' : case '?' : case 'O' : case '-' : - p_pars[0]=p_pars[1]=p_pars[2]=p_pars[3]=1;break; + p_pars[pos+0]=p_pars[pos+1]=p_pars[pos+2]=p_pars[pos+3]=1;break; default : { - printf("\n. Unknown character state : %c\n",state); - Exit("\n. Init failed (check the data type)\n"); - break; + PhyML_Fprintf(stderr,"\n. Unknown character state : '%c'.\n",state); + Exit("\n. Init failed (data type supposed to be DNA)\n"); + break; } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Init_Tips_At_One_Site_AA_Float(char aa, phydbl *p_lk) +void Init_Tips_At_One_Site_AA_Float(char aa, int pos, phydbl *p_lk) { int i; - For(i,20) p_lk[i] = .0; + for(i=0;i<20;i++) p_lk[pos+i] = .0; switch(aa){ - case 'A' : p_lk[0]= 1.; break;/* Alanine */ - case 'R' : p_lk[1]= 1.; break;/* Arginine */ - case 'N' : p_lk[2]= 1.; break;/* Asparagine */ - case 'D' : p_lk[3]= 1.; break;/* Aspartic acid */ - case 'C' : p_lk[4]= 1.; break;/* Cysteine */ - case 'Q' : p_lk[5]= 1.; break;/* Glutamine */ - case 'E' : p_lk[6]= 1.; break;/* Glutamic acid */ - case 'G' : p_lk[7]= 1.; break;/* Glycine */ - case 'H' : p_lk[8]= 1.; break;/* Histidine */ - case 'I' : p_lk[9]= 1.; break;/* Isoleucine */ - case 'L' : p_lk[10]=1.; break;/* Leucine */ - case 'K' : p_lk[11]=1.; break;/* Lysine */ - case 'M' : p_lk[12]=1.; break;/* Methionine */ - case 'F' : p_lk[13]=1.; break;/* Phenylalanin */ - case 'P' : p_lk[14]=1.; break;/* Proline */ - case 'S' : p_lk[15]=1.; break;/* Serine */ - case 'T' : p_lk[16]=1.; break;/* Threonine */ - case 'W' : p_lk[17]=1.; break;/* Tryptophan */ - case 'Y' : p_lk[18]=1.; break;/* Tyrosine */ - case 'V' : p_lk[19]=1.; break;/* Valine */ - - case 'B' : p_lk[2]= 1.; break;/* Asparagine */ - case 'Z' : p_lk[5]= 1.; break;/* Glutamine */ - - case 'X' : case '?' : case '-' : For(i,20) p_lk[i] = 1.; break; + case 'A' : p_lk[pos+0]= 1.; break;/* Alanine */ + case 'R' : p_lk[pos+1]= 1.; break;/* Arginine */ + case 'N' : p_lk[pos+2]= 1.; break;/* Asparagine */ + case 'D' : p_lk[pos+3]= 1.; break;/* Aspartic acid */ + case 'C' : p_lk[pos+4]= 1.; break;/* Cysteine */ + case 'Q' : p_lk[pos+5]= 1.; break;/* Glutamine */ + case 'E' : p_lk[pos+6]= 1.; break;/* Glutamic acid */ + case 'G' : p_lk[pos+7]= 1.; break;/* Glycine */ + case 'H' : p_lk[pos+8]= 1.; break;/* Histidine */ + case 'I' : p_lk[pos+9]= 1.; break;/* Isoleucine */ + case 'L' : p_lk[pos+10]=1.; break;/* Leucine */ + case 'K' : p_lk[pos+11]=1.; break;/* Lysine */ + case 'M' : p_lk[pos+12]=1.; break;/* Methionine */ + case 'F' : p_lk[pos+13]=1.; break;/* Phenylalanin */ + case 'P' : p_lk[pos+14]=1.; break;/* Proline */ + case 'S' : p_lk[pos+15]=1.; break;/* Serine */ + case 'T' : p_lk[pos+16]=1.; break;/* Threonine */ + case 'W' : p_lk[pos+17]=1.; break;/* Tryptophan */ + case 'Y' : p_lk[pos+18]=1.; break;/* Tyrosine */ + case 'V' : p_lk[pos+19]=1.; break;/* Valine */ + + case 'B' : p_lk[pos+2]= 1.; break;/* Asparagine */ + case 'Z' : p_lk[pos+5]= 1.; break;/* Glutamine */ + + case 'X' : case '?' : case '-' : for(i=0;i<20;i++) p_lk[pos+i] = 1.; break; default : { - printf("\n. Unknown character state : %c\n",aa); - Exit("\n. Init failed (check the data type)\n"); + PhyML_Fprintf(stderr,"\n. Unknown character state : '%c'.\n",aa); + Exit("\n. Init failed (data type supposed to be amino-acids)\n"); break; } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Init_Tips_At_One_Site_AA_Int(char aa, short int *p_pars) +void Init_Tips_At_One_Site_AA_Int(char aa, int pos, short int *p_pars) { int i; - For(i,20) p_pars[i] = .0; + for(i=0;i<20;i++) p_pars[pos+i] = .0; switch(aa){ - case 'A' : p_pars[0] = 1; break;/* Alanine */ - case 'R' : p_pars[1] = 1; break;/* Arginine */ - case 'N' : p_pars[2] = 1; break;/* Asparagine */ - case 'D' : p_pars[3] = 1; break;/* Aspartic acid */ - case 'C' : p_pars[4] = 1; break;/* Cysteine */ - case 'Q' : p_pars[5] = 1; break;/* Glutamine */ - case 'E' : p_pars[6] = 1; break;/* Glutamic acid */ - case 'G' : p_pars[7] = 1; break;/* Glycine */ - case 'H' : p_pars[8] = 1; break;/* Histidine */ - case 'I' : p_pars[9] = 1; break;/* Isoleucine */ - case 'L' : p_pars[10] = 1; break;/* Leucine */ - case 'K' : p_pars[11] = 1; break;/* Lysine */ - case 'M' : p_pars[12] = 1; break;/* Methionine */ - case 'F' : p_pars[13] = 1; break;/* Phenylalanin */ - case 'P' : p_pars[14] = 1; break;/* Proline */ - case 'S' : p_pars[15] = 1; break;/* Serine */ - case 'T' : p_pars[16] = 1; break;/* Threonine */ - case 'W' : p_pars[17] = 1; break;/* Tryptophan */ - case 'Y' : p_pars[18] = 1; break;/* Tyrosine */ - case 'V' : p_pars[19] = 1; break;/* Valine */ - - case 'B' : p_pars[2] = 1; break;/* Asparagine */ - case 'Z' : p_pars[5] = 1; break;/* Glutamine */ - - case 'X' : case '?' : case '-' : For(i,20) p_pars[i] = 1; break; + case 'A' : p_pars[pos+0] = 1; break;/* Alanine */ + case 'R' : p_pars[pos+1] = 1; break;/* Arginine */ + case 'N' : p_pars[pos+2] = 1; break;/* Asparagine */ + case 'D' : p_pars[pos+3] = 1; break;/* Aspartic acid */ + case 'C' : p_pars[pos+4] = 1; break;/* Cysteine */ + case 'Q' : p_pars[pos+5] = 1; break;/* Glutamine */ + case 'E' : p_pars[pos+6] = 1; break;/* Glutamic acid */ + case 'G' : p_pars[pos+7] = 1; break;/* Glycine */ + case 'H' : p_pars[pos+8] = 1; break;/* Histidine */ + case 'I' : p_pars[pos+9] = 1; break;/* Isoleucine */ + case 'L' : p_pars[pos+10] = 1; break;/* Leucine */ + case 'K' : p_pars[pos+11] = 1; break;/* Lysine */ + case 'M' : p_pars[pos+12] = 1; break;/* Methionine */ + case 'F' : p_pars[pos+13] = 1; break;/* Phenylalanin */ + case 'P' : p_pars[pos+14] = 1; break;/* Proline */ + case 'S' : p_pars[pos+15] = 1; break;/* Serine */ + case 'T' : p_pars[pos+16] = 1; break;/* Threonine */ + case 'W' : p_pars[pos+17] = 1; break;/* Tryptophan */ + case 'Y' : p_pars[pos+18] = 1; break;/* Tyrosine */ + case 'V' : p_pars[pos+19] = 1; break;/* Valine */ + + case 'B' : p_pars[pos+2] = 1; break;/* Asparagine */ + case 'Z' : p_pars[pos+5] = 1; break;/* Glutamine */ + + case 'X' : case '?' : case '-' : for(i=0;i<20;i++) p_pars[pos+i] = 1; break; default : { - printf("\n. Unknown character state : %c\n",aa); - Exit("\n. Init failed (check the data type)\n"); + PhyML_Fprintf(stderr,"\n. Unknown character state : '%c'.\n",aa); + Exit("\n. Init failed (data type supposed to be amino-acids)\n"); break; } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Get_All_Partial_Lk_Scale(arbre *tree, edge *b_fcus, node *a, node *d) +void Init_Tips_At_One_Site_Generic_Float(char *state, int ns, int state_len, int pos, phydbl *p_lk) { - if(d->tax) return; + int i; + int state_int; + + for(i=0;i ns) + { + PhyML_Fprintf(stderr,"\n. %s %d cstate: %.2s istate: %d state_len: %d.\n",__FILE__,__LINE__,state,state_int,state_len); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit(""); + } + p_lk[pos+state_int] = 1.; + /* PhyML_Printf("\n. %s %d cstate: %.2s istate: %d state_len: %d ns: %d pos: %d",__FILE__,__LINE__,state,state_int,state_len,ns,pos); */ } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Post_Order_Lk(node *a, node *d, arbre *tree) +void Init_Tips_At_One_Site_Generic_Int(char *state, int ns, int state_len, int pos, short int *p_pars) { - int i,dir; + int i; + int state_int; - dir = -1; + for(i=0;itax) return; + if(Is_Ambigu(state,GENERIC,state_len)) for(i=0;iv[i] != a) - Post_Order_Lk(d,d->v[i],tree); - else dir = i; - } - Get_All_Partial_Lk_Scale(tree,d->b[dir],a,d); + char format[6]; + sprintf(format,"%%%dd",state_len); + if(!sscanf(state,format,&state_int)) + { + PhyML_Fprintf(stderr,"\n. state='%c'",state); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit(""); + } + if(state_int > ns) + { + PhyML_Fprintf(stderr,"\n. %s %d cstate: %.2s istate: %d state_len: %d.\n",__FILE__,__LINE__,state,state_int,state_len); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit(""); + } + p_pars[pos+state_int] = 1; +/* PhyML_Printf("\n* %s %d cstate: %.2s istate: %d state_len: %d ns: %d pos: %d",__FILE__,__LINE__,state,state_int,state_len,ns,pos); */ } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Pre_Order_Lk(node *a, node *d, arbre *tree) +void Get_All_Partial_Lk_Scale(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d) { - int i; + Update_Partial_Lk(tree,b_fcus,d); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +void Post_Order_Lk(t_node *a, t_node *d, t_tree *tree) +{ + int i,dir; + + dir = -1; + + /* PhyML_Printf("\n. %p a: %3d d: %3d root: %3d root->v1: %3d root->v2: %3d [%3d %3d %3d] (%3d %3d) (%3d %3d)", */ + /* tree, */ + /* a->num, */ + /* d->num, */ + /* tree->n_root?tree->n_root->num:-1, */ + /* tree->n_root->v[1]->num, */ + /* tree->n_root->v[2]->num, */ + /* d->v[0]?d->v[0]->num:-1, */ + /* d->v[1]?d->v[1]->num:-1, */ + /* d->v[2]?d->v[2]->num:-1, */ + /* tree->a_nodes[5]->num, */ + /* tree->a_nodes[5]->v[0]->num, */ + /* tree->mixt_tree? tree->mixt_tree->a_nodes[5]->num : -1, */ + /* tree->mixt_tree? tree->mixt_tree->a_nodes[5]->v[0]->num : -1); */ + if(d->tax) return; else { - For(i,3) - { - if(d->v[i] != a) - { - Get_All_Partial_Lk_Scale(tree,d->b[i],d->v[i],d); - Pre_Order_Lk(d,d->v[i],tree); - } - } + if(tree->is_mixt_tree) + { + MIXT_Post_Order_Lk(a,d,tree); + return; + } + + if(tree->n_root) + { + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + Post_Order_Lk(d,d->v[i],tree); + else dir = i; + } + } + else + { + for(i=0;i<3;i++) + { + if(d->v[i] != a) + Post_Order_Lk(d,d->v[i],tree); + else dir = i; + } + } + + if(dir < 0) + { + PhyML_Printf("\n. a->num: %d d->num: %d d->v[0]->num: %d d->v[1]->num: %d d->v[2]->num: %d d->b[0]->num: %d d->b[1]->num: %d d->b[2]->num: %d root ? %d e_root ? %d\n", + a?a->num:-1, + d?d->num:1, + d->v[0]?d->v[0]->num:-1, + d->v[1]?d->v[1]->num:-1, + d->v[2]?d->v[2]->num:-1, + d->b[0]?d->b[0]->num:-1, + d->b[1]?d->b[1]->num:-1, + d->b[2]?d->b[2]->num:-1, + tree->n_root?tree->n_root->num:-1, + tree->e_root?tree->e_root->num:-1); + assert(FALSE); + } + + if(tree->ignore_root == NO && d->b[dir] == tree->e_root) + { + if(d == tree->n_root->v[1]) Update_Partial_Lk(tree,tree->n_root->b[1],d); + else Update_Partial_Lk(tree,tree->n_root->b[2],d); + } + else + { + Update_Partial_Lk(tree,d->b[dir],d); + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Lk(arbre *tree) +void Pre_Order_Lk(t_node *a, t_node *d, t_tree *tree) { - int br,site; - int n_patterns; - - n_patterns = tree->n_pattern; - - tree->number_of_lk_calls++; - - Set_Model_Parameters(tree->mod); - -#ifndef PHYML - if(tree->bl_from_node_stamps) MC_Bl_From_T(tree); -#endif + int i; - For(br,2*tree->n_otu-3) + if(d->tax) return; + else { - if(!tree->t_edges[br]->rght->tax) - For(site,n_patterns) tree->t_edges[br]->sum_scale_f_rght[site] = .0; - - if(!tree->t_edges[br]->left->tax) - For(site,n_patterns) tree->t_edges[br]->sum_scale_f_left[site] = .0; - - Update_PMat_At_Given_Edge(tree->t_edges[br],tree); - } + if(tree->is_mixt_tree) + { + MIXT_Pre_Order_Lk(a,d,tree); + return; + } + + if(tree->n_root) + { + for(i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + Update_Partial_Lk(tree,d->b[i],d); + Pre_Order_Lk(d,d->v[i],tree); + } + } + } + else + { + for(i=0;i<3;++i) + { + if(d->v[i] != a) + { + Update_Partial_Lk(tree,d->b[i],d); + Pre_Order_Lk(d,d->v[i],tree); + } + } + } + } +} - Post_Order_Lk(tree->noeud[0],tree->noeud[0]->v[0],tree); - if(tree->both_sides) - Pre_Order_Lk(tree->noeud[0], - tree->noeud[0]->v[0], - tree); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - tree->c_lnL = .0; - tree->curr_catg = 0; - tree->curr_site = 0; - For(site,n_patterns) +// Updates all partial likelihood vectors. Depending on whether +// both_sides = YES or NO, only 'up' or 'up'&'down' partials will +// be updates +void Update_All_Partial_Lk(t_tree *tree) +{ + if(tree->n_root) { - tree->c_lnL_sorted[site] = .0; - tree->site_lk[site] = .0; - tree->curr_site = site; - Site_Lk(tree); + if(tree->ignore_root == NO) + { + Post_Order_Lk(tree->n_root,tree->n_root->v[1],tree); + Post_Order_Lk(tree->n_root,tree->n_root->v[2],tree); + + Update_Partial_Lk(tree,tree->n_root->b[1],tree->n_root); + Update_Partial_Lk(tree,tree->n_root->b[2],tree->n_root); + + if(tree->both_sides == YES) + { + Pre_Order_Lk(tree->n_root,tree->n_root->v[2],tree); + Pre_Order_Lk(tree->n_root,tree->n_root->v[1],tree); + } + } + else + { + + Post_Order_Lk(tree->e_root->rght,tree->e_root->left,tree); + Post_Order_Lk(tree->e_root->left,tree->e_root->rght,tree); + + if(tree->both_sides == YES) + { + Pre_Order_Lk(tree->e_root->rght,tree->e_root->left,tree); + Pre_Order_Lk(tree->e_root->left,tree->e_root->rght,tree); + } + } } - -/* Qksort(tree->c_lnL_sorted,0,n_patterns-1); */ - - tree->c_lnL = .0; - For(site,n_patterns) + else { - if(tree->c_lnL_sorted[site] < .0) /* WARNING : change cautiously */ - tree->c_lnL += tree->c_lnL_sorted[site]; + Post_Order_Lk(tree->a_nodes[tree->tip_root],tree->a_nodes[tree->tip_root]->v[0],tree); + if(tree->both_sides == YES) + Pre_Order_Lk(tree->a_nodes[tree->tip_root],tree->a_nodes[tree->tip_root]->v[0],tree); } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Site_Lk(arbre *tree) +phydbl Lk(t_edge *b, t_tree *tree) { - edge *eroot; - - eroot = tree->noeud[0]->b[0]; + unsigned int br,catg,state,ambiguity_check,site; + phydbl len,*expl,*dot_prod,*p_lk_left,*p_lk_rght; - if(!eroot->rght->tax) + const unsigned int ns = tree->mod->ns; + const unsigned int ncatg = tree->mod->ras->n_catg; + const unsigned int npatterns = tree->n_pattern; + const unsigned int nsncatg = ns * ncatg; + + tree->numerical_warning = NO; + + /* if(tree->eval_alnL == NO) return UNLIKELY; */ + + if(b == NULL && tree->mod->s_opt->curr_opt_free_rates == YES) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + tree->mod->s_opt->curr_opt_free_rates = NO; + Optimize_Free_Rate_Weights(tree,YES,YES); + tree->mod->s_opt->curr_opt_free_rates = YES; } + +#ifdef PHYREX + PHYREX_Ldsk_To_Tree(tree); +#endif + + + if(tree->is_mixt_tree == YES) + { +#ifdef BEAGLE + Warn_And_Exit(TODO_BEAGLE); +#endif + return MIXT_Lk(b,tree); + } + + tree->old_lnL = tree->c_lnL; + - if(tree->data->wght[tree->curr_site] > MDBL_MIN) Lk_Core(eroot,tree); - else tree->c_lnL_sorted[tree->curr_site] = 1.; /* WARNING : change cautiously */ -} - -/*********************************************************/ - -phydbl Lk_At_Given_Edge(edge *b_fcus, arbre *tree) -{ - int n_patterns; - - tree->number_of_branch_lk_calls++; - - n_patterns = tree->n_pattern; -#ifndef PHYML - if(tree->bl_from_node_stamps) MC_Bl_From_T(tree); +#if (defined PHYTIME || defined INVITEE || defined PHYREX) + if((tree->rates) && (tree->rates->bl_from_rt)) RATES_Update_Cur_Bl(tree); #endif - Update_PMat_At_Given_Edge(b_fcus,tree); + if(tree->rates && tree->io && tree->io->lk_approx == NORMAL) + { +#ifdef BEAGLE + Warn_And_Exit(TODO_BEAGLE); +#endif + tree->c_lnL = Lk_Normal_Approx(tree); + return tree->c_lnL; + } + + expl = tree->expl; + dot_prod = tree->dot_prod; + + + if(b == NULL) + { + Update_Boundaries(tree->mod); + Update_RAS(tree->mod); + Update_Efrq(tree->mod); + Update_Eigen(tree->mod); + } - if(b_fcus->left->tax) + + + if(tree->mod->s_opt->skip_tree_traversal == NO) { - printf("\n. Err in file %s at line %d",__FILE__,__LINE__); - Warn_And_Exit(""); + if(!b) //Update PMat for all edges + { + for(br=0;br<2*tree->n_otu-3;++br) + { + Update_PMat_At_Given_Edge(tree->a_edges[br],tree); + } + + if(tree->n_root && tree->ignore_root == NO) + { + Update_PMat_At_Given_Edge(tree->n_root->b[1],tree); + Update_PMat_At_Given_Edge(tree->n_root->b[2],tree); + } + } + else//Update PMat for a specific edge + { + if(tree->use_eigen_lr == NO) Update_PMat_At_Given_Edge(b,tree); + } + + if(!b) + { + if(tree->n_root != NULL) + { + if(tree->ignore_root == NO) + { + Post_Order_Lk(tree->n_root,tree->n_root->v[1],tree); + Post_Order_Lk(tree->n_root,tree->n_root->v[2],tree); + + Update_Partial_Lk(tree,tree->n_root->b[1],tree->n_root); + Update_Partial_Lk(tree,tree->n_root->b[2],tree->n_root); + + if(tree->both_sides == YES) + { + Pre_Order_Lk(tree->n_root,tree->n_root->v[2],tree); + Pre_Order_Lk(tree->n_root,tree->n_root->v[1],tree); + } + } + else + { + Post_Order_Lk(tree->e_root->rght,tree->e_root->left,tree); + Post_Order_Lk(tree->e_root->left,tree->e_root->rght,tree); + + if(tree->both_sides == YES) + { + Pre_Order_Lk(tree->e_root->rght,tree->e_root->left,tree); + Pre_Order_Lk(tree->e_root->left,tree->e_root->rght,tree); + } + } + } + else + { + Post_Order_Lk(tree->a_nodes[tree->tip_root],tree->a_nodes[tree->tip_root]->v[0],tree); + if(tree->both_sides == YES) + Pre_Order_Lk(tree->a_nodes[tree->tip_root],tree->a_nodes[tree->tip_root]->v[0],tree); + } + } } - tree->c_lnL = .0; - For(tree->curr_site,n_patterns) + if(!b) { - if(tree->data->wght[tree->curr_site] > MDBL_MIN) Lk_Core(b_fcus,tree); - else tree->c_lnL_sorted[tree->curr_site] = 1.; /* WARNING : change cautiously */ + if(tree->n_root) + { + if(tree->ignore_root == NO) + b = (tree->n_root->v[1]->tax == NO)?(tree->n_root->b[2]):(tree->n_root->b[1]); + else + b = tree->e_root; + } + else + b = tree->a_nodes[tree->tip_root]->b[0]; } -/* Qksort(tree->c_lnL_sorted,0,n_patterns-1); */ + tree->c_lnL = .0; + tree->sum_min_sum_scale = .0; - tree->c_lnL = .0; - For(tree->curr_site,n_patterns) - if(tree->c_lnL_sorted[tree->curr_site] < .0) /* WARNING : change cautiously */ - tree->c_lnL += tree->c_lnL_sorted[tree->curr_site]; +#ifdef BEAGLE + calc_edgelks_beagle(b, tree); +#else - return tree->c_lnL; -} + + if(tree->update_eigen_lr == YES) Update_Eigen_Lr(b,tree); + + if(tree->use_eigen_lr == YES) + { + for(catg=0;catgl->v)*tree->mod->ras->gamma_rr->v[catg]; + len *= tree->mod->br_len_mult->v; + if(tree->mixt_tree != NULL) len *= tree->mixt_tree->mod->ras->gamma_rr->v[tree->mod->ras->parent_class_number]; + if(len < tree->mod->l_min) len = tree->mod->l_min; + else if(len > tree->mod->l_max) len = tree->mod->l_max; + for(state=0;statemod->eigen->e_val[state],len); + } + } -/*********************************************************/ + p_lk_left = b->p_lk_left; + p_lk_rght = b->rght->tax ? b->p_lk_tip_r : b->p_lk_rght; -phydbl Lk_Core(edge *b, arbre *tree) -{ - phydbl log_site_lk, site_lk, site_lk_cat; - phydbl scale_left, scale_rght; - phydbl sum; - int ambiguity_check,state; - int catg,ns,k,l,site; - - log_site_lk = site_lk = site_lk_cat = .0; - ambiguity_check = state = -1; - site = tree->curr_site; - ns = tree->mod->ns; - - scale_left = - (b->sum_scale_f_left)? - (b->sum_scale_f_left[site]): - (0.0); - - scale_rght = - (b->sum_scale_f_rght)? - (b->sum_scale_f_rght[site]): - (0.0); - - if((b->rght->tax) && (!tree->mod->s_opt->greedy)) - { - ambiguity_check = tree->data->c_seq[b->rght->num]->is_ambigu[site]; - if(!ambiguity_check) state = Get_State_From_P_Pars(b->p_lk_tip_r[site],tree); - } - - if(tree->mod->use_m4mod) ambiguity_check = 1; - - For(catg,tree->mod->n_catg) - { - site_lk_cat = .0; - - if((b->rght->tax) && (!tree->mod->s_opt->greedy)) - { - if(!ambiguity_check) - { - sum = .0; - For(l,ns) - { - sum += - (phydbl)(b->Pij_rr[catg][state][l]) * - b->p_lk_left[site][catg][l]; - } - site_lk_cat += sum * tree->mod->pi[state]; - } - else - { - For(k,ns) - { - sum = .0; - if(b->p_lk_tip_r[site][k] > .0) - { - For(l,ns) - { - sum += - (phydbl)(b->Pij_rr[catg][k][l]) * - b->p_lk_left[site][catg][l]; - } - site_lk_cat += - sum * - tree->mod->pi[k] * - (phydbl)(b->p_lk_tip_r[site][k]); - } - } - } - } - else - { - For(k,ns) - { - sum = .0; - if(b->p_lk_rght[site][catg][k] > .0) - { - For(l,ns) - { - sum += - (phydbl)(b->Pij_rr[catg][k][l]) * - b->p_lk_left[site][catg][l]; - } - site_lk_cat += - sum * - tree->mod->pi[k] * - b->p_lk_rght[site][catg][k]; - } - } - } - - tree->log_site_lk_cat[catg][site] = site_lk_cat; - site_lk += site_lk_cat * tree->mod->gamma_r_proba[catg]; - - } - - /* site_lk may be too small ? */ - if(site_lk < 1.E-300) site_lk = 1.E-300; - - if(!tree->mod->invar) - { - log_site_lk = (phydbl)log(site_lk) + scale_left + scale_rght; - } - else + CALL++; + + + for(site=0;sitedata->invar[site] > -0.5) - { - if((scale_left + scale_rght > 0.0) || (scale_left + scale_rght < 0.0)) - site_lk *= (phydbl)exp(scale_left + scale_rght); - - log_site_lk = (phydbl)log(site_lk*(1.0-tree->mod->pinvar) + tree->mod->pinvar*tree->mod->pi[tree->data->invar[site]]); - } + ambiguity_check = -1; + state = -1; + tree->curr_site = site; + + if((b->rght->tax) && (tree->mod->s_opt->greedy == NO)) + { + ambiguity_check = b->rght->c_seq->is_ambigu[tree->curr_site]; + if(ambiguity_check == NO) + { + state = b->rght->c_seq->d_state[tree->curr_site]; + } + } + + if(tree->mod->use_m4mod) ambiguity_check = YES; + + if(tree->use_eigen_lr == YES) + { + if(tree->data->wght[site] > SMALL) Lk_Core_Eigen_Lr(expl,dot_prod,b,tree); + dot_prod += nsncatg; + } else - { - log_site_lk = (phydbl)log(site_lk*(1.0-tree->mod->pinvar)) + scale_left + scale_rght; - } + { + if(tree->data->wght[site] > SMALL) Lk_Core(state,ambiguity_check,p_lk_left,p_lk_rght,b->Pij_rr,b->tPij_rr,b,tree); + + if(b->rght->tax == YES) + { + p_lk_left += nsncatg; + p_lk_rght += ns; + } + else + { + p_lk_left += nsncatg; + p_lk_rght += nsncatg; + } + } } +#endif + + return tree->c_lnL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// First derivative of the log-likelihood with respect +// to the length of edge b +phydbl dLk(phydbl *l, t_edge *b, t_tree *tree) +{ + unsigned int catg,state,site; + phydbl len,rr; + phydbl lk,dlk,dlnlk,lnlk; + phydbl ev,expevlen; + + const unsigned int ns = tree->mod->ns; + const unsigned int ncatg = tree->mod->ras->n_catg; + const unsigned int npattern = tree->n_pattern; + + phydbl *dot_prod = tree->dot_prod; + phydbl *expl = tree->expl; + + tree->numerical_warning = NO; - if(log_site_lk < -MDBL_MAX) Warn_And_Exit("\nlog_site_lk < -MDBL_MAX\n"); + assert(isnan(*l) == FALSE); + + if(*l < tree->mod->l_min) *l = tree->mod->l_min; + else if(*l > tree->mod->l_max) *l = tree->mod->l_max; - For(catg,tree->mod->n_catg) - tree->log_site_lk_cat[catg][site] = - (phydbl)log(tree->log_site_lk_cat[catg][site]) + - scale_left + - scale_rght; + assert(b != NULL); - tree->site_lk[site] = log_site_lk; - tree->c_lnL_sorted[site] = tree->data->wght[site]*log_site_lk; - return log_site_lk; -} + if(tree->is_mixt_tree == YES) + { +#ifdef BEAGLE + Warn_And_Exit(TODO_BEAGLE); +#endif + return MIXT_dLk(l,b,tree); + } + + if(tree->update_eigen_lr == YES) Update_Eigen_Lr(b,tree); + + for(catg=0;catgmod->ras->gamma_rr->v[catg]; + rr *= tree->mod->br_len_mult->v; + + len = (*l) * rr; + + if(isinf(len) || isnan(len)) + { + PhyML_Fprintf(stderr,"\n. len=%f rr=%f l=%f",len,rr,*l); + assert(FALSE); + } + + if(len < tree->mod->l_min) len = tree->mod->l_min; + else if(len > tree->mod->l_max) len = tree->mod->l_max; + // value of rr should be corrected too if any of these two conditions + // is true. Leads to numerical precision issues though... + + + for(state=0;statemod->eigen->e_val[state]; + expevlen = exp(ev*len); + + expl[catg*2*ns + 2*state] = expevlen; + expl[catg*2*ns + 2*state + 1] = expevlen*ev*rr; + } + } + + dlnlk = 0.0; + lnlk = 0.0; + + for(site=0;sitedata->wght[site] > SMALL) + { + tree->curr_site = site; + + Lk_dLk_Core_Eigen_Lr(expl,dot_prod+site*ns*ncatg,b,&lk,&dlk,tree); + + assert(lk > .0); + + dlk /= lk; + dlnlk += tree->data->wght[site] * dlk; + lnlk += tree->data->wght[site] * (log(lk) - (phydbl)LOG2 * tree->fact_sum_scale[site]); + } + } -/*********************************************************/ + tree->c_dlnL = dlnlk; + tree->c_lnL = lnlk; -phydbl Return_Lk(arbre *tree) -{ - Lk(tree); return tree->c_lnL; } -/*********************************************************/ - -phydbl Return_Abs_Lk(arbre *tree) -{ - Lk(tree); - return fabs(tree->c_lnL); -} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ +/* Core of the likelihood calculation. Assume that the partial likelihoods on both + sides of t_edge *b are up-to-date. Calculate the log-likelihood at one site. + Note: this function can be used to evaluate first or second derivative of the + likelihood function with respect to the length of b, at a given site. Hence, be + careful with the meaning of 'site_lk'. If 'derivative=TRUE', then site_lk is + either the first or second derivative of the likelihood at that site, given the + length of edge 'b'. +*/ -matrix *ML_Dist(allseq *data, model *mod) +phydbl Lk_Core(int state, int ambiguity_check, + phydbl *p_lk_left, phydbl *p_lk_rght, + phydbl *Pij_rr, + phydbl *tPij_rr, + t_edge *b, + t_tree *tree) { - int i,j,k,l; - phydbl init; - int n_catg; - phydbl d_max,sum; - matrix *mat; - allseq *twodata,*tmpdata; - int state0, state1,len; - phydbl *F; - eigen *eigen_struct; - - tmpdata = (allseq *)mCalloc(1,sizeof(allseq)); - tmpdata->c_seq = (seq **)mCalloc(2,sizeof(seq *)); - tmpdata->b_frq = (phydbl *)mCalloc(mod->ns,sizeof(phydbl)); - tmpdata->ambigu = (short int *)mCalloc(data->crunch_len,sizeof(short int)); - F = (phydbl *)mCalloc(mod->ns*mod->ns,sizeof(phydbl )); - eigen_struct = (eigen *)Make_Eigen_Struct(mod); - - tmpdata->n_otu = 2; + phydbl site_lk,res,*pi,*site_lk_cat,log_site_lk; + unsigned int catg; + + const unsigned int ns = tree->mod->ns; + const unsigned int ncatg = tree->mod->ras->n_catg; + const unsigned int site = tree->curr_site; + const unsigned nsns = ns*ns; - tmpdata->crunch_len = 0; - tmpdata->init_len = 0; - For(i,data->crunch_len) + + assert(tree->data->wght[site] > SMALL); + + pi = tree->mod->e_frq->pi->v; + + if(tree->mod->s_opt->skip_tree_traversal == NO) { - if(data->wght[i] > .0) - { - tmpdata->crunch_len++; - tmpdata->init_len+=(int)data->wght[i]; - } + for(catg=0;catgsite_lk_cat[catg] = AVX_Lk_Core_One_Class_No_Eigen_Lr(p_lk_left,p_lk_rght,Pij_rr,tPij_rr,pi,ns,ambiguity_check,state); +#elif (defined(__SSE3__)) + tree->site_lk_cat[catg] = SSE_Lk_Core_One_Class_No_Eigen_Lr(p_lk_left,p_lk_rght,Pij_rr,tPij_rr,pi,ns,ambiguity_check,state); +#else + tree->site_lk_cat[catg] = Lk_Core_One_Class_No_Eigen_Lr(p_lk_left,p_lk_rght,Pij_rr,pi,ns,ambiguity_check,state); +#endif + } + else + { + tree->site_lk_cat[catg] = Lk_Core_One_Class_No_Eigen_Lr(p_lk_left,p_lk_rght,Pij_rr,pi,ns, ambiguity_check, state); + } + + Pij_rr += nsns; + tPij_rr += nsns; + if(b->left->tax == NO) p_lk_left += ns; + if(b->rght->tax == NO) p_lk_rght += ns; + } + + Pull_Scaling_Factors(site,b,tree); + } - mat = - (mod->datatype == NT) ? - ((mod->whichmodel < 10)?(K80_dist(data,2000)):(JC69_Dist(data,mod))): - (JC69_Dist(data,mod)); + site_lk = .0; + site_lk_cat = tree->unscaled_site_lk_cat + site*ncatg; + for(catg=0;catgmod->ras->gamma_r_proba->v[catg]; - For(i,mod->n_catg) /* Don't use gamma distribution */ + if(tree->mod->ras->invar == YES) { - mod->gamma_rr[i] = 1.0; - mod->gamma_r_proba[i] = 1.0; + int num_prec_issue = NO; + phydbl inv_site_lk = Invariant_Lk(tree->fact_sum_scale[site],site,&num_prec_issue,tree); + + switch(num_prec_issue) + { + case YES : + { + assert(isinf(inv_site_lk)); + tree->fact_sum_scale[site] = 0; + inv_site_lk = Invariant_Lk(0,site,&num_prec_issue,tree); + site_lk = inv_site_lk * tree->mod->ras->pinvar->v; + break; + } + case NO : + { + site_lk = site_lk * (1. - tree->mod->ras->pinvar->v) + inv_site_lk * tree->mod->ras->pinvar->v; + break; + } + } + } - n_catg = mod->n_catg; - mod->n_catg = 1; + if(tree->apply_lk_scaling == YES) res = site_lk / pow(2,tree->fact_sum_scale[site]); + else res = site_lk; - For(j,data->n_otu-1) + if(site_lk < SMALL) { - tmpdata->c_seq[0] = data->c_seq[j]; - tmpdata->c_seq[0]->name = data->c_seq[j]->name; - tmpdata->wght = data->wght; + site_lk = SMALL; + tree->numerical_warning = YES; + } - for(k=j+1;kn_otu;k++) - { - tmpdata->c_seq[1] = data->c_seq[k]; - tmpdata->c_seq[1]->name = data->c_seq[k]->name; - - twodata = Compact_CSeq(tmpdata,mod); - For(l,mod->ns) twodata->b_frq[l] = data->b_frq[l]; - Check_Ambiguities(twodata,mod->datatype,1); - Hide_Ambiguities(twodata); - - init = mat->dist[j][k]; - if((init == DIST_MAX) || (init < .0)) init = 0.1; - - d_max = init; - - For(i,mod->ns*mod->ns) F[i]=.0; - len = 0; - For(l,twodata->c_seq[0]->len) - { - state0 = Assign_State(twodata->c_seq[0]->state+l,mod->datatype,mod->stepsize); - state1 = Assign_State(twodata->c_seq[1]->state+l,mod->datatype,mod->stepsize); - if((state0 > -1) && (state1 > -1)) - { - F[mod->ns*state0+state1] += twodata->wght[l]; - len += (int)twodata->wght[l]; - } - } - if(len > .0) {For(i,mod->ns*mod->ns) F[i] /= (phydbl)len;} - - sum = 0.; - For(i,mod->ns*mod->ns) sum += F[i]; - if(sum < .001) d_max = -1.; - else if((sum > 1. - .001) && (sum < 1. + .001)) Opt_Dist_F(&(d_max),F,mod); - else - { - printf("\n. sum = %f\n",sum); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Exit(""); - } - - /* BRENT */ - /* d_max = Optimize_Dist(mod,init,twodata); */ - -/* printf("\n. Warning : not using the ML pairwise distances..."); */ -/* d_max = init; */ - - if(d_max >= DIST_MAX) - { -/* printf("\n. Large distance encountered between %s and %s sequences.", */ -/* tmpdata->c_seq[1]->name, */ -/* tmpdata->c_seq[0]->name); */ - d_max = DIST_MAX; - } - - /* Do not correct for dist < BL_MIN, otherwise Fill_Missing_Dist - * will not be called - */ - - mat->dist[j][k] = d_max; - mat->dist[k][j] = mat->dist[j][k]; - Free_Cseq(twodata); - } - } - - mod->n_catg = n_catg; + + log_site_lk = log(site_lk) - (phydbl)LOG2 * tree->fact_sum_scale[site]; // log_site_lk = log(site_lk_scaled / 2^(left_subtree+right_subtree)) + tree->c_lnL_sorted[site] = log_site_lk; + tree->c_lnL += tree->data->wght[site] * log_site_lk; + tree->cur_site_lk[site] = exp(log_site_lk); // note to self : add opt out option to avoid calculating this if not necessary - Free(tmpdata->ambigu); - Free(tmpdata->b_frq); - Free(tmpdata->c_seq); - free(tmpdata); - Free_Eigen(eigen_struct); - Free(F); - - return mat; + /* printf("\n. clnL: %f",tree->c_lnL); */ + return res; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Lk_Given_Two_Seq(allseq *data, int numseq1, int numseq2, phydbl dist, model *mod, phydbl *loglk) +phydbl Lk_Core_Eigen_Lr(phydbl *expl, phydbl *dot_prod, t_edge *b, t_tree *tree) { - seq *seq1,*seq2; - phydbl site_lk,log_site_lk; - int i,j,k,l; - phydbl **p_lk_l,**p_lk_r; - phydbl len; + phydbl site_lk,res,*site_lk_cat,log_site_lk; + unsigned int catg; + int num_prec_issue; + + const unsigned int ns = tree->mod->ns; + const unsigned int ncatg = tree->mod->ras->n_catg; + const unsigned int site = tree->curr_site; - DiscreteGamma(mod->gamma_r_proba, mod->gamma_rr, mod->alpha, - mod->alpha,mod->n_catg,1); + assert(tree->data->wght[site] > SMALL); + + if(tree->mod->s_opt->skip_tree_traversal == NO) + { + for(catg=0;catgmod->io->datatype == NT || tree->mod->io->datatype == AA) + { +#if (defined(__AVX__) || defined(__AVX2__)) + tree->site_lk_cat[catg] = AVX_Lk_Core_One_Class_Eigen_Lr(dot_prod,expl ? expl : NULL,ns); +#elif (defined(__SSE3__)) + tree->site_lk_cat[catg] = SSE_Lk_Core_One_Class_Eigen_Lr(dot_prod,expl ? expl : NULL,ns); +#else + tree->site_lk_cat[catg] = Lk_Core_One_Class_Eigen_Lr(dot_prod,expl ? expl : NULL,ns); +#endif + } + else + { + tree->site_lk_cat[catg] = Lk_Core_One_Class_Eigen_Lr(dot_prod,expl ? expl : NULL,ns); + } - seq1 = data->c_seq[numseq1]; - seq2 = data->c_seq[numseq2]; + dot_prod += ns; + if(expl) expl += ns; + } - p_lk_l = (phydbl **)mCalloc(data->c_seq[0]->len,sizeof(phydbl *)); - p_lk_r = (phydbl **)mCalloc(data->c_seq[0]->len,sizeof(phydbl *)); + Pull_Scaling_Factors(site,b,tree); - For(i,data->c_seq[0]->len) - { - p_lk_l[i] = (phydbl *)mCalloc(mod->ns,sizeof(phydbl)); - p_lk_r[i] = (phydbl *)mCalloc(mod->ns,sizeof(phydbl)); } - - if(dist < BL_MIN) dist = BL_START; - else if(dist > BL_MAX) dist = BL_START; - - For(i,mod->n_catg) + + + site_lk_cat = tree->unscaled_site_lk_cat + site*ncatg; + site_lk = .0; + for(catg=0;catgmod->ras->gamma_r_proba->v[catg]; + + if(tree->mod->ras->invar == YES) { - len = dist*mod->gamma_rr[i]; - if(len < BL_MIN) len = BL_MIN; - else if(len > BL_MAX) len = BL_MAX; - PMat(len,mod,&(mod->Pij_rr[i])); + num_prec_issue = NO; + phydbl inv_site_lk = Invariant_Lk(tree->fact_sum_scale[site],site,&num_prec_issue,tree); + + switch(num_prec_issue) + { + case YES : + { + assert(isinf(inv_site_lk)); + tree->fact_sum_scale[site] = 0; + inv_site_lk = Invariant_Lk(0,site,&num_prec_issue,tree); + site_lk = inv_site_lk * tree->mod->ras->pinvar->v; + break; + } + case NO : + { + site_lk = site_lk * (1. - tree->mod->ras->pinvar->v) + inv_site_lk * tree->mod->ras->pinvar->v; + break; + } + } } - if(mod->datatype == NT) - { - For(i,data->c_seq[0]->len) - { - Init_Tips_At_One_Site_Nucleotides_Float(seq1->state[i],p_lk_l[i]); - Init_Tips_At_One_Site_Nucleotides_Float(seq2->state[i],p_lk_r[i]); - } - } - else + if(site_lk < SMALL) { - For(i,data->c_seq[0]->len) - { - Init_Tips_At_One_Site_AA_Float(seq1->state[i],p_lk_l[i]); - Init_Tips_At_One_Site_AA_Float(seq2->state[i],p_lk_r[i]); - } + site_lk = SMALL; + tree->numerical_warning = YES; } + // likelihood (or 1st, 2nd derivative) not rescaled here. Valid only if all partial likelihoods + // were scaled using the same factor, i.e., when scaling_method == SCALE_FAST. In this case, the + // scaling factors will cancel out in dlk/lk and d2lk/lk + res = site_lk; + + log_site_lk = log(site_lk) - (phydbl)LOG2 * tree->fact_sum_scale[site]; // log_site_lk = log(site_lk_scaled / 2^(left_subtree+right_subtree)) + tree->c_lnL_sorted[site] = log_site_lk; + tree->c_lnL += tree->data->wght[site] * log_site_lk; + tree->cur_site_lk[site] = exp(log_site_lk); // note to self : add opt out option to avoid calculating this if not necessary + + return res; +} - site_lk = .0; - *loglk = 0; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Compute likelihood and first derivative of likelihood with respect to the length of edge b *unscaled* +void Lk_dLk_Core_Eigen_Lr(phydbl *expl, phydbl *dot_prod, t_edge *b, phydbl *lk, phydbl *dlk, t_tree *tree) +{ + phydbl core_lk,core_dlk; + unsigned int catg; + int num_prec_issue; + + const unsigned int ns = tree->mod->ns; + const unsigned int ncatg = tree->mod->ras->n_catg; + const unsigned int site = tree->curr_site; + + *lk = *dlk = 0.0; - For(i,data->c_seq[0]->len) + assert(tree->data->wght[site] > SMALL); + + if(tree->mod->s_opt->skip_tree_traversal == NO) { - if(data->wght[i]) - { - site_lk = log_site_lk = .0; - if(!data->ambigu[i]) - { - For(k,mod->ns) {if(p_lk_l[i][k] > .0001) break;} - For(l,mod->ns) {if(p_lk_r[i][l] > .0001) break;} - For(j,mod->n_catg) - { - site_lk += - mod->gamma_r_proba[j] * - mod->pi[k] * - p_lk_l[i][k] * - (phydbl)mod->Pij_rr[j][k][l] * - p_lk_r[i][l]; - } - } - else - { - For(j,mod->n_catg) - { - For(k,mod->ns) /*sort sum terms ? No global effect*/ - { - For(l,mod->ns) - { - site_lk += - mod->gamma_r_proba[j] * - mod->pi[k] * - p_lk_l[i][k] * - (phydbl)mod->Pij_rr[j][k][l] * - p_lk_r[i][l]; - } - } - } - } - -/* printf("'%c' '%c' -> %f\n",seq1->state[i],seq2->state[i],site_lk); */ - - if(site_lk <= .0) - { - printf("'%c' '%c'\n",seq1->state[i],seq2->state[i]); - Exit("\n. Err: site lk <= 0\n"); - } - - log_site_lk += (phydbl)log(site_lk); - - *loglk += data->wght[i] * log_site_lk;/* sort sum terms ? No global effect*/ - } + for(catg=0;catgmod->io->datatype == NT || tree->mod->io->datatype == AA) + { +#if (defined(__AVX__) || defined(__AVX2__)) + AVX_Lk_dLk_Core_One_Class_Eigen_Lr(dot_prod, + expl ? expl : NULL, + ns,&core_lk,&core_dlk); +#elif (defined(__SSE3__)) + SSE_Lk_dLk_Core_One_Class_Eigen_Lr(dot_prod, + expl ? expl : NULL, + ns,&core_lk,&core_dlk); +#else + Lk_dLk_Core_One_Class_Eigen_Lr(dot_prod, + expl ? expl : NULL, + ns,&core_lk,&core_dlk); +#endif + } + else + { + Lk_dLk_Core_One_Class_Eigen_Lr(dot_prod, + expl ? expl : NULL, + ns,&core_lk,&core_dlk); + } + + *lk += core_lk * tree->mod->ras->gamma_r_proba->v[catg]; + *dlk += core_dlk * tree->mod->ras->gamma_r_proba->v[catg]; + + dot_prod += ns; + if(expl) expl += 2*ns; + } + Pull_Scaling_Factors(site,b,tree); } - - For(i,data->c_seq[0]->len) + + if(tree->mod->ras->invar == YES) { - Free(p_lk_l[i]); - Free(p_lk_r[i]); + num_prec_issue = NO; + phydbl inv_site_lk = Invariant_Lk(tree->fact_sum_scale[site],site,&num_prec_issue,tree); + + switch(num_prec_issue) + { + case YES : + { + *lk = inv_site_lk * tree->mod->ras->pinvar->v; + *dlk = 0.0; + break; + } + case NO : + { + *lk = *lk * (1. - tree->mod->ras->pinvar->v) + inv_site_lk * tree->mod->ras->pinvar->v; + *dlk = *dlk * (1. - tree->mod->ras->pinvar->v); + break; + } + } } - Free(p_lk_l); Free(p_lk_r); - return *loglk; -} - -/*********************************************************/ -void Unconstraint_Lk(arbre *tree) -{ - int i; - - tree->unconstraint_lk = .0; - - For(i,tree->data->crunch_len) + if(*lk < SMALL) { - tree->unconstraint_lk += - tree->data->wght[i]*(phydbl)log(tree->data->wght[i]); + *lk = SMALL; + tree->numerical_warning = YES; } - tree->unconstraint_lk -= - tree->data->init_len*(phydbl)log(tree->data->init_len); } -/*********************************************************/ -void Update_P_Lk(arbre *tree, edge *b, node *d) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Update_Eigen_Lr(t_edge *b, t_tree *tree) { -/* - | - |<- b_cus - | - n - / \ - / \ - / \ -*/ - node *n_v1, *n_v2; - phydbl p1_lk1,p2_lk2; - phydbl ***p_lk,***p_lk_v1,***p_lk_v2; - double ***Pij1,***Pij2; - phydbl max_p_lk; - phydbl *sum_scale, *sum_scale_v1, *sum_scale_v2; - phydbl scale_v1, scale_v2; - int i,j; - int catg,site; - int dir1,dir2; - int n_patterns; - int ambiguity_check_v1,ambiguity_check_v2; - int state_v1,state_v2; + unsigned int site,catg,i,j; + phydbl *dot_prod,*r_e_vect,*l_e_vect,*p_lk_left,*p_lk_rght,*pi; + phydbl left,rght; - state_v1 = state_v2 = -1; - ambiguity_check_v1 = ambiguity_check_v2 = -1; - scale_v1 = scale_v2 = 0.0; - p1_lk1 = p2_lk2 = .0; - - - if(d->tax) - { - printf("\n. node %d is a leaf...",d->num); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit("\n"); - } + const unsigned int npattern = tree->n_pattern; + const unsigned int ns = tree->mod->ns; + const unsigned int ncatg = tree->mod->ras->n_catg; + const unsigned int nsncatg = ns*ncatg; -/* n_patterns = (int)floor(tree->n_pattern*tree->prop_of_sites_to_consider); */ - n_patterns = tree->n_pattern; - - dir1=dir2=-1; - For(i,3) if(d->b[i] != b) (dir1<0)?(dir1=i):(dir2=i); - n_v1 = d->v[dir1]; - n_v2 = d->v[dir2]; - - if(d == b->left) - { - p_lk = b->p_lk_left; - sum_scale = b->sum_scale_f_left; - } - else + if(tree->is_mixt_tree == YES) { - p_lk = b->p_lk_rght; - sum_scale = b->sum_scale_f_rght; + MIXT_Update_Eigen_Lr(b,tree); + return; } - - if(d == d->b[dir1]->left) + + if(tree->mod->ns == 4 || tree->mod->ns == 20) { - p_lk_v1 = d->b[dir1]->p_lk_rght; - sum_scale_v1 = d->b[dir1]->sum_scale_f_rght; +#if (defined(__AVX__) || defined(__AVX2__)) + AVX_Update_Eigen_Lr(b,tree); + return; +#elif (defined(__SSE3__)) + SSE_Update_Eigen_Lr(b,tree); + return; +#endif } - else + + assert(tree->update_eigen_lr == YES); + + dot_prod = tree->dot_prod; + r_e_vect = tree->mod->eigen->r_e_vect; + l_e_vect = tree->mod->eigen->l_e_vect; + pi = tree->mod->e_frq->pi->v; + + if(b->left->tax == YES) p_lk_left = b->p_lk_tip_l; + else p_lk_left = b->p_lk_left; + + if(b->rght->tax == YES) p_lk_rght = b->p_lk_tip_r; + else p_lk_rght = b->p_lk_rght; + + for(site=0;siteb[dir1]->p_lk_left; - sum_scale_v1 = d->b[dir1]->sum_scale_f_left; + if(tree->data->wght[site] > SMALL) + { + for(catg=0;catgleft->tax == NO) p_lk_left += ns; + if(b->rght->tax == NO) p_lk_rght += ns; + } + if(b->left->tax == YES) p_lk_left += ns; + if(b->rght->tax == YES) p_lk_rght += ns; + } + else + { + if(b->left->tax == YES) p_lk_left += ns; + else p_lk_left += nsncatg; + + if(b->rght->tax == YES) p_lk_rght += ns; + else p_lk_rght += nsncatg; + + dot_prod += nsncatg; + } } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Rate_Correction(int exponent, phydbl *site_lk_cat) +{ + int piecewise_exponent; + phydbl multiplier,dum; + unsigned long long int one = 1; - if(d == d->b[dir2]->left) + dum = *site_lk_cat; + if(exponent >= 0) { - p_lk_v2 = d->b[dir2]->p_lk_rght; - sum_scale_v2 = d->b[dir2]->sum_scale_f_rght; + /* Multiply by 2^exponent */ + do + { + piecewise_exponent = MIN(exponent,63); + multiplier = (phydbl)(one << piecewise_exponent); + dum = dum * multiplier; + exponent = exponent - piecewise_exponent; + } + while(exponent != 0); } else { - p_lk_v2 = d->b[dir2]->p_lk_left; - sum_scale_v2 = d->b[dir2]->sum_scale_f_left; + /* Divide by 2^exponent */ + do + { + piecewise_exponent = MAX(exponent,-63); + multiplier = 1. / (phydbl)(one << -piecewise_exponent); + dum = dum * multiplier; + exponent = exponent - piecewise_exponent; + } + while(exponent != 0); } - - Pij1 = d->b[dir1]->Pij_rr; - Pij2 = d->b[dir2]->Pij_rr; - - For(site,n_patterns) - { - scale_v1 = (sum_scale_v1)?(sum_scale_v1[site]):(0.0); - scale_v2 = (sum_scale_v2)?(sum_scale_v2[site]):(0.0); - sum_scale[site] = scale_v1 + scale_v2; - max_p_lk = -MDBL_MAX; - state_v1 = state_v2 = -1; - ambiguity_check_v1 = ambiguity_check_v2 = -1; - - if(!tree->mod->s_opt->greedy) - { - if(n_v1->tax) - { - ambiguity_check_v1 = tree->data->c_seq[n_v1->num]->is_ambigu[site]; - if(!ambiguity_check_v1) state_v1 = Get_State_From_P_Pars(n_v1->b[0]->p_lk_tip_r[site],tree); - } - - if(n_v2->tax) - { - ambiguity_check_v2 = tree->data->c_seq[n_v2->num]->is_ambigu[site]; - if(!ambiguity_check_v2) state_v2 = Get_State_From_P_Pars(n_v2->b[0]->p_lk_tip_r[site],tree); - } - } - - if(tree->mod->use_m4mod) - { - ambiguity_check_v1 = 1; - ambiguity_check_v2 = 1; - } - - For(catg,tree->mod->n_catg) - { - For(i,tree->mod->ns) - { - p1_lk1 = .0; - - if((n_v1->tax) && (!tree->mod->s_opt->greedy)) - { - if(!ambiguity_check_v1) - { - p1_lk1 = (phydbl)Pij1[catg][i][state_v1]; - } - else - { - For(j,tree->mod->ns) - { - p1_lk1 += (phydbl)(Pij1[catg][i][j]) * (phydbl)(n_v1->b[0]->p_lk_tip_r[site][j]); - } - } - } - else - { - For(j,tree->mod->ns) - { - p1_lk1 += (phydbl)(Pij1[catg][i][j]) * (phydbl)(p_lk_v1[site][catg][j]); - } - } - - p2_lk2 = .0; - - if((n_v2->tax) && (!tree->mod->s_opt->greedy)) - { - if(!ambiguity_check_v2) - { - p2_lk2 = (phydbl)Pij2[catg][i][state_v2]; - } - else - { - For(j,tree->mod->ns) - { - p2_lk2 += (phydbl)(Pij2[catg][i][j]) * (phydbl)(n_v2->b[0]->p_lk_tip_r[site][j]); - } - } - } - else - { - For(j,tree->mod->ns) - { - p2_lk2 += (phydbl)(Pij2[catg][i][j]) * (phydbl)(p_lk_v2[site][catg][j]); - } - } - - p_lk[site][catg][i] = p1_lk1 * p2_lk2; - - - if(p_lk[site][catg][i] > max_p_lk) max_p_lk = p_lk[site][catg][i]; - } - } - - if((max_p_lk < LIM_SCALE_VAL) || (max_p_lk > (1./LIM_SCALE_VAL))) - { - For(catg,tree->mod->n_catg) - { - For(i,tree->mod->ns) - { - p_lk[site][catg][i] /= max_p_lk; - -/* if((p_lk[site][catg][i] > MDBL_MAX) || (p_lk[site][catg][i] < MDBL_MIN)) */ -/* { */ -/* printf("\n. Err in file %s at line %d",__FILE__,__LINE__); */ -/* printf("\n. p_lk[%3d][%2d][%3d] = %G max_p_lk = %G",site,catg,i,p_lk[site][catg][i],max_p_lk); */ -/* printf("\n. alpha=%f pinv=%f",tree->mod->alpha,tree->mod->pinvar); */ -/* For(i,tree->mod->n_catg) printf("\n. rr[%2d] = %G",i,tree->mod->rr[i]); */ -/* printf("\n. d->b[dir1]->l = %f, d->b[dir2]->l = %f",d->b[dir1]->l,d->b[dir2]->l); */ -/* printf("\n. d->v[dir1]->num = %d, d->v[dir2]->num = %d",d->v[dir1]->num,d->v[dir2]->num); */ -/* if(d->v[dir1]->tax) */ -/* { */ -/* printf("\n. Character observed at d->v[dir1] = %d",state_v1); */ -/* } */ -/* if(d->v[dir2]->tax) */ -/* { */ -/* printf("\n. Character observed at d->v[dir2] = %d",state_v2); */ -/* } */ -/* Warn_And_Exit("\n. Numerical precision problem ! (send me an e-mail : s.guindon@auckland.ac.nz)\n"); */ -/* } */ - } - } - sum_scale[site] += (phydbl)log(max_p_lk); - } - } + *site_lk_cat = dum; } -/*********************************************************/ - +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Make_Tree_4_Lk(arbre *tree, allseq *alldata, int n_site) +phydbl Lk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, int ns) { - int i; + unsigned int l; + phydbl lk = 0.0; + if(expl != NULL) for(l=0;lc_lnL_sorted = (phydbl *)mCalloc(tree->n_pattern, sizeof(phydbl)); - tree->site_lk = (phydbl *)mCalloc(alldata->crunch_len,sizeof(phydbl)); - tree->log_site_lk_cat = (phydbl **)mCalloc(tree->mod->n_catg,sizeof(phydbl *)); - For(i,tree->mod->n_catg) - tree->log_site_lk_cat[i] = (phydbl *)mCalloc(alldata->crunch_len,sizeof(phydbl)); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - tree->log_lks_aLRT = (phydbl **)mCalloc(3,sizeof(phydbl *)); - For(i,3) tree->log_lks_aLRT[i] = (phydbl *)mCalloc(tree->data->init_len,sizeof(phydbl)); +void Lk_dLk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, unsigned int ns, phydbl *lk, phydbl *dlk) +{ + unsigned int i; - For(i,2*tree->n_otu-3) + *lk = *dlk = 0.0; + for(i=0;it_edges[i],tree); - Make_Edge_NNI(tree->t_edges[i]); + *lk += dot_prod[i] * expl[2*i]; + *dlk += dot_prod[i] * expl[2*i+1]; } - - For(i,2*tree->n_otu-2) Make_Node_Lk(tree->noeud[i]); - - if(tree->mod->s_opt->greedy) Init_P_Lk_Tips_Double(tree); - else Init_P_Lk_Tips_Int(tree); } + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ - -void Init_P_Lk_Tips_Double(arbre *tree) +phydbl Lk_Core_One_Class_No_Eigen_Lr(phydbl *p_lk_left, phydbl *p_lk_rght, phydbl *Pij,phydbl *pi, int ns, int ambiguity_check, int state) { - int curr_site,i,j,k; - - Fors(curr_site,tree->data->crunch_len,tree->mod->stepsize) - { - For(i,tree->n_otu) - { - if (tree->mod->datatype == NT) - { - if(tree->noeud[i]->b[0]->rght->tax != 1) - { - printf("\n. tree->noeud[i]->b[0]->rght->num = %d ; %f %f %f %f\n", - tree->noeud[i]->b[0]->rght->num, - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][0], - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][1], - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][2], - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][3]); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Exit(""); - } - - Init_Tips_At_One_Site_Nucleotides_Float(tree->data->c_seq[i]->state[curr_site], - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0]); - } - else - { - Init_Tips_At_One_Site_AA_Float(tree->data->c_seq[i]->state[curr_site], - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0]); - } - - for(j=1;jmod->n_catg;j++) - { - For(k,tree->mod->ns) - { - tree->noeud[i]->b[0]->p_lk_rght[curr_site][j][k]= - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][k]; - } - } - } - } - - #ifndef PHYML - if(tree->mod->m4mod) M4_Init_P_Lk_Tips_Double(tree); - #endif -} - -/*********************************************************/ + unsigned int l,k; + phydbl lk = 0.0; + phydbl sum; -void Init_P_Lk_Tips_Int(arbre *tree) -{ - int curr_site,i; - - - Fors(curr_site,tree->data->crunch_len,tree->mod->stepsize) - { - For(i,tree->n_otu) - { - if(tree->mod->datatype == NT) - { - if(tree->noeud[i]->b[0]->rght->tax != 1) - { - printf("\n. tree->noeud[i]->b[0]->rght->num = %d ; %f %f %f %f\n", - tree->noeud[i]->b[0]->rght->num, - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][0], - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][1], - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][2], - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][3]); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Exit(""); - } - - Init_Tips_At_One_Site_Nucleotides_Int(tree->data->c_seq[i]->state[curr_site], - tree->noeud[i]->b[0]->p_lk_tip_r[curr_site]); - } - else - { - Init_Tips_At_One_Site_AA_Int(tree->data->c_seq[i]->state[curr_site], - tree->noeud[i]->b[0]->p_lk_tip_r[curr_site]); - } - } - } - - #ifndef PHYML - if(tree->mod->m4mod) M4_Init_P_Lk_Tips_Int(tree); - #endif + + if(ambiguity_check == NO)/* tip case */ + { + sum = .0; + Pij += state*ns; + for(l=0;l .0) /* Only bother ascending into the subtrees if the likelihood of state k, at site "site*dim2" is > 0 */ + { + sum = .0; + for(l=0;lmod->ras->invar == YES) + { + /* The site is invariant */ + if(tree->data->invar[site] > -0.5) + { + inv_site_lk = tree->mod->e_frq->pi->v[tree->data->invar[site]]; + + /* printf("\n. inv_site_lk = %f [%c] [%d] invar: %d",inv_site_lk,tree->data->c_seq[0]->state[site],tree->data->invar[site],tree->data->invar[site]); */ + + if(tree->apply_lk_scaling == YES) + { + exponent = fact_sum_scale; + do + { + piecewise_exponent = MIN(exponent,63); + multiplier = (phydbl)((unsigned long long)(1) << piecewise_exponent); + inv_site_lk *= multiplier; + exponent -= piecewise_exponent; + } + while(exponent != 0); + } + + /* Update the value of site_lk */ + if(isinf(inv_site_lk)) // P(D|r=0) >> P(D|r>0) => assume P(D) = P(D|r=0)P(r=0) + { + int i; + PhyML_Fprintf(stderr,"\n. fact_sum_scale: %d",fact_sum_scale); + PhyML_Fprintf(stderr,"\n. pi: %f",tree->mod->e_frq->pi->v[tree->data->invar[site]]); + for(i=0;imod->ns;i++) PhyML_Fprintf(stderr,"\n. pi %d: %f",i,tree->mod->e_frq->pi->v[i]); + PhyML_Fprintf(stderr,"\n. Numerical precision issue alert."); + PhyML_Fprintf(stderr,"\n. File %s at line %d (function '%s')\n",__FILE__,__LINE__,__FUNCTION__); + (*num_prec_issue) = YES; + } + } + } + + return inv_site_lk; + +} - if(!a->tax) Exit("\n. Node 'a' must be a tip (err. in Init_P_Lk_At_One_Node)\n"); - if(a->b[0]->rght != a) Exit("\n. Node 'a' must be on the right handside of the terminal branch (err. in Init_P_Lk_At_One_Node)\n"); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - Fors(curr_site,tree->data->crunch_len,tree->mod->stepsize) +/* Update partial likelihood on edge b on the side of b where + node d lies. +*/ + +void Update_Partial_Lk(t_tree *tree, t_edge *b, t_node *d) +{ + /* if(tree->eval_alnL == NO) return; */ + if(b->left == d && b->update_partial_lk_left == NO) return; + if(b->rght == d && b->update_partial_lk_rght == NO) return; + + if(tree->is_mixt_tree) { - if(tree->mod->datatype == NT) - Init_Tips_At_One_Site_Nucleotides_Float(tree->data->c_seq[a->num]->state[curr_site], - tree->noeud[a->num]->b[0]->p_lk_rght[curr_site][0]); + MIXT_Update_Partial_Lk(tree,b,d); + return; + } + + if((tree->io->do_alias_subpatt == YES) && + (tree->update_alias_subpatt == YES)) + Alias_One_Subpatt((d==b->left)?(b->rght):(b->left),d,tree); + + if(d->tax) return; + + +#ifdef BEAGLE + update_beagle_partials(tree, b, d); +#else + if(tree->mod->use_m4mod == NO) + { + if(tree->mod->ns == 4 || tree->mod->ns == 20) + { +#if (defined(__AVX__) || defined(__AVX2__)) + AVX_Update_Partial_Lk(tree,b,d); +#elif (defined(__SSE3__)) + SSE_Update_Partial_Lk(tree,b,d); +#else + Default_Update_Partial_Lk(tree,b,d); +#endif + } else - Init_Tips_At_One_Site_AA_Float(tree->data->c_seq[a->num]->state[curr_site], - tree->noeud[a->num]->b[0]->p_lk_rght[curr_site][0]); - - for(j=1;jmod->n_catg;j++) - { - For(k,tree->mod->ns) - { - a->b[0]->p_lk_rght[curr_site][j][k]= - a->b[0]->p_lk_rght[curr_site][0][k]; - } - } + { + Update_Partial_Lk_Generic(tree,b,d); + } + } + else + { + Update_Partial_Lk_Generic(tree,b,d); } +#endif + + + // Print_Edge_Likelihoods(tree, b, false); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#ifndef BEAGLE -void Update_PMat_At_Given_Edge(edge *b_fcus, arbre *tree) +void Update_Partial_Lk_Generic(t_tree *tree, t_edge *b, t_node *d) { - int i; - phydbl len; +/* + | + |<- b + | + d + / \ + / \ + / \ + n_v1 n_v2 +*/ + t_node *n_v1, *n_v2; + phydbl p1_lk1,p2_lk2; + phydbl *p_lk,*p_lk_v1,*p_lk_v2; + phydbl *Pij1,*Pij2; + phydbl *tPij1,*tPij2; + int *sum_scale, *sum_scale_v1, *sum_scale_v2; + int sum_scale_v1_val, sum_scale_v2_val; + int i,j; + int catg,site; + int n_patterns; + short int ambiguity_check_v1,ambiguity_check_v2; + int state_v1,state_v2; + phydbl smallest_p_lk,largest_p_lk; + int *p_lk_loc; - len = -1.0; + unsigned const int ncatg = tree->mod->ras->n_catg; + unsigned const int ns = tree->mod->ns; + unsigned const int ncatgns = ncatg * ns; + unsigned const int nsns = ns * ns; + + + + if(tree->n_root && tree->ignore_root == YES && + (d == tree->n_root->v[1] || d == tree->n_root->v[2]) && + (b == tree->n_root->b[1] || b == tree->n_root->b[2])) + { + assert(FALSE); + } + + + state_v1 = state_v2 = -1; + ambiguity_check_v1 = ambiguity_check_v2 = NO; + sum_scale_v1_val = sum_scale_v2_val = 0; + p1_lk1 = p2_lk2 = .0; - if(b_fcus->l < BL_MIN) b_fcus->l = BL_MIN; - else if(b_fcus->l > BL_MAX) b_fcus->l = BL_MAX; + if(d->tax) + { + PhyML_Fprintf(stderr,"\n. t_node %d is a leaf...",d->num); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s').\n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } - For(i,tree->mod->n_catg) + n_patterns = tree->n_pattern; + + n_v1 = n_v2 = NULL; + p_lk = p_lk_v1 = p_lk_v2 = NULL; + Pij1 = Pij2 = NULL; + tPij1 = tPij2 = NULL; + sum_scale_v1 = sum_scale_v2 = NULL; + p_lk_loc = NULL; + smallest_p_lk = BIG; + + Set_All_Partial_Lk(&n_v1,&n_v2, + &p_lk,&sum_scale,&p_lk_loc, + &Pij1,&tPij1,&p_lk_v1,&sum_scale_v1, + &Pij2,&tPij2,&p_lk_v2,&sum_scale_v2, + d,b,tree); + + /* For every site in the alignment */ + for(site=0;sitehas_zero_br_len) len = -1.0; + if(tree->data->wght[site] > SMALL) + { + state_v1 = state_v2 = -1; + ambiguity_check_v1 = ambiguity_check_v2 = NO; + + if(tree->mod->s_opt->greedy == NO) + { + /* n_v1 and n_v2 are tip nodes */ + if(n_v1 && n_v1->tax) + { + /* Is the state at this tip ambiguous? */ + ambiguity_check_v1 = n_v1->c_seq->is_ambigu[site]; + /* if(ambiguity_check_v1 == NO) state_v1 = Get_State_From_Partial_Pars(n_v1->b[0]->p_lk_tip_r,site*ns,tree); */ + if(ambiguity_check_v1 == NO) state_v1 = n_v1->c_seq->d_state[site]; + } + + if(n_v2 && n_v2->tax) + { + /* Is the state at this tip ambiguous? */ + ambiguity_check_v2 = n_v2->c_seq->is_ambigu[site]; + /* ambiguity_check_v2 = tree->data->c_seq[n_v2->num]->is_ambigu[site]; */ + /* if(ambiguity_check_v2 == NO) state_v2 = Get_State_From_Partial_Pars(n_v2->b[0]->p_lk_tip_r,site*ns,tree); */ + if(ambiguity_check_v2 == NO) state_v2 = n_v2->c_seq->d_state[site]; + } + } + + if(tree->mod->use_m4mod) + { + ambiguity_check_v1 = YES; + ambiguity_check_v2 = YES; + } + + /* For all the rate classes */ + for(catg=0;catgmod->ras->skip_rate_cat[catg] == YES) continue; + + smallest_p_lk = BIG; + + /* For all the states at node d */ + for(i=0;imod->ns;i++) + { + p1_lk1 = .0; + + if(n_v1) + { + /* n_v1 is a tip */ + if((n_v1->tax) && (!tree->mod->s_opt->greedy)) + { + if(ambiguity_check_v1 == NO) + { + /* For the (non-ambiguous) state at node n_v1 */ + p1_lk1 = Pij1[catg*nsns+i*ns+state_v1]; + } + else + { + /* For all the states at node n_v1 */ + for(j=0;jmod->ns;j++) + { + p1_lk1 += Pij1[catg*nsns+i*ns+j] * (phydbl)n_v1->b[0]->p_lk_tip_r[site*ns+j]; + } + } + } + /* n_v1 is an internal node */ + else + { + /* For the states at node n_v1 */ + for(j=0;jmod->ns;j++) + { + p1_lk1 += Pij1[catg*nsns+i*ns+j] * p_lk_v1[site*ncatgns+catg*ns+j]; + } + } + } + else + { + p1_lk1 = 1.0; + } + + p2_lk2 = .0; + + /* We do exactly the same as for node n_v1 but for node n_v2 this time.*/ + if(n_v2) + { + /* n_v2 is a tip */ + if((n_v2->tax) && (!tree->mod->s_opt->greedy)) + { + if(ambiguity_check_v2 == NO) + { + /* For the (non-ambiguous) state at node n_v2 */ + p2_lk2 = Pij2[catg*nsns+i*ns+state_v2]; + } + else + { + /* For all the states at node n_v2 */ + for(j=0;jmod->ns;j++) + { + p2_lk2 += Pij2[catg*nsns+i*ns+j] * (phydbl)n_v2->b[0]->p_lk_tip_r[site*ns+j]; + } + } + } + /* n_v2 is an internal node */ + else + { + /* For all the states at node n_v2 */ + for(j=0;jmod->ns;j++) + { + p2_lk2 += Pij2[catg*nsns+i*ns+j] * p_lk_v2[site*ncatgns+catg*ns+j]; + } + } + } + else + { + p2_lk2 = 1.0; + } + + p_lk[site*ncatgns+catg*ns+i] = p1_lk1 * p2_lk2; + + /* if(site == 0) PhyML_Printf("\n+ site: %d %G",site,p_lk[site*ncatgns+catg*ns+i]); */ + + } + + if(tree->scaling_method == SCALE_RATE_SPECIFIC) + { + smallest_p_lk = BIG; + for(i=0;imod->augmented == NO && + tree->apply_lk_scaling == YES && + (n_v1->tax == NO || n_v2->tax == NO)) + + { + int curr_scaler_pow; + curr_scaler_pow = (int)(-500.*LOG2-log(smallest_p_lk))/LOG2; + sum_scale[site*ncatg+catg] += curr_scaler_pow; + for(i=0;iscaling_method == SCALE_FAST) + { + sum_scale_v1_val = (sum_scale_v1)?(sum_scale_v1[site]):(0); + sum_scale_v2_val = (sum_scale_v2)?(sum_scale_v2[site]):(0); + sum_scale[site] = sum_scale_v1_val + sum_scale_v2_val; + + sum_scale[site*ncatg+catg] = sum_scale_v1_val + sum_scale_v2_val; + + assert(sum_scale[site] < 1024); + + largest_p_lk = -BIG; + for(i=0;i largest_p_lk) + largest_p_lk = p_lk[site*ncatgns+i] ; + + if(largest_p_lk < INV_TWO_TO_THE_LARGE && + tree->mod->augmented == NO && + tree->apply_lk_scaling == YES) + { + for(i=0;il*tree->mod->gamma_rr[i]; - if(len < BL_MIN) len = BL_MIN; - else if(len > BL_MAX) len = BL_MAX; - } - PMat(len,tree->mod,&b_fcus->Pij_rr[i]); + { + for(i=0;imod->ras->n_catg; + const unsigned int ns = tree->mod->ns; + const unsigned int n_patterns = tree->n_pattern; -/* /\* */ -/* \ / */ -/* target\___________b_/ */ -/* / \ \ \ \ */ -/* / \ \ \ \ */ + if(tree->n_root && tree->ignore_root == YES && + (d == tree->n_root->v[1] || d == tree->n_root->v[2]) && + (b == tree->n_root->b[1] || b == tree->n_root->b[2])) + { + assert(FALSE); + } + + if(d->tax) + { + PhyML_Fprintf(stderr,"\n. t_node %d is a leaf...",d->num); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s')\n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } -/* target is the root of the subtree at which we want */ -/* the likelihood to be updated */ -/* *\/ */ + n_v1 = n_v2 = NULL; + p_lk = p_lk_v1 = p_lk_v2 = NULL; + Pij1 = Pij2 = NULL; + tPij1 = tPij2 = NULL; + p_lk_loc = NULL; + sum_scale_v1 = NULL; + sum_scale_v2 = NULL; + + Set_All_Partial_Lk(&n_v1,&n_v2, + &p_lk,&sum_scale,&p_lk_loc, + &Pij1,&tPij1,&p_lk_v1,&sum_scale_v1, + &Pij2,&tPij2,&p_lk_v2,&sum_scale_v2, + d,b,tree); + + Core_Default_Update_Partial_Lk(n_v1,n_v2, + p_lk,p_lk_v1,p_lk_v2, + Pij1,Pij2, + sum_scale,sum_scale_v1,sum_scale_v2, + ns,ncatg,n_patterns, + tree->apply_lk_scaling, + tree->data->wght); +} -/* /\* printf("Update_p_lk on (%d %d) at %d (target=%d %d)\n", *\/ */ -/* /\* b->left->num, *\/ */ -/* /\* b->rght->num, *\/ */ -/* /\* a->num, *\/ */ -/* /\* target_one_side->num, *\/ */ -/* /\* target_other_side->num); *\/ */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/* Update_P_Lk(tree,b,a); */ -/* if((a == target_one_side) && (d == target_other_side)) */ -/* return; */ -/* else */ -/* { */ -/* Update_P_Lk_On_A_Path(d, */ -/* d->v[tree->t_dir[d->num][target_other_side->num]], */ -/* d->b[tree->t_dir[d->num][target_other_side->num]], */ -/* target_one_side, */ -/* target_other_side, */ -/* tree); */ -/* } */ -/* } */ +void Core_Default_Update_Partial_Lk(const t_node *n_v1, const t_node *n_v2, + phydbl *plk0, const phydbl *plk1, const phydbl *plk2, + const phydbl *Pij1, const phydbl *Pij2, + int *sum_scale0, const int *sum_scale1, const int *sum_scale2, + const int ns, const int ncatg, const int npatterns, const int apply_scaling, + const phydbl *wght) +{ + + unsigned int i,site,ncatgns,catg,nsns; + int state_v1,state_v2; + int ambiguity_check_v1,ambiguity_check_v2; + int sum_scale_v1_val, sum_scale_v2_val; + phydbl largest_p_lk; + const phydbl *init_Pij1, *init_Pij2; + + ncatgns = ncatg*ns; + nsns = ns*ns; + init_Pij1 = Pij1; + init_Pij2 = Pij2; + + /* For every site in the alignment */ + for(site=0;site SMALL) + { + state_v1 = state_v2 = -1; + ambiguity_check_v1 = ambiguity_check_v2 = YES; + + /* n_v1 and n_v2 are tip nodes */ + if(n_v1->tax) + { + /* Is the state at this tip ambiguous? */ + ambiguity_check_v1 = n_v1->c_seq->is_ambigu[site]; + if(ambiguity_check_v1 == NO) state_v1 = n_v1->c_seq->d_state[site]; + } + + if(n_v2->tax) + { + /* Is the state at this tip ambiguous? */ + ambiguity_check_v2 = n_v2->c_seq->is_ambigu[site]; + if(ambiguity_check_v2 == NO) state_v2 = n_v2->c_seq->d_state[site]; + } + + Pij1 = init_Pij1; + Pij2 = init_Pij2; + + /* For all the rate classes */ + for(catg=0;catgtax) ? 0 : ns; + plk2 += (n_v2->tax) ? 0 : ns; + plk0 += ns; + } + + plk1 += (n_v1->tax) ? ns : 0; + plk2 += (n_v2->tax) ? ns : 0; + + sum_scale_v1_val = (sum_scale1)?(sum_scale1[site]):(0); + sum_scale_v2_val = (sum_scale2)?(sum_scale2[site]):(0); + sum_scale0[site] = sum_scale_v1_val + sum_scale_v2_val; + + plk0 -= ncatgns; + largest_p_lk = -BIG; + for(i=0;i largest_p_lk) + largest_p_lk = plk0[i]; + + if(largest_p_lk < INV_TWO_TO_THE_LARGE && apply_scaling == YES) + { + for(i=0;itax) ? ns : ncatgns; + plk2 += (n_v2->tax) ? ns : ncatgns; + } + } +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Update_P_Lk_Along_A_Path(node **path, int path_length, arbre *tree) +phydbl Return_Abs_Lk(t_tree *tree) { - int i,j; + Lk(NULL,tree); + return FABS(tree->c_lnL); +} - For(i,path_length-1) - { - For(j,3) - if(path[i]->v[j] == path[i+1]) - { - if(path[i] == path[i]->b[j]->left) - { - if(!path[i]->b[j]->is_p_lk_l_u2d) - { - Update_P_Lk(tree,path[i]->b[j],path[i]->b[j]->left); - } - path[i]->b[j]->is_p_lk_l_u2d = 1; - } - - else if(path[i] == path[i]->b[j]->rght) - { - if(!path[i]->b[j]->is_p_lk_r_u2d) - { - Update_P_Lk(tree,path[i]->b[j],path[i]->b[j]->rght); - } - path[i]->b[j]->is_p_lk_r_u2d = 1; - } - break; - } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -#ifdef DEBUG - if(j == 3) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Exit(""); - } -#endif +matrix *ML_Dist(calign *data, t_mod *mod) +{ + int i,j,k,l; + phydbl init; + int n_catg; + phydbl d_max,sum; + matrix *mat; + calign *twodata,*tmpdata; + int state0, state1; + phydbl *F,len; + eigen *eigen_struct; + + tmpdata = (calign *)mCalloc(1,sizeof(calign)); + tmpdata->c_seq = (align **)mCalloc(2,sizeof(align *)); + tmpdata->obs_state_frq = (phydbl *)mCalloc(mod->ns,sizeof(phydbl)); + tmpdata->ambigu = (short int *)mCalloc(data->crunch_len,sizeof(short int)); + F = (phydbl *)mCalloc(mod->ns*mod->ns,sizeof(phydbl )); + eigen_struct = (eigen *)Make_Eigen_Struct(mod->ns); + + Set_Update_Eigen(YES,mod); + Update_Boundaries(mod); + Update_Eigen(mod); + + tmpdata->n_otu = 2; + + tmpdata->crunch_len = data->crunch_len; + tmpdata->init_len = data->init_len; + + mat = NULL; + if(mod->io->datatype == NT) mat = (mod->whichmodel < 10)?(K80_dist(data,1E+6)):(JC69_Dist(data,mod)); + else if(mod->io->datatype == AA) mat = JC69_Dist(data,mod); + else if(mod->io->datatype == GENERIC) mat = JC69_Dist(data,mod); + + + for(i=0;iras->n_catg;i++) /* Don't use the discrete gamma distribution */ + { + mod->ras->gamma_rr->v[i] = 1.0; + mod->ras->gamma_r_proba->v[i] = 1.0; + } + + n_catg = mod->ras->n_catg; + mod->ras->n_catg = 1; + + for(j=0;jn_otu-1;j++) + { + tmpdata->c_seq[0] = data->c_seq[j]; + tmpdata->c_seq[0]->name = data->c_seq[j]->name; + tmpdata->wght = data->wght; + for(k=j+1;kn_otu;k++) + { + tmpdata->c_seq[1] = data->c_seq[k]; + tmpdata->c_seq[1]->name = data->c_seq[k]->name; + + twodata = Compact_Cdata(tmpdata,mod->io); + + Check_Ambiguities(twodata,mod->io->datatype,mod->io->state_len); + + Hide_Ambiguities(twodata); + + init = mat->dist[j][k]; + + if((init > DIST_MAX-SMALL) || (init < .0)) init = 0.1; + + d_max = init; + + for(i=0;ins*mod->ns;++i) F[i]=.0; + len = 0.0; + for(l=0;lc_seq[0]->len;++l) + { + state0 = Assign_State(twodata->c_seq[0]->state+l*mod->io->state_len,mod->io->datatype,mod->io->state_len); + state1 = Assign_State(twodata->c_seq[1]->state+l*mod->io->state_len,mod->io->datatype,mod->io->state_len); + + if((state0 > -1) && (state1 > -1)) + { + F[mod->ns*state0+state1] += twodata->wght[l]; + len += twodata->wght[l]; + } + } + + if(len > .0) + { + for(i=0;ins*mod->ns;++i) F[i] /= len; + } + + sum = 0.; + for(i=0;ins*mod->ns;++i) sum += F[i]; + + /* for(i=0;ins*mod->ns;++i) PhyML_Printf("\n. %g",F[i]); */ + + /* if(sum < .001) d_max = -1.; */ + if(sum < .001) d_max = init; + else if((sum > 1. - .001) && (sum < 1. + .001)) Opt_Dist_F(&(d_max),F,mod); + else + { + PhyML_Fprintf(stderr,"\n\n. sum = %f",sum); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit(""); + } + + if(d_max >= DIST_MAX) d_max = DIST_MAX; + + + /* Do not correct for dist < BL_MIN, otherwise Fill_Missing_Dist + * will not be called + */ + mat->dist[j][k] = d_max; + mat->dist[k][j] = mat->dist[j][k]; + Free_Calign(twodata); + } } + + mod->ras->n_catg = n_catg; + + + Free(tmpdata->ambigu); + Free(tmpdata->obs_state_frq); + Free(tmpdata->c_seq); + free(tmpdata); + Free_Eigen(eigen_struct); + Free(F); + + return mat; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Sort_Sites_Based_On_Lk(arbre *tree) +phydbl Lk_Given_Two_Seq(calign *data, int numseq1, int numseq2, phydbl dist, t_mod *mod, phydbl *loglk) { - int i,j,k,l,m; - phydbl buff_dbl; - char buff_char; - int buff_int; - - For(i,tree->data->crunch_len) - { - for(j=i+1;jdata->crunch_len;j++) - { - if(tree->site_lk[j]*tree->data->wght[j] < tree->site_lk[i]*tree->data->wght[i]) - { - buff_dbl = tree->site_lk[j]; - tree->site_lk[j] = tree->site_lk[i]; - tree->site_lk[i] = buff_dbl; - - buff_dbl = tree->data->wght[j]; - tree->data->wght[j] = tree->data->wght[i]; - tree->data->wght[i] = buff_dbl; - - buff_int = tree->data->invar[j]; - tree->data->invar[j] = tree->data->invar[i]; - tree->data->invar[i] = buff_int; - - buff_int = tree->data->ambigu[j]; - tree->data->ambigu[j] = tree->data->ambigu[i]; - tree->data->ambigu[i] = buff_int; - - if(tree->data->c_seq[0]->state) - { - For(k,tree->n_otu) - { - buff_char = tree->data->c_seq[k]->state[j]; - tree->data->c_seq[k]->state[j] = tree->data->c_seq[k]->state[i]; - tree->data->c_seq[k]->state[i] = buff_char; - } - } - - For(k,2*tree->n_otu-3) - { - For(l,tree->mod->n_catg) - { - For(m,tree->mod->ns) - { - buff_dbl = tree->t_edges[k]->p_lk_rght[j][l][m]; - tree->t_edges[k]->p_lk_rght[j][l][m] = tree->t_edges[k]->p_lk_rght[i][l][m]; - tree->t_edges[k]->p_lk_rght[i][l][m] = buff_dbl; - - buff_dbl = tree->t_edges[k]->p_lk_left[j][l][m]; - tree->t_edges[k]->p_lk_left[j][l][m] = tree->t_edges[k]->p_lk_left[i][l][m]; - tree->t_edges[k]->p_lk_left[i][l][m] = buff_dbl; - } - } - - buff_dbl = tree->t_edges[k]->sum_scale_f_rght[j]; - tree->t_edges[k]->sum_scale_f_rght[j] = tree->t_edges[k]->sum_scale_f_rght[i]; - tree->t_edges[k]->sum_scale_f_rght[i] = buff_dbl; - - buff_dbl = tree->t_edges[k]->sum_scale_f_left[j]; - tree->t_edges[k]->sum_scale_f_left[j] = tree->t_edges[k]->sum_scale_f_left[i]; - tree->t_edges[k]->sum_scale_f_left[i] = buff_dbl; - } - } - } + align *seq1,*seq2; + phydbl site_lk,log_site_lk; + int i,j,k,l; +/* phydbl **p_lk_l,**p_lk_r; */ + phydbl *p_lk_l,*p_lk_r; + phydbl len; + int dim1,dim2; + + dim1 = mod->ns; + dim2 = mod->ns * mod->ns; + + DiscreteGamma(mod->ras->gamma_r_proba->v, mod->ras->gamma_rr->v, mod->ras->alpha->v, + mod->ras->alpha->v,mod->ras->n_catg,mod->ras->gamma_median); + + seq1 = data->c_seq[numseq1]; + seq2 = data->c_seq[numseq2]; + + + p_lk_l = (phydbl *)mCalloc(data->c_seq[0]->len * mod->ns,sizeof(phydbl)); + p_lk_r = (phydbl *)mCalloc(data->c_seq[0]->len * mod->ns,sizeof(phydbl)); + + + for(i=0;iras->n_catg;i++) + { + len = dist*mod->ras->gamma_rr->v[i]; + if(len < mod->l_min) len = mod->l_min; + else if(len > mod->l_max) len = mod->l_max; + PMat(len,mod,dim2*i,mod->Pij_rr->v,NULL); + } + + if(mod->io->datatype == NT) + { + For(i,data->c_seq[0]->len) + { + Init_Tips_At_One_Site_Nucleotides_Float(seq1->state[i],i*mod->ns,p_lk_l); + Init_Tips_At_One_Site_Nucleotides_Float(seq2->state[i],i*mod->ns,p_lk_r); + } } + else if(mod->io->datatype == AA) + { + For(i,data->c_seq[0]->len) + { + Init_Tips_At_One_Site_AA_Float(seq1->state[i],i*mod->ns,p_lk_l); + Init_Tips_At_One_Site_AA_Float(seq2->state[i],i*mod->ns,p_lk_r); + } + } + else + { + PhyML_Fprintf(stderr,"\n\n. Not implemented yet..."); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit("\n"); + } + + + site_lk = .0; + *loglk = 0; + + For(i,data->c_seq[0]->len) + { + if(data->wght[i] > 0.0) + { + site_lk = log_site_lk = .0; + if(!data->ambigu[i]) + { + for(k=0;kns;k++) {if(p_lk_l[i*mod->ns+k] > .0001) break;} + for(l=0;lns;l++) {if(p_lk_r[i*mod->ns+l] > .0001) break;} + for(j=0;jras->n_catg;j++) + { + site_lk += + mod->ras->gamma_r_proba->v[j] * + mod->e_frq->pi->v[k] * + p_lk_l[i*dim1+k] * + mod->Pij_rr->v[j*dim2+k*dim1+l] * + p_lk_r[i*dim1+l]; + } + } + else + { + for(j=0;jras->n_catg;j++) + { + for(k=0;kns;k++) /*sort sum terms ? No global effect*/ + { + for(l=0;lns;l++) + { + site_lk += + mod->ras->gamma_r_proba->v[j] * + mod->e_frq->pi->v[k] * + p_lk_l[i*dim1+k] * + mod->Pij_rr->v[j*dim2+k*dim1+l] * + p_lk_r[i*dim1+l]; + } + } + } + } + + if(site_lk <= .0) + { + PhyML_Fprintf(stderr,"\n\n. '%c' '%c'\n",seq1->state[i],seq2->state[i]); + Exit("\n. Err: site lk <= 0\n"); + } + + log_site_lk += (phydbl)log(site_lk); + + *loglk += data->wght[i] * log_site_lk;/* sort sum terms ? No global effect*/ + } + } + +/* For(i,data->c_seq[0]->len) */ +/* { */ +/* Free(p_lk_l[i]); */ +/* Free(p_lk_r[i]); */ +/* } */ + + Free(p_lk_l); Free(p_lk_r); + return *loglk; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Multinomial log likelihood +void Unconstraint_Lk(t_tree *tree) +{ + int i; + + tree->unconstraint_lk = .0; + for(i=0;idata->crunch_len;i++) tree->unconstraint_lk += tree->data->wght[i]*(phydbl)log(tree->data->wght[i]); + tree->unconstraint_lk -= tree->data->init_len*(phydbl)log(tree->data->init_len); +} -phydbl Lk_Dist(phydbl *F, phydbl dist, model *mod) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Log-likelihood assuming a tree with edge of infinite lengths +void Composite_Lk(t_tree *tree) { - int i,j,k; - phydbl len,lnL,tmp; + int i; + tree->composite_lk = 0.0; + for(i=0;imod->ns;++i) + tree->composite_lk += + tree->data->obs_state_frq[i]* + tree->data->init_len* + tree->n_otu* + log(tree->mod->e_frq->pi->v[i]); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - len = -1.; - For(k,mod->n_catg) +void Init_Partial_Lk_Tips_Double(t_tree *tree) +{ + unsigned int curr_site,i,dim1; + + if(tree->is_mixt_tree == YES) return; + + dim1 = tree->mod->ns; + + + for(i=0;in_otu;i++) { - len = dist*mod->gamma_rr[k]; - if(len < BL_MIN) len = BL_MIN; - else if(len > BL_MAX) len = BL_MAX; - PMat(len,mod,&(mod->Pij_rr[k])); + if(!tree->a_nodes[i]->c_seq || + strcmp(tree->a_nodes[i]->c_seq->name,tree->a_nodes[i]->name)) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit(""); + } } - lnL = .0; - For(i,mod->ns) + for(curr_site=0;curr_sitedata->crunch_len;curr_site++) { - For(j,mod->ns) - { - tmp = .0; - For(k,mod->n_catg) - { - tmp += - mod->gamma_r_proba[k] * - mod->pi[i] * - (phydbl)(mod->Pij_rr[k][i][j]); - } - lnL += F[mod->ns*i+j] * (phydbl)log(tmp); - } + for(i=0;in_otu;i++) + { + if (tree->io->datatype == NT) + Init_Tips_At_One_Site_Nucleotides_Float(tree->a_nodes[i]->c_seq->state[curr_site], + curr_site*dim1, + tree->a_nodes[i]->b[0]->p_lk_tip_r); + else if(tree->io->datatype == AA) + Init_Tips_At_One_Site_AA_Float(tree->a_nodes[i]->c_seq->state[curr_site], + curr_site*dim1, + tree->a_nodes[i]->b[0]->p_lk_tip_r); + + else if(tree->io->datatype == GENERIC) + Init_Tips_At_One_Site_Generic_Float(tree->a_nodes[i]->c_seq->state+curr_site*tree->mod->io->state_len, + tree->mod->ns, + tree->mod->io->state_len, + curr_site*dim1, + tree->a_nodes[i]->b[0]->p_lk_tip_r); + } } - return lnL; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Update_Lk_At_Given_Edge(edge *b_fcus, arbre *tree) +void Init_Partial_Lk_Tips_Int(t_tree *tree) { - if(!b_fcus->left->tax) Update_P_Lk(tree,b_fcus,b_fcus->left); - if(!b_fcus->rght->tax) Update_P_Lk(tree,b_fcus,b_fcus->rght); - tree->c_lnL = Lk_At_Given_Edge(b_fcus,tree); - return tree->c_lnL; + int curr_site,i,dim1; + + if(tree->is_mixt_tree == YES) return; + + dim1 = tree->mod->ns; + + for(i=0;in_otu;i++) + { + if(!tree->a_nodes[i]->c_seq || + strcmp(tree->a_nodes[i]->c_seq->name,tree->a_nodes[i]->name)) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit(""); + } + } + + for(curr_site=0;curr_sitedata->crunch_len;curr_site++) + { + for(i=0;in_otu;i++) + { + /* printf("\n. site: %3d %c",curr_site,tree->a_nodes[i]->c_seq->state[curr_site]); */ + /* printf("\n. init at %s %p",tree->a_nodes[i]->name,tree->a_nodes[i]->b[0]->p_lk_tip_r); fflush(NULL); */ + if(tree->io->datatype == NT) + { + Init_Tips_At_One_Site_Nucleotides_Float(tree->a_nodes[i]->c_seq->state[curr_site], + curr_site*dim1, + tree->a_nodes[i]->b[0]->p_lk_tip_r); + /* Init_Tips_At_One_Site_Nucleotides_Int(tree->data->c_seq[i]->state[curr_site], */ + /* curr_site*dim1, */ + /* tree->a_nodes[i]->b[0]->p_lk_tip_r); */ + } + else if(tree->io->datatype == AA) + Init_Tips_At_One_Site_AA_Float(tree->a_nodes[i]->c_seq->state[curr_site], + curr_site*dim1, + tree->a_nodes[i]->b[0]->p_lk_tip_r); + /* Init_Tips_At_One_Site_AA_Int(tree->data->c_seq[i]->state[curr_site], */ + /* curr_site*dim1, */ + /* tree->a_nodes[i]->b[0]->p_lk_tip_r); */ + + else if(tree->io->datatype == GENERIC) + { + Init_Tips_At_One_Site_Generic_Float(tree->a_nodes[i]->c_seq->state+curr_site*tree->mod->io->state_len, + tree->mod->ns, + tree->mod->io->state_len, + curr_site*dim1, + tree->a_nodes[i]->b[0]->p_lk_tip_r); + + /* Init_Tips_At_One_Site_Generic_Int(tree->data->c_seq[i]->state+curr_site*tree->mod->io->state_len, */ + /* tree->mod->ns, */ + /* tree->mod->io->state_len, */ + /* curr_site*dim1, */ + /* tree->a_nodes[i]->b[0]->p_lk_tip_r); */ + } +#ifdef BEAGLE + //Recall that tip partials are stored on the branch leading + //to the tip, rather than on the tip itself (hence `p_lk_tip_idx` + //is a field of the branch (i.e. b[0]) rather than the node. + //Secondly, the BEAGLE's partial buffers are laid out as + //BEAGLE's partials buffer = [ tax1, tax2, ..., taxN, b1Left, b2Left, b3Left,...,bMLeft, b1Rght, b2Rght, b3Rght,...,bMRght] (N taxa, M branches) + tree->a_nodes[i]->b[0]->p_lk_tip_idx = i; +#endif + } + } } -/*********************************************************/ - -/* root - \ - / - a - | - | - d - / \ - / \ - w x - - d->t has changed and we need to compute - the likelihood. - (1) update the three branch lengths l(ad), l(dw) and l(dx) - (2) update the change proba matrices along these branches - (3) update the likelihood of subtree (w,x) (WARNING: (a,x) and (a,w) are not updated) -*/ -phydbl Lk_Triplet(node *a, node *d, arbre *tree) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Update_PMat_At_Given_Edge(t_edge *b_fcus, t_tree *tree) { int i; - phydbl max_height; - phydbl up_bound, low_bound; + phydbl len; + phydbl l_min, l_max; + phydbl shape, scale, mean, var; - if(d->tax) + assert(b_fcus); + assert(tree); + + if(tree->is_mixt_tree == YES) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + MIXT_Update_PMat_At_Given_Edge(b_fcus,tree); + return; } - up_bound = low_bound = -1.0; - max_height = -1.0; - For(i,3) + if(tree->mixt_tree != NULL) assert(tree->mod->ras->n_catg == 1); + + if(tree->io->mod->gamma_mgf_bl == YES) Set_Br_Len_Var(b_fcus,tree); + + l_min = tree->mod->l_min; + l_max = tree->mod->l_max; + + + len = -1.0; + + if(tree->mod->log_l == YES) b_fcus->l->v = exp(b_fcus->l->v); + + /* if(b_fcus->l->v < l_min) b_fcus->l->v = l_min; */ + /* if(b_fcus->l->v > l_max) b_fcus->l->v = l_max; */ + + for(i=0;imod->ras->n_catg;i++) { - if((d->v[i] != a) && (d->b[i] != tree->e_root)) - { - if(d->v[i]->t > max_height) - { - max_height = d->v[i]->t; - } - } + if(tree->mod->ras->skip_rate_cat[i] == YES) continue; + + //Update the branch length + if(b_fcus->has_zero_br_len == YES) + { +#ifdef BEAGLE + Warn_And_Exit(TODO_BEAGLE); +#endif + len = -1.0; + mean = -1.0; + var = -1.0; + } else - { - up_bound = (a == tree->n_root)?(a->t):(d->v[i]->t); - } + { + len = MAX(0.0,b_fcus->l->v)*tree->mod->ras->gamma_rr->v[i];//branch_len * rate + len *= tree->mod->br_len_mult->v; + if(tree->mixt_tree) len *= tree->mixt_tree->mod->ras->gamma_rr->v[tree->mod->ras->parent_class_number]; + if(len < l_min) len = l_min; + else if(len > l_max) len = l_max; + + mean = len; + var = MAX(0.0,b_fcus->l_var->v) * POW(tree->mod->ras->gamma_rr->v[i]*tree->mod->br_len_mult->v,2); + if(tree->mixt_tree) var *= POW(tree->mixt_tree->mod->ras->gamma_rr->v[tree->mod->ras->parent_class_number],2); + + /* var = 1.E-10; */ + + if(var > tree->mod->l_var_max) var = tree->mod->l_var_max; + if(var < tree->mod->l_var_min) var = tree->mod->l_var_min; + } + + //Update the transition prob. matrix + if(tree->mod->gamma_mgf_bl == NO) + { +#ifdef BEAGLE + assert(UNINITIALIZED != tree->mod->b_inst); +#endif + + PMat(len,tree->mod,i*tree->mod->ns*tree->mod->ns,b_fcus->Pij_rr,b_fcus->tPij_rr); + } + else + { +#ifdef BEAGLE + Warn_And_Exit(TODO_BEAGLE); +#endif + + shape = mean*mean/var; + scale = var/mean; + PMat_MGF_Gamma(b_fcus->Pij_rr+tree->mod->ns*tree->mod->ns*i,shape,scale,1.0,tree->mod); + } } - low_bound = max_height; +#ifdef BEAGLE + int whichmodel = tree->mod->whichmodel; + //Only for some models we use Beagle to compute/update the P-matrices, for other models + //we compute them in PhyML and explicitly set the P-matrices in BEAGLE + if((tree->mod->io->datatype == AA || whichmodel==GTR || whichmodel==CUSTOM) && tree->mod->use_m4mod == NO) + { + if(b_fcus->has_zero_br_len == YES) + Warn_And_Exit(TODO_BEAGLE); + + // + update_beagle_eigen(tree->mod); + update_beagle_ras(tree->mod); + + // + len = MAX(0.0, b_fcus->l->v) * tree->mod->br_len_mult->v; + int p_matrices[1] = b_fcus->Pij_rr_idx; + double branch_lens[1] = len; + int ret = beagleUpdateTransitionMatrices(tree->b_inst,0,p_matrices,NULL,NULL,branch_lens,1); + if(ret<0) + { + PhyML_Fprintf(stderr, "beagleUpdateTransitionMatrices() on instance %i failed:%i\n\n",tree->b_inst,ret); + Exit(""); + } + //Retrieve a "local" copy of the P-matrix + ret = beagleGetTransitionMatrix(tree->b_inst, b_fcus->Pij_rr_idx, b_fcus->Pij_rr); + if(ret<0) + { + PhyML_Fprintf(stderr, "beagleGetTransitionMatrix() on instance %i failed:%i\n\n",tree->b_inst,ret); + Exit(""); + } + } + else + { + int ret = beagleSetTransitionMatrix(tree->b_inst, b_fcus->Pij_rr_idx, b_fcus->Pij_rr, -1); + if(ret<0) + { + PhyML_Fprintf(stderr, "beagleSetTransitionMatrix() on instance %i failed:%i\n\n",tree->b_inst,ret); + Exit(""); + } + } +#endif + if(tree->mod->log_l == YES) b_fcus->l->v = log(b_fcus->l->v); + +// Print_Model(tree->mod); +// Dump_Arr_D(tree->cur_site_lk, tree->n_pattern); +// Print_Edge_PMats(tree, b_fcus); +// Print_Edge_Likelihoods(tree,b_fcus,true); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if(up_bound < low_bound - 1.E-10) +void Update_Partial_Lk_Along_A_Path(t_node **path, int path_length, t_tree *tree) +{ + int i,j; + + for(i=0;inum=%d d->num=%d",a->num,d->num); - printf("\n. up_bound = %f, low_bound = %f",up_bound,low_bound); - Warn_And_Exit("\n"); + for(j=0;j<3;++j) + if(path[i]->v[j] == path[i+1]) + { + if(path[i] == path[i]->b[j]->left) + { + Update_Partial_Lk(tree,path[i]->b[j],path[i]->b[j]->left); + } + else if(path[i] == path[i]->b[j]->rght) + { + Update_Partial_Lk(tree,path[i]->b[j],path[i]->b[j]->rght); + } + else + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d. \n",__FILE__,__LINE__); + assert(FALSE); + } + break; + } +#ifdef DEBUG + if(j == 3) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d.\n",__FILE__,__LINE__); + assert(FALSE); + } +#endif } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Lk_Dist(phydbl *F, phydbl dist, t_mod *mod) +{ + int i,j,k; + phydbl lnL,len; + int dim1,dim2; + phydbl pi, pijk; - if(d->t < low_bound) d->t = low_bound; - else if(d->t > up_bound) d->t = up_bound; + // Compute likelihood of the model made of the + // first class of the mixture. + /* if(mod->is_mixt_mod == YES) mod = mod->next; */ + /* assert(mod); */ - /* Step (1) */ - For(i,3) + if(mod->log_l == YES) dist = exp(dist); + + for(k=0;kras->n_catg;k++) { - if((d->v[i] != a) && (d->b[i] != tree->e_root)) - { - d->b[i]->l = - (d->t - d->v[i]->t) * - tree->rates->mean_r * - tree->rates->br_r[d->b[i]->num]; - } - else - { - if(a == tree->n_root) - { - d->b[i]->l = - (tree->n_root->t - tree->n_root->v[0]->t + - tree->n_root->t - tree->n_root->v[1]->t) * tree->rates->mean_r; - } - else - { - d->b[i]->l = (a->t - d->t) * tree->rates->mean_r * tree->rates->br_r[d->b[i]->num]; - } - } - } - - /* Step (2) */ - For(i,3) Update_PMat_At_Given_Edge(d->b[i],tree); - - For(i,3) - if((d->v[i] == a) || (d->b[i] == tree->e_root)) - { - Update_P_Lk(tree,d->b[i],d); - Lk_At_Given_Edge(d->b[i],tree); - break; - } + len = dist*mod->ras->gamma_rr->v[k]; + if(len < mod->l_min) len = mod->l_min; + else if(len > mod->l_max) len = mod->l_max; + PMat(len,mod,mod->ns*mod->ns*k,mod->Pij_rr->v,NULL); + /* PhyML_Printf("\n. p: %g len: %g",mod->Pij_rr->v[0],len); */ + } + + dim1 = mod->ns*mod->ns; + dim2 = mod->ns; + lnL = .0; + pi = -1.; + pijk = -1.; + for(i=0;ins-1;i++) + { + pi = mod->e_frq->pi->v[i]; + + for(j=i+1;jns;j++) + { + for(k=0;kras->n_catg;k++) + { + pijk = mod->Pij_rr->v[dim1*k+dim2*i+j]; + lnL += (F[dim1*k+dim2*i+j] + F[dim1*k+dim2*j+i]) * log(pi * pijk); + /* PhyML_Printf("\n. pijk: %g lnL: %g",pijk,lnL); */ + } + } + } + + for(i=0;ins;i++) + { + pi = mod->e_frq->pi->v[i]; + + for(k=0;kras->n_catg;k++) + { + pijk = mod->Pij_rr->v[dim1*k+dim2*i+i]; + lnL += F[dim1*k+dim2*i+i]* log(pi * pijk); + /* PhyML_Printf("\n. pijk: %g lnL: %g",pijk,lnL); */ + } + } + + return lnL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Update_Lk_At_Given_Edge(t_edge *b_fcus, t_tree *tree) +{ + Update_Partial_Lk(tree,b_fcus,b_fcus->left); + Update_Partial_Lk(tree,b_fcus,b_fcus->rght); + tree->c_lnL = Lk(b_fcus,tree); return tree->c_lnL; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Print_Lk_Given_Edge_Recurr(node *a, node *d, edge *b, arbre *tree) +void Init_Partial_Lk_Loc(t_tree *tree) { - printf("\n___ Edge %3d (left=%3d rght=%3d) lnL=%f", - b->num, - b->left->num, - b->rght->num, - Lk_At_Given_Edge(b,tree)); + int i,j; + t_node *d; + int *patt_id_d; - if(d->tax) return; - else + if(tree->is_mixt_tree == YES) return; + + for(i=0;i<2*tree->n_otu-1;++i) { - int i; - For(i,3) - if(d->v[i] != a) - Print_Lk_Given_Edge_Recurr(d,d->v[i],d->b[i],tree); + for(j=0;jn_pattern;j++) + { + tree->a_edges[i]->p_lk_loc_left[j] = j; + tree->a_edges[i]->p_lk_loc_rght[j] = j; + } + } + + for(i=0;in_otu;i++) + { + d = tree->a_nodes[i]; + patt_id_d = (d == d->b[0]->left)?(d->b[0]->patt_id_left):(d->b[0]->patt_id_rght); + for(j=0;jn_pattern;j++) + { + assert(tree->a_nodes[d->num]->c_seq); + patt_id_d[j] = (int)tree->a_nodes[d->num]->c_seq->state[j]; + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/* Returns a vector containing the posterior probabilities of - the different branch rate classes -*/ -phydbl *Post_Prob_Rates_At_Given_Edge(edge *b, phydbl *post_prob, arbre *tree) +phydbl Lk_Normal_Approx(t_tree *tree) { - phydbl norm_factor; - int rcat, scale_int; - phydbl sum,log2,lnL,worst_lnL,best_lnL,mid_lnL; + phydbl lnL; + int i; + int dim; + phydbl first_order; + dim = 2*tree->n_otu-3; - For(rcat,tree->mod->n_rr_branch) post_prob[rcat] = .0; + lnL = Dnorm_Multi_Given_InvCov_Det(tree->rates->u_cur_l, + tree->rates->mean_l, + tree->rates->invcov, + tree->rates->covdet, + 2*tree->n_otu-3,YES); - log2 = 0.6931472; - - best_lnL = UNLIKELY; - worst_lnL = .0; - For(rcat,tree->mod->n_rr_branch) + first_order = 0.0; + for(i=0;irates->u_cur_l[i] - tree->rates->mean_l[i]) * tree->rates->grad_l[i]; + + lnL += first_order; + + return(lnL); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Wrap_Part_Lk_At_Given_Edge(t_edge *b, t_tree *tree, supert_tree *stree) +{ + return -1.0; + /* return PART_Lk_At_Given_Edge(b,stree);; */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Wrap_Part_Lk(t_edge *b, t_tree *tree, supert_tree *stree) +{ + return -1.0; + /* return PART_Lk(stree); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Wrap_Lk(t_edge *b, t_tree *tree, supert_tree *stree) +{ + Lk(NULL,tree); + return tree->c_lnL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Wrap_Geo_Lk(t_edge *b, t_tree *tree, supert_tree *stree) +{ + TIPO_Lk(tree); + return tree->geo_lnL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Wrap_Lk_At_Given_Edge(t_edge *b, t_tree *tree, supert_tree *stree) +{ + Lk(b,tree); + return tree->c_lnL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Wrap_Lk_Rates(t_edge *b, t_tree *tree, supert_tree *stree) +{ + RATES_Lk_Rates(tree); + return tree->rates->c_lnL_rates; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Wrap_Lk_Times(t_edge *b, t_tree *tree, supert_tree *stree) +{ + TIMES_Lk_Times(NO,tree); + return tree->rates->c_lnL_times; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Wrap_Lk_Linreg(t_edge *b, t_tree *tree, supert_tree *stree) +{ + /* RATES_Lk_Linreg(tree); */ + return -1.; + /* return tree->rates->c_lnL_linreg; */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Wrap_Diff_Lk_Norm_At_Given_Edge(t_edge *b, t_tree *tree, supert_tree *stree) +{ + phydbl diff; + diff = Diff_Lk_Norm_At_Given_Edge(b,tree); + return(-diff); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Check_Lk_At_Given_Edge(int verbose, t_tree *tree) +{ + int res; + int i; + phydbl *lk; + + lk = (phydbl *)mCalloc(2*tree->n_otu-3,sizeof(phydbl)); + + res = 0; + for(i=0;i<2*tree->n_otu-3;++i) { - tree->rates->br_r[b->num] = tree->mod->rr_branch[rcat]; - lnL = Lk_At_Given_Edge(b,tree); + lk[i] = Lk(tree->a_edges[i],tree); + if(verbose == YES) PhyML_Printf("\n. Edge %3d %13G %f %13G", + tree->a_edges[i]->num,tree->a_edges[i]->l->v,lk[i], + tree->a_edges[i]->l_var->v); + + } - if(lnL < worst_lnL) worst_lnL = lnL; - if(lnL > best_lnL) best_lnL = lnL; - post_prob[rcat] = lnL; + if(tree->n_root && tree->ignore_root == NO) + { + Lk(tree->n_root->b[1],tree); + if(verbose == YES) PhyML_Printf("\nx Edge %3d %13G %f %13G", + tree->n_root->b[1]->num,tree->n_root->b[1]->l->v,tree->c_lnL, + tree->n_root->b[1]->l_var->v + ); + + Lk(tree->n_root->b[2],tree); + if(verbose == YES) PhyML_Printf("\nx Edge %3d %13G %f %13G", + tree->n_root->b[2]->num,tree->n_root->b[2]->l->v,tree->c_lnL, + tree->n_root->b[2]->l_var->v + ); - tree->rates->br_r[b->num] = 1.0; } - mid_lnL = worst_lnL + fabs(worst_lnL - best_lnL)/2.; + res=1; + for(i=1;i<2*tree->n_otu-3;i++) + { + if(FABS(lk[i]-lk[i-1]) > 1.E-2) res=0; + } + Free(lk); + + return res; +} - /* exp(log(P(D|r))) is hard to compute. Try exp(log(K*P(D|r))) - instead. The value of K is chosen such that the most accurate - estimates of the posterior probabilities are obtained for the - most likely rate classes. - */ - scale_int = 0; - do scale_int++; - while(best_lnL + scale_int * log2 < 20.0); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - norm_factor = .0; - For(rcat,tree->mod->n_rr_branch) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Computes the value of fact_sum_scale, the part of the scaling factors +// that is common to all classes of the mixture and scale the +// likelihood for each mixture using the part of the scaling +// factors that is class-specific + +void Pull_Scaling_Factors(int site, t_edge *b, t_tree *tree) +{ + unsigned int catg; + const unsigned int ncatg = tree->mod->ras->n_catg; + + if(tree->apply_lk_scaling == NO) + { + tree->fact_sum_scale[site] = 0; + for(catg=0;catgunscaled_site_lk_cat[site*ncatg+catg] = tree->site_lk_cat[catg]; + return; + } + else { -/* printf("\n. best_lnL=%f curr_lnL=%f %f %E", */ -/* best_lnL, */ -/* post_prob[rcat] , */ -/* post_prob[rcat] + scale_int * log2, */ -/* exp(post_prob[rcat] + scale_int * log2)); */ + switch(tree->scaling_method) + { + case SCALE_RATE_SPECIFIC : + { + int *sum_scale_left_cat,*sum_scale_rght_cat; + int exponent; + phydbl max_sum_scale,min_sum_scale; + phydbl sum,tmp,dum; + + sum_scale_left_cat = b->sum_scale_left_cat; + sum_scale_rght_cat = b->sum_scale_rght_cat; + + max_sum_scale = (phydbl)BIG; + min_sum_scale = -(phydbl)BIG; + + for(catg=0;catgsum_scale_left)? + (b->sum_scale_left[site*ncatg+catg]): + (0.0); + + sum_scale_rght_cat[catg] = + (b->sum_scale_rght)? + (b->sum_scale_rght[site*ncatg+catg]): + (0.0); + + sum = sum_scale_left_cat[catg] + sum_scale_rght_cat[catg]; + + if(sum < .0) + { + PhyML_Fprintf(stderr,"\n. tree: %s\n",Write_Tree(tree)); + PhyML_Fprintf(stderr,"\n. b->num = %d sum = %G root ? %d",sum,b->num,b == tree->e_root); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d.\n",__FILE__,__LINE__); + Exit("\n"); + } + + dum = log(FABS(tree->site_lk_cat[catg])); + + tmp = sum + ((phydbl)LOGBIG - dum)/(phydbl)LOG2; + if(tmp < max_sum_scale) max_sum_scale = tmp; /* min of the maxs */ + + tmp = sum + ((phydbl)LOGSMALL - dum)/(phydbl)LOG2; + if(tmp > min_sum_scale) min_sum_scale = tmp; /* max of the mins */ + + assert(isnan(tmp) == NO); + } + + if(min_sum_scale > max_sum_scale) + { +#ifdef SAFEMODE + PhyML_Printf("\n. Numerical precision issue alert."); + PhyML_Printf("\n. min_sum_scale = %G max_sum_scale = %G",min_sum_scale,max_sum_scale); +#endif + min_sum_scale = max_sum_scale; + } + + tree->fact_sum_scale[site] = (int)((max_sum_scale + min_sum_scale) / 2); + + /* Apply scaling factors */ + for(catg=0;catgfact_sum_scale[site]; + Rate_Correction(exponent,tree->site_lk_cat + catg); + } + + break; + } + case SCALE_FAST : + { + int sum_scale_left,sum_scale_rght; + + sum_scale_left = + (b->sum_scale_left)? + (b->sum_scale_left[site]): + (0.0); + + sum_scale_rght = + (b->sum_scale_rght)? + (b->sum_scale_rght[site]): + (0.0); + + tree->fact_sum_scale[site] = sum_scale_left + sum_scale_rght; + + break; + } + } + for(catg=0;catgunscaled_site_lk_cat[site*ncatg+catg] = tree->site_lk_cat[catg]; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - post_prob[rcat] = exp(post_prob[rcat] + scale_int * log2); +// Tree should be ready for likelihood analysis when calling +// this function. + void Stepwise_Add_Lk(t_tree *tree) + { + t_edge **residuals,**targets,*best_target; + int *nd_idx,i,j,n_targets,*tg_idx,n_opt; + residuals = (t_edge **)mCalloc(tree->n_otu-3,sizeof(t_edge *)); + targets = (t_edge **)mCalloc(2*tree->n_otu-3,sizeof(t_edge *)); + best_target = NULL; + nd_idx = Permutate(tree->n_otu-3); - post_prob[rcat] *= tree->mod->p_rr_branch[rcat]; - norm_factor += post_prob[rcat]; + // Remove all tips except that corresponding to a_nodes[0], + // a_nodes[1] and a_nodes[2]. + for(i=0;in_otu-3;i++) + { + Prune_Subtree(tree->a_nodes[i+3]->v[0], + tree->a_nodes[i+3], + NULL, + residuals+i, + tree); } - sum = .0; - For(rcat,tree->mod->n_rr_branch) + // Initial targets + n_targets = 3; + for(i=0;ia_nodes[i]->b[0]; + + // Regraft each tip on the tree at most parsimonious position + for(i=0;in_otu-3;i++) { - post_prob[rcat] /= norm_factor; -/* printf("%f ",post_prob[rcat]); */ - sum += post_prob[rcat]; + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + + printf("\n. [%d/%d]",i,tree->n_otu-3); + + tree->best_lnL = UNLIKELY; + best_target = NULL; + tg_idx = Permutate(n_targets); + + for(j=0;ja_nodes[nd_idx[i]+3]->v[0], + NULL, + residuals[i], + NULL, + tree); + + Update_PMat_At_Given_Edge(targets[tg_idx[j]],tree); + Update_PMat_At_Given_Edge(tree->a_nodes[nd_idx[i]+3]->b[0],tree); + Update_Partial_Lk(tree,residuals[i],tree->a_nodes[nd_idx[i]+3]->v[0]); + Lk(residuals[i],tree); + + if(tree->c_lnL > tree->best_lnL) + { + tree->best_lnL = tree->c_lnL; + best_target = targets[tg_idx[j]]; + } + + Prune_Subtree(tree->a_nodes[nd_idx[i]+3]->v[0], + tree->a_nodes[nd_idx[i]+3], + NULL, + residuals+i, + tree); + } + + assert(best_target); + + Graft_Subtree(best_target, + tree->a_nodes[nd_idx[i]+3]->v[0], + NULL, + residuals[i], + NULL, + tree); + + n_opt = 0; + do Optimize_Br_Len_Serie (2,tree); while(n_opt++ < 3); + + targets[n_targets] = residuals[i]; + targets[n_targets+1] = tree->a_nodes[nd_idx[i]+3]->b[0]; + + Free(tg_idx); + n_targets+=2; } + + Round_Optimize(tree,5); + PhyML_Fprintf(stderr,"\n. lk: %f",tree->c_lnL); + Exit("\n"); + + Free(nd_idx); + Free(residuals); + Free(targets); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/* | + | + |b + | + |d + / \ + / \ + / \ + / \ + /v1 \v2 + + Set p_lk and sum_scale for subtrees with d, v1 and v2 as root, + Pij for edges b, and the two edges connecting d to v1 and d to + v2; + Account for rooted trees. +*/ + +void Set_All_Partial_Lk(t_node **n_v1, t_node **n_v2, + phydbl **p_lk, int **sum_scale, int **p_lk_loc, + phydbl **Pij1, phydbl **tPij1, phydbl **p_lk_v1, int **sum_scale_v1, + phydbl **Pij2, phydbl **tPij2, phydbl **p_lk_v2, int **sum_scale_v2, + t_node *d, t_edge *b, t_tree *tree +#ifdef BEAGLE + , int *dest_p_idx, int *child1_p_idx, int* child2_p_idx, int* Pij1_idx, int* Pij2_idx +#endif + ) +{ + unsigned int i; + + assert(tree->is_mixt_tree == NO); + assert(d->tax == NO); - if(sum < 0.999 || sum > 1.001) + if(tree->n_root == NULL || tree->ignore_root == YES) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + /* Does d lie on the "left" or "right" of the branch? */ + if(d == b->left) + { + *p_lk = b->p_lk_left; + *sum_scale = b->sum_scale_left; + *p_lk_loc = b->p_lk_loc_left; +#ifdef BEAGLE + *dest_p_idx = b->p_lk_left_idx; +#endif + } + else + { + *p_lk = b->p_lk_rght; + *sum_scale = b->sum_scale_rght; + *p_lk_loc = b->p_lk_loc_rght; +#ifdef BEAGLE + *dest_p_idx = b->p_lk_rght_idx; +#endif + } + + *n_v1 = *n_v2 = NULL; + for(i=0;i<3;++i) + { + if(d->b[i] != b) + { + if(!(*n_v1)) + { + *n_v1 = d->v[i]; +#ifdef BEAGLE + Set_Partial_Lk_One_Side(Pij1,tPij1,p_lk_v1,sum_scale_v1,d,d->b[i],tree,child1_p_idx,Pij1_idx); +#else + Set_Partial_Lk_One_Side(Pij1,tPij1,p_lk_v1,sum_scale_v1,d,d->b[i],tree); +#endif + } + else if(!(*n_v2)) + { + *n_v2 = d->v[i]; +#ifdef BEAGLE + Set_Partial_Lk_One_Side(Pij2,tPij2,p_lk_v2,sum_scale_v2,d,d->b[i],tree,child2_p_idx,Pij2_idx); +#else + Set_Partial_Lk_One_Side(Pij2,tPij2,p_lk_v2,sum_scale_v2,d,d->b[i],tree); +#endif + } + else assert(FALSE); + } + } } + else + { + if(b == tree->e_root) + { + if(d == tree->n_root->v[1]) b = tree->n_root->b[1]; + else if(d == tree->n_root->v[2]) b = tree->n_root->b[2]; + else assert(FALSE); + } + + if(d == tree->n_root) + { + if(b == tree->n_root->b[1]) + { + *p_lk = tree->n_root->b[1]->p_lk_left; + *sum_scale = tree->n_root->b[1]->sum_scale_left; + *p_lk_loc = tree->n_root->b[1]->p_lk_loc_left; +#ifdef BEAGLE + *dest_p_idx = tree->n_root->b[1]->p_lk_left_idx; +#endif + } + else + { + *p_lk = tree->n_root->b[2]->p_lk_left; + *sum_scale = tree->n_root->b[2]->sum_scale_left; + *p_lk_loc = tree->n_root->b[2]->p_lk_loc_left; +#ifdef BEAGLE + *dest_p_idx = tree->n_root->b[2]->p_lk_left_idx; +#endif + } + + *n_v1 = NULL; + *Pij1 = NULL; + *tPij1 = NULL; + *p_lk_v1 = NULL; + *sum_scale_v1 = NULL; + + if(b == tree->n_root->b[1]) + { + *n_v2 = tree->n_root->v[2]; + *Pij2 = tree->n_root->b[2]->Pij_rr; + *tPij2 = tree->n_root->b[2]->tPij_rr; + *p_lk_v2 = tree->n_root->b[2]->p_lk_rght; + *sum_scale_v2 = tree->n_root->b[2]->sum_scale_rght; +#ifdef BEAGLE + *child2_p_idx = tree->n_root->b[2]->p_lk_rght_idx; + *Pij2_idx = tree->n_root->b[2]->Pij_rr_idx; +#endif + } + else if(b == tree->n_root->b[2]) + { + *n_v2 = tree->n_root->v[1]; + *Pij2 = tree->n_root->b[1]->Pij_rr; + *tPij2 = tree->n_root->b[1]->tPij_rr; + *p_lk_v2 = tree->n_root->b[1]->p_lk_rght; + *sum_scale_v2 = tree->n_root->b[1]->sum_scale_rght; +#ifdef BEAGLE + *child2_p_idx = tree->n_root->b[1]->p_lk_rght_idx; + *Pij2_idx = tree->n_root->b[1]->Pij_rr_idx; +#endif + } + else assert(FALSE); + } + else if(d == tree->n_root->v[1] || d == tree->n_root->v[2]) + { + if(b == tree->n_root->b[1] || b == tree->n_root->b[2]) + { + if(b == tree->n_root->b[1]) + { + *p_lk = tree->n_root->b[1]->p_lk_rght; + *sum_scale = tree->n_root->b[1]->sum_scale_rght; + *p_lk_loc = tree->n_root->b[1]->p_lk_loc_left; +#ifdef BEAGLE + *dest_p_idx = tree->n_root->b[1]->p_lk_rght_idx; +#endif + } + else + { + *p_lk = tree->n_root->b[2]->p_lk_rght; + *sum_scale = tree->n_root->b[2]->sum_scale_rght; + *p_lk_loc = tree->n_root->b[2]->p_lk_loc_rght; +#ifdef BEAGLE + *dest_p_idx = tree->n_root->b[2]->p_lk_rght_idx; +#endif + } + + *n_v1 = *n_v2 = NULL; + for(i=0;i<3;++i) + { + if(d->b[i] != tree->e_root) + { + if(!(*n_v1)) + { + *n_v1 = d->v[i]; +#ifdef BEAGLE + Set_Partial_Lk_One_Side(Pij1,tPij1,p_lk_v1,sum_scale_v1,d,d->b[i],tree,child1_p_idx,Pij1_idx); +#else + Set_Partial_Lk_One_Side(Pij1,tPij1,p_lk_v1,sum_scale_v1,d,d->b[i],tree); +#endif + } + else + { + *n_v2 = d->v[i]; +#ifdef BEAGLE + Set_Partial_Lk_One_Side(Pij2,tPij2,p_lk_v2,sum_scale_v2,d,d->b[i],tree,child2_p_idx,Pij2_idx); +#else + Set_Partial_Lk_One_Side(Pij2,tPij2,p_lk_v2,sum_scale_v2,d,d->b[i],tree); +#endif + } + } + } + } + else + { + if(d == b->left) + { + *p_lk = b->p_lk_left; + *sum_scale = b->sum_scale_left; + *p_lk_loc = b->p_lk_loc_left; +#ifdef BEAGLE + *dest_p_idx = b->p_lk_left_idx; +#endif + } + else + { + *p_lk = b->p_lk_rght; + *sum_scale = b->sum_scale_rght; + *p_lk_loc = b->p_lk_loc_rght; +#ifdef BEAGLE + *dest_p_idx = b->p_lk_rght_idx; +#endif + } + + + *n_v1 = tree->n_root; +#ifdef BEAGLE + Set_Partial_Lk_One_Side(Pij1,tPij1,p_lk_v1,sum_scale_v1,d, + (d == tree->n_root->v[1])? + (tree->n_root->b[1]): + (tree->n_root->b[2]), + tree,child1_p_idx,Pij1_idx); +#else + Set_Partial_Lk_One_Side(Pij1,tPij1,p_lk_v1,sum_scale_v1,d, + (d == tree->n_root->v[1])? + (tree->n_root->b[1]): + (tree->n_root->b[2]), + tree); +#endif + for(i=0;i<3;i++) + { + if(d->b[i] != tree->e_root && d->b[i] != b) + { + *n_v2 = d->v[i]; +#ifdef BEAGLE + Set_Partial_Lk_One_Side(Pij2,tPij2,p_lk_v2,sum_scale_v2,d,d->b[i],tree,child2_p_idx,Pij2_idx); +#else + Set_Partial_Lk_One_Side(Pij2,tPij2,p_lk_v2,sum_scale_v2,d,d->b[i],tree); +#endif + break; + } + } - return post_prob; + } + } + else + { + if(d == b->left) + { + *p_lk = b->p_lk_left; + *sum_scale = b->sum_scale_left; + *p_lk_loc = b->p_lk_loc_left; +#ifdef BEAGLE + *dest_p_idx = b->p_lk_left_idx; +#endif + } + else + { + *p_lk = b->p_lk_rght; + *sum_scale = b->sum_scale_rght; + *p_lk_loc = b->p_lk_loc_rght; +#ifdef BEAGLE + *dest_p_idx = b->p_lk_rght_idx; +#endif + } + + *n_v1 = *n_v2 = NULL; + for(i=0;i<3;i++) + { + if(d->b[i] != b) + { + if(!(*n_v1)) + { + *n_v1 = d->v[i]; +#ifdef BEAGLE + Set_Partial_Lk_One_Side(Pij1,tPij1,p_lk_v1,sum_scale_v1,d,d->b[i],tree,child1_p_idx,Pij1_idx); +#else + Set_Partial_Lk_One_Side(Pij1,tPij1,p_lk_v1,sum_scale_v1,d,d->b[i],tree); +#endif + } + else + { + *n_v2 = d->v[i]; +#ifdef BEAGLE + Set_Partial_Lk_One_Side(Pij2,tPij2,p_lk_v2,sum_scale_v2,d,d->b[i],tree,child2_p_idx,Pij2_idx); +#else + Set_Partial_Lk_One_Side(Pij2,tPij2,p_lk_v2,sum_scale_v2,d,d->b[i],tree); +#endif + } + } + } + } + } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* | + | + |d + / \ + / \ + / \b + / \ + / \x (either n_v1 or n_v2) -phydbl Lk_With_MAP_Branch_Rates(arbre *tree) + Returns p_lk and sum_scale for subtree with x as root, Pij for edge b +*/ + +void Set_Partial_Lk_One_Side(phydbl **Pij, phydbl **tPij, phydbl **p_lk, int **sum_scale, t_node *d, t_edge *b, t_tree *tree +#ifdef BEAGLE + , int* child_p_idx, int* Pij_idx +#endif + ) { - int br,rcat,best_post_prob_cat; - phydbl *post_prob; - phydbl best_post_prob; - edge *b; + if(Pij != NULL) + { + *Pij = b->Pij_rr; + *tPij = b->tPij_rr; +#ifdef BEAGLE + *Pij_idx = b->Pij_rr_idx; +#endif + } - post_prob = (phydbl *)mCalloc(tree->mod->n_rr_branch,sizeof(phydbl)); - - Lk(tree); - Record_Br_Len(tree); + if(d->tax == NO) + { + if(d == b->left) // if d is on the left of b, then d's neighbor is on the right + { + *p_lk = (b->rght->tax == YES) ? b->p_lk_tip_r : b->p_lk_rght; + *sum_scale = b->sum_scale_rght; +#ifdef BEAGLE + *child_p_idx = b->rght->tax? b->p_lk_tip_idx: b->p_lk_rght_idx; +#endif + assert(*p_lk); + } + else + { + *p_lk = b->p_lk_left; + *sum_scale = b->sum_scale_left; +#ifdef BEAGLE + *child_p_idx = b->rght->tax? b->p_lk_tip_idx: b->p_lk_left_idx; +#endif + assert(*p_lk); + } + } + else + { +#ifdef BEAGLE + Warn_And_Exit(TODO_BEAGLE); +#endif + *p_lk = NULL; + *sum_scale = NULL; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(br,2*tree->n_otu-3) +void Switch_Partial_Lk_Post(t_node *a, t_node *d, t_edge *b, short int yesno, t_tree *tree) +{ + if(a == tree->n_root) assert(FALSE); + if(d->tax == NO) { - b = tree->t_edges[br]; + int i; - /* Compute the posterior probability of each rate class on edge b */ - post_prob = (phydbl *)Post_Prob_Rates_At_Given_Edge(b,post_prob,tree); + for(i=0;i<3;++i) + if(d->v[i] != a) + Switch_Partial_Lk_Post(d,d->v[i],d->b[i],yesno,tree); + } - /* Find the most probable class */ - best_post_prob = UNLIKELY; - best_post_prob_cat = -1; - For(rcat,tree->mod->n_rr_branch) - { - if(post_prob[rcat] > best_post_prob) - { - best_post_prob = post_prob[rcat]; - best_post_prob_cat = rcat; - } - } + if(b->left == d) b->update_partial_lk_left = yesno; + else if(b->rght == d) b->update_partial_lk_rght = yesno; + else assert(FALSE); - /* The relative rate on this branch corresponds to the most probable rate class */ - tree->rates->br_r[br] = tree->mod->rr_branch[best_post_prob_cat]; + return; +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Switch_Partial_Lk_Pre(t_node *a, t_node *d, t_edge *b, short int yesno, t_tree *tree) +{ + if(a == tree->n_root) assert(FALSE); + if(d->tax == YES) return; + else + { + int i; + + for(i=0;i<3;++i) + { + if(d->v[i] != a) + { + if(d->b[i]->left == d) d->b[i]->update_partial_lk_left = yesno; + else if(d->b[i]->rght == d) d->b[i]->update_partial_lk_rght = yesno; + else assert(FALSE); + } + } + + for(i=0;i<3;++i) + if(d->v[i] != a) + Switch_Partial_Lk_Pre(d,d->v[i],d->b[i],yesno,tree); } + + return; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Partial_Lk_Inin(const phydbl *Pij1, const phydbl *plk1, const phydbl *Pij2, const phydbl *plk2, const int ns, phydbl *plk0) +{ + unsigned int i,j; - Lk(tree); - For(br,2*tree->n_otu-3) tree->rates->br_r[br] = 1.0; + for(i=0;i 1.0 || plk1[i] < 1.0 || plk2[i] > 1.0 || plk2[i] < 1.0) break; + + if(i != ns) + { + for(i=0;ic_lnL; +void Partial_Lk_Exex(const phydbl *Pij1, const int state1, const phydbl *Pij2, const int state2, const int ns, phydbl *plk0) +{ + unsigned int i; + for(i=0;i + +#ifndef LK_H +#define LK_H + +#include "utilities.h" +#include "optimiz.h" +#include "models.h" +#include "free.h" +#include "times.h" +#include "mixt.h" +#include "avx.h" +#include "sse.h" + +void Update_All_Partial_Lk(t_tree *tree); +void Init_Tips_At_One_Site_Nucleotides_Float(char state, int pos, phydbl *p_lk); +void Init_Tips_At_One_Site_AA_Float(char aa, int pos, phydbl *p_lk); +void Get_All_Partial_Lk(t_tree *tree,t_edge *b_fcus,t_node *a,t_node *d); +void Get_All_Partial_Lk_Scale(t_tree *tree,t_edge *b_fcus,t_node *a,t_node *d); +void Post_Order_Lk(t_node *pere, t_node *fils, t_tree *tree); +void Pre_Order_Lk(t_node *pere, t_node *fils, t_tree *tree); +phydbl Lk(t_edge *b, t_tree *tree); +void Site_Lk(t_tree *tree); +phydbl Return_Abs_Lk(t_tree *tree); +matrix *ML_Dist(calign *data, t_mod *mod); +phydbl Lk_Given_Two_Seq(calign *data, int numseq1, int numseq2, phydbl dist, t_mod *mod, phydbl *loglk); +void Unconstraint_Lk(t_tree *tree); +void Update_Partial_Lk(t_tree *tree,t_edge *b_fcus,t_node *n); +void Update_Partial_Lk_Generic(t_tree *tree,t_edge *b_fcus,t_node *n); +/* void Default_Update_Partial_Lk(t_tree *tree,t_edge *b_fcus,t_node *n); */ +void Init_Partial_Lk_Tips_Double(t_tree *tree); +void Init_Partial_Lk_Tips_Int(t_tree *tree); +void Init_Partial_Lk_At_One_Node(t_node *a, t_tree *tree); +void Update_PMat_At_Given_Edge(t_edge *b_fcus, t_tree *tree); +void Sort_Sites_Based_On_Lk(t_tree *tree); +void Get_Partial_Lk_Scale(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d); +void Get_Partial_Lk(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d); +void Init_Tips_At_One_Site_Nucleotides_Int(char state, int pos, short int *p_pars); +void Init_Tips_At_One_Site_AA_Int(char aa, int pos, short int *p_pars); +void Update_Partial_Lk_Along_A_Path(t_node **path, int path_length, t_tree *tree); +phydbl Lk_Dist(phydbl *F, phydbl dist, t_mod *mod); +phydbl Update_Lk_At_Given_Edge(t_edge *b_fcus, t_tree *tree); +void Update_Partial_Lk_Greedy(t_tree *tree, t_edge *b_fcus, t_node *n); +void Get_All_Partial_Lk_Scale_Greedy(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d); +phydbl Lk_Triplet(t_node *a, t_node *d, t_tree *tree); +phydbl *Post_Prob_Rates_At_Given_Edge(t_edge *b, phydbl *post_prob, t_tree *tree); +phydbl Lk_With_MAP_Branch_Rates(t_tree *tree); +void Init_Tips_At_One_Site_Generic_Int(char *state, int ns, int state_len, int pos, short int *p_pars); +void Init_Tips_At_One_Site_Generic_Float(char *state, int ns, int state_len, int pos, phydbl *p_lk); +void Backup_Partial_Lk(t_node *d, t_edge *b, t_tree *tree); +void Restore_Partial_Lk(t_node *d, t_edge *b, t_tree *tree); +void Backup_Partial_Scale(t_node *d, t_edge *b, t_tree *tree); +void Restore_Partial_Scale(t_node *d, t_edge *b, t_tree *tree); +void Init_Partial_Lk_Loc(t_tree *tree); +phydbl Lk_Normal_Approx(t_tree *tree); +phydbl Wrap_Lk(t_edge *b, t_tree *tree, supert_tree *stree); +phydbl Wrap_Lk_At_Given_Edge(t_edge *b, t_tree *tree, supert_tree *stree); +phydbl Wrap_Part_Lk_At_Given_Edge(t_edge *b, t_tree *tree, supert_tree *stree); +phydbl Wrap_Part_Lk(t_edge *b, t_tree *tree, supert_tree *stree); +phydbl Wrap_Geo_Lk(t_edge *b, t_tree *tree, supert_tree *stree); +phydbl Wrap_Diff_Lk_Norm_At_Given_Edge(t_edge *b, t_tree *tree, supert_tree *stree); +phydbl Wrap_Lk_Rates(t_edge *b, t_tree *tree, supert_tree *stree); +phydbl Wrap_Lk_Linreg(t_edge *b, t_tree *tree, supert_tree *stree); +phydbl Wrap_Lk_Times(t_edge *b, t_tree *tree, supert_tree *stree); +phydbl Lk_LastFirst(t_tree *tree); +int Check_Lk_At_Given_Edge(int verbose, t_tree *tree); +void Stepwise_Add_Lk(t_tree *tree); +void Update_Eigen_Lr(t_edge *b, t_tree *tree); +phydbl dLk(phydbl *l, t_edge *b, t_tree *tree); +phydbl Lk_Core(int state, int ambiguity_check,phydbl *p_lk_left, phydbl *p_lk_rght,phydbl *Pij_rr,phydbl *tPij_rr,t_edge *b,t_tree *tree); +/* void Lk_dLk_Core_Eigen_Lr(phydbl *expl, phydbl *dot_prod, t_edge *b, phydbl *lk, phydbl *dlk, t_tree *tree); */ +phydbl Lk_Core_Eigen_Lr(phydbl *expl, phydbl *dot_prod, t_edge *b, t_tree *tree); +phydbl Invariant_Lk(int fact_sum_scale, int site, int *num_prec_issue, t_tree *tree); +void Composite_Lk(t_tree *tree); +int Sample_Ancestral_Seq_Core(t_node *a, t_node *d, t_edge *b, int r_cat, int site, t_tree *tree); +void Default_Update_Partial_Lk(t_tree *tree, t_edge *b, t_node *d); +void Lk_dLk_Core_Eigen_Lr(phydbl *expl, phydbl *dot_prod, t_edge *b, phydbl *lk, phydbl *dlk, t_tree *tree); +void Lk_dLk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, unsigned int ns, phydbl *lk, phydbl *dlk); +phydbl Lk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, int ns); +void Core_Default_Update_Partial_Lk(const t_node *n_v1, const t_node *n_v2, + phydbl *plk0, const phydbl *plk1, const phydbl *plk2, + const phydbl *Pij1, const phydbl *Pij2, + int *sum_scale0, const int *sum_scale1, const int *sum_scale2, + const int ns, const int ncatg, const int npatterns, const int apply_scaling, + const phydbl *wght); + + + + + + +/* phydbl Lk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, int ns); */ +/* void Lk_dLk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, unsigned int ns, phydbl *lk, phydbl *dlk); */ +phydbl Lk_Core_One_Class_No_Eigen_Lr(phydbl *p_lk_left, phydbl *p_lk_rght, phydbl *Pij,phydbl *pi, int ns, int ambiguity_check, int state); + +void Pull_Scaling_Factors(int site,t_edge *b,t_tree *tree); +void Set_All_Partial_Lk(t_node **n_v1, t_node **n_v2,phydbl **p_lk, int **sum_scale, int **p_lk_loc,phydbl **Pij1, phydbl **tPij1, phydbl **p_lk_v1, int **sum_scale_v1,phydbl **Pij2, phydbl **tPij2, phydbl **p_lk_v2, int **sum_scale_v2,t_node *d, t_edge *b, t_tree *tree +#ifdef BEAGLE + , int *dest_p_idx, int *child1_p_idx, int* child2_p_idx, int* Pij1_idx, int* Pij2_idx +#endif + ); +void Set_Partial_Lk_One_Side(phydbl **Pij, phydbl **tPij, phydbl **p_lk, int **sum_scale, t_node *d, t_edge *b, t_tree *tree +#ifdef BEAGLE + , int* child_p_idx, int* Pij_idx +#endif + ); +void Rate_Correction(int exponent, phydbl *site_lk_cat); +void Switch_Partial_Lk_Pre(t_node *a, t_node *d, t_edge *b, short int yesno, t_tree *tree); +void Switch_Partial_Lk_Post(t_node *a, t_node *d, t_edge *b, short int yesno, t_tree *tree); + +void Partial_Lk_Inin(const phydbl *Pij1, const phydbl *plk1, const phydbl *Pij2, const phydbl *plk2, const int ns, phydbl *plk0); +void Partial_Lk_Exex(const phydbl *Pij1, const int state1, const phydbl *Pij2, const int state2, const int ns, phydbl *plk0); +void Partial_Lk_Exin(const phydbl *Pij1, const int state1, const phydbl *Pij2, const phydbl *plk2, const int ns, phydbl *plk0); #endif diff --git a/phyml/m4.c b/phyml/m4.c index 835b608..5510712 100644 --- a/phyml/m4.c +++ b/phyml/m4.c @@ -13,68 +13,51 @@ the GNU public licence. See http://www.opensource.org for details. /* Routines for Markov-Modulated Markov Models (M4) */ -#include "spr.h" -#include "utilities.h" -#include "lk.h" -#include "optimiz.h" -#include "bionj.h" -#include "models.h" -#include "free.h" -#include "options.h" -#include "simu.h" -#include "eigen.h" -#include "pars.h" -#include "alrt.h" #include "m4.h" -#include "mc.h" -#include "draw.h" -#ifdef MG -#include "mg.h" -#endif - int M4_main(int argc, char **argv) { - seq **data; - allseq *alldata; + + calign *cdata; option *io; - arbre *tree; - int n_otu, num_data_set; - int num_tree,tree_line_number,num_rand_tree; - matrix *mat; - model *mod; - m4 *m4mod; + t_tree *tree; + int num_data_set; + int num_tree,num_rand_tree; + t_mod *mod; time_t t_beg,t_end; - div_t hour,min; phydbl best_lnL; - int bootstrap_this_tree; int r_seed; + char *most_likely_tree=NULL; + +#ifdef MPI + int rc; + rc = MPI_Init(&argc,&argv); + if (rc != MPI_SUCCESS) { + PhyML_Printf("\n== Err. starting MPI program. Terminating.\n"); + MPI_Abort(MPI_COMM_WORLD, rc); + } + MPI_Comm_size(MPI_COMM_WORLD,&Global_numTask); + MPI_Comm_rank(MPI_COMM_WORLD,&Global_myRank); +#endif #ifdef QUIET setvbuf(stdout,NULL,_IOFBF,2048); #endif - tree = NULL; - mod = NULL; - data = NULL; - bootstrap_this_tree = 1; - best_lnL = UNLIKELY; + tree = NULL; + mod = NULL; + best_lnL = UNLIKELY; + io = (option *)Get_Input(argc,argv); r_seed = (io->r_seed < 0)?(time(NULL)):(io->r_seed); srand(r_seed); - Make_Model_Complete(io->mod); - mod = io->mod; - m4mod = mod->m4mod; - if(io->in_tree) Test_Multiple_Data_Set_Format(io); - else io->n_trees = 1; - + io->r_seed = r_seed; - if(io->mod->s_opt->random_input_tree) bootstrap_this_tree = 0; - mat = NULL; - tree_line_number = 0; + if(io->in_tree == 2) Test_Multiple_Data_Set_Format(io); + else io->n_trees = 1; if((io->n_data_sets > 1) && (io->n_trees > 1)) @@ -83,295 +66,244 @@ int M4_main(int argc, char **argv) io->n_trees = MIN(io->n_trees,io->n_data_sets); } - - For(num_data_set,io->n_data_sets) + for(num_data_set=0;num_data_setn_data_sets;num_data_set++) { - n_otu = 0; best_lnL = UNLIKELY; - data = Get_Seq(io,0); - - if(data) + Get_Seq(io); + Make_Model_Complete(io->mod); + Set_Model_Name(io->mod); + Print_Settings(io); + mod = io->mod; + + if(io->data) { - if(io->n_data_sets > 1) printf("\n. Data set [#%d]\n",num_data_set+1); - printf("\n. Compressing sequences...\n"); - alldata = Compact_Seq(data,io); - Free_Seq(data,alldata->n_otu); - Check_Ambiguities(alldata,io->mod->datatype,io->mod->stepsize); + if(io->n_data_sets > 1) PhyML_Printf("\n. Data set [#%d]\n",num_data_set+1); + cdata = Compact_Data(io->data,io); - for(num_tree=(io->n_trees == 1)?(0):(num_data_set);num_tree < io->n_trees;num_tree++) + Free_Seq(io->data,cdata->n_otu); + + if(cdata) Check_Ambiguities(cdata,io->datatype,io->state_len); + else { + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + for(num_tree=(io->n_trees == 1)?(0):(num_data_set);num_tree < io->n_trees;num_tree++) + { if(!io->mod->s_opt->random_input_tree) io->mod->s_opt->n_rand_starts = 1; - For(num_rand_tree,io->mod->s_opt->n_rand_starts) + for(num_rand_tree=0;num_rand_treemod->s_opt->n_rand_starts;num_rand_tree++) { - if((io->mod->s_opt->random_input_tree) && (io->mod->s_opt->topo_search == SPR_MOVE)) - printf("\n. [Random start %3d/%3d]\n",num_rand_tree+1,io->mod->s_opt->n_rand_starts); + if((io->mod->s_opt->random_input_tree) && (io->mod->s_opt->topo_search != NNI_MOVE)) + if(!io->quiet) PhyML_Printf("\n. [Random start %3d/%3d]\n",num_rand_tree+1,io->mod->s_opt->n_rand_starts); - Init_Model(alldata,mod); - if(io->m4_model) M4_Init_Model(m4mod,alldata,mod); + Init_Model(cdata,mod,io); - if(!io->in_tree) - { - printf("\n. Computing pairwise distances...\n"); - mat = ML_Dist(alldata,mod); - Fill_Missing_Dist(mat); - printf("\n. Building BIONJ tree...\n"); - mat->tree = Make_Tree_From_Scratch(alldata->n_otu,alldata); - Bionj(mat); - tree = mat->tree; - tree->mat = mat; + if(io->mod->use_m4mod) M4_Init_Model(mod->m4mod,cdata,mod); - } - else + switch(io->in_tree) { - if((io->n_trees == 1) || (!num_tree)) - { - rewind(io->fp_in_tree); - tree_line_number = 0; - } - - if(io->n_trees > 1) printf("\n. Reading tree [#%d]\n",tree_line_number+1); - else printf("\n. Reading tree...\n"); - fflush(NULL); - - tree = Read_Tree_File(io->fp_in_tree); - tree_line_number++; - - if(!tree) - { - printf("\n. Input tree not found...\n"); - Exit("\n\n"); - } - - if(!tree->has_branch_lengths) - { - printf("\n. Computing branch length estimates...\n"); - Order_Tree_CSeq(tree,alldata); - mat = ML_Dist(alldata,mod); - mat->tree = tree; - mat->method = 0; - Bionj_Br_Length(mat); - tree->mat = mat; - } - - tree->mod = mod; - tree->io = io; - tree->data = alldata; - tree->both_sides = 1; - tree->n_pattern = tree->data->crunch_len/tree->mod->stepsize; + case 0 : case 1 : { tree = Dist_And_BioNJ(cdata,mod,io); break; } + case 2 : { tree = Read_User_Tree(cdata,mod,io); break; } } + if(!tree) continue; time(&t_beg); time(&(tree->t_beg)); - + tree->mod = mod; tree->io = io; - tree->data = alldata; - tree->both_sides = 1; - tree->n_pattern = tree->data->crunch_len/tree->mod->stepsize; - - if((!num_data_set) && (!num_tree) && (!num_rand_tree)) - { -#ifndef BATCH - Check_Memory_Amount(tree); -#endif - } + tree->data = cdata; + tree->n_pattern = tree->data->crunch_len; - Order_Tree_CSeq(tree,alldata); + Set_Both_Sides(YES,tree); + + if(mod->s_opt->random_input_tree) Random_Tree(tree); - if((tree->mod->s_opt->random_input_tree) && (tree->mod->s_opt->topo_search == SPR_MOVE)) - { - printf("\n. Randomising the tree...\n"); - Random_Tree(tree); - } + if((!num_data_set) && (!num_tree) && (!num_rand_tree)) Check_Memory_Amount(tree); - Fill_Dir_Table(tree); - Update_Dirs(tree); - Make_Tree_4_Pars(tree,alldata,alldata->init_len); - Make_Tree_4_Lk(tree,alldata,alldata->init_len); - tree->triplet_struct = Make_Triplet_Struct(mod); - Br_Len_Not_Involving_Invar(tree); - - if((tree->mod->s_opt->topo_search == SPR_MOVE) || - (tree->mod->s_opt->topo_search == NNI_MOVE && - tree->mod->s_opt->spr_step_after_nnis)) + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); + Make_Spr(tree); + + if(io->do_alias_subpatt) { - Make_Spr_List(tree); - Make_Best_Spr(tree); + MIXT_Set_Alias_Subpatt(YES,tree); + Lk(NULL,tree); + MIXT_Set_Alias_Subpatt(NO,tree); } - if(tree->mod->s_opt->opt_topo) { - if(tree->mod->s_opt->topo_search == NNI_MOVE) - { - Simu(tree,1000); - } - else - { - if(tree->mod->s_opt->steph_spr) - { - Speed_Spr(tree); - Simu(tree,1000); - } - else - { - Init_SPR(tree); - Optim_SPR(tree,0,ALL); - Clean_SPR(tree); - } - } + if(tree->mod->s_opt->topo_search == NNI_MOVE) Simu_Loop(tree); + else if(tree->mod->s_opt->topo_search == SPR_MOVE) Global_Spr_Search(tree); + else Best_Of_NNI_And_SPR(tree); } else { - if(tree->mod->s_opt->opt_num_param || tree->mod->s_opt->opt_bl) - { - Round_Optimize(tree,tree->data); - } - else - { - Lk(tree); - Print_Lk(tree,""); - } + if(tree->mod->s_opt->opt_subst_param || + tree->mod->s_opt->opt_bl) Round_Optimize(tree,ROUND_MAX); + else Lk(NULL,tree); } - - if(tree->io->ratio_test) aLRT(tree); - - Lk(tree); - printf("\n\n. Final log likelihood : %f",tree->c_lnL); + + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + Pars(NULL,tree); + Get_Tree_Size(tree); + PhyML_Printf("\n. Log likelihood of the current tree: %f.\n",tree->c_lnL); + + Exit("\n"); /* */ M4_Compute_Proba_Hidden_States_On_Edges(tree); /* */ + Get_Best_Root_Position(tree); - - if((tree->c_lnL > best_lnL) && (io->mod->s_opt->n_rand_starts > 1)) + /* Print the tree estimated using the current random (or BioNJ) starting tree */ + if(io->mod->s_opt->n_rand_starts > 1) { - best_lnL = tree->c_lnL; - io->fp_out_best_tree = (FILE *)fopen(io->out_best_tree_file,"w"); - Print_Tree(io->fp_out_best_tree,tree); + Br_Len_Involving_Invar(tree); + Print_Tree(io->fp_out_trees,tree); fflush(NULL); - fclose(io->fp_out_best_tree); } - if((tree->mod->bootstrap) && (bootstrap_this_tree)) + /* Record the most likely tree in a string of characters */ + if(tree->c_lnL > best_lnL) { - if(num_rand_tree > 0) io->in_tree = 0; - Bootstrap(tree); - tree->mod->bootstrap = 0; + best_lnL = tree->c_lnL; + Br_Len_Involving_Invar(tree); + if(most_likely_tree) Free(most_likely_tree); + most_likely_tree = Write_Tree(tree); + Get_Tree_Size(tree); } - Br_Len_Involving_Invar(tree); - Print_Tree(io->fp_out_tree,tree); +/* JF(tree); */ - Unconstraint_Lk(tree); time(&t_end); - hour = div(t_end-t_beg,3600); - min = div(t_end-t_beg,60 ); - min.quot -= hour.quot*60; - printf("\n\n. Time used %dh%dm%ds\n", hour.quot,min.quot,(int)(t_end-t_beg)%60); - printf("\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); + Print_Fp_Out(io->fp_out_stats,t_beg,t_end,tree, io,num_data_set+1, - (tree->mod->s_opt->n_rand_starts > 1)?(num_rand_tree):(num_tree)); + (tree->mod->s_opt->n_rand_starts > 1)? + (num_rand_tree):(num_tree),YES, io->precision); if(tree->io->print_site_lnl) Print_Site_Lk(tree,io->fp_out_lk); /* Start from BioNJ tree */ - if((num_rand_tree == io->mod->s_opt->n_rand_starts-1) - && (io->mod->s_opt->n_rand_starts > 1) - && (tree->mod->s_opt->random_input_tree)) + if((num_rand_tree == io->mod->s_opt->n_rand_starts-1) && (tree->mod->s_opt->random_input_tree)) { + /* Do one more iteration in the loop, but don't randomize the tree */ num_rand_tree--; tree->mod->s_opt->random_input_tree = 0; } - - if((num_rand_tree == io->mod->s_opt->n_rand_starts - 1) && - (!tree->mod->s_opt->random_input_tree) && - (io->mod->s_opt->n_rand_starts > 1)) - { - if(tree->mod->bootstrap) - { - num_rand_tree--; - io->in_tree = 1; - io->fp_in_tree = io->fp_out_best_tree; - bootstrap_this_tree = 1; - io->fp_in_tree = (FILE *)fopen(io->out_best_tree_file,"r"); - } - else - { - io->fp_out_best_tree = (FILE *)fopen(io->out_best_tree_file,"w"); - Print_Tree(io->fp_out_best_tree,tree); - fflush(NULL); - fclose(io->fp_out_best_tree); - } - } - - if((tree->mod->s_opt->topo_search == SPR_MOVE) || - (tree->mod->s_opt->topo_search == NNI_MOVE && - tree->mod->s_opt->spr_step_after_nnis)) - { - Free_Spr_List(tree); - Free_One_Spr(tree->best_spr); - } - + + Free_Spr_List_One_Edge(tree); + Free_One_Spr(tree->best_spr); if(tree->mat) Free_Mat(tree->mat); - Free_Triplet(tree->triplet_struct); Free_Tree_Pars(tree); Free_Tree_Lk(tree); Free_Tree(tree); } + + + /* Launch bootstrap analysis */ + if(io->do_boot || io->do_tbe) + { + if(!io->quiet) PhyML_Printf("\n. Launch bootstrap analysis on the most likely tree...\n"); + + #ifdef MPI + MPI_Bcast (most_likely_tree, strlen(most_likely_tree)+1, MPI_CHAR, 0, MPI_COMM_WORLD); + if(!io->quiet) PhyML_Printf("\n. The bootstrap analysis will use %d CPUs.\n",Global_numTask); + #endif + + most_likely_tree = Bootstrap_From_String(most_likely_tree,cdata,mod,io); + } + else if(io->ratio_test) + { + /* Launch aLRT */ + if(!io->quiet) PhyML_Printf("\n. Compute aLRT branch supports on the most likely tree...\n"); + most_likely_tree = aLRT_From_String(most_likely_tree,cdata,mod,io); + } + + /* Print the most likely tree in the output file */ + if(!io->quiet) PhyML_Printf("\n. Printing the most likely tree in file '%s'...\n", Basename(io->out_tree_file)); + if(io->n_data_sets == 1) rewind(io->fp_out_tree); + PhyML_Fprintf(io->fp_out_tree,"%s\n",most_likely_tree); + + if(io->n_trees > 1 && io->n_data_sets > 1) break; } - Free_Cseq(alldata); + Free_Calign(cdata); } + else + { + PhyML_Printf("\n. No data was found.\n"); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + Free_Model_Complete(mod); } + + if(most_likely_tree) Free(most_likely_tree); - if(io->mod->s_opt->n_rand_starts > 1) printf("\n\n. Best log likelihood : %f\n",best_lnL); + if(mod->s_opt->n_rand_starts > 1) PhyML_Printf("\n. Best log likelihood: %f\n",best_lnL); - Free_Model(mod); + Free_Optimiz(mod->s_opt); + Free_Model_Basic(mod); - if(io->fp_in_seq) fclose(io->fp_in_seq); + if(io->fp_in_align) fclose(io->fp_in_align); if(io->fp_in_tree) fclose(io->fp_in_tree); if(io->fp_out_lk) fclose(io->fp_out_lk); if(io->fp_out_tree) fclose(io->fp_out_tree); + if(io->fp_out_trees) fclose(io->fp_out_trees); if(io->fp_out_stats) fclose(io->fp_out_stats); Free_Input(io); - return 0; + time(&t_end); + Print_Time_Info(t_beg,t_end); + +#ifdef MPI + MPI_Finalize(); +#endif + + return 0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /* Allocate memory */ -m4 *M4_Make_Light(int n_o) +m4 *M4_Make_Light() { m4 *m4mod; m4mod = (m4 *)mCalloc(1,sizeof(m4)); - m4mod->n_o = n_o; - m4mod->o_rr = (phydbl *)mCalloc(n_o*n_o,sizeof(phydbl)); - m4mod->o_fq = (phydbl *)mCalloc(n_o,sizeof(phydbl)); M4_Set_M4mod_Default(m4mod); return m4mod; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void M4_Set_M4mod_Default(m4 *m4mod) { m4mod->use_cov_alpha = 1; m4mod->use_cov_alpha = 0; + m4mod->n_h = 3; + m4mod->n_o = 4; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /* Allocate memory */ void M4_Make_Complete(int n_h, int n_o, m4 *m4mod) { @@ -379,8 +311,11 @@ void M4_Make_Complete(int n_h, int n_o, m4 *m4mod) m4mod->n_h = n_h; m4mod->n_o = n_o; + m4mod->n_o = n_o; + m4mod->o_rr = (phydbl *)mCalloc(n_o*n_o,sizeof(phydbl)); + m4mod->o_fq = (phydbl *)mCalloc(n_o,sizeof(phydbl)); m4mod->o_mats = (phydbl **)mCalloc(n_h,sizeof(phydbl *)); - For(i,n_h) m4mod->o_mats[i] = (phydbl *)mCalloc(n_o*n_o,sizeof(phydbl)); + for(i=0;io_mats[i] = (phydbl *)mCalloc(n_o*n_o,sizeof(phydbl)); m4mod->h_mat = (phydbl *)mCalloc(n_h*n_h,sizeof(phydbl)); m4mod->h_rr = (phydbl *)mCalloc(n_h*n_h,sizeof(phydbl)); m4mod->h_fq = (phydbl *)mCalloc(n_h,sizeof(phydbl)); @@ -389,57 +324,11 @@ void M4_Make_Complete(int n_h, int n_o, m4 *m4mod) m4mod->h_fq_unscaled = (phydbl *)mCalloc(n_h,sizeof(phydbl)); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/* Free memory */ -void M4_Free_M4_Model(m4 *m4mod) -{ - int i; - - For(i,m4mod->n_h) Free(m4mod->o_mats[i]); - Free(m4mod->o_mats); - Free(m4mod->h_mat); - Free(m4mod->o_rr); - Free(m4mod->h_rr); - Free(m4mod->o_fq); - Free(m4mod->h_fq); - Free(m4mod->multipl); - Free(m4mod->multipl_unscaled); - Free(m4mod->h_fq_unscaled); - Free(m4mod); -} - -/*********************************************************/ - -void M4_Init_Model(m4 *m4mod, allseq *data, model *mod) -{ - int i; - phydbl fq; - - - m4mod->n_o = (mod->datatype == NT)?(4):(20); - mod->ns = m4mod->n_o * m4mod->n_h; - For(i,m4mod->n_o) m4mod->o_fq[i] = data->b_frq[i]; - For(i,(int)(m4mod->n_h)) m4mod->multipl[i] = 1.; - For(i,(int)(m4mod->n_o*(m4mod->n_o-1)/2)) m4mod->o_rr[i] = 1.; - For(i,(int)(m4mod->n_h*(m4mod->n_h-1)/2)) m4mod->h_rr[i] = 1.; - fq = (phydbl)(1./m4mod->n_h); - - if(mod->s_opt->opt_cov_delta) m4mod->delta = 1.0; - if(mod->s_opt->opt_cov_alpha) m4mod->alpha = 1.0; - For(i,m4mod->n_h) m4mod->h_fq[i] = fq; - For(i,m4mod->n_h) m4mod->h_fq_unscaled[i] = 1.0; - For(i,m4mod->n_h) m4mod->multipl[i] = i; - For(i,m4mod->n_h) m4mod->multipl_unscaled[i] = i; - - mod->update_eigen = 1; - M4_Update_Qmat(m4mod,mod); -} - -/*********************************************************/ - -/* Fill the (big) rate matrix of the M4 model */ -void M4_Update_Qmat(m4 *m4mod, model *mod) +/* Fill in the (big) rate matrix of the M4 t_mod */ +void M4_Update_Qmat(m4 *m4mod, t_mod *mod) { int i,j; int n_s, n_o, n_h; @@ -453,110 +342,133 @@ void M4_Update_Qmat(m4 *m4mod, model *mod) n_o = m4mod->n_o; n_h = m4mod->n_h; - /* Set the relative substitution rates */ if(mod->m4mod->use_cov_alpha) { - DiscreteGamma(m4mod->h_fq,m4mod->multipl,m4mod->alpha,m4mod->alpha,m4mod->n_h,1); + DiscreteGamma(m4mod->h_fq,m4mod->multipl,m4mod->alpha,m4mod->alpha,m4mod->n_h,mod->ras->gamma_median); } else if(mod->m4mod->use_cov_free) { sum = .0; - For(i,mod->m4mod->n_h) sum += fabs(mod->m4mod->h_fq_unscaled[i]); - For(i,mod->m4mod->n_h) mod->m4mod->h_fq[i] = fabs(mod->m4mod->h_fq_unscaled[i])/sum; + for(i=0;im4mod->n_h;i++) sum += FABS(mod->m4mod->h_fq_unscaled[i]); + for(i=0;im4mod->n_h;i++) mod->m4mod->h_fq[i] = FABS(mod->m4mod->h_fq_unscaled[i])/sum; do { sum = .0; - For(i,mod->m4mod->n_h) + for(i=0;im4mod->n_h;i++) { if(mod->m4mod->h_fq[i] < 0.01) mod->m4mod->h_fq[i]=0.01; if(mod->m4mod->h_fq[i] > 0.99) mod->m4mod->h_fq[i]=0.99; sum += mod->m4mod->h_fq[i]; } - For(i,mod->m4mod->n_h) mod->m4mod->h_fq[i]/=sum; + + for(i=0;im4mod->n_h;i++) mod->m4mod->h_fq[i]/=sum; } while((sum > 1.01) || (sum < 0.99)); - /* Make sure the multipliers are centered around 1.0 */ + /* Make sure the multipliers are centered on 1.0 */ sum = .0; - For(i,mod->m4mod->n_h) sum += fabs(mod->m4mod->multipl_unscaled[i]) * mod->m4mod->h_fq[i]; - For(i,mod->m4mod->n_h) mod->m4mod->multipl[i] = mod->m4mod->multipl_unscaled[i] / sum; + for(i=0;im4mod->n_h;i++) sum += FABS(mod->m4mod->multipl_unscaled[i]) * mod->m4mod->h_fq[i]; + for(i=0;im4mod->n_h;i++) mod->m4mod->multipl[i] = mod->m4mod->multipl_unscaled[i] / sum; + /* printf("\n. WARNING\n"); */ + /* mod->m4mod->h_fq[0] = 1./3; */ + /* mod->m4mod->h_fq[1] = 1./3; */ + /* mod->m4mod->h_fq[2] = 1./3; */ -/* mod->m4mod->h_fq[0] = 0.33; */ -/* mod->m4mod->h_fq[1] = 0.33; */ -/* mod->m4mod->h_fq[2] = 0.33; */ - -/* mod->m4mod->multipl[0] = 0.1; */ -/* mod->m4mod->multipl[1] = 1.0; */ -/* mod->m4mod->multipl[2] = 10.0; */ - + /* mod->m4mod->multipl[0] = 1.0; */ + /* mod->m4mod->multipl[1] = 1.0; */ + /* mod->m4mod->multipl[2] = 1.0; */ sum = 0; - For(i,mod->m4mod->n_h) sum += mod->m4mod->multipl[i] * mod->m4mod->h_fq[i]; + for(i=0;im4mod->n_h;i++) sum += mod->m4mod->multipl[i] * mod->m4mod->h_fq[i]; if(sum < 0.99 || sum > 1.01) { - printf("\n. sum = %f",sum); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Printf("\n. sum = %f",sum); + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); Warn_And_Exit("\n"); } -/* printf("\n__ "); */ -/* For(i,mod->m4mod->n_h) printf("\n.%f %f %f", */ -/* mod->m4mod->h_fq[i], */ -/* mod->m4mod->h_fq_unscaled[i], */ -/* mod->m4mod->multipl[i]); */ + /* PhyML_Printf("\n__ "); */ + /* for(i=0;im4mod->n_h;i++) PhyML_Printf("\n.%f %f %f", */ + /* mod->m4mod->h_fq[i], */ + /* mod->m4mod->h_fq_unscaled[i], */ + /* mod->m4mod->multipl[i]); */ } -/* printf("\n."); */ -/* printf("\n. M4 model parameters"); */ -/* printf("\n. Delta = %f",m4mod->delta); */ -/* For(i,mod->m4mod->n_h) printf("\n. multipl %d = %f",i,m4mod->multipl[i]); */ -/* For(i,mod->m4mod->n_h) printf("\n. fq %d = %f",i,m4mod->h_fq[i]); */ + /* PhyML_Printf("\n."); */ + /* PhyML_Printf("\n. M4 model parameters"); */ + /* m4mod->delta=.0; */ + /* PhyML_Printf("\n. Delta = %f",m4mod->delta); */ + /* for(i=0;im4mod->n_h;i++) PhyML_Printf("\n. multipl %d = %f",i,m4mod->multipl[i]); */ + /* for(i=0;im4mod->n_h;i++) PhyML_Printf("\n. fq %d = %f",i,m4mod->h_fq[i]); */ /* Set up the stationary frequency vector */ - For(i,n_s) mod->pi[i] = m4mod->o_fq[i%n_o] * m4mod->h_fq[i/n_o]; + for(i=0;ie_frq->pi->v[i] = m4mod->o_fq[i%n_o] * m4mod->h_fq[i/n_o]; - /* Fill the matrices of nucleotide substitution rates here */ + + if(mod->whichmodel != CUSTOM && + mod->whichmodel != GTR && + mod->io->datatype == NT) + { + phydbl kappa1,kappa2; + + if((mod->whichmodel != F84) && (mod->whichmodel != TN93)) mod->lambda->v = 1.; + else if(mod->whichmodel == F84) + { + mod->lambda->v = Get_Lambda_F84(mod->e_frq->pi->v,&(mod->kappa->v)); + } + + kappa2 = mod->kappa->v*2./(1.+mod->lambda->v); + kappa1 = kappa2 * mod->lambda->v; + + /* A <-> C */ m4mod->o_rr[0] = 1.0; + /* A <-> G */ m4mod->o_rr[1] = kappa2; + /* A <-> T */ m4mod->o_rr[2] = 1.0; + /* C <-> G */ m4mod->o_rr[3] = 1.0; + /* C <-> T */ m4mod->o_rr[4] = kappa1; + } + + /* Fill in the matrices of nucleotide or amino-acid substitution rates here */ Update_Qmat_Generic(m4mod->o_rr, m4mod->o_fq, m4mod->n_o, m4mod->o_mats[0]); - /* Multiply each of these matrix by a relative substitution rate */ + /* Print_Square_Matrix_Generic(n_o,m4mod->o_mats[0]); */ + + /* Multiply each of these matrices by a relative substitution rate */ for(i=1;in_h;i++) For(j,n_o*n_o) m4mod->o_mats[i][j] = m4mod->o_mats[0][j]*m4mod->multipl[i]; For(j,n_o*n_o) m4mod->o_mats[0][j] *= m4mod->multipl[0]; - For(i,n_s*n_s) mod->qmat[i] = .0; + For(i,n_s*n_s) mod->r_mat->qmat->v[i] = .0; /* Diagonal blocks (i.e, nucleotide substitutions), symmetric */ - For(i,n_s) + for(i=0;iqmat[i*n_s+j] = m4mod->o_mats[(int)(i/n_o)][(i%n_o)*n_o+j%n_o]; - mod->qmat[j*n_s+i] = mod->qmat[i*n_s+j] * m4mod->o_fq[i%n_o] / m4mod->o_fq[j%n_o]; + mod->r_mat->qmat->v[i*n_s+j] = m4mod->o_mats[(int)(i/n_o)][(i%n_o)*n_o+j%n_o]; + mod->r_mat->qmat->v[j*n_s+i] = mod->r_mat->qmat->v[i*n_s+j] * m4mod->o_fq[i%n_o] / m4mod->o_fq[j%n_o]; } } } - /* Note: nucleotide equilibrium frequencies are already built in the o_mats matrices. - No need to 'add' these frequencies later on. */ - - /* Work out scaling factor */ + /* Work out scaling factor such that the expected number of observed state substitution + along a branch of length 1 is 1.*/ mr = .0; - For(i,n_s) + for(i=0;iqmat[i*n_s+j]; + for(j=0;jr_mat->qmat->v[i*n_s+j]; mr += sum * m4mod->o_fq[i%n_o] * m4mod->h_fq[(int)(i/n_o)]; } /* Scale the diagonal blocks */ - For(i,n_s*n_s) mod->qmat[i] /= mr; + For(i,n_s*n_s) mod->r_mat->qmat->v[i] /= mr; /* We are done with the diagonal blocks. Let's fill the non-diagonal ones now. */ @@ -569,7 +481,7 @@ void M4_Update_Qmat(m4 *m4mod, model *mod) For(i,n_h*n_h) m4mod->h_mat[i] *= m4mod->delta; /* Fill the non diagonal blocks */ - For(i,n_s) + for(i=0;iqmat[i*n_s+j] = m4mod->h_mat[(int)(i/n_o)*n_h+(int)(j/n_o)]; - mod->qmat[j*n_s+i] = mod->qmat[i*n_s+j] * m4mod->h_fq[(int)(i/n_o)] / m4mod->h_fq[(int)(j/n_o)]; + mod->r_mat->qmat->v[i*n_s+j] = m4mod->h_mat[(int)(i/n_o)*n_h+(int)(j/n_o)]; + mod->r_mat->qmat->v[j*n_s+i] = mod->r_mat->qmat->v[i*n_s+j] * m4mod->h_fq[(int)(i/n_o)] / m4mod->h_fq[(int)(j/n_o)]; } } } @@ -589,263 +501,303 @@ void M4_Update_Qmat(m4 *m4mod, model *mod) /* We are done with the non diagonal blocks */ + /* Diagonal cells */ - For(i,n_s) + for(i=0;iqmat[i*n_s+j]; + sum += mod->r_mat->qmat->v[i*n_s+j]; } - mod->qmat[i*n_s+i] = -sum; + mod->r_mat->qmat->v[i*n_s+i] = -sum; } - /* Print_Square_Matrix_Generic(n_s,mod->qmat); */ - For(i,n_s*n_s) mod->eigen->q[i] = mod->qmat[i]; + For(i,n_s*n_s) mod->eigen->q[i] = mod->r_mat->qmat->v[i]; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void M4_Init_P_Lk_Tips_Double(arbre *tree) + +void M4_Init_Partial_Lk_Tips_Double(t_tree *tree) { - int curr_site,i,j,k,l; + int curr_site,i,j,k,l,dim1,dim2,dim3; - Fors(curr_site,tree->data->crunch_len,tree->mod->stepsize) + dim1 = tree->mod->ras->n_catg * tree->mod->m4mod->n_h * tree->mod->m4mod->n_o; + dim2 = tree->mod->m4mod->n_h * tree->mod->m4mod->n_o; + dim3 = tree->mod->m4mod->n_o; + + + Fors(curr_site,tree->data->crunch_len,tree->mod->io->state_len) { - For(i,tree->n_otu) + for(i=0;in_otu;i++) { for(j=1;jmod->m4mod->n_h;j++) { - For(k,tree->mod->m4mod->n_o) - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][j*tree->mod->m4mod->n_o+k] = - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][k]; - - For(k,tree->mod->m4mod->n_o) - for(l=1;lmod->n_catg;l++) - tree->noeud[i]->b[0]->p_lk_rght[curr_site][l][j*tree->mod->m4mod->n_o+k] = - tree->noeud[i]->b[0]->p_lk_rght[curr_site][0][j*tree->mod->m4mod->n_o+k]; + for(k=0;kmod->m4mod->n_o;k++) + { + tree->a_nodes[i]->b[0]->p_lk_rght[curr_site*dim1 + 0*dim2 + j*dim3+k] = + tree->a_nodes[i]->b[0]->p_lk_rght[curr_site*dim1 + 0*dim2 + 0*dim3+k]; + + printf("\n() i=%d plk=%f", + curr_site*dim1 + 0*dim2 + j*dim3+k, + tree->a_nodes[i]->b[0]->p_lk_rght[curr_site*dim1 + 0*dim2 + j*dim3+k]); + + /* tree->a_nodes[i]->b[0]->p_lk_rght[curr_site][0][j*tree->mod->m4mod->n_o+k] = */ + /* tree->a_nodes[i]->b[0]->p_lk_rght[curr_site][0][k]; */ + } + + + for(k=0;kmod->m4mod->n_o;k++) + for(l=1;lmod->ras->n_catg;l++) + tree->a_nodes[i]->b[0]->p_lk_rght[curr_site*dim1 + l*dim2 + j*dim3+k] = + tree->a_nodes[i]->b[0]->p_lk_rght[curr_site*dim1 + 0*dim2 + j*dim3+k]; + /* tree->a_nodes[i]->b[0]->p_lk_rght[curr_site][l][j*tree->mod->m4mod->n_o+k] = */ + /* tree->a_nodes[i]->b[0]->p_lk_rght[curr_site][0][j*tree->mod->m4mod->n_o+k]; */ } } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void M4_Init_P_Lk_Tips_Int(arbre *tree) +void M4_Init_Partial_Lk_Tips_Int(t_tree *tree) { - int curr_site,i,j,k; + int curr_site,i,j,k,dim2,dim3; - Fors(curr_site,tree->data->crunch_len,tree->mod->stepsize) + dim2 = tree->mod->m4mod->n_h * tree->mod->m4mod->n_o; + dim3 = tree->mod->m4mod->n_o; + + Fors(curr_site,tree->data->crunch_len,tree->mod->io->state_len) { - For(i,tree->n_otu) + for(i=0;in_otu;i++) { for(j=1;jmod->m4mod->n_h;j++) { - For(k,tree->mod->m4mod->n_o) - tree->noeud[i]->b[0]->p_lk_tip_r[curr_site][j*tree->mod->m4mod->n_o+k] = - tree->noeud[i]->b[0]->p_lk_tip_r[curr_site][k]; + for(k=0;kmod->m4mod->n_o;k++) + { + tree->a_nodes[i]->b[0]->p_lk_tip_r[curr_site*dim2 + j*dim3+k] = + tree->a_nodes[i]->b[0]->p_lk_tip_r[curr_site*dim2 + 0*dim3+k]; + /* tree->a_nodes[i]->b[0]->p_lk_tip_r[curr_site][j*tree->mod->m4mod->n_o+k] = */ + /* tree->a_nodes[i]->b[0]->p_lk_tip_r[curr_site][k]; */ + } } } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl ****M4_Integral_Term_On_One_Edge(edge *b, arbre *tree) + +phydbl ****M4_Integral_Term_On_One_Edge(t_edge *b, t_tree *tree) { - phydbl ****integral,***P1,***P2; + phydbl ****integral,*P1,*P2; int ns; int g,i,j,k,l; int step; + ns = tree->mod->ns; - P1 = (phydbl ***)mCalloc(tree->mod->n_catg,sizeof(phydbl **)); - For(g,tree->mod->n_catg) - { - P1[g] = (phydbl **)mCalloc(ns,sizeof(phydbl *)); - For(j,ns) P1[g][j] = (phydbl *)mCalloc(ns,sizeof(phydbl)); - } - P2 = (phydbl ***)mCalloc(tree->mod->n_catg,sizeof(phydbl **)); - For(g,tree->mod->n_catg) - { - P2[g] = (phydbl **)mCalloc(ns,sizeof(phydbl *)); - For(j,ns) P2[g][j] = (phydbl *)mCalloc(ns,sizeof(phydbl)); - } + P1 = (phydbl *)mCalloc(tree->mod->ras->n_catg*ns*ns,sizeof(phydbl)); + P2 = (phydbl *)mCalloc(tree->mod->ras->n_catg*ns*ns,sizeof(phydbl)); - integral = (phydbl ****)mCalloc(tree->mod->n_catg,sizeof(phydbl ***)); - For(g,tree->mod->n_catg) + integral = (phydbl ****)mCalloc(tree->mod->ras->n_catg,sizeof(phydbl ***)); + for(g=0;gmod->ras->n_catg;g++) { integral[g] = (phydbl ***)mCalloc(ns,sizeof(phydbl **)); - For(j,ns) + for(j=0;jmod->n_catg) + for(g=0;gmod->ras->n_catg;g++) { - PMat(((phydbl)(i+0.5)/step)*b->l*tree->mod->gamma_rr[g],tree->mod,P1+g); - PMat(((phydbl)(step-i-0.5)/step)*b->l*tree->mod->gamma_rr[g],tree->mod,P2+g); + PMat(((phydbl)(i+0.5)/step)*b->l->v*tree->mod->ras->gamma_rr->v[g],tree->mod,g*ns*ns,P1,NULL); + PMat(((phydbl)(step-i-0.5)/step)*b->l->v*tree->mod->ras->gamma_rr->v[g],tree->mod,g*ns*ns,P2,NULL); - For(j,ns) + for(j=0;jmod->n_catg) - { - For(i,ns) Free(P1[g][i]); - Free(P1[g]); - } Free(P1); - - For(g,tree->mod->n_catg) - { - For(i,ns) Free(P2[g][i]); - Free(P2[g]); - } Free(P2); return integral; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void M4_Post_Prob_H_Class_Edge_Site(edge *b, phydbl ****integral, phydbl *postprob, arbre *tree) + +void M4_Post_Prob_H_Class_Edge_Site(t_edge *b, phydbl ****integral, phydbl *postprob, t_tree *tree) { /* Calculation of the expected frequencies of each hidden class at a given site. */ phydbl site_lk; int g,i,j,k,l; - int ns,n_h; + int n_h; phydbl sum; + int dim1,dim2; + + dim1 = tree->mod->ras->n_catg * tree->mod->ns; + dim2 = tree->mod->ns; - ns = tree->mod->ns; n_h = tree->mod->m4mod->n_h; /* number of classes, i.e., number of hidden states */ - site_lk = (phydbl)exp(tree->site_lk[tree->curr_site]); + site_lk = (phydbl)exp(tree->cur_site_lk[tree->curr_site]); if(b->rght->tax) { sum = .0; - For(i,n_h) + for(i=0;imod->m4mod->n_o) + for(j=0;jmod->m4mod->n_o;j++) { - For(g,tree->mod->n_catg) + for(g=0;gmod->ras->n_catg;g++) { - For(k,tree->mod->ns) + for(k=0;kmod->ns;k++) { - For(l,tree->mod->ns) + for(l=0;lmod->ns;l++) { postprob[i] += + (1./site_lk) * - tree->mod->gamma_r_proba[g] * + tree->mod->ras->gamma_r_proba->v[g] * tree->mod->m4mod->h_fq[i] * tree->mod->m4mod->o_fq[j] * - b->p_lk_left[tree->curr_site][g][k] * - b->p_lk_tip_r[tree->curr_site][l] * - /* b->p_lk_rght[tree->curr_site][0][l] * */ + b->p_lk_left[tree->curr_site*dim1 + g*dim2 + k] * + b->p_lk_tip_r[tree->curr_site*dim2 + l] * integral[g][i*tree->mod->m4mod->n_o+j][k][l]; + + /* (1./site_lk) * */ + /* tree->mod->ras->gamma_r_proba[g] * */ + /* tree->mod->m4mod->h_fq[i] * */ + /* tree->mod->m4mod->o_fq[j] * */ + /* b->p_lk_left[tree->curr_site][g][k] * */ + /* b->p_lk_tip_r[tree->curr_site][l] * */ + /* /\* b->p_lk_rght[tree->curr_site][0][l] * *\/ */ + /* integral[g][i*tree->mod->m4mod->n_o+j][k][l]; */ } } } } sum += postprob[i]; } - For(i,n_h) postprob[i] *= exp(b->sum_scale_f_left[tree->curr_site]); + + /* TO DO */ + for(i=0;isum_scale_left[tree->curr_site]); + } else { sum = .0; - For(i,n_h) + for(i=0;imod->m4mod->n_o) + for(j=0;jmod->m4mod->n_o;j++) { - For(g,tree->mod->n_catg) + for(g=0;gmod->ras->n_catg;g++) { - For(k,tree->mod->ns) + for(k=0;kmod->ns;k++) { - For(l,tree->mod->ns) + for(l=0;lmod->ns;l++) { postprob[i] += + (1./site_lk) * - tree->mod->gamma_r_proba[g] * + tree->mod->ras->gamma_r_proba->v[g] * tree->mod->m4mod->h_fq[i] * tree->mod->m4mod->o_fq[j] * - b->p_lk_left[tree->curr_site][g][k] * - b->p_lk_rght[tree->curr_site][g][l] * + b->p_lk_left[tree->curr_site*dim1 + g*dim2 + k] * + b->p_lk_rght[tree->curr_site*dim1 + g*dim2 + l] * integral[g][i*tree->mod->m4mod->n_o+j][k][l]; + + /* (1./site_lk) * */ + /* tree->mod->ras->gamma_r_proba[g] * */ + /* tree->mod->m4mod->h_fq[i] * */ + /* tree->mod->m4mod->o_fq[j] * */ + /* b->p_lk_left[tree->curr_site][g][k] * */ + /* b->p_lk_rght[tree->curr_site][g][l] * */ + /* integral[g][i*tree->mod->m4mod->n_o+j][k][l]; */ } } } } sum += postprob[i]; } - For(i,n_h) postprob[i] *= exp(b->sum_scale_f_left[tree->curr_site] + b->sum_scale_f_rght[tree->curr_site]); + + /* TO DO */ + for(i=0;isum_scale_left[tree->curr_site] + b->sum_scale_rght[tree->curr_site]); + } - For(i,n_h) + for(i=0;i 1.0+1.E-5)) { - printf("\n. Cat : %d Prob : %f\n",i,postprob[i]); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Printf("\n. Cat : %d Prob : %f\n",i,postprob[i]); + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); Warn_And_Exit("\n"); } sum = 0.0; - For(i,n_h) sum += postprob[i]; + for(i=0;i 1.0+1.E-2) || (sum < 1.0-1.E-2)) { - printf("\n. Sum = %f\n",sum); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Printf("\n. Sum = %f\n",sum); + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); Exit("\n"); } return; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl ***M4_Compute_Proba_Hidden_States_On_Edges(arbre *tree) +phydbl ***M4_Compute_Proba_Hidden_States_On_Edges(t_tree *tree) { int i; - phydbl ***post_probs, *dwell; + phydbl ***post_probs; phydbl ****integral; - dwell = (phydbl *)mCalloc(tree->mod->m4mod->n_h,sizeof(phydbl)); post_probs = (phydbl ***)mCalloc(2*tree->n_otu-3,sizeof(phydbl **)); For(i,2*tree->n_otu-3) { post_probs[i] = (phydbl **)mCalloc(tree->n_pattern,sizeof(phydbl *)); - For(tree->curr_site,tree->n_pattern) + for(tree->curr_site=0;tree->curr_siten_pattern;tree->curr_site++) post_probs[i][tree->curr_site] = (phydbl *)mCalloc(tree->mod->m4mod->n_h,sizeof(phydbl)); } @@ -855,12 +807,12 @@ phydbl ***M4_Compute_Proba_Hidden_States_On_Edges(arbre *tree) */ For(i,2*tree->n_otu-3) { - printf("\n. Edge %4d/%4d",i+1,2*tree->n_otu-3); + PhyML_Printf("\n. Edge %4d/%4d",i+1,2*tree->n_otu-3); - integral = M4_Integral_Term_On_One_Edge(tree->t_edges[i],tree); + integral = M4_Integral_Term_On_One_Edge(tree->a_edges[i],tree); - For(tree->curr_site,tree->n_pattern) - M4_Post_Prob_H_Class_Edge_Site(tree->t_edges[i], + for(tree->curr_site=0;tree->curr_siten_pattern;tree->curr_site++) + M4_Post_Prob_H_Class_Edge_Site(tree->a_edges[i], integral, post_probs[i][tree->curr_site], tree); @@ -870,7 +822,9 @@ phydbl ***M4_Compute_Proba_Hidden_States_On_Edges(arbre *tree) return post_probs; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /* Estimate the (posterior) mean relative rate of substitution on each branch at each site. The posterior mean rates averaged over sites is also estimated @@ -878,7 +832,7 @@ phydbl ***M4_Compute_Proba_Hidden_States_On_Edges(arbre *tree) is the tree with posterior mean rates averaged over the sites. The following trees have posterior mean rates computed for each site. */ -void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) +void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, t_tree *tree) { char *s; int i; @@ -901,7 +855,7 @@ void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) /* Compute the posterior mean relative rate on each branch averaged over the whole set of patterns (sites) */ len_var = 0; - For(patt,tree->n_pattern) + for(patt=0;pattn_pattern;patt++) { if(!Is_Invar(patt,1,NT,tree->data)) { @@ -909,7 +863,7 @@ void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) { max_prob = -1.; best_r = -1; - For(rcat,tree->mod->m4mod->n_h) + for(rcat=0;rcatmod->m4mod->n_h;rcat++) { if(post_probs[br][patt][rcat] > max_prob) { @@ -919,7 +873,7 @@ void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) } /* /\* Add weight on each category, weight is proportional to the corresponding posterior probability *\/ */ -/* For(rcat,tree->mod->m4mod->n_h) */ +/* for(rcat=0;rcatmod->m4mod->n_h;rcat++) */ /* { */ /* mean_post_probs[br][rcat] += post_probs[br][patt][rcat] * tree->data->wght[patt]; */ /* } */ @@ -933,7 +887,7 @@ void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) For(br,2*tree->n_otu-3) { - For(rcat,tree->mod->m4mod->n_h) + for(rcat=0;rcatmod->m4mod->n_h;rcat++) { mean_post_probs[br][rcat] /= (phydbl)len_var; } @@ -943,58 +897,58 @@ void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) each branch length using this factor */ For(br,2*tree->n_otu-3) { - For(rcat,tree->mod->m4mod->n_h) + for(rcat=0;rcatmod->m4mod->n_h;rcat++) { mrr[br] += mean_post_probs[br][rcat] * tree->mod->m4mod->multipl[rcat]; } - tree->t_edges[br]->l *= mrr[br]; + tree->a_edges[br]->l->v *= mrr[br]; } - fprintf(tree->io->fp_out_stats,"\n. Mean posterior probabilities & rates\n"); - For(rcat,tree->mod->m4mod->n_h) fprintf(tree->io->fp_out_stats,"%2.4f ",tree->mod->m4mod->multipl[rcat]); - fprintf(tree->io->fp_out_stats,"\n"); + PhyML_Fprintf(tree->io->fp_out_stats,"\n. Mean posterior probabilities & rates\n"); + for(rcat=0;rcatmod->m4mod->n_h;rcat++) PhyML_Fprintf(tree->io->fp_out_stats,"%2.4f ",tree->mod->m4mod->multipl[rcat]); + PhyML_Fprintf(tree->io->fp_out_stats,"\n"); For(br,2*tree->n_otu-3) { - For(rcat,tree->mod->m4mod->n_h) + for(rcat=0;rcatmod->m4mod->n_h;rcat++) { - fprintf(tree->io->fp_out_stats,"%2.4f ",mean_post_probs[br][rcat]); + PhyML_Fprintf(tree->io->fp_out_stats,"%2.4f ",mean_post_probs[br][rcat]); } -/* fprintf(tree->io->fp_out_stats," -- %f -> %f x %f = %f",mrr[br],tree->t_edges[br]->l,mrr[br],tree->t_edges[br]->l*mrr[br]); */ +/* PhyML_Fprintf(tree->io->fp_out_stats," -- %f -> %f x %f = %f",mrr[br],tree->a_edges[br]->l->v,mrr[br],tree->a_edges[br]->l->v*mrr[br]); */ - fprintf(tree->io->fp_out_stats," mrr=%f ",mrr[br]); + PhyML_Fprintf(tree->io->fp_out_stats," mrr=%f ",mrr[br]); - if(mrr[br] > 1.) fprintf(tree->io->fp_out_stats,"FAST "); - else fprintf(tree->io->fp_out_stats,"SLOW "); + if(mrr[br] > 1.) PhyML_Fprintf(tree->io->fp_out_stats,"FAST "); + else PhyML_Fprintf(tree->io->fp_out_stats,"SLOW "); - fprintf(tree->io->fp_out_stats,"%s",tree->t_edges[br]->labels[0]); + PhyML_Fprintf(tree->io->fp_out_stats,"%s",tree->a_edges[br]->labels[0]); - fprintf(tree->io->fp_out_stats,"\n"); + PhyML_Fprintf(tree->io->fp_out_stats,"\n"); } /* Print the tree */ - fprintf(tree->io->fp_out_tree,"Constrained tree with corrected branch lengths = "); + PhyML_Fprintf(tree->io->fp_out_tree,"Constrained tree with corrected branch lengths = "); s = Write_Tree(tree); - fprintf(tree->io->fp_out_tree,"%s\n",s); + PhyML_Fprintf(tree->io->fp_out_tree,"%s\n",s); Free(s); tree->ps_tree = DR_Make_Tdraw_Struct(tree); DR_Print_Postscript_Header(tree->n_pattern,tree->io->fp_out_ps); tree->ps_page_number = 0; - DR_Print_Tree_Postscript(tree->ps_page_number++,tree->io->fp_out_ps,tree); + DR_Print_Tree_Postscript(tree->ps_page_number++,YES,tree->io->fp_out_ps,tree); /* Go back to the initial scaled branch lengths */ - For(br,2*tree->n_otu-3) tree->t_edges[br]->l /= mrr[br]; + For(br,2*tree->n_otu-3) tree->a_edges[br]->l->v /= mrr[br]; /* Compute the posterior mean relative rate at each site, for each branch and each rate category. Scale branch lengths using these factors and print each tree (i.e., on tree per site pattern) */ - For(patt,tree->n_pattern) + for(patt=0;pattn_pattern;patt++) { For(br,2*tree->n_otu-3) { mrr[br] = .0; max_prob = -1.; best_r = -1; - For(rcat,tree->mod->m4mod->n_h) /* For each rate class */ + for(rcat=0;rcatmod->m4mod->n_h;rcat++) /* For each rate class */ { mrr[br] += post_probs[br][patt][rcat] * tree->mod->m4mod->multipl[rcat]; if(post_probs[br][patt][rcat] > max_prob) @@ -1004,24 +958,24 @@ void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) } } /* mrr[br] = tree->mod->m4mod->multipl[best_r]; /\* Use the most probable relative rate instead of mean *\/ */ - tree->t_edges[br]->l *= mrr[br]; + tree->a_edges[br]->l->v *= mrr[br]; } - For(br,2*tree->n_otu-3) mean_br_len[br] += tree->t_edges[br]->l * tree->data->wght[patt]; + For(br,2*tree->n_otu-3) mean_br_len[br] += tree->a_edges[br]->l->v * tree->data->wght[patt]; - fprintf(tree->io->fp_out_stats,"\n. Posterior probabilities site %4d (weight=%d, is_inv=%d)\n", + PhyML_Fprintf(tree->io->fp_out_stats,"\n. Posterior probabilities site %4d (weight=%d, is_inv=%d)\n", patt, tree->data->wght[patt], Is_Invar(patt,1,NT,tree->data)); - For(rcat,tree->mod->m4mod->n_h) fprintf(tree->io->fp_out_stats,"%2.4f ",tree->mod->m4mod->multipl[rcat]); - fprintf(tree->io->fp_out_stats,"\n"); + for(rcat=0;rcatmod->m4mod->n_h;rcat++) PhyML_Fprintf(tree->io->fp_out_stats,"%2.4f ",tree->mod->m4mod->multipl[rcat]); + PhyML_Fprintf(tree->io->fp_out_stats,"\n"); For(br,2*tree->n_otu-3) { - fprintf(tree->io->fp_out_stats,"Edge %3d ",br); + PhyML_Fprintf(tree->io->fp_out_stats,"Edge %3d ",br); max_prob = -1.0; best_r = -1; - For(rcat,tree->mod->m4mod->n_h) + for(rcat=0;rcatmod->m4mod->n_h;rcat++) { if(post_probs[br][patt][rcat] > max_prob) { @@ -1030,43 +984,43 @@ void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) } } - For(rcat,tree->mod->m4mod->n_h) + for(rcat=0;rcatmod->m4mod->n_h;rcat++) { - fprintf(tree->io->fp_out_stats,"%2.4f",post_probs[br][patt][rcat]); - if(rcat == best_r) fprintf(tree->io->fp_out_stats,"* "); - else fprintf(tree->io->fp_out_stats," "); + PhyML_Fprintf(tree->io->fp_out_stats,"%2.4f",post_probs[br][patt][rcat]); + if(rcat == best_r) PhyML_Fprintf(tree->io->fp_out_stats,"* "); + else PhyML_Fprintf(tree->io->fp_out_stats," "); } -/* fprintf(tree->io->fp_out_stats," -- %f -> %f x %f = %f",mrr[br],tree->t_edges[br]->l,mrr[br],tree->t_edges[br]->l*mrr[br]); */ +/* PhyML_Fprintf(tree->io->fp_out_stats," -- %f -> %f x %f = %f",mrr[br],tree->a_edges[br]->l->v,mrr[br],tree->a_edges[br]->l->v*mrr[br]); */ - if(mrr[br] > 1.01) fprintf(tree->io->fp_out_stats," %s ","FAST"); - else if(mrr[br] < 0.99) fprintf(tree->io->fp_out_stats," %s ","SLOW"); - else fprintf(tree->io->fp_out_stats," %s ","MEDIUM"); - fprintf(tree->io->fp_out_stats,"%s ",tree->t_edges[br]->labels[0]); - fprintf(tree->io->fp_out_stats,"\n"); + if(mrr[br] > 1.01) PhyML_Fprintf(tree->io->fp_out_stats," %s ","FAST"); + else if(mrr[br] < 0.99) PhyML_Fprintf(tree->io->fp_out_stats," %s ","SLOW"); + else PhyML_Fprintf(tree->io->fp_out_stats," %s ","MEDIUM"); + PhyML_Fprintf(tree->io->fp_out_stats,"%s ",tree->a_edges[br]->labels[0]); + PhyML_Fprintf(tree->io->fp_out_stats,"\n"); } - fprintf(tree->io->fp_out_tree,"tree %d = ",patt+1); + PhyML_Fprintf(tree->io->fp_out_tree,"tree %d = ",patt+1); s = Write_Tree(tree); - fprintf(tree->io->fp_out_tree,"%s\n",s); + PhyML_Fprintf(tree->io->fp_out_tree,"%s\n",s); Free(s); - DR_Print_Tree_Postscript(tree->ps_page_number++,tree->io->fp_out_ps,tree); + DR_Print_Tree_Postscript(tree->ps_page_number++,YES,tree->io->fp_out_ps,tree); /* Go back to the initial scaled branch lengths */ - For(br,2*tree->n_otu-3) tree->t_edges[br]->l /= mrr[br]; + For(br,2*tree->n_otu-3) tree->a_edges[br]->l->v /= mrr[br]; For(br,2*tree->n_otu-3) { sum = .0; - For(rcat,tree->mod->m4mod->n_h) + for(rcat=0;rcatmod->m4mod->n_h;rcat++) { sum += post_probs[br][patt][rcat]; } if((sum < 0.99) || (sum > 1.01)) { - fprintf(tree->io->fp_out_stats,"\n. sum = %f\n",sum); - fprintf(tree->io->fp_out_stats,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Fprintf(tree->io->fp_out_stats,"\n. sum = %f\n",sum); + PhyML_Fprintf(tree->io->fp_out_stats,"\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); Warn_And_Exit("\n"); } } @@ -1076,11 +1030,11 @@ void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) For(br,2*tree->n_otu-3) { mean_br_len[br] /= (phydbl)tree->data->init_len; - tree->t_edges[br]->l = mean_br_len[br]; + tree->a_edges[br]->l->v = mean_br_len[br]; } - fprintf(tree->io->fp_out_tree,"Mean branch lengths="); + PhyML_Fprintf(tree->io->fp_out_tree,"Mean branch lengths="); s = Write_Tree(tree); - fprintf(tree->io->fp_out_tree,"%s\n",s); + PhyML_Fprintf(tree->io->fp_out_tree,"%s\n",s); Free(s); /* DR_Print_Tree_Postscript(tree->ps_page_number++,tree->io->fp_out_ps,tree); */ @@ -1090,7 +1044,7 @@ void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) For(br,2*tree->n_otu-3) { - For(tree->curr_site,tree->n_pattern) + for(tree->curr_site=0;tree->curr_siten_pattern;tree->curr_site++) Free(post_probs[br][tree->curr_site]); Free(post_probs[br]); } @@ -1101,28 +1055,30 @@ void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree) Free(mean_br_len); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /* Classifiy each branch, at each site, among one of the rate classes */ -phydbl **M4_Site_Branch_Classification(phydbl ***post_probs, arbre *tree) +phydbl **M4_Site_Branch_Classification(phydbl ***post_probs, t_tree *tree) { int patt, br, rcat, i; phydbl **best_probs; phydbl post_prob_fast, post_prob_slow; best_probs = (phydbl **)mCalloc(tree->n_pattern,sizeof(phydbl *)); - For(i,tree->n_pattern) best_probs[i] = (phydbl *)mCalloc(2*tree->n_otu-3,sizeof(phydbl)); + for(i=0;in_pattern;i++) best_probs[i] = (phydbl *)mCalloc(2*tree->n_otu-3,sizeof(phydbl)); - tree->print_labels = 1; + tree->write_labels = YES; - For(patt,tree->n_pattern) + for(patt=0;pattn_pattern;patt++) { For(br,2*tree->n_otu-3) { post_prob_fast = .0; post_prob_slow = .0; - For(rcat,tree->mod->m4mod->n_h) /* For each rate class */ + for(rcat=0;rcatmod->m4mod->n_h;rcat++) /* For each rate class */ { if(tree->mod->m4mod->multipl[rcat] > 1.0) post_prob_fast += post_probs[br][patt][rcat]; @@ -1132,71 +1088,75 @@ phydbl **M4_Site_Branch_Classification(phydbl ***post_probs, arbre *tree) best_probs[patt][br] = (post_prob_fast > post_prob_slow)?(post_prob_fast):(post_prob_slow); - if(!(tree->t_edges[br]->n_labels%BLOCK_LABELS)) Make_New_Edge_Label(tree->t_edges[br]); + if(!(tree->a_edges[br]->n_labels%BLOCK_LABELS)) Make_New_Edge_Label(tree->a_edges[br]); /* if((post_prob_fast > post_prob_slow) && (best_probs[patt][br] > 0.95)) */ -/* strcpy(tree->t_edges[br]->labels[tree->t_edges[br]->n_labels],"FASTER"); */ +/* strcpy(tree->a_edges[br]->labels[tree->a_edges[br]->n_labels],"FASTER"); */ /* else if((post_prob_fast < post_prob_slow) && (best_probs[patt][br] > 0.95)) */ -/* strcpy(tree->t_edges[br]->labels[tree->t_edges[br]->n_labels],"SLOWER"); */ +/* strcpy(tree->a_edges[br]->labels[tree->a_edges[br]->n_labels],"SLOWER"); */ /* else */ -/* strcpy(tree->t_edges[br]->labels[tree->t_edges[br]->n_labels],"UNKNOWN"); */ +/* strcpy(tree->a_edges[br]->labels[tree->a_edges[br]->n_labels],"UNKNOWN"); */ if(post_prob_fast > post_prob_slow) - strcpy(tree->t_edges[br]->labels[tree->t_edges[br]->n_labels],"FASTER"); + strcpy(tree->a_edges[br]->labels[tree->a_edges[br]->n_labels],"FASTER"); else - strcpy(tree->t_edges[br]->labels[tree->t_edges[br]->n_labels],"SLOWER"); + strcpy(tree->a_edges[br]->labels[tree->a_edges[br]->n_labels],"SLOWER"); - tree->t_edges[br]->n_labels++; + tree->a_edges[br]->n_labels++; } } return best_probs; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void M4_Site_Branch_Classification_Experiment(arbre *tree) + +void M4_Site_Branch_Classification_Experiment(t_tree *tree) { - allseq *ori_data,*cpy_data; + calign *cpy_data; short int **true_rclass, **est_rclass; phydbl **best_probs; int i,j; phydbl correct_class, mis_class, unknown; - - + true_rclass = (short int **)mCalloc(tree->data->init_len, sizeof(short int *)); est_rclass = (short int **)mCalloc(tree->data->init_len, sizeof(short int *)); - For(i,tree->data->init_len) + for(i=0;idata->init_len;i++) { true_rclass[i] = (short int *)mCalloc(2*tree->n_otu-3,sizeof(short int)); est_rclass[i] = (short int *)mCalloc(2*tree->n_otu-3,sizeof(short int)); } - ori_data = tree->data; - - cpy_data = Copy_Cseq(tree->data, - tree->data->init_len, - (tree->mod->datatype == NT)?(4):(20)); + if(tree->io->datatype != NT && tree->io->datatype != AA) + { + PhyML_Printf("\n. Not implemented yet."); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + cpy_data = Copy_Cseq(tree->data,tree->io); /* Generate a simulated data set under H0, with the right sequence length. */ - printf("\n. Evolving sequences (delta=%f, alpha=%f) ...\n",tree->mod->m4mod->delta,tree->mod->m4mod->alpha); - Evolve(cpy_data,tree->mod,tree); + PhyML_Printf("\n. Evolving sequences (delta=%f, alpha=%f) ...\n",tree->mod->m4mod->delta,tree->mod->m4mod->alpha); + Evolve(cpy_data,tree->mod,0,tree); - For(i,cpy_data->init_len) + for(i=0;iinit_len;i++) { For(j,2*tree->n_otu-3) { - if(!strcmp(tree->t_edges[j]->labels[i],"FASTER")) + if(!strcmp(tree->a_edges[j]->labels[i],"FASTER")) { true_rclass[i][j] = 1; } - else if(!strcmp(tree->t_edges[j]->labels[i],"SLOWER")) + else if(!strcmp(tree->a_edges[j]->labels[i],"SLOWER")) { true_rclass[i][j] = 0; } else { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); Warn_And_Exit("\n"); } } @@ -1204,8 +1164,8 @@ void M4_Site_Branch_Classification_Experiment(arbre *tree) For(j,2*tree->n_otu-3) { - Free_Edge_Labels(tree->t_edges[j]); - tree->t_edges[j]->n_labels = 0; + Free_Edge_Labels(tree->a_edges[j]); + tree->a_edges[j]->n_labels = 0; } /* Generate the memory needed for likelihood calculation because @@ -1220,40 +1180,40 @@ void M4_Site_Branch_Classification_Experiment(arbre *tree) /* Allocate memory and initialize likelihood structure with simulated sequences (i.e., columns are not compressed) */ - Make_Tree_4_Pars(tree,cpy_data,cpy_data->init_len); - Make_Tree_4_Lk(tree,cpy_data,cpy_data->init_len); + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); /* Estimate model parameters */ - printf("\n. Estimating model parameters...\n"); + PhyML_Printf("\n. Estimating model parameters...\n"); tree->mod->s_opt->opt_cov_alpha = 1; tree->mod->s_opt->opt_cov_delta = 1; - Round_Optimize(tree,tree->data); + Round_Optimize(tree,ROUND_MAX); tree->both_sides = 1; - Lk(tree); + Lk(NULL,tree); /* Classify branches */ best_probs = M4_Site_Branch_Classification(M4_Compute_Proba_Hidden_States_On_Edges(tree),tree); - For(i,tree->data->init_len) + for(i=0;idata->init_len;i++) { For(j,2*tree->n_otu-3) { - if(!strcmp(tree->t_edges[j]->labels[i],"FASTER")) + if(!strcmp(tree->a_edges[j]->labels[i],"FASTER")) { est_rclass[i][j] = 1; } - else if(!strcmp(tree->t_edges[j]->labels[i],"SLOWER")) + else if(!strcmp(tree->a_edges[j]->labels[i],"SLOWER")) { est_rclass[i][j] = 0; } - else if(!strcmp(tree->t_edges[j]->labels[i],"UNKNOWN")) + else if(!strcmp(tree->a_edges[j]->labels[i],"UNKNOWN")) { est_rclass[i][j] = -1; } else { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); Warn_And_Exit("\n"); } } @@ -1262,11 +1222,11 @@ void M4_Site_Branch_Classification_Experiment(arbre *tree) unknown = .0; correct_class = .0; mis_class = .0; - For(i,tree->data->init_len) + for(i=0;idata->init_len;i++) { For(j,2*tree->n_otu-3) { -/* printf("\n. Edge %3d %4d %4d - %f",j,true_rclass[i][j],est_rclass[i][j],best_probs[i][j]); */ +/* PhyML_Printf("\n. Edge %3d %4d %4d - %f",j,true_rclass[i][j],est_rclass[i][j],best_probs[i][j]); */ if(est_rclass[i][j] == -1) { unknown += 1.; @@ -1281,24 +1241,24 @@ void M4_Site_Branch_Classification_Experiment(arbre *tree) } else { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); Warn_And_Exit("\n"); } } -/* printf("\n"); */ +/* PhyML_Printf("\n"); */ } correct_class /= ((tree->data->init_len * (2*tree->n_otu-3)) - unknown); mis_class /= ((tree->data->init_len * (2*tree->n_otu-3)) - unknown); unknown /= (tree->data->init_len * (2*tree->n_otu-3)); - printf("\n. correct_class = %f mis_class = %f unknown = %f", + PhyML_Printf("\n. correct_class = %f mis_class = %f unknown = %f", correct_class, mis_class, unknown); - For(i,tree->data->init_len) + for(i=0;idata->init_len;i++) { Free(true_rclass[i]); Free(est_rclass[i]); @@ -1310,21 +1270,23 @@ void M4_Site_Branch_Classification_Experiment(arbre *tree) } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /* Scale branch lengths such that they express expected number of nucleotide or amino-acid substitutions */ -void M4_Scale_Br_Len(arbre *tree) +void M4_Scale_Br_Len(t_tree *tree) { phydbl scale_fact,mrs; int i,j; /* (1) Work out the relative mean rate of switches */ mrs = .0; - For(i,tree->mod->m4mod->n_h) + for(i=0;imod->m4mod->n_h;i++) { - For(j,tree->mod->m4mod->n_h) + for(j=0;jmod->m4mod->n_h;j++) { if(j != i) mrs += tree->mod->m4mod->h_fq[i] * tree->mod->m4mod->h_mat[i*tree->mod->m4mod->n_h+j]; @@ -1335,20 +1297,22 @@ void M4_Scale_Br_Len(arbre *tree) scale_fact = 1.0 + tree->mod->m4mod->delta * mrs; /* (3) Scale branch lengths */ - For(i,2*tree->n_otu-3) tree->t_edges[i]->l /= scale_fact; + For(i,2*tree->n_otu-3) tree->a_edges[i]->l->v /= scale_fact; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void M4_Free_Integral_Term_On_One_Edge(phydbl ****integral, arbre *tree) +void M4_Free_Integral_Term_On_One_Edge(phydbl ****integral, t_tree *tree) { int g,i,j; - For(g,tree->mod->n_catg) + for(g=0;gmod->ras->n_catg;g++) { - For(i,tree->mod->m4mod->n_h) + for(i=0;imod->m4mod->n_h;i++) { - For(j,tree->mod->m4mod->n_h) + for(j=0;jmod->m4mod->n_h;j++) { Free(integral[g][i][j]); } @@ -1359,12 +1323,14 @@ void M4_Free_Integral_Term_On_One_Edge(phydbl ****integral, arbre *tree) Free(integral); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void M4_Detect_Site_Switches_Experiment(arbre *tree) + +void M4_Detect_Site_Switches_Experiment(t_tree *tree) { - model *nocov_mod,*cov_mod,*ori_mod; - allseq *ori_data,*cpy_data; + t_mod *nocov_mod,*cov_mod,*ori_mod; + calign *ori_data,*cpy_data; int i,n_iter; phydbl *nocov_bl,*cov_bl; phydbl *site_lnl_nocov, *site_lnl_cov; @@ -1376,33 +1342,39 @@ void M4_Detect_Site_Switches_Experiment(arbre *tree) ori_data = tree->data; ori_mod = tree->mod; - cpy_data = Copy_Cseq(tree->data, - tree->data->init_len, - (tree->mod->datatype == NT)?(4):(20)); - printf("\n. Estimate model parameters under non-switching substitution model.\n"); + if(tree->io->datatype != NT && tree->io->datatype != AA) + { + PhyML_Printf("\n== Not implemented yet."); + PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + cpy_data = Copy_Cseq(tree->data,tree->io); + + PhyML_Printf("\n. Estimate model parameters under non-switching substitution model.\n"); Switch_From_M4mod_To_Mod(tree->mod); Simu_Loop(tree); - nocov_mod = (model *)Copy_Model(tree->mod); /* Record model parameters */ - For(i,2*tree->n_otu-3) nocov_bl[i] = tree->t_edges[i]->l; /* Record branch lengths */ - For(i,tree->data->crunch_len) site_lnl_nocov[i] = tree->site_lk[i]; + nocov_mod = (t_mod *)Copy_Model(tree->mod); /* Record model parameters */ + For(i,2*tree->n_otu-3) nocov_bl[i] = tree->a_edges[i]->l->v; /* Record branch lengths */ + for(i=0;idata->crunch_len;i++) site_lnl_nocov[i] = tree->cur_site_lk[i]; Print_Lk(tree,"[LnL under non-switching substitution model]"); - printf("\n. Estimate model parameters under switching substitution model.\n"); + PhyML_Printf("\n. Estimate model parameters under switching substitution model.\n"); Switch_From_Mod_To_M4mod(tree->mod); Simu_Loop(tree); - cov_mod = (model *)Copy_Model(tree->mod); /* Record model parameters */ - For(i,2*tree->n_otu-3) cov_bl[i] = tree->t_edges[i]->l; /* Record branch lengths */ - For(i,tree->data->crunch_len) site_lnl_cov[i] = tree->site_lk[i]; + cov_mod = (t_mod *)Copy_Model(tree->mod); /* Record model parameters */ + For(i,2*tree->n_otu-3) cov_bl[i] = tree->a_edges[i]->l->v; /* Record branch lengths */ + for(i=0;idata->crunch_len;i++) site_lnl_cov[i] = tree->cur_site_lk[i]; Print_Lk(tree,"[LnL under switching substitution model]"); - printf("\n"); - For(i,tree->data->crunch_len) printf("TRUTH %f %f\n",site_lnl_nocov[i],site_lnl_cov[i]); + PhyML_Printf("\n"); + for(i=0;idata->crunch_len;i++) PhyML_Printf("TRUTH %f %f\n",site_lnl_nocov[i],site_lnl_cov[i]); /* Generate a simulated data set under H0, with the right sequence length. */ tree->mod = nocov_mod; - Evolve(cpy_data, nocov_mod, tree); + Evolve(cpy_data, nocov_mod, 0, tree); /* Generate the memory needed for likelihood calculation because we will need bigger arrays @@ -1418,8 +1390,8 @@ void M4_Detect_Site_Switches_Experiment(arbre *tree) /* Allocate memory and initialize likelihood structure with simulated sequences (i.e., columns are not compressed) */ - Make_Tree_4_Pars(tree,cpy_data,cpy_data->init_len); - Make_Tree_4_Lk(tree,cpy_data,cpy_data->init_len); + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); n_iter = 0; @@ -1427,30 +1399,30 @@ void M4_Detect_Site_Switches_Experiment(arbre *tree) { /* Get the transition proba right to generate sequences */ tree->mod = nocov_mod; - For(i,2*tree->n_otu-3) tree->t_edges[i]->l = nocov_bl[i]; - For(i,2*tree->n_otu-3) Update_PMat_At_Given_Edge(tree->t_edges[i],tree); + For(i,2*tree->n_otu-3) tree->a_edges[i]->l->v = nocov_bl[i]; + For(i,2*tree->n_otu-3) Update_PMat_At_Given_Edge(tree->a_edges[i],tree); /* Generate sequences */ - Evolve(cpy_data, nocov_mod, tree); + Evolve(cpy_data, nocov_mod, 0, tree); tree->data = cpy_data; - if(tree->mod->s_opt->greedy) Init_P_Lk_Tips_Double(tree); - else Init_P_Lk_Tips_Int(tree); + if(tree->mod->s_opt->greedy) Init_Partial_Lk_Tips_Double(tree); + else Init_Partial_Lk_Tips_Int(tree); tree->mod = nocov_mod; - For(i,2*tree->n_otu-3) tree->t_edges[i]->l = nocov_bl[i]; - Lk(tree); - For(i,tree->data->crunch_len) site_lnl_nocov[i] = tree->site_lk[i]; + For(i,2*tree->n_otu-3) tree->a_edges[i]->l->v = nocov_bl[i]; + Lk(NULL,tree); + for(i=0;idata->crunch_len;i++) site_lnl_nocov[i] = tree->cur_site_lk[i]; Print_Lk(tree,"[CPY LnL under non-switching substitution model]"); tree->mod = cov_mod; - For(i,2*tree->n_otu-3) tree->t_edges[i]->l = cov_bl[i]; - Lk(tree); - For(i,tree->data->crunch_len) site_lnl_cov[i] = tree->site_lk[i]; + For(i,2*tree->n_otu-3) tree->a_edges[i]->l->v = cov_bl[i]; + Lk(NULL,tree); + for(i=0;idata->crunch_len;i++) site_lnl_cov[i] = tree->cur_site_lk[i]; Print_Lk(tree,"[CPY LnL under switching substitution model]"); - printf("\n"); - For(i,tree->data->crunch_len) printf("SYNTH %f %f\n",site_lnl_nocov[i],site_lnl_cov[i]); + PhyML_Printf("\n"); + for(i=0;idata->crunch_len;i++) PhyML_Printf("SYNTH %f %f\n",site_lnl_nocov[i],site_lnl_cov[i]); } while(++n_iter < 200); @@ -1461,17 +1433,17 @@ void M4_Detect_Site_Switches_Experiment(arbre *tree) tree->data = ori_data; tree->n_pattern = tree->data->crunch_len; - Make_Tree_4_Pars(tree,ori_data,ori_data->init_len); - Make_Tree_4_Lk(tree,ori_data,ori_data->init_len); + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); tree->mod = nocov_mod; - For(i,2*tree->n_otu-3) tree->t_edges[i]->l = nocov_bl[i]; - Lk(tree); + For(i,2*tree->n_otu-3) tree->a_edges[i]->l->v = nocov_bl[i]; + Lk(NULL,tree); Print_Lk(tree,"[FINAL LnL under non-switching substitution model]"); tree->mod = cov_mod; - For(i,2*tree->n_otu-3) tree->t_edges[i]->l = cov_bl[i]; - Lk(tree); + For(i,2*tree->n_otu-3) tree->a_edges[i]->l->v = cov_bl[i]; + Lk(NULL,tree); Print_Lk(tree,"[FINAL LnL under switching substitution model]"); tree->mod = ori_mod; @@ -1481,29 +1453,32 @@ void M4_Detect_Site_Switches_Experiment(arbre *tree) Free(site_lnl_cov); Free(site_lnl_nocov); - Free_Cseq(cpy_data); + Free_Calign(cpy_data); Free(nocov_bl); Free(cov_bl); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void M4_Posterior_Prediction_Experiment(arbre *tree) +void M4_Posterior_Prediction_Experiment(t_tree *tree) { - model *ori_mod; - allseq *ori_data,*cpy_data; + calign *ori_data,*cpy_data; int i,n_iter,n_simul; FILE *fp_nocov,*fp_cov,*fp_obs; char *s; - edge *best_edge; + t_edge *best_edge; s = (char *)mCalloc(100,sizeof(char)); + + best_edge = NULL; - strcpy(s,tree->io->in_seq_file); + strcpy(s,tree->io->in_align_file); fp_nocov = Openfile(strcat(s,"_nocov"),1); - strcpy(s,tree->io->in_seq_file); + strcpy(s,tree->io->in_align_file); fp_cov = Openfile(strcat(s,"_cov"),1); - strcpy(s,tree->io->in_seq_file); + strcpy(s,tree->io->in_align_file); fp_obs = Openfile(strcat(s,"_obs"),1); Free(s); @@ -1513,16 +1488,20 @@ void M4_Posterior_Prediction_Experiment(arbre *tree) Print_Diversity_Header(fp_obs, tree); ori_data = tree->data; - ori_mod = tree->mod; - cpy_data = Copy_Cseq(tree->data, - tree->data->init_len, - (tree->mod->datatype == NT)?(4):(20)); + if(tree->io->datatype != NT && tree->io->datatype != AA) + { + PhyML_Printf("\n. Not implemented yet."); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + cpy_data = Copy_Cseq(tree->data,tree->io); /* Generate a simulated data set under H0, with the right sequence length. */ Set_Model_Parameters(tree->mod); - For(i,2*tree->n_otu-3) Update_PMat_At_Given_Edge(tree->t_edges[i],tree); - Evolve(cpy_data,tree->mod,tree); + For(i,2*tree->n_otu-3) Update_PMat_At_Given_Edge(tree->a_edges[i],tree); + Evolve(cpy_data,tree->mod,0,tree); /* Generate the memory needed for likelihood calculation because we will need bigger arrays @@ -1536,25 +1515,25 @@ void M4_Posterior_Prediction_Experiment(arbre *tree) /* Allocate memory and initialize likelihood structure with simulated sequences (i.e., columns are not compressed) */ - Make_Tree_4_Pars(tree,cpy_data,cpy_data->init_len); - Make_Tree_4_Lk(tree,cpy_data,cpy_data->init_len); + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); /* Go back to the original data set */ tree->data = ori_data; tree->n_pattern = ori_data->crunch_len; - if(tree->mod->s_opt->greedy) Init_P_Lk_Tips_Double(tree); - else Init_P_Lk_Tips_Int(tree); + if(tree->mod->s_opt->greedy) Init_Partial_Lk_Tips_Double(tree); + else Init_Partial_Lk_Tips_Int(tree); - printf("\n. Estimate model parameters under non-switching substitution model.\n"); + PhyML_Printf("\n. Estimate model parameters under non-switching substitution model.\n"); Switch_From_M4mod_To_Mod(tree->mod); tree->bl_from_node_stamps = 1; - best_edge = MC_Find_Best_Root_Position(tree); - printf("\n. Put root on edge %3d",i); - MC_Least_Square_Node_Times(best_edge,tree); - MC_Adjust_Node_Times(tree); - MC_Round_Optimize(tree); + /* best_edge = TIMES_Find_Best_Root_Position(tree); */ + PhyML_Printf("\n. Put root on t_edge %3d",i); + TIMES_Least_Square_Node_Times(best_edge,tree); + TIMES_Adjust_Node_Times(tree); + /* TIMES_Round_Optimize(tree); */ /* Round_Optimize(tree,tree->data); */ /* Simu_Loop(tree); */ @@ -1570,14 +1549,14 @@ void M4_Posterior_Prediction_Experiment(arbre *tree) n_iter = 0; do { - Evolve(cpy_data,tree->mod,tree); + Evolve(cpy_data,tree->mod,0,tree); tree->data = cpy_data; tree->n_pattern = cpy_data->init_len; - if(tree->mod->s_opt->greedy) Init_P_Lk_Tips_Double(tree); - else Init_P_Lk_Tips_Int(tree); + if(tree->mod->s_opt->greedy) Init_Partial_Lk_Tips_Double(tree); + else Init_Partial_Lk_Tips_Int(tree); - Lk(tree); + Lk(NULL,tree); Init_Ui_Tips(tree); Site_Diversity(tree); @@ -1591,12 +1570,12 @@ void M4_Posterior_Prediction_Experiment(arbre *tree) tree->data = ori_data; tree->n_pattern = ori_data->crunch_len; - if(tree->mod->s_opt->greedy) Init_P_Lk_Tips_Double(tree); - else Init_P_Lk_Tips_Int(tree); + if(tree->mod->s_opt->greedy) Init_Partial_Lk_Tips_Double(tree); + else Init_Partial_Lk_Tips_Int(tree); - printf("\n. Estimate model parameters under switching substitution model.\n"); + PhyML_Printf("\n. Estimate model parameters under switching substitution model.\n"); Switch_From_Mod_To_M4mod(tree->mod); - MC_Round_Optimize(tree); + /* TIME_Round_Optimize(tree); */ /* Round_Optimize(tree,tree->data); */ /* Simu_Loop(tree); */ Print_Lk(tree,"[LnL under switching substitution model]"); @@ -1605,13 +1584,13 @@ void M4_Posterior_Prediction_Experiment(arbre *tree) n_iter = 0; do { - Evolve(cpy_data,tree->mod,tree); + Evolve(cpy_data,tree->mod,0,tree); tree->data = cpy_data; tree->n_pattern = cpy_data->init_len; - if(tree->mod->s_opt->greedy) Init_P_Lk_Tips_Double(tree); - else Init_P_Lk_Tips_Int(tree); + if(tree->mod->s_opt->greedy) Init_Partial_Lk_Tips_Double(tree); + else Init_Partial_Lk_Tips_Int(tree); - Lk(tree); + Lk(NULL,tree); Init_Ui_Tips(tree); Site_Diversity(tree); @@ -1625,38 +1604,53 @@ void M4_Posterior_Prediction_Experiment(arbre *tree) fclose(fp_cov); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -m4 *M4_Copy_M4_Model(model *ori_mod, m4 *ori_m4mod) +m4 *M4_Copy_M4_Model(t_mod *ori_mod, m4 *ori_m4mod) { int i,j,n_h, n_o; m4 *cpy_m4mod; + + if(ori_mod->io->datatype != NT && ori_mod->io->datatype != AA) + { + PhyML_Printf("\n== Not implemented yet."); + PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } - cpy_m4mod = (m4 *)M4_Make_Light((ori_mod->datatype == NT)?(4):(20)); - cpy_m4mod->n_h = ori_m4mod->n_h; - - M4_Make_Complete(cpy_m4mod->n_h, - cpy_m4mod->n_o, - cpy_m4mod); - n_h = cpy_m4mod->n_h; - n_o = cpy_m4mod->n_o; - - cpy_m4mod->n_h = ori_m4mod->n_h; + cpy_m4mod = (m4 *)M4_Make_Light(); cpy_m4mod->n_o = ori_m4mod->n_o; - For(i,n_h) For(j,n_o*n_o) cpy_m4mod->o_mats[i][j] = ori_m4mod->o_mats[i][j]; - For(i,n_h) cpy_m4mod->multipl[i] = ori_m4mod->multipl[i]; - For(i,n_h) cpy_m4mod->multipl_unscaled[i] = ori_m4mod->multipl_unscaled[i]; - For(i,n_o*n_o) cpy_m4mod->o_rr[i] = ori_m4mod->o_rr[i]; - For(i,n_h*n_h) cpy_m4mod->h_rr[i] = ori_m4mod->h_rr[i]; - For(i,n_h*n_h) cpy_m4mod->h_mat[i] = ori_m4mod->h_mat[i]; - For(i,n_o) cpy_m4mod->o_fq[i] = ori_m4mod->o_fq[i]; - For(i,n_h) cpy_m4mod->h_fq[i] = ori_m4mod->h_fq[i]; - For(i,n_h) cpy_m4mod->h_fq_unscaled[i] = ori_m4mod->h_fq_unscaled[i]; - cpy_m4mod->delta = ori_m4mod->delta; - cpy_m4mod->alpha = ori_m4mod->alpha; + cpy_m4mod->n_h = ori_m4mod->n_h; + + if(ori_mod->use_m4mod) + { + M4_Make_Complete(cpy_m4mod->n_h, + cpy_m4mod->n_o, + cpy_m4mod); + + n_h = cpy_m4mod->n_h; + n_o = cpy_m4mod->n_o; + + cpy_m4mod->n_h = ori_m4mod->n_h; + cpy_m4mod->n_o = ori_m4mod->n_o; + for(i=0;io_mats[i][j] = ori_m4mod->o_mats[i][j]; + for(i=0;imultipl[i] = ori_m4mod->multipl[i]; + for(i=0;imultipl_unscaled[i] = ori_m4mod->multipl_unscaled[i]; + For(i,n_o*n_o) cpy_m4mod->o_rr[i] = ori_m4mod->o_rr[i]; + For(i,n_h*n_h) cpy_m4mod->h_rr[i] = ori_m4mod->h_rr[i]; + For(i,n_h*n_h) cpy_m4mod->h_mat[i] = ori_m4mod->h_mat[i]; + for(i=0;io_fq[i] = ori_m4mod->o_fq[i]; + for(i=0;ih_fq[i] = ori_m4mod->h_fq[i]; + for(i=0;ih_fq_unscaled[i] = ori_m4mod->h_fq_unscaled[i]; + cpy_m4mod->delta = ori_m4mod->delta; + cpy_m4mod->alpha = ori_m4mod->alpha; + } return cpy_m4mod; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + diff --git a/phyml/m4.h b/phyml/m4.h index b4a6c7a..1d9c050 100644 --- a/phyml/m4.h +++ b/phyml/m4.h @@ -10,29 +10,49 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef M4_H #define M4_H +#include "spr.h" +#include "utilities.h" +#include "lk.h" +#include "optimiz.h" +#include "bionj.h" +#include "models.h" +#include "free.h" +#include "help.h" +#include "simu.h" +#include "eigen.h" +#include "pars.h" +#include "alrt.h" +#include "time.h" +#include "draw.h" +#ifdef PART +#include "mg.h" +#endif + int M4_main(int argc, char **argv); void M4_Make_Complete(int n_h, int n_o, m4 *m4mod); -m4 *M4_Make_Light(int n_o); +m4 *M4_Make_Light(); void M4_Free_M4_Model(m4 *m4mod); -void M4_Init_Qmat(m4 *m4mod, allseq *data, model *mod); -void M4_Update_Qmat(m4 *m4mod, model *mod); -void M4_Init_Model(m4 *m4mod, allseq *data, model *mod); -void M4_Init_P_Lk_Tips_Double(arbre *tree); -void M4_Init_P_Lk_Tips_Int(arbre *tree); -void M4_Post_Prob_H_Class_Edge_Site(edge *b, phydbl ****integral, phydbl *postprob, arbre *tree); -phydbl ****M4_Integral_Term_On_One_Edge(edge *b, arbre *tree); -phydbl ***M4_Compute_Proba_Hidden_States_On_Edges(arbre *tree); -void M4_Free_Integral_Term_On_One_Edge(phydbl ****integral, arbre *tree); -void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree); -void M4_Scale_Br_Len(arbre *tree); -void M4_Detect_Site_Switches_Experiment(arbre *tree); -m4 *M4_Copy_M4_Model(model *ori_mod, m4 *ori_m4mod); -void M4_Posterior_Prediction_Experiment(arbre *tree); +void M4_Init_Qmat(m4 *m4mod, calign *data, t_mod *mod); +void M4_Update_Qmat(m4 *m4mod, t_mod *mod); +void M4_Init_Model(m4 *m4mod, calign *data, t_mod *mod); +void M4_Init_Partial_Lk_Tips_Double(t_tree *tree); +void M4_Init_Partial_Lk_Tips_Int(t_tree *tree); +void M4_Post_Prob_H_Class_Edge_Site(t_edge *b, phydbl ****integral, phydbl *postprob, t_tree *tree); +phydbl ****M4_Integral_Term_On_One_Edge(t_edge *b, t_tree *tree); +phydbl ***M4_Compute_Proba_Hidden_States_On_Edges(t_tree *tree); +void M4_Free_Integral_Term_On_One_Edge(phydbl ****integral, t_tree *tree); +void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, t_tree *tree); +void M4_Scale_Br_Len(t_tree *tree); +void M4_Detect_Site_Switches_Experiment(t_tree *tree); +m4 *M4_Copy_M4_Model(t_mod *ori_mod, m4 *ori_m4mod); +void M4_Posterior_Prediction_Experiment(t_tree *tree); void M4_Set_M4mod_Default(m4 *m4mod); -phydbl **M4_Site_Branch_Classification(phydbl ***post_probs, arbre *tree); -void M4_Site_Branch_Classification_Experiment(arbre *tree); +phydbl **M4_Site_Branch_Classification(phydbl ***post_probs, t_tree *tree); +void M4_Site_Branch_Classification_Experiment(t_tree *tree); #endif diff --git a/phyml/main.c b/phyml/main.c index f81182a..7050ffe 100644 --- a/phyml/main.c +++ b/phyml/main.c @@ -17,57 +17,89 @@ the GNU public licence. See http://www.opensource.org for details. #include "bionj.h" #include "models.h" #include "free.h" -#include "options.h" +#include "help.h" #include "simu.h" #include "eigen.h" #include "pars.h" #include "alrt.h" +#include "mixt.h" +#include "invitee.h" +#ifdef MPI +#include "mpi_boot.h" +#endif + +#ifdef BEAGLE +#include "beagle_utils.h" +#endif -#ifdef PHYML + + +#if (defined PHYML || EVOLVE) int main(int argc, char **argv) { - seq **data; - allseq *alldata; + calign *cdata; option *io; - arbre *tree; - int n_otu, num_data_set; - int num_tree,tree_line_number,num_rand_tree; - matrix *mat; - model *mod; + t_tree *tree; + int num_data_set; + int num_tree,num_rand_tree; + t_mod *mod; time_t t_beg,t_end; - div_t hour,min; phydbl best_lnL; - int bootstrap_this_tree; int r_seed; + char *most_likely_tree=NULL; + int orig_random_input_tree; + +#ifdef MPI + int rc; + rc = MPI_Init(&argc,&argv); + if (rc != MPI_SUCCESS) + { + PhyML_Fprintf(stderr,"\n. Err. starting MPI program. Terminating.\n"); + MPI_Abort(MPI_COMM_WORLD, rc); + } + if(MPI_Comm_size(MPI_COMM_WORLD,&Global_numTask) != MPI_SUCCESS) MPI_Abort(MPI_COMM_WORLD, rc); + if(MPI_Comm_rank(MPI_COMM_WORLD,&Global_myRank) != MPI_SUCCESS) MPI_Abort(MPI_COMM_WORLD, rc); + PhyML_Fprintf(stdout,"\n\n. Running the analysis on %d CPU%s.", + Global_numTask, + Global_numTask>1?"s.":"."); +#endif #ifdef QUIET setvbuf(stdout,NULL,_IOFBF,2048); #endif - - tree = NULL; - mod = NULL; - data = NULL; - bootstrap_this_tree = 1; + tree = NULL; + mod = NULL; best_lnL = UNLIKELY; + io = (option *)Get_Input(argc,argv); + if(!io) return(0); + else if(io->use_xml == YES) + { + Free(io); + return(0); + } + +#ifdef EVOLVE + io->colalias = NO; +#endif + r_seed = (io->r_seed < 0)?(time(NULL)):(io->r_seed); srand(r_seed); - Make_Model_Complete(io->mod); - mod = io->mod; - if(io->in_tree) Test_Multiple_Data_Set_Format(io); - else io->n_trees = 1; - - - if(io->mod->s_opt->random_input_tree) bootstrap_this_tree = 0; + io->r_seed = r_seed; - mat = NULL; - tree_line_number = 0; + if(io->in_tree == 2) Test_Multiple_Data_Set_Format(io); + else io->n_trees = 1; + if(io->n_trees == 0 && io->in_tree == 2) + { + PhyML_Printf("\n== Err.: the input tree file does not provide a tree in valid format."); + Exit("\n"); + } if((io->n_data_sets > 1) && (io->n_trees > 1)) { @@ -75,335 +107,570 @@ int main(int argc, char **argv) io->n_trees = MIN(io->n_trees,io->n_data_sets); } - - For(num_data_set,io->n_data_sets) + for(num_data_set=0;num_data_setn_data_sets;num_data_set++) { - n_otu = 0; best_lnL = UNLIKELY; - data = Get_Seq(io,0); - - if(data) - { - if(io->n_data_sets > 1) printf("\n. Data set [#%d]\n",num_data_set+1); - printf("\n. Compressing sequences...\n"); - alldata = Compact_Seq(data,io); - Free_Seq(data,alldata->n_otu); - Check_Ambiguities(alldata,io->mod->datatype,io->mod->stepsize); - - for(num_tree=(io->n_trees == 1)?(0):(num_data_set);num_tree < io->n_trees;num_tree++) - { + Get_Seq(io); + Make_Model_Complete(io->mod); + Set_Model_Name(io->mod); + Print_Settings(io); + mod = io->mod; + orig_random_input_tree = io->mod->s_opt->random_input_tree; + + + if(io->data) + { + if(io->n_data_sets > 1) PhyML_Printf("\n. Data set [#%d]\n",num_data_set+1); + cdata = Compact_Data(io->data,io); + + Free_Seq(io->data,cdata->n_otu); + + for(num_tree=(io->n_trees == 1)?(0):(num_data_set);num_tree < io->n_trees;num_tree++) + { + if(io->mod->s_opt->random_input_tree == NO) io->mod->s_opt->n_rand_starts = 1; + + if(orig_random_input_tree == YES && io->n_trees > 1) + { + PhyML_Printf("\n== Cannot combine random starting trees with multiple input trees."); + Exit("\n"); + } + + for(num_rand_tree=0;num_rand_treemod->s_opt->n_rand_starts;num_rand_tree++) + { + if((io->mod->s_opt->random_input_tree) && (io->mod->s_opt->topo_search != NNI_MOVE)) + if(!io->quiet) PhyML_Printf("\n\n. [Random start %3d/%3d]",num_rand_tree+1,io->mod->s_opt->n_rand_starts); + + Init_Model(cdata,mod,io); + +#ifdef M4 + if(io->mod->use_m4mod) M4_Init_Model(mod->m4mod,cdata,mod); +#endif - if(!io->mod->s_opt->random_input_tree) io->mod->s_opt->n_rand_starts = 1; + // Make the initial tree + switch(io->in_tree) + { + case 0 : case 1 : { tree = Dist_And_BioNJ(cdata,mod,io); break; } + case 2 : { tree = Read_User_Tree(cdata,mod,io); break; } + } + + if(io->mod->s_opt->opt_topo == YES) Remove_Duplicates(cdata,io,tree); + + if(io->fp_in_constraint_tree != NULL) + { + char *s; + + PhyML_Printf("\n. Reading constraint tree file..."); + + io->cstr_tree = Read_Tree_File_Phylip(io->fp_in_constraint_tree); + + if(io->cstr_tree->n_root != NULL) + { + PhyML_Printf("\n== The constraint tree file must be unrooted"); + Exit("\n"); + } + + s = Add_Taxa_To_Constraint_Tree(io->fp_in_constraint_tree,cdata); + fflush(NULL); + Free_Tree(tree); + tree = Read_Tree(&s); + io->in_tree = 2; + Free(s); + Check_Constraint_Tree_Taxa_Names(io->cstr_tree,cdata); + Alloc_Bip(io->cstr_tree); + Get_Bip(io->cstr_tree->a_nodes[0], + io->cstr_tree->a_nodes[0]->v[0], + io->cstr_tree); + if(tree->has_branch_lengths == NO) Add_BioNJ_Branch_Lengths(tree,cdata,mod,NULL); + } + + + if(!tree) continue; + + time(&t_beg); + time(&(tree->t_beg)); + + tree->mod = mod; + tree->io = io; + tree->data = cdata; + tree->n_pattern = tree->data->crunch_len; + tree->n_root = NULL; + tree->e_root = NULL; + tree->n_tot_bl_opt = 0; + + Set_Both_Sides(YES,tree); + + if((!num_data_set) && (!num_tree) && (!num_rand_tree)) Check_Memory_Amount(tree); + + if(io->cstr_tree && !Check_Topo_Constraints(tree,io->cstr_tree)) + { + PhyML_Printf("\n\n== The initial tree does not satisfy the topological constraint."); + PhyML_Printf("\n== Please use the user input tree option with an adequate tree topology."); + Exit("\n"); + } + + Connect_CSeqs_To_Nodes(tree->data,tree->io,tree); + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); + Make_Spr(tree); + Br_Len_Not_Involving_Invar(tree); + Unscale_Br_Len_Multiplier_Tree(tree); + + +#ifdef BEAGLE + if(mod->bootstrap == YES) + { + PhyML_Printf("\n== PhyML-BEAGLE does not support bootstrap analysis yet... "); + Exit("\n"); + } + if(mod->ras->invar == YES) + { + PhyML_Printf("\n== PhyML-BEAGLE does not support invariant site models yet... "); + Exit("\n"); + } +#endif - For(num_rand_tree,io->mod->s_opt->n_rand_starts) - { - if((io->mod->s_opt->random_input_tree) && (io->mod->s_opt->topo_search == SPR_MOVE)) - printf("\n. [Random start %3d/%3d]\n",num_rand_tree+1,io->mod->s_opt->n_rand_starts); +#ifdef PHYML + if(tree->io->print_json_trace == YES) JSON_Tree_Io(tree,tree->io->fp_out_json_trace); - Init_Model(alldata,mod); - if(!io->in_tree) - { - printf("\n. Computing pairwise distances...\n"); - mat = ML_Dist(alldata,mod); - Fill_Missing_Dist(mat); - printf("\n. Building BIONJ tree...\n"); - mat->tree = Make_Tree_From_Scratch(alldata->n_otu,alldata); - Bionj(mat); - tree = mat->tree; - tree->mat = mat; - } - else + + Set_Update_Eigen(YES,tree->mod); + Lk(NULL,tree); + Set_Update_Eigen(NO,tree->mod); + + + if(tree->mod->s_opt->opt_topo) { - if((io->n_trees == 1) || (!num_tree)) - { - rewind(io->fp_in_tree); - tree_line_number = 0; - } - - if(io->n_trees > 1) printf("\n. Reading tree [#%d]\n",tree_line_number+1); - else printf("\n. Reading tree...\n"); - fflush(NULL); - - tree = Read_Tree_File(io->fp_in_tree); - tree_line_number++; - - if(!tree) - { - printf("\n. Input tree not found...\n"); - Exit("\n\n"); - } - - if(!tree->has_branch_lengths) - { - printf("\n. Computing branch length estimates...\n"); - Order_Tree_CSeq(tree,alldata); - mat = ML_Dist(alldata,mod); - mat->tree = tree; - mat->method = 0; - Bionj_Br_Length(mat); - tree->mat = mat; - } - - tree->mod = mod; - tree->io = io; - tree->data = alldata; - tree->both_sides = 1; - tree->n_pattern = tree->data->crunch_len/tree->mod->stepsize; - } - - if(!tree) continue; - - time(&t_beg); - time(&(tree->t_beg)); - - tree->mod = mod; - tree->io = io; - tree->data = alldata; - tree->both_sides = 1; - tree->n_pattern = tree->data->crunch_len/tree->mod->stepsize; - -#ifndef BATCH - if((!num_data_set) && (!num_tree) && (!num_rand_tree)) Check_Memory_Amount(tree); + Global_Spr_Search(tree); + if(tree->n_root) Add_Root(tree->a_edges[0],tree); + } + else + { +#ifdef BEAGLE + tree->b_inst = create_beagle_instance(tree, io->quiet, io); +#endif + if(tree->mod->s_opt->opt_subst_param || tree->mod->s_opt->opt_bl) Round_Optimize(tree,ROUND_MAX); + } + + + if(tree->mod->gamma_mgf_bl) Best_Root_Position_IL_Model(tree); + + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + Pars(NULL,tree); + Get_Tree_Size(tree); + PhyML_Printf("\n\n. Log likelihood of the current tree: %.*f.",DECIMAL_DIG,tree->c_lnL); + + if(tree->io->ancestral == YES) Ancestral_Sequences(tree,YES); + + Check_Br_Lens(tree); + Br_Len_Involving_Invar(tree); + Rescale_Br_Len_Multiplier_Tree(tree); + + +#elif defined EVOLVE + Evolve(tree->data,tree->mod,tree); + Exit("\n. Exiting 'evolve'\n"); #endif - Order_Tree_CSeq(tree,alldata); - - if((tree->mod->s_opt->random_input_tree) && (tree->mod->s_opt->topo_search == SPR_MOVE)) - { - printf("\n. Randomising the tree...\n"); - Random_Tree(tree); - } - - Fill_Dir_Table(tree); - Update_Dirs(tree); - Make_Tree_4_Pars(tree,alldata,alldata->init_len); - Make_Tree_4_Lk(tree,alldata,alldata->init_len); - tree->triplet_struct = Make_Triplet_Struct(mod); - Br_Len_Not_Involving_Invar(tree); - - if((tree->mod->s_opt->topo_search == SPR_MOVE) || - (tree->mod->s_opt->topo_search == NNI_MOVE && - tree->mod->s_opt->spr_step_after_nnis)) - { - Make_Spr_List(tree); - Make_Best_Spr(tree); - } + if(!tree->n_root) Get_Best_Root_Position(tree); + + /* Print the tree estimated using the current random (or BioNJ) starting tree */ + /* if(io->mod->s_opt->n_rand_starts > 1) */ + if(orig_random_input_tree == YES) + { + Print_Tree(io->fp_out_trees,tree); + fflush(NULL); + } + + /* Record the most likely tree in a string of characters */ + if(tree->c_lnL > best_lnL) + { + best_lnL = tree->c_lnL; + if(most_likely_tree) Free(most_likely_tree); + most_likely_tree = Write_Tree(tree); + + time(&t_end); + + Print_Fp_Out(io->fp_out_stats,t_beg,t_end,tree, + io,num_data_set+1, + (orig_random_input_tree == YES)?(num_rand_tree):(num_tree), + (num_rand_tree == io->mod->s_opt->n_rand_starts-1)?(YES):(NO), io->precision); + + if(tree->io->print_site_lnl) Print_Site_Lk(tree,io->fp_out_lk); + } + + + + /* Start from BioNJ tree */ + if((num_rand_tree == io->mod->s_opt->n_rand_starts-1) && (tree->mod->s_opt->random_input_tree)) + { + /* Do one more iteration in the loop, but don't randomize the tree */ + tree->mod->s_opt->n_rand_starts++; + tree->mod->s_opt->random_input_tree = NO; + } +#ifdef BEAGLE + finalize_beagle_instance(tree); +#endif + Free_One_Spr(tree->best_spr); + Free_Spr_List_One_Edge(tree); + Free_Spr_List_All_Edge(tree); + Free_Tree_Pars(tree); + Free_Tree_Lk(tree); + Free_Tree(tree); + } //Tree done + + if(io->n_data_sets == 1) rewind(io->fp_out_tree); + if(most_likely_tree) PhyML_Fprintf(io->fp_out_tree,"%s\n",most_likely_tree); + + + /* Launch bootstrap analysis */ + if(io->do_boot || io->do_tbe) + { + if(!io->quiet) PhyML_Printf("\n\n. Launch bootstrap analysis on the most likely tree..."); + +#ifdef MPI + MPI_Bcast (most_likely_tree, strlen(most_likely_tree)+1, MPI_CHAR, 0, MPI_COMM_WORLD); + if(!io->quiet) PhyML_Printf("\n\n. The bootstrap analysis will use %d CPU%c.",Global_numTask,Global_numTask>1?'s':'\0'); +#endif + + most_likely_tree = Bootstrap_From_String(most_likely_tree,cdata,mod,io); + + PhyML_Printf("\n\n. Completed the bootstrap analysis succesfully."); fflush(NULL); + } + else + if(io->ratio_test != NO) + { + /* Launch aLRT */ + most_likely_tree = aLRT_From_String(most_likely_tree,cdata,mod,io); + } + + + /* Print the most likely tree in the output file */ + if(!io->quiet) PhyML_Printf("\n\n. Printing the most likely tree in file '%s'.", Basename(io->out_tree_file)); + if(io->n_data_sets == 1) rewind(io->fp_out_tree); + + t_tree *dum; + dum = Read_Tree(&most_likely_tree); + dum->data = cdata; + dum->mod = mod; + dum->io = io; + Connect_CSeqs_To_Nodes(cdata,io,dum); + Insert_Duplicates(dum); + Free(most_likely_tree); + most_likely_tree = Write_Tree(dum); + printf("most_likely_tree: %s\n", most_likely_tree); + Free_Tree(dum); + + PhyML_Fprintf(io->fp_out_tree,"%s\n",most_likely_tree); + + if(io->n_trees > 1 && io->n_data_sets > 1) break; + } + Free_Calign(cdata); + } + else + { + PhyML_Printf("\n== No data was found.\n"); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + Free_Model_Complete(mod); + } - if(io->mod->s_opt->spr_step_after_nnis) - { - printf("\n. The NNI+SPR option is not available yet, sorry."); - Warn_And_Exit(""); - } + if(most_likely_tree) Free(most_likely_tree); - if(tree->mod->s_opt->opt_topo) - { - if(tree->mod->s_opt->topo_search == NNI_MOVE) - { - Simu_Loop(tree); - } - else - { - if(tree->mod->s_opt->steph_spr) - { - Speed_Spr_Loop(tree); - } - else - { - Init_SPR(tree); - Optim_SPR(tree,0,ALL); - Clean_SPR(tree); - } - } - } - else - { - if(tree->mod->s_opt->opt_num_param || tree->mod->s_opt->opt_bl) - { - Round_Optimize(tree,tree->data); - } - else - { - Lk(tree); - Print_Lk(tree,""); - } - } - - Lk(tree); - printf("\n\n. Final log likelihood : %f",tree->c_lnL); - - if(tree->io->ratio_test) aLRT(tree); - - if((tree->c_lnL > best_lnL) && (io->mod->s_opt->n_rand_starts > 1)) - { - best_lnL = tree->c_lnL; - io->fp_out_best_tree = (FILE *)fopen(io->out_best_tree_file,"w"); - Print_Tree(io->fp_out_best_tree,tree); - fflush(NULL); - fclose(io->fp_out_best_tree); - } - - if((tree->mod->bootstrap) && (bootstrap_this_tree)) - { - if(num_rand_tree > 0) io->in_tree = 0; - Bootstrap(tree); - tree->mod->bootstrap = 0; - } - - Br_Len_Involving_Invar(tree); - Print_Tree(io->fp_out_tree,tree); - -/* //printing loglk for each site, to compute SH-like tests *\/ */ -/* phydbl sum=0.0; */ -/* printf("\n\nSITES LKS:\n"); */ -/* int n_patterns = (int)floor(tree->n_pattern*tree->prop_of_sites_to_consider); */ -/* int site=0; */ -/* For(site,n_patterns) { */ -/* int wei=0; */ -/* For(wei,tree->data->wght[site]) { */ -/* printf("%f\n",tree->c_lnL_sorted[site] / tree->data->wght[site]); */ -/* sum+=tree->c_lnL_sorted[site] / tree->data->wght[site]; */ -/* } */ -/* } */ - -/* printf("\n\nsum=%f\n\n",sum); */ -/* int i=0; */ -/* For(i,2*tree->n_otu-3) */ -/* { */ -/* if((!tree->t_edges[i]->left->tax) && (!tree->t_edges[i]->rght->tax)) */ -/* { */ -/* printf("%3d %f %f %f\n", */ -/* tree->t_edges[i]->bip_score,tree->t_edges[i]->alrt_statistic, tree->t_edges[i]->ratio_test,tree->t_edges[i]->l); */ -/* } */ -/* } */ - - -/* //printing loglk for each site, to compute SH-like tests */ -/* phydbl sum=0.0; */ -/* printf("\n\nSITES LKS:\n"); */ -/* int n_patterns = (int)floor(tree->n_pattern*tree->prop_of_sites_to_consider); */ -/* int site=0; */ -/* For(site,n_patterns) { */ -/* int wei=0; */ -/* For(wei,tree->data->wght[site]) { */ -/* printf("%f\n",tree->c_lnL_sorted[site] / tree->data->wght[site]); */ -/* sum+=tree->c_lnL_sorted[site] / tree->data->wght[site]; */ -/* } */ -/* } */ - -/* printf("\n\nsum=%f\n\n",sum); */ - -/* int i=0; */ -/* For(i,2*tree->n_otu-3) */ -/* { */ -/* if((!tree->t_edges[i]->left->tax) && (!tree->t_edges[i]->rght->tax)) */ -/* { */ -/* printf("%3d %f %f %f\n", */ -/* tree->t_edges[i]->bip_score,tree->t_edges[i]->alrt_statistic, tree->t_edges[i]->ratio_test,tree->t_edges[i]->l); */ -/* } */ -/* } */ - - - Unconstraint_Lk(tree); - time(&t_end); - hour = div(t_end-t_beg,3600); - min = div(t_end-t_beg,60 ); - min.quot -= hour.quot*60; - printf("\n\n. Time used %dh%dm%ds\n", hour.quot,min.quot,(int)(t_end-t_beg)%60); - printf("\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); - Print_Fp_Out(io->fp_out_stats,t_beg,t_end,tree, - io,num_data_set+1, - (tree->mod->s_opt->n_rand_starts > 1)?(num_rand_tree):(num_tree)); - - if(tree->io->print_site_lnl) Print_Site_Lk(tree,io->fp_out_lk); - - /* Start from BioNJ tree */ - if((num_rand_tree == io->mod->s_opt->n_rand_starts-1) - && (io->mod->s_opt->n_rand_starts > 1) - && (tree->mod->s_opt->random_input_tree)) - { - num_rand_tree--; - tree->mod->s_opt->random_input_tree = 0; - } + if(mod->s_opt->n_rand_starts > 1) PhyML_Printf("\n. Best log likelihood: %f\n",best_lnL); - if((num_rand_tree == io->mod->s_opt->n_rand_starts - 1) && - (!tree->mod->s_opt->random_input_tree) && - (io->mod->s_opt->n_rand_starts > 1)) - { - if(tree->mod->bootstrap) - { - num_rand_tree--; - io->in_tree = 1; - io->fp_in_tree = io->fp_out_best_tree; - bootstrap_this_tree = 1; - io->fp_in_tree = (FILE *)fopen(io->out_best_tree_file,"r"); - } - else - { - io->fp_out_best_tree = (FILE *)fopen(io->out_best_tree_file,"w"); - Print_Tree(io->fp_out_best_tree,tree); - fflush(NULL); - fclose(io->fp_out_best_tree); - } - } - - if((tree->mod->s_opt->topo_search == SPR_MOVE) || - (tree->mod->s_opt->topo_search == NNI_MOVE && - tree->mod->s_opt->spr_step_after_nnis)) - { - Free_Spr_List(tree); - Free_One_Spr(tree->best_spr); - } - - if(tree->mat) Free_Mat(tree->mat); - Free_Triplet(tree->triplet_struct); - Free_Tree_Pars(tree); - Free_Tree_Lk(tree); - Free_Tree(tree); - } - if(io->n_trees > 1 && io->n_data_sets > 1) break; - } - Free_Cseq(alldata); - } - } + Free_Optimiz(mod->s_opt); + Free_Model_Basic(mod); - if(io->mod->s_opt->n_rand_starts > 1) printf("\n\n. Best log likelihood : %f\n",best_lnL); + if(io->fp_in_constraint_tree) fclose(io->fp_in_constraint_tree); + if(io->fp_in_align) fclose(io->fp_in_align); + if(io->fp_in_tree) fclose(io->fp_in_tree); + if(io->fp_out_lk) fclose(io->fp_out_lk); + if(io->fp_out_tree) fclose(io->fp_out_tree); + if(io->fp_out_trees) fclose(io->fp_out_trees); + if(io->fp_out_stats) fclose(io->fp_out_stats); + if(io->fp_out_trace) fclose(io->fp_out_trace); + if(io->fp_out_json_trace) fclose(io->fp_out_json_trace); - Free_Model(mod); + if(io->fp_in_constraint_tree != NULL) Free_Tree(io->cstr_tree); + Free_Input(io); - if(io->fp_in_seq) fclose(io->fp_in_seq); - if(io->fp_in_tree) fclose(io->fp_in_tree); - if(io->fp_out_lk) fclose(io->fp_out_lk); - if(io->fp_out_tree) fclose(io->fp_out_tree); - if(io->fp_out_stats) fclose(io->fp_out_stats); + time(&t_end); + Print_Time_Info(t_beg,t_end); +#ifdef MPI + MPI_Finalize(); +#endif - Free_Input(io); return 0; } -#elif(MG) +#elif(M4) +#include "m4.h" +int main(int argc, char **argv) +{ + M4_main(argc, argv); + return 1; +} + +#elif(PART) #include "mg.h" int main(int argc, char **argv) { - MC_main(argc, argv); + PART_main(argc, argv); return 1; } -#elif(M4) -#include "m4.h" +/* #elif(PHYTIME) */ +/* #include "times.h" */ +/* int main(int argc, char **argv) */ +/* { */ +/* TIMES_main(argc, argv); */ +/* return 1; */ +/* } */ + +#elif(PHYCONT) +#include "continuous.h" +int main(int argc, char **argv) +{ + CONT_main(argc, argv); + return 1; +} + +#elif(RF) int main(int argc, char **argv) { - MC_main(argc, argv); + option *io; + int r_seed; + + + io = (option *)Get_Input(argc,argv); + if(!io) return(0); + + r_seed = (io->r_seed < 0)?(time(NULL)):(io->r_seed); + srand(r_seed); + io->r_seed = r_seed; + + Get_Seq(io); + Shuffle_Sites(io->mod->ras->pinvar->v,io->data,io->n_otu); + Print_Seq(stdout,io->data,io->n_otu); + + /* t_tree *tree1, *tree2; */ + /* FILE *fp_tree1, *fp_tree2; */ + /* int i,j; */ + + /* fp_tree1 = (FILE *)fopen(argv[1],"r"); */ + /* fp_tree2 = (FILE *)fopen(argv[2],"r"); */ + + /* tree1 = Read_Tree_File_Phylip(fp_tree1); */ + /* tree2 = Read_Tree_File_Phylip(fp_tree2); */ + + + /* Prune_Tree(tree1,tree2); */ + /* Prune_Tree(tree2,tree1); */ + + + /* PhyML_Printf("%s\n%s", */ + /* Write_Tree(tree1), */ + /* Write_Tree(tree2)); */ + + + /* Match_Nodes_In_Small_Tree(tree1,tree2); */ + + /* For(i,2*tree1->n_otu-2) */ + /* { */ + /* printf("\n. Node %d in tree1 matches node %d in tree2",i,(tree1->noeud[i]->match_node)?(tree1->noeud[i]->match_node->num):(-1)); */ + /* } */ + + + + +/* t_tree *tree1, *tree2; */ +/* FILE *fp_tree1, *fp_tree2; */ +/* int i,j,rf,n_edges,n_common,bip_size; */ +/* phydbl thresh; */ +/* t_edge *b; */ + + +/* fp_tree1 = (FILE *)fopen(argv[1],"r"); */ +/* fp_tree2 = (FILE *)fopen(argv[2],"r"); */ +/* thresh = (phydbl)atof(argv[3]); */ + +/* tree1 = Read_Tree_File(fp_tree1); */ +/* tree2 = Read_Tree_File(fp_tree2); */ + +/* Get_Rid_Of_Prefix('_',tree1); */ + +/* /\* Find_Common_Tips(tree1,tree2); *\/ */ + +/* Alloc_Bip(tree1); */ +/* Alloc_Bip(tree2); */ + +/* Get_Bip(tree1->noeud[0],tree1->noeud[0]->v[0],tree1); */ +/* Get_Bip(tree2->noeud[0],tree2->noeud[0]->v[0],tree2); */ + +/* /\* PhyML_Printf("\n. rf=%f\n",Compare_Bip_On_Existing_Edges(thresh,tree1,tree2)); *\/ */ +/* For(i,2*tree1->n_otu-3) tree1->a_edges[i]->bip_score = 0; */ +/* For(i,2*tree2->n_otu-3) tree2->a_edges[i]->bip_score = 0; */ + +/* rf = 0; */ +/* n_edges = 0; */ + +/* /\* First tree *\/ */ +/* For(i,2*tree1->n_otu-3) */ +/* { */ +/* /\* Consider the branch only if the corresponding bipartition has size > 1 *\/ */ +/* b = tree1->a_edges[i]; */ +/* bip_size = MIN(b->left->bip_size[b->l_r],b->rght->bip_size[b->r_l]); */ + +/* if(bip_size > 1) */ +/* { */ +/* /\* with non-zero length *\/ */ +/* if(tree1->a_edges[i]->l > thresh) */ +/* { */ +/* n_edges++; */ +/* /\* This t_edge is not found in tree2 *\/ */ +/* if(!tree1->a_edges[i]->bip_score) rf++; ; */ +/* } */ +/* } */ +/* } */ + + +/* /\* Second tree *\/ */ +/* For(i,2*tree2->n_otu-3) */ +/* { */ +/* b = tree2->a_edges[i]; */ +/* bip_size = MIN(b->left->bip_size[b->l_r],b->rght->bip_size[b->r_l]); */ + +/* if(bip_size > 1) */ +/* { */ +/* if(tree2->a_edges[i]->l > thresh) */ +/* { */ +/* n_edges++; */ +/* /\* This t_edge is not found in tree1 *\/ */ +/* if(!tree2->a_edges[i]->bip_score) rf++; ; */ +/* } */ +/* } */ +/* } */ + +/* if(!n_edges) */ +/* { */ +/* Exit("\n. No comparable internal edges were found.\n"); */ +/* } */ +/* else */ +/* { */ +/* PhyML_Printf("\n. Robinson and Foulds distance: %f.",(double)rf/(n_edges)); */ +/* /\* PhyML_Printf("\n. %d internal edges were processed (%d in the first tree, %d in the second).\n",n_edges,n_edges_t1,n_edges-n_edges_t1); *\/ */ +/* PhyML_Printf("\n"); */ +/* } */ + return 1; } -#elif(MC) -#include "mc.h" +#elif(TIPORDER) +#include "tiporder.h" int main(int argc, char **argv) { - MC_main(argc, argv); + TIPO_main(argc, argv); + return 1; +} + +#elif(TEST) +#include "xml.h" +int main(int argc, char **argv) +{ + option *io; + int i; + int year; + + io = (option *)Get_Input(argc,argv); + if(!io) return(0); + + Get_Seq(io); + + for(i=0;in_otu;i++) + { + sscanf(io->data[i]->name,"%d",&year); + PhyML_Printf("\n",i+1); + PhyML_Printf("\n\t",io->data[i]->name); + PhyML_Printf("\n"); + PhyML_Printf("\n",i+1); + PhyML_Printf("\n\t%d",year); + PhyML_Printf("\n\t%d",year); + PhyML_Printf("\n\t",i+1); + PhyML_Printf("\n"); + } + + /* FILE *fp; */ + /* char *name,*date; */ + /* int i; */ + + /* name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); */ + /* date = (char *)mCalloc(T_MAX_NAME,sizeof(char)); */ + + /* i = 0; */ + /* fp = Openfile(argv[1],READ); */ + /* do */ + /* { */ + /* if(fscanf(fp,"%s",name) == EOF) break; */ + /* if(fscanf(fp,"%s",date) == EOF) break; */ + /* PhyML_Printf("\n",i+1); */ + /* PhyML_Printf("\n\t",name); */ + /* PhyML_Printf("\n"); */ + /* PhyML_Printf("\n",i+1); */ + /* PhyML_Printf("\n\t%s",date); */ + /* PhyML_Printf("\n\t%s",date); */ + /* PhyML_Printf("\n\t",i+1); */ + /* PhyML_Printf("\n"); */ + /* ++i; */ + /* } */ + /* while(1); */ + +} + +#elif(INVITEE) +#include "invitee.h" +int main(int argc, char **argv) +{ + /*My_Function(argc, argv);*/ + /* PhyTime_XML(argc, argv); */ + Get_Input(argc,argv); + return 1; +} + +#elif(GEO) +#include "geo.h" +int main(int argc, char **argv) +{ + GEO_Main(argc,argv); + return 1; +} + +#elif(defined PHYREX || PHYREXSIM) +#include "phyrex.h" +int main(int argc, char **argv) +{ + PHYREX_Main(argc,argv); + return 1; +} + +#elif(PHYTIME) +#include "date.h" +int main(int argc, char **argv) +{ + DATE_Main(argc,argv); + return 1; +} + +#elif(CHECKPOINT) +#include "checkpoint.h" +int main(int argc, char **argv) +{ + CHECK_Main(argc,argv); return 1; } #endif + diff --git a/phyml/make.c b/phyml/make.c new file mode 100644 index 0000000..827a170 --- /dev/null +++ b/phyml/make.c @@ -0,0 +1,1767 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "make.h" + +////////////////////////////////////////////////////////////// + +void Make_Tree_For_Lk(t_tree *tree) +{ + int i; + calign *cdata; + + cdata = tree->data; + assert(cdata); + + + tree->c_lnL_sorted = (phydbl *)mCalloc(tree->n_pattern,sizeof(phydbl)); + tree->cur_site_lk = (phydbl *)mCalloc(tree->n_pattern,sizeof(phydbl)); + tree->old_site_lk = (phydbl *)mCalloc(tree->n_pattern,sizeof(phydbl)); + tree->site_lk_cat = (phydbl *)mCalloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(phydbl)); + tree->unscaled_site_lk_cat = (phydbl *)mCalloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->n_pattern,sizeof(phydbl)); + tree->fact_sum_scale = (int *)mCalloc(tree->n_pattern,sizeof(int)); + + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&tree->eigen_lr_left,BYTE_ALIGN,(size_t)MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&tree->eigen_lr_rght,BYTE_ALIGN,(size_t)MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&tree->dot_prod,BYTE_ALIGN,(size_t)tree->n_pattern*tree->mod->ns*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&tree->expl,BYTE_ALIGN,(size_t)3*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + tree->eigen_lr_left = _aligned_malloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); + tree->eigen_lr_rght = _aligned_malloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); + tree->dot_prod = _aligned_malloc(tree->n_pattern*tree->mod->ns*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*sizeof(phydbl),BYTE_ALIGN); + tree->expl = _aligned_malloc(3*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + tree->eigen_lr_left = (phydbl *)mCalloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns,sizeof(phydbl)); + tree->eigen_lr_rght = (phydbl *)mCalloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns,sizeof(phydbl)); + tree->dot_prod = (phydbl *)mCalloc(tree->n_pattern*tree->mod->ns*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(phydbl)); + tree->expl = (phydbl *)mCalloc(3*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns,sizeof(phydbl)); +#endif + + + tree->log_lks_aLRT = (phydbl **)mCalloc(3,sizeof(phydbl *)); + for(i=0;i<3;i++) tree->log_lks_aLRT[i] = (phydbl *)mCalloc(tree->data->init_len,sizeof(phydbl)); + + for(i=0;i<2*tree->n_otu-1;++i) Make_Edge_NNI(tree->a_edges[i]); + + Make_Extra_Edge_Lk(tree); + + if(tree->is_mixt_tree == NO) + { + for(i=0;i<2*tree->n_otu-1;++i) Make_Edge_Lk(tree->a_edges[i],tree); + for(i=0;i<2*tree->n_otu-2;++i) Make_Node_Lk(tree->a_nodes[i]); + for(i=0;i<2*tree->n_otu-1;++i) Make_Edge_Loc(tree->a_edges[i],tree); + + Init_Partial_Lk_Tips_Double(tree); + Init_Partial_Lk_Loc(tree); + + if(tree->n_root != NULL) + { + Free_Edge_Lk_Rght(tree->n_root->b[1]); + Free_Edge_Lk_Rght(tree->n_root->b[2]); + Free_Edge_Loc_Rght(tree->n_root->b[1]); + Free_Edge_Loc_Rght(tree->n_root->b[2]); + + tree->n_root->b[1]->p_lk_rght = tree->e_root->p_lk_left; + tree->n_root->b[2]->p_lk_rght = tree->e_root->p_lk_rght; + + tree->n_root->b[1]->p_lk_tip_r = tree->e_root->p_lk_tip_l; + tree->n_root->b[2]->p_lk_tip_r = tree->e_root->p_lk_tip_r; + + tree->n_root->b[1]->div_post_pred_rght = tree->e_root->div_post_pred_rght; + tree->n_root->b[2]->div_post_pred_rght = tree->e_root->div_post_pred_left; + + tree->n_root->b[1]->sum_scale_rght = tree->e_root->sum_scale_rght; + tree->n_root->b[2]->sum_scale_rght = tree->e_root->sum_scale_left; + + tree->n_root->b[1]->sum_scale_rght_cat = tree->e_root->sum_scale_rght_cat; + tree->n_root->b[2]->sum_scale_rght_cat = tree->e_root->sum_scale_left_cat; + + tree->n_root->b[1]->patt_id_rght = tree->e_root->patt_id_rght; + tree->n_root->b[2]->patt_id_rght = tree->e_root->patt_id_left; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Tree_For_Pars(t_tree *tree) +{ + int i; + calign *cdata; + + cdata = tree->data; + assert(cdata); + + assert(tree->mod); + + tree->site_pars = (int *)mCalloc(tree->n_pattern,sizeof(int)); + tree->step_mat = (int *)mCalloc(tree->mod->ns * tree->mod->ns,sizeof(int)); + + for(i=0;i<2*tree->n_otu-1;++i) Make_Edge_Pars(tree->a_edges[i],tree); + + Init_Ui_Tips(tree); + Init_Partial_Pars_Tips(tree); /* Must be called after Init_Ui_Tips is called */ + + if(tree->n_root) + { + Free_Edge_Pars_Rght(tree->a_edges[2*tree->n_otu-3]); + Free_Edge_Pars_Rght(tree->a_edges[2*tree->n_otu-2]); + } + + Get_Step_Mat(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_All_Edges_Lk(t_node *a, t_node *d, t_tree *tree) +{ + int i; + + for(i=0;i<3;i++) + if((a->v[i]) && (a->v[i] == d)) + Make_Edge_Lk(a->b[i],tree); + + if(d->tax) return; + else + { + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + Make_All_Edges_Lk(d,d->v[i],tree); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_edge *Make_Edge_Light(t_node *a, t_node *d, int num) +{ + t_edge *b; + + b = (t_edge *)mCalloc(1,sizeof(t_edge)); + + b->l = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(b->l); + + b->l_old = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(b->l_old); + + b->l_var = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(b->l_var); + + b->l_var_old = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(b->l_var_old); + + Init_Edge_Light(b,num); + + if(a && b) + { + b->left = a; + b->rght = d; + if(a->tax) {b->rght = a; b->left = d;} /* root */ + /* a tip is necessary on the right side of the t_edge */ + + (b->left == a)? + (Set_Edge_Dirs(b,a,d,NULL)): + (Set_Edge_Dirs(b,d,a,NULL)); + + assert(b->l_r > -1); + assert(b->r_l > -1); + + b->l_old->v = b->l->v; + } + else + { + b->left = NULL; + b->rght = NULL; + } + + return b; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Edge_Pars(t_edge *b, t_tree *tree) +{ + assert(b); + Make_Edge_Pars_Left(b,tree); + Make_Edge_Pars_Rght(b,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Edge_Pars_Left(t_edge *b, t_tree *tree) +{ + b->pars_l = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); + b->ui_l = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); + b->p_pars_l = (int *)mCalloc(tree->data->crunch_len*tree->mod->ns,sizeof(int )); + b->n_diff_states_l = (int *)mCalloc(tree->mod->ns,sizeof(int )); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Edge_Pars_Rght(t_edge *b, t_tree *tree) +{ + b->pars_r = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); + b->ui_r = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); + b->p_pars_r = (int *)mCalloc(tree->data->crunch_len*tree->mod->ns,sizeof(int )); + b->n_diff_states_r = (int *)mCalloc(tree->mod->ns,sizeof(int )); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Edge_Lk(t_edge *b, t_tree *tree) +{ + if(tree->is_mixt_tree) + { + PhyML_Printf("\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit(""); + } + + b->l_old->v = b->l->v; + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void *)&b->Pij_rr,BYTE_ALIGN,(size_t)tree->mod->ras->n_catg*tree->mod->ns*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void *)&b->tPij_rr,BYTE_ALIGN,(size_t)tree->mod->ras->n_catg*tree->mod->ns*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + b->Pij_rr = _aligned_malloc(tree->mod->ras->n_catg*tree->mod->ns*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); + b->tPij_rr = _aligned_malloc(tree->mod->ras->n_catg*tree->mod->ns*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + b->Pij_rr = (phydbl *)mCalloc(tree->mod->ras->n_catg*tree->mod->ns*tree->mod->ns,sizeof(phydbl)); + b->tPij_rr = (phydbl *)mCalloc(tree->mod->ras->n_catg*tree->mod->ns*tree->mod->ns,sizeof(phydbl)); +#endif + + Make_Edge_Lk_Left(b,tree); + Make_Edge_Lk_Rght(b,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Edge_Lk_Left(t_edge *b, t_tree *tree) +{ + int ns = tree->mod->ns; + + b->div_post_pred_left = (short int *)mCalloc(ns,sizeof(short int)); + + b->sum_scale_left_cat = (int *)mCalloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(int)); + + if(b->left && !b->left->tax) + b->sum_scale_left = (int *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(int)); + else + b->sum_scale_left = NULL; + + if(b->left) + { + if((!b->left->tax) || (tree->mod->s_opt->greedy)) + { +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&b->p_lk_left,BYTE_ALIGN,(size_t)tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + b->p_lk_left = _aligned_malloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + b->p_lk_left = (phydbl *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns,sizeof(phydbl)); +#endif + b->p_lk_tip_l = NULL; + } + else if(b->left->tax) + { + b->p_lk_left = NULL; + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&b->p_lk_tip_l,BYTE_ALIGN,(size_t)tree->data->crunch_len*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + b->p_lk_tip_l = _aligned_malloc(tree->data->crunch_len*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + b->p_lk_tip_l = (phydbl *)mCalloc(tree->data->crunch_len*tree->mod->ns,sizeof(phydbl)); +#endif + } + } + else + { + b->p_lk_left = NULL; + b->p_lk_tip_l = NULL; + } + + if(b->num >= 2*tree->n_otu-3) + { + b->sum_scale_left = (int *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(int)); + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&b->p_lk_left,BYTE_ALIGN,(size_t)tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + b->p_lk_left = _aligned_malloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + b->p_lk_left = (phydbl *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns,sizeof(phydbl)); +#endif + } + + b->patt_id_left = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Edge_Lk_Rght(t_edge *b, t_tree *tree) +{ + int ns = tree->mod->ns; + + b->div_post_pred_rght = (short int *)mCalloc(ns,sizeof(short int)); + + b->sum_scale_rght_cat = (int *)mCalloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(int)); + + if(b->rght && !b->rght->tax) + b->sum_scale_rght = (int *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(int)); + else + b->sum_scale_rght = NULL; + + + if(b->rght) + { + if((!b->rght->tax) || (tree->mod->s_opt->greedy)) + { +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&b->p_lk_rght,BYTE_ALIGN,(size_t)tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + b->p_lk_rght = _aligned_malloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + b->p_lk_rght = (phydbl *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns,sizeof(phydbl)); +#endif + b->p_lk_tip_r = NULL; + } + else if(b->rght->tax) + { +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&b->p_lk_tip_r,BYTE_ALIGN,(size_t)tree->data->crunch_len*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + b->p_lk_tip_r = _aligned_malloc(tree->data->crunch_len*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + b->p_lk_tip_r = (phydbl *)mCalloc(tree->data->crunch_len*tree->mod->ns,sizeof(phydbl)); +#endif + b->p_lk_rght = NULL; + } + } + else + { + b->p_lk_rght = NULL; + b->p_lk_tip_r = NULL; + } + + if(b->num >= 2*tree->n_otu-3) + { + b->sum_scale_rght = (int *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(int)); +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&b->p_lk_rght,BYTE_ALIGN,(size_t)tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + b->p_lk_rght = _aligned_malloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif + + +#else + b->p_lk_rght = (phydbl *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns,sizeof(phydbl)); +#endif + } + + b->patt_id_rght = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Extra_Edge_Lk(t_tree *tree) +{ + int ns = tree->mod->ns; + + tree->div_post_pred_extra_0 = (short int *)mCalloc(ns,sizeof(short int)); + + tree->sum_scale_cat_extra_0 = (int *)mCalloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(int)); + + tree->sum_scale_extra_0 = (int *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(int)); + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&tree->p_lk_extra_0,BYTE_ALIGN,(size_t)tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + tree->p_lk_extra_0 = _aligned_malloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + tree->p_lk_extra_0 = (phydbl *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns,sizeof(phydbl)); +#endif + + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&tree->p_lk_tip_extra_0,BYTE_ALIGN,(size_t)tree->data->crunch_len*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + tree->p_lk_tip_extra_0 = _aligned_malloc(tree->data->crunch_len*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + tree->p_lk_tip_extra_0 = (phydbl *)mCalloc(tree->data->crunch_len*tree->mod->ns,sizeof(phydbl)); +#endif + + tree->patt_id_extra_0 = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); + + tree->div_post_pred_extra_1 = (short int *)mCalloc(ns,sizeof(short int)); + + tree->sum_scale_cat_extra_1 = (int *)mCalloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(int)); + + tree->sum_scale_extra_1 = (int *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(int)); + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&tree->p_lk_extra_1,BYTE_ALIGN,(size_t)tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + tree->p_lk_extra_1 = _aligned_malloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + tree->p_lk_extra_1 = (phydbl *)mCalloc(tree->data->crunch_len*MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->mod->ns,sizeof(phydbl)); +#endif + + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&tree->p_lk_tip_extra_1,BYTE_ALIGN,(size_t)tree->data->crunch_len*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + tree->p_lk_tip_extra_1 = _aligned_malloc(tree->data->crunch_len*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + tree->p_lk_tip_extra_1 = (phydbl *)mCalloc(tree->data->crunch_len*tree->mod->ns,sizeof(phydbl)); +#endif + + tree->patt_id_extra_1 = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Edge_Loc(t_edge *b, t_tree *tree) +{ + Make_Edge_Loc_Left(b,tree); + Make_Edge_Loc_Rght(b,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Edge_Loc_Rght(t_edge *b, t_tree *tree) +{ + b->p_lk_loc_rght = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Edge_Loc_Left(t_edge *b, t_tree *tree) +{ + b->p_lk_loc_left = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Edge_NNI(t_edge *b) +{ + b->nni = Make_NNI(); + b->nni->b = b; + b->nni->left = b->left; + b->nni->rght = b->rght; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_nni *Make_NNI() +{ + t_nni *a_nni; + + a_nni = (t_nni *)mCalloc(1,sizeof(t_nni)); + + Init_NNI(a_nni); + return a_nni; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_node *Make_Node_Light(int num) +{ + t_node *n; + + n = (t_node *)mCalloc(1,sizeof(t_node)); + n->v = (t_node **)mCalloc(3,sizeof(t_node *)); + n->b = (t_edge **)mCalloc(3,sizeof(t_edge *)); + n->score = (phydbl *)mCalloc(3,sizeof(phydbl)); + n->s_ingrp = (int *)mCalloc(3,sizeof(int)); + n->s_outgrp = (int *)mCalloc(3,sizeof(int)); + n->cal = (t_cal **)mCalloc(MAX_N_CAL,sizeof(t_cal *)); + + Init_Node_Light(n,num); + + return n; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Node_Lk(t_node *n) +{ +/* n->n_ex_nodes = (int *)mCalloc(2,sizeof(int)); */ + return; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +nexcom **Make_Nexus_Com() +{ + nexcom **com; + int i; + + com = (nexcom **)mCalloc(N_MAX_NEX_COM,sizeof(nexcom *)); + + for(i=0;iname = (char *)mCalloc(T_MAX_NEX_COM,sizeof(char)); + com[i]->parm = (nexparm **)mCalloc(N_MAX_NEX_PARM,sizeof(nexparm *)); + } + + return com; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +nexparm *Make_Nexus_Parm() +{ + nexparm *parm; + + parm = (nexparm *)mCalloc(1,sizeof(nexparm)); + parm->name = (char *)mCalloc(T_MAX_TOKEN,sizeof(char )); + parm->value = (char *)mCalloc(T_MAX_TOKEN,sizeof(char )); + + return parm; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +matrix *Make_Mat(int n_otu) +{ + matrix *mat; + int i; + + mat = (matrix *)mCalloc(1,sizeof(matrix)); + + mat->n_otu = n_otu; + + mat->P = (phydbl **)mCalloc(n_otu,sizeof(phydbl *)); + mat->Q = (phydbl **)mCalloc(n_otu,sizeof(phydbl *)); + mat->dist = (phydbl **)mCalloc(n_otu,sizeof(phydbl *)); + mat->on_off = (int *)mCalloc(n_otu,sizeof(int)); + mat->name = (char **)mCalloc(n_otu,sizeof(char *)); + mat->tip_node = (t_node **)mCalloc(n_otu,sizeof(t_node *)); + + + for(i=0;iP[i] = (phydbl *)mCalloc(n_otu,sizeof(phydbl)); + mat->Q[i] = (phydbl *)mCalloc(n_otu,sizeof(phydbl)); + mat->dist[i] = (phydbl *)mCalloc(n_otu,sizeof(phydbl)); + mat->name[i] = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + } + + return mat; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_tree *Make_Tree_From_Scratch(int n_otu, calign *data) +{ + t_tree *tree; + + tree = Make_Tree(n_otu); + Init_Tree(tree,n_otu); + Make_All_Tree_Nodes(tree); + Make_All_Tree_Edges(tree); + Make_Tree_Path(tree); + if(data) + { + Copy_Tax_Names_To_Tip_Labels(tree,data); + tree->data = data; + } + + +#ifdef BEAGLE + //offset the branch's partial indices because BEAGLE insists on first storing the tips/taxa + int num_branches = 2*tree->n_otu-1; + int i; + for(i=0;i<2*tree->n_otu-1;++i) + { + //For edgeX, its "left" partial lies at index `num_tax + edgeX->num" + tree->a_edges[i]->p_lk_left_idx = tree->n_otu + tree->a_edges[i]->p_lk_left_idx; + //For edgeX, its "right" partial lies at index `num_tax + edgeX->num + num_branches" + tree->a_edges[i]->p_lk_rght_idx = tree->n_otu + tree->a_edges[i]->p_lk_left_idx + num_branches; + } +#endif + + return tree; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_tree *Make_Tree(int n_otu) +{ + t_tree *tree; + tree = (t_tree *)mCalloc(1,sizeof(t_tree )); + tree->t_dir = (short int *)mCalloc((2*n_otu-2)*(2*n_otu-2),sizeof(int)); + return tree; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Make_Tree_Path(t_tree *tree) +{ + tree->curr_path = (t_node **)mCalloc(tree->n_otu,sizeof(t_node *)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Make_All_Tree_Nodes(t_tree *tree) +{ + int i; + + tree->a_nodes = (t_node **)mCalloc(2*tree->n_otu-1,sizeof(t_node *)); + + for(i=0;i<2*tree->n_otu-1;++i) + { + tree->a_nodes[i] = (t_node *)Make_Node_Light(i); + if(i < tree->n_otu) tree->a_nodes[i]->tax = YES; + else tree->a_nodes[i]->tax = NO; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_All_Tree_Edges(t_tree *tree) +{ + int i; + tree->a_edges = (t_edge **)mCalloc(2*tree->n_otu-1,sizeof(t_edge *)); + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i] = (t_edge *)Make_Edge_Light(NULL,NULL,i); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +calign *Make_Calign(int n_otu, int crunch_len, int state_len, int init_len, char **sp_names_in, int n_rm, char **sp_names_out) +{ + calign *cdata; + int j; + + cdata = (calign *)mCalloc(1,sizeof(calign)); + cdata->c_seq = (align **)mCalloc(n_otu,sizeof(align *)); + cdata->obs_state_frq = (phydbl *)mCalloc(T_MAX_ALPHABET,sizeof(phydbl)); + cdata->wght = (phydbl *)mCalloc(crunch_len,sizeof(phydbl)); + cdata->ambigu = (short int *)mCalloc(crunch_len,sizeof(short int)); + cdata->invar = (short int *)mCalloc(crunch_len,sizeof(short int)); + cdata->sitepatt = (int *)mCalloc(init_len,sizeof(int )); + + if(n_rm > 0) cdata->c_seq_rm = (align **)mCalloc(n_rm,sizeof(align *)); + + for(j=0;jc_seq[j] = (align *)mCalloc(1,sizeof(align)); + cdata->c_seq[j]->name = (char *)mCalloc((int)(strlen(sp_names_in[j])+1),sizeof(char)); + strcpy(cdata->c_seq[j]->name,sp_names_in[j]); + cdata->c_seq[j]->state = (char *)mCalloc(crunch_len*state_len+1,sizeof(char)); + cdata->c_seq[j]->d_state = (short int *)mCalloc(crunch_len*state_len,sizeof(short int)); + cdata->c_seq[j]->is_ambigu = (short int *)mCalloc(crunch_len,sizeof(short int)); + } + + for(j=0;jc_seq_rm[j] = (align *)mCalloc(1,sizeof(align)); + cdata->c_seq_rm[j]->name = (char *)mCalloc((int)(strlen(sp_names_out[j])+1),sizeof(char)); + strcpy(cdata->c_seq_rm[j]->name,sp_names_out[j]); + cdata->c_seq_rm[j]->state = (char *)mCalloc(crunch_len*state_len+1,sizeof(char)); + cdata->c_seq_rm[j]->d_state = (short int *)mCalloc(crunch_len*state_len,sizeof(short int)); + cdata->c_seq_rm[j]->is_ambigu = (short int *)mCalloc(crunch_len,sizeof(short int)); + } + + return cdata; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +t_treelist *Make_Treelist(int list_size) +{ + t_treelist *tlist; + + tlist = (t_treelist *)mCalloc(1,sizeof(t_treelist)); + tlist->list_size = list_size; + tlist->tree = (t_tree **)mCalloc(list_size,sizeof(t_tree *)); + + return tlist; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_opt *Make_Optimiz() +{ + t_opt *s_opt; + s_opt = (t_opt *)mCalloc(1,sizeof(t_opt)); + return s_opt; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Custom_Model(t_mod *mod) +{ + if(!mod->r_mat) + { + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if(!mod->r_mat->rr->v) + mod->r_mat->rr->v = (phydbl *)mCalloc(mod->ns*(mod->ns-1)/2,sizeof(phydbl)); + + if(!mod->r_mat->rr_val->v) + mod->r_mat->rr_val->v = (phydbl *)mCalloc(mod->ns*(mod->ns-1)/2,sizeof(phydbl)); + + if(!mod->r_mat->rr_num->v) + mod->r_mat->rr_num->v = (int *)mCalloc(mod->ns*(mod->ns-1)/2,sizeof(int *)); + + if(!mod->r_mat->n_rr_per_cat->v) + mod->r_mat->n_rr_per_cat->v = (int *)mCalloc(mod->ns*(mod->ns-1)/2,sizeof(int)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_string *Make_String(int len) +{ + t_string *ts; + + ts = (t_string *)mCalloc(1,sizeof(t_string)); + ts->s = (char *)mCalloc(len,sizeof(char)); + + return(ts); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_mod *Make_Model_Basic() +{ + t_mod *mod; + + mod = (t_mod *)mCalloc(1,sizeof(t_mod)); + + mod->modelname = Make_String(T_MAX_NAME); + Init_String(mod->modelname); + + mod->custom_mod_string = Make_String(T_MAX_NAME); + Init_String(mod->custom_mod_string); + + mod->ras = Make_RAS_Basic(); + + mod->kappa = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(mod->kappa); + + mod->lambda = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(mod->lambda); + + mod->br_len_mult = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(mod->br_len_mult); + + mod->br_len_mult_unscaled = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(mod->br_len_mult_unscaled); + + mod->mr = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(mod->mr); + + mod->e_frq_weight = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(mod->e_frq_weight); + + mod->r_mat_weight = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(mod->r_mat_weight); + + mod->aa_rate_mat_file = Make_String(T_MAX_FILE); + Init_String(mod->aa_rate_mat_file); + + return mod; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/*! Call only when the values of mod->ns & ras->n_catg is set to its final value */ + +void Make_Model_Complete(t_mod *mod) +{ + mod->Pij_rr = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + Init_Vect_Dbl(0,mod->Pij_rr); + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&mod->Pij_rr->v,BYTE_ALIGN,(size_t)mod->ras->n_catg*mod->ns*mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + mod->Pij_rr->v = _aligned_malloc(mod->ras->n_catg*mod->ns*mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + mod->Pij_rr->v = (phydbl *)mCalloc(mod->ras->n_catg*mod->ns*mod->ns,sizeof(phydbl)); +#endif + + mod->eigen = (eigen *)Make_Eigen_Struct(mod->ns); + + // If r_mat (e_frq) are not NULL, then they have been created elsewhere and affected. + if(!mod->r_mat) + { + mod->r_mat = (t_rmat *)Make_Rmat(mod->ns); + Init_Rmat(mod->r_mat); + } + + if(!mod->e_frq) + { + mod->e_frq = (t_efrq *)Make_Efrq(mod->ns); + Init_Efrq(NULL,mod->e_frq); + } + + Make_RAS_Complete(mod->ras); + + mod->e_frq->user_b_freq->len = mod->ns; + + if(mod->whichmodel < 0) + { + PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + if(mod->whichmodel == CUSTOM) + { + Make_Custom_Model(mod); + Translate_Custom_Mod_String(mod); + } + + if(mod->io->datatype == NT && mod->whichmodel == GTR) + { + Make_Custom_Model(mod); + } + else if(mod->io->datatype == GENERIC) + { + Make_Custom_Model(mod); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_ras *Make_RAS_Basic() +{ + t_ras *ras; + + ras = (t_ras *)mCalloc(1,sizeof(t_ras)); + + ras->gamma_r_proba = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + Init_Vect_Dbl(0,ras->gamma_r_proba); + ras->gamma_r_proba->v = NULL; + + ras->gamma_r_proba_unscaled = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + Init_Vect_Dbl(0,ras->gamma_r_proba_unscaled); + ras->gamma_r_proba_unscaled->v = NULL; + + ras->gamma_rr = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + Init_Vect_Dbl(0,ras->gamma_rr); + ras->gamma_rr->v = NULL; + + ras->gamma_rr_unscaled = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + Init_Vect_Dbl(0,ras->gamma_rr_unscaled); + ras->gamma_rr_unscaled->v = NULL; + + ras->alpha = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(ras->alpha); + + ras->pinvar = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(ras->pinvar); + + ras->free_rate_mr = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(ras->free_rate_mr); + + return(ras); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/*! Call only when the value of ras->n_catg is set to its final value */ +void Make_RAS_Complete(t_ras *ras) +{ + if(!ras->gamma_r_proba->v) + { + ras->gamma_r_proba->v = (phydbl *)mCalloc(ras->n_catg,sizeof(phydbl)); + ras->gamma_r_proba_unscaled->v = (phydbl *)mCalloc(ras->n_catg,sizeof(phydbl)); + ras->gamma_rr->v = (phydbl *)mCalloc(ras->n_catg,sizeof(phydbl)); + ras->gamma_rr_unscaled->v = (phydbl *)mCalloc(ras->n_catg,sizeof(phydbl)); + ras->skip_rate_cat = (short int *)mCalloc(ras->n_catg,sizeof(short int)); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_efrq *Make_Efrq(int ns) +{ + t_efrq *e_frq; + + e_frq = (t_efrq *)mCalloc(1,sizeof(t_efrq)); + + e_frq->pi = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + e_frq->pi->len = ns; + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&e_frq->pi->v,BYTE_ALIGN,(size_t)ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + e_frq->pi->v = _aligned_malloc(ns * sizeof(phydbl),BYTE_ALIGN); +#endif +#else + e_frq->pi->v = (phydbl *)mCalloc(ns,sizeof(phydbl)); +#endif + + + e_frq->pi_unscaled = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + e_frq->pi_unscaled->v = (phydbl *)mCalloc(ns,sizeof(phydbl)); + e_frq->pi_unscaled->len = ns; + + e_frq->user_b_freq = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + Init_Vect_Dbl(0,e_frq->user_b_freq); + e_frq->user_b_freq->v = (phydbl *)mCalloc(T_MAX_OPTION,sizeof(phydbl)); + + return e_frq; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_rmat *Make_Rmat(int ns) +{ + t_rmat *r_mat; + + r_mat = (t_rmat *)mCalloc(1,sizeof(t_rmat)); + + r_mat->qmat = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + Init_Vect_Dbl(0,r_mat->qmat); + + r_mat->qmat_buff = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + Init_Vect_Dbl(0,r_mat->qmat_buff); + + r_mat->rr = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + Init_Vect_Dbl(0,r_mat->rr); + + r_mat->rr_val = (vect_dbl *)mCalloc(1,sizeof(vect_dbl)); + Init_Vect_Dbl(0,r_mat->rr_val); + + r_mat->rr_num = (vect_int *)mCalloc(1,sizeof(vect_int)); + Init_Vect_Int(0,r_mat->rr_num); + + r_mat->n_rr_per_cat = (vect_int *)mCalloc(1,sizeof(vect_int)); + Init_Vect_Int(0,r_mat->n_rr_per_cat); + + r_mat->qmat->v = (phydbl *)mCalloc(ns*ns,sizeof(phydbl)); + r_mat->qmat_buff->v = (phydbl *)mCalloc(ns*ns,sizeof(phydbl)); + + return(r_mat); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +option *Make_Input() +{ + int i; + option* io = (option *)mCalloc(1,sizeof(option)); + + io->nt_or_cd = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + // mod no longer exists + + io->in_tree_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + // out_best_tree_file no longer exists + io->out_boot_tree_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_boot_stats_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_stats_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_tree_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_trace_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_lk_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_ps_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + + + + io->in_align_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->in_constraint_tree_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->in_coord_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_trees_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_ancestral_seq_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_ancestral_tree_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->weight_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_summary_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->out_json_trace_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->run_id_string = (char *)mCalloc(T_MAX_OPTION,sizeof(char)); + io->clade_list_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + io->alphabet = (char **)mCalloc(T_MAX_ALPHABET,sizeof(char *)); + for(i=0;ialphabet[i] = (char *)mCalloc(T_MAX_STATE,sizeof(char )); + io->treelist = (t_treelist *)mCalloc(1,sizeof(t_treelist)); + io->mcmc = (t_mcmc *)MCMC_Make_MCMC_Struct(); + io->rates = (t_rate *)RATES_Make_Rate_Struct(-1); + + return io; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_mcmc *MCMC_Make_MCMC_Struct() +{ + t_mcmc *mcmc; + + mcmc = (t_mcmc *)mCalloc(1,sizeof(t_mcmc)); + mcmc->out_filename = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + + return(mcmc); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +eigen *Make_Eigen_Struct(int ns) +{ + eigen *eig; + + eig = (eigen *)mCalloc(1,sizeof(eigen)); + eig->size = ns; + eig->space = (phydbl *)mCalloc(2*ns,sizeof(phydbl)); + eig->space_int = (int *)mCalloc(2*ns,sizeof(int)); + eig->e_val = (phydbl *)mCalloc(ns,sizeof(phydbl)); + eig->e_val_im = (phydbl *)mCalloc(ns,sizeof(phydbl)); + eig->r_e_vect_im = (phydbl *)mCalloc(ns*ns,sizeof(phydbl)); + eig->q = (phydbl *)mCalloc(ns*ns,sizeof(phydbl)); + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&eig->r_e_vect,BYTE_ALIGN,ns*ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&eig->l_e_vect,BYTE_ALIGN,ns*ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&eig->dum,BYTE_ALIGN,ns*ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + eig->r_e_vect = _aligned_malloc(ns*ns*sizeof(phydbl),BYTE_ALIGN); + eig->l_e_vect = _aligned_malloc(ns*ns*sizeof(phydbl),BYTE_ALIGN); + eig->dum = _aligned_malloc(ns*ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + eig->r_e_vect = (phydbl *)mCalloc(ns*ns,sizeof(phydbl)); + eig->l_e_vect = (phydbl *)mCalloc(ns*ns,sizeof(phydbl)); + eig->dum = (phydbl *)mCalloc(ns*ns,sizeof(phydbl)); +#endif + + Init_Eigen_Struct(eig); + + return eig; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Short_L(t_tree *tree) +{ + if(!tree->short_l) + tree->short_l = (phydbl *)mCalloc(tree->n_short_l,sizeof(phydbl)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +xml_attr *XML_Make_Attribute(xml_attr *prev, char *attr_name, char *attr_value) +{ + xml_attr *new_attr; + + new_attr = (xml_attr *)mCalloc(1,sizeof(xml_attr)); + + new_attr->prev = prev; + new_attr->next = NULL; + if(prev != NULL) prev->next = new_attr; + + new_attr->name = (char *)mCalloc(strlen(attr_name)+1,sizeof(char)); + strcpy(new_attr->name,attr_name); + + new_attr->value = (char *)mCalloc(strlen(attr_value)+1,sizeof(char)); + strcpy(new_attr->value,attr_value); + + return new_attr; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Make_Node_Id(xml_node *n, char *id) +{ + if(id) n->id = (char *)mCalloc(strlen(id)+1,sizeof(char)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Make_Node_Value(xml_node *n, char *val) +{ + if(val) n->value = (char *)mCalloc(strlen(val)+1,sizeof(char)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +xml_node *XML_Make_Node(char *name) +{ + xml_node *new_node = (xml_node *)mCalloc(1,sizeof(xml_node)); + if(name) new_node->name = (char *)mCalloc(strlen(name)+1,sizeof(char)); + new_node->ds = (t_ds *)mCalloc(1,sizeof(t_ds)); + return new_node; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Best_Spr(t_tree *tree) +{ + tree->best_spr = Make_One_Spr(tree); + Init_One_Spr(tree->best_spr); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Spr(t_tree *tree) +{ + Make_Spr_List_One_Edge(tree); + Make_Spr_List_All_Edge(tree); + Make_Best_Spr(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Spr_List_One_Edge(t_tree *tree) +{ + int i; + + tree->size_spr_list_one_edge = 2*tree->n_otu-3; + + tree->spr_list_one_edge = (t_spr **)mCalloc(2*tree->n_otu-2,sizeof(t_spr *)); + + for(i=0;i<2*tree->n_otu-2;++i) + { + tree->spr_list_one_edge[i] = Make_One_Spr(tree); + Init_One_Spr(tree->spr_list_one_edge[i]); + } + + tree->perform_spr_right_away = NO; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Spr_List_All_Edge(t_tree *tree) +{ + int i; + + tree->size_spr_list_all_edge = 2*tree->n_otu-3; + + tree->spr_list_all_edge = (t_spr **)mCalloc(2*tree->n_otu-2,sizeof(t_spr *)); + + for(i=0;i<2*tree->n_otu-2;++i) + { + tree->spr_list_all_edge[i] = Make_One_Spr(tree); + Init_One_Spr(tree->spr_list_all_edge[i]); + } + + tree->perform_spr_right_away = NO; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_spr *Make_One_Spr(t_tree *tree) +{ + t_spr *a_spr; + a_spr = (t_spr *)mCalloc(1,sizeof(t_spr)); + a_spr->path = (t_node **)mCalloc(tree->n_otu,sizeof(t_node *)); + return a_spr; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_rate *RATES_Make_Rate_Struct(int n_otu) +{ + t_rate *rates; + + rates = (t_rate *)mCalloc(1,sizeof(t_rate)); + rates->is_allocated = NO; + + if(n_otu > 0) + { + rates->is_allocated = YES; + rates->nd_r = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->br_r = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->buff_br_r = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->buff_nd_r = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->true_r = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->nd_t = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->buff_t = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->true_t = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->t_mean = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->t_prior = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->t_prior_min = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->t_prior_max = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->t_floor = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->t_rank = (int *)mCalloc(2*n_otu-1,sizeof(int)); + rates->t_has_prior = (short int *)mCalloc(2*n_otu-1,sizeof(short int)); + rates->dens = (phydbl *)mCalloc(2*n_otu-2,sizeof(phydbl)); + rates->triplet = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->n_jps = (int *)mCalloc(2*n_otu-1,sizeof(int)); + rates->t_jps = (int *)mCalloc(2*n_otu-2,sizeof(int)); + rates->cov_l = (phydbl *)mCalloc((2*n_otu-2)*(2*n_otu-2),sizeof(phydbl)); + rates->invcov = (phydbl *)mCalloc((2*n_otu-2)*(2*n_otu-2),sizeof(phydbl)); + rates->mean_l = (phydbl *)mCalloc(2*n_otu-2,sizeof(phydbl)); + rates->ml_l = (phydbl *)mCalloc(2*n_otu-2,sizeof(phydbl)); + rates->cur_l = (phydbl *)mCalloc(2*n_otu-2,sizeof(phydbl)); + rates->u_ml_l = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->u_cur_l = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->cov_r = (phydbl *)mCalloc((2*n_otu-2)*(2*n_otu-2),sizeof(phydbl)); + rates->cond_var = (phydbl *)mCalloc(2*n_otu-2,sizeof(phydbl)); + rates->mean_r = (phydbl *)mCalloc(2*n_otu-2,sizeof(phydbl)); + rates->mean_t = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->lca = (t_node **)mCalloc((2*n_otu-1)*(2*n_otu-1),sizeof(t_node *)); + rates->reg_coeff = (phydbl *)mCalloc((2*n_otu-2)*(2*n_otu-2),sizeof(phydbl)); + rates->trip_reg_coeff = (phydbl *)mCalloc((2*n_otu-2)*(6*n_otu-9),sizeof(phydbl)); + rates->trip_cond_cov = (phydbl *)mCalloc((2*n_otu-2)*9,sizeof(phydbl)); + rates->_2n_vect1 = (phydbl *)mCalloc(2*n_otu,sizeof(phydbl)); + rates->_2n_vect2 = (phydbl *)mCalloc(2*n_otu,sizeof(phydbl)); + rates->_2n_vect3 = (phydbl *)mCalloc(2*n_otu,sizeof(phydbl)); + rates->_2n_vect4 = (phydbl *)mCalloc(2*n_otu,sizeof(phydbl)); + rates->_2n_vect5 = (short int *)mCalloc(2*n_otu,sizeof(short int)); + rates->_2n2n_vect1 = (phydbl *)mCalloc(4*n_otu*n_otu,sizeof(phydbl)); + rates->_2n2n_vect2 = (phydbl *)mCalloc(4*n_otu*n_otu,sizeof(phydbl)); + rates->br_do_updt = (short int *)mCalloc(2*n_otu-1,sizeof(short int)); + rates->cur_gamma_prior_mean = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->cur_gamma_prior_var = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->n_tips_below = (int *)mCalloc(2*n_otu-1,sizeof(int)); + rates->time_slice_lims = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->n_time_slice_spans = (int *)mCalloc(2*n_otu-1,sizeof(int)); + rates->curr_slice = (int *)mCalloc(2*n_otu-1,sizeof(int)); + rates->has_survived = (int *)mCalloc(2*n_otu-1,sizeof(int)); + rates->survival_rank = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->survival_dur = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->calib_prob = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->t_prior_min_ori = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->t_prior_max_ori = (phydbl *)mCalloc(2*n_otu-1,sizeof(phydbl)); + rates->times_partial_proba = (phydbl *)mCalloc(n_otu*n_otu,sizeof(phydbl)); + rates->numb_calib_chosen = (int *)mCalloc(n_otu*n_otu,sizeof(phydbl)); + rates->a_cal = (t_cal **)mCalloc(10*n_otu,sizeof(t_cal *)); + rates->model_name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + } + + return rates; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_cal *Make_Calibration() +{ + t_cal *calib; + calib = (t_cal *)mCalloc(1, sizeof(t_cal)); + return(calib); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_clad *Make_Clade() +{ + t_clad *clade; + clade = (t_clad *)mCalloc(1, sizeof(t_clad)); + return(clade); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +t_node **Make_Target_Tip(int n) +{ + t_node **this; + this = (t_node **)mCalloc(n,sizeof(t_node *)); + return(this); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_All_Calibration(t_tree *tree) +{ + int i; + t_cal **all_cal; + + assert(tree->rates); + + all_cal = (t_cal **)mCalloc(2*tree->n_otu-1,sizeof(t_cal *)); + + For(i,2*tree->n_otu-1) all_cal[i] = Make_Calibration(); + + tree->rates->a_cal = all_cal; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Rmat_Weight(t_tree *mixt_tree) +{ + t_tree *tree, *buff_tree; + scalar_dbl *curr_weight; + + tree = mixt_tree; + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + + buff_tree = mixt_tree->next; + do + { + if(buff_tree->mod->r_mat_weight == tree->mod->r_mat_weight) break; + buff_tree = buff_tree->next; + } + while(buff_tree != tree); + + if(buff_tree == tree) Free(tree->mod->r_mat_weight); + + tree = tree->next; + } + while(tree); + + + tree = mixt_tree; + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + tree->mod->r_mat_weight = NULL; + tree = tree->next; + } + while(tree); + + + tree = mixt_tree->next; + tree->mod->r_mat_weight = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(tree->mod->r_mat_weight); + tree->mod->r_mat_weight->v = 1.0; + curr_weight = tree->mod->r_mat_weight; + + + buff_tree = tree = mixt_tree; + do // For each mixt_tree + { + if(tree->is_mixt_tree == YES) + { + tree = tree->next; + } + + buff_tree = mixt_tree->next; + do + { + if(buff_tree->mod->r_mat == tree->mod->r_mat) + { + tree->mod->r_mat_weight = buff_tree->mod->r_mat_weight; + break; + } + buff_tree = buff_tree->next; + } + while(buff_tree != tree); + + if(!tree->mod->r_mat_weight) + { + tree->mod->r_mat_weight = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(tree->mod->r_mat_weight); + tree->mod->r_mat_weight->v = 1.0; + curr_weight->next = tree->mod->r_mat_weight; + tree->mod->r_mat_weight->prev = curr_weight; + curr_weight = tree->mod->r_mat_weight; + } + + tree = tree->next; + + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Efrq_Weight(t_tree *mixt_tree) +{ + t_tree *tree, *buff_tree; + scalar_dbl *curr_weight; + + + tree = mixt_tree; + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + + buff_tree = mixt_tree->next; + do + { + if(buff_tree->mod->e_frq_weight == tree->mod->e_frq_weight) break; + buff_tree = buff_tree->next; + } + while(buff_tree != tree); + + if(buff_tree == tree) + { + Free(tree->mod->e_frq_weight); + } + + tree = tree->next; + } + while(tree); + + + tree = mixt_tree; + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + tree->mod->e_frq_weight = NULL; + tree = tree->next; + } + while(tree); + + + tree = mixt_tree->next; + tree->mod->e_frq_weight = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(tree->mod->e_frq_weight); + tree->mod->e_frq_weight->v = 1.0; + curr_weight = tree->mod->e_frq_weight; + + + buff_tree = tree = mixt_tree; + do // For each mixt_tree + { + if(tree->is_mixt_tree == YES) tree = tree->next; + + buff_tree = mixt_tree->next; + do + { + if(buff_tree->mod->e_frq == tree->mod->e_frq) + { + tree->mod->e_frq_weight = buff_tree->mod->e_frq_weight; + break; + } + buff_tree = buff_tree->next; + } + while(buff_tree != tree); + + if(!tree->mod->e_frq_weight) + { + tree->mod->e_frq_weight = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(tree->mod->e_frq_weight); + tree->mod->e_frq_weight->v = 1.0; + curr_weight->next = tree->mod->e_frq_weight; + tree->mod->e_frq_weight->prev = curr_weight; + curr_weight = tree->mod->e_frq_weight; + } + + tree = tree->next; + + } + while(tree); + } + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_geo *GEO_Make_Geo_Basic() +{ + t_geo *t; + t = (t_geo *)mCalloc(1,sizeof(t_geo)); + return(t); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void GEO_Make_Geo_Complete(int ldscape_sz, int n_dim, int n_tax, t_geo *t) +{ + int i; + + // F matrix + t->f_mat = (phydbl *)mCalloc(ldscape_sz*ldscape_sz,sizeof(phydbl)); + + // R matrix + t->r_mat = (phydbl *)mCalloc(ldscape_sz*ldscape_sz,sizeof(phydbl)); + + // Occupation vectors: one vector for each node + t->occup = (int *)mCalloc((2*n_tax-1)*ldscape_sz,sizeof(int)); + + // Lineage locations + t->idx_loc = (int *)mCalloc((int)(2*n_tax-1),sizeof(int)); + + // Sorted node heights + t->sorted_nd = (t_node **)mCalloc((int)(2*n_tax-1),sizeof(t_node *)); + + // Covariance matrix + t->cov = (phydbl *)mCalloc((int)(n_dim*n_dim),sizeof(phydbl)); + + // gives the location occupied beneath each node in the tree + t->idx_loc_beneath = (int *)mCalloc((int)(2*n_tax-1)*ldscape_sz,sizeof(int)); + + // Locations + t->coord_loc = (t_geo_coord **)mCalloc(ldscape_sz,sizeof(t_geo_coord *)); + for(i=0;icoord_loc[i] = GEO_Make_Geo_Coord(n_dim); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_geo_coord *GEO_Make_Geo_Coord(int dim) +{ + t_geo_coord *t; + t = (t_geo_coord *)mCalloc(1,sizeof(t_geo_coord)); + t->lonlat = (phydbl *)mCalloc(dim,sizeof(phydbl)); + t->id = (char *)mCalloc(T_MAX_ID_COORD,sizeof(char)); + + t->cpy = (t_geo_coord *)mCalloc(1,sizeof(t_geo_coord)); + t->cpy->lonlat = (phydbl *)mCalloc(dim,sizeof(phydbl)); + t->cpy->id = (char *)mCalloc(T_MAX_ID_COORD,sizeof(char)); + + return(t); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_phyrex_mod *PHYREX_Make_Migrep_Model(int dim) +{ + t_phyrex_mod *t; + t = (t_phyrex_mod *)mCalloc(1,sizeof(t_phyrex_mod)); + t->lim_up = GEO_Make_Geo_Coord(dim); + t->lim_do = GEO_Make_Geo_Coord(dim); + return(t); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_dsk *PHYREX_Make_Disk_Event(int n_dim, int n_otu) +{ + t_dsk *t; + + t = (t_dsk *)mCalloc(1,sizeof(t_dsk)); + t->centr = GEO_Make_Geo_Coord(n_dim); + t->id = (char *)mCalloc(T_MAX_ID_DISK,sizeof(char)); + t->ldsk_a = (t_ldsk **)mCalloc(n_otu,sizeof(t_ldsk *)); + + return(t); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_ldsk *PHYREX_Make_Lindisk_Node(int n_dim) +{ + t_ldsk *t; + t = (t_ldsk *)mCalloc(1,sizeof(t_ldsk)); + t->coord = GEO_Make_Geo_Coord(n_dim); + t->cpy_coord = GEO_Make_Geo_Coord(n_dim); + return(t); +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void PHYREX_Make_Lindisk_Next(t_ldsk *t) +{ + + if(t->n_next == 0) + t->next = (t_ldsk **)mCalloc(NEXT_BLOCK_SIZE,sizeof(t_ldsk *)); + else if(!(t->n_next%NEXT_BLOCK_SIZE)) + t->next = (t_ldsk **)mRealloc(t->next,t->n_next+NEXT_BLOCK_SIZE,sizeof(t_ldsk *)); + + t->n_next++; + /* PhyML_Printf("\n. make next for ldsk %s n_next set to %d [%p] %d",t->coord->id,t->n_next,t->next,NEXT_BLOCK_SIZE); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_poly *Make_Poly(int n) +{ + t_poly *p; + int i; + p = (t_poly *)mCalloc(1,sizeof(t_poly)); + p->poly_vert = (t_geo_coord **)mCalloc(n,sizeof(t_geo_coord *)); + for(i=0;ipoly_vert[i] = GEO_Make_Geo_Coord(2); + return(p); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_sarea *Make_Sarea(int n_poly) +{ + t_sarea *s; + s = (t_sarea *)mCalloc(1,sizeof(t_sarea )); + s->a_poly = (t_poly **)mCalloc(n_poly,sizeof(t_poly *)); + return(s); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_ll *Make_Linked_List() +{ + t_ll *list; + + // Create list if non-existing and add + list = (t_ll *)mCalloc(1,sizeof(t_ll)); + + return list; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Matrices used in transfer bootstrap computation (tbe.c) */ +void Alloc_TBE_Matrices(int n_otu, short unsigned*** i_matrix, short unsigned*** c_matrix,short unsigned*** hamming, short unsigned** min_dist, short unsigned** min_dist_edge, int** cluster_sizes){ + int i; + int nb_edges = 2*n_otu-3; + (*min_dist) = (short unsigned*) malloc(nb_edges*sizeof(short unsigned)); /* array of min Hamming distances */ + (*min_dist_edge) = (short unsigned*) malloc(nb_edges*sizeof(short unsigned)); /* array of edge ids corresponding to min Hamming distances */ + (*cluster_sizes) = (int*) malloc(nb_edges*sizeof(int)); /* array of sizes of clusters associated to each branch (in the post order traversal) */ + (*c_matrix) = (short unsigned**) malloc(nb_edges*sizeof(short unsigned*)); /* matrix of cardinals of complements */ + (*i_matrix) = (short unsigned**) malloc(nb_edges*sizeof(short unsigned*)); /* matrix of cardinals of intersections */ + (*hamming) = (short unsigned**) malloc(nb_edges*sizeof(short unsigned*)); /* matrix of Hamming distances */ + for (i=0; iC A<->G A<->T C<->G C<->T G<->T) + do + { + tree->mutmap = (int *)mCalloc((2*tree->n_otu-3)*(tree->n_pattern)*6,sizeof(int)); + tree = tree->next_mixt; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_label *Make_Label() +{ + t_label *lab; + + lab = (t_label *)mCalloc(1,sizeof(t_label)); + lab->key = (char *)mCalloc(T_MAX_KEY,sizeof(char)); + lab->val = (char *)mCalloc(T_MAX_VAL,sizeof(char)); + lab->next = NULL; + + return(lab); +} + + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + diff --git a/phyml/make.h b/phyml/make.h new file mode 100644 index 0000000..482d41c --- /dev/null +++ b/phyml/make.h @@ -0,0 +1,87 @@ +/* + +PHYML : a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences + +Copyright (C) Stephane Guindon. Oct 2003 onward + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef MAKE_H +#define MAKE_H + +#include "utilities.h" + +void Make_All_Edges_Lk(t_node *a,t_node *d,t_tree *tree); +t_edge *Make_Edge_Light(t_node *a,t_node *d,int num); +void Make_Edge_Pars(t_edge *b,t_tree *tree); +void Make_Edge_Pars_Left(t_edge *b,t_tree *tree); +void Make_Edge_Pars_Rght(t_edge *b,t_tree *tree); +void Make_Edge_Lk(t_edge *b,t_tree *tree); +void Make_Edge_Lk_Left(t_edge *b,t_tree *tree); +void Make_Edge_Lk_Rght(t_edge *b,t_tree *tree); +void Make_Edge_NNI(t_edge *b); +t_nni *Make_NNI(); +t_node *Make_Node_Light(int num); +void Make_Node_Lk(t_node *n); +nexcom **Make_Nexus_Com(); +nexparm *Make_Nexus_Parm(); +matrix *Make_Mat(int n_otu); +t_tree *Make_Tree_From_Scratch(int n_otu,calign *data); +t_tree *Make_Tree(int n_otu); +void Make_Tree_Path(t_tree *tree); +void Make_All_Tree_Nodes(t_tree *tree); +void Make_All_Tree_Edges(t_tree *tree); +calign *Make_Calign(int n_otu,int crunch_len,int state_len,int init_len,char **sp_names,int n_rm,char **sp_names_out); +t_treelist *Make_Treelist(int list_size); +t_opt *Make_Optimiz(); +void Make_Custom_Model(t_mod *mod); +t_mod *Make_Model_Basic(); +void Make_Model_Complete(t_mod *mod); +t_efrq *Make_Efrq(int ns); +t_rmat *Make_Rmat(int ns); +option *Make_Input(); +eigen *Make_Eigen_Struct(int ns); +void Make_Short_L(t_tree *tree); +void Make_RAS_Complete(t_ras *ras); +t_ras *Make_RAS_Basic(); +void Make_Best_Spr(t_tree *tree); +void Make_Spr_List_One_Edge(t_tree *tree); +void Make_Spr_List_All_Edge(t_tree *tree); +t_spr *Make_One_Spr(t_tree *tree); +void Make_Tree_For_Pars(t_tree *tree); +void Make_Tree_For_Lk(t_tree *tree); +t_string *Make_String(int len); +t_mcmc *MCMC_Make_MCMC_Struct(); +void Make_Tree_4_Lk(t_tree *tree,calign *cdata,int n_site); +t_rate *RATES_Make_Rate_Struct(int n_otu); +t_cal *Make_Calibration(); +void Make_Efrq_Weight(t_tree *mixt_tree); +void Make_Rmat_Weight(t_tree *mixt_tree); +t_geo *GEO_Make_Geo_Basic(); +void GEO_Make_Geo_Complete(int ldscape_sz,int n_dim,int n_tax,t_geo *t); +t_geo_coord *GEO_Make_Geo_Coord(int n_dim); +t_phyrex_mod *PHYREX_Make_Migrep_Model(); +t_dsk *PHYREX_Make_Disk_Event(int n_dim, int n_otu); +t_ldsk *PHYREX_Make_Lindisk_Node(int n_dim); +void PHYREX_Make_Lindisk_Next(t_ldsk *t); +t_poly *Make_Poly(int n); +void Make_All_Calibration(t_tree *tree); +t_sarea *Make_Sarea(int n_poly); +void Make_Edge_Loc(t_edge *b, t_tree *tree); +void Make_Edge_Loc_Rght(t_edge *b, t_tree *tree); +void Make_Edge_Loc_Left(t_edge *b, t_tree *tree); +t_ll *Make_Linked_List(); +t_node **Make_Target_Tip(int n); +t_clad *Make_Clade(); +void Alloc_TBE_Matrices(int n_otu, short unsigned*** i_matrix, short unsigned*** c_matrix,short unsigned*** hamming, + short unsigned** min_dist, short unsigned** min_dist_edge, int** cluster_sizes); +void Make_Extra_Edge_Lk(t_tree *tree); +void Make_Spr(t_tree *tree); +t_label *Make_Label(); +#endif diff --git a/phyml/mc.c b/phyml/mc.c deleted file mode 100644 index 7fe9584..0000000 --- a/phyml/mc.c +++ /dev/null @@ -1,1069 +0,0 @@ -/* - -PhyML: a program that computes maximum likelihood phylogenies from -DNA or AA homologous sequences. - -Copyright (C) Stephane Guindon. Oct 2003 onward. - -All parts of the source except where indicated are distributed under -the GNU public licence. See http://www.opensource.org for details. - -*/ - - -/* Routines for molecular clock trees and molecular dating */ - -#include "spr.h" -#include "utilities.h" -#include "lk.h" -#include "optimiz.h" -#include "bionj.h" -#include "models.h" -#include "free.h" -#include "options.h" -#include "simu.h" -#include "eigen.h" -#include "pars.h" -#include "alrt.h" -#include "mc.h" -#include "m4.h" -#include "draw.h" -#include "rates.h" - - -/*********************************************************/ - -int MC_main(int argc, char **argv) -{ - seq **data; - allseq *alldata; - option *io; - arbre *tree; - int n_otu, num_data_set; - int num_tree,tree_line_number,num_rand_tree; - matrix *mat; - model *mod; - m4 *m4mod; - time_t t_beg,t_end; - div_t hour,min; - phydbl best_lnL; - int bootstrap_this_tree; - int r_seed; - - -#ifdef QUIET - setvbuf(stdout,NULL,_IOFBF,2048); -#endif - - tree = NULL; - mod = NULL; - data = NULL; - bootstrap_this_tree = 1; - best_lnL = UNLIKELY; - - io = (option *)Get_Input(argc,argv); - r_seed = (io->r_seed < 0)?(time(NULL)):(io->r_seed); - srand(r_seed); - Make_Model_Complete(io->mod); - mod = io->mod; - m4mod = mod->m4mod; - if(io->in_tree) Test_Multiple_Data_Set_Format(io); - else io->n_trees = 1; - - if(io->mod->s_opt->random_input_tree) bootstrap_this_tree = 0; - - mat = NULL; - tree_line_number = 0; - - if((io->n_data_sets > 1) && (io->n_trees > 1)) - { - io->n_data_sets = MIN(io->n_trees,io->n_data_sets); - io->n_trees = MIN(io->n_trees,io->n_data_sets); - } - - For(num_data_set,io->n_data_sets) - { - n_otu = 0; - best_lnL = UNLIKELY; - data = Get_Seq(io,0); - - if(data) - { - if(io->n_data_sets > 1) printf("\n. Data set [#%d]\n",num_data_set+1); - printf("\n. Compressing sequences...\n"); - alldata = Compact_Seq(data,io); - Free_Seq(data,alldata->n_otu); - Check_Ambiguities(alldata,io->mod->datatype,io->mod->stepsize); - - for(num_tree=(io->n_trees == 1)?(0):(num_data_set);num_tree < io->n_trees;num_tree++) - { - if(!io->mod->s_opt->random_input_tree) io->mod->s_opt->n_rand_starts = 1; - - For(num_rand_tree,io->mod->s_opt->n_rand_starts) - { - if((io->mod->s_opt->random_input_tree) && (io->mod->s_opt->topo_search == SPR_MOVE)) - printf("\n. [Random start %3d/%3d]\n",num_rand_tree+1,io->mod->s_opt->n_rand_starts); - - Init_Model(alldata,mod); - if(io->m4_model) M4_Init_Model(m4mod,alldata,mod); - - if(!io->in_tree) - { - printf("\n. Computing pairwise distances...\n"); - mat = ML_Dist(alldata,mod); - Fill_Missing_Dist(mat); - printf("\n. Building BIONJ tree...\n"); - mat->tree = Make_Tree_From_Scratch(alldata->n_otu,alldata); - Bionj(mat); - tree = mat->tree; - tree->mat = mat; - - } - else - { - if((io->n_trees == 1) || (!num_tree)) - { - rewind(io->fp_in_tree); - tree_line_number = 0; - } - - if(io->n_trees > 1) printf("\n. Reading tree [#%d]\n",tree_line_number+1); - else printf("\n. Reading tree...\n"); - fflush(NULL); - - tree = Read_Tree_File(io->fp_in_tree); - tree_line_number++; - - if(!tree) - { - printf("\n. Input tree not found...\n"); - Exit("\n\n"); - } - - if(!tree->has_branch_lengths) - { - printf("\n. Computing branch length estimates...\n"); - Order_Tree_CSeq(tree,alldata); - mat = ML_Dist(alldata,mod); - mat->tree = tree; - mat->method = 0; - Bionj_Br_Length(mat); - tree->mat = mat; - } - - tree->mod = mod; - tree->io = io; - tree->data = alldata; - tree->both_sides = 1; - tree->n_pattern = tree->data->crunch_len/tree->mod->stepsize; - } - - if(!tree) continue; - - time(&t_beg); - time(&(tree->t_beg)); - - tree->mod = mod; - tree->io = io; - tree->data = alldata; - tree->both_sides = 1; - tree->n_pattern = tree->data->crunch_len/tree->mod->stepsize; - - if((!num_data_set) && (!num_tree) && (!num_rand_tree)) - { -#ifndef BATCH - Check_Memory_Amount(tree); -#endif - } - - Order_Tree_CSeq(tree,alldata); - - if((tree->mod->s_opt->random_input_tree) && (tree->mod->s_opt->topo_search == SPR_MOVE)) - { - printf("\n. Randomising the tree...\n"); - Random_Tree(tree); - } - - Fill_Dir_Table(tree); - Update_Dirs(tree); - Make_Tree_4_Pars(tree,alldata,alldata->init_len); - Make_Tree_4_Lk(tree,alldata,alldata->init_len); - tree->triplet_struct = Make_Triplet_Struct(mod); - Br_Len_Not_Involving_Invar(tree); - - if((tree->mod->s_opt->topo_search == SPR_MOVE) || - (tree->mod->s_opt->topo_search == NNI_MOVE && - tree->mod->s_opt->spr_step_after_nnis)) - { - Make_Spr_List(tree); - Make_Best_Spr(tree); - } - -/* M4_Site_Branch_Classification_Experiment(tree); */ -/* Exit("\n"); */ - -/* M4_Detect_Site_Switches_Experiment(tree); */ -/* Site_Diversity(tree); */ -/* M4_Posterior_Prediction_Experiment(tree); */ -/* Exit("\n"); */ - - if(tree->mod->s_opt->opt_topo) - { - if(tree->mod->s_opt->topo_search == NNI_MOVE) - { - Simu_Loop(tree); - } - else - { - if(tree->mod->s_opt->steph_spr) - { - Speed_Spr_Loop(tree); - } - else - { - Init_SPR(tree); - Optim_SPR(tree,0,ALL); - Clean_SPR(tree); - } - } - } - else - { - if(tree->mod->s_opt->opt_num_param || tree->mod->s_opt->opt_bl) - { - Round_Optimize(tree,tree->data); - } - else - { - Lk(tree); - Print_Lk(tree,""); - } - } - - - Lk(tree); - printf("\n. Best unconstrained lnL = %f",tree->c_lnL); - fprintf(tree->io->fp_out_stats,"\n. Best unconstrained lnL = %f",tree->c_lnL); - fprintf(tree->io->fp_out_tree,"\n[unconstrained tree] = %s\n",Write_Tree(tree)); - fflush(NULL); - - Record_Br_Len(tree); - - edge *best_edge; - tree->bl_from_node_stamps = 1; - tree->rates = RATES_Make_Rate_Struct(tree); - RATES_Init_Rate_Struct(tree->rates,tree); - best_edge = MC_Find_Best_Root_Position_Approx(tree); - MC_Least_Square_Node_Times(best_edge,tree); - MC_Adjust_Node_Times(tree); - MC_Round_Optimize(tree); - MC_Estimate_Branch_Rate_Parameter(tree); - MC_Classify_Branch_Rates(tree); -/* MC_Compute_Rates_And_Times_Least_Square_Adjustments(tree); */ - RATES_Print_Rates(tree); - For(tree->rates->curr_mc_run,tree->rates->n_mc_runs) RATES_Monte_Carlo_Mean_Rates(tree); - - int i,j,k; - phydbl density; - phydbl **x, *where; - - where = (phydbl *)mCalloc(1,sizeof(phydbl)); - x = (phydbl **)mCalloc(1,sizeof(phydbl)); - x[0] = (phydbl *)mCalloc(tree->rates->n_mc_runs,sizeof(phydbl)); - - printf("\n. Kernel values \n"); - For(i,2*tree->n_otu-1) - { - For(j,tree->rates->n_mc_runs) - { - density = Univariate_Kernel_Density_Estimate(tree->rates->mc_mr[i][j], - tree->rates->mc_mr[i], - tree->rates->n_mc_runs); - - printf("\nS %d %f %f",i,tree->rates->mc_mr[i][j],density); - - where[0] = tree->rates->mc_mr[i][j]; - For(k,tree->rates->n_mc_runs) - { - x[0][k] = tree->rates->mc_mr[i][k]; - } - density = Multivariate_Kernel_Density_Estimate(where, - x, - tree->rates->n_mc_runs, - 1); - - printf("\nM %d %f %f",i,tree->rates->mc_mr[i][j],density); - } - } - - tree->bl_from_node_stamps = 0; - - -/* /\* Constrain the tree to be molecular-clock like and find best root position *\/ */ -/* tree->bl_from_node_stamps = 1; */ -/* edge *best_edge; */ -/* best_edge = MC_Find_Best_Root_Position(tree); */ -/* /\* best_edge = Find_Edge_With_Label("ROOT",tree); *\/ */ -/* if(!best_edge) */ -/* { */ -/* printf("\n. Could not find the root !"); */ -/* Warn_And_Exit("\n"); */ -/* } */ - - - if(tree->io->ratio_test) aLRT(tree); - - Lk(tree); - printf("\n\n. Final log likelihood : %f",tree->c_lnL); - - - if((tree->c_lnL > best_lnL) && (io->mod->s_opt->n_rand_starts > 1)) - { - best_lnL = tree->c_lnL; - io->fp_out_best_tree = (FILE *)fopen(io->out_best_tree_file,"w"); - Print_Tree(io->fp_out_best_tree,tree); - fflush(NULL); - fclose(io->fp_out_best_tree); - } - - if((tree->mod->bootstrap) && (bootstrap_this_tree)) - { - if(num_rand_tree > 0) io->in_tree = 0; - Bootstrap(tree); - tree->mod->bootstrap = 0; - } - - Br_Len_Involving_Invar(tree); - Print_Tree(io->fp_out_tree,tree); - - Unconstraint_Lk(tree); - time(&t_end); - hour = div(t_end-t_beg,3600); - min = div(t_end-t_beg,60 ); - min.quot -= hour.quot*60; - printf("\n\n. Time used %dh%dm%ds\n", hour.quot,min.quot,(int)(t_end-t_beg)%60); - printf("\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); - Print_Fp_Out(io->fp_out_stats,t_beg,t_end,tree, - io,num_data_set+1, - (tree->mod->s_opt->n_rand_starts > 1)?(num_rand_tree):(num_tree)); - - if(tree->io->print_site_lnl) Print_Site_Lk(tree,io->fp_out_lk); - - /* Start from BioNJ tree */ - if((num_rand_tree == io->mod->s_opt->n_rand_starts-1) - && (io->mod->s_opt->n_rand_starts > 1) - && (tree->mod->s_opt->random_input_tree)) - { - num_rand_tree--; - tree->mod->s_opt->random_input_tree = 0; - } - - if((num_rand_tree == io->mod->s_opt->n_rand_starts - 1) && - (!tree->mod->s_opt->random_input_tree) && - (io->mod->s_opt->n_rand_starts > 1)) - { - if(tree->mod->bootstrap) - { - num_rand_tree--; - io->in_tree = 1; - io->fp_in_tree = io->fp_out_best_tree; - bootstrap_this_tree = 1; - io->fp_in_tree = (FILE *)fopen(io->out_best_tree_file,"r"); - } - else - { - io->fp_out_best_tree = (FILE *)fopen(io->out_best_tree_file,"w"); - Print_Tree(io->fp_out_best_tree,tree); - fflush(NULL); - fclose(io->fp_out_best_tree); - } - } - - if((tree->mod->s_opt->topo_search == SPR_MOVE) || - (tree->mod->s_opt->topo_search == NNI_MOVE && - tree->mod->s_opt->spr_step_after_nnis)) - { - Free_Spr_List(tree); - Free_One_Spr(tree->best_spr); - } - - if(tree->mat) Free_Mat(tree->mat); - Free_Triplet(tree->triplet_struct); - Free_Tree_Pars(tree); - Free_Tree_Lk(tree); - Free_Tree(tree); - } - if(io->n_trees > 1 && io->n_data_sets > 1) break; - } - Free_Cseq(alldata); - } - } - - if(io->mod->s_opt->n_rand_starts > 1) printf("\n\n. Best log likelihood : %f\n",best_lnL); - - Free_Model(mod); - - if(io->fp_in_seq) fclose(io->fp_in_seq); - if(io->fp_in_tree) fclose(io->fp_in_tree); - if(io->fp_out_lk) fclose(io->fp_out_lk); - if(io->fp_out_tree) fclose(io->fp_out_tree); - if(io->fp_out_stats) fclose(io->fp_out_stats); - - Free_Input(io); - return 0; -} - -/*********************************************************/ - -void MC_Least_Square_Node_Times(edge *e_root, arbre *tree) -{ - - /* Solve A.x = b, where x are the node time estimated - under the least square criterion. - - A is a n x n matrix, with n being the number of - nodes in a rooted tree (i.e. 2*n_otu-1). - */ - - phydbl *A, *b, *x; - int n; - int i,j; - node *root; - - - printf("\n. Making the tree molecular clock like."); - - n = 2*tree->n_otu-1; - - A = (phydbl *)mCalloc(n*n,sizeof(phydbl)); - b = (phydbl *)mCalloc(n, sizeof(phydbl)); - x = (phydbl *)mCalloc(n, sizeof(phydbl)); - - (e_root)?(Add_Root(e_root,tree)):(Add_Root(tree->t_edges[0],tree)); - - root = tree->n_root; - - MC_Least_Square_Node_Times_Pre(root,root->v[0],A,b,n,tree); - MC_Least_Square_Node_Times_Pre(root,root->v[1],A,b,n,tree); - - b[root->num] = tree->e_root->l/2.; - - A[root->num * n + root->num] = 1.0; - A[root->num * n + root->v[0]->num] = -.5; - A[root->num * n + root->v[1]->num] = -.5; - - Matinv(A, n, n, NULL); - - For(i,n) x[i] = .0; - For(i,n) For(j,n) x[i] += A[i*n+j] * b[j]; - - For(i,n-1) tree->noeud[i]->t = x[i] / tree->rates->mean_r; - root->t = x[n-1] / tree->rates->mean_r; - - Free(A); - Free(b); - Free(x); - -} - -/*********************************************************/ - -void MC_Least_Square_Node_Times_Pre(node *a, node *d, phydbl *A, phydbl *b, int n, arbre *tree) -{ - if(d->tax) - { - A[d->num * n + d->num] = 1.; - - /* Set the time stamp at tip nodes to 0.0 */ -/* printf("\n. Tip node date set to 0"); */ - b[d->num] = 0.0; - return; - } - else - { - int i; - - For(i,3) - if((d->v[i] != a) && (d->b[i] != tree->e_root)) - MC_Least_Square_Node_Times_Pre(d,d->v[i],A,b,n,tree); - - A[d->num * n + d->num] = 1.; - b[d->num] = .0; - For(i,3) - { - A[d->num * n + d->v[i]->num] = -1./3.; - if(d->v[i] != a) b[d->num] += d->b[i]->l; - else b[d->num] -= d->b[i]->l; - } - b[d->num] /= 3.; - } -} - -/*********************************************************/ - -/* Adjust node times in order to have correct time stamp ranking with - respect to the tree topology */ - -void MC_Adjust_Node_Times(arbre *tree) -{ - MC_Adjust_Node_Times_Pre(tree->n_root->v[0],tree->n_root->v[1],tree); - MC_Adjust_Node_Times_Pre(tree->n_root->v[1],tree->n_root->v[0],tree); - if(tree->n_root->t < MAX(tree->n_root->v[0]->t,tree->n_root->v[1]->t)) -/* tree->n_root->t = MAX(tree->n_root->v[0]->t,tree->n_root->v[1]->t) + BL_MIN; */ - tree->n_root->t = MAX(tree->n_root->v[0]->t,tree->n_root->v[1]->t); -} - -/*********************************************************/ - -void MC_Adjust_Node_Times_Pre(node *a, node *d, arbre *tree) -{ - if(d->tax) return; - else - { - int i; - phydbl max_height; - - For(i,3) - if((d->v[i] != a) && (d->b[i] != tree->e_root)) - { - MC_Adjust_Node_Times_Pre(d,d->v[i],tree); - } - - max_height = -1.0; - For(i,3) - { - if((d->v[i] != a) && (d->b[i] != tree->e_root)) - { - if(d->v[i]->t > max_height) - { - max_height = d->v[i]->t; - } - } - } - - if(d->t < max_height) - { -/* d->t = max_height + BL_MIN; */ - d->t = max_height; - } - } -} -/*********************************************************/ - - /* Multiply each time stamp at each internal - node by 'tree->time_stamp_mult'. - */ - -void MC_Mult_Time_Stamps(arbre *tree) -{ - int i; - For(i,2*tree->n_otu-2) tree->noeud[i]->t *= fabs(tree->mod->s_opt->tree_size_mult); - tree->n_root->t *= fabs(tree->mod->s_opt->tree_size_mult); -} - -/*********************************************************/ - -/* Divide each time stamp at each internal - node by 'tree->time_stamp_mult'. -*/ -void MC_Div_Time_Stamps(arbre *tree) -{ - int i; - For(i,2*tree->n_otu-2) tree->noeud[i]->t /= fabs(tree->mod->s_opt->tree_size_mult); - tree->n_root->t /= fabs(tree->mod->s_opt->tree_size_mult); -} - -/*********************************************************/ - -void MC_Bl_From_T(arbre *tree) -{ - phydbl mean_rate, branch_rate; - - /* Branch lengths are deduced from time stamps */ - MC_Bl_From_T_Post(tree->n_root,tree->n_root->v[0],NULL,tree); - MC_Bl_From_T_Post(tree->n_root,tree->n_root->v[1],NULL,tree); - - mean_rate = tree->rates->mean_r; - branch_rate = tree->rates->br_r[tree->e_root->num]; - - tree->e_root->l = - mean_rate * branch_rate * (tree->n_root->t - tree->e_root->left->t) + - mean_rate * branch_rate * (tree->n_root->t - tree->e_root->rght->t); - - /* -tree->e_root->left->t - tree->e_root->rght->t + 2*tree->n_root->t; */ - - /* Actual formula => tree->e_root->l = - (tree->n_root->t - tree->e_root->left->t) + - (tree->n_root->t - tree->e_root->rght->t); */ - - tree->n_root_pos = (tree->n_root->t - tree->e_root->left->t)/tree->e_root->l; - -} - -/*********************************************************/ - -void MC_Bl_From_T_Post(node *a, node *d, edge *b, arbre *tree) -{ - - if(b) - { - phydbl mean_rate, branch_rate; - - mean_rate = tree->rates->mean_r; - branch_rate = tree->rates->br_r[b->num]; - - b->l = (a->t - d->t) * mean_rate * branch_rate; - if(b->l < 0.0) - { - printf("\n. Correction failed."); - printf("\n. d->t = %f a->t = %f",d->t,a->t); - printf("\n. a->num=%d d->num=%d",a->num,d->num); - Warn_And_Exit("\n"); - } - } - - if(d->tax) return; - else - { - int i; - For(i,3) if((d->v[i] != a) && (d->b[i] != tree->e_root)) MC_Bl_From_T_Post(d,d->v[i],d->b[i],tree); - } -} - -/*********************************************************/ - -void MC_Round_Optimize(arbre *tree) -{ - int n_round,each; - phydbl lk_old, lk_new, tol; - - lk_new = UNLIKELY; - lk_old = UNLIKELY; - n_round = 0; - each = 5; - tol = 1.e-2; - - tree->both_sides = 1; - Lk(tree); - - while(n_round < ROUND_MAX) - { - if(tree->mod->s_opt->opt_bl) - { - MC_Optimize_Node_Times_Serie(tree->n_root,tree->n_root->v[0],NULL,tree); - MC_Optimize_Node_Times_Serie(tree->n_root,tree->n_root->v[1],NULL,tree); - MC_Optimize_Root_Height(tree); - } - - tree->both_sides = 1; - Lk(tree); - - if(tree->mod->s_opt->print) Print_Lk(tree,"[Node times ]"); - - lk_new = tree->c_lnL; - if((!each) || - (fabs(lk_new - lk_old) < tree->mod->s_opt->min_diff_lk_global)) - { - each = 1; - MC_Optimize_Tree_Height(tree); - Optimiz_All_Free_Param(tree,tree->mod->s_opt->print); - tree->both_sides = 1; - Lk(tree); - } - - lk_new = tree->c_lnL; - - if(lk_new < lk_old - tree->mod->s_opt->min_diff_lk_global*10.) - { - printf("\n. lk_new = %f lk_old = %f",lk_new,lk_old); - Warn_And_Exit("\n. Optimisation failed ! (Round_Optimize)\n"); - } - if(fabs(lk_new - lk_old) < tree->mod->s_opt->min_diff_lk_global) break; -/* if(fabs(lk_new - lk_old) < tree->mod->s_opt->min_diff_lk_local) break; */ - else lk_old = lk_new; - n_round++; - each--; - } -} - - - -/*********************************************************/ - -void MC_Optimize_Node_Times_Serie(node *a, node *d, edge *b, arbre *tree) -{ - int i; - - if(d->tax) return; - else - { - node *v1, *v2; /* the two sons of d */ - phydbl t_sup, t_inf; - phydbl lk_init; - - lk_init = tree->c_lnL; - - v1 = v2 = NULL; - For(i,3) if(d->v[i] != a) - { - if(!v1) v1 = d->v[i]; - else v2 = d->v[i]; - } - - t_inf = MAX(v1->t,v2->t); - t_sup = a->t; - - if(t_sup < t_inf - MDBL_MAX) - { - printf("\n. t_sup = %f t_inf = %f",t_sup,t_inf); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - else - { - Node_Time_Brent(t_inf,d->t,t_sup, - tree->mod->s_opt->min_diff_lk_local, - a,d,tree, - tree->mod->s_opt->brent_it_max); - } - - if(tree->c_lnL < lk_init - tree->mod->s_opt->min_diff_lk_local*10.) -/* if(tree->c_lnL < lk_init - 1.E-03) */ - { - printf("\n. t-inf= %f t-sup=%f t-est=%f",t_inf,t_sup,d->t); - printf("\n. %f -- %f",lk_init,tree->c_lnL); - printf("\n. a->num = %d, d->num = %d",a->num,d->num); - Warn_And_Exit("\n. Err. in MC_Optimize_Node_Times_Serie."); - } - -/* printf("\n. init_lnL = %f c_lnL = %f",lk_init,tree->c_lnL); */ - - For(i,3) - if((d->v[i] != a) && (d->b[i] != tree->e_root)) - { - Update_P_Lk(tree,d->b[i],d); - MC_Optimize_Node_Times_Serie(d,d->v[i],d->b[i],tree); - } - - For(i,3) - if((d->v[i] == a) || (d->b[i] == tree->e_root)) - { - Update_P_Lk(tree,d->b[i],d); - break; - } - } -} - -/*********************************************************/ - -void MC_Print_Node_Times(node *a, node *d, arbre *tree) -{ - edge *b; - int i; - - b = NULL; - For(i,3) if((d->v[i]) && (d->v[i] == a)) {b = d->b[i]; break;} - - printf("\n. (%3d %3d) a->t = %f d->t = %f (#=%f) b->l = %f",a->num,d->num,a->t,d->t,a->t-d->t,(b)?(b->l):(-1.0)); - if(d->tax) return; - else - { - int i; - For(i,3) - if((d->v[i] != a) && (d->b[i] != tree->e_root)) - MC_Print_Node_Times(d,d->v[i],tree); - } -} - -/*********************************************************/ - -edge *MC_Find_Best_Root_Position(arbre *tree) -{ - int i; - edge *best_edge; - phydbl best_lnL,best_pos; - - Record_Br_Len(tree); - best_pos = -1.; - best_edge = NULL; - best_lnL = UNLIKELY; - For(i,2*tree->n_otu-3) - { - Restore_Br_Len(tree); - printf("\n. Root positioned on edge %3d",i); - MC_Least_Square_Node_Times(tree->t_edges[i],tree); - MC_Adjust_Node_Times(tree); - MC_Round_Optimize(tree); - if(tree->c_lnL > best_lnL) - { - best_lnL = tree->c_lnL; - best_edge = tree->t_edges[i]; - best_pos = tree->n_root_pos; - } - } - tree->n_root_pos = best_pos; /* Set the root node to its best position */ - printf("\n. Best root position: edge %3d",best_edge->num); - printf("\n. Best constrained lnL = %f",best_lnL); - fprintf(tree->io->fp_out_stats,"\n. Best constrained lnL = %f",best_lnL); - return best_edge; -} - -/*********************************************************/ - -edge *MC_Find_Best_Root_Position_Approx(arbre *tree) -{ - int i; - edge *best_edge; - phydbl best_lnL,best_pos; - - Record_Br_Len(tree); - best_pos = -1.; - best_edge = NULL; - best_lnL = UNLIKELY; - For(i,2*tree->n_otu-3) - { - Restore_Br_Len(tree); - printf("\n. Root positioned on edge %3d",i); - MC_Least_Square_Node_Times(tree->t_edges[i],tree); - MC_Adjust_Node_Times(tree); - Lk(tree); - printf("\n. LnL = %f",tree->c_lnL); - if(tree->c_lnL > best_lnL) - { - best_lnL = tree->c_lnL; - best_edge = tree->t_edges[i]; - best_pos = tree->n_root_pos; - } - } - tree->n_root_pos = best_pos; /* Set the root node to its best position */ - printf("\n. Best root position: edge %3d",best_edge->num); - printf("\n. Best constrained lnL = %f",best_lnL); - fprintf(tree->io->fp_out_stats,"\n. Best constrained lnL = %f",best_lnL); - return best_edge; -} - -/*********************************************************/ - -void MC_Optimize_Tree_Height(arbre *tree) -{ - tree->mod->s_opt->tree_size_mult = 1.0; - Time_Stamps_Mult_Brent(0.1,1.0,10.0, - tree->mod->s_opt->min_diff_lk_global, - tree,100); -} - -/*********************************************************/ - -void MC_Optimize_Root_Height(arbre *tree) -{ - /* - t_root - --x--- -l_2 / mu | | l_2 / mu - | | - x x t_r -l_1 / mu | - | - x t_l - - l* = 2 l_2 + l_1 is the ML estimate of the root branch length. - l_1 = (Max(t_l,t_r) - Min(t_l,t_r)) * mu - l_2 = (l* - l1)/2 - t_root = Max(t_l,t_r) + l_2 / mu - - */ - - phydbl l_1, l_2; - phydbl mean_rate, branch_rate; - - mean_rate = tree->rates->mean_r; - branch_rate = tree->rates->br_r[tree->e_root->num]; - - Br_Len_Brent_Default(tree->e_root,tree); - - l_1 = - (MAX(tree->e_root->left->t,tree->e_root->rght->t) - - MIN(tree->e_root->left->t,tree->e_root->rght->t)) * - mean_rate * branch_rate; - - l_2 = (tree->e_root->l - l_1) / 2.; - - if(l_2 < 0.0) - { - l_2 = 0.0; - tree->e_root->l = l_1; - Lk_At_Given_Edge(tree->e_root,tree); - } - - tree->n_root->t = - MAX(tree->e_root->left->t,tree->e_root->rght->t) + - l_2 / (mean_rate * branch_rate); - -/* /\* Check that the optimal 'root branch' length is longer than the */ -/* lower bound determined by time stamps on the left and */ -/* right handside of the root branch */ -/* *\/ */ -/* if(tree->e_root->l < */ -/* MAX(tree->e_root->left->t,tree->e_root->rght->t) - */ -/* MIN(tree->e_root->left->t,tree->e_root->rght->t)) */ -/* { */ -/* tree->e_root->l = */ -/* MAX(tree->e_root->left->t,tree->e_root->rght->t) - */ -/* MIN(tree->e_root->left->t,tree->e_root->rght->t); */ -/* Lk_At_Given_Edge(tree->e_root,tree); */ -/* } */ - -/* tree->n_root->t = .5 * (tree->e_root->l + tree->e_root->left->t + tree->e_root->rght->t); */ - -/* /\* printf("\n. Root->t = %f left->t=%f rght->t=%f e_root->l=%f", *\/ */ -/* /\* tree->n_root->t, *\/ */ -/* /\* tree->e_root->left->t, *\/ */ -/* /\* tree->e_root->rght->t, *\/ */ -/* /\* tree->e_root->l); *\/ */ - - if((tree->n_root->t < tree->e_root->left->t-1.E-4) || - (tree->n_root->t < tree->e_root->rght->t-1.E-4)) - { - printf("\n. t_root = %f t_left = %f t_rght = %f", - tree->n_root->t, - tree->e_root->left->t, - tree->e_root->rght->t); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } -} - -/*********************************************************/ - -void MC_Estimate_Branch_Rate_Parameter(arbre *tree) -{ - - /* The tree should be clock-like already */ - Branch_Rate_Shape_Brent(0.3, tree->mod->rr_branch_alpha, 100., - tree->mod->s_opt->min_diff_lk_global, - &(tree->mod->rr_branch_alpha), - tree,tree->mod->s_opt->brent_it_max); -} - -/*********************************************************/ - -void MC_Compute_Rates_And_Times_Least_Square_Adjustments(arbre *tree) -{ - MC_Compute_Rates_And_Times_Least_Square_Adjustments_Post(tree->n_root,tree->n_root->v[0],NULL,tree); - MC_Compute_Rates_And_Times_Least_Square_Adjustments_Post(tree->n_root,tree->n_root->v[1],NULL,tree); -} - -/*********************************************************/ - -void MC_Compute_Rates_And_Times_Least_Square_Adjustments_Post(node *a, node *d, edge *b, arbre *tree) -{ - int i; - - if(d->tax) return; - - if(b) - { - phydbl t0, t1, t2, t3; - phydbl mu1, mu2, mu3; - phydbl K; - - t0 = a->t; - t1 = d->t; - - mu1 = tree->rates->br_r[b->num]; - mu2 = -1.; - mu3 = -1.; - - t2 = t3 = -1.; - For(i,3) - if(d->v[i] != a) - { - if(t2 < 0) - { - t2 = d->v[i]->t; - mu2 = tree->rates->br_r[d->b[i]->num]; - } - if(t3 < 0) - { - t3 = d->v[i]->t; - mu3 = tree->rates->br_r[d->b[i]->num]; - } - } - - printf("\n. t0=%f, t1=%f, t2=%f, t3=%f, mu1=%f, mu2=%f, mu3=%f", - t0,t1,t2,t3, - mu1,mu2,mu3); - - if(t2 < 1.E-10 && t3 < 1.E-10) - { - K = t0 / t1; - } - else - { - K = - (pow(mu2,2)*t2)/(pow(t1-t2,2)) + - (pow(mu1,2)*t0)/(pow(t0-t1,2)) + - (pow(mu3,2)*t3)/(pow(t1-t3,2)) + - (pow(mu1,2)*t0)/(pow(t0-t1,2)) + - mu2 * mu1 * (t0 + t2) / ((t1-t2)*(t0-t1)) + - mu3 * mu1 * (t0 + t3) / ((t1-t3)*(t0-t1)) ; - - K /= - t1 * - ( - (pow(mu2,2))/(pow(t1-t2,2)) + - (pow(mu1,2))/(pow(t0-t1,2)) + - (pow(mu3,2))/(pow(t1-t3,2)) + - (pow(mu1,2))/(pow(t0-t1,2)) + - 2.*mu2*mu1/((t1-t2)*(t0-t1)) + - 2.*mu3*mu1/((t1-t3)*(t0-t1)) - ); - } - printf("\n. K = %f",K); - } - - For(i,3) - if(d->v[i] != a) - MC_Compute_Rates_And_Times_Least_Square_Adjustments_Post(d,d->v[i],d->b[i],tree); - -} - -/*********************************************************/ - -void MC_Classify_Branch_Rates(arbre *tree) -{ - int br,rcat,best_post_prob_cat; - phydbl *post_prob; - phydbl best_post_prob; - edge *b; - - post_prob = (phydbl *)mCalloc(tree->mod->n_rr_branch,sizeof(phydbl)); - - Lk(tree); - - Record_Br_Len(tree); - - For(br,2*tree->n_otu-3) - { - b = tree->t_edges[br]; - post_prob = (phydbl *)Post_Prob_Rates_At_Given_Edge(b,post_prob,tree); - - best_post_prob = UNLIKELY; - best_post_prob_cat = -1; - For(rcat,tree->mod->n_rr_branch) - { - if(post_prob[rcat] > best_post_prob) - { - best_post_prob = post_prob[rcat]; - best_post_prob_cat = rcat; - } - } - tree->rates->br_r[br] = tree->mod->rr_branch[best_post_prob_cat]; - } - - Free(post_prob); -} - -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ diff --git a/phyml/mc.h b/phyml/mc.h deleted file mode 100644 index 457cb50..0000000 --- a/phyml/mc.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - -PhyML: a program that computes maximum likelihood phylogenies from -DNA or AA homologous sequences. - -Copyright (C) Stephane Guindon. Oct 2003 onward. - -All parts of the source except where indicated are distributed under -the GNU public licence. See http://www.opensource.org for details. - -*/ - -#ifndef MC_H -#define MC_H - -void MC_Least_Square_Node_Times_Pre(node *a, node *d, phydbl *A, phydbl *b, int n, arbre *tree); -int MC_main(int argc, char **argv); -void MC_Bl_From_T_Post(node *a, node *d, edge *b, arbre *tree); -void MC_Bl_From_T(arbre *tree); -void MC_Optimize_Node_Times_Serie(node *a, node *d, edge *b, arbre *tree); -void MC_Round_Optimize(arbre *tree); -void MC_Print_Node_Times(node *a, node *d, arbre *tree); -edge *MC_Find_Best_Root_Position(arbre *tree); -void MC_Least_Square_Node_Times(edge *e_root, arbre *tree); -void MC_Mult_Time_Stamps(arbre *tree); -void MC_Div_Time_Stamps(arbre *tree); -void MC_Optimize_Tree_Height(arbre *tree); -void MC_Adjust_Node_Times(arbre *tree); -void MC_Adjust_Node_Times_Pre(node *a, node *d, arbre *tree); -void MC_Optimize_Root_Height(arbre *tree); -void MC_Estimate_Branch_Rates(arbre *tree); -edge *MC_Find_Best_Root_Position_Approx(arbre *tree); -void MC_Estimate_Branch_Rate_Parameter(arbre *tree); -phydbl MC_Classify_Branch_In_Rate_Class(arbre *tree); -void MC_Compute_Rates_And_Times_Least_Square_Adjustments(arbre *tree); -void MC_Compute_Rates_And_Times_Least_Square_Adjustments_Post(node *a, node *d, edge *b, arbre *tree); -void MC_Classify_Branch_Rates(arbre *tree); - -#endif diff --git a/phyml/mcmc.c b/phyml/mcmc.c new file mode 100644 index 0000000..fa38e13 --- /dev/null +++ b/phyml/mcmc.c @@ -0,0 +1,10267 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "mcmc.h" + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Single_Param_Generic(phydbl *val, + phydbl lim_inf, + phydbl lim_sup, + int move_num, + phydbl *lnPrior, + phydbl *lnLike, + phydbl (*prior_func)(t_edge *,t_tree *,supert_tree *), + phydbl (*like_func)(t_edge *,t_tree *,supert_tree *), + int move_type, + int _log, /* _log == YES: the model describes the distribution of log(val) but the move applies to val. Need a correction factor */ + t_edge *branch, t_tree *tree, supert_tree *stree) +{ + phydbl cur_val,new_val,new_lnLike,new_lnPrior,cur_lnLike,cur_lnPrior; + phydbl u,alpha,ratio; + phydbl K; + phydbl new_lnval, cur_lnval; + + Record_Br_Len(tree); + + cur_val = *val; + new_val = -1.0; + ratio = 0.0; + K = tree->mcmc->tune_move[move_num]; + cur_lnval = log(*val); + new_lnval = cur_lnval; + + if(lnLike) + { + cur_lnLike = *lnLike; + new_lnLike = *lnLike; + } + else + { + cur_lnLike = 0.0; + new_lnLike = 0.0; + } + + if(lnPrior) + { + cur_lnPrior = *lnPrior; + new_lnPrior = *lnPrior; + } + else + { + cur_lnPrior = 0.0; + new_lnPrior = 0.0; + } + + MCMC_Make_Move(&cur_val,&new_val,lim_inf,lim_sup,&ratio,K,move_type); + + if(new_val < lim_sup && new_val > lim_inf) + { + *val = new_val; + + if(tree->rates) RATES_Update_Cur_Bl(tree); + + if(_log == YES) ratio += (cur_lnval - new_lnval); + + if(prior_func) /* Prior ratio */ + { + new_lnPrior = (*prior_func)(branch,tree,stree); + ratio += (new_lnPrior - cur_lnPrior); + } + + if(like_func) /* Likelihood ratio */ + { + new_lnLike = (*like_func)(branch,tree,stree); + ratio += (new_lnLike - cur_lnLike); + } + + /* printf("\n. %s cur_val: %f new_val:%f cur_lnL: %f new_lnL: %f cur_lnPrior: %f new_lnPrior: %f ratio: %f", */ + /* tree->mcmc->move_name[move_num], */ + /* cur_val, */ + /* new_val, */ + /* cur_lnLike, */ + /* new_lnLike, */ + /* cur_lnPrior, */ + /* new_lnPrior, */ + /* ratio); */ + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_lnLike > UNLIKELY) alpha = 1.0; + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + *val = cur_val; + new_val = cur_val; + if(lnPrior) *lnPrior = cur_lnPrior; + if(lnLike) *lnLike = cur_lnLike; + Restore_Br_Len(tree); + if(tree->mod && tree->mod->update_eigen) + { + if(!Update_Eigen(tree->mod)) + { + PhyML_Fprintf(stderr,"\n. Problem in move %s",tree->mcmc->move_name[tree->mcmc->move_idx]); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + } + else /* Accept */ + { + tree->mcmc->acc_move[move_num]++; + if(lnPrior) *lnPrior = new_lnPrior; + if(lnLike) *lnLike = new_lnLike; + } + } + + tree->mcmc->run_move[move_num]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +/* Formula from ``Markov chain Monte Carlo in practice: a roundtable discussion'', + Kass, Robert E and Carlin, Bradley P and Gelman, Andrew and Neal, Radford M + The American Statistician, 1998 +*/ +void MCMC_Update_Effective_Sample_Size(int move_num, t_mcmc *mcmc, t_tree *tree) +{ + int i,N,lag; + phydbl rho,mean,var,old_rho,act,ess; + int burnin; + + N = mcmc->sample_num+1; + + burnin = (int)(0.1*N); + if(burnin < 1) return; + + N -= burnin; + + mean = Weighted_Mean(mcmc->sampled_val+move_num*mcmc->sample_size+burnin,NULL,N); + var = Variance(mcmc->sampled_val+move_num*mcmc->sample_size+burnin,N); + + /* if(move_num == tree->mcmc->num_move_phyrex_sigsq) */ + /* printf("\n. %d %f %f\n",N,mean,var); */ + + act = -1.0; + old_rho = 1.0; + For(lag,MIN(N,mcmc->max_lag)) + { + rho = 0.0; + for(i=0;isampled_val[move_num*mcmc->sample_size+burnin+i] - mean) * + (mcmc->sampled_val[move_num*mcmc->sample_size+burnin+i+lag] - mean) ; + + rho /= (N - lag)*var; + + if(old_rho + rho < 0.0) + { + break; /* Geyer (1992) stopping criterion */ + } + + old_rho = rho; + + act += 2.*rho; + } + + if(act > 0.0) ess = N/act; + else ess = 0.0; + + mcmc->ess[move_num] = ess; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Update_Mode(int move_num, t_mcmc *mcmc, t_tree *tree) +{ + int i,j,N,best_bin; + int burnin,breaks,*bin_score,best_score; + phydbl min,max; + + breaks = 100; + bin_score = (int *)mCalloc(breaks,sizeof(int)); + + N = mcmc->sample_num+1; + + burnin = (int)(0.1*N); + if(burnin < 1) return; + + N -= burnin; + + min = +INFINITY; + for(i=0;isampled_val[move_num*mcmc->sample_size+burnin+i] < min) + min = mcmc->sampled_val[move_num*mcmc->sample_size+burnin+i]; + + max = -INFINITY; + for(i=0;isampled_val[move_num*mcmc->sample_size+burnin+i] > max) + max = mcmc->sampled_val[move_num*mcmc->sample_size+burnin+i]; + + + for(i=0;i mcmc->sampled_val[move_num*mcmc->sample_size+burnin+i]) + { + bin_score[j-1]++; + break; + } + } + + best_score = 0; + best_bin = 0; + for(j=0;j best_score) + { + best_score = bin_score[j]; + best_bin = j; + } + + mcmc->mode[move_num] = min + best_bin*(max-min)/breaks; + + Free(bin_score); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Clock_R(t_tree *tree) +{ + /* t_tree *tree; */ + + /* tree = mixt_tree; */ + /* do */ + /* { */ + /* MCMC_Single_Param_Generic(&(tree->rates->clock_r), */ + /* mixt_tree->rates->min_clock, */ + /* mixt_tree->rates->max_clock, */ + /* mixt_tree->mcmc->num_move_clock_r, */ + /* NULL,&(mixt_tree->c_lnL), */ + /* NULL,Wrap_Lk, */ + /* mixt_tree->mcmc->move_type[mixt_tree->mcmc->num_move_clock_r], */ + /* NO,NULL,mixt_tree,NULL); */ + + /* tree = tree->next; */ + /* } */ + /* while(tree); */ + + phydbl new_lnL_data, cur_lnL_data; + phydbl new_lnL_rate, cur_lnL_rate; + phydbl u, ratio, alpha; + phydbl new_clock_r, cur_clock_r; + phydbl min, max; + int move_num; + phydbl K; + + + /* PhyML_Printf("\n. %d %d",tree->eval_alnL,tree->mod->s_opt->opt_clock_r); */ + if(tree->mod->s_opt->opt_clock_r == NO) return; + + new_clock_r = tree->rates->clock_r; + cur_clock_r = tree->rates->clock_r; + min = tree->rates->min_clock; + max = tree->rates->max_clock; + ratio = 0.0; + move_num = tree->mcmc->num_move_clock_r; + K = tree->mcmc->tune_move[move_num]; + cur_lnL_data = tree->c_lnL; + new_lnL_data = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + + MCMC_Make_Move(&cur_clock_r,&new_clock_r,min,max,&ratio,K,tree->mcmc->move_type[move_num]); + + if(new_clock_r > min && new_clock_r < max) + { + tree->rates->clock_r = new_clock_r; + + RATES_Update_Cur_Bl(tree); + + if(tree->eval_alnL == YES) new_lnL_data = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + + ratio += (new_lnL_data - cur_lnL_data); + ratio += (new_lnL_rate - cur_lnL_rate); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* PhyML_Printf("\n. reject"); */ + tree->rates->clock_r = cur_clock_r; + tree->c_lnL = cur_lnL_data; + tree->rates->c_lnL_rates = cur_lnL_rate; + RATES_Update_Cur_Bl(tree); + } + else + { + /* PhyML_Printf("\n. accept"); */ + tree->mcmc->acc_move[move_num]++; + } + } + tree->mcmc->run_move[move_num]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#ifdef GEO +// Sample dispersal parameter from a phylogeo model +void MCMC_GEO_Sigma(t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + MCMC_Single_Param_Generic(&(tree->geo->sigma), + mixt_tree->geo->min_sigma, + mixt_tree->geo->max_sigma, + mixt_tree->mcmc->num_move_geo_sigma, + NULL,&(mixt_tree->geo->c_lnL), + NULL,GEO_Wrap_Lk, + mixt_tree->mcmc->move_type[mixt_tree->mcmc->num_move_geo_sigma], + NO,NULL,mixt_tree,NULL); + + GEO_Update_Fmat(tree->geo); + tree = tree->next; + } + while(tree); +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#ifdef GEO +// Sample competition parameter from a phylogeo model +void MCMC_GEO_Lbda(t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + MCMC_Single_Param_Generic(&(tree->geo->lbda), + mixt_tree->geo->min_lbda, + mixt_tree->geo->max_lbda, + mixt_tree->mcmc->num_move_geo_lambda, + NULL,&(mixt_tree->geo->c_lnL), + NULL,GEO_Wrap_Lk, + mixt_tree->mcmc->move_type[mixt_tree->mcmc->num_move_geo_lambda], + NO,NULL,mixt_tree,NULL); + + tree = tree->next; + } + while(tree); +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#ifdef GEO +// Sample global migration rate parameter from a phylogeo model +void MCMC_GEO_Tau(t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + MCMC_Single_Param_Generic(&(tree->geo->tau), + mixt_tree->geo->min_tau, + mixt_tree->geo->max_tau, + mixt_tree->mcmc->num_move_geo_tau, + NULL,&(mixt_tree->geo->c_lnL), + NULL,GEO_Wrap_Lk, + mixt_tree->mcmc->move_type[mixt_tree->mcmc->num_move_geo_tau], + NO,NULL,mixt_tree,NULL); + + tree = tree->next; + } + while(tree); +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#ifdef GEO +void MCMC_GEO_Dum(t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + MCMC_Single_Param_Generic(&(tree->geo->dum), + mixt_tree->geo->min_dum, + mixt_tree->geo->max_dum, + mixt_tree->mcmc->num_move_geo_dum, + NULL,&(mixt_tree->geo->c_lnL), + NULL,GEO_Wrap_Lk, + mixt_tree->mcmc->move_type[mixt_tree->mcmc->num_move_geo_dum], + NO,NULL,mixt_tree,NULL); + + tree = tree->next; + } + while(tree); +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#ifdef GEO +void MCMC_GEO_Loc(t_tree *tree) +{ + int target; + int *rec_loc; // recorded locations + int i; + phydbl cur_lnL, new_lnL; + phydbl u, ratio, alpha; + phydbl sum; + phydbl *probs; + + cur_lnL = tree->geo->c_lnL; + + rec_loc = (int *)mCalloc(2*tree->n_otu-1,sizeof(int)); + + For(i,2*tree->n_otu-1) rec_loc[i] = tree->geo->idx_loc[i]; + + // Choose an internal node (including the root) at random + target = Rand_Int(tree->n_otu,2*tree->n_otu-2); + + target = 2*tree->n_otu-2; + + // Root node is special. Select new location uniformly at random + if(tree->a_nodes[target] == tree->n_root) + { + probs = (phydbl *)mCalloc(tree->geo->ldscape_sz,sizeof(phydbl)); + + sum = 0.0; + for(i=0;igeo->ldscape_sz;i++) sum += tree->geo->idx_loc_beneath[tree->n_root->num * tree->geo->ldscape_sz + i]; + for(i=0;igeo->ldscape_sz;i++) probs[i] = tree->geo->idx_loc_beneath[tree->n_root->num * tree->geo->ldscape_sz + i]/sum; + + tree->geo->idx_loc[tree->n_root->num] = Sample_i_With_Proba_pi(probs,tree->geo->ldscape_sz); + + Free(probs); + } + + + // Randomize the locations below the selected node + GEO_Randomize_Locations(tree->a_nodes[target], + tree->geo, + tree); + + new_lnL = GEO_Lk(tree->geo,tree); + + ratio = (new_lnL - cur_lnL); + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + For(i,2*tree->n_otu-1) tree->geo->idx_loc[i] = rec_loc[i]; + tree->geo->c_lnL = GEO_Lk(tree->geo,tree); // TO DO: you only need to update the occupation vector here... + } + + Free(rec_loc); +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Sample_Joint_Rates_Prior(t_tree *tree) +{ + int i,dim; + phydbl T; + phydbl *r,*t,*lambda; + phydbl *min_r,*max_r; + phydbl k; + + dim = 2*tree->n_otu-2; + lambda = tree->rates->_2n_vect1; + min_r = tree->rates->_2n_vect2; + max_r = tree->rates->_2n_vect3; + r = tree->rates->br_r; + t = tree->rates->nd_t; + + for(i=0;irates->mean_r[i] = 1.0; + + RATES_Fill_Lca_Table(tree); + RATES_Covariance_Mu(tree); + + T = .0; + for(i=0;ia_nodes[i]->num] - t[tree->a_nodes[i]->anc->num]); + for(i=0;ia_nodes[i]->num] - t[tree->a_nodes[i]->anc->num])/T; + for(i=0;irates->min_rate; + for(i=0;irates->max_rate; + + k = 1.; /* We want \sum_i lambda[i] r[i] = 1 */ + + Rnorm_Multid_Trunc_Constraint(tree->rates->mean_r, + tree->rates->cov_r, + min_r,max_r, + lambda, + k, + r, + dim); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Rates_All(t_tree *tree) +{ + Set_Both_Sides(NO,tree); + if(tree->eval_alnL == YES) Lk(NULL,tree); + MCMC_One_Rate(tree->n_root,tree->n_root->v[1],YES,tree); + Update_Partial_Lk(tree,tree->e_root,tree->n_root->v[1]); + MCMC_One_Rate(tree->n_root,tree->n_root->v[2],YES,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_One_Rate(t_node *a, t_node *d, int traversal, t_tree *tree) +{ + t_edge *b; + int i; + phydbl u; + phydbl new_lnL_seq, cur_lnL_seq, new_lnL_rate, cur_lnL_rate; + phydbl ratio, alpha; + phydbl new_mu, cur_mu; + phydbl r_min, r_max; + int move_num,err; + phydbl K; + + if(tree->rates->model == STRICTCLOCK) return; + if(tree->rates->model == GUINDON) return; + + b = NULL; + if(a == tree->n_root) b = tree->e_root; + else for(i=0;i<3;i++) if(d->v[i] == a) { b = d->b[i]; break; } + + cur_mu = tree->rates->br_r[d->num]; + r_min = tree->rates->min_rate; + r_max = tree->rates->max_rate; + ratio = 0.0; + move_num = tree->mcmc->num_move_br_r; + K = tree->mcmc->tune_move[move_num]; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + + /* MCMC_Make_Move(&cur_mu,&new_mu,r_min,r_max,&ratio,K,tree->mcmc->move_type[move_num]); */ + + /* new_mu = Rnorm_Trunc(1.0,3.*tree->rates->nu,r_min,r_max,&err); */ + /* ratio -= Log_Dnorm_Trunc(new_mu,1.0,3.*tree->rates->nu,r_min,r_max,&err); */ + /* ratio += Log_Dnorm_Trunc(cur_mu,1.0,3.*tree->rates->nu,r_min,r_max,&err); */ + + err = NO; + new_mu = Rnorm_Trunc(cur_mu,K*tree->rates->nu,r_min,r_max,&err); + + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + ratio -= Log_Dnorm_Trunc(new_mu,cur_mu,K*tree->rates->nu,r_min,r_max,&err); + ratio += Log_Dnorm_Trunc(cur_mu,new_mu,K*tree->rates->nu,r_min,r_max,&err); + + if(new_mu > r_min && new_mu < r_max) + { + tree->rates->br_r[d->num] = new_mu; + tree->rates->br_do_updt[d->num] = YES; + + if(tree->eval_alnL == YES) new_lnL_seq = Lk(b,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + + ratio += (new_lnL_seq - cur_lnL_seq); + ratio += (new_lnL_rate - cur_lnL_rate); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + /* PhyML_Printf("\n. %f->%f %f->%f %f->%f ratio:%f", */ + /* cur_mu,new_mu, */ + /* cur_lnL_seq,new_lnL_seq, */ + /* cur_lnL_rate,new_lnL_rate, */ + /* ratio); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + tree->rates->br_r[d->num] = cur_mu; + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_rates = cur_lnL_rate; + + RATES_Update_Cur_Bl(tree); + Update_PMat_At_Given_Edge(b,tree); + } + else + { + tree->mcmc->acc_move[move_num]++; + } + } + + tree->mcmc->run_move[move_num]++; + + if(traversal == YES) + { + if(d->tax == YES) return; + else + { + for(i=0;i<3;++i) + if(d->v[i] != a && d->b[i] != tree->e_root) + { + Update_Partial_Lk(tree,d->b[i],d); + MCMC_One_Rate(d,d->v[i],YES,tree); + } + Update_Partial_Lk(tree,b,d); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_One_Node_Rate(t_node *a, t_node *d, int traversal, t_tree *tree) +{ + t_edge *b; + int i; + + b = NULL; + if(a == tree->n_root) b = tree->e_root; + else + for(i=0;i<3;i++) if(d->v[i] == a) { b = d->b[i]; break; } + + /* Only the log_RANDWALK move seems to work here. Change with caution then. */ + tree->rates->br_do_updt[d->num] = YES; + MCMC_Single_Param_Generic(&(tree->rates->nd_r[d->num]), + tree->rates->min_rate, + tree->rates->max_rate, + tree->mcmc->num_move_nd_r, + &(tree->rates->c_lnL_rates),NULL, + Wrap_Lk_Rates,NULL, + tree->mcmc->move_type[tree->mcmc->num_move_nd_r], + NO,NULL,tree,NULL); + + + Update_PMat_At_Given_Edge(b,tree); + + if(traversal == YES) + { + if(d->tax == YES) return; + else + { + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + { + MCMC_One_Node_Rate(d,d->v[i],YES,tree); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Times_And_Rates_All(t_tree *tree) +{ + MCMC_Times_And_Rates_Root(tree); + MCMC_Times_And_Rates_Recur(tree->n_root,tree->n_root->v[1],YES,tree); + MCMC_Times_And_Rates_Recur(tree->n_root,tree->n_root->v[2],YES,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Times_And_Rates_Root(t_tree *tree) +{ + phydbl u; + phydbl t_min,t_max; + phydbl r_min,r_max; + phydbl t1_cur, t1_new; + phydbl cur_lnL_rate, new_lnL_rate; + phydbl cur_lnL_time, new_lnL_time; + phydbl cur_lnL_seq, new_lnL_seq; + phydbl ratio,alpha; + phydbl t0,t2,t3; + t_node *v2,*v3; + phydbl K; + int move_num; + t_node *root; + phydbl r2_cur,r3_cur; + phydbl r2_new,r3_new; + + root = tree->n_root; + + if(FABS(tree->rates->t_prior_min[root->num] - tree->rates->t_prior_max[root->num]) < 1.E-10) return; + + move_num = tree->mcmc->num_move_times_and_rates_root; + K = tree->mcmc->tune_move[move_num]; + t1_cur = tree->rates->nd_t[root->num]; + ratio = 0.0; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + r_min = tree->rates->min_rate; + r_max = tree->rates->max_rate; + + v2 = root->v[2]; + v3 = root->v[1]; + + t0 = tree->rates->t_prior_min[root->num]; + t2 = tree->rates->nd_t[v2->num]; + t3 = tree->rates->nd_t[v3->num]; + + t_min = -INFINITY; + t_max = MIN(t2,t3); + + t_min += tree->rates->min_dt; + t_max -= tree->rates->min_dt; + + u = Uni(); + t1_new = t_max - (t_max - t1_cur)*exp(K*(u-.5)); + ratio += log((t1_new - t_max) / (t1_cur - t_max)); + + r2_cur = r3_cur = -1.0; + + if(tree->rates->model == THORNE || + tree->rates->model == LOGNORMAL || + tree->rates->model == STRICTCLOCK) + { + r2_cur = tree->rates->br_r[v2->num]; + r3_cur = tree->rates->br_r[v3->num]; + } + else if(tree->rates->model == GUINDON) + { + r2_cur = tree->rates->nd_r[v2->num]; + r3_cur = tree->rates->nd_r[v3->num]; + } + else assert(FALSE); + + + r2_new = r2_cur * (t2 - t1_cur) / (t2 - t1_new); + r3_new = r3_cur * (t3 - t1_cur) / (t3 - t1_new); + + + if(t_min > t_max) + { + PhyML_Fprintf(stderr,"\n. glnL:%f",TIMES_Lk_Times(NO,tree)); + PhyML_Fprintf(stderr,"\n. t:%f",tree->rates->nd_t[tree->n_root->num]); + PhyML_Fprintf(stderr,"\n. t0 = %f t2 = %f t3 = %f",t0,t2,t3); + PhyML_Fprintf(stderr,"\n. t_min = %f t_max = %f",t_min,t_max); + PhyML_Fprintf(stderr,"\n. prior_min = %f prior_max = %f",tree->rates->t_prior_min[root->num],tree->rates->t_prior_max[root->num]); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + + + if(t1_new > t_min && + t1_new < t_max && + r2_new > r_min && + r2_new < r_max && + r3_new > r_min && + r3_new < r_max) + { + RATES_Record_Times(tree); + + tree->rates->nd_t[root->num] = t1_new; + + if(tree->rates->model == THORNE || + tree->rates->model == LOGNORMAL || + tree->rates->model == STRICTCLOCK) + { + tree->rates->br_r[v2->num] = r2_new; + tree->rates->br_r[v3->num] = r3_new; + } + else if(tree->rates->model == GUINDON) + { + tree->rates->nd_r[v2->num] = r2_new; + tree->rates->nd_r[v3->num] = r3_new; + } + else assert(FALSE); + + RATES_Update_Cur_Bl(tree); + + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + + if(tree->rates->model == GUINDON) + { + RATES_Update_Cur_Bl(tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + } + else new_lnL_seq = cur_lnL_seq; + + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_time - cur_lnL_time); + ratio += (new_lnL_seq - cur_lnL_seq); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + /* printf("\n. alnL:%f->%f tlnL: %f->%f rlnL: %f->%f ratio: %f", */ + /* cur_lnL_seq,new_lnL_seq, */ + /* cur_lnL_time,new_lnL_time, */ + /* cur_lnL_rate,new_lnL_rate, */ + /* ratio); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + tree->rates->nd_t[root->num] = t1_cur; + + if(tree->rates->model == THORNE || + tree->rates->model == LOGNORMAL || + tree->rates->model == STRICTCLOCK) + { + tree->rates->br_r[v2->num] = r2_cur; + tree->rates->br_r[v3->num] = r3_cur; + } + else if(tree->rates->model == GUINDON) + { + tree->rates->nd_r[v2->num] = r2_cur; + tree->rates->nd_r[v3->num] = r3_cur; + } + else assert(FALSE); + + RATES_Update_Cur_Bl(tree); + + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->rates->c_lnL_times = cur_lnL_time; + tree->c_lnL = cur_lnL_seq; + + } + else + { + tree->mcmc->acc_move[move_num]+=1; + } + + // Ignore boundaries when updating tuning parameter + tree->mcmc->run_move[move_num]+=1; + + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Times_And_Rates_Recur(t_node *a, t_node *d, int traversal, t_tree *tree) +{ + phydbl u; + phydbl t_min,t_max; + phydbl r_min,r_max; + phydbl t1_cur, t1_new; + phydbl cur_lnL_rate, new_lnL_rate; + phydbl cur_lnL_time, new_lnL_time; + phydbl cur_lnL_seq, new_lnL_seq; + phydbl ratio,alpha; + int i; + phydbl t0,t2,t3; + t_node *v2,*v3; + int move_num; + phydbl r1_cur,r2_cur,r3_cur; + phydbl r1_new,r2_new,r3_new; + + if(d->tax) return; /* Won't change time at tip */ + + move_num = tree->mcmc->num_move_times_and_rates; + t1_cur = tree->rates->nd_t[d->num]; + ratio = 0.0; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + r_min = tree->rates->min_rate; + r_max = tree->rates->max_rate; + r2_cur = -1.0; + r1_cur = -1.0; + r3_cur = -1.0; + + + v2 = v3 = NULL; + for(i=0;i<3;++i) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(!v2) { v2 = d->v[i]; } + else { v3 = d->v[i]; } + } + + if(tree->rates->model == THORNE || + tree->rates->model == LOGNORMAL || + tree->rates->model == STRICTCLOCK) + { + r1_cur = tree->rates->br_r[d->num]; + r2_cur = tree->rates->br_r[v2->num]; + r3_cur = tree->rates->br_r[v3->num]; + } + else if(tree->rates->model == GUINDON) + { + r1_cur = tree->rates->nd_r[d->num]; + r2_cur = tree->rates->nd_r[v2->num]; + r3_cur = tree->rates->nd_r[v3->num]; + } + else assert(FALSE); + + t0 = tree->rates->nd_t[a->num]; + t2 = tree->rates->nd_t[v2->num]; + t3 = tree->rates->nd_t[v3->num]; + + t_min = MAX(t0,tree->rates->t_prior_min[d->num]); + t_max = MIN(tree->rates->t_prior_max[d->num],MIN(t2,t3)); + + t_min += tree->rates->min_dt; + t_max -= tree->rates->min_dt; + + t1_new = Uni()*(t_max - t_min) + t_min; + + r1_new = r1_cur * (t1_cur - t0) / (t1_new - t0); + r2_new = r2_cur * (t2 - t1_cur) / (t2 - t1_new); + r3_new = r3_cur * (t3 - t1_cur) / (t3 - t1_new); + + ratio += + log((t1_cur - t0) / (t1_new - t0) * + (t2 - t1_cur) / (t2 - t1_new) * + (t3 - t1_cur) / (t3 - t1_new)); + + if(t1_new > t_min && t1_new < t_max && + r1_new > r_min && r1_new < r_max && + r2_new > r_min && r2_new < r_max && + r3_new > r_min && r3_new < r_max) + { + RATES_Record_Times(tree); + + tree->rates->nd_t[d->num] = t1_new; + + if(tree->rates->model == THORNE || + tree->rates->model == LOGNORMAL || + tree->rates->model == STRICTCLOCK) + { + tree->rates->br_r[d->num] = r1_new; + tree->rates->br_r[v2->num] = r2_new; + tree->rates->br_r[v3->num] = r3_new; + } + else if(tree->rates->model == GUINDON) + { + tree->rates->nd_r[d->num] = r1_new; + tree->rates->nd_r[v2->num] = r2_new; + tree->rates->nd_r[v3->num] = r3_new; + } + else assert(FALSE); + + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + + if(tree->rates->model == GUINDON) + { + RATES_Update_Cur_Bl(tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + } + else new_lnL_seq = cur_lnL_seq; + + ratio += (new_lnL_time - cur_lnL_time); + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_seq - cur_lnL_seq); + + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* printf("\n. rej"); */ + RATES_Reset_Times(tree); + + if(tree->rates->model == THORNE || + tree->rates->model == LOGNORMAL || + tree->rates->model == STRICTCLOCK) + { + tree->rates->br_r[d->num] = r1_cur; + tree->rates->br_r[v2->num] = r2_cur; + tree->rates->br_r[v3->num] = r3_cur; + } + else if(tree->rates->model == GUINDON) + { + tree->rates->nd_r[d->num] = r1_cur; + tree->rates->nd_r[v2->num] = r2_cur; + tree->rates->nd_r[v3->num] = r3_cur; + } + else assert(FALSE); + + RATES_Update_Cur_Bl(tree); + + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->rates->c_lnL_times = cur_lnL_time; + tree->c_lnL = cur_lnL_seq; + } + else + { + /* printf("\n. acc"); */ + tree->mcmc->acc_move[move_num]++; + } + } + + tree->mcmc->run_move[move_num]++; + + if(d->tax == YES) return; + else + { + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + { + MCMC_Times_And_Rates_Recur(d,d->v[i],YES,tree); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Times_All(t_tree *tree) +{ + // Down partials may not be up to date. + Set_Both_Sides(YES,tree); + if(tree->eval_alnL == YES) Lk(NULL,tree); + Set_Both_Sides(NO,tree); + MCMC_Root_Time(tree); + MCMC_Time_Recur(tree->n_root,tree->n_root->v[1],YES,tree); + if(tree->eval_alnL == YES) Update_Partial_Lk(tree,tree->e_root,tree->n_root->v[1]); + MCMC_Time_Recur(tree->n_root,tree->n_root->v[2],YES,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Time_Recur(t_node *a, t_node *d, int traversal, t_tree *tree) +{ + phydbl u; + phydbl t_min,t_max; + phydbl t1_cur, t1_new; + phydbl cur_lnL_seq, new_lnL_seq; + phydbl cur_lnL_rate, new_lnL_rate; + phydbl cur_lnL_time, new_lnL_time; + /* phydbl K; */ + phydbl ratio,alpha; + t_edge *b1,*b2,*b3; + int i; + phydbl t0,t2,t3; + t_node *v2,*v3; + int move_num; + + if(d->tax) return; /* Won't change time at tip */ + + move_num = tree->mcmc->num_move_times; + t1_cur = tree->rates->nd_t[d->num]; + ratio = 0.0; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + + v2 = v3 = NULL; + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(!v2) { v2 = d->v[i]; } + else { v3 = d->v[i]; } + } + + + b1 = NULL; + if(a == tree->n_root) b1 = tree->e_root; + else for(i=0;i<3;i++) if(d->v[i] == a) { b1 = d->b[i]; break; } + + b2 = b3 = NULL; + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(!b2) { b2 = d->b[i]; } + else { b3 = d->b[i]; } + } + + t0 = tree->rates->nd_t[a->num]; + t2 = tree->rates->nd_t[v2->num]; + t3 = tree->rates->nd_t[v3->num]; + + t_min = MAX(t0,tree->rates->t_prior_min[d->num]); + t_max = MIN(tree->rates->t_prior_max[d->num],MIN(t2,t3)); + + t_min += tree->rates->min_dt; + t_max -= tree->rates->min_dt; + + /* K = tree->mcmc->tune_move[tree->mcmc->num_move_times] * (t_max - t_min); */ + /* MCMC_Make_Move(&t1_cur,&t1_new,t_min,t_max,&ratio,K,tree->mcmc->move_type[move_num]); */ + t1_new = Uni()*(t_max - t_min) + t_min; + + if(t1_new > t_min && t1_new < t_max) + { + RATES_Record_Times(tree); + + tree->rates->nd_t[d->num] = t1_new; + + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + ratio += (new_lnL_time - cur_lnL_time); + + if(new_lnL_time > UNLIKELY) + { + RATES_Update_Cur_Bl(tree); + + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + ratio += (new_lnL_rate - cur_lnL_rate); + + if(tree->eval_alnL == YES && tree->io->lk_approx == EXACT) + { + Update_PMat_At_Given_Edge(b1,tree); + Update_PMat_At_Given_Edge(b2,tree); + Update_PMat_At_Given_Edge(b3,tree); + Update_Partial_Lk(tree,b1,d); + } + if(tree->eval_alnL == YES) new_lnL_seq = Lk(b1,tree); + + ratio += (new_lnL_seq - cur_lnL_seq); + } + + /* printf("\n. One_Time cur_t: %f new_t: %f ratio: %f alnL:%f->%f tlnL: %f->%f rlnL: %f->%f", */ + /* t1_cur,t1_new, */ + /* ratio, */ + /* cur_lnL_seq,new_lnL_seq, */ + /* cur_lnL_time,new_lnL_time, */ + /* cur_lnL_rate,new_lnL_rate); */ + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* printf("\n. rej"); */ + RATES_Reset_Times(tree); + RATES_Update_Cur_Bl(tree); + + if(tree->eval_alnL == YES && tree->io->lk_approx == EXACT) + { + Update_PMat_At_Given_Edge(b1,tree); + Update_PMat_At_Given_Edge(b2,tree); + Update_PMat_At_Given_Edge(b3,tree); + Update_Partial_Lk(tree,b1,d); + } + + if(isinf(FABS(new_lnL_time)) == YES || isnan(new_lnL_time) == YES) + { + Print_Node(tree->n_root,tree->n_root->v[1],tree); + Print_Node(tree->n_root,tree->n_root->v[2],tree); + assert(FALSE); + } + + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->rates->c_lnL_times = cur_lnL_time; + + if(Are_Equal(tree->rates->c_lnL_times,cur_lnL_time,1.E-3) == NO) + { + PhyML_Fprintf(stderr,"\n\n"); + PhyML_Fprintf(stderr,"\n. moved node %d from %f to %f\n",d->num,t1_cur,t1_new); + Print_Node(tree->n_root,tree->n_root->v[1],tree); + Print_Node(tree->n_root,tree->n_root->v[2],tree); + PhyML_Fprintf(stderr,"\n. new_glnL: %f cur_glnL: %f",tree->rates->c_lnL_times,cur_lnL_time); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + /* new_lnL_seq = Lk(NULL,tree); /\* Not necessary. Remove once tested *\/ */ + /* if(Are_Equal(new_lnL_seq,cur_lnL_seq,1.E-3) == NO) */ + /* { */ + /* PhyML_Printf("\n. a: %d d: %d v2: %d v3: %d",a->num,d->num,v2->num,v3->num); */ + /* PhyML_Printf("\n. t1_cur: %f t1_new: %f",t1_cur,t1_new); */ + /* PhyML_Printf("\n. new_alnL: %f cur_alnL: %f",new_lnL_seq,cur_lnL_seq); */ + /* Generic_Exit(__FILE__,__LINE__,__FUNCTION__); */ + /* } */ + } + else + { + /* cur_lnL_seq = Lk(NULL,tree); /\* Not necessary. Remove once tested *\/ */ + /* if(Are_Equal(new_lnL_seq,cur_lnL_seq,1.E-3) == NO) */ + /* { */ + /* PhyML_Printf("\n. a: %d d: %d v2: %d v3: %d",a->num,d->num,v2->num,v3->num); */ + /* PhyML_Printf("\n. t1_cur: %f t1_new: %f",t1_cur,t1_new); */ + /* PhyML_Printf("\n. new_alnL: %f cur_alnL: %f",new_lnL_seq,cur_lnL_seq); */ + /* Generic_Exit(__FILE__,__LINE__,__FUNCTION__); */ + /* } */ + tree->mcmc->acc_move[move_num]++; + } + + /* printf("\n. %f",new_lnL_seq); fflush(NULL); */ + + if(t1_new < t0) + { + t1_new = t0+1.E-4; + PhyML_Fprintf(stderr,"\n"); + PhyML_Fprintf(stderr,"\n. a is root -> %s",(a == tree->n_root)?("YES"):("NO")); + PhyML_Fprintf(stderr,"\n. t0 = %f t1_new = %f",t0,t1_new); + PhyML_Fprintf(stderr,"\n. t_min=%f t_max=%f",t_min,t_max); + PhyML_Fprintf(stderr,"\n. (t1-t0)=%f (t2-t1)=%f",t1_cur-t0,t2-t1_cur); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + /* Exit("\n"); */ + } + if(t1_new > MIN(t2,t3)) + { + PhyML_Fprintf(stderr,"\n"); + PhyML_Fprintf(stderr,"\n. a is root -> %s",(a == tree->n_root)?("YES"):("NO")); + PhyML_Fprintf(stderr,"\n. t0 = %f t1_new = %f t1 = %f t2 = %f t3 = %f MIN(t2,t3)=%f",t0,t1_new,t1_cur,t2,t3,MIN(t2,t3)); + PhyML_Fprintf(stderr,"\n. t_min=%f t_max=%f",t_min,t_max); + PhyML_Fprintf(stderr,"\n. (t1-t0)=%f (t2-t1)=%f",t1_cur-t0,t2-t1_cur); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + /* Exit("\n"); */ + } + + if(isnan(t1_new)) + { + PhyML_Fprintf(stderr,"\n. run=%d",tree->mcmc->run); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + } + } + + tree->mcmc->run_move[move_num]++; + + if(traversal == YES) + { + if(d->tax == YES) return; + else + { + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(tree->eval_alnL == YES) Update_Partial_Lk(tree,d->b[i],d); + MCMC_Time_Recur(d,d->v[i],YES,tree); + } + if(tree->eval_alnL == YES) Update_Partial_Lk(tree,b1,d); + } + } +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Root_Time(t_tree *tree) +{ + phydbl u; + phydbl t_min,t_max; + phydbl t1_cur, t1_new; + phydbl cur_lnL_seq, new_lnL_seq; + phydbl cur_lnL_rate, new_lnL_rate; + phydbl cur_lnL_time, new_lnL_time; + phydbl ratio,alpha; + t_edge *b1; + phydbl t0,t2,t3; + t_node *v2,*v3; + phydbl K; + int move_num; + t_node *root; + + /* printf("\n IN ROOT: %f",tree->rates->c_lnL_times); */ + + root = tree->n_root; + + if(FABS(tree->rates->t_prior_min[root->num] - tree->rates->t_prior_max[root->num]) < 1.E-10) return; + + move_num = tree->mcmc->num_move_root_time; + K = tree->mcmc->tune_move[move_num]; + t1_cur = tree->rates->nd_t[root->num]; + ratio = 0.0; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + v2 = root->v[2]; + v3 = root->v[1]; + + b1 = tree->e_root; + + t0 = tree->rates->t_prior_min[root->num]; + t2 = tree->rates->nd_t[v2->num]; + t3 = tree->rates->nd_t[v3->num]; + + t_min = -INFINITY; + t_max = MIN(t2,t3); + + t_min += tree->rates->min_dt; + t_max -= tree->rates->min_dt; + + if(t_min > t_max) + { + PhyML_Fprintf(stderr,"\n. glnL:%f",TIMES_Lk_Times(NO,tree)); + PhyML_Fprintf(stderr,"\n. t:%f",tree->rates->nd_t[tree->n_root->num]); + PhyML_Fprintf(stderr,"\n. t0 = %f t2 = %f t3 = %f",t0,t2,t3); + PhyML_Fprintf(stderr,"\n. t_min = %f t_max = %f",t_min,t_max); + PhyML_Fprintf(stderr,"\n. prior_min = %f prior_max = %f",tree->rates->t_prior_min[root->num],tree->rates->t_prior_max[root->num]); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + u = Uni(); + t1_new = t_max - (t_max - t1_cur)*exp(K*(u-.5)); + ratio += log((t1_new - t_max) / (t1_cur - t_max)); + /* MCMC_Make_Move(&t1_cur,&t1_new,t_min,t_max,&ratio,K,tree->mcmc->move_type[move_num]); */ + /* t1_new = Uni()*(t_max-t_min) + t_min; */ + + /* PhyML_Printf("\n. K: %f t1: %f->%f acc.num: %d run: %d acc.rate: %f", */ + /* K,t1_cur,t1_new, */ + /* tree->mcmc->acc_move[move_num], */ + /* tree->mcmc->run_move[move_num], */ + /* tree->mcmc->run_move[move_num] > 0 ? (phydbl)tree->mcmc->acc_move[move_num]/tree->mcmc->run_move[move_num] : -1.); */ + + if(t1_new > t_min && t1_new < t_max) + { + RATES_Record_Times(tree); + + tree->rates->nd_t[root->num] = t1_new; + + RATES_Update_Cur_Bl(tree); + + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + + if(new_lnL_time > UNLIKELY) + { + if(tree->eval_alnL == YES) new_lnL_seq = Lk(b1,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + } + + ratio += (new_lnL_seq - cur_lnL_seq); + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_time - cur_lnL_time); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + /* printf("\n. alnL:%f->%f tlnL: %f->%f rlnL: %f->%f ratio: %f", */ + /* cur_lnL_seq,new_lnL_seq, */ + /* cur_lnL_time,new_lnL_time, */ + /* cur_lnL_rate,new_lnL_rate, */ + /* ratio); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + RATES_Reset_Times(tree); + RATES_Update_Cur_Bl(tree); + if(tree->eval_alnL == YES) Update_PMat_At_Given_Edge(b1,tree); + + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->rates->c_lnL_times = cur_lnL_time; + + /* if(Are_Equal(tree->rates->c_lnL_times,cur_lnL_time,1.E-3) == NO) */ + /* { */ + /* PhyML_Printf("\n\n"); */ + /* Print_Node(tree->n_root,tree->n_root->v[1],tree); */ + /* Print_Node(tree->n_root,tree->n_root->v[2],tree); */ + /* PhyML_Printf("\n. new_glnL: %f cur_glnL: %f",tree->rates->c_lnL_times,cur_lnL_time); */ + /* Generic_Exit(__FILE__,__LINE__,__FUNCTION__); */ + /* } */ + } + else + { + tree->mcmc->acc_move[move_num]++; + } + + // Ignore boundaries when updating tuning parameter + tree->mcmc->run_move[move_num]+=1; + + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Tree_Height(t_tree *tree) +{ + phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL_seq,new_lnL_seq; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl floor; + int n_nodes; + + if(FABS(tree->rates->t_prior_max[tree->n_root->num] - tree->rates->t_prior_min[tree->n_root->num]) < 1.E-10) return; + + RATES_Record_Times(tree); + + K = tree->mcmc->tune_move[tree->mcmc->num_move_tree_height]; + ratio = 0.0; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + u = Uni(); + mult = exp(K*(u-0.5)); + + floor = 0.0; + Scale_Subtree_Height(tree->n_root,mult,floor,&n_nodes,tree); + + RATES_Update_Cur_Bl(tree); + + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + + if(new_lnL_time > UNLIKELY) + { + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + } + + ratio += (phydbl)(n_nodes)*log(mult); + + ratio += (new_lnL_seq - cur_lnL_seq); + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_time - cur_lnL_time); + + /* printf("\n. seq: %f %f times: %f %f rates: %f %f", */ + /* new_lnL_seq,cur_lnL_seq, */ + /* new_lnL_time,cur_lnL_time, */ + /* new_lnL_rate,cur_lnL_rate); */ + + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + RATES_Reset_Times(tree); + RATES_Update_Cur_Bl(tree); + tree->rates->c_lnL_times = TIMES_Lk_Times(NO,tree); // Required in order to set t_prior_min/max to their original values + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_rates = cur_lnL_rate; + + if(Are_Equal(tree->rates->c_lnL_times,cur_lnL_time,1.E-3) == NO) + { + PhyML_Fprintf(stderr,"\n. new_glnL: %f cur_glnL: %f",tree->rates->c_lnL_times,cur_lnL_time); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_tree_height]++; + } + + tree->mcmc->run_move[tree->mcmc->num_move_tree_height]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Updown_T_Cr(t_tree *tree) +{ + /*! TO DO: make sure to change the values of clock_r across + the different seq partitions + */ + + int i; + phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl cur_lnL_seq,new_lnL_seq; + phydbl floor; + int n_nodes; + + /*! Check that sequences are isochronous. */ + for(i=0;in_otu-1;i++) if(!Are_Equal(tree->rates->nd_t[i+1],tree->rates->nd_t[i],1.E-10)) return; + + if(FABS(tree->rates->t_prior_max[tree->n_root->num] - tree->rates->t_prior_min[tree->n_root->num]) < 1.E-10) return; + + RATES_Record_Times(tree); + + K = tree->mcmc->tune_move[tree->mcmc->num_move_updown_t_cr]; + ratio = 0.0; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + + + u = Uni(); + mult = exp(K*(u-0.5)); + + floor = 0.0; + Scale_Subtree_Height(tree->n_root,mult,floor,&n_nodes,tree); + + if(tree->mod->s_opt->opt_clock_r == YES) + { + tree->rates->clock_r /= mult; + if(tree->rates->clock_r < tree->rates->min_clock || tree->rates->clock_r > tree->rates->max_clock) + { + tree->rates->clock_r *= mult; + RATES_Reset_Times(tree); + tree->mcmc->run_move[tree->mcmc->num_move_updown_t_cr]++; + return; + } + } + + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + + /* The Hastings ratio is actually mult^(n) when changing the absolute + node heights. When considering the relative heights, this ratio combined + to the Jacobian for the change of variable ends up to being equal to mult. + */ + ratio += (n_nodes - 1)*log(mult); + + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_time - cur_lnL_time); + + + if(tree->rates->model == GUINDON) + { + RATES_Update_Cur_Bl(tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + } + else new_lnL_seq = cur_lnL_seq; + + ratio += (new_lnL_seq - cur_lnL_seq); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + /* printf("\n. t_old = %f t_new = %f cr_old = %f cr_new = %f", */ + /* tree->rates->nd_t[tree->n_root->num]/mult, */ + /* tree->rates->nd_t[tree->n_root->num], */ + /* tree->rates->clock_r*mult, */ + /* tree->rates->clock_r); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + /* printf(" reject"); */ + RATES_Reset_Times(tree); + if(tree->mod->s_opt->opt_clock_r == YES) tree->rates->clock_r *= mult; + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->rates->c_lnL_times = cur_lnL_time; + if(tree->rates->model == GUINDON && tree->eval_alnL == YES) + { + RATES_Update_Cur_Bl(tree); + tree->c_lnL = cur_lnL_seq; + } + } + else + { + /* printf("\ accept"); */ + tree->mcmc->acc_move[tree->mcmc->num_move_updown_t_cr]++; + } + + tree->mcmc->run_move[tree->mcmc->num_move_updown_t_cr]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Updown_T_Br(t_tree *tree) +{ + + int i; + phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL_seq,new_lnL_seq; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl floor; + int n_nodes, target; + + /*! Check that sequences are isochronous. */ + for(i=0;in_otu-1;i++) if(!Are_Equal(tree->rates->nd_t[i+1],tree->rates->nd_t[i],1.E-10)) return; + + if(FABS(tree->rates->t_prior_max[tree->n_root->num] - tree->rates->t_prior_min[tree->n_root->num]) < 1.E-10) return; + + RATES_Record_Times(tree); + + K = tree->mcmc->tune_move[tree->mcmc->num_move_updown_t_br]; + ratio = 0.0; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + u = Uni(); + mult = exp(K*(u-0.5)); + + target = Rand_Int(tree->n_otu,2*tree->n_otu-3); + floor = 0.0; + Scale_Subtree_Height(tree->a_nodes[target],mult,floor,&n_nodes,tree); + + for(i=0;i<2*tree->n_otu-1;++i) + { + if(tree->rates->nd_t[i] > tree->rates->t_prior_max[i] || + tree->rates->nd_t[i] < tree->rates->t_prior_min[i]) + { + RATES_Reset_Times(tree); + tree->mcmc->run_move[tree->mcmc->num_move_updown_t_br]++; + return; + } + } + + if(RATES_Check_Node_Times(tree)) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + + ratio += n_nodes*log(mult); + + /* Likelihood ratio */ + ratio += (new_lnL_seq - cur_lnL_seq); + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_time - cur_lnL_time); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + RATES_Reset_Times(tree); + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->rates->c_lnL_times = cur_lnL_time; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_updown_t_br]++; + } + + tree->mcmc->run_move[tree->mcmc->num_move_updown_t_br]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Subtree_Height(t_tree *tree) +{ + phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL_seq,new_lnL_seq; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl floor; + int target; + int n_nodes; + + RATES_Record_Times(tree); + + K = tree->mcmc->tune_move[tree->mcmc->num_move_subtree_height]; + ratio = 0.0; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + u = Uni(); + mult = exp(K*(u-0.5)); + + target = Rand_Int(tree->n_otu,2*tree->n_otu-3); + floor = 0.0; + if(tree->a_nodes[target] == tree->n_root) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + if(!Scale_Subtree_Height(tree->a_nodes[target],mult,floor,&n_nodes,tree)) + { + RATES_Reset_Times(tree); + tree->mcmc->run_move[tree->mcmc->num_move_subtree_height]++; + return; + } + + if(RATES_Check_Node_Times(tree)) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + + if(new_lnL_time > UNLIKELY) + { + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + } + + ratio += (phydbl)(n_nodes)*log(mult); + ratio += (new_lnL_seq - cur_lnL_seq); + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_time - cur_lnL_time); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + RATES_Reset_Times(tree); + RATES_Update_Cur_Bl(tree); + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->rates->c_lnL_times = cur_lnL_time; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_subtree_height]++; + } + + tree->mcmc->run_move[tree->mcmc->num_move_subtree_height]++; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Tree_Rates(t_tree *tree) +{ + phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_seq,new_lnL_seq; + int n_nodes; + phydbl init_clock; + + if(tree->eval_alnL == NO) return; + if(tree->rates->model == STRICTCLOCK) return; + + RATES_Record_Rates(tree); + + tree->mcmc->run_move[tree->mcmc->num_move_tree_rates]++; + + K = tree->mcmc->tune_move[tree->mcmc->num_move_tree_rates]; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = UNLIKELY; + init_clock = tree->rates->clock_r; + ratio = 0.0; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = UNLIKELY; + + u = Uni(); + mult = exp(K*(u-0.5)); + + /* Multiply branch rates (or add to log of rates) */ + if(!Scale_Subtree_Rates(tree->n_root,mult,&n_nodes,tree)) + { + RATES_Reset_Rates(tree); + return; + } + + if(n_nodes != 2*tree->n_otu-2) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + /* Divide clock_r */ + if(tree->mod->s_opt->opt_clock_r == YES) + { + tree->rates->clock_r /= mult; + if(tree->rates->clock_r < tree->rates->min_clock || tree->rates->clock_r > tree->rates->max_clock) + { + tree->rates->clock_r = init_clock; + RATES_Reset_Rates(tree); + return; + } + } + + if((tree->rates->model == GUINDON) || + (tree->rates->is_asynchronous == YES) || + (tree->mod->s_opt->opt_clock_r == NO)) + { + RATES_Update_Cur_Bl(tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + } + else + new_lnL_seq = cur_lnL_seq; + + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + + ratio += (n_nodes-1)*log(mult); + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_seq - cur_lnL_seq); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + tree->rates->clock_r = init_clock; + RATES_Reset_Rates(tree); + tree->rates->c_lnL_rates = cur_lnL_rate; + if(tree->rates->model == GUINDON) + { + RATES_Update_Cur_Bl(tree); + tree->c_lnL = cur_lnL_seq; + } + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_tree_rates]++; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Subtree_Rates(t_tree *tree) +{ phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_seq,new_lnL_seq; + int target; + int n_nodes; + + if(tree->rates->model == STRICTCLOCK) return; + + RATES_Record_Rates(tree); + Record_Br_Len(tree); + + K = tree->mcmc->tune_move[tree->mcmc->num_move_subtree_rates]; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = cur_lnL_rate; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = cur_lnL_seq; + ratio = 0.0; + + u = Uni(); + mult = exp(K*(u-0.5)); + /* mult = Rgamma(1./K,K); */ + + target = Rand_Int(tree->n_otu,2*tree->n_otu-3); + + /* Multiply branch rates */ + if(!Scale_Subtree_Rates(tree->a_nodes[target],mult,&n_nodes,tree)) + { + RATES_Reset_Rates(tree); + tree->mcmc->run_move[tree->mcmc->num_move_subtree_rates]++; + return; + } + + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + + /* Proposal ratio: 2n-2=> number of multiplications, 1=>number of divisions */ + ratio += (+n_nodes)*log(mult); + /* ratio += (n_nodes-2)*log(mult) + log(Dgamma(1./mult,1./K,K)/Dgamma(mult,1./K,K)); */ + + + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_seq - cur_lnL_seq); + + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + RATES_Reset_Rates(tree); + Restore_Br_Len(tree); + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->c_lnL = cur_lnL_seq; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_subtree_rates]++; + } + + tree->mcmc->run_move[tree->mcmc->num_move_subtree_rates]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Swing(t_tree *tree) +{ + int i; + phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL_seq,new_lnL_seq; + phydbl cur_lnL_rate,new_lnL_rate; + + if(tree->rates->model == STRICTCLOCK) return; + + RATES_Record_Times(tree); + RATES_Record_Rates(tree); + Record_Br_Len(tree); + + K = 3.; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = cur_lnL_seq; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = cur_lnL_rate; + ratio = 0.0; + + u = Uni(); + /* mult = exp(K*(u-0.5)); */ + mult = u*(K - 1./K) + 1./K; + + + For(i,2*tree->n_otu-1) + { + if(tree->a_nodes[i]->tax == NO) + { + tree->rates->nd_t[i] *= mult; + } + + if(tree->rates->nd_t[i] > tree->rates->t_prior_max[i] || + tree->rates->nd_t[i] < tree->rates->t_prior_min[i]) + { + RATES_Reset_Times(tree); + Restore_Br_Len(tree); + return; + } + } + + For(i,2*tree->n_otu-2) + { + tree->rates->br_r[i] /= mult; + + if(tree->rates->br_r[i] > tree->rates->max_rate || + tree->rates->br_r[i] < tree->rates->min_rate) + { + RATES_Reset_Times(tree); + RATES_Reset_Rates(tree); + Restore_Br_Len(tree); + return; + } + } + + RATES_Update_Cur_Bl(tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + + ratio += (-(tree->n_otu-1.)-2.)*log(mult); + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_seq - cur_lnL_seq); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + RATES_Reset_Times(tree); + RATES_Reset_Rates(tree); + Restore_Br_Len(tree); + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_rates = cur_lnL_rate; + /* printf("\n. Reject %8f",mult); */ + } + else + { + /* printf("\n. Accept %8f",mult); */ + } + + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Updown_Nu_Cr(t_tree *tree) +{ + phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_seq,new_lnL_seq; + + RATES_Record_Rates(tree); + Record_Br_Len(tree); + + K = tree->mcmc->tune_move[tree->mcmc->num_move_updown_nu_cr]; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + + u = Uni(); + mult = exp(K*(u-0.5)); + + /* Multiply branch rates */ + /* if(!Scale_Subtree_Rates(tree->n_root,mult,&n_nodes,tree)) */ + /* { */ + /* RATES_Reset_Rates(tree); */ + /* Restore_Br_Len(tree); */ + /* tree->mcmc->run_move[tree->mcmc->num_move_updown_nu_cr]++; */ + /* return; */ + /* } */ + + + if(tree->mod->s_opt->opt_clock_r == YES) + { + tree->rates->clock_r /= mult; + if(tree->rates->clock_r < tree->rates->min_clock || tree->rates->clock_r > tree->rates->max_clock) + { + tree->rates->clock_r *= mult; + RATES_Reset_Rates(tree); + Restore_Br_Len(tree); + tree->mcmc->run_move[tree->mcmc->num_move_updown_nu_cr]++; + return; + } + } + + tree->rates->nu *= mult; + if(tree->rates->nu < tree->rates->min_nu || tree->rates->nu > tree->rates->max_nu) + { + tree->rates->nu /= mult; + tree->rates->clock_r *= mult; + RATES_Reset_Rates(tree); + Restore_Br_Len(tree); + tree->mcmc->run_move[tree->mcmc->num_move_updown_nu_cr]++; + return; + } + + RATES_Update_Cur_Bl(tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + + ratio = 0.0; + /* Proposal ratio: 2n-2=> number of multiplications, 1=>number of divisions */ + /* ratio += n_nodes*log(mult); /\* (1-1)*log(mult); *\/ */ + ratio += 0.0*log(mult); /* (1-1)*log(mult); */ + /* Prior density ratio */ + ratio += (new_lnL_rate - cur_lnL_rate); + /* Likelihood density ratio */ + ratio += (new_lnL_seq - cur_lnL_seq); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + if(tree->mod->s_opt->opt_clock_r == YES) tree->rates->clock_r *= mult; + tree->rates->nu /= mult; + RATES_Reset_Rates(tree); + Restore_Br_Len(tree); + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->c_lnL = cur_lnL_seq; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_updown_nu_cr]++; + } + + tree->mcmc->run_move[tree->mcmc->num_move_updown_nu_cr]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Time_Slice(t_tree *tree) +{ + int i; + phydbl K,mult,u,alpha,ratio; + phydbl cur_lnL_seq,new_lnL_seq; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl floor; + int n_nodes; + + /*! Check that sequences are isochronous. */ + for(i=0;in_otu-1;i++) if(!Are_Equal(tree->rates->nd_t[i+1],tree->rates->nd_t[i],1.E-10)) return; + + RATES_Record_Times(tree); + + K = tree->mcmc->tune_move[tree->mcmc->num_move_time_slice]; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = UNLIKELY; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = UNLIKELY; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = UNLIKELY; + ratio = 0.0; + + u = Uni(); + mult = exp(K*(u-0.5)); + + floor = Uni()*tree->rates->nd_t[tree->n_root->num]; + + Scale_Subtree_Height(tree->n_root,mult,floor,&n_nodes,tree); + + if(TIMES_Check_Node_Height_Ordering(tree) != NO) + { + RATES_Update_Cur_Bl(tree); + + new_lnL_time = TIMES_Lk_Times(NO,tree); + + if(new_lnL_time > UNLIKELY) + { + new_lnL_seq = Lk(NULL,tree); + new_lnL_rate = RATES_Lk_Rates(tree); + } + + ratio += (phydbl)(n_nodes)*log(mult); + + /* Likelihood ratio */ + ratio += (new_lnL_seq - cur_lnL_seq); + + /* Prior ratio */ + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_time - cur_lnL_time); + + /* printf("\n. seq: %f<-%f times: %f<-%f rates: %f<-%f acc.: [%d/%d] k: %f t: %f x: %f", */ + /* new_lnL_seq,cur_lnL_seq, */ + /* new_lnL_time,cur_lnL_time, */ + /* new_lnL_rate,cur_lnL_rate, */ + /* tree->mcmc->acc_move[tree->mcmc->num_move_time_slice], */ + /* tree->mcmc->run_move[tree->mcmc->num_move_time_slice], */ + /* K,floor,mult); */ + + ratio = exp(ratio); + } + else + { + ratio = 0.0; + } + + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + RATES_Reset_Times(tree); + RATES_Update_Cur_Bl(tree); + tree->rates->c_lnL_times = TIMES_Lk_Times(NO,tree); // Required in order to set t_prior_min/max to their original values + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_rates = cur_lnL_rate; + + if(Are_Equal(tree->rates->c_lnL_times,cur_lnL_time,1.E-3) == NO) + { + PhyML_Fprintf(stderr,"\n. new_glnL: %f cur_glnL: %f",tree->rates->c_lnL_times,cur_lnL_time); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_time_slice]++; + } + + tree->mcmc->run_move[tree->mcmc->num_move_time_slice]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Print_Param_Stdin(t_mcmc *mcmc, t_tree *tree) +{ + time_t cur_time; + + time(&cur_time); + + + + if(mcmc->run == 1) + { + PhyML_Printf("\n\n"); + PhyML_Printf("%9s","Run"); + PhyML_Printf(" %5s","Time"); + PhyML_Printf(" %10s","Likelihood"); + PhyML_Printf(" %10s","Prior"); + PhyML_Printf(" %19s","SubstRate[ ESS ]"); + PhyML_Printf(" %17s","TreeHeight[ ESS ]"); + if(tree->rates->model == THORNE || tree->rates->model == GUINDON) PhyML_Printf(" %16s","AutoCor[ ESS ]"); + else PhyML_Printf(" %16s","RateVar[ ESS ]"); + PhyML_Printf(" %15s","BirthR[ ESS ]"); + PhyML_Printf(" %8s","MinESS"); + } + + if((cur_time - mcmc->t_last_print) > mcmc->print_every) + { + mcmc->t_last_print = cur_time; + PhyML_Printf("\n"); + PhyML_Printf("%9d",tree->mcmc->run); + PhyML_Printf(" %5d",(int)(cur_time-mcmc->t_beg)); + PhyML_Printf(" %10.2f",tree->c_lnL); + PhyML_Printf(" %10.2f",(tree->rates ? tree->rates->c_lnL_rates+tree->rates->c_lnL_times : +1)); + PhyML_Printf(" %12.6f[%5.0f]",RATES_Average_Substitution_Rate(tree),tree->mcmc->ess[tree->mcmc->num_move_clock_r]); + /* PhyML_Printf("\t%12.6f[%5.0f]",tree->rates->clock_r,tree->mcmc->ess[tree->mcmc->num_move_clock_r]); */ + PhyML_Printf(" %9f[%5.0f]", + (tree->rates ? tree->rates->nu : -1.), + tree->mcmc->ess[tree->mcmc->num_move_nu]); + PhyML_Printf(" %8f[%5.0f]", + (tree->rates ? tree->rates->birth_rate : -1.), + tree->mcmc->ess[tree->mcmc->num_move_birth_rate]); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Print_Param(t_mcmc *mcmc, t_tree *tree) +{ + int i; + FILE *fp; + char *s; + int orig_approx; + phydbl orig_lnL; + char *s_tree; + + if(tree->mcmc->run > mcmc->chain_len) return; + + s = (char *)mCalloc(100,sizeof(char)); + + fp = mcmc->out_fp_stats; + +/* if(tree->mcmc->run == 0) */ +/* { */ +/* PhyML_Fprintf(stdout," ["); */ +/* fflush(NULL); */ +/* } */ + +/* if(!(mcmc->run%(mcmc->chain_len/10))) */ +/* { */ +/* PhyML_Fprintf(stdout,"."); */ +/* fflush(NULL); */ +/* } */ + +/* if(tree->mcmc->run == mcmc->chain_len) */ +/* { */ +/* PhyML_Fprintf(stdout,"]"); */ +/* fflush(NULL); */ +/* } */ + + +/* MCMC_Print_Means(mcmc,tree); */ +/* MCMC_Print_Last(mcmc,tree); */ + + + + if(!(mcmc->run%mcmc->sample_interval)) + { + MCMC_Copy_To_New_Param_Val(tree->mcmc,tree); + + for(i=0;imcmc->n_moves;i++) + { + if((tree->mcmc->acc_rate[i] > .1) && (tree->mcmc->start_ess[i] == NO)) tree->mcmc->start_ess[i] = YES; + if(tree->mcmc->start_ess[i] == YES) MCMC_Update_Effective_Sample_Size(i,tree->mcmc,tree); + if(tree->mcmc->run > (int) tree->mcmc->chain_len * 0.1) tree->mcmc->adjust_tuning[i] = NO; + } + + if(tree->mcmc->run == 0) + { + time(&(mcmc->t_beg)); + time(&(mcmc->t_last_print)); + + PhyML_Fprintf(fp,"# Random seed: %d",tree->io->r_seed); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"Run\t"); +/* PhyML_Fprintf(fp,"Time\t"); */ + /* PhyML_Fprintf(fp,"MeanRate\t"); */ +/* PhyML_Fprintf(fp,"NormFact\t"); */ + + /* for(i=0;in_moves;i++) */ + /* { */ + /* strcpy(s,"Acc."); */ + /* PhyML_Fprintf(fp,"%s%d\t",strcat(s,mcmc->move_name[i]),i); */ + /* } */ + + /* for(i=0;in_moves;i++) */ + /* { */ + /* strcpy(s,"Tune."); */ + /* PhyML_Fprintf(fp,"%s%d\t",strcat(s,mcmc->move_name[i]),i); */ + /* } */ + + /* for(i=0;in_moves;i++) */ + /* { */ + /* strcpy(s,"Run."); */ + /* PhyML_Fprintf(fp,"%s\t",strcat(s,mcmc->move_name[i])); */ + /* } */ + + PhyML_Fprintf(fp,"LnLike[Exact]\t"); + PhyML_Fprintf(fp,"LnLike[Approx]\t"); + PhyML_Fprintf(fp,"LnRates\t"); + PhyML_Fprintf(fp,"LnTimes\t"); + PhyML_Fprintf(fp,"LnPosterior\t"); + PhyML_Fprintf(fp,"ClockRate\t"); + PhyML_Fprintf(fp,"EvolRate\t"); + PhyML_Fprintf(fp,"Nu\t"); + PhyML_Fprintf(fp,"BirthRate\t"); + PhyML_Fprintf(fp,"TsTv\t"); + + + if(tree->mod->ras->n_catg > 1) + { + if(tree->mod->ras->free_mixt_rates == NO) PhyML_Fprintf(fp,"Alpha\t"); + else + { + for(i=0;imod->ras->n_catg;i++) PhyML_Fprintf(fp,"p%d\t",i); + for(i=0;imod->ras->n_catg;i++) PhyML_Fprintf(fp,"r%d\t",i); + } + } + + + if(tree->mod->m4mod->n_h > 1 && tree->mod->use_m4mod == YES) + { + for(i=0;imod->m4mod->n_h;i++) PhyML_Fprintf(fp,"cov_p%d\t",i); + for(i=0;imod->m4mod->n_h;i++) PhyML_Fprintf(fp,"cov_r%d\t",i); + PhyML_Fprintf(fp,"cov_switch\t"); + } + + + if(fp != stdout) + { + for(i=tree->n_otu;i<2*tree->n_otu-1;i++) + { + if(tree->a_nodes[i] == tree->n_root->v[2]) + PhyML_Fprintf(fp,"T%d%s\t",i,"[LeftRoot]"); + else if(tree->a_nodes[i] == tree->n_root->v[1]) + PhyML_Fprintf(fp,"T%d%s\t",i,"[RightRoot]"); + else if(tree->a_nodes[i] == tree->n_root) + PhyML_Fprintf(fp,"T%d%s\t",i,"[Root]"); + else + PhyML_Fprintf(fp,"T%d[%d]\t",i,tree->a_nodes[i]->anc->num); + } + } + + +/* if(fp != stdout) */ +/* { */ +/* For(i,2*tree->n_otu-1) */ +/* { */ +/* if(tree->a_nodes[i] == tree->n_root->v[2]) */ +/* PhyML_Fprintf(fp,"R%d[LeftRoot]\t",i); */ +/* else if(tree->a_nodes[i] == tree->n_root->v[1]) */ +/* PhyML_Fprintf(fp,"R%d[RightRoot]\t",i); */ +/* else if(tree->a_nodes[i] != tree->n_root) */ +/* PhyML_Fprintf(fp," R%d[%d]\t",i,tree->a_nodes[i]->anc->num); */ +/* else */ +/* PhyML_Fprintf(fp," R%d[Root]\t",i); */ + +/* /\* PhyML_Fprintf(fp," R%d[%f]\t",i,tree->rates->mean_l[i]); *\/ */ +/* } */ +/* } */ + + + if(fp != stdout) + { + For(i,2*tree->n_otu-2) + { + if(tree->a_nodes[i] == tree->n_root->v[2]) + PhyML_Fprintf(fp,"B%d[LeftRoot]\t",i); + else if(tree->a_nodes[i] == tree->n_root->v[1]) + PhyML_Fprintf(fp,"B%d[RightRoot]\t",i); + else + PhyML_Fprintf(fp," B%d[%d]\t",i,tree->a_nodes[i]->anc->num); + +/* PhyML_Fprintf(fp," R%d[%f]\t",i,tree->rates->mean_l[i]); */ + } + } + + + /* if(fp != stdout) */ + /* { */ + /* For(i,2*tree->n_otu-2) */ + /* { */ + /* if(tree->a_nodes[i] == tree->n_root->v[2]) */ + /* PhyML_Fprintf(fp,"G%d[LeftRoot]\t",i); */ + /* else if(tree->a_nodes[i] == tree->n_root->v[1]) */ + /* PhyML_Fprintf(fp,"G%d[RightRoot]\t",i); */ + /* else */ + /* PhyML_Fprintf(fp," G%d[%f]\t",i,tree->rates->ml_l[i]); */ + + + /* /\* PhyML_Fprintf(fp," R%d[%f]\t",i,tree->rates->mean_l[i]); *\/ */ + /* } */ + /* } */ + + + /* if(fp != stdout) */ + /* { */ + /* For(i,2*tree->n_otu-3) */ + /* { */ + /* if(tree->a_edges[i] == tree->e_root) */ + /* PhyML_Fprintf(fp,"*L[%f]%d\t",i,tree->rates->u_ml_l[i]); */ + /* else */ + /* PhyML_Fprintf(fp," L[%f]%d\t",i,tree->rates->u_ml_l[i]); */ + /* } */ + /* } */ + + + PhyML_Fprintf(mcmc->out_fp_trees,"#NEXUS\n"); + PhyML_Fprintf(mcmc->out_fp_trees,"BEGIN TREES;\n"); + PhyML_Fprintf(mcmc->out_fp_trees,"\tTRANSLATE\n"); + for(i=0;in_otu-1;i++) PhyML_Fprintf(mcmc->out_fp_trees,"\t%3d\t%s,\n",tree->a_nodes[i]->num+1,tree->a_nodes[i]->name); + PhyML_Fprintf(mcmc->out_fp_trees,"\t%3d\t%s;\n",tree->a_nodes[i]->num+1,tree->a_nodes[i]->name); + tree->write_tax_names = NO; + } + + PhyML_Fprintf(fp,"\n"); + + PhyML_Fprintf(fp,"%6d\t",tree->mcmc->run); + +/* time(&mcmc->t_cur); */ +/* PhyML_Fprintf(fp,"%6d\t",(int)(mcmc->t_cur-mcmc->t_beg)); */ + +/* RATES_Update_Cur_Bl(tree); */ +/* PhyML_Fprintf(fp,"%f\t",RATES_Check_Mean_Rates(tree)); */ + +/* PhyML_Fprintf(fp,"%f\t",tree->rates->norm_fact); */ + /* for(i=0;imcmc->n_moves;i++) PhyML_Fprintf(fp,"%f\t",tree->mcmc->acc_rate[i]); */ + /* for(i=0;imcmc->n_moves;i++) PhyML_Fprintf(fp,"%f\t",(phydbl)(tree->mcmc->tune_move[i])); */ +/* for(i=0;imcmc->n_moves;i++) PhyML_Fprintf(fp,"%d\t",(int)(tree->mcmc->run_move[i])); */ + + orig_approx = tree->io->lk_approx; + orig_lnL = tree->c_lnL; + tree->io->lk_approx = EXACT; + Lk(NULL,tree); + PhyML_Fprintf(fp,"%.1f\t",tree->c_lnL); + tree->io->lk_approx = NORMAL; + tree->c_lnL = 0.0; + Lk(NULL,tree); + PhyML_Fprintf(fp,"%.1f\t",tree->c_lnL); + tree->io->lk_approx = orig_approx; + tree->c_lnL = orig_lnL; + +/* PhyML_Fprintf(fp,"0\t0\t"); */ + + PhyML_Fprintf(fp,"%G\t",tree->rates->c_lnL_rates); + PhyML_Fprintf(fp,"%G\t",tree->rates->c_lnL_times); + PhyML_Fprintf(fp,"%G\t",tree->c_lnL+tree->rates->c_lnL_rates+tree->rates->c_lnL_times); + PhyML_Fprintf(fp,"%G\t",tree->rates->clock_r); + PhyML_Fprintf(fp,"%G\t",RATES_Average_Substitution_Rate(tree)); + PhyML_Fprintf(fp,"%G\t",tree->rates->nu); + PhyML_Fprintf(fp,"%G\t",tree->rates->birth_rate); + PhyML_Fprintf(fp,"%G\t",tree->mod->kappa->v); + + if(tree->mod->ras->n_catg > 1) + { + if(tree->mod->ras->free_mixt_rates == NO) + PhyML_Fprintf(fp,"%G\t",tree->mod->ras->alpha->v); + else + { + for(i=0;imod->ras->n_catg;i++) PhyML_Fprintf(fp,"%G\t",tree->mod->ras->gamma_r_proba->v[i]); + for(i=0;imod->ras->n_catg;i++) PhyML_Fprintf(fp,"%G\t",tree->mod->ras->gamma_rr->v[i]); + /* for(i=0;imod->ras->n_catg;i++) PhyML_Fprintf(fp,"%G\t",tree->mod->ras->gamma_r_proba_unscaled[i]); */ + /* for(i=0;imod->ras->n_catg;i++) PhyML_Fprintf(fp,"%G\t",tree->mod->ras->gamma_rr_unscaled[i]); */ + } + } + + if(tree->mod->m4mod->n_h > 1 && tree->mod->use_m4mod == YES) + { + for(i=0;imod->m4mod->n_h;i++) PhyML_Fprintf(fp,"%G\t",tree->mod->m4mod->h_fq[i]); + for(i=0;imod->m4mod->n_h;i++) PhyML_Fprintf(fp,"%G\t",tree->mod->m4mod->multipl[i]); + PhyML_Fprintf(fp,"%G\t",tree->mod->m4mod->delta); + } + + + char *format = (char *)mCalloc(100,sizeof(char)); + sprintf(format,"%%.%df\t",tree->mcmc->nd_t_digits); + for(i=tree->n_otu;i<2*tree->n_otu-1;i++) PhyML_Fprintf(fp,format,tree->rates->nd_t[i]); + Free(format); + + /* for(i=0;i<2*tree->n_otu-1;i++) PhyML_Fprintf(fp,"%.4f\t",log(tree->rates->nd_r[i])); */ + + // Average rate along edges: length divided by elapsed time + For(i,2*tree->n_otu-2) + PhyML_Fprintf(fp,"%.4f\t", + tree->rates->cur_l[i]/(tree->rates->nd_t[tree->a_nodes[i]->num] - tree->rates->nd_t[tree->a_nodes[i]->anc->num])); + + /* fp_pred = fopen("predict.txt","a"); */ + /* for(i=0;i<2*tree->n_otu-2;i++) */ + /* PhyML_Fprintf(fp_pred,"B%d\t%12f\t%12f\t%4d\n",i,exp(tree->rates->br_r[i]),tree->rates->nd_t[i],tree->rates->has_survived[i]); */ + /* fclose(fp_pred); */ + + + /* phydbl p,sd,mean; */ + + /* for(i=0;i<2*tree->n_otu-2;i++) */ + /* { */ + /* sd = tree->rates->nu * (tree->rates->nd_t[i] - tree->rates->nd_t[tree->a_nodes[i]->anc->num]); */ + /* mean = tree->rates->br_r[tree->a_nodes[i]->anc->num] - .5*sd*sd; */ + /* p = Pnorm(tree->rates->br_r[i],mean,sd); */ + /* PhyML_Fprintf(fp,"%f\t",p); */ + /* tree->rates->mean_r[i] += p; */ + /* } */ + + /* for(i=0;i<2*tree->n_otu-2;i++) PhyML_Fprintf(fp,"%.4f\t",tree->rates->cur_gamma_prior_mean[i]); */ + /* if(fp != stdout) for(i=tree->n_otu;i<2*tree->n_otu-1;i++) PhyML_Fprintf(fp,"%G\t",tree->rates->t_prior[i]); */ +/* For(i,2*tree->n_otu-3) PhyML_Fprintf(fp,"%f\t",exp(tree->a_edges[i]->l->v)); */ + + + /* RATES_Update_Cur_Bl(tree); */ + /* For(i,2*tree->n_otu-3) PhyML_Fprintf(fp,"%f\t",tree->a_edges[i]->l->v); */ + + + For(i,2*tree->n_otu-2) tree->rates->mean_r[i] = exp(tree->rates->br_r[i]); + For(i,2*tree->n_otu-1) tree->rates->mean_t[i] = tree->rates->nd_t[i]; + + /* Time_To_Branch(tree); */ + /* char *s; */ + /* s = (char *)mCalloc(T_MAX_NAME,sizeof(char)); */ + /* strcpy(s,mcmc->io->in_align_file); */ + /* strcat(s,"_"); */ + /* strcat(s,mcmc->out_filename); */ + /* strcat(s,".ps"); */ + /* DR_Draw_Tree(s,tree); */ + /* Free(s); */ + + /* FILE *fp; */ + /* int j; */ + /* t_node *d, *v1, *v2; */ + /* int n1, n2; */ + /* phydbl r1, r2; */ + + /* s = (char *)mCalloc(T_MAX_NAME,sizeof(char)); */ + /* strcpy(s,mcmc->io->in_align_file); */ + /* strcat(s,"_"); */ + /* strcat(s,mcmc->out_filename); */ + /* strcat(s,".corr"); */ + /* fp = fopen(s,"w"); */ + + /* n1 = n2 = 0; */ + /* r1 = r2 = 0.f; */ + /* For(i,2*tree->n_otu-3) */ + /* { */ + /* if(tree->a_nodes[i]->tax == NO) */ + /* { */ + /* d = tree->a_nodes[i]; */ + /* v1 = v2 = NULL; */ + /* for(j=0;j<3;j++) */ + /* { */ + /* if(d->v[j] != d->anc && d->b[j] != tree->e_root) */ + /* { */ + /* if(!v1) v1 = d->v[j]; */ + /* else v2 = d->v[j]; */ + /* } */ + /* } */ + + /* for(j=0;j<3;j++) */ + /* { */ + /* if(v1->v[j] && v1->v[j] == d) */ + /* { */ + /* n1 = v1->bip_size[j]; */ + /* /\* r1 = RATES_Get_Mean_Rate_In_Subtree(v1,tree); *\/ */ + /* r1 = exp(tree->rates->br_r[v1->num]); */ + /* break; */ + /* } */ + /* } */ + + + /* for(j=0;j<3;j++) */ + /* { */ + /* if(v2->v[j] && v2->v[j] == d) */ + /* { */ + /* n2 = v2->bip_size[j]; */ + /* /\* r2 = RATES_Get_Mean_Rate_In_Subtree(v2,tree); *\/ */ + /* r2 = exp(tree->rates->br_r[v2->num]); */ + /* break; */ + /* } */ + /* } */ + + /* fprintf(fp,"\n%4d %4d %15f %15f",n1,n2,r1,r2); */ + /* } */ + /* } */ + + /* fclose(fp); */ + + // TREES + TIMES_Time_To_Bl(tree); + tree->bl_ndigits = 3; + s_tree = Write_Tree(tree); + tree->bl_ndigits = 7; + PhyML_Fprintf(mcmc->out_fp_trees,"TREE %8d [%f] = [&R] %s\n",mcmc->run,tree->c_lnL,s_tree); + Free(s_tree); + } + + if(tree->mcmc->run == mcmc->chain_len) PhyML_Fprintf(mcmc->out_fp_trees,"END;\n"); + + fflush(NULL); + + Free(s); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Print_Means(t_mcmc *mcmc, t_tree *tree) +{ + + if(!(mcmc->run%mcmc->sample_interval)) + { + int i; + char *s; + + s = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + + strcpy(s,tree->mcmc->out_filename); + strcat(s,".means"); + + fclose(mcmc->out_fp_means); + + mcmc->out_fp_means = fopen(s,"w"); + + PhyML_Fprintf(mcmc->out_fp_means,"#"); + for(i=tree->n_otu;i<2*tree->n_otu-1;i++) PhyML_Fprintf(mcmc->out_fp_means,"T%d\t",i); + + PhyML_Fprintf(mcmc->out_fp_means,"\n"); + + for(i=tree->n_otu;i<2*tree->n_otu-1;i++) tree->rates->t_mean[i] *= (phydbl)(mcmc->run / mcmc->sample_interval); + + for(i=tree->n_otu;i<2*tree->n_otu-1;i++) + { + tree->rates->t_mean[i] += tree->rates->nd_t[i]; + tree->rates->t_mean[i] /= (phydbl)(mcmc->run / mcmc->sample_interval + 1); + +/* PhyML_Fprintf(tree->mcmc->out_fp_means,"%d\t",tree->mcmc->run / tree->mcmc->sample_interval); */ + PhyML_Fprintf(tree->mcmc->out_fp_means,"%.1f\t",tree->rates->t_mean[i]); + } + + PhyML_Fprintf(tree->mcmc->out_fp_means,"\n"); + fflush(NULL); + + Free(s); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Print_Last(t_mcmc *mcmc, t_tree *tree) +{ + + if(!(mcmc->run%mcmc->sample_interval)) + { + int i; + char *s; + + s = (char *)mCalloc(T_MAX_FILE,sizeof(char)); + + strcpy(s,tree->mcmc->out_filename); + strcat(s,".lasts"); + + fclose(mcmc->out_fp_last); + + mcmc->out_fp_last = fopen(s,"w"); + +/* rewind(mcmc->out_fp_last); */ + + PhyML_Fprintf(mcmc->out_fp_last,"#"); + PhyML_Fprintf(tree->mcmc->out_fp_last,"Time\t"); + + for(i=tree->n_otu;i<2*tree->n_otu-1;i++) + PhyML_Fprintf(tree->mcmc->out_fp_last,"T%d\t",i); + + PhyML_Fprintf(tree->mcmc->out_fp_last,"\n"); + + if(mcmc->run) + { + time(&(mcmc->t_cur)); + PhyML_Fprintf(tree->mcmc->out_fp_last,"%d\t",(int)(mcmc->t_cur-mcmc->t_beg)); +/* PhyML_Fprintf(tree->mcmc->out_fp_last,"%d\t",(int)(mcmc->t_beg)); */ + } + + for(i=tree->n_otu;i<2*tree->n_otu-1;i++) PhyML_Fprintf(tree->mcmc->out_fp_last,"%.1f\t",tree->rates->nd_t[i]); + + PhyML_Fprintf(tree->mcmc->out_fp_last,"\n"); + fflush(NULL); + + Free(s); + } +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Pause(t_mcmc *mcmc) +{ + char choice; + char *s; + int len; + + s = (char *)mCalloc(100,sizeof(char)); + + + if(!(mcmc->run%mcmc->chain_len) && (mcmc->is_burnin == NO)) + { + PhyML_Printf("\n. Do you wish to stop the analysis [N/y] "); + if(!scanf("%c",&choice)) Exit("\n"); + if(choice == '\n') choice = 'N'; + else getchar(); /* \n */ + + Uppercase(&choice); + + switch(choice) + { + case 'N': + { + len = 1E+4; + PhyML_Printf("\n. How many extra generations is required [default: 1E+4] "); + Getstring_Stdin(s); + if(s[0] == '\0') len = 1E+4; + else len = (int)atof(s); + + if(len < 0) + { + PhyML_Fprintf(stderr,"\n. The value entered must be an integer greater than 0.\n"); + Exit("\n"); + } + mcmc->chain_len += len; + break; + } + + case 'Y': + { + PhyML_Printf("\n. Ok. Done.\n"); + Exit("\n"); + break; + } + + default: + { + PhyML_Printf("\n. Please enter 'Y' or 'N'.\n"); + Exit("\n"); + } + } + } + + Free(s); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Terminate() +{ + char choice; + PhyML_Printf("\n\n. Do you really want to terminate [Y/n]: "); + if(!scanf("%c",&choice)) Exit("\n"); + if(choice == '\n') choice = 'Y'; + else getchar(); /* \n */ + Uppercase(&choice); + if(choice == 'Y') raise(SIGTERM); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Copy_MCMC_Struct(t_mcmc *ori, t_mcmc *cpy, char *filename) +{ + int pid; + int i; + + cpy->sample_interval = ori->sample_interval ; + cpy->chain_len = ori->chain_len ; + cpy->randomize = ori->randomize ; + cpy->norm_freq = ori->norm_freq ; + cpy->n_moves = ori->n_moves ; + cpy->max_tune = ori->max_tune ; + cpy->min_tune = ori->min_tune ; + cpy->print_every = ori->print_every ; + cpy->is_burnin = ori->is_burnin ; + cpy->is = ori->is ; + cpy->io = ori->io ; + cpy->in_fp_par = ori->in_fp_par ; + cpy->nd_t_digits = ori->nd_t_digits ; + cpy->max_lag = ori->max_lag ; + cpy->move_idx = ori->move_idx ; + + for(i=0;in_moves;i++) + { + cpy->start_ess[i] = ori->start_ess[i]; + cpy->ess_run[i] = ori->ess_run[i]; + cpy->ess[i] = ori->ess[i]; + cpy->move_weight[i] = ori->move_weight[i]; + cpy->run_move[i] = ori->run_move[i]; + cpy->acc_move[i] = ori->acc_move[i]; + cpy->prev_run_move[i] = ori->prev_run_move[i]; + cpy->prev_acc_move[i] = ori->prev_acc_move[i]; + cpy->acc_rate[i] = ori->acc_rate[i]; + cpy->tune_move[i] = ori->tune_move[i]; + strcpy(cpy->move_name[i],ori->move_name[i]); + cpy->adjust_tuning[i] = ori->adjust_tuning[i]; + } + + + + if(filename) + { + char *s; + + s = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + strcpy(cpy->out_filename,filename); + pid = getpid(); + sprintf(cpy->out_filename+strlen(cpy->out_filename),"_%d",pid); + + strcpy(s,cpy->io->in_align_file); + strcat(s,"_"); + strcat(s,cpy->out_filename); + strcat(s,"_stats"); + cpy->out_fp_stats = fopen(s,"w"); + + strcpy(s,cpy->io->in_align_file); + strcat(s,"_"); + strcat(s,cpy->out_filename); + strcat(s,"_trees"); + cpy->out_fp_trees = fopen(s,"w"); + + strcpy(s,cpy->io->in_align_file); + strcat(s,"_"); + strcat(s,cpy->out_filename); + strcat(s,"_constree"); + cpy->out_fp_constree = fopen(s,"w"); + + Free(s); + } + else + { + cpy->out_fp_stats = stderr; + cpy->out_fp_trees = stderr; + } +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Close_MCMC(t_mcmc *mcmc) +{ + fclose(mcmc->out_fp_trees); + fclose(mcmc->out_fp_stats); + fclose(mcmc->out_fp_constree); + /* fclose(mcmc->out_fp_means); */ + /* fclose(mcmc->out_fp_last); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Randomize_Kappa(t_tree *tree) +{ + tree->mod->kappa->v = Uni()*5.; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Randomize_Rate_Across_Sites(t_tree *tree) +{ + if(tree->mod->ras->n_catg == 1) return; + + if(tree->mod->ras->free_mixt_rates == YES) + { + int i; + for(i=0;imod->ras->n_catg-1;i++) tree->mod->ras->gamma_r_proba_unscaled->v[i] = Uni(); + tree->mod->ras->gamma_r_proba_unscaled->v[tree->mod->ras->n_catg-1] = 1.; + for(i=0;imod->ras->n_catg-1;i++) tree->mod->ras->gamma_rr_unscaled->v[i] = (phydbl)i+0.1; /* Do not randomize those as their ordering matter */ + tree->mod->ras->gamma_rr_unscaled->v[tree->mod->ras->n_catg-1] = (phydbl)tree->mod->ras->n_catg; + } + else + { + tree->mod->ras->alpha->v = Uni()*5.; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Randomize_Covarion_Rates(t_tree *tree) +{ + if(tree->mod->use_m4mod == NO) return; + + if(tree->mod->m4mod->n_h == 1) return; + + int i; + + for(i=0;imod->m4mod->n_h;i++) + { + tree->mod->m4mod->multipl_unscaled[i] = (phydbl)i+1.; + tree->mod->m4mod->h_fq_unscaled[i] = Uni()*(100.-0.01) + 0.01; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Randomize_Covarion_Switch(t_tree *tree) +{ + if(tree->mod->use_m4mod == NO) return; + + tree->mod->m4mod->delta = Uni()*(10.-0.01)+0.01; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Randomize_Branch_Lengths(t_tree *tree) +{ + int i; + + if(tree->mod->log_l == NO) + For(i,2*tree->n_otu-3) tree->a_edges[i]->l->v = Rexp(10.); + else + For(i,2*tree->n_otu-3) tree->a_edges[i]->l->v = -4* Uni(); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Randomize_Node_Rates(t_tree *tree) +{ + + int i,err; + phydbl mean_r, var_r; + phydbl min_r, max_r; + + mean_r = 1.0; + var_r = 0.5; + min_r = tree->rates->min_rate; + max_r = tree->rates->max_rate; + + for(i=0;i<2*tree->n_otu-2;++i) + if(tree->a_nodes[i] != tree->n_root) + { + tree->rates->nd_r[i] = Rnorm_Trunc(mean_r,SQRT(var_r),min_r,max_r,&err); + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Randomize_Rates(t_tree *tree) +{ + + /* Should be called once t_node times have been determined */ + + int i; + + For(i,2*tree->n_otu-2) tree->rates->br_r[i] = 1.0; + +/* For(i,2*tree->n_otu-2) */ +/* { */ +/* u = Uni(); */ +/* u = u * (r_max-r_min) + r_min; */ +/* tree->rates->br_r[i] = u; */ + +/* if(tree->rates->br_r[i] < tree->rates->min_rate) tree->rates->br_r[i] = tree->rates->min_rate; */ +/* if(tree->rates->br_r[i] > tree->rates->max_rate) tree->rates->br_r[i] = tree->rates->max_rate; */ +/* } */ + + MCMC_Randomize_Rates_Pre(tree->n_root,tree->n_root->v[2],tree); + MCMC_Randomize_Rates_Pre(tree->n_root,tree->n_root->v[1],tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Randomize_Rates_Pre(t_node *a, t_node *d, t_tree *tree) +{ + int i; + phydbl mean_r, sd_r; + phydbl min_r, max_r; + int err; + + mean_r = 1.0; + sd_r = 1.0; + min_r = tree->rates->min_rate; + max_r = tree->rates->max_rate; + err = -1; + + tree->rates->br_r[d->num] = Rnorm_Trunc(mean_r,sd_r,min_r,max_r,&err); + if(err == YES) + { + PhyML_Fprintf(stderr,"\n. mean_r: %f sd_r: %f min_r: %f max_r: %f", + mean_r, + sd_r, + min_r, + max_r); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + if(d->tax) return; + else + { + for(i=0;i<3;++i) + if(d->v[i] != a && d->b[i] != tree->e_root) + MCMC_Randomize_Rates_Pre(d,d->v[i],tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Randomize_Birth(t_tree *tree) +{ + phydbl min_b,max_b; + phydbl u; + + min_b = tree->rates->birth_rate_min; + max_b = MIN(0.5,tree->rates->birth_rate_max); + + u = Uni(); + tree->rates->birth_rate = (max_b - min_b) * u + min_b; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Randomize_Death(t_tree *tree) +{ + phydbl min_d,max_d; + phydbl u; + + min_d = tree->rates->death_rate_min; + max_d = MIN(MIN(0.5,tree->rates->death_rate_max),tree->rates->birth_rate); + + u = Uni(); + tree->rates->death_rate = (max_d - min_d) * u + min_d; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Randomize_Nu(t_tree *tree) +{ + phydbl min_nu,max_nu; + phydbl u; + + /* It is preferable to start with small values of nu + as if is difficult for the MCMC sampler to sample + equal rates on edge (i.e., molecular clock) since + such combination of rate lies on the boundary of + the space of all edge rate combination. We give + here a bit of help to the sampler by considering + starting points close to the molecular clock + constraint. + */ + min_nu = tree->rates->min_nu; + max_nu = tree->rates->max_nu/10.; + + u = Uni(); + tree->rates->nu = (max_nu - min_nu) * u + min_nu; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Randomize_Clock_Rate(t_tree *tree) +{ + phydbl u; + u = Uni(); + if(tree->mod->s_opt->opt_clock_r == YES) tree->rates->clock_r = u * (1.0 - tree->rates->min_clock) + tree->rates->min_clock; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Randomize_Alpha(t_tree *tree) +{ + phydbl u; + + u = Uni(); + tree->rates->alpha = u*6.0+1.0; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Randomize_Node_Times(t_tree *tree) +{ + phydbl t_sup, t_inf; + phydbl u; + int iter; + int i; + phydbl dt,min_dt; + int min_node; + + t_inf = tree->rates->t_prior_min[tree->n_root->num]; + t_sup = tree->rates->t_prior_max[tree->n_root->num]; + + u = Uni(); + u *= (t_sup - t_inf); + u += t_inf; + + tree->rates->nd_t[tree->n_root->num] = u; + + printf("\n. ROOT: %f %f %d",t_inf,t_sup,tree->n_root->num); + printf("\n. ROOT: %f",u); + + MCMC_Randomize_Node_Times_Top_Down(tree->n_root,tree->n_root->v[2],tree); + MCMC_Randomize_Node_Times_Top_Down(tree->n_root,tree->n_root->v[1],tree); + + min_node = -1; + iter = 0; + do + { + min_dt = MDBL_MAX; + For(i,2*tree->n_otu-2) + { + dt = tree->rates->nd_t[i] - tree->rates->nd_t[tree->a_nodes[i]->anc->num]; + if(dt < min_dt) + { + min_dt = dt; + min_node = i; + } + } + + if(min_dt > 0.01 * FABS(tree->rates->nd_t[tree->n_root->num])/(phydbl)(tree->n_otu-1)) break; + + RATES_Record_Times(tree); + For(i,2*tree->n_otu-1) + { + if(tree->a_nodes[i]->tax == NO) + tree->rates->nd_t[i] -= 0.1*FABS(tree->rates->nd_t[tree->n_root->num])/(phydbl)(tree->n_otu-1); + + if(tree->rates->nd_t[i] < tree->rates->t_prior_min[i] || + tree->rates->nd_t[i] > tree->rates->t_prior_max[i]) + { + RATES_Reset_Times(tree); + break; + } + } + + MCMC_Randomize_Node_Times_Bottom_Up(tree->n_root,tree->n_root->v[2],tree); + MCMC_Randomize_Node_Times_Bottom_Up(tree->n_root,tree->n_root->v[1],tree); + + iter++; + } + while(iter < 1000); + + if(iter == 1000) + { + PhyML_Fprintf(stderr,"\n. min_dt = %f",min_dt); + PhyML_Fprintf(stderr,"\n. min->t=%f min->anc->t=%f",tree->rates->nd_t[min_node],tree->rates->nd_t[tree->a_nodes[min_node]->anc->num]); + PhyML_Fprintf(stderr,"\n. d up=%f down=%f",tree->rates->t_prior_min[min_node],tree->rates->t_prior_max[min_node]); + PhyML_Fprintf(stderr,"\n. a up=%f down=%f",tree->rates->t_prior_min[tree->a_nodes[min_node]->anc->num],tree->rates->t_prior_max[tree->a_nodes[min_node]->anc->num]); + PhyML_Fprintf(stderr,"\n. up=%f down=%f",tree->rates->t_prior_min[min_node],tree->rates->t_floor[tree->a_nodes[min_node]->anc->num]); + PhyML_Fprintf(stderr,"\n. min_node = %d",min_node); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + +/* PhyML_Printf("\n. Needed %d iterations to randomize node heights.",iter); */ +/* TIMES_Print_Node_Times(tree->n_root,tree->n_root->v[2],tree); */ +/* TIMES_Print_Node_Times(tree->n_root,tree->n_root->v[1],tree); */ + + if(RATES_Check_Node_Times(tree)) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Randomize_Node_Times_Bottom_Up(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax) return; + else + { + int i; + phydbl u; + phydbl t_inf, t_sup; + t_node *v1, *v2; + + + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + MCMC_Randomize_Node_Times_Bottom_Up(d,d->v[i],tree); + } + } + + v1 = v2 = NULL; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(!v1) v1 = d->v[i]; + else v2 = d->v[i]; + } + } + + t_sup = MIN(tree->rates->nd_t[v1->num],tree->rates->nd_t[v2->num]); + t_inf = tree->rates->nd_t[a->num]; + + u = Uni(); + u *= (t_sup - t_inf); + u += t_inf; + + + if(u > tree->rates->t_prior_min[d->num] && u < tree->rates->t_prior_max[d->num]) + tree->rates->nd_t[d->num] = u; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Randomize_Node_Times_Top_Down(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax) return; + else + { + int i; + phydbl u; + phydbl t_inf, t_sup; + + t_inf = MAX(tree->rates->nd_t[a->num],tree->rates->t_prior_min[d->num]); + t_sup = tree->rates->t_prior_max[d->num]; + + u = Uni(); + u *= (t_sup - t_inf); + u += t_inf; + + tree->rates->nd_t[d->num] = u; + + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + MCMC_Randomize_Node_Times_Top_Down(d,d->v[i],tree); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Get_Acc_Rates(t_mcmc *mcmc) +{ + int i; + phydbl eps; + int lag; + + + lag = 100; + + eps = 1.E-6; + + for(i=0;in_moves;i++) + { + if(mcmc->run_move[i] - mcmc->prev_run_move[i] > lag) + { + mcmc->acc_rate[i] = + (phydbl)(mcmc->acc_move[i] - mcmc->prev_acc_move[i] + eps) / + (phydbl)(mcmc->run_move[i] - mcmc->prev_run_move[i] + eps) ; + + + mcmc->prev_run_move[i] = mcmc->run_move[i]; + mcmc->prev_acc_move[i] = mcmc->acc_move[i]; + + MCMC_Adjust_Tuning_Parameter(i,mcmc); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Adjust_Tuning_Parameter(int move, t_mcmc *mcmc) +{ + if(mcmc->adjust_tuning[move] == YES) + { + phydbl scale; + phydbl rate; + phydbl rate_inf,rate_sup; + + if(mcmc->run < (int)(0.01*mcmc->chain_len)) scale = 1.5; + else scale = 1.2; + + if(!strcmp(mcmc->move_name[move],"tree_height")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"subtree_height")) + { + rate_inf = 0.2; + rate_sup = 0.2; + } + else if(!strcmp(mcmc->move_name[move],"updown_t_cr")) + { + rate_inf = 0.1; + rate_sup = 0.1; + } + else if(!strcmp(mcmc->move_name[move],"clock")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + + /* if(!strcmp(mcmc->move_name[move],"tree_rates")) */ + /* { */ + /* rate_inf = 0.05; */ + /* rate_sup = 0.05; */ + /* } */ + else if(!strcmp(mcmc->move_name[move],"phyrex_lbda")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"phyrex_mu")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"phyrex_rad")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"phyrex_ldsk_and_disk")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"phyrex_ldsk_multi")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"phyrex_disk_multi")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"phyrex_indel_disk")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"phyrex_indel_hit")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"phyrex_scale_times")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"phyrex_ldsk_given_disk")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else if(!strcmp(mcmc->move_name[move],"phyrex_disk_given_ldsk")) + { + rate_inf = 0.234; + rate_sup = 0.234; + } + else + { + rate_inf = 0.234; // Gareth Robert's magic number ! + rate_sup = 0.234; + } + + + rate = mcmc->acc_rate[move]; + + if(rate < rate_inf) + { + mcmc->tune_move[move] /= scale; + } + + else if(rate > rate_sup) + { + mcmc->tune_move[move] *= scale; + } + + if(mcmc->tune_move[move] > mcmc->max_tune) mcmc->tune_move[move] = mcmc->max_tune; + if(mcmc->tune_move[move] < mcmc->min_tune) mcmc->tune_move[move] = mcmc->min_tune; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_One_Length(t_edge *b, t_tree *tree) +{ + phydbl u; + phydbl new_lnL_seq, cur_lnL_seq; + phydbl ratio, alpha; + phydbl new_l, cur_l; + phydbl K,mult; + + + cur_l = b->l->v; + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + K = 0.1; + + u = Uni(); + mult = exp(K*(u-0.5)); + /* mult = u*(K-1./K)+1./K; */ + new_l = cur_l * mult; + + if(new_l < tree->mod->l_min || new_l > tree->mod->l_max) return; + + b->l->v = new_l; + if(tree->eval_alnL == YES) new_lnL_seq = Lk(b,tree); + + ratio = + (new_lnL_seq - cur_lnL_seq) + + (log(mult)); + + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + b->l->v = cur_l; + Update_PMat_At_Given_Edge(b,tree); + tree->c_lnL = cur_lnL_seq; + } + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Scale_Br_Lens(t_tree *tree) +{ + phydbl u; + phydbl new_lnL_seq, cur_lnL_seq; + phydbl ratio, alpha; + phydbl K,mult; + int i; + + Record_Br_Len(tree); + + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + K = 1.2; + + u = Uni(); + mult = u*(K-1./K)+1./K; + + for(i=0;i<2*tree->n_otu-3;++i) + { + tree->a_edges[i]->l->v *= mult; + if(tree->a_edges[i]->l->v < tree->mod->l_min || + tree->a_edges[i]->l->v > tree->mod->l_max) return; + } + + Set_Both_Sides(NO,tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + + ratio = + (new_lnL_seq - cur_lnL_seq) + + (2*tree->n_otu-5) * (log(mult)); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + Restore_Br_Len(tree); + tree->c_lnL = cur_lnL_seq; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Br_Lens(t_tree *tree) +{ + MCMC_Br_Lens_Pre(tree->a_nodes[0], + tree->a_nodes[0]->v[0], + tree->a_nodes[0]->b[0],tree); + + /* int i; */ + /* For(i,2*tree->n_otu-3) */ + /* { */ + /* MCMC_One_Length(tree->a_edges[Rand_Int(0,2*tree->n_otu-4)],acc,run,tree); */ + /* } */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Br_Lens_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree) +{ + int i; + + if(a == tree->n_root || d == tree->n_root) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + MCMC_One_Length(b,tree); + if(d->tax) return; + else + { + for(i=0;i<3;i++) + if(d->v[i] != a) + { + Update_Partial_Lk(tree,d->b[i],d); + MCMC_Br_Lens_Pre(d,d->v[i],d->b[i],tree); + } + Update_Partial_Lk(tree,b,d); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Potentially one kappa parameter for each tree in a mixture -> update each of them +void MCMC_Kappa(t_tree *mixt_tree) +{ + t_tree *tree; + phydbl cur_kappa,new_kappa; + phydbl u,alpha,ratio; + phydbl min_kappa,max_kappa; + phydbl K; + phydbl cur_lnL_seq, new_lnL_seq; + + if(mixt_tree->eval_alnL == NO) return; + + Set_Update_Eigen(YES,mixt_tree->mod); + + tree = mixt_tree; + + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + + if(!(tree->mod->whichmodel == HKY85 || tree->mod->whichmodel == K80 || tree->mod->whichmodel == TN93)) tree = tree->next; + + if(tree == NULL) return; + + cur_kappa = -1.0; + new_kappa = -1.0; + ratio = 0.0; + + K = mixt_tree->mcmc->tune_move[mixt_tree->mcmc->num_move_kappa]; + + cur_lnL_seq = mixt_tree->c_lnL; + new_lnL_seq = mixt_tree->c_lnL; + cur_kappa = tree->mod->kappa->v; + + min_kappa = 0.1; + max_kappa = 100.; + + MCMC_Make_Move(&cur_kappa,&new_kappa,min_kappa,max_kappa,&ratio,K,mixt_tree->mcmc->move_type[mixt_tree->mcmc->num_move_kappa]); + + if(new_kappa < max_kappa && new_kappa > min_kappa) + { + tree->mod->kappa->v = new_kappa; + + if(mixt_tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,mixt_tree); + + ratio += (new_lnL_seq - cur_lnL_seq); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + tree->mod->kappa->v = cur_kappa; + mixt_tree->c_lnL = cur_lnL_seq; + if(!Set_Model_Parameters(mixt_tree->mod)) + { + PhyML_Fprintf(stderr,"\n. Problem in move %s",tree->mcmc->move_name[tree->mcmc->move_idx]); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + else + { + mixt_tree->mcmc->acc_move[mixt_tree->mcmc->num_move_kappa]++; + } + + /* PhyML_Printf("\n. MCMC cur_k: %f new_k: %f cur: %f new: %f k: %f -> %f",cur_kappa,new_kappa,cur_lnL_seq,new_lnL_seq,tree->mod->kappa->v,mixt_tree->c_lnL); */ + + } + mixt_tree->mcmc->run_move[mixt_tree->mcmc->num_move_kappa]++; + + tree = tree->next; + } + while(tree != NULL); + + Set_Update_Eigen(NO,mixt_tree->mod); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Potentially one set of relative rate parameters for each tree in a mixture -> update each of them + +void MCMC_RR(t_tree *mixt_tree) +{ + t_tree *tree; + phydbl cur_rr,new_rr; + phydbl u,alpha,ratio; + int n_r_mat,*permut; + phydbl K; + phydbl cur_lnL_seq, new_lnL_seq; + t_rmat **r_mat; + int i; + + if(mixt_tree->eval_alnL == NO) return; + + Set_Update_Eigen(YES,mixt_tree->mod); + + tree = mixt_tree; + n_r_mat = 0; + r_mat = NULL; + permut = NULL; + + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + + if(!(tree->mod->whichmodel == GTR || tree->mod->whichmodel == CUSTOM)) tree = tree->next; + + if(tree == NULL) return; + + for(i=0;imod->r_mat == r_mat[i]) break; + + if(i == n_r_mat && + (tree->mod->whichmodel == GTR || tree->mod->whichmodel == CUSTOM) && + tree->mod->r_mat->n_diff_rr > 1) + { + permut = Permutate(tree->mod->r_mat->n_diff_rr); + + for(i=0;imod->r_mat->n_diff_rr;++i) + { + cur_rr = -1.0; + new_rr = -1.0; + ratio = 0.0; + K = 1.0; + cur_lnL_seq = mixt_tree->c_lnL; + new_lnL_seq = UNLIKELY; + + mixt_tree->mcmc->run_move[mixt_tree->mcmc->num_move_rr]++; + + cur_rr = tree->mod->r_mat->rr_val->v[permut[i]]; + + MCMC_Make_Move(&cur_rr,&new_rr,UNSCALED_RR_MIN,UNSCALED_RR_MAX,&ratio,K,mixt_tree->mcmc->move_type[mixt_tree->mcmc->num_move_rr]); + + if(new_rr < UNSCALED_RR_MAX && new_rr > UNSCALED_RR_MIN) + { + tree->mod->r_mat->rr_val->v[permut[i]] = new_rr; + + new_lnL_seq = Lk(NULL,mixt_tree); + + ratio += (new_lnL_seq - cur_lnL_seq); + ratio += log(new_rr) - log(cur_rr); /* Because we are updating log(rr) instead of rr */ + + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + tree->mod->r_mat->rr_val->v[permut[i]] = cur_rr; + mixt_tree->c_lnL = cur_lnL_seq; + if(!Set_Model_Parameters(mixt_tree->mod)) + { + PhyML_Fprintf(stderr,"\n. Problem in move %s",tree->mcmc->move_name[tree->mcmc->move_idx]); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + else + { + mixt_tree->mcmc->acc_move[mixt_tree->mcmc->num_move_rr]++; + } + + /* PhyML_Printf("\n. MCMC cur_rr: %f new_rr: %f cur: %f new: %f",cur_rr,new_rr,cur_lnL_seq,new_lnL_seq); */ + } + } + Free(permut); + } + tree = tree->next; + } + while(tree != NULL); + + Set_Update_Eigen(NO,mixt_tree->mod); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Rate_Across_Sites(t_tree *tree) +{ + int i; + + if(tree->mod->ras->n_catg == 1) return; + + for(i=0;imod->ras->n_catg;i++) + { + if(tree->mod->ras->free_mixt_rates == YES) MCMC_Free_Mixt_Rate(tree); + else MCMC_Alpha(tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Alpha(t_tree *tree) +{ + int i; + + For(i,2*tree->n_otu-2) tree->rates->br_do_updt[i] = NO; + MCMC_Single_Param_Generic(&(tree->mod->ras->alpha->v),0.,100.,tree->mcmc->num_move_ras, + NULL,&(tree->c_lnL), + NULL,Wrap_Lk,tree->mcmc->move_type[tree->mcmc->num_move_ras],NO,NULL,tree,NULL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Free_Mixt_Rate(t_tree *mixt_tree) +{ + t_tree *tree; + phydbl *u,*v; + phydbl *f; + phydbl cur_val; + phydbl cur_A, new_A; + phydbl low_bound,up_bound; + unsigned int k,i,idx; + phydbl hr,z; + int n_moves; + phydbl cur_lnL_seq, new_lnL_seq; + phydbl ratio,alpha; + + tree = mixt_tree; + + do + { + + tree->mod->ras->sort_rate_classes = YES; + tree->mod->ras->normalise_rr = YES; + + cur_lnL_seq = mixt_tree->c_lnL; + new_lnL_seq = mixt_tree->c_lnL; + + k = tree->mod->ras->n_catg; + + f = tree->mod->ras->gamma_r_proba->v; + + u = tree->mod->ras->gamma_r_proba_unscaled->v; + v = tree->mod->ras->gamma_rr_unscaled->v; + + + // Setting the values of the unscaled rr freq as is done below + // does not lead to changing the likelihood. + u[0] = f[0]; + for(i=1;imod); + for(i=0;i GAMMA_RR_UNSCALED_MAX) break; + if(v[i] < GAMMA_R_PROBA_UNSCALED_MIN || v[i] > GAMMA_R_PROBA_UNSCALED_MAX) break; + } + if(i != k) new_lnL_seq = -INFINITY; + else new_lnL_seq = Lk(NULL,mixt_tree); + + new_A = 0.0; + for(i=0;i new: %f",idx,u[idx],cur_val,cur_lnL_seq,new_lnL_seq); */ + + z = Uni(); + if(z > alpha) /* Reject */ + { + u[idx] = cur_val; + + if(!Set_Model_Parameters(mixt_tree->mod)) + { + PhyML_Fprintf(stderr,"\n. Problem in move %s",tree->mcmc->move_name[tree->mcmc->move_idx]); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + /* phydbl cur_lk = cur_lnL_seq; */ + /* phydbl new_lk = Lk(NULL,mixt_tree); */ + /* if(Are_Equal(cur_lk,new_lk,1.E-5) == NO) */ + /* { */ + /* PhyML_Printf("\n. new: %f cur: %f",new_lk,cur_lk); */ + /* assert(FALSE); */ + /* } */ + + mixt_tree->c_lnL = cur_lnL_seq; + } + else /* Accept */ + { + cur_lnL_seq = new_lnL_seq; + } + + } + else + { + // Update rates + + cur_A = 0.0; + for(i=0;imod); + for(i=0;i GAMMA_RR_UNSCALED_MAX) break; + if(v[i] < GAMMA_R_PROBA_UNSCALED_MIN || v[i] > GAMMA_R_PROBA_UNSCALED_MAX) break; + } + if(i != k) new_lnL_seq = -INFINITY; + else new_lnL_seq = Lk(NULL,mixt_tree); + + new_A = 0.0; + for(i=0;i new: %f",idx,v[idx],cur_val,cur_lnL_seq,new_lnL_seq); */ + + + z = Uni(); + if(z > alpha) /* Reject */ + { + v[idx] = cur_val; + + if(!Set_Model_Parameters(mixt_tree->mod)) + { + PhyML_Fprintf(stderr,"\n. Problem in move %s",tree->mcmc->move_name[tree->mcmc->move_idx]); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + + /* phydbl cur_lk = cur_lnL_seq; */ + /* phydbl new_lk = Lk(NULL,mixt_tree); */ + /* if(Are_Equal(cur_lk,new_lk,1.E-5) == NO) */ + /* { */ + /* PhyML_Printf("\n. new: %f cur: %f",new_lk,cur_lk); */ + /* assert(FALSE); */ + /* } */ + + mixt_tree->c_lnL = cur_lnL_seq; + } + else /* Accept */ + { + cur_lnL_seq = new_lnL_seq; + } + + } + } + while(n_moves != k); + + tree = tree->next_mixt; + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Covarion_Rates(t_tree *tree) +{ + int i, class; + phydbl u; + phydbl min,max; + + if(tree->mod->use_m4mod == NO) return; + + Set_Update_Eigen(YES,tree->mod); + + For(i,2*tree->n_otu-2) tree->rates->br_do_updt[i] = YES; + + class = Rand_Int(0,tree->mod->m4mod->n_h-1); + + + min = 0.01; + max = 100.; + u = Uni(); + if(u < .5) + { + if(!class) + { + min = 0.01; + max = tree->mod->m4mod->multipl_unscaled[1]; + } + else if(class == tree->mod->m4mod->n_h-1) + { + min = tree->mod->m4mod->multipl_unscaled[tree->mod->m4mod->n_h-2]; + max = +100.; + } + else + { + min = MIN(tree->mod->m4mod->multipl_unscaled[class-1],tree->mod->m4mod->multipl_unscaled[class+1]); + max = MAX(tree->mod->m4mod->multipl_unscaled[class-1],tree->mod->m4mod->multipl_unscaled[class+1]); + } + + MCMC_Single_Param_Generic(&(tree->mod->m4mod->multipl_unscaled[class]),min,max,tree->mcmc->num_move_cov_rates+class+tree->mod->m4mod->n_h, + NULL,&(tree->c_lnL), + NULL,Wrap_Lk,tree->mcmc->move_type[tree->mcmc->num_move_cov_rates+class+tree->mod->m4mod->n_h],NO,NULL,tree,NULL); + } + else + { + MCMC_Single_Param_Generic(&(tree->mod->m4mod->h_fq_unscaled[class]),0.01,+100.,tree->mcmc->num_move_cov_rates+class, + NULL,&(tree->c_lnL), + NULL,Wrap_Lk,tree->mcmc->move_type[tree->mcmc->num_move_cov_rates+class],NO,NULL,tree,NULL); + } + + Set_Update_Eigen(NO,tree->mod); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void MCMC_Covarion_Switch(t_tree *tree) +{ + if(tree->mod->use_m4mod == NO) return; + + Set_Update_Eigen(YES,tree->mod); + MCMC_Single_Param_Generic(&(tree->mod->m4mod->delta),0.01,+100.,tree->mcmc->num_move_cov_switch, + NULL,&(tree->c_lnL), + NULL,Wrap_Lk,tree->mcmc->move_type[tree->mcmc->num_move_cov_switch],NO,NULL,tree,NULL); + Set_Update_Eigen(NO,tree->mod); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Birth_Rate(t_tree *tree) +{ + /* MCMC_Single_Param_Generic(&(tree->rates->birth_rate), */ + /* tree->rates->birth_rate_min, */ + /* tree->rates->birth_rate_max, */ + /* tree->mcmc->num_move_birth_rate, */ + /* &(tree->rates->c_lnL_times),NULL, */ + /* Wrap_Lk_Times,NULL,tree->mcmc->move_type[tree->mcmc->num_move_birth_rate],NO,NULL,tree,NULL); */ + + phydbl cur_birth_rate,new_birth_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl cur_lnL_time_ghost,new_lnL_time_ghost; + /* phydbl cur_lnL_time_pivot,new_lnL_time_pivot; */ + phydbl u,alpha,ratio; + phydbl birth_rate_min,birth_rate_max; + phydbl K; + int i,n_mcmc_steps,move; + + cur_birth_rate = -1.0; + new_birth_rate = -1.0; + ratio = 0.0; + n_mcmc_steps = tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] == 1 ? 1000 : 100; + move = -1; + + K = tree->mcmc->tune_move[tree->mcmc->num_move_birth_rate]; + + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + cur_lnL_time_ghost = UNLIKELY; + new_lnL_time_ghost = UNLIKELY; + + /* cur_lnL_time_pivot = UNLIKELY; */ + /* new_lnL_time_pivot = UNLIKELY; */ + + cur_birth_rate = tree->rates->birth_rate; + + birth_rate_min = MAX(tree->rates->birth_rate_min,tree->rates->death_rate); + birth_rate_max = tree->rates->birth_rate_max; + + MCMC_Make_Move(&cur_birth_rate,&new_birth_rate,birth_rate_min,birth_rate_max,&ratio,K,tree->mcmc->move_type[tree->mcmc->num_move_birth_rate]); + /* new_birth_rate = Uni()*(birth_rate_max - birth_rate_min) + birth_rate_min; */ + + if(new_birth_rate < birth_rate_max && new_birth_rate > birth_rate_min && new_birth_rate > tree->rates->death_rate) + { + tree->rates->birth_rate = new_birth_rate; + new_lnL_time = TIMES_Lk_Times(NO,tree); + ratio += (new_lnL_time - cur_lnL_time); + + /* printf("\n. b :%4d: %12G -> %12G ratio : %12G [real: %12G %12G]", */ + /* tree->mcmc->run_move[tree->mcmc->num_move_birth_rate], */ + /* cur_birth_rate, */ + /* new_birth_rate, */ + /* ratio, */ + /* cur_lnL_time, */ + /* new_lnL_time); */ + + + if(tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] == 500) + { + tree->rates->birth_rate_pivot = tree->rates->birth_rate; + tree->rates->death_rate_pivot = tree->rates->death_rate; + } + + if(tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] >= 0) + { + /* if(tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] >= 500) */ + /* { */ + /* tree->extra_tree->rates->birth_rate = tree->rates->birth_rate_pivot; */ + /* tree->extra_tree->rates->death_rate = tree->rates->death_rate_pivot; */ + /* cur_lnL_time_pivot = TIMES_Lk_Times(NO,tree->extra_tree); */ + /* } */ + + /* tree->extra_tree->rates->birth_rate = cur_birth_rate; */ + /* tree->extra_tree->rates->death_rate = tree->rates->death_rate; */ + /* cur_lnL_time_ghost = TIMES_Lk_Times(NO,tree->extra_tree); */ + + /* Copy_Tree(tree->extra_tree,tree->extra_tree->extra_tree); */ + /* RATES_Copy_Rate_Struct(tree->extra_tree->rates,tree->extra_tree->extra_tree->rates,tree->n_otu); */ + /* DATE_Assign_Primary_Calibration(tree->extra_tree->extra_tree); */ + + + + tree->extra_tree->eval_alnL = NO; + tree->extra_tree->eval_rlnL = NO; + tree->extra_tree->eval_glnL = YES; + tree->extra_tree->rates->birth_rate = new_birth_rate; + tree->extra_tree->rates->c_lnL_rates = UNLIKELY; + tree->extra_tree->c_lnL = UNLIKELY; + + TIMES_Randomize_Tree_With_Time_Constraints(tree->extra_tree->rates->a_cal[0],tree->extra_tree); + tree->extra_tree->rates->birth_rate = new_birth_rate; + tree->extra_tree->rates->death_rate = tree->rates->death_rate; + TIMES_Lk_Times(NO,tree->extra_tree); + + if(!(tree->extra_tree->rates->c_lnL_times > UNLIKELY)) + { + PhyML_Fprintf(stderr,"\n. glnL=%f",tree->extra_tree->rates->c_lnL_times); + PhyML_Fprintf(stderr,"\n. birth=%G death=%G [%G]",new_birth_rate,tree->rates->death_rate,tree->extra_tree->rates->death_rate); + TIMES_Lk_Times(YES,tree->extra_tree); + assert(FALSE); + } + + i = 0; + do + { + u = Uni(); + for(move=0;movemcmc->n_moves;move++) if(tree->mcmc->move_weight[move] > u-1.E-10) break; + + + /* if(!(i%10)) PhyML_Printf("\n<< %5d Move '%20s' %12f",i,tree->mcmc->move_name[move],tree->extra_tree->rates->c_lnL_times); */ + + if(!strcmp(tree->mcmc->move_name[move],"tree_height")) { MCMC_Tree_Height(tree->extra_tree); i++; } + if(!strcmp(tree->mcmc->move_name[move],"times")) { MCMC_Times_All(tree->extra_tree); i++; } + if(!strcmp(tree->mcmc->move_name[move],"spr")) { MCMC_Prune_Regraft(tree->extra_tree); i++; } + if(!strcmp(tree->mcmc->move_name[move],"spr_local")) { MCMC_Prune_Regraft_Local(tree->extra_tree); i++; } + + if(!(tree->extra_tree->rates->c_lnL_times > UNLIKELY)) + { + PhyML_Fprintf(stderr,"\n. move: %s",tree->mcmc->move_name[move]); + PhyML_Fprintf(stderr,"\n. glnL=%f",tree->extra_tree->rates->c_lnL_times); + TIMES_Lk_Times(YES,tree->extra_tree); + assert(FALSE); + } + + /* PhyML_Printf("\n.> %4d %15f",i,tree->extra_tree->rates->c_lnL_times); */ + } + while(i < n_mcmc_steps); + + tree->extra_tree->rates->birth_rate = cur_birth_rate; + tree->extra_tree->rates->death_rate = tree->rates->death_rate; + cur_lnL_time_ghost = TIMES_Lk_Times(NO,tree->extra_tree); + + tree->extra_tree->rates->birth_rate = new_birth_rate; + tree->extra_tree->rates->death_rate = tree->rates->death_rate; + new_lnL_time_ghost = TIMES_Lk_Times(NO,tree->extra_tree); + + ratio += (cur_lnL_time_ghost - new_lnL_time_ghost); + + /* if(tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] >= 500) */ + /* { */ + /* tree->extra_tree->rates->birth_rate = tree->rates->birth_rate_pivot; */ + /* tree->extra_tree->rates->death_rate = tree->rates->death_rate_pivot; */ + /* new_lnL_time_pivot = TIMES_Lk_Times(NO,tree->extra_tree); */ + /* ratio += (new_lnL_time_pivot - cur_lnL_time_pivot); */ + /* } */ + } + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* printf("\n. b :%4d: %12G -> %12G ratio : %12G [ghost: %12G %12G -- real: %12G %12G]", */ + /* tree->mcmc->run_move[tree->mcmc->num_move_birth_rate], */ + /* cur_birth_rate, */ + /* new_birth_rate, */ + /* ratio, */ + /* cur_lnL_time_ghost, */ + /* new_lnL_time_ghost, */ + /* cur_lnL_time, */ + /* new_lnL_time); */ + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* PhyML_Printf(" reject"); */ + tree->rates->birth_rate = cur_birth_rate; + tree->rates->c_lnL_times = cur_lnL_time; + + /* Copy_Tree(tree->extra_tree->extra_tree,tree->extra_tree); */ + /* RATES_Copy_Rate_Struct(tree->extra_tree->extra_tree->rates,tree->extra_tree->rates,tree->n_otu); */ + /* DATE_Assign_Primary_Calibration(tree->extra_tree); */ + } + else + { + /* PhyML_Printf(" accept"); */ + tree->mcmc->acc_move[tree->mcmc->num_move_birth_rate]++; + } + } + tree->mcmc->run_move[tree->mcmc->num_move_birth_rate]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Death_Rate(t_tree *tree) +{ + + /* MCMC_Single_Param_Generic(&(tree->rates->death_rate), */ + /* 0.0, // instead of tree->rates->death_rate_min as death rate can be equal to 0 (Yule model) */ + /* tree->rates->death_rate_max, */ + /* tree->mcmc->num_move_death_rate, */ + /* &(tree->rates->c_lnL_times),NULL, */ + /* Wrap_Lk_Times,NULL,tree->mcmc->move_type[tree->mcmc->num_move_death_rate],NO,NULL,tree,NULL); */ + + phydbl cur_death_rate,new_death_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl cur_lnL_time_ghost,new_lnL_time_ghost; + /* phydbl cur_lnL_time_pivot,new_lnL_time_pivot; */ + phydbl u,alpha,ratio; + phydbl death_rate_min,death_rate_max; + phydbl K; + int i,n_mcmc_steps,move; + + cur_death_rate = -1.0; + new_death_rate = -1.0; + ratio = 0.0; + n_mcmc_steps = tree->mcmc->run_move[tree->mcmc->num_move_death_rate] == 1 ? 1000 : 100; + move = -1; + + K = tree->mcmc->tune_move[tree->mcmc->num_move_death_rate]; + + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + cur_lnL_time_ghost = UNLIKELY; + new_lnL_time_ghost = UNLIKELY; + + /* cur_lnL_time_pivot = UNLIKELY; */ + /* new_lnL_time_pivot = UNLIKELY; */ + + cur_death_rate = tree->rates->death_rate; + + death_rate_min = tree->rates->death_rate_min; + death_rate_max = MIN(tree->rates->death_rate_max,tree->rates->birth_rate); + + MCMC_Make_Move(&cur_death_rate,&new_death_rate,death_rate_min,death_rate_max,&ratio,K,tree->mcmc->move_type[tree->mcmc->num_move_death_rate]); + /* new_death_rate = Uni()*(death_rate_max - death_rate_min) + death_rate_min; */ + + if(new_death_rate < death_rate_max && new_death_rate > death_rate_min && new_death_rate < tree->rates->birth_rate) + { + tree->rates->death_rate = new_death_rate; + new_lnL_time = TIMES_Lk_Times(NO,tree); + ratio += (new_lnL_time - cur_lnL_time); + + if(tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] >= 0) + { + /* if(tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] >= 500) */ + /* { */ + /* tree->extra_tree->rates->birth_rate = tree->rates->birth_rate_pivot; */ + /* tree->extra_tree->rates->death_rate = tree->rates->death_rate_pivot; */ + /* cur_lnL_time_pivot = TIMES_Lk_Times(NO,tree->extra_tree); */ + /* } */ + + /* tree->extra_tree->rates->death_rate = cur_death_rate; */ + /* tree->extra_tree->rates->birth_rate = tree->rates->birth_rate; */ + /* cur_lnL_time_ghost = TIMES_Lk_Times(NO,tree->extra_tree); */ + + /* Copy_Tree(tree->extra_tree,tree->extra_tree->extra_tree); */ + /* RATES_Copy_Rate_Struct(tree->extra_tree->rates,tree->extra_tree->extra_tree->rates,tree->n_otu); */ + /* DATE_Assign_Primary_Calibration(tree->extra_tree->extra_tree); */ + + + + tree->extra_tree->eval_alnL = NO; + tree->extra_tree->eval_rlnL = NO; + tree->extra_tree->eval_glnL = YES; + tree->extra_tree->rates->c_lnL_rates = UNLIKELY; + tree->extra_tree->c_lnL = UNLIKELY; + + TIMES_Randomize_Tree_With_Time_Constraints(tree->extra_tree->rates->a_cal[0],tree->extra_tree); + tree->extra_tree->rates->birth_rate = tree->rates->birth_rate; + tree->extra_tree->rates->death_rate = new_death_rate; + TIMES_Lk_Times(NO,tree->extra_tree); + + if(!(tree->extra_tree->rates->c_lnL_times > UNLIKELY)) + { + PhyML_Fprintf(stderr,"\n. glnL=%f",tree->extra_tree->rates->c_lnL_times); + PhyML_Fprintf(stderr,"\n. death=%G birth=%G [%G]",new_death_rate,tree->rates->birth_rate,tree->extra_tree->rates->birth_rate); + PhyML_Fprintf(stderr,"\n"); + for(int i=0;iextra_tree->rates->n_cal;++i) + { + t_cal *cal = tree->extra_tree->rates->a_cal[i]; + PhyML_Fprintf(stderr,"\n. calibration %s applies to clade %s\t",cal->id,cal->clade_list[cal->current_clade_idx]->id); + for(int j=0;jclade_list_size;++j) + { + t_clad *clade = cal->clade_list[j]; + PhyML_Fprintf(stderr,"time:%G\t",tree->extra_tree->rates->nd_t[clade->target_nd->num]); + } + } + + PhyML_Fprintf(stderr,"\n"); + TIMES_Lk_Times(YES,tree->extra_tree); + assert(FALSE); + } + + i = 0; + do + { + u = Uni(); + for(move=0;movemcmc->n_moves;move++) if(tree->mcmc->move_weight[move] > u-1.E-10) break; + + /* if(!(i%10)) PhyML_Printf("\n>> %5d Move '%20s' %12f",i,tree->mcmc->move_name[move],tree->extra_tree->rates->c_lnL_times); */ + + if(!strcmp(tree->mcmc->move_name[move],"tree_height")) { MCMC_Tree_Height(tree->extra_tree); i++; } + if(!strcmp(tree->mcmc->move_name[move],"times")) { MCMC_Times_All(tree->extra_tree); i++; } + if(!strcmp(tree->mcmc->move_name[move],"spr")) { MCMC_Prune_Regraft(tree->extra_tree); i++; } + if(!strcmp(tree->mcmc->move_name[move],"spr_local")) { MCMC_Prune_Regraft_Local(tree->extra_tree); i++; } + + if(!(tree->extra_tree->rates->c_lnL_times > UNLIKELY)) + { + PhyML_Fprintf(stderr,"\n. move: %s",tree->mcmc->move_name[move]); + PhyML_Fprintf(stderr,"\n. glnL=%f",tree->extra_tree->rates->c_lnL_times); + TIMES_Lk_Times(YES,tree->extra_tree); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + while(i < n_mcmc_steps); + + tree->extra_tree->rates->death_rate = cur_death_rate; + tree->extra_tree->rates->birth_rate = tree->rates->birth_rate; + cur_lnL_time_ghost = TIMES_Lk_Times(NO,tree->extra_tree); + + tree->extra_tree->rates->birth_rate = tree->rates->birth_rate; + tree->extra_tree->rates->death_rate = new_death_rate; + new_lnL_time_ghost = TIMES_Lk_Times(NO,tree->extra_tree); + + ratio += (cur_lnL_time_ghost - new_lnL_time_ghost); + + /* if(tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] >= 500) */ + /* { */ + /* tree->extra_tree->rates->birth_rate = tree->rates->birth_rate_pivot; */ + /* tree->extra_tree->rates->death_rate = tree->rates->death_rate_pivot; */ + /* new_lnL_time_pivot = TIMES_Lk_Times(NO,tree->extra_tree); */ + /* ratio += (new_lnL_time_pivot - cur_lnL_time_pivot); */ + /* } */ + } + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* printf("\n. d :%4d: %12G -> %12G ratio : %12G [ghost: %12G %12G -- real: %12G %12G]", */ + /* tree->mcmc->run_move[tree->mcmc->num_move_death_rate], */ + /* cur_death_rate, */ + /* new_death_rate, */ + /* ratio, */ + /* cur_lnL_time_ghost, */ + /* new_lnL_time_ghost, */ + /* cur_lnL_time, */ + /* new_lnL_time); */ + + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* PhyML_Printf(" reject"); */ + tree->rates->death_rate = cur_death_rate; + tree->rates->c_lnL_times = cur_lnL_time; + + /* Copy_Tree(tree->extra_tree->extra_tree,tree->extra_tree); */ + /* RATES_Copy_Rate_Struct(tree->extra_tree->extra_tree->rates,tree->extra_tree->rates,tree->n_otu); */ + /* DATE_Assign_Primary_Calibration(tree->extra_tree); */ + } + else + { + /* PhyML_Printf(" accept"); */ + tree->mcmc->acc_move[tree->mcmc->num_move_death_rate]++; + } + } + tree->mcmc->run_move[tree->mcmc->num_move_death_rate]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Birth_Death_Updown(t_tree *tree) +{ + phydbl cur_death_rate,new_death_rate; + phydbl cur_birth_rate,new_birth_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl cur_lnL_time_ghost,new_lnL_time_ghost; + /* phydbl cur_lnL_time_pivot,new_lnL_time_pivot; */ + phydbl u,alpha,ratio; + phydbl death_rate_min,death_rate_max; + phydbl birth_rate_min,birth_rate_max; + phydbl K,scale; + int i,n_mcmc_steps,move; + + cur_death_rate = -1.0; + new_death_rate = -1.0; + cur_birth_rate = -1.0; + new_birth_rate = -1.0; + ratio = 0.0; + n_mcmc_steps = tree->mcmc->run_move[tree->mcmc->num_move_birth_death_updown] == 1 ? 1000 : 100; + move = -1; + + K = tree->mcmc->tune_move[tree->mcmc->num_move_birth_death_updown]; + + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + cur_lnL_time_ghost = UNLIKELY; + new_lnL_time_ghost = UNLIKELY; + + /* cur_lnL_time_pivot = UNLIKELY; */ + /* new_lnL_time_pivot = UNLIKELY; */ + + cur_death_rate = tree->rates->death_rate; + cur_birth_rate = tree->rates->birth_rate; + + death_rate_min = tree->rates->death_rate_min; + death_rate_max = tree->rates->death_rate_max; + + birth_rate_min = tree->rates->birth_rate_min; + birth_rate_max = tree->rates->birth_rate_max; + + scale = exp(K*(Uni()-.5)); + new_birth_rate = cur_birth_rate * scale; + new_death_rate = cur_death_rate * scale; + ratio += 2.*log(scale); + + if(new_death_rate < death_rate_max && new_death_rate > death_rate_min && + new_birth_rate < birth_rate_max && new_birth_rate > birth_rate_min && + new_death_rate < new_birth_rate) + { + tree->rates->death_rate = new_death_rate; + tree->rates->birth_rate = new_birth_rate; + new_lnL_time = TIMES_Lk_Times(NO,tree); + ratio += (new_lnL_time - cur_lnL_time); + + if(tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] >= 0) + { + /* if(tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] >= 500) */ + /* { */ + /* tree->extra_tree->rates->death_rate = tree->rates->death_rate_pivot; */ + /* tree->extra_tree->rates->birth_rate = tree->rates->birth_rate_pivot; */ + /* cur_lnL_time_pivot = TIMES_Lk_Times(NO,tree->extra_tree); */ + /* } */ + + /* tree->extra_tree->rates->death_rate = cur_death_rate; */ + /* tree->extra_tree->rates->birth_rate = cur_birth_rate; */ + /* cur_lnL_time_ghost = TIMES_Lk_Times(NO,tree->extra_tree); */ + + /* Copy_Tree(tree->extra_tree,tree->extra_tree->extra_tree); */ + /* RATES_Copy_Rate_Struct(tree->extra_tree->rates,tree->extra_tree->extra_tree->rates,tree->n_otu); */ + /* DATE_Assign_Primary_Calibration(tree->extra_tree->extra_tree); */ + + tree->extra_tree->eval_alnL = NO; + tree->extra_tree->eval_rlnL = NO; + tree->extra_tree->eval_glnL = YES; + tree->extra_tree->rates->c_lnL_rates = UNLIKELY; + tree->extra_tree->c_lnL = UNLIKELY; + + TIMES_Randomize_Tree_With_Time_Constraints(tree->extra_tree->rates->a_cal[0],tree->extra_tree); + tree->extra_tree->rates->death_rate = new_death_rate; + tree->extra_tree->rates->birth_rate = new_birth_rate; + TIMES_Lk_Times(NO,tree->extra_tree); + + if(!(tree->extra_tree->rates->c_lnL_times > UNLIKELY)) + { + PhyML_Fprintf(stderr,"\n. glnL=%f",tree->extra_tree->rates->c_lnL_times); + PhyML_Fprintf(stderr,"\n. death=%G birth=%G [%G]",new_death_rate,tree->rates->birth_rate,tree->extra_tree->rates->birth_rate); + TIMES_Lk_Times(YES,tree->extra_tree); + assert(FALSE); + } + + + i = 0; + do + { + u = Uni(); + for(move=0;movemcmc->n_moves;move++) if(tree->mcmc->move_weight[move] > u-1.E-10) break; + + /* PhyML_Printf("\n>> Move '%s' %f %f b:%f d:%f-%f", */ + /* tree->mcmc->move_name[move], */ + /* tree->extra_tree->rates->c_lnL_times, */ + /* tree->rates->c_lnL_times, */ + /* tree->rates->birth_rate, */ + /* cur_death_rate, */ + /* new_death_rate); */ + + if(!strcmp(tree->mcmc->move_name[move],"tree_height")) MCMC_Tree_Height(tree->extra_tree); + if(!strcmp(tree->mcmc->move_name[move],"times")) MCMC_Times_All(tree->extra_tree); + if(!strcmp(tree->mcmc->move_name[move],"spr")) MCMC_Prune_Regraft(tree->extra_tree); + if(!strcmp(tree->mcmc->move_name[move],"spr_local")) MCMC_Prune_Regraft_Local(tree->extra_tree); + + if(!(tree->extra_tree->rates->c_lnL_times > UNLIKELY)) + { + PhyML_Fprintf(stderr,"\n. move: %s",tree->mcmc->move_name[move]); + PhyML_Fprintf(stderr,"\n. glnL=%f",tree->extra_tree->rates->c_lnL_times); + TIMES_Lk_Times(YES,tree->extra_tree); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + i++; + } + while(i < n_mcmc_steps); + + tree->extra_tree->rates->death_rate = cur_death_rate; + tree->extra_tree->rates->birth_rate = cur_birth_rate; + cur_lnL_time_ghost = TIMES_Lk_Times(NO,tree->extra_tree); + + tree->extra_tree->rates->death_rate = new_death_rate; + tree->extra_tree->rates->birth_rate = new_birth_rate; + new_lnL_time_ghost = TIMES_Lk_Times(NO,tree->extra_tree); + + ratio += (cur_lnL_time_ghost - new_lnL_time_ghost); + + /* if(tree->mcmc->run_move[tree->mcmc->num_move_birth_rate] == 500) */ + /* { */ + /* tree->extra_tree->rates->death_rate = tree->rates->death_rate_pivot; */ + /* tree->extra_tree->rates->birth_rate = tree->rates->birth_rate_pivot; */ + /* new_lnL_time_pivot = TIMES_Lk_Times(NO,tree->extra_tree); */ + /* ratio += (new_lnL_time_pivot - cur_lnL_time_pivot); */ + /* } */ + } + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* printf("\n. bd :%4d: %12G -> %12G ratio : %12G [ghost: %12G %12G -- real: %12G %12G]", */ + /* tree->mcmc->run_move[tree->mcmc->num_move_birth_death_updown], */ + /* cur_death_rate, */ + /* new_death_rate, */ + /* ratio, */ + /* cur_lnL_time_ghost, */ + /* new_lnL_time_ghost, */ + /* cur_lnL_time, */ + /* new_lnL_time); */ + + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* PhyML_Printf(" reject"); */ + tree->rates->death_rate = cur_death_rate; + tree->rates->birth_rate = cur_birth_rate; + tree->rates->c_lnL_times = cur_lnL_time; + + /* Copy_Tree(tree->extra_tree->extra_tree,tree->extra_tree); */ + /* RATES_Copy_Rate_Struct(tree->extra_tree->extra_tree->rates,tree->extra_tree->rates,tree->n_otu); */ + /* DATE_Assign_Primary_Calibration(tree->extra_tree); */ + } + else + { + /* PhyML_Printf(" accept"); */ + tree->mcmc->acc_move[tree->mcmc->num_move_birth_death_updown]++; + } + } + tree->mcmc->run_move[tree->mcmc->num_move_birth_death_updown]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Nu(t_tree *tree) +{ + phydbl cur_nu,new_nu,cur_lnL_rate,new_lnL_rate; + phydbl u,alpha,ratio; + phydbl min_nu,max_nu; + phydbl K; + phydbl cur_lnL_seq, new_lnL_seq; + + cur_nu = -1.0; + new_nu = -1.0; + ratio = 0.0; + + K = tree->mcmc->tune_move[tree->mcmc->num_move_nu]; + + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + + cur_nu = tree->rates->nu; + + min_nu = tree->rates->min_nu; + max_nu = tree->rates->max_nu; + + MCMC_Make_Move(&cur_nu,&new_nu,min_nu,max_nu,&ratio,K,tree->mcmc->move_type[tree->mcmc->num_move_nu]); + + if(new_nu < max_nu && new_nu > min_nu) + { + tree->rates->nu = new_nu; + + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + + if(tree->rates->model == GUINDON) + { + RATES_Update_Cur_Bl(tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + } + else + new_lnL_seq = cur_lnL_seq; + + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_seq - cur_lnL_seq); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + tree->rates->nu = cur_nu; + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->c_lnL = cur_lnL_seq; + if(tree->rates->model == GUINDON && tree->eval_alnL == YES) RATES_Update_Cur_Bl(tree); + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_nu]++; + } + } + tree->mcmc->run_move[tree->mcmc->num_move_nu]++; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Clade_Change(t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl cur_lnL_calib, new_lnL_calib; + phydbl cur_lnL_time, new_lnL_time; + int target_cal_idx,current_clade_idx,new_clade_idx; + t_cal *cal; + + ratio = 0.0; + cal = NULL; + cur_lnL_calib = DATE_Lk_Calib(tree); + + new_lnL_time = tree->rates->c_lnL_times; + cur_lnL_time = tree->rates->c_lnL_times; + + + + // Choose a calibration uniformly at random + target_cal_idx = Rand_Int(0,tree->rates->n_cal-1); + cal = tree->rates->a_cal[target_cal_idx]; + + /* printf("\n. CURRENT cal: %s clade: %s target: %d",cal->id,cal->clade_list[cal->current_clade_idx]->id,cal->clade_list[cal->current_clade_idx]->target_nd->num); */ + + // Choose a new clade uniformly at random + current_clade_idx = cal->current_clade_idx; + new_clade_idx = Rand_Int(0,cal->clade_list_size-1); + cal->current_clade_idx = new_clade_idx; + + new_lnL_time = TIMES_Lk_Times(NO,tree); + ratio += new_lnL_time - cur_lnL_time; + + /* printf("\n. NEW cal: %s clade: %s target: %d",cal->id,cal->clade_list[cal->current_clade_idx]->id,cal->clade_list[cal->current_clade_idx]->target_nd->num); */ + + new_lnL_calib = DATE_Lk_Calib(tree); + ratio += new_lnL_calib - cur_lnL_calib; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* printf("\n. reject\n"); */ + cal->current_clade_idx = current_clade_idx; + tree->rates->c_lnL_times = cur_lnL_time; + TIMES_Lk_Times(NO,tree); // Required in order to update node targeted by selected calibration + } + else + { + /* printf("\n. accept\n"); */ + tree->mcmc->acc_move[tree->mcmc->num_move_clade_change]++; + } + tree->mcmc->run_move[tree->mcmc->num_move_clade_change]++; +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_All_Rates(t_tree *tree) +{ + phydbl cur_lnL_seq, new_lnL_seq, cur_lnL_rate; + phydbl u, ratio, alpha; + + new_lnL_seq = tree->c_lnL; + cur_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + ratio = 0.0; + + Record_Br_Len(tree); + RATES_Record_Rates(tree); + + MCMC_Sim_Rate(tree->n_root,tree->n_root->v[2],tree); + MCMC_Sim_Rate(tree->n_root,tree->n_root->v[1],tree); + + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + + ratio += (new_lnL_seq - cur_lnL_seq); + ratio = exp(ratio); + + alpha = MIN(1.,ratio); + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + Restore_Br_Len(tree); + RATES_Reset_Rates(tree); + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->c_lnL = cur_lnL_seq; + } + else + { + tree->rates->c_lnL_rates = RATES_Lk_Rates(tree);; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/* Only works when simulating from prior */ +void MCMC_Sim_Rate(t_node *a, t_node *d, t_tree *tree) +{ + int err; + phydbl mean,sd,br_r_a,dt_d; + + br_r_a = tree->rates->br_r[a->num]; + dt_d = tree->rates->nd_t[d->num] - tree->rates->nd_t[a->num]; + sd = SQRT(dt_d*tree->rates->nu); + + mean = br_r_a; + + if(tree->rates->model == STRICTCLOCK) tree->rates->br_r[d->num] = 1.0; + else + { + tree->rates->br_r[d->num] = Rnorm_Trunc(mean,sd,tree->rates->min_rate,tree->rates->max_rate,&err); + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + if(d->tax) return; + else + { + int i; + + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + MCMC_Sim_Rate(d,d->v[i],tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Prune_Regraft(t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl t_min,t_max; + phydbl cur_lnL_seq,new_lnL_seq; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl new_t; + int i,prune_idx,n_iter,n_regraft_nd,regraft_idx,dir_prune; + phydbl *times; + int rnd_dir,dir_v1,dir_v2; + t_node *prune,*prune_daughter,*new_regraft_nd,*cur_regraft_nd; + t_ll *regraft_nd_list; + t_edge *target, *ori_target, *residual,*regraft_edge; + phydbl regraft_t_min,regraft_t_max; + /* phydbl *prob_idx; */ + /* phydbl r,sum,prob_select_fwd,prob_select_bwd; */ + + n_iter = MAX(1,(int)(tree->n_otu/5)); + /* n_iter = tree->n_otu-2; */ + times = tree->rates->nd_t; + + /* prob_idx = (phydbl *)mCalloc(tree->n_otu-1,sizeof(phydbl)); */ + + // Shallowest node has probability proportional to r to be + // to be selected as prune node while deepest a proba prop to 1. + /* r = 0.5; */ + /* for(i=0;in_otu-1;i++) prob_idx[i] = i*(r-1.0)/(tree->n_otu-2) + 1.0; */ + + /* sum = .0; */ + /* for(i=0;in_otu-1;i++) sum += prob_idx[i]; */ + /* for(i=0;in_otu-1;i++) prob_idx[i] /= sum; */ + + + while(n_iter--) + { + + TIMES_Update_Node_Ordering(tree); + + /* if(tree->eval_alnL == YES) Lk(NULL,tree); */ + + tree->mcmc->run_move[tree->mcmc->num_move_spr]++; + + RATES_Record_Times(tree); + + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + ratio = 0.0; + regraft_edge = NULL; + new_regraft_nd = NULL; + cur_regraft_nd = NULL; + new_t = 0.0; + + // Select prune node (any internal node) + prune_idx = Rand_Int(tree->n_otu,2*tree->n_otu-2); + + /* prune_idx = Sample_i_With_Proba_pi(prob_idx,tree->n_otu-1); */ + /* prob_select_fwd = prob_idx[prune_idx]; */ + /* ratio -= log(prob_select_fwd); */ + /* prune_idx = tree->rates->t_rank[prune_idx]; */ + + prune = tree->a_nodes[prune_idx]; + + + assert(prune && prune->tax == NO); + + // Select a daughter of prune node + dir_v1 = dir_v2 = -1; + for(i=0;i<3;i++) + if(prune->v[i] != prune->anc && prune->b[i] != tree->e_root) + { + if(dir_v1 < 0) dir_v1 = i; + else dir_v2 = i; + } + + u = Uni(); + if(u < 0.5) rnd_dir = dir_v1; + else rnd_dir = dir_v2; + + prune_daughter = prune->v[rnd_dir]; + cur_regraft_nd = prune->v[rnd_dir == dir_v1 ? dir_v2 : dir_v1]; + + if(prune == tree->n_root) + { + if(prune_daughter == prune->v[dir_v1] && prune->v[dir_v2]->tax == YES) + { + prune_daughter = prune->v[dir_v2]; + cur_regraft_nd = prune->v[dir_v1]; + } + + if(prune_daughter == prune->v[dir_v2] && prune->v[dir_v1]->tax == YES) + { + prune_daughter = prune->v[dir_v1]; + cur_regraft_nd = prune->v[dir_v2]; + } + } + + if(prune_daughter->anc != prune) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + dir_prune = -1; + for(i=0;i<3;i++) + { + if(prune_daughter->v[i] == prune || prune_daughter->b[i] == tree->e_root) + { + dir_prune = i; + break; + } + } + assert(dir_prune > -1); + + + // Get the list of potential regraft nodes (oldest node on regraft edge) + regraft_nd_list = DATE_List_Of_Regraft_Nodes(prune_daughter->v[dir_prune],prune_daughter,®raft_t_min,®raft_t_max,NO,tree); + assert(regraft_nd_list); + if(prune == tree->n_root) Push_Bottom_Linked_List(prune,®raft_nd_list,YES); + + // Number of regraft nodes + n_regraft_nd = Linked_List_Len(regraft_nd_list); + + if(!(n_regraft_nd > 0)) // Should be at least 1, since original graft site is in the list + { + printf("\n\n. prune: %d [%d-%d-%d] [%s-%s-%s] [%f-%f;%f] prune_daughter: %d [%f-%f;%f] prune->anc: %d [%f-%f;%f] effective: %d glnL: %f", + prune->num, + prune->v[0] ? prune->v[0]->num : -1, + prune->v[1]->num, + prune->v[2]->num, + prune->v[0] ? prune->v[0]->tax ? prune->v[0]->name : "XXX" : "XXX", + prune->v[1]->tax ? prune->v[1]->name : "XXX", + prune->v[2]->tax ? prune->v[2]->name : "XXX", + tree->rates->nd_t[prune->num], + tree->rates->t_prior_min[prune->num], + tree->rates->t_prior_max[prune->num], + prune_daughter->num, + tree->rates->nd_t[prune_daughter->num], + tree->rates->t_prior_min[prune_daughter->num], + tree->rates->t_prior_max[prune_daughter->num], + prune->anc ? prune->anc->num : -1, + prune->anc ? tree->rates->nd_t[prune->anc->num] : -1, + prune->anc ? tree->rates->t_prior_min[prune->anc->num] : -1, + prune->anc ? tree->rates->t_prior_max[prune->anc->num] : -1, + prune_daughter->v[dir_prune]->num, + tree->rates->c_lnL_times); fflush(NULL); + + regraft_nd_list = DATE_List_Of_Regraft_Nodes(prune_daughter->v[dir_prune],prune_daughter,®raft_t_min,®raft_t_max,YES,tree); + + assert(FALSE); + } + + // Randomly select one (uniform) + regraft_idx = Rand_Int(0,n_regraft_nd-1); + new_regraft_nd = Linked_List_Elem(regraft_idx,regraft_nd_list); + Free_Linked_List(regraft_nd_list); + + + // Time of regraft node and corresponding (partial) Hastings ratio + t_max = MIN(times[prune_daughter->num],times[cur_regraft_nd->num]); + if(prune == tree->n_root) t_min = 10.0*t_max; + else t_min = times[prune->anc->num]; + t_min = MAX(t_min,regraft_t_min); + ratio += log(1./(t_max - t_min)); + + t_max = MIN(times[prune_daughter->num],times[new_regraft_nd->num]); + if(new_regraft_nd == tree->n_root) t_min = 10.0*t_max; + else t_min = times[new_regraft_nd->anc->num]; + t_min = MAX(t_min,regraft_t_min); + ratio -= log(1./(t_max - t_min)); + + new_t = Uni()*(t_max-t_min) + t_min; + + // Age of root node changes when pruned subtree is on one side of that node + // Change here, not after the prune and regraft move + /* if(prune == tree->n_root) */ + /* { */ + /* if(prune_daughter == tree->n_root->v[1]) */ + /* times[tree->n_root->num] = times[tree->n_root->v[2]->num]; */ + /* else if(prune_daughter == tree->n_root->v[2]) */ + /* times[tree->n_root->num] = times[tree->n_root->v[1]->num]; */ + /* else assert(false); */ + /* } */ + + + // New age + if(prune == tree->n_root || new_regraft_nd == tree->n_root) + { + if(prune == tree->n_root) + { + if(prune_daughter == tree->n_root->v[1]) times[tree->n_root->num] = times[tree->n_root->v[2]->num]; + else times[tree->n_root->num] = times[tree->n_root->v[1]->num]; + times[prune_daughter->v[dir_prune]->num] = new_t; + } + if(new_regraft_nd == tree->n_root) + { + times[prune_daughter->v[dir_prune]->num] = times[tree->n_root->num]; + times[tree->n_root->num] = new_t; + } + } + else + { + times[prune->num] = new_t; + } + + + // Prune + target = residual = NULL; + Prune_Subtree(prune_daughter->v[dir_prune], + prune_daughter, + &target,&residual,tree); + ori_target = target; + + + // Regraft edge is the one sitting above regraft_nd + if(new_regraft_nd == tree->n_root->v[1] || + new_regraft_nd == tree->n_root->v[2] || + new_regraft_nd == tree->n_root) regraft_edge = tree->e_root; + else + { + for(i=0;i<3;i++) if(new_regraft_nd->v[i] == new_regraft_nd->anc) break; + assert(i!=3); + regraft_edge = new_regraft_nd->b[i]; + } + + assert(regraft_edge); + assert(residual->left != residual->rght); + assert(regraft_edge->left != prune_daughter->v[dir_prune]); + assert(regraft_edge->rght != prune_daughter->v[dir_prune]); + + + // Regraft + Graft_Subtree(regraft_edge, + prune_daughter->v[dir_prune], + prune_daughter, + residual, + new_regraft_nd,tree); + + + /* TIMES_Update_Node_Ordering(tree); */ + /* For(i,2*tree->n_otu-2) if(prune->num == tree->rates->t_rank[i]) break; */ + /* prob_select_bwd = prob_idx[i]; */ + /* ratio += log(prob_select_bwd); */ + + if(!TIMES_Check_Node_Height_Ordering(tree)) + { + printf("\n. prune[%d]->t:%.3f daughter[%d]->t:%.3f prune_anc[%d]->t:%.3f regraft[%d]->t:%.3f regraft_anc[%d]->t:%.3f [effective:%d] t_prior_min/max: [prune:[%.3f %.3f] regraft:[%.3f %.3f]] ", + prune->num, + times[prune->num], + prune_daughter->num, + times[prune_daughter->num], + prune->anc ? prune->anc->num : -1, + prune->anc ? times[prune->anc->num] : -1., + new_regraft_nd->num, + times[new_regraft_nd->num], + new_regraft_nd->anc ? new_regraft_nd->anc->num : -1, + new_regraft_nd->anc ? times[new_regraft_nd->anc->num] : +1., + prune->num, + tree->rates->t_prior_min[prune->num], + tree->rates->t_prior_max[prune->num], + tree->rates->t_prior_min[new_regraft_nd->num], + tree->rates->t_prior_max[new_regraft_nd->num]); + PhyML_Fprintf(stderr,"\n. root: %d %d %d",tree->n_root->num,tree->n_root->v[1]->num,tree->n_root->v[2]->num); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + DATE_Assign_Primary_Calibration(tree); + RATES_Update_Cur_Bl(tree); + + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + + if(new_lnL_time > UNLIKELY) + { + Set_Both_Sides(NO,tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + } + + ratio += (new_lnL_seq - cur_lnL_seq); + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_time - cur_lnL_time); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_lnL_time > UNLIKELY) alpha = 1.0; + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + // Reject + Prune_Subtree(prune_daughter->v[dir_prune], + prune_daughter, + &target,&residual,tree); + assert(residual->left != residual->rght); + assert(ori_target->left != prune_daughter->v[dir_prune]); + assert(ori_target->rght != prune_daughter->v[dir_prune]); + Graft_Subtree(ori_target, + prune_daughter->v[dir_prune], + prune_daughter,residual,prune == tree->n_root ? tree->n_root : cur_regraft_nd,tree); + + RATES_Reset_Times(tree); + RATES_Update_Cur_Bl(tree); + DATE_Assign_Primary_Calibration(tree); + + new_lnL_time = TIMES_Lk_Times(NO,tree); + if(Are_Equal(new_lnL_time,cur_lnL_time,1.E-5) == NO) + { + PhyML_Printf("\n. new_lnL_time: %f cur_lnL_time: %f",new_lnL_time,cur_lnL_time); + assert(FALSE); + } + + /* if(tree->eval_alnL == YES) */ + /* { */ + /* new_lnL_seq = Lk(NULL,tree); */ + /* if(Are_Equal(new_lnL_seq,cur_lnL_seq,1.E-5) == NO) */ + /* { */ + /* PhyML_Printf("\n. new: %f cur: %f",new_lnL_seq,cur_lnL_seq); */ + /* assert(FALSE); */ + /* } */ + /* } */ + + if(!(tree->rates->c_lnL_times > UNLIKELY)) + { + printf("\n. time prune: %f",times[prune->num]); + printf("\n. time prune_daughter: %f",times[prune_daughter->num]); + printf("\n. prune: %d prune_daughter: %d prune_daughter->v[dir_prune]: %d cur_regraft_nd: %d new_regraft_nd: %d", + prune->num, + prune_daughter->num, + prune_daughter->v[dir_prune]->num, + cur_regraft_nd->num, + new_regraft_nd->num); + TIMES_Lk_Times(YES,tree); + fflush(NULL); + } + assert(tree->rates->c_lnL_times > UNLIKELY); + + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_times = cur_lnL_time; + tree->rates->c_lnL_rates = cur_lnL_rate; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_spr]++; + } + } + /* Free(prob_idx); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Prune_Regraft_Weighted(t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl cur_lnL_seq,new_lnL_seq; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl new_t; + int i,prune_idx,n_iter,dir_prune; + phydbl *times; + int rnd_dir,dir_v1,dir_v2; + t_node *prune,*prune_daughter,*new_regraft_nd,*cur_regraft_nd; + t_edge *target, *ori_target, *residual,*regraft_edge; + phydbl radius; + + n_iter = MAX(1,(int)(tree->n_otu/5)); + times = tree->rates->nd_t; + + while(n_iter--) + { + tree->mcmc->run_move[tree->mcmc->num_move_spr_weighted]++; + + RATES_Record_Times(tree); + + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + ratio = 0.0; + regraft_edge = NULL; + new_regraft_nd = NULL; + cur_regraft_nd = NULL; + new_t = 0.0; + + // Select prune node (any internal node) + prune_idx = Rand_Int(tree->n_otu,2*tree->n_otu-2); + prune = tree->a_nodes[prune_idx]; + + assert(prune && prune->tax == NO); + + // Select a daughter of prune node + dir_v1 = dir_v2 = -1; + for(i=0;i<3;i++) + if(prune->v[i] != prune->anc && prune->b[i] != tree->e_root) + { + if(dir_v1 < 0) dir_v1 = i; + else dir_v2 = i; + } + + u = Uni(); + if(u < 0.5) rnd_dir = dir_v1; + else rnd_dir = dir_v2; + + prune_daughter = prune->v[rnd_dir]; + cur_regraft_nd = prune->v[rnd_dir == dir_v1 ? dir_v2 : dir_v1]; + + if(prune == tree->n_root) + { + if(prune_daughter == prune->v[dir_v1] && prune->v[dir_v2]->tax == YES) + { + prune_daughter = prune->v[dir_v2]; + cur_regraft_nd = prune->v[dir_v1]; + } + + if(prune_daughter == prune->v[dir_v2] && prune->v[dir_v1]->tax == YES) + { + prune_daughter = prune->v[dir_v1]; + cur_regraft_nd = prune->v[dir_v2]; + } + } + + assert(prune_daughter->anc == prune); + + dir_prune = -1; + for(i=0;i<3;i++) + { + if(prune_daughter->v[i] == prune || prune_daughter->b[i] == tree->e_root) + { + dir_prune = i; + break; + } + } + assert(dir_prune > -1); + + + radius = Rnorm(0.0,0.05); + radius = fabs(radius); + radius += tree->rates->cur_l[prune_daughter->num]; // valid too when prune == tree->n_root + + /* printf("\n. Init rad: %G l: %G %G root: %d",radius,tree->rates->cur_l[prune_daughter->num],prune_daughter->b[dir_prune]->l->v,prune_daughter->b[dir_prune] == tree->e_root); */ + // Get the list of potential regraft nodes (oldest node on regraft edge) + Random_Walk_Along_Tree_On_Radius(prune_daughter, + prune_daughter->v[dir_prune], + prune_daughter->b[dir_prune], + &radius, + ®raft_edge, + &new_regraft_nd, + &new_t, + tree); + + + /* printf("\n. new_regraft_edge: %d, new_regraft_nd: %d time: %f cur_regraft_nd: %d prune: %d prune_daughter: %d", */ + /* regraft_edge ? regraft_edge->num : -1, */ + /* new_regraft_nd ? new_regraft_nd->num : -1, */ + /* new_t, */ + /* cur_regraft_nd->num, */ + /* prune->num, */ + /* prune_daughter->num); fflush(NULL); */ + + if(new_regraft_nd == NULL) continue; + if(new_regraft_nd == prune) continue; + if(new_regraft_nd == cur_regraft_nd) continue; + if(new_t > times[prune_daughter->num]) continue; + assert(new_regraft_nd != prune_daughter); + + // New age + if(prune == tree->n_root || new_regraft_nd == tree->n_root) + { + if(prune == tree->n_root) + { + if(prune_daughter == tree->n_root->v[1]) times[tree->n_root->num] = times[tree->n_root->v[2]->num]; + else times[tree->n_root->num] = times[tree->n_root->v[1]->num]; + times[prune_daughter->v[dir_prune]->num] = new_t; + } + if(new_regraft_nd == tree->n_root) + { + times[prune_daughter->v[dir_prune]->num] = times[tree->n_root->num]; + times[tree->n_root->num] = new_t; + } + } + else + { + times[prune->num] = new_t; + } + + + // Prune + target = residual = NULL; + Prune_Subtree(prune_daughter->v[dir_prune], + prune_daughter, + &target,&residual,tree); + ori_target = target; + + + // Regraft edge is the one sitting above new_regraft_nd + if(new_regraft_nd == tree->n_root->v[1] || + new_regraft_nd == tree->n_root->v[2] || + new_regraft_nd == tree->n_root) regraft_edge = tree->e_root; + else + { + for(i=0;i<3;++i) if(new_regraft_nd->v[i] == new_regraft_nd->anc) break; + assert(i!=3); + regraft_edge = new_regraft_nd->b[i]; + } + + assert(regraft_edge); + assert(residual->left != residual->rght); + assert(regraft_edge->left != prune_daughter->v[dir_prune]); + assert(regraft_edge->rght != prune_daughter->v[dir_prune]); + + // Regraft + Graft_Subtree(regraft_edge, + prune_daughter->v[dir_prune], + prune_daughter, + residual, + new_regraft_nd,tree); + + + if(!TIMES_Check_Node_Height_Ordering(tree)) + { + PhyML_Fprintf(stderr,"\n. prune[%d]->t:%.3f daughter[%d]->t:%.3f prune_anc[%d]->t:%.3f regraft[%d]->t:%.3f regraft_anc[%d]->t:%.3f [effective:%d] t_prior_min/max: [prune:[%.3f %.3f] regraft:[%.3f %.3f]] ", + prune->num, + times[prune->num], + prune_daughter->num, + times[prune_daughter->num], + prune->anc ? prune->anc->num : -1, + prune->anc ? times[prune->anc->num] : -1., + new_regraft_nd->num, + times[new_regraft_nd->num], + new_regraft_nd->anc ? new_regraft_nd->anc->num : -1, + new_regraft_nd->anc ? times[new_regraft_nd->anc->num] : +1., + prune->num, + tree->rates->t_prior_min[prune->num], + tree->rates->t_prior_max[prune->num], + tree->rates->t_prior_min[new_regraft_nd->num], + tree->rates->t_prior_max[new_regraft_nd->num]); + PhyML_Fprintf(stderr,"\n. root: %d %d %d",tree->n_root->num,tree->n_root->v[1]->num,tree->n_root->v[2]->num); + assert(FALSE); + } + + RATES_Update_Cur_Bl(tree); + DATE_Assign_Primary_Calibration(tree); + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + + if(new_lnL_time > UNLIKELY) + { + Set_Both_Sides(NO,tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + } + + ratio += (new_lnL_seq - cur_lnL_seq); + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_time - cur_lnL_time); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_lnL_time > UNLIKELY) alpha = 1.0; + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + // Reject + Prune_Subtree(prune_daughter->v[dir_prune], + prune_daughter, + &target,&residual,tree); + assert(residual->left != residual->rght); + assert(ori_target->left != prune_daughter->v[dir_prune]); + assert(ori_target->rght != prune_daughter->v[dir_prune]); + Graft_Subtree(ori_target, + prune_daughter->v[dir_prune], + prune_daughter,residual,prune == tree->n_root ? tree->n_root : cur_regraft_nd,tree); + + RATES_Reset_Times(tree); + RATES_Update_Cur_Bl(tree); + DATE_Assign_Primary_Calibration(tree); + new_lnL_time = TIMES_Lk_Times(NO,tree); + if(Are_Equal(new_lnL_time,cur_lnL_time,1.E-5) == NO) + { + PhyML_Printf("\n. new_lnL_time: %f cur_lnL_time: %f",new_lnL_time,cur_lnL_time); + assert(FALSE); + } + + /* new_lnL_seq = Lk(NULL,tree); */ + /* if(Are_Equal(new_lnL_seq,cur_lnL_seq,1.E-5) == NO) */ + /* { */ + /* PhyML_Printf("\n. new: %f cur: %f",new_lnL_seq,cur_lnL_seq); */ + /* assert(FALSE); */ + /* } */ + + if(!(tree->rates->c_lnL_times > UNLIKELY)) + { + printf("\n. time prune: %f",times[prune->num]); + printf("\n. time prune_daughter: %f",times[prune_daughter->num]); + printf("\n. prune: %d prune_daughter: %d prune_daughter->v[dir_prune]: %d cur_regraft_nd: %d new_regraft_nd: %d", + prune->num, + prune_daughter->num, + prune_daughter->v[dir_prune]->num, + cur_regraft_nd->num, + new_regraft_nd->num); + TIMES_Lk_Times(YES,tree); + fflush(NULL); + } + assert(tree->rates->c_lnL_times > UNLIKELY); + + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_times = cur_lnL_time; + tree->rates->c_lnL_rates = cur_lnL_rate; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_spr_weighted]++; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Prune_Regraft_Local(t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl t_min,t_max; + phydbl cur_lnL_seq,new_lnL_seq; + phydbl cur_lnL_rate,new_lnL_rate; + phydbl cur_lnL_time,new_lnL_time; + phydbl new_t; + int i,prune_idx,n_iter,n_regraft_nd,regraft_idx,dir_prune; + phydbl *times; + int rnd_dir,dir_v1,dir_v2; + t_node *prune,*prune_daughter,*new_regraft_nd,*cur_regraft_nd; + t_ll *regraft_nd_list; + t_edge *target, *ori_target, *residual,*regraft_edge; + t_node *a, *b, *c, *d, *e; + + n_iter = MAX(1,(int)(tree->n_otu/5)); + times = tree->rates->nd_t; + + while(n_iter--) + { + tree->mcmc->run_move[tree->mcmc->num_move_spr_local]++; + + RATES_Record_Times(tree); + + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_rate = tree->rates->c_lnL_rates; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = tree->rates->c_lnL_times; + + ratio = 0.0; + regraft_edge = NULL; + new_regraft_nd = NULL; + cur_regraft_nd = NULL; + new_t = 0.0; + + // Select prune node (any internal node) + prune_idx = Rand_Int(tree->n_otu,2*tree->n_otu-2); + /* prune_idx = tree->n_otu+n_iter; */ + + prune = tree->a_nodes[prune_idx]; + + assert(prune && prune->tax == NO); + + // Select a daughter of prune node + dir_v1 = dir_v2 = -1; + for(i=0;i<3;i++) + if(prune->v[i] != prune->anc && prune->b[i] != tree->e_root) + { + if(dir_v1 < 0) dir_v1 = i; + else dir_v2 = i; + } + + u = Uni(); + if(u < 0.5) rnd_dir = dir_v1; + else rnd_dir = dir_v2; + + prune_daughter = prune->v[rnd_dir]; + cur_regraft_nd = prune->v[rnd_dir == dir_v1 ? dir_v2 : dir_v1]; + + if(prune == tree->n_root) + { + if(prune_daughter == prune->v[dir_v1] && prune->v[dir_v2]->tax == YES) + { + prune_daughter = prune->v[dir_v2]; + cur_regraft_nd = prune->v[dir_v1]; + } + + if(prune_daughter == prune->v[dir_v2] && prune->v[dir_v1]->tax == YES) + { + prune_daughter = prune->v[dir_v1]; + cur_regraft_nd = prune->v[dir_v2]; + } + } + + assert(prune_daughter->anc == prune); + + dir_prune = -1; + for(i=0;i<3;i++) + { + if(prune_daughter->v[i] == prune || prune_daughter->b[i] == tree->e_root) + { + dir_prune = i; + break; + } + } + assert(dir_prune > -1); + + /* + + | + | + d + / \ + / \c + / \ + e / \prune_daughter + /\ + / \ + a b + + */ + + + // Probability of forward move + regraft_nd_list = NULL; + a = b = c = d = e = NULL; + e = cur_regraft_nd; + + if(e->tax == NO && times[e->num] < times[prune_daughter->num]) + { + for(i=0;i<3;i++) + { + if(e->v[i] != e->anc && e->b[i] != tree->e_root) + { + if(a == NULL) a = e->v[i]; + else b = e->v[i]; + } + } + Push_Bottom_Linked_List(a,®raft_nd_list,YES); + Push_Bottom_Linked_List(b,®raft_nd_list,YES); + } + + if(prune_daughter->anc != tree->n_root) + { + d = prune_daughter->anc->anc; + + for(i=0;i<3;i++) + { + if(d->v[i] != d->anc && d->b[i] != tree->e_root && d->v[i] != prune) + { + c = d->v[i]; + break; + } + } + Push_Bottom_Linked_List(c,®raft_nd_list,YES); + Push_Bottom_Linked_List(d,®raft_nd_list,YES); + } + + n_regraft_nd = Linked_List_Len(regraft_nd_list); + + if(n_regraft_nd == 0) + { + Free_Linked_List(regraft_nd_list); + continue; + } + + assert(n_regraft_nd > 0); + ratio -= log(1./n_regraft_nd); + + // Randomly select one node among potential regraft sites (uniform) + regraft_idx = Rand_Int(0,n_regraft_nd-1); + new_regraft_nd = Linked_List_Elem(regraft_idx,regraft_nd_list); + Free_Linked_List(regraft_nd_list); + + + // Time of regraft node and corresponding (partial) Hastings ratio + t_max = MIN(times[prune_daughter->num],times[cur_regraft_nd->num]); + if(prune == tree->n_root) t_min = 10.0*t_max; + else t_min = times[prune->anc->num]; + ratio += log(1./(t_max - t_min)); + + + t_max = MIN(times[prune_daughter->num],times[new_regraft_nd->num]); + if(new_regraft_nd == tree->n_root) t_min = 10.0*t_max; + else t_min = times[new_regraft_nd->anc->num]; + ratio -= log(1./(t_max - t_min)); + + new_t = Uni()*(t_max-t_min) + t_min; + + + // Age of root node changes when pruned subtree is on one side of that node + // Change here, not after the prune and regraft move + /* if(prune == tree->n_root) */ + /* { */ + /* if(prune_daughter == tree->n_root->v[1]) */ + /* times[tree->n_root->num] = times[tree->n_root->v[2]->num]; */ + /* else if(prune_daughter == tree->n_root->v[2]) */ + /* times[tree->n_root->num] = times[tree->n_root->v[1]->num]; */ + /* else assert(false); */ + /* } */ + + /* printf("\n-> prune: %d prune_daughter: %d prune_daughter->v[dir_prune]: %d cur_regraft_nd: %d new_regraft_nd: %d", */ + /* prune->num, */ + /* prune_daughter->num, */ + /* prune_daughter->v[dir_prune]->num, */ + /* cur_regraft_nd->num, */ + /* new_regraft_nd->num); */ + + /* printf("\n. a:%d b:%d c:%d d:%d e:%d", */ + /* a ? a->num : -1, */ + /* b ? b->num : -1, */ + /* c ? c->num : -1, */ + /* d ? d->num : -1, */ + /* e ? e->num : -1); */ + /* fflush(NULL); */ + + + // New age + if(prune == tree->n_root || new_regraft_nd == tree->n_root) + { + if(prune == tree->n_root) + { + if(prune_daughter == tree->n_root->v[1]) times[tree->n_root->num] = times[tree->n_root->v[2]->num]; + else times[tree->n_root->num] = times[tree->n_root->v[1]->num]; + times[prune_daughter->v[dir_prune]->num] = new_t; + } + if(new_regraft_nd == tree->n_root) + { + times[prune_daughter->v[dir_prune]->num] = times[tree->n_root->num]; + times[tree->n_root->num] = new_t; + } + } + else + { + times[prune->num] = new_t; + } + + + + // Prune + target = residual = NULL; + Prune_Subtree(prune_daughter->v[dir_prune], + prune_daughter, + &target,&residual,tree); + ori_target = target; + + // Regraft edge is the one sitting above regraft_nd + if(new_regraft_nd == tree->n_root->v[1] || + new_regraft_nd == tree->n_root->v[2] || + new_regraft_nd == tree->n_root) regraft_edge = tree->e_root; + else + { + for(i=0;i<3;i++) if(new_regraft_nd->v[i] == new_regraft_nd->anc) break; + assert(i!=3); + regraft_edge = new_regraft_nd->b[i]; + } + + assert(regraft_edge); + assert(residual->left != residual->rght); + assert(regraft_edge->left != prune_daughter->v[dir_prune]); + assert(regraft_edge->rght != prune_daughter->v[dir_prune]); + + // Regraft + Graft_Subtree(regraft_edge, + prune_daughter->v[dir_prune], + prune_daughter, + residual, + new_regraft_nd,tree); + + + a = b = c = d = e = NULL; + regraft_nd_list = NULL; + e = new_regraft_nd; + if(new_regraft_nd == tree->n_root) + { + if(prune_daughter == tree->n_root->v[1]) + e = tree->n_root->v[2]; + else if(prune_daughter == tree->n_root->v[2]) + e = tree->n_root->v[1]; + else assert(false); + } + + if(e->tax == NO && times[e->num] < times[prune_daughter->num]) + { + for(i=0;i<3;i++) + { + if(e->v[i] != e->anc && e->b[i] != tree->e_root) + { + if(a == NULL) a = e->v[i]; + else b = e->v[i]; + } + } + Push_Bottom_Linked_List(a,®raft_nd_list,YES); + Push_Bottom_Linked_List(b,®raft_nd_list,YES); + } + + // prune is different from prune_daughter->anc here if prune == tree->n_root + if(prune_daughter->anc != tree->n_root) + { + d = prune_daughter->anc->anc; + + for(i=0;i<3;i++) + { + if(d->v[i] != d->anc && d->b[i] != tree->e_root && d->v[i] != prune) + { + c = d->v[i]; + break; + } + } + Push_Bottom_Linked_List(c,®raft_nd_list,YES); + Push_Bottom_Linked_List(d,®raft_nd_list,YES); + } + + /* printf("\n+ a:%d b:%d c:%d d:%d e:%d", */ + /* a ? a->num : -1, */ + /* b ? b->num : -1, */ + /* c ? c->num : -1, */ + /* d ? d->num : -1, */ + /* e ? e->num : -1); */ + /* fflush(NULL); */ + + // Number of regraft nodes + n_regraft_nd = Linked_List_Len(regraft_nd_list); + assert(n_regraft_nd > 0); + ratio += log(1./n_regraft_nd); + Free_Linked_List(regraft_nd_list); + + // New age + /* if(new_regraft_nd == tree->n_root) */ + /* { */ + /* if(prune_daughter == tree->n_root->v[1]) */ + /* times[tree->n_root->v[2]->num] = times[tree->n_root->num]; */ + /* else if(prune_daughter == tree->n_root->v[2]) */ + /* times[tree->n_root->v[1]->num] = times[tree->n_root->num]; */ + /* else assert(false); */ + + /* times[tree->n_root->num] = new_t; */ + /* } */ + /* else if(prune == tree->n_root) */ + /* { */ + /* times[prune_daughter->v[dir_prune]->num] = new_t; */ + /* } */ + /* else */ + /* { */ + /* times[prune->num] = new_t; */ + /* } */ + + + + + + if(!TIMES_Check_Node_Height_Ordering(tree)) + { + printf("\n. prune[%d]->t:%.3f daughter[%d]->t:%.3f prune_anc[%d]->t:%.3f regraft[%d]->t:%.3f regraft_anc[%d]->t:%.3f [effective:%d] t_prior_min/max: [prune:[%.3f %.3f] regraft:[%.3f %.3f]] ", + prune->num, + times[prune->num], + prune_daughter->num, + times[prune_daughter->num], + prune->anc ? prune->anc->num : -1, + prune->anc ? times[prune->anc->num] : -1., + new_regraft_nd->num, + times[new_regraft_nd->num], + new_regraft_nd->anc ? new_regraft_nd->anc->num : -1, + new_regraft_nd->anc ? times[new_regraft_nd->anc->num] : +1., + prune->num, + tree->rates->t_prior_min[prune->num], + tree->rates->t_prior_max[prune->num], + tree->rates->t_prior_min[new_regraft_nd->num], + tree->rates->t_prior_max[new_regraft_nd->num]); + PhyML_Fprintf(stderr,"\n. root: %d %d %d",tree->n_root->num,tree->n_root->v[1]->num,tree->n_root->v[2]->num); + assert(FALSE); + } + + RATES_Update_Cur_Bl(tree); + DATE_Assign_Primary_Calibration(tree); + + if(tree->eval_glnL == YES) new_lnL_time = TIMES_Lk_Times(NO,tree); + + if(new_lnL_time > UNLIKELY) + { + Set_Both_Sides(NO,tree); + if(tree->eval_alnL == YES) new_lnL_seq = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_lnL_rate = RATES_Lk_Rates(tree); + } + + ratio += (new_lnL_seq - cur_lnL_seq); + ratio += (new_lnL_rate - cur_lnL_rate); + ratio += (new_lnL_time - cur_lnL_time); + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_lnL_time > UNLIKELY) alpha = 1.0; + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) + { + // Reject + Prune_Subtree(prune_daughter->v[dir_prune], + prune_daughter, + &target,&residual,tree); + assert(residual->left != residual->rght); + assert(ori_target->left != prune_daughter->v[dir_prune]); + assert(ori_target->rght != prune_daughter->v[dir_prune]); + Graft_Subtree(ori_target, + prune_daughter->v[dir_prune], + prune_daughter,residual,prune == tree->n_root ? tree->n_root : cur_regraft_nd,tree); + + RATES_Reset_Times(tree); + RATES_Update_Cur_Bl(tree); + DATE_Assign_Primary_Calibration(tree); + new_lnL_time = TIMES_Lk_Times(NO,tree); + if(Are_Equal(new_lnL_time,cur_lnL_time,1.E-5) == NO) + { + PhyML_Printf("\n. new_lnL_time: %f cur_lnL_time: %f",new_lnL_time,cur_lnL_time); + assert(FALSE); + } + + /* new_lnL_seq = Lk(NULL,tree); */ + /* if(Are_Equal(new_lnL_seq,cur_lnL_seq,1.E-5) == NO) */ + /* { */ + /* PhyML_Printf("\n. new: %f cur: %f",new_lnL_seq,cur_lnL_seq); */ + /* assert(FALSE); */ + /* } */ + + + if(!(tree->rates->c_lnL_times > UNLIKELY)) + { + printf("\n. time prune: %f",times[prune->num]); + printf("\n. time prune_daughter: %f",times[prune_daughter->num]); + printf("\n. prune: %d prune_daughter: %d prune_daughter->v[dir_prune]: %d cur_regraft_nd: %d new_regraft_nd: %d", + prune->num, + prune_daughter->num, + prune_daughter->v[dir_prune]->num, + cur_regraft_nd->num, + new_regraft_nd->num); + TIMES_Lk_Times(YES,tree); + fflush(NULL); + } + assert(tree->rates->c_lnL_times > UNLIKELY); + + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_times = cur_lnL_time; + tree->rates->c_lnL_rates = cur_lnL_rate; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_spr_local]++; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Complete_MCMC(t_mcmc *mcmc, t_tree *tree) +{ + int i; + phydbl sum; + + mcmc->io = tree->io; + mcmc->n_moves = 0; + mcmc->move_idx = -1; + + mcmc->num_move_nd_r = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_br_r = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_times = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_times_and_rates = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_times_and_rates_root = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_root_time = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_nu = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_clock_r = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_tree_height = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_time_slice = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_subtree_height = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_kappa = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_rr = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_tree_rates = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_subtree_rates = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_updown_nu_cr = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_ras = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_updown_t_cr = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_cov_rates = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_cov_switch = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_birth_rate = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_death_rate = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_birth_death_updown = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_spr = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_spr_weighted = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_spr_local = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_spr_root = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_updown_t_br = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_jump_calibration = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_geo_lambda = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_geo_sigma = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_geo_tau = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_geo_updown_tau_lbda = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_geo_updown_lbda_sigma = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_geo_dum = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_lbda = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_mu = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_rad = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_indel_disk = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_move_disk_ud = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_swap_disk = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_indel_hit = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_spr = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_spr_local = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_scale_times = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_ldscape_lim = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_sigsq = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_sim = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_traj = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_indel_disk_serial = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_sim_plus = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_indel_hit_serial = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_ldsk_given_disk = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_disk_given_ldsk = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_ldsk_and_disk = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_ldsk_multi = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_disk_multi = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_add_remove_jump = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_clade_change = mcmc->n_moves; mcmc->n_moves += 1; + mcmc->num_move_phyrex_ldsk_tip_to_root = mcmc->n_moves; mcmc->n_moves += 1; + + mcmc->run_move = (int *)mCalloc(mcmc->n_moves,sizeof(int)); + mcmc->acc_move = (int *)mCalloc(mcmc->n_moves,sizeof(int)); + mcmc->prev_run_move = (int *)mCalloc(mcmc->n_moves,sizeof(int)); + mcmc->prev_acc_move = (int *)mCalloc(mcmc->n_moves,sizeof(int)); + mcmc->acc_rate = (phydbl *)mCalloc(mcmc->n_moves,sizeof(phydbl)); + mcmc->move_weight = (phydbl *)mCalloc(mcmc->n_moves,sizeof(phydbl)); + mcmc->move_type = (int *)mCalloc(mcmc->n_moves,sizeof(int)); + + /* TO DO: instead of n_moves here we should have something like n_param */ + mcmc->ess = (phydbl *)mCalloc(mcmc->n_moves,sizeof(phydbl)); + mcmc->ess_run = (int *)mCalloc(mcmc->n_moves,sizeof(int)); + mcmc->start_ess = (int *)mCalloc(mcmc->n_moves,sizeof(int)); + mcmc->adjust_tuning = (int *)mCalloc(mcmc->n_moves,sizeof(int)); + mcmc->tune_move = (phydbl *)mCalloc(mcmc->n_moves,sizeof(phydbl)); + mcmc->sampled_val = (phydbl *)mCalloc((int)mcmc->n_moves*(mcmc->chain_len/mcmc->sample_interval + 1),sizeof(phydbl)); + mcmc->mode = (phydbl *)mCalloc((int)mcmc->n_moves,sizeof(phydbl)); + mcmc->move_name = (char **)mCalloc(mcmc->n_moves,sizeof(char *)); + for(i=0;in_moves;i++) mcmc->move_name[i] = (char *)mCalloc(T_MAX_MCMC_MOVE_NAME,sizeof(char)); + + for(i=0;in_moves;i++) mcmc->adjust_tuning[i] = YES; + + strcpy(mcmc->move_name[mcmc->num_move_br_r],"br_rate"); + strcpy(mcmc->move_name[mcmc->num_move_nd_r],"nd_rate"); + strcpy(mcmc->move_name[mcmc->num_move_times],"times"); + strcpy(mcmc->move_name[mcmc->num_move_times_and_rates],"times_and_rates"); + strcpy(mcmc->move_name[mcmc->num_move_times_and_rates_root],"times_and_rates_root"); + strcpy(mcmc->move_name[mcmc->num_move_root_time],"root_time"); + strcpy(mcmc->move_name[mcmc->num_move_nu],"nu"); + strcpy(mcmc->move_name[mcmc->num_move_clock_r],"clock"); + strcpy(mcmc->move_name[mcmc->num_move_tree_height],"tree_height"); + strcpy(mcmc->move_name[mcmc->num_move_time_slice],"time_slice"); + strcpy(mcmc->move_name[mcmc->num_move_subtree_height],"subtree_height"); + strcpy(mcmc->move_name[mcmc->num_move_kappa],"kappa"); + strcpy(mcmc->move_name[mcmc->num_move_rr],"rr"); + strcpy(mcmc->move_name[mcmc->num_move_spr],"spr"); + strcpy(mcmc->move_name[mcmc->num_move_spr_weighted],"spr_weighted"); + strcpy(mcmc->move_name[mcmc->num_move_spr_local],"spr_local"); + strcpy(mcmc->move_name[mcmc->num_move_spr_root],"spr_root"); + strcpy(mcmc->move_name[mcmc->num_move_tree_rates],"tree_rates"); + strcpy(mcmc->move_name[mcmc->num_move_subtree_rates],"subtree_rates"); + strcpy(mcmc->move_name[mcmc->num_move_updown_nu_cr],"updown_nu_cr"); + strcpy(mcmc->move_name[mcmc->num_move_ras],"ras"); + strcpy(mcmc->move_name[mcmc->num_move_updown_t_cr],"updown_t_cr"); + strcpy(mcmc->move_name[mcmc->num_move_cov_rates],"cov_rates"); + strcpy(mcmc->move_name[mcmc->num_move_cov_switch],"cov_switch"); + strcpy(mcmc->move_name[mcmc->num_move_birth_rate],"birth_rate"); + strcpy(mcmc->move_name[mcmc->num_move_death_rate],"death_rate"); + strcpy(mcmc->move_name[mcmc->num_move_birth_death_updown],"birth_death_updown"); + strcpy(mcmc->move_name[mcmc->num_move_updown_t_br],"updown_t_br"); + strcpy(mcmc->move_name[mcmc->num_move_jump_calibration],"jump_calibration"); + strcpy(mcmc->move_name[mcmc->num_move_geo_lambda],"geo_lambda"); + strcpy(mcmc->move_name[mcmc->num_move_geo_sigma],"geo_sigma"); + strcpy(mcmc->move_name[mcmc->num_move_geo_tau],"geo_tau"); + strcpy(mcmc->move_name[mcmc->num_move_geo_updown_tau_lbda],"geo_updown_tau_lbda"); + strcpy(mcmc->move_name[mcmc->num_move_geo_updown_lbda_sigma],"geo_updown_lbda_sigma"); + strcpy(mcmc->move_name[mcmc->num_move_geo_dum],"geo_dum"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_lbda],"phyrex_lbda"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_mu],"phyrex_mu"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_rad],"phyrex_rad"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_indel_disk],"phyrex_indel_disk"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_move_disk_ud],"phyrex_move_disk_ud"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_swap_disk],"phyrex_swap_disk"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_indel_hit],"phyrex_indel_hit"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_spr],"phyrex_spr"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_spr_local],"phyrex_spr_local"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_scale_times],"phyrex_scale_times"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_ldscape_lim],"phyrex_ldscape_lim"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_sigsq],"phyrex_sigsq"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_sim],"phyrex_sim"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_traj],"phyrex_traj"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_indel_disk_serial],"phyrex_indel_disk_serial"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_sim_plus],"phyrex_sim_plus"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_indel_hit_serial],"phyrex_indel_hit_serial"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_ldsk_multi],"phyrex_ldsk_multi"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_disk_multi],"phyrex_disk_multi"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_ldsk_and_disk],"phyrex_ldsk_and_disk"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_disk_given_ldsk],"phyrex_disk_given_ldsk"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_ldsk_given_disk],"phyrex_ldsk_given_disk"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_add_remove_jump],"phyrex_add_remove_jump"); + strcpy(mcmc->move_name[mcmc->num_move_clade_change],"clade_change"); + strcpy(mcmc->move_name[mcmc->num_move_phyrex_ldsk_tip_to_root],"phyrex_ldsk_tip_to_root"); + + + for(i=0;in_moves;i++) mcmc->move_type[i] = -1; + mcmc->move_type[mcmc->num_move_nd_r] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_br_r] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_times] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_root_time] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_nu] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_clock_r] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_tree_height] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_time_slice] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_subtree_height] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_kappa] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_rr] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_tree_rates] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_subtree_rates] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_updown_nu_cr] = MCMC_MOVE_RANDWALK_NORMAL; + mcmc->move_type[mcmc->num_move_ras] = MCMC_MOVE_RANDWALK_NORMAL; + mcmc->move_type[mcmc->num_move_updown_t_cr] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_cov_rates] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_cov_switch] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_birth_rate] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_death_rate] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_birth_death_updown] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_updown_t_br] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_jump_calibration] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_geo_lambda] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_geo_sigma] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_geo_tau] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_geo_updown_tau_lbda] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_geo_updown_lbda_sigma] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_geo_dum] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_phyrex_lbda] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_phyrex_mu] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_phyrex_rad] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_phyrex_scale_times] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_phyrex_sigsq] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_phyrex_indel_hit] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_phyrex_indel_disk] = MCMC_MOVE_SCALE_THORNE; + mcmc->move_type[mcmc->num_move_phyrex_ldsk_tip_to_root] = MCMC_MOVE_SCALE_THORNE; + + /* We start with small tuning parameter values in order to have inflated ESS + for clock_r */ + for(i=0;in_moves;i++) + { + switch(mcmc->move_type[i]) + { + case MCMC_MOVE_RANDWALK_NORMAL: + { + /* mcmc->tune_move[i] = 1.E-1; */ + mcmc->tune_move[i] = 100.; + break; + } + case MCMC_MOVE_RANDWALK_UNIFORM: + { + /* mcmc->tune_move[i] = 2.0; */ + mcmc->tune_move[i] = 20.0; + break; + } + case MCMC_MOVE_SCALE_GAMMA: + { + mcmc->tune_move[i] = 1.0; + /* mcmc->tune_move[i] = 10.0; */ + break; + } + case MCMC_MOVE_SCALE_THORNE: + { + mcmc->tune_move[i] = 1.0; + break; + } + default : + { + mcmc->tune_move[i] = 1.0; + break; + } + } + } + + mcmc->move_weight[mcmc->num_move_br_r] = 1.0; + mcmc->move_weight[mcmc->num_move_nd_r] = 0.0; + mcmc->move_weight[mcmc->num_move_times] = 1.0; + mcmc->move_weight[mcmc->num_move_times_and_rates] = 5.0; + mcmc->move_weight[mcmc->num_move_root_time] = 0.0; + mcmc->move_weight[mcmc->num_move_clock_r] = 1.0; + mcmc->move_weight[mcmc->num_move_tree_height] = 1.0; + mcmc->move_weight[mcmc->num_move_time_slice] = 0.0; + mcmc->move_weight[mcmc->num_move_subtree_height] = 0.0; + mcmc->move_weight[mcmc->num_move_nu] = 1.0; + mcmc->move_weight[mcmc->num_move_kappa] = 0.5; + mcmc->move_weight[mcmc->num_move_rr] = 0.5; + mcmc->move_weight[mcmc->num_move_spr] = 3.0; + mcmc->move_weight[mcmc->num_move_spr_weighted] = 5.0; + mcmc->move_weight[mcmc->num_move_spr_local] = 3.0; + mcmc->move_weight[mcmc->num_move_spr_root] = 0.0; + mcmc->move_weight[mcmc->num_move_tree_rates] = 1.0; + mcmc->move_weight[mcmc->num_move_subtree_rates] = 0.0; + mcmc->move_weight[mcmc->num_move_updown_nu_cr] = 0.0; + mcmc->move_weight[mcmc->num_move_ras] = 1.0; + mcmc->move_weight[mcmc->num_move_updown_t_cr] = 1.0; /* Does not seem to work well (does not give uniform prior on root height + when sampling from prior) */ + mcmc->move_weight[mcmc->num_move_cov_rates] = 0.0; + mcmc->move_weight[mcmc->num_move_cov_switch] = 0.0; + mcmc->move_weight[mcmc->num_move_birth_rate] = 1.0; + mcmc->move_weight[mcmc->num_move_death_rate] = 1.0; + mcmc->move_weight[mcmc->num_move_birth_death_updown] = 1.0; + mcmc->move_weight[mcmc->num_move_updown_t_br] = 0.0; +#if defined (INVITEE) + mcmc->move_weight[mcmc->num_move_jump_calibration] = 0.1; +#else + mcmc->move_weight[mcmc->num_move_jump_calibration] = 0.0; +#endif + mcmc->move_weight[mcmc->num_move_geo_lambda] = 1.0; + mcmc->move_weight[mcmc->num_move_geo_sigma] = 1.0; + mcmc->move_weight[mcmc->num_move_geo_tau] = 1.0; + mcmc->move_weight[mcmc->num_move_geo_updown_tau_lbda] = 1.0; + mcmc->move_weight[mcmc->num_move_geo_updown_lbda_sigma] = 1.0; + mcmc->move_weight[mcmc->num_move_geo_dum] = 1.0; + mcmc->move_weight[mcmc->num_move_clade_change] = 1.0; + +# if defined (PHYREX) + + mcmc->move_weight[mcmc->num_move_phyrex_lbda] = 1.0; + mcmc->move_weight[mcmc->num_move_phyrex_mu] = 1.0; + mcmc->move_weight[mcmc->num_move_phyrex_rad] = 1.0; + mcmc->move_weight[mcmc->num_move_phyrex_sigsq] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_indel_disk] = 1.0; + mcmc->move_weight[mcmc->num_move_phyrex_indel_hit] = 1.0; + mcmc->move_weight[mcmc->num_move_phyrex_move_disk_ud] = 2.0; + mcmc->move_weight[mcmc->num_move_phyrex_swap_disk] = 2.0; + mcmc->move_weight[mcmc->num_move_phyrex_spr] = 0.5; + mcmc->move_weight[mcmc->num_move_phyrex_spr_local] = 1.0; + mcmc->move_weight[mcmc->num_move_phyrex_scale_times] = 2.0; + mcmc->move_weight[mcmc->num_move_phyrex_ldscape_lim] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_sim] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_traj] = 2.0; + mcmc->move_weight[mcmc->num_move_phyrex_sim_plus] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_indel_disk_serial] = 2.0; + mcmc->move_weight[mcmc->num_move_phyrex_indel_hit_serial] = 2.0; + + mcmc->move_weight[mcmc->num_move_phyrex_ldsk_given_disk] = 1.0; + mcmc->move_weight[mcmc->num_move_phyrex_disk_given_ldsk] = 1.0; + mcmc->move_weight[mcmc->num_move_phyrex_ldsk_and_disk] = 0.5; + mcmc->move_weight[mcmc->num_move_phyrex_ldsk_multi] = 1.0; + mcmc->move_weight[mcmc->num_move_phyrex_disk_multi] = 1.0; + mcmc->move_weight[mcmc->num_move_phyrex_add_remove_jump] = 3.0; + mcmc->move_weight[mcmc->num_move_phyrex_ldsk_tip_to_root] = 1.0; + +# else + + mcmc->move_weight[mcmc->num_move_phyrex_lbda] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_mu] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_rad] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_sigsq] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_indel_disk] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_indel_hit] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_move_disk_ud] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_swap_disk] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_spr] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_spr_local] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_scale_times] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_ldscape_lim] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_sim] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_traj] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_sim_plus] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_indel_disk_serial] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_indel_hit_serial] = 0.0; + + mcmc->move_weight[mcmc->num_move_phyrex_ldsk_given_disk] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_disk_given_ldsk] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_ldsk_and_disk] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_ldsk_multi] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_disk_multi] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_add_remove_jump] = 0.0; + mcmc->move_weight[mcmc->num_move_phyrex_ldsk_tip_to_root] = 0.0; +#endif + + sum = 0.0; + for(i=0;in_moves;i++) sum += mcmc->move_weight[i]; + for(i=0;in_moves;i++) mcmc->move_weight[i] /= sum; + for(i=1;in_moves;i++) mcmc->move_weight[i] += mcmc->move_weight[i-1]; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Initialize_Param_Val(t_mcmc *mcmc, t_tree *tree) +{ + /* int i; */ + + /* mcmc->lag_param_val[mcmc->num_move_nu] = tree->rates->nu; */ + /* mcmc->lag_param_val[mcmc->num_move_clock_r] = tree->rates->clock_r; */ + /* mcmc->lag_param_val[mcmc->num_move_tree_height] = tree->rates->nd_t[tree->n_root->num]; */ + /* mcmc->lag_param_val[mcmc->num_move_kappa] = tree->mod->kappa->v; */ + + /* For(i,2*tree->n_otu-2) */ + /* mcmc->lag_param_val[mcmc->num_move_br_r+i] = tree->rates->br_r[i]; */ + + /* for(i=0;in_otu-1;i++) */ + /* mcmc->lag_param_val[mcmc->num_move_nd_t+i] = tree->rates->nd_t[tree->n_otu+i]; */ + + /* For(i,2*tree->n_otu-1) */ + /* mcmc->lag_param_val[mcmc->num_move_nd_r+i] = tree->rates->nd_r[i]; */ + + /* for(i=0;in_moves;i++) tree->mcmc->new_param_val[i] = tree->mcmc->lag_param_val[i]; */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Copy_To_New_Param_Val(t_mcmc *mcmc, t_tree *tree) +{ + mcmc->sampled_val[mcmc->num_move_nu*mcmc->sample_size+mcmc->sample_num] = tree->rates->nu; + mcmc->sampled_val[mcmc->num_move_clock_r*mcmc->sample_size+mcmc->sample_num] = tree->rates->clock_r; + mcmc->sampled_val[mcmc->num_move_tree_height*mcmc->sample_size+mcmc->sample_num] = tree->rates->nd_t[tree->n_root->num]; + mcmc->sampled_val[mcmc->num_move_kappa*mcmc->sample_size+mcmc->sample_num] = tree->mod ? tree->mod->kappa->v : -1.; + mcmc->sampled_val[mcmc->num_move_birth_rate*mcmc->sample_size+mcmc->sample_num] = tree->rates->birth_rate; + mcmc->sampled_val[mcmc->num_move_death_rate*mcmc->sample_size+mcmc->sample_num] = tree->rates->death_rate; + + /* For(i,2*tree->n_otu-2) */ + /* mcmc->sampled_val[(mcmc->num_move_br_r+i)*mcmc->sample_size+mcmc->sample_num] = tree->rates->br_r[i]; */ + + + /* For(i,2*tree->n_otu-1) */ + /* mcmc->sampled_val[(mcmc->num_move_nd_r+i)*mcmc->sample_size+mcmc->sample_num] = tree->rates->nd_r[i]; */ + + mcmc->sampled_val[mcmc->num_move_geo_tau*mcmc->sample_size+mcmc->sample_num] = tree->geo ? tree->geo->tau : -1.; + mcmc->sampled_val[mcmc->num_move_geo_lambda*mcmc->sample_size+mcmc->sample_num] = tree->geo ? tree->geo->lbda : -1.; + mcmc->sampled_val[mcmc->num_move_geo_sigma*mcmc->sample_size+mcmc->sample_num] = tree->geo ? tree->geo->sigma : -1.; + mcmc->sampled_val[mcmc->num_move_geo_dum*mcmc->sample_size+mcmc->sample_num] = tree->geo ? tree->geo->dum : -1.; + #ifdef PHYREX + mcmc->sampled_val[mcmc->num_move_phyrex_lbda*mcmc->sample_size+mcmc->sample_num] = tree->mmod ? tree->mmod->lbda : -1.; + mcmc->sampled_val[mcmc->num_move_phyrex_mu*mcmc->sample_size+mcmc->sample_num] = tree->mmod ? PHYREX_Neighborhood_Size(tree) : -1.; + mcmc->sampled_val[mcmc->num_move_phyrex_sigsq*mcmc->sample_size+mcmc->sample_num] = tree->mmod ? PHYREX_Update_Sigsq(tree) : -1.; + mcmc->sampled_val[mcmc->num_move_phyrex_rad*mcmc->sample_size+mcmc->sample_num] = tree->mmod ? tree->mmod->rad : -1.; + #endif +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Slice_One_Rate(t_node *a, t_node *d, int traversal, t_tree *tree) +{ + phydbl L,R; /* Left and Right limits of the slice */ + phydbl w; /* window width */ + phydbl u; + phydbl x0,x1; + phydbl logy; + t_edge *b; + int i; + + + + b = NULL; + if(a == tree->n_root) b = tree->e_root; + else for(i=0;i<3;i++) if(d->v[i] == a) { b = d->b[i]; break; } + + w = 0.05; + /* w = 10.; */ + + x0 = tree->rates->br_r[d->num]; + logy = tree->c_lnL+tree->rates->c_lnL_rates - Rexp(1.); + + u = Uni(); + + L = x0 - w*u; + R = L + w; + + do + { + tree->rates->br_r[d->num] = L; + tree->rates->br_do_updt[d->num] = YES; + RATES_Update_Cur_Bl(tree); + Lk(b,tree); + RATES_Lk_Rates(tree); + if(L < tree->rates->min_rate) { L = tree->rates->min_rate - w; break;} + L = L - w; + } + while(tree->c_lnL + tree->rates->c_lnL_rates > logy); + L = L + w; + + + do + { + tree->rates->br_r[d->num] = R; + tree->rates->br_do_updt[d->num] = YES; + RATES_Update_Cur_Bl(tree); + Lk(b,tree); + RATES_Lk_Rates(tree); + if(R > tree->rates->max_rate) { R = tree->rates->max_rate + w; break;} + R = R + w; + } + while(tree->c_lnL + tree->rates->c_lnL_rates > logy); + R = R - w; + + + for(;;) + { + u = Uni(); + x1 = L + u*(R-L); + + tree->rates->br_r[d->num] = x1; + tree->rates->br_do_updt[d->num] = YES; + RATES_Update_Cur_Bl(tree); + Lk(b,tree); + RATES_Lk_Rates(tree); + + if(tree->c_lnL + tree->rates->c_lnL_rates > logy) break; + + if(x1 < x0) L = x1; + else R = x1; + } + + + if(traversal == YES) + { + if(d->tax == YES) return; + else + { + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(tree->io->lk_approx == EXACT) Update_Partial_Lk(tree,d->b[i],d); + MCMC_Slice_One_Rate(d,d->v[i],YES,tree); + } + } + if(tree->io->lk_approx == EXACT) Update_Partial_Lk(tree,b,d); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Make_Move(phydbl *cur, phydbl *new, phydbl inf, phydbl sup, phydbl *loghr, phydbl tune, int move_type) +{ + phydbl u; + + + + switch(move_type) + { + + case MCMC_MOVE_RANDWALK_NORMAL: + { + *new = *cur + Rnorm(0.0,tune); + /* Do not use reflection here */ + *loghr = 0.0; + + break; + } + + case MCMC_MOVE_RANDWALK_UNIFORM: + { + u = Uni(); + /* *new = u * (2.*tune) + (*cur) - tune; */ + /* *new = Reflect(*new,inf,sup); */ + *new = u*(sup-inf)+inf; + *loghr = 0.0; + break; + } + + case MCMC_MOVE_SCALE_THORNE: + { + u = Uni(); + *new = (*cur) * exp(tune*(u-.5)); + *loghr = log((*new)/(*cur)); + break; + } + + case MCMC_MOVE_SCALE_GAMMA: + { + phydbl r; + *new = (*cur) * Rgamma(1./tune,tune); + r = (*new)/(*cur); + *loghr = -log(r) + log(Dgamma(1./r,1./tune,tune)/Dgamma(r,1./tune,tune)); + break; + } + + default : + { + PhyML_Printf("\n. Move not implemented"); + Exit(""); + break; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MCMC_Read_Param_Vals(t_tree *tree) +{ + char *token; + int sizemax; + FILE *in_fp; + phydbl val; + int i,v; + + in_fp = tree->mcmc->in_fp_par; + + sizemax = T_MAX_LINE; + + token = (char *)mCalloc(sizemax,sizeof(char)); + + if(fgets(token,sizemax,in_fp) == NULL) // Skip first line + { + PhyML_Fprintf(stderr,"\n. Wrong file format."); + assert(FALSE); + } + + if(fgets(token,sizemax,in_fp) == NULL) // Skip second + { + PhyML_Fprintf(stderr,"\n. Wrong file format."); + assert(FALSE); + } + + v=fscanf(in_fp,"%lf\t",&val); // Run + /* PhyML_Printf("\n. Run = %d",(int)val); */ + v=fscanf(in_fp,"%lf\t",&val); // LnLike[Exact] + /* PhyML_Printf("\n. LnLike = %f",val); */ + v=fscanf(in_fp,"%lf\t",&val); // LnLike[Approx] + /* PhyML_Printf("\n. LnLike = %f",val); */ + v=fscanf(in_fp,"%lf\t",&val); // LnPriorRate + /* PhyML_Printf("\n. LnPrior = %f",val); */ + v=fscanf(in_fp,"%lf\t",&val); // LnPriorTime + /* PhyML_Printf("\n. LnPrior = %f",val); */ + v=fscanf(in_fp,"%lf\t",&val); // LnPosterior + /* PhyML_Printf("\n. LnPost = %f",val); */ + + v=fscanf(in_fp,"%lf\t",&val); // ClockRate + tree->rates->clock_r = val; + /* PhyML_Printf("\n. Clock = %f",val); */ + + v=fscanf(in_fp,"%lf\t",&val); // EvolRate + + v=fscanf(in_fp,"%lf\t",&val); // Nu + tree->rates->nu = val; + /* PhyML_Printf("\n. Nu = %f",val); */ + + v=fscanf(in_fp,"%lf\t",&val); // Birth rate + tree->rates->birth_rate = val; + + v=fscanf(in_fp,"%lf\t",&val); // TsTv + tree->mod->kappa->v = val; + /* PhyML_Printf("\n. TsTv = %f",val); */ + + for(i=0;in_otu-1;i++) + { + v=fscanf(in_fp,"%lf\t",&val); // Node heights + tree->rates->nd_t[i+tree->n_otu] = val; + } + + For(i,2*tree->n_otu-2) + { + v=fscanf(in_fp,"%lf\t",&val); // Edge average rates + tree->rates->br_r[i] = log(val); + } + + v++; + + Free(token); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#ifdef PHYREX +void MCMC_PHYREX_Lbda(t_tree *tree) +{ + /* MCMC_Single_Param_Generic(&(tree->mmod->lbda), */ + /* tree->mmod->min_lbda, */ + /* tree->mmod->max_lbda, */ + /* tree->mcmc->num_move_phyrex_lbda, */ + /* NULL,&(tree->mmod->c_lnL), */ + /* NULL,(tree->eval_glnL == YES) ? PHYREX_Wrap_Lk : NULL, */ + /* tree->mcmc->move_type[tree->mcmc->num_move_phyrex_lbda], */ + /* NO,NULL,tree,NULL); */ + + + phydbl u,alpha,ratio; + phydbl cur_glnL, new_glnL, hr; + phydbl cur_lbda, new_lbda; + phydbl K; + + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_lbda]++; + + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + cur_lbda = tree->mmod->lbda; + new_lbda = tree->mmod->lbda; + K = tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_lbda]; + + MCMC_Make_Move(&cur_lbda,&new_lbda,tree->mmod->min_lbda,tree->mmod->max_lbda,&ratio,K,tree->mcmc->move_type[tree->mcmc->num_move_phyrex_lbda]); + + if(new_lbda < tree->mmod->max_lbda && new_lbda > tree->mmod->min_lbda) + { + tree->mmod->lbda = new_lbda; + + if(tree->eval_glnL == YES) new_glnL = PHYREX_Lk(tree); + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + + /* PhyML_Printf("\n. cur_lbda: %12f new_lbda: %12f cur_glnL: %12f new_glnL: %12f K=%g [%d/%d]", */ + /* cur_lbda,new_lbda,cur_glnL,new_glnL,K, */ + /* tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_lbda], */ + /* tree->mcmc->run_move[tree->mcmc->num_move_phyrex_lbda]); */ + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + if(u > alpha) /* Reject */ + { + tree->mmod->lbda = cur_lbda; + tree->mmod->c_lnL = cur_glnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_lbda]++; + } + } +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#ifdef PHYREX +void MCMC_PHYREX_Mu(t_tree *tree) +{ + MCMC_Single_Param_Generic(&(tree->mmod->mu), + tree->mmod->min_mu, + tree->mmod->max_mu, + tree->mcmc->num_move_phyrex_mu, + NULL,&(tree->mmod->c_lnL), + NULL,(tree->eval_glnL == YES) ? PHYREX_Wrap_Lk : NULL, + tree->mcmc->move_type[tree->mcmc->num_move_phyrex_mu], + NO,NULL,tree,NULL); +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#ifdef PHYREX +void MCMC_PHYREX_Radius(t_tree *tree) +{ + MCMC_Single_Param_Generic(&(tree->mmod->rad), + tree->mmod->min_rad, + tree->mmod->max_rad, + tree->mcmc->num_move_phyrex_rad, + NULL,&(tree->mmod->c_lnL), + NULL,(tree->eval_glnL == YES) ? PHYREX_Wrap_Lk : NULL, + tree->mcmc->move_type[tree->mcmc->num_move_phyrex_rad], + NO,NULL,tree,NULL); + + /* phydbl u,alpha,ratio; */ + /* phydbl cur_glnL, new_glnL, hr; */ + /* phydbl cur_rad, new_rad; */ + /* phydbl K; */ + + /* tree->mcmc->run_move[tree->mcmc->num_move_phyrex_rad]++; */ + + /* new_glnL = tree->mmod->c_lnL; */ + /* cur_glnL = tree->mmod->c_lnL; */ + /* hr = 0.0; */ + /* ratio = 0.0; */ + /* cur_rad = tree->mmod->rad; */ + /* new_rad = tree->mmod->rad; */ + /* K = tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_rad]; */ + + /* MCMC_Make_Move(&cur_rad,&new_rad,tree->mmod->min_rad,tree->mmod->max_rad,&ratio,K,tree->mcmc->move_type[tree->mcmc->num_move_phyrex_rad]); */ + + /* if(new_rad < tree->mmod->max_rad && new_rad > tree->mmod->min_rad) */ + /* { */ + /* tree->mmod->rad = new_rad; */ + + /* if(tree->eval_glnL == YES) new_glnL = PHYREX_Lk(tree); */ + + /* ratio += (new_glnL - cur_glnL); */ + /* ratio += hr; */ + + /* ratio = exp(ratio); */ + /* alpha = MIN(1.,ratio); */ + + + /* PhyML_Printf("\n. new_rad: %12f cur_rad: %12f new_glnL: %12f cur_glnL: %12f",new_rad,cur_rad,new_glnL,cur_glnL); */ + + /* /\* Always accept move *\/ */ + /* if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; */ + + /* u = Uni(); */ + + /* if(u > alpha) /\* Reject *\/ */ + /* { */ + /* tree->mmod->rad = cur_rad; */ + /* tree->mmod->c_lnL = cur_glnL; */ + /* } */ + /* else */ + /* { */ + /* tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_rad]++; */ + /* } */ + /* } */ +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Sigsq(t_tree *tree) +{ + tree->mmod->update_rad = YES; + MCMC_Single_Param_Generic(&(tree->mmod->sigsq), + tree->mmod->min_sigsq, + tree->mmod->max_sigsq, + tree->mcmc->num_move_phyrex_sigsq, + NULL,&(tree->mmod->c_lnL), + NULL,(tree->eval_glnL == YES) ? PHYREX_Wrap_Lk : NULL, + tree->mcmc->move_type[tree->mcmc->num_move_phyrex_sigsq], + NO,NULL,tree,NULL); + tree->mmod->rad = PHYREX_Update_Radius(tree); + tree->mmod->update_rad = NO; +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +#ifdef PHYREX +void MCMC_PHYREX_Indel_Disk(t_tree *tree) +{ + int n_disks_cur, n_disks_new; + phydbl hr; + phydbl cur_lbda,new_lbda; + phydbl cur_mu,new_mu; + phydbl cur_rad,new_rad; + t_dsk *disk; + + hr = 0.0; + new_lbda = tree->mmod->lbda; + cur_lbda = tree->mmod->lbda; + new_mu = tree->mmod->mu; + cur_mu = tree->mmod->mu; + new_rad = tree->mmod->rad; + cur_rad = tree->mmod->rad; + + /* new_lbda = cur_lbda * exp(1.0*(Uni()-.5)); */ + /* hr += log(new_lbda/cur_lbda); */ + + /* new_mu = cur_mu * exp(0.5*(Uni()-.5)); */ + /* hr += log(new_mu/cur_mu); */ + + /* new_rad = cur_rad * exp(0.5*(Uni()-.5)); */ + /* hr += log(new_rad/cur_rad); */ + + if(new_rad > tree->mmod->max_rad || new_rad < tree->mmod->min_rad) return; + if(new_mu > tree->mmod->max_mu || new_mu < tree->mmod->min_mu) return; + if(new_lbda > tree->mmod->max_lbda || new_lbda < tree->mmod->min_lbda) return; + + tree->mmod->lbda = new_lbda; + tree->mmod->mu = new_mu; + tree->mmod->rad = new_rad; + + disk = tree->young_disk->prev; + n_disks_cur = 0; + do + { + if(disk->ldsk == NULL && disk->age_fixed == NO) n_disks_cur++; + disk = disk->prev; + } + while(disk); + + n_disks_new = (int)Rpois(n_disks_cur+SMALL); + hr += Dpois(n_disks_cur,n_disks_new+SMALL,YES); + hr -= Dpois(n_disks_new,n_disks_cur+SMALL,YES); + + if(n_disks_new < n_disks_cur) + { + MCMC_PHYREX_Delete_Disk(hr, n_disks_cur - n_disks_new , cur_lbda, cur_mu, cur_rad, tree); + } + else + { + MCMC_PHYREX_Insert_Disk(hr, n_disks_new - n_disks_cur, cur_lbda, cur_mu, cur_rad, tree); + } + +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Insert or delete a disk that does not affect any ldisk */ +#ifdef PHYREX +void MCMC_PHYREX_Delete_Disk(phydbl hr, int n_delete_disks, phydbl cur_lbda, phydbl cur_mu, phydbl cur_rad, t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl cur_glnL, new_glnL; + phydbl T; + t_dsk *disk,**target_disk,**valid_disks; + int i,j,block,n_valid_disks,*permut; + + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_indel_disk]++; + + if(n_delete_disks == 0) + { + tree->mmod->lbda = cur_lbda; + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + return; + } + + valid_disks = NULL; + disk = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + ratio = 0.0; + block = 100; + + disk = tree->young_disk->prev; + + if(!disk->prev) + { + tree->mmod->lbda = cur_lbda; + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + return; + } + + n_valid_disks = 0; + do + { + if(!disk->ldsk && disk->age_fixed == NO) + { + if(!n_valid_disks) valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_valid_disks%block)) valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + valid_disks[n_valid_disks] = disk; + n_valid_disks++; + } + disk = disk->prev; + } + while(disk && disk->prev); + + + if(!n_valid_disks || (n_valid_disks - n_delete_disks < 0)) + { + tree->mmod->lbda = cur_lbda; + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + return; + } + + target_disk = (t_dsk **)mCalloc(n_delete_disks,sizeof(t_dsk *)); + + permut = Permutate(n_valid_disks); + + for(j=0;jmmod->n_dim;i++) hr += log(1./(tree->mmod->lim_up->lonlat[i]-tree->mmod->lim_do->lonlat[i])); + } + + T = PHYREX_Tree_Height(tree); + T = fabs(T-tree->young_disk->time); + + + // Pr(n -> n-k) i.e, denominator + hr += LnChoose(n_valid_disks,n_delete_disks); + + // Pr(n-k -> n) i.e., numerator + hr += n_delete_disks * log(1./T); + hr += LnFact(n_delete_disks); + + if(tree->eval_glnL == YES) new_glnL = PHYREX_Lk(tree); + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + /* PhyML_Printf("\n- Delete new_glnL: %f [%f] hr: %f u:%f alpha: %f n_delete: %d [%d %d %f]", */ + /* new_glnL,cur_glnL,hr,u,alpha,n_delete_disks, */ + /* tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_indel_disk], */ + /* tree->mcmc->run_move[tree->mcmc->num_move_phyrex_indel_disk], */ + /* tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_indel_disk]); */ + + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + tree->mmod->lbda = cur_lbda; + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + + for(j=0;jmmod->c_lnL = cur_glnL; + } + else + { + for(j=0;jmcmc->acc_move[tree->mcmc->num_move_phyrex_indel_disk]++; + } + + Free(valid_disks); + Free(target_disk); + Free(permut); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Insert_Disk(phydbl hr, int n_insert_disks, phydbl cur_lbda, phydbl cur_mu, phydbl cur_rad, t_tree *tree) +{ + t_dsk *disk,**new_disk,**target_disk; + phydbl T,t; + phydbl cur_glnL, new_glnL; + phydbl u,alpha,ratio; + int i,j,n_valid_disks,num_prec_issue; + + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_indel_disk]++; + + if(n_insert_disks == 0) + { + tree->mmod->lbda = cur_lbda; + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + return; + } + + disk = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + ratio = 0.0; + num_prec_issue = NO; + + if(tree->young_disk->next) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + T = PHYREX_Tree_Height(tree); + + disk = tree->young_disk->prev; + n_valid_disks = 0; + do + { + if(!disk->ldsk) n_valid_disks++; + disk = disk->prev; + } + while(disk && disk->prev); + + target_disk = (t_dsk **)mCalloc(n_insert_disks,sizeof(t_dsk *)); + new_disk = (t_dsk **)mCalloc(n_insert_disks,sizeof(t_dsk *)); + + + for(j=0;jyoung_disk->time-T) + T; + disk = tree->young_disk->prev; + while(disk && disk->time > t) disk = disk->prev; + + if(!(disk->time != t)) + { + PhyML_Printf("\n. Numerical precision issue in insert_disk"); + PhyML_Printf("\n. t=%g disk->time=%g diff=%g",t,disk->time,t-disk->time); + num_prec_issue = YES; + } + }while(num_prec_issue == YES); + + + + + assert(disk->next); + target_disk[j] = disk->next; + + new_disk[j] = PHYREX_Make_Disk_Event(tree->mmod->n_dim,tree->n_otu); + PHYREX_Init_Disk_Event(new_disk[j],tree->mmod->n_dim,tree->mmod); + new_disk[j]->time = t; + + PHYREX_Insert_Disk(new_disk[j],tree); + + for(i=0;immod->n_dim;i++) new_disk[j]->centr->lonlat[i] = Uni()*(tree->mmod->lim_up->lonlat[i]-tree->mmod->lim_do->lonlat[i])+tree->mmod->lim_do->lonlat[i]; + + for(i=0;immod->n_dim;i++) hr -= log(1./(tree->mmod->lim_up->lonlat[i]-tree->mmod->lim_do->lonlat[i])); + } + + /* // Pr(n+k -> n) i.e, numerator */ + hr -= LnChoose(n_valid_disks+n_insert_disks,n_insert_disks); + + /* // Pr(n -> n+k) i.e., denominator */ + T = fabs(T-tree->young_disk->time); + hr -= n_insert_disks * log(1./T); + hr -= LnFact(n_insert_disks); + + + if(tree->eval_glnL == YES) new_glnL = PHYREX_Lk(tree); + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + /* PhyML_Printf("\n+ Insert new_glnL: %f [%f] hr: %f u: %f alpha: %f n_insert: %d [%d %d %d %d %f]", */ + /* new_glnL,cur_glnL,hr,u,alpha,n_insert_disks, */ + /* tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_indel_disk], */ + /* tree->mcmc->run_move[tree->mcmc->num_move_phyrex_indel_disk], */ + /* tree->mcmc->prev_acc_move[tree->mcmc->num_move_phyrex_indel_disk], */ + /* tree->mcmc->prev_run_move[tree->mcmc->num_move_phyrex_indel_disk], */ + /* tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_indel_disk]); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + tree->mmod->lbda = cur_lbda; + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + + for(j=0;jmmod->c_lnL = cur_glnL; + } + else + { + /* printf("\nI Accept %f",tree->mmod->lbda); */ + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_indel_disk]++; + } + + Free(target_disk); + Free(new_disk); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Update time of disk */ +#ifdef PHYREX + +void MCMC_PHYREX_Move_Disk_Updown(t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl cur_glnL, new_glnL, hr; + phydbl cur_alnL, new_alnL; + phydbl cur_rlnL, new_rlnL; + phydbl *ori_time,new_time,cur_time; + phydbl max, min; + t_dsk *disk,**target_disk,**all_disks; + int i,block,n_all_disks,n_move_disks,*permut,update_alnL; + + disk = NULL; + block = 100; + all_disks = NULL; + + disk = tree->young_disk->prev; + n_all_disks = 0; + do + { + if((disk->age_fixed) == NO && !(disk->ldsk && disk->ldsk->n_next > 1 && tree->mod->s_opt->opt_bl == NO)) + { + if(!n_all_disks) all_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_all_disks%block)) all_disks = (t_dsk **)mRealloc(all_disks,n_all_disks+block,sizeof(t_dsk *)); + all_disks[n_all_disks] = disk; + n_all_disks++; + } + disk = disk->prev; + } + while(disk); + + if(!n_all_disks) return; + + n_move_disks = (int)(1+0.2*n_all_disks); + + target_disk = (t_dsk **)mCalloc(n_all_disks,sizeof(t_dsk *)); + ori_time = (phydbl *)mCalloc(n_all_disks,sizeof(phydbl)); + + permut = Permutate(n_all_disks); + + for(i=0;imcmc->run_move[tree->mcmc->num_move_phyrex_move_disk_ud]++; + + /* cur_glnL = PHYREX_Lk(tree); */ + cur_glnL = tree->mmod->c_lnL; + new_glnL = tree->mmod->c_lnL; + new_alnL = tree->c_lnL; + cur_alnL = tree->c_lnL; + new_rlnL = tree->rates->c_lnL_rates; + cur_rlnL = tree->rates->c_lnL_rates; + hr = 0.0; + ratio = 0.0; + + target_disk[i] = all_disks[permut[i]]; + + + update_alnL = NO; + if(target_disk[i]->ldsk && target_disk[i]->ldsk->n_next > 1) update_alnL = YES; + + ori_time[i] = target_disk[i]->time; + cur_time = target_disk[i]->time; + + + if(target_disk[i]->prev) + { + max = target_disk[i]->next->time; + min = target_disk[i]->prev->time; + new_time = Uni()*(max - min) + min; + /* PhyML_Printf("\n. disk: %s max: %f min: %f curr_time: %f new_time: %f",target_disk[i]->id,max,min,target_disk[i]->time,new_time); */ + } + else + { + /* phydbl new_plusmin, cur_plusmin; */ + phydbl K; + + K = 0.1; + + max = target_disk[i]->next->time; + + /* cur_plusmin = fabs(ori_time[i] - max); */ + /* new_plusmin = Rexp(1./cur_plusmin); */ + + /* new_time = max - new_plusmin; */ + new_time = max - Rexp(K*tree->mmod->lbda); + + /* hr += log(Dexp(cur_plusmin,1./new_plusmin)); */ + /* hr -= log(Dexp(new_plusmin,1./cur_plusmin)); */ + + hr -= -(max-new_time)*K*tree->mmod->lbda; + hr += -(max-cur_time)*K*tree->mmod->lbda; + /* PhyML_Printf("\n* disk: %s max: %f cur_time: %f new_time: %f",target_disk[i]->id,max,target_disk[i]->time,new_time); */ + + + /* new_glnL += -tree->mmod->lbda * fabs(new_time); */ + /* new_glnL -= -tree->mmod->lbda * fabs(cur_time); */ + + /* tree->mmod->c_lnL = new_glnL; */ + + } + + + target_disk[i]->time = new_time; + + if(tree->eval_glnL == YES) new_glnL = PHYREX_Lk(tree); + if(tree->eval_alnL == YES && update_alnL == YES) new_alnL = Lk(NULL,tree); + if(tree->eval_rlnL == YES && update_alnL == YES) new_rlnL = RATES_Lk_Rates(tree); + + ratio += (new_alnL - cur_alnL); + ratio += (new_glnL - cur_glnL); + ratio += (new_rlnL - cur_rlnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + /* if(target_disk[i]->prev == NULL) PhyML_Printf("\n- Move disk new_glnL: %12f [%12f] hr: %12f u:%6f alpha: %12f new_time: %12f cur_time: %12f max: %12f",new_glnL,cur_glnL,hr,u,alpha,new_time,cur_time,max); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* printf("- Reject"); */ + + target_disk[i]->time = ori_time[i]; + + tree->mmod->c_lnL = cur_glnL; + tree->c_lnL = cur_alnL; + tree->rates->c_lnL_rates = cur_rlnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_move_disk_ud]++; + /* printf("- Accept"); */ + } + } + + Free(target_disk); + Free(all_disks); + Free(ori_time); + Free(permut); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Scale_Times(t_tree *tree) +{ + phydbl u,alpha,ratio; + /* phydbl cur_height,new_height; */ + phydbl cur_glnL, new_glnL, hr; + phydbl cur_alnL, new_alnL; + phydbl cur_rlnL, new_rlnL; + phydbl scale_fact_times; + int n_disks; + t_dsk *start_disk; + phydbl K; + + if(tree->mod->s_opt->opt_bl == NO) return; + + cur_alnL = tree->c_lnL; + new_alnL = tree->c_lnL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + new_rlnL = tree->rates->c_lnL_rates; + cur_rlnL = tree->rates->c_lnL_rates; + hr = 0.0; + ratio = 0.0; + /* cur_height = fabs(PHYREX_Tree_Height(tree)); */ + K = tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_scale_times]; + + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_scale_times]++; + + u = Uni(); + K = 2.; + scale_fact_times = exp(K*(u-.5)); + + start_disk = tree->old_samp_disk; + assert(start_disk); + + n_disks = PHYREX_Scale_All(scale_fact_times,start_disk,tree); + if(!PHYREX_Check_Struct(tree)) + { + PHYREX_Scale_All(1./scale_fact_times,start_disk,tree); + return; + } + + + /* The Hastings ratio involves (n_disk-2) when considering a uniform distrib + for the multiplier, which is not the case here. + */ + hr += (n_disks)*log(scale_fact_times); + + if(tree->eval_glnL == YES) + { + /* new_height = cur_height * scale_fact_times + fabs(start_disk->time) * (1. - scale_fact_times); */ + + /* Not so simple with serially sampled data... */ + /* new_glnL = cur_glnL; */ + /* new_glnL -= -tree->mmod->lbda * cur_height; */ + /* new_glnL += -tree->mmod->lbda * new_height; */ + /* tree->mmod->c_lnL = new_glnL; */ + + PHYREX_Lk(tree); + new_glnL = tree->mmod->c_lnL; + } + + if(tree->eval_alnL == YES) new_alnL = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_rlnL = RATES_Lk_Rates(tree); + + ratio += (new_alnL - cur_alnL); + ratio += (new_glnL - cur_glnL); + ratio += (new_rlnL - cur_rlnL); + + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + /* PhyML_Printf("\n. Scale times hr: %f new_glnL: %f cur_glnL: %f new_alnL: %f cur_alnL: %f new_rlnL: %f cur_rlnL: %f ratio: %f scale: %f", */ + /* hr, */ + /* new_glnL,cur_glnL, */ + /* new_alnL,cur_alnL, */ + /* new_rlnL,cur_rlnL, */ + /* ratio,scale_fact_times); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + + if(u > alpha) /* Reject */ + { + PHYREX_Scale_All(1./scale_fact_times,start_disk,tree); + PHYREX_Update_Lindisk_List(tree); + tree->mmod->c_lnL = cur_glnL; + tree->c_lnL = cur_alnL; + tree->rates->c_lnL_rates = cur_rlnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_scale_times]++; + } +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Swap_Disk(t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl cur_glnL, new_glnL; + phydbl cur_alnL, new_alnL; + phydbl cur_rlnL, new_rlnL; + phydbl hr,t,t_min,t_max,ori_time; + t_dsk *disk,*target_disk,*ori_disk_old,*ori_disk_young,**valid_disks; + t_ldsk *ldsk_next; + int i,j,block,n_valid_disks; + + valid_disks = NULL; + block = 100; + + disk = tree->young_disk->prev; + if(!disk->prev) return; + + n_valid_disks = 0; + do + { + /* Record disk with a lineage displacement or coalescent that is not the root disk and not a disk with sampled taxa on it */ + if(disk && disk->prev && disk->ldsk && disk->ldsk->n_next >= 1 && disk->age_fixed == NO) + { + if(!(disk->ldsk->n_next > 1 && tree->mod->s_opt->opt_bl == NO)) + { + if(!n_valid_disks) valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_valid_disks%block)) valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + valid_disks[n_valid_disks] = disk; + n_valid_disks++; + } + } + disk = disk->prev; + } + while(disk && disk->prev); + if(n_valid_disks < 2) return; + + for(j=0;jn_otu));++j) + { + disk = NULL; + target_disk = NULL; + ori_disk_old = NULL; + ori_disk_young = NULL; + ldsk_next = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + new_alnL = tree->c_lnL; + cur_alnL = tree->c_lnL; + new_rlnL = tree->rates->c_lnL_rates; + cur_rlnL = tree->rates->c_lnL_rates; + hr = 0.0; + ratio = 0.0; + + + /* Uniform selection of a valid disk */ + i = Rand_Int(0,n_valid_disks-1); + target_disk = valid_disks[i]; + + ori_disk_old = target_disk->prev; + ori_disk_young = target_disk->next; + ori_time = target_disk->time; + + t_min = target_disk->ldsk->prev->disk->time; + t_max = +INFINITY; + for(i=0;ildsk->n_next;++i) + if(target_disk->ldsk->next[i]->disk->time < t_max) + { + t_max = target_disk->ldsk->next[i]->disk->time; + ldsk_next = target_disk->ldsk->next[i]; + } + + t_max = t_max - SMALL; + t_min = t_min + SMALL; + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) new_glnL -= PHYREX_Lk_Range(ldsk_next->disk,target_disk->ldsk->prev->disk,tree); + + if(!(t_max > t_min)) + { + PhyML_Printf("\n. t_max: %g t_min: %g",t_max,t_min); + assert(t_max > t_min); + } + t = Uni()*(t_max - t_min) + t_min; + target_disk->time = t; + + PHYREX_Remove_Disk(target_disk); + PHYREX_Insert_Disk(target_disk,tree); + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Range(ldsk_next->disk,target_disk->ldsk->prev->disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + if(tree->eval_alnL == YES) new_alnL = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_rlnL = RATES_Lk_Rates(tree); + + ratio += (new_alnL - cur_alnL); + ratio += (new_glnL - cur_glnL); + ratio += (new_rlnL - cur_rlnL); + + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + /* printf("\n- Swap new_glnL: %f [%f] new_alnL: %f [%f] hr: %f u:%f alpha: %f",new_glnL,cur_glnL,new_alnL,cur_alnL,hr,u,alpha); */ + + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* printf("\n- Reject %f %f",target_disk->time,ori_time); */ + + PHYREX_Remove_Disk(target_disk); + + target_disk->time = ori_time; + target_disk->prev = ori_disk_old; + target_disk->next = ori_disk_young; + + PHYREX_Insert_Disk(target_disk,tree); + PHYREX_Update_Lindisk_List_Range(ldsk_next->disk,target_disk->ldsk->prev->disk,tree); + + tree->mmod->c_lnL = cur_glnL; + tree->c_lnL = cur_alnL; + tree->rates->c_lnL_rates = cur_rlnL; + } + else + { + /* printf("\n- Accept %f %f",target_disk->time,ori_time); */ + } + } + + Free(valid_disks); + +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +#ifdef PHYREX +void MCMC_PHYREX_Indel_Hit(t_tree *tree) +{ + int n_disks_cur, n_disks_new; + t_dsk *disk; + phydbl hr; + phydbl cur_lbda,new_lbda; + phydbl cur_mu,new_mu; + phydbl cur_rad,new_rad; + + + hr = 0.0; + new_lbda = tree->mmod->lbda; + cur_lbda = tree->mmod->lbda; + new_rad = tree->mmod->rad; + cur_rad = tree->mmod->rad; + new_mu = tree->mmod->mu; + cur_mu = tree->mmod->mu; + + /* new_lbda = cur_lbda * exp(1.0*(Uni()-.5)); */ + /* hr += log(new_lbda/cur_lbda); */ + + /* new_mu = cur_mu * exp(0.5*(Uni()-.5)); */ + /* hr += log(new_mu/cur_mu); */ + + /* new_rad = cur_rad * exp(0.5*(Uni()-.5)); */ + /* hr += log(new_rad/cur_rad); */ + + if(new_rad > tree->mmod->max_rad || new_rad < tree->mmod->min_rad) return; + if(new_mu > tree->mmod->max_mu || new_mu < tree->mmod->min_mu) return; + if(new_lbda > tree->mmod->max_lbda || new_lbda < tree->mmod->min_lbda) return; + + tree->mmod->lbda = new_lbda; + tree->mmod->mu = new_mu; + tree->mmod->rad = new_rad; + + + disk = tree->young_disk->prev; + n_disks_cur = 0; + do + { + if(disk->ldsk != NULL && disk->ldsk->n_next == 1) n_disks_cur++; + disk = disk->prev; + } + while(disk); + + n_disks_new = (int)Rpois(n_disks_cur+SMALL); + hr += Dpois(n_disks_cur,n_disks_new+SMALL,YES); + hr -= Dpois(n_disks_new,n_disks_cur+SMALL,YES); + + if(n_disks_new < n_disks_cur) + { + MCMC_PHYREX_Delete_Hit(hr, n_disks_cur - n_disks_new, cur_lbda, cur_rad, cur_mu, tree); + } + else + { + MCMC_PHYREX_Insert_Hit(hr, n_disks_new - n_disks_cur, cur_lbda, cur_rad, cur_mu, tree); + } + +} +#endif + + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Insert a disk with a new lineage displacement */ +#ifdef PHYREX +void MCMC_PHYREX_Insert_Hit(phydbl hr, int n_insert_disks, phydbl cur_lbda, phydbl cur_rad, phydbl cur_mu, t_tree *tree) +{ + t_dsk *disk,**new_disk,*young_disk,*old_disk; + t_ldsk **young_ldsk, **old_ldsk, **new_ldsk; + phydbl T,t; + phydbl cur_glnL, new_glnL; + phydbl u,alpha,ratio; + int i,j,*dir_old_young,n_valid_disks,err,num_prec_issue; + + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_indel_hit]++; + + if(n_insert_disks == 0) + { + tree->mmod->lbda = cur_lbda; + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + return; + } + + + disk = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + ratio = 0.0; + num_prec_issue = NO; + + disk = tree->young_disk->prev; + n_valid_disks = 0; + do + { + if(disk->ldsk != NULL && disk->ldsk->n_next == 1) n_valid_disks++; + disk = disk->prev; + } + while(disk && disk->prev); + + + new_disk = (t_dsk **)mCalloc(n_insert_disks,sizeof(t_dsk *)); + new_ldsk = (t_ldsk **)mCalloc(n_insert_disks,sizeof(t_ldsk *)); + old_ldsk = (t_ldsk **)mCalloc(n_insert_disks,sizeof(t_ldsk *)); + young_ldsk = (t_ldsk **)mCalloc(n_insert_disks,sizeof(t_ldsk *)); + dir_old_young = (int *)mCalloc(n_insert_disks,sizeof(int)); + + T = PHYREX_Tree_Height(tree); + + for(j=0;jyoung_disk->time-T) + T; + disk = tree->young_disk->prev; + while(disk && disk->time > t) disk = disk->prev; + + if(!(disk->time != t)) + { + PhyML_Printf("\n. Numerical precision issue in insert_hit"); + PhyML_Printf("\n. t=%g disk->time=%g diff=%g",t,disk->time,t-disk->time); + num_prec_issue = YES; + } + }while(num_prec_issue == YES); + + + /* Disks located just prior and after inserted disk */ + young_disk = disk->next; + assert(young_disk->n_ldsk_a); + + old_disk = disk; + assert(old_disk->n_ldsk_a); + + /* Make and initialize new disk */ + new_disk[j] = PHYREX_Make_Disk_Event(tree->mmod->n_dim,tree->n_otu); + PHYREX_Init_Disk_Event(new_disk[j],tree->mmod->n_dim,tree->mmod); + + /* Time of the new disk */ + new_disk[j]->time = t; + + /* Insert it */ + PHYREX_Insert_Disk(new_disk[j],tree); + + assert(new_disk[j]->next == young_disk); + assert(new_disk[j]->prev == old_disk); + + /* Which lineage is going to be hit ? */ + hr -= log(1./PHYREX_Number_Of_Outgoing_Ldsks(young_disk)); + + young_ldsk[j] = PHYREX_Random_Select_Outgoing_Ldsk(young_disk); + old_ldsk[j] = young_ldsk[j]->prev; + + if(old_ldsk[j]->disk->time > young_ldsk[j]->disk->time || + young_ldsk[j]->disk->time < new_disk[j]->time || + old_ldsk[j]->disk->time > new_disk[j]->time) + { + PhyML_Fprintf(stderr,"\n. young_disk->time: %f",young_disk->time); + PhyML_Fprintf(stderr,"\n. old_disk->time: %f",old_disk->time); + PhyML_Fprintf(stderr,"\n. young_ldsk->disk->time: %f",young_ldsk[j]->disk->time); + PhyML_Fprintf(stderr,"\n. old_ldsk->disk->time: %f",old_ldsk[j]->disk->time); + PhyML_Fprintf(stderr,"\n. new_disk->disk->time: %f",new_disk[j]->time); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + + /* Direction from old to young ldsk */ + dir_old_young[j] = PHYREX_Get_Next_Direction(young_ldsk[j],old_ldsk[j]); + assert(dir_old_young[j] != -1); + + /* Make and initialize new ldsk */ + new_ldsk[j] = PHYREX_Make_Lindisk_Node(tree->mmod->n_dim); + PHYREX_Init_Lindisk_Node(new_ldsk[j],new_disk[j],tree->mmod->n_dim); + PHYREX_Make_Lindisk_Next(new_ldsk[j]); + new_disk[j]->ldsk = new_ldsk[j]; + + + /* Connect it */ + new_ldsk[j]->prev = old_ldsk[j]; + new_ldsk[j]->next[0] = young_ldsk[j]; + young_ldsk[j]->prev = new_ldsk[j]; + old_ldsk[j]->next[dir_old_young[j]] = new_ldsk[j]; + + /* NOT OPTIMAL */ + /* Update ldsk_a arrays in the time interval affected by the insertion */ + PHYREX_Update_Lindisk_List_Range(new_ldsk[j]->disk,old_ldsk[j]->disk,tree); + + /* Sample position of the displaced ldsk */ + for(i=0;immod->n_dim;i++) + { + new_disk[j]->centr->lonlat[i] = Uni() * (tree->mmod->lim_up->lonlat[i]-tree->mmod->lim_do->lonlat[i])+tree->mmod->lim_do->lonlat[i]; + hr -= log(1./(tree->mmod->lim_up->lonlat[i]-tree->mmod->lim_do->lonlat[i])); + + err = NO; + new_ldsk[j]->coord->lonlat[i] = Rnorm_Trunc(new_disk[j]->centr->lonlat[i], + 1.0*tree->mmod->rad, + tree->mmod->lim_do->lonlat[i], + tree->mmod->lim_up->lonlat[i],&err); + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + hr -= Log_Dnorm_Trunc(new_ldsk[j]->coord->lonlat[i], + new_disk[j]->centr->lonlat[i], + 1.0*tree->mmod->rad, + tree->mmod->lim_do->lonlat[i], + tree->mmod->lim_up->lonlat[i],&err); + } + } + + T = PHYREX_Tree_Height(tree); + T = fabs(T-tree->young_disk->time); + + hr -= LnChoose(n_valid_disks+n_insert_disks,n_insert_disks); + hr -= n_insert_disks * log(1./T); + hr -= LnFact(n_insert_disks); + + if(tree->eval_glnL == YES) new_glnL = PHYREX_Lk(tree); + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + /* printf("\n- Insert hit %15f %15f %5d",new_glnL - cur_glnL, alpha, n_insert_disks); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* printf("+ Reject"); */ + + tree->mmod->lbda = cur_lbda; + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + + for(j=n_insert_disks-1;j>=0;j--) + { + old_ldsk[j]->next[dir_old_young[j]] = young_ldsk[j]; + young_ldsk[j]->prev = old_ldsk[j]; + + PHYREX_Remove_Disk(new_disk[j]); + } + + + PHYREX_Update_Lindisk_List(tree); + tree->mmod->c_lnL = cur_glnL; + + for(j=n_insert_disks-1;j>=0;j--) + { + Free_Disk(new_disk[j]); + Free_Ldisk(new_ldsk[j]); + } + } + else + { + /* printf("+ Accept"); */ + /* if(indel > 0) printf("\n. Accept"); */ + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_indel_hit]++; + } + + + Free(new_disk); + Free(new_ldsk); + Free(old_ldsk); + Free(young_ldsk); + Free(dir_old_young); + + +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Remove one or more disks with a lineage displacement */ +#ifdef PHYREX +void MCMC_PHYREX_Delete_Hit(phydbl hr, int n_delete_disks, phydbl cur_lbda, phydbl cur_rad, phydbl cur_mu, t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl cur_glnL,new_glnL,T; + t_dsk *disk,**target_disk,**valid_disks; + t_ldsk **target_ldsk,**old_ldsk,**young_ldsk; + int i,j,block,n_valid_disks,*dir_old_young,*permut,err; + + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_indel_hit]++; + + if(n_delete_disks == 0) + { + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + return; + } + + disk = NULL; + valid_disks = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + ratio = 0.0; + block = 100; + + if(tree->young_disk->next) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + disk = tree->young_disk->prev; + if(!disk->prev) + { + tree->mmod->lbda = cur_lbda; + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + return; + } + + n_valid_disks = 0; + do + { + /* Include only disks with displacement that are not coalescent events */ + if(disk->ldsk != NULL && disk->ldsk->n_next == 1) + { + if(!n_valid_disks) valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_valid_disks%block)) valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + valid_disks[n_valid_disks] = disk; + n_valid_disks++; + } + disk = disk->prev; + } + while(disk && disk->prev); + + if(!n_valid_disks || (n_valid_disks - n_delete_disks < 0)) + { + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + return; + } + + + target_disk = (t_dsk **)mCalloc(n_delete_disks,sizeof(t_dsk *)); + target_ldsk = (t_ldsk **)mCalloc(n_delete_disks,sizeof(t_ldsk *)); + old_ldsk = (t_ldsk **)mCalloc(n_delete_disks,sizeof(t_ldsk *)); + young_ldsk = (t_ldsk **)mCalloc(n_delete_disks,sizeof(t_ldsk *)); + dir_old_young = (int *)mCalloc(n_delete_disks,sizeof(int)); + + permut = Permutate(n_valid_disks); + + for(j=0;jldsk; + + assert(target_disk[j]->age_fixed == NO); + assert(target_ldsk[j] != NULL); + assert(target_ldsk[j]->n_next == 1); + + old_ldsk[j] = target_ldsk[j]->prev; + young_ldsk[j] = target_ldsk[j]->next[0]; + + dir_old_young[j] = PHYREX_Get_Next_Direction(young_ldsk[j],old_ldsk[j]); + assert(dir_old_young[j] != -1); + + + /* Part of the Hastings ratio corresponding to the probability of selecting */ + /* target_disk->ldsk->next[0] to be hit (reverse move) */ + hr += log(1./target_disk[j]->next->n_ldsk_a); + + /* Density for position of the displaced ldsk */ + for(i=0;immod->n_dim;i++) + { + hr += log(1./(tree->mmod->lim_up->lonlat[i]-tree->mmod->lim_do->lonlat[i])); + + hr += Log_Dnorm_Trunc(target_ldsk[j]->coord->lonlat[i], + target_disk[j]->centr->lonlat[i], + 1.0*tree->mmod->rad, + tree->mmod->lim_do->lonlat[i], + tree->mmod->lim_up->lonlat[i],&err); + } + + + /* New connections between old_ldsk and young_ldsk */ + old_ldsk[j]->next[dir_old_young[j]] = young_ldsk[j]; + young_ldsk[j]->prev = old_ldsk[j]; + + /* Remove target disk */ + PHYREX_Remove_Disk(target_disk[j]); + + /* Update ldsk_a arrays in the time interval affected by the deletion */ + PHYREX_Update_Lindisk_List_Range(young_ldsk[j]->disk,old_ldsk[j]->disk,tree); + } + + T = PHYREX_Tree_Height(tree); + T = fabs(T-tree->young_disk->time); + + hr += LnChoose(n_valid_disks,n_delete_disks); + hr += n_delete_disks * log(1./T); + hr += LnFact(n_delete_disks); + + Free(valid_disks); + + if(tree->eval_glnL == YES) new_glnL = PHYREX_Lk(tree); + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + /* printf("\n- Delete hit %15f %15f %5d",new_glnL - cur_glnL, alpha, n_delete_disks); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + tree->mmod->lbda = cur_lbda; + tree->mmod->rad = cur_rad; + tree->mmod->mu = cur_mu; + + for(j=n_delete_disks-1;j>=0;j--) + { + PHYREX_Insert_Disk(target_disk[j],tree); + old_ldsk[j]->next[dir_old_young[j]] = target_ldsk[j]; + young_ldsk[j]->prev = target_ldsk[j]; + } + + PHYREX_Update_Lindisk_List(tree); + + tree->mmod->c_lnL = cur_glnL; + } + else + { + for(j=0;jmcmc->acc_move[tree->mcmc->num_move_phyrex_indel_hit]++; + } + + + Free(target_disk); + Free(target_ldsk); + Free(old_ldsk); + Free(young_ldsk); + Free(dir_old_young); + Free(permut); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Prune_Regraft(t_tree *tree) +{ + phydbl u,alpha,ratio,hr; + phydbl cur_glnL, new_glnL; + phydbl cur_alnL, new_alnL; + phydbl cur_rlnL, new_rlnL; + t_dsk *disk,*regraft_disk,**valid_disks,*oldest_disk; + t_ldsk *prune_ldsk,*regraft_ldsk,*prune_ldsk_daughter,*cur_path,*new_path,*ldsk,*ldsk_dum,**valid_ldsks; + phydbl *prob_disks_prune,*prob_disks_regraft; + int i,block,n_valid_disks,num_regraft_disk,num_prune_disk,n_valid_ldsks; + phydbl max_dist, param_exp; + int cur_path_len; + int n_iter; + int cur_pos,new_pos; + phydbl sum; + + if(tree->mod->s_opt->opt_topo == NO) return; + + n_iter = 1+(int)(tree->n_otu/10); + + while(n_iter--) + { + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_spr]++; + + valid_ldsks = NULL; + valid_disks = NULL; + disk = NULL; + prob_disks_regraft = NULL; + prob_disks_prune = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + new_alnL = tree->c_lnL; + cur_alnL = tree->c_lnL; + new_rlnL = tree->rates->c_lnL_rates; + cur_rlnL = tree->rates->c_lnL_rates; + hr = 0.0; + ratio = 0.0; + block = 100; + cur_pos = -1; + new_pos = -1; + param_exp = 1.0; + num_regraft_disk = -1; + num_prune_disk = -1; + + if(tree->young_disk->next) assert(FALSE); + + /* Get a ldsk from which you can prune a lineage */ + disk = tree->young_disk->prev; + n_valid_ldsks = 0; + do + { + /* Include only disks with displacement that are coalescent events */ + if(disk->ldsk != NULL && disk->ldsk->n_next > 1) + { + /* Root has degree 2: don't pull any lineage */ + if(!(disk->prev == NULL && disk->ldsk->n_next == 2)) + { + if(!n_valid_ldsks) valid_ldsks = (t_ldsk **)mCalloc(disk->ldsk->n_next,sizeof(t_ldsk *)); + else valid_ldsks = (t_ldsk **)mRealloc(valid_ldsks,n_valid_ldsks+disk->ldsk->n_next,sizeof(t_ldsk *)); + for(i=0;ildsk->n_next;++i) + { + valid_ldsks[n_valid_ldsks] = disk->ldsk->next[i]; + n_valid_ldsks++; + } + } + } + disk = disk->prev; + } + while(disk); + + if(!n_valid_ldsks) return; + + prune_ldsk_daughter = valid_ldsks[Rand_Int(0,n_valid_ldsks-1)]; + prune_ldsk = prune_ldsk_daughter->prev; + hr -= log(1./(phydbl)(n_valid_ldsks)); + Free(valid_ldsks); + + /* prune_ldsk_daughter is the next coalescent event or tip node */ + while(prune_ldsk_daughter->n_next == 1) prune_ldsk_daughter = prune_ldsk_daughter->next[0]; + + + /* Get a ldsk to reattach the pruned lineage to */ + disk = tree->young_disk->prev; + n_valid_disks = 0; + do + { + /* Include only disks with displacement that are not younger + than prune_ldsk_daughter and different from prune_ldsk */ + if((disk->ldsk != NULL) && + (disk->ldsk->n_next >= 1) && + (disk->time < prune_ldsk_daughter->disk->time) && + (PHYREX_Is_On_Path(disk->ldsk,prune_ldsk_daughter,prune_ldsk) == NO)) + { + if(!n_valid_disks) + { + valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + prob_disks_prune = (phydbl *)mCalloc(block,sizeof(phydbl)); + } + else if(!(n_valid_disks%block)) + { + valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + prob_disks_prune = (phydbl *)mRealloc(prob_disks_prune,n_valid_disks+block,sizeof(phydbl)); + } + + valid_disks[n_valid_disks] = disk; + + prob_disks_prune[n_valid_disks] = PHYREX_Dist_Between_Two_Ldsk(disk->ldsk,prune_ldsk,tree); + + n_valid_disks++; + } + disk = disk->prev; + } + while(disk); + + assert(n_valid_disks); + + if(n_valid_disks > 1) + { + max_dist = -INFINITY; + for(i=0;i max_dist) max_dist = prob_disks_prune[i]; + + sum = 0.0; + for(i=0;ildsk; + + /* Prob of selecting this node as regraft site */ + hr -= log(prob_disks_prune[num_regraft_disk]); + } + + Free(prob_disks_prune); + Free(valid_disks); + + if(n_valid_disks == 1) return; + + oldest_disk = (regraft_ldsk->disk->time < prune_ldsk->disk->time) ? (regraft_ldsk->disk) : (prune_ldsk->disk); + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) new_glnL -= PHYREX_Lk_Range(prune_ldsk_daughter->disk,oldest_disk,tree); + + /* Prune and regraft */ + cur_path_len = PHYREX_Path_Len(prune_ldsk_daughter,prune_ldsk)-2; + + hr += PHYREX_Path_Logdensity(prune_ldsk_daughter,prune_ldsk,1.0*tree->mmod->rad,tree); + + new_path = PHYREX_Generate_Path(prune_ldsk_daughter,regraft_ldsk,cur_path_len,1.0*tree->mmod->rad,tree); + cur_path = PHYREX_Remove_Path(prune_ldsk_daughter,prune_ldsk,&cur_pos,tree); + new_pos = Rand_Int(0,regraft_ldsk->n_next); + hr -= log(1./(phydbl)(regraft_ldsk->n_next+1)); + hr += log(1./(phydbl)(prune_ldsk->n_next+1)); + PHYREX_Insert_Path(prune_ldsk_daughter,regraft_ldsk,new_path,new_pos,tree); + + hr -= PHYREX_Path_Logdensity(prune_ldsk_daughter,regraft_ldsk,1.0*tree->mmod->rad,tree); + + + PHYREX_Ldsk_To_Tree(tree); + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + RATES_Update_Cur_Bl(tree); + + assert(isinf(hr) == NO); + + PHYREX_Update_Lindisk_List(tree); + + /* Number of ldsk which can be pruned (reverse move) */ + if(regraft_disk->prev == NULL && regraft_ldsk->n_next == 3) // regraft_ldsk is root & went from 2 to 3 outgoing lineages + n_valid_ldsks+=3; + if(prune_ldsk->prev == NULL && prune_ldsk->n_next == 2) // prune_ldsk is root & went from 3 to 2 outgoing lineages + n_valid_ldsks-=3; + if(regraft_ldsk->n_next == 2) n_valid_ldsks += 2; + if(prune_ldsk->n_next == 1) n_valid_ldsks -= 2; + + assert(n_valid_ldsks > 0); + hr += log(1./(phydbl)(n_valid_ldsks)); + + + + + /* Get a ldsk to reattach the pruned lineage to (reverse move) */ + disk = tree->young_disk->prev; + n_valid_disks = 0; + do + { + /* Include only disks with displacement that are not younger + than prune_ldsk_daughter and different from prune_ldsk */ + if((disk->ldsk != NULL) && + (disk->ldsk->n_next >= 1) && + (disk->time < prune_ldsk_daughter->disk->time) && + (PHYREX_Is_On_Path(disk->ldsk,prune_ldsk_daughter,regraft_ldsk) == NO)) + { + if(!n_valid_disks) + { + valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + prob_disks_regraft = (phydbl *)mCalloc(block,sizeof(phydbl)); + } + else if(!(n_valid_disks%block)) + { + valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + prob_disks_regraft = (phydbl *)mRealloc(prob_disks_regraft,n_valid_disks+block,sizeof(phydbl)); + } + + valid_disks[n_valid_disks] = disk; + + prob_disks_regraft[n_valid_disks] = PHYREX_Dist_Between_Two_Ldsk(disk->ldsk,regraft_ldsk,tree); + + if(disk == prune_ldsk->disk) num_prune_disk = n_valid_disks; + + n_valid_disks++; + } + disk = disk->prev; + } + while(disk); + + max_dist = -INFINITY; + for(i=0;i max_dist) max_dist = prob_disks_regraft[i]; + + sum = 0.0; + for(i=0;i -1); + /* Prob of selecting this node as regraft site (reverse move) */ + hr += log(prob_disks_regraft[num_prune_disk]); + + Free(prob_disks_regraft); + Free(valid_disks); + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Range(prune_ldsk_daughter->disk,oldest_disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + if(tree->eval_alnL == YES) new_alnL = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_rlnL = RATES_Lk_Rates(tree); + + ratio += (new_alnL - cur_alnL); + ratio += (new_glnL - cur_glnL); + ratio += (new_rlnL - cur_rlnL); + + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* PhyML_Printf("\nYYY %12f %12f %4d %4d %12f %12f", */ + /* prune_ldsk_daughter->disk->time - prune_ldsk->disk->time, */ + /* prune_ldsk_daughter->disk->time - regraft_ldsk->disk->time, */ + /* cur_path_len, */ + /* new_path_len, */ + /* PHYREX_Dist_Between_Two_Ldsk(regraft_ldsk,prune_ldsk,tree), */ + /* alpha); */ + + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + /* printf("\n. %3d %3d alpha:%12f %3d",prune_ldsk->n_next+1,regraft_ldsk->n_next-1,alpha,new_n_coal); */ + /* PhyML_Printf("\n. new_glnL: %f cur_glnL: %f hr: %f alpha: %f",new_glnL,cur_glnL,hr,alpha); */ + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + new_path = PHYREX_Remove_Path(prune_ldsk_daughter,regraft_ldsk,&new_pos,tree); + PHYREX_Insert_Path(prune_ldsk_daughter,prune_ldsk,cur_path,cur_pos,tree); + + PHYREX_Ldsk_To_Tree(tree); + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + RATES_Fill_Lca_Table(tree); + RATES_Update_Cur_Bl(tree); + + + PHYREX_Update_Lindisk_List(tree); + tree->c_lnL = cur_alnL; + tree->mmod->c_lnL = cur_glnL; + tree->rates->c_lnL_rates = cur_rlnL; + + ldsk = new_path; + while(ldsk) + { + Free_Disk(ldsk->disk); + ldsk_dum = ldsk; + ldsk = ldsk->prev; + Free_Ldisk(ldsk_dum); + } + } + else + { + ldsk = cur_path; + while(ldsk) + { + Free_Disk(ldsk->disk); + ldsk_dum = ldsk; + ldsk = ldsk->prev; + Free_Ldisk(ldsk_dum); + } + + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_spr]++; + } + } +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Prune_Regraft_Local(t_tree *tree) +{ + phydbl u,alpha,ratio,hr; + phydbl cur_glnL, new_glnL; + phydbl cur_alnL, new_alnL; + phydbl cur_rlnL, new_rlnL; + t_dsk *disk,*regraft_disk,*oldest_disk,**valid_disks; + t_ldsk *prune_ldsk,*prune_ldsk_daughter,*regraft_ldsk,*cur_path,**valid_ldsks; + int i,block,n_valid_disks,n_valid_ldsks; + int n_iter; + int cur_pos,new_pos; + + if(tree->mod->s_opt->opt_topo == NO) return; + + n_iter = 1+(int)(tree->n_otu/10); + + while(n_iter--) + { + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_spr_local]++; + + valid_ldsks = NULL; + valid_disks = NULL; + disk = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + new_alnL = tree->c_lnL; + cur_alnL = tree->c_lnL; + new_rlnL = tree->rates->c_lnL_rates; + cur_rlnL = tree->rates->c_lnL_rates; + hr = 0.0; + ratio = 0.0; + block = 100; + cur_pos = -1; + new_pos = -1; + + if(tree->young_disk->next) assert(FALSE); + + /* Get a ldsk from which you can prune a lineage */ + disk = tree->young_disk->prev; + n_valid_ldsks = 0; + do + { + /* Include only disks with displacement that are coalescent events */ + if(disk->ldsk != NULL && disk->ldsk->n_next > 1) + { + /* Root has degree 2: don't pull any lineage */ + if(!(disk->prev == NULL && disk->ldsk->n_next == 2)) + { + if(!n_valid_ldsks) valid_ldsks = (t_ldsk **)mCalloc(disk->ldsk->n_next,sizeof(t_ldsk *)); + else valid_ldsks = (t_ldsk **)mRealloc(valid_ldsks,n_valid_ldsks+disk->ldsk->n_next,sizeof(t_ldsk *)); + for(i=0;ildsk->n_next;++i) + { + valid_ldsks[n_valid_ldsks] = disk->ldsk->next[i]; + n_valid_ldsks++; + } + } + } + disk = disk->prev; + } + while(disk); + + if(!n_valid_ldsks) return; + + prune_ldsk_daughter = valid_ldsks[Rand_Int(0,n_valid_ldsks-1)]; + prune_ldsk = prune_ldsk_daughter->prev; + hr -= log(1./(phydbl)(n_valid_ldsks)); + Free(valid_ldsks); + + + /* Get a ldsk to reattach the pruned lineage to */ + n_valid_disks = 0; + if(prune_ldsk->prev != NULL) + { + valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + valid_disks[0] = prune_ldsk->prev->disk; + n_valid_disks++; + } + + for(i=0;in_next;++i) + { + if(prune_ldsk->next[i] != prune_ldsk_daughter && + prune_ldsk->next[i]->n_next >= 1 && + prune_ldsk->next[i]->disk->time < prune_ldsk_daughter->disk->time) + { + if(n_valid_disks == 0) + { + valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + } + else + { + if(!(n_valid_disks%block)) + { + valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + } + } + + valid_disks[n_valid_disks] = prune_ldsk->next[i]->disk; + + n_valid_disks++; + } + } + + if(!n_valid_disks) return; + + regraft_disk = valid_disks[Rand_Int(0,n_valid_disks-1)]; + regraft_ldsk = regraft_disk->ldsk; + hr -= log(1./(phydbl)(n_valid_disks)); + Free(valid_disks); + + oldest_disk = (regraft_disk->time < prune_ldsk->disk->time) ? (regraft_disk) : (prune_ldsk->disk); + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) new_glnL -= PHYREX_Lk_Range(prune_ldsk_daughter->disk,oldest_disk,tree); + + /* Prune and regraft */ + cur_path = PHYREX_Remove_Path(prune_ldsk_daughter,prune_ldsk,&cur_pos,tree); + new_pos = Rand_Int(0,regraft_ldsk->n_next); + hr -= log(1./(phydbl)(regraft_ldsk->n_next+1)); + hr += log(1./(phydbl)(prune_ldsk->n_next+1)); + PHYREX_Insert_Path(prune_ldsk_daughter,regraft_ldsk,cur_path,new_pos,tree); + + PHYREX_Ldsk_To_Tree(tree); + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + RATES_Update_Cur_Bl(tree); + + assert(isinf(hr) == NO); + + PHYREX_Update_Lindisk_List_Range(prune_ldsk_daughter->disk,oldest_disk,tree); + + + /* Number of ldsk which one can be pruned (reverse move) */ + if(regraft_disk->prev == NULL && regraft_ldsk->n_next == 3) // regraft_ldsk is root & went from 2 to 3 outgoing lineages + n_valid_ldsks+=3; + if(prune_ldsk->prev == NULL && prune_ldsk->n_next == 2) // prune_ldsk is root & went from 3 to 2 outgoing lineages + n_valid_ldsks-=3; + if(regraft_ldsk->n_next == 2) n_valid_ldsks += 2; + if(prune_ldsk->n_next == 1) n_valid_ldsks -= 2; + + + assert(n_valid_ldsks > 0); + hr += log(1./(phydbl)(n_valid_ldsks)); + + + /* Get a ldsk to reattach the pruned lineage to (reverse move) */ + n_valid_disks = 0; + if(regraft_ldsk->prev != NULL) n_valid_disks++; + + for(i=0;in_next;++i) + { + if(regraft_ldsk->next[i] != prune_ldsk_daughter && + regraft_ldsk->next[i]->n_next >= 1 && + regraft_ldsk->next[i]->disk->time < prune_ldsk_daughter->disk->time) + { + n_valid_disks++; + } + } + + assert(n_valid_disks > 0); + hr += log(1./(phydbl)(n_valid_disks)); + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Range(prune_ldsk_daughter->disk,oldest_disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + if(tree->eval_alnL == YES) new_alnL = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_rlnL = RATES_Lk_Rates(tree); + + ratio += (new_alnL - cur_alnL); + ratio += (new_glnL - cur_glnL); + ratio += (new_rlnL - cur_rlnL); + + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* PhyML_Printf("\nZZZ %12f %12f %12f %12f", */ + /* prune_ldsk_daughter->disk->time - prune_ldsk->disk->time, */ + /* prune_ldsk_daughter->disk->time - regraft_ldsk->disk->time, */ + /* PHYREX_Dist_Between_Two_Ldsk(regraft_ldsk,prune_ldsk,tree), */ + /* alpha); */ + + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + /* printf("\n. %3d %3d alpha:%12f %3d",prune_ldsk->n_next+1,regraft_ldsk->n_next-1,alpha,new_n_coal); */ + /* PhyML_Printf("\n. new_glnL: %f cur_glnL: %f hr: %f alpha: %f",new_glnL,cur_glnL,hr,alpha); */ + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + cur_path = PHYREX_Remove_Path(prune_ldsk_daughter,regraft_ldsk,&new_pos,tree); + PHYREX_Insert_Path(prune_ldsk_daughter,prune_ldsk,cur_path,cur_pos,tree); + + PHYREX_Ldsk_To_Tree(tree); + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + RATES_Fill_Lca_Table(tree); + RATES_Update_Cur_Bl(tree); + + PHYREX_Update_Lindisk_List_Range(prune_ldsk_daughter->disk,oldest_disk,tree); + + tree->c_lnL = cur_alnL; + tree->mmod->c_lnL = cur_glnL; + tree->rates->c_lnL_rates = cur_rlnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_spr_local]++; + } + } +} + +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +#ifdef PHYREX +void MCMC_PHYREX_Lineage_Traj(t_tree *tree) +{ + phydbl u,alpha,ratio,hr; + phydbl cur_glnL, new_glnL; + t_dsk *disk,**valid_disks; + t_ldsk *old_ldsk,*young_ldsk,*cur_path,*new_path,*ldsk,*ldsk_dum; + int j,block,n_valid_disks; + int n_iter,cur_path_len,new_path_len; + int pos,*permut,dir_next; + phydbl area; + + n_iter = 0; + valid_disks = NULL; + disk = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + block = 100; + pos = -1; + dir_next = -1; + + area = 1.0; + for(j=0;jmmod->n_dim;++j) area *= (tree->mmod->lim_up->lonlat[j] - tree->mmod->lim_do->lonlat[j]); + + disk = tree->young_disk->prev; + n_valid_disks = 0; + do + { + if(disk->ldsk && disk->ldsk->n_next >= 2) + { + if(!n_valid_disks) valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_valid_disks%block)) valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + valid_disks[n_valid_disks] = disk; + n_valid_disks++; + } + disk = disk->prev; + } + while(disk); + + if(!n_valid_disks) return; + + permut = Permutate(n_valid_disks); + n_iter = 1+(int)(0.1*n_valid_disks); + + for(j=0;jmcmc->run_move[tree->mcmc->num_move_phyrex_traj]++; + + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + dir_next = -1; + + old_ldsk = valid_disks[permut[Rand_Int(0,n_valid_disks-1)]]->ldsk; + assert(old_ldsk != NULL); + + dir_next = Rand_Int(0,old_ldsk->n_next-1); + young_ldsk = old_ldsk->next[dir_next]; + while(young_ldsk->n_next == 1) young_ldsk = young_ldsk->next[0]; + + + /* dt = fabs(young_ldsk->disk->time - old_ldsk->disk->time); */ + + assert(young_ldsk != NULL); + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) new_glnL -= PHYREX_Lk_Range(young_ldsk->disk,old_ldsk->disk,tree); + + /* phydbl dist = Euclidean_Dist(young_ldsk->coord,old_ldsk->coord); */ + cur_path_len = PHYREX_Path_Len(young_ldsk,old_ldsk)-2; + + /* new_path_len = Rpois(dt * 2. * PI * tree->mmod->lbda * tree->mmod->mu * pow(tree->mmod->rad,2) / area); */ + /* new_path_len = Rpois(cur_path_len+0.01); // To be avoided as create non-irreducible markov chain when new_path_len = 0 (since Pr(cur_path_len|new_path_len)=0) */ + /* new_path_len = Rpois((int)(pow(dist,2)/(4.*pow(tree->mmod->rad,2)))+0.01); */ + + /* hr -= Dpois(new_path_len,dt * 2.* PI * tree->mmod->lbda * tree->mmod->mu * pow(tree->mmod->rad,2) / area,YES); */ + /* hr += Dpois(cur_path_len,dt * 2.* PI * tree->mmod->lbda * tree->mmod->mu * pow(tree->mmod->rad,2) / area,YES); */ + /* hr -= Dpois(new_path_len,cur_path_len+0.01,YES); */ + /* hr += Dpois(cur_path_len,new_path_len+0.01,YES); */ + /* hr -= Dpois(new_path_len,(int)(pow(dist,2)/(4.*pow(tree->mmod->rad,2)))+0.01,YES); */ + /* hr += Dpois(cur_path_len,(int)(pow(dist,2)/(4.*pow(tree->mmod->rad,2)))+0.01,YES); */ + + /* hr -= (new_path_len) * log(1./dt); */ + /* hr += (cur_path_len) * log(1./dt); */ + + /* hr -= LnFact(new_path_len); */ + /* hr += LnFact(cur_path_len); */ + + new_path_len = cur_path_len; + + hr += PHYREX_Path_Logdensity(young_ldsk,old_ldsk,1.0*tree->mmod->rad,tree); + + new_path = PHYREX_Generate_Path(young_ldsk,old_ldsk,new_path_len,1.0*tree->mmod->rad,tree); + cur_path = PHYREX_Remove_Path(young_ldsk,old_ldsk,&pos,tree); + PHYREX_Insert_Path(young_ldsk,old_ldsk,new_path,pos,tree); + + hr -= PHYREX_Path_Logdensity(young_ldsk,old_ldsk,1.0*tree->mmod->rad,tree); + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Range(young_ldsk->disk,old_ldsk->disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* PhyML_Printf("\nXXX %12f %4d %4d %12f %12f", */ + /* young_ldsk->disk->time - old_ldsk->disk->time, */ + /* cur_path_len,new_path_len,alpha,Euclidean_Dist(young_ldsk->coord,old_ldsk->coord)); */ + + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + + u = Uni(); + + if(u > alpha) /* Reject */ + { + new_path = PHYREX_Remove_Path(young_ldsk,old_ldsk,&pos,tree); + PHYREX_Insert_Path(young_ldsk,old_ldsk,cur_path,pos,tree); + + PHYREX_Update_Lindisk_List(tree); + tree->mmod->c_lnL = cur_glnL; + + ldsk = new_path; + while(ldsk) + { + Free_Disk(ldsk->disk); + ldsk_dum = ldsk; + ldsk = ldsk->prev; + Free_Ldisk(ldsk_dum); + } + } + else + { + ldsk = cur_path; + while(ldsk) + { + Free_Disk(ldsk->disk); + ldsk_dum = ldsk; + ldsk = ldsk->prev; + Free_Ldisk(ldsk_dum); + } + + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_traj]++; + } + + } + + Free(valid_disks); + Free(permut); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Disk_Multi(t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl cur_glnL, new_glnL, hr; + t_dsk *disk,**target_disk,**all_disks; + int i,j,block,n_all_disks,n_move_disks,*permut; + int err; + + disk = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + block = 100; + all_disks = NULL; + + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_disk_multi]++; + + disk = tree->young_disk->prev; + n_all_disks = 0; + do + { + if(disk->age_fixed == NO) + { + if(!n_all_disks) all_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_all_disks%block)) all_disks = (t_dsk **)mRealloc(all_disks,n_all_disks+block,sizeof(t_dsk *)); + all_disks[n_all_disks] = disk; + n_all_disks++; + } + + disk = disk->prev; + } + while(disk); + + if(!n_all_disks) return; + + target_disk = (t_dsk **)mCalloc(n_all_disks,sizeof(t_dsk *)); + + /* n_move_disks = Rand_Int(1,1+(int)(n_all_disks/10)); */ + /* n_move_disks = MIN(10,(int)(1.+0.1*n_all_disks)); */ + n_move_disks = (int)(1+n_all_disks/20); + + permut = Permutate(n_all_disks); + + for(i=0;icentr); + + if(target_disk[i]->ldsk != NULL) + { + for(j=0;jmmod->n_dim;j++) + { + err = NO; + target_disk[i]->centr->lonlat[j] = + Rnorm_Trunc(target_disk[i]->centr->lonlat[j], + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + hr -= Log_Dnorm_Trunc(target_disk[i]->centr->lonlat[j], + target_disk[i]->centr->cpy->lonlat[j], + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + hr += Log_Dnorm_Trunc(target_disk[i]->centr->cpy->lonlat[j], + target_disk[i]->centr->lonlat[j], + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + } + } + else + { + for(j=0;jmmod->n_dim;j++) + { + err = NO; + target_disk[i]->centr->lonlat[j] = + Rnorm_Trunc(target_disk[i]->centr->lonlat[j], + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + hr -= Log_Dnorm_Trunc(target_disk[i]->centr->lonlat[j], + target_disk[i]->centr->cpy->lonlat[j], + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + hr += Log_Dnorm_Trunc(target_disk[i]->centr->cpy->lonlat[j], + target_disk[i]->centr->lonlat[j], + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + } + } + } + + Free(permut); + + if(tree->eval_glnL == YES) + { + new_glnL = PHYREX_Lk(tree); + } + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + /* printf("\n- Delete new_glnL: %f [%f] hr: %f u:%f alpha: %f",new_glnL,cur_glnL,hr,u,alpha); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* printf("- Reject"); */ + + for(i=0;icentr); + + tree->mmod->c_lnL = cur_glnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_disk_multi]++; + } + + + Free(all_disks); + Free(target_disk); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Move ldsk on landscape */ +#ifdef PHYREX +void MCMC_PHYREX_Ldsk_Multi(t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl cur_glnL,new_glnL,hr,c; + t_dsk *disk,**target_disk,**all_disks; + int i,j,block,n_all_disks,n_move_ldsk,*permut; + int err; + + disk = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + block = 100; + all_disks = NULL; + c = -1.; + + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_ldsk_multi]++; + + if(tree->young_disk->next) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + disk = tree->young_disk->prev; + n_all_disks = 0; + do + { + if(disk->ldsk != NULL && (disk->ldsk->nd != NULL && disk->ldsk->nd->tax == NO)) + { + if(!n_all_disks) all_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_all_disks%block)) all_disks = (t_dsk **)mRealloc(all_disks,n_all_disks+block,sizeof(t_dsk *)); + all_disks[n_all_disks] = disk; + n_all_disks++; + } + disk = disk->prev; + } + while(disk); + + if(!n_all_disks) return; + + n_move_ldsk = (int)(1+n_all_disks/20); + + target_disk = (t_dsk **)mCalloc(n_all_disks,sizeof(t_dsk *)); + + permut = Permutate(n_all_disks); + + for(i=0;ildsk->coord); + + for(j=0;jmmod->n_dim;j++) + { + /* c: center; o: pos of direct ldsk ancestor */ + /* c = target_disk[i]->centr->lonlat[j]; */ + c = target_disk[i]->ldsk->coord->lonlat[j]; + + err = NO; + target_disk[i]->ldsk->coord->lonlat[j] = + Rnorm_Trunc(c, + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + hr -= Log_Dnorm_Trunc(target_disk[i]->ldsk->coord->lonlat[j], + c, + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + /* hr += Log_Dnorm_Trunc(target_disk[i]->ldsk->coord->cpy->lonlat[j], */ + /* c, */ + /* 1.*tree->mmod->rad, */ + /* tree->mmod->lim_do->lonlat[j], */ + /* tree->mmod->lim_up->lonlat[j],&err); */ + hr += Log_Dnorm_Trunc(c, + target_disk[i]->ldsk->coord->lonlat[j], + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + } + } + + Free(permut); + + if(tree->eval_glnL == YES) new_glnL = PHYREX_Lk(tree); + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + /* printf("\n- Move_ldsk %15f",new_glnL-cur_glnL); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* printf("- Reject"); */ + + for(i=0;ildsk->coord); + + tree->mmod->c_lnL = cur_glnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_ldsk_multi]++; + } + + + Free(all_disks); + Free(target_disk); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Ldsk_And_Disk(t_tree *tree) +{ + phydbl u,alpha,ratio; + phydbl cur_glnL, new_glnL, hr; + phydbl cur_rad,new_rad; + t_dsk *disk,**target_disk,**all_disks; + int i,j,block,n_all_disks,n_move_ldsk,*permut; + int err; + + disk = NULL; + new_glnL = tree->mmod->c_lnL; + cur_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + block = 100; + all_disks = NULL; + cur_rad = tree->mmod->rad; + new_rad = tree->mmod->rad; + + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_ldsk_and_disk]++; + + if(tree->young_disk->next) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + disk = tree->young_disk->prev; + n_all_disks = 0; + do + { + if(disk->ldsk != NULL && disk->ldsk->n_next >= 1 && (disk->ldsk->nd != NULL && disk->ldsk->nd->tax == NO)) + { + if(!n_all_disks) all_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_all_disks%block)) all_disks = (t_dsk **)mRealloc(all_disks,n_all_disks+block,sizeof(t_dsk *)); + all_disks[n_all_disks] = disk; + n_all_disks++; + } + disk = disk->prev; + } + while(disk); + + if(!n_all_disks) return; + + n_move_ldsk = (int)(1+n_all_disks/20); + /* n_move_ldsk = n_all_disks; */ + + target_disk = (t_dsk **)mCalloc(n_all_disks,sizeof(t_dsk *)); + + permut = Permutate(n_all_disks); + + + new_rad = cur_rad * exp(0.5*(Uni()-.5)); + hr += log(new_rad/cur_rad); + + + for(i=0;ildsk->coord); + PHYREX_Store_Geo_Coord(target_disk[i]->centr); + + for(j=0;jmmod->n_dim;j++) + { + err = NO; + + target_disk[i]->centr->lonlat[j] = + Rnorm_Trunc(target_disk[i]->ldsk->coord->lonlat[j], + 1.*new_rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + target_disk[i]->ldsk->coord->lonlat[j] = + Rnorm_Trunc(target_disk[i]->centr->lonlat[j], + 1.*new_rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + + hr -= Log_Dnorm_Trunc(target_disk[i]->centr->lonlat[j], + target_disk[i]->ldsk->coord->cpy->lonlat[j], + 1.*new_rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + hr += Log_Dnorm_Trunc(target_disk[i]->centr->cpy->lonlat[j], + target_disk[i]->ldsk->coord->lonlat[j], + 1.*new_rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + hr -= Log_Dnorm_Trunc(target_disk[i]->ldsk->coord->lonlat[j], + target_disk[i]->centr->lonlat[j], + 1.*new_rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + hr += Log_Dnorm_Trunc(target_disk[i]->ldsk->coord->cpy->lonlat[j], + target_disk[i]->centr->cpy->lonlat[j], + 1.*new_rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + } + } + + + Free(permut); + + if(tree->eval_glnL == YES) new_glnL = PHYREX_Lk(tree); + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + /* printf("\n- Move_ldsk %15f",new_glnL-cur_glnL); */ + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + /* printf("- Reject"); */ + for(i=0;ildsk->coord); + for(i=0;icentr); + + tree->mmod->rad = cur_rad; + tree->mmod->c_lnL = cur_glnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_ldsk_and_disk]++; + } + + Free(all_disks); + Free(target_disk); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Ldsk_Given_Disk(t_tree *tree) +{ + phydbl u,alpha,ratio,hr,c; + phydbl cur_glnL, new_glnL; + phydbl K; + t_dsk *disk,**all_disks; + int i,j,err,n_all_disks,block,n_move_ldsk,*permut; + + block = 100; + all_disks = NULL; + n_all_disks = 0; + c = -1.; + K = tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_ldsk_given_disk]; + + disk = tree->young_disk->prev; + do + { + if(disk->ldsk != NULL) + { + if(!n_all_disks) all_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_all_disks%block)) all_disks = (t_dsk **)mRealloc(all_disks,n_all_disks+block,sizeof(t_dsk *)); + all_disks[n_all_disks] = disk; + n_all_disks++; + } + disk = disk->prev; + } + while(disk); + + if(!n_all_disks) return; + + /* n_move_ldsk = Rand_Int(1,1+(int)(n_all_disks/5)); */ + /* n_move_ldsk = MIN(10,(int)(1.+0.1*n_all_disks)); */ + /* n_move_ldsk = 1+(int)(n_all_disks/2); */ + n_move_ldsk = n_all_disks; + + permut = Permutate(n_all_disks); + cur_glnL = tree->mmod->c_lnL; + new_glnL = tree->mmod->c_lnL; + for(i=0;imcmc->run_move[tree->mcmc->num_move_phyrex_ldsk_given_disk]++; + + disk = all_disks[permut[i]]; + + hr = 0.0; + ratio = 0.0; + + PHYREX_Store_Geo_Coord(disk->ldsk->coord); + + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) + { + if(disk->ldsk->prev != NULL) new_glnL -= PHYREX_Lk_Range(disk,disk->ldsk->prev->disk,tree); + else new_glnL -= PHYREX_Lk_Core(disk,tree); + } + + for(j=0;jmmod->n_dim;j++) + { + c = disk->centr->lonlat[j]; + + err = NO; + disk->ldsk->coord->lonlat[j] = + Rnorm_Trunc(c, + K*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + hr -= Log_Dnorm_Trunc(disk->ldsk->coord->lonlat[j], + c, + K*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + hr += Log_Dnorm_Trunc(disk->ldsk->coord->cpy->lonlat[j], + c, + K*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + } + + if(tree->eval_glnL == YES) + { + if(disk->ldsk->prev != NULL) new_glnL += PHYREX_Lk_Range(disk,disk->ldsk->prev->disk,tree); + else new_glnL += PHYREX_Lk_Core(disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + PHYREX_Restore_Geo_Coord(disk->ldsk->coord); + tree->mmod->c_lnL = cur_glnL; + } + else + { + cur_glnL = new_glnL; + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_ldsk_given_disk]++; + } + } + + Free(permut); + Free(all_disks); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Disk_Given_Ldsk(t_tree *tree) +{ + phydbl u,alpha,ratio,hr; + phydbl cur_glnL, new_glnL; + t_dsk *disk,**all_disks; + int i,j,n_all_disks,block,n_move_ldsk,*permut; + + block = 100; + all_disks = NULL; + n_all_disks = 0; + + + disk = tree->young_disk->prev; + do + { + if(!n_all_disks) all_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_all_disks%block)) all_disks = (t_dsk **)mRealloc(all_disks,n_all_disks+block,sizeof(t_dsk *)); + all_disks[n_all_disks] = disk; + n_all_disks++; + disk = disk->prev; + } + while(disk); + + if(!n_all_disks) return; + + /* n_move_ldsk = Rand_Int(1,1+(int)(n_all_disks/10)); */ + /* n_move_ldsk = MIN(10,(int)(1+0.1*n_all_disks)); */ + /* n_move_ldsk = (int)(1+n_all_disks/2); */ + n_move_ldsk = n_all_disks; + + permut = Permutate(n_all_disks); + + + for(i=0;imcmc->run_move[tree->mcmc->num_move_phyrex_disk_given_ldsk]++; + + disk = all_disks[permut[i]]; + + hr = 0.0; + ratio = 0.0; + cur_glnL = tree->mmod->c_lnL; + new_glnL = tree->mmod->c_lnL; + + if(tree->eval_glnL == YES) new_glnL -= PHYREX_Lk_Core(disk,tree); + + PHYREX_Store_Geo_Coord(disk->centr); + + for(j=0;jmmod->n_dim;j++) + { + /* if(disk->ldsk == NULL) */ + disk->centr->lonlat[j] = Uni()*(tree->mmod->lim_up->lonlat[j]-tree->mmod->lim_do->lonlat[j])+tree->mmod->lim_do->lonlat[j]; + + /* else */ + /* { */ + /* /\* c: center; o: pos of direct ldsk ancestor *\/ */ + /* c = disk->ldsk->coord->lonlat[j]; */ + + /* err = NO; */ + /* disk->centr->lonlat[j] = */ + /* Rnorm_Trunc(c, */ + /* 2.*tree->mmod->rad, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[j],&err); */ + + /* if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); */ + + /* hr -= Log_Dnorm_Trunc(disk->centr->lonlat[j], */ + /* c, */ + /* 2.*tree->mmod->rad, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[j],&err); */ + + /* hr += Log_Dnorm_Trunc(disk->centr->cpy->lonlat[j], */ + /* c, */ + /* 2.*tree->mmod->rad, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[j],&err); */ + /* } */ + } + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Core(disk,tree); + tree->mmod->c_lnL = new_glnL; + } + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + PHYREX_Restore_Geo_Coord(disk->centr); + tree->mmod->c_lnL = cur_glnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_disk_given_ldsk]++; + } + } + + Free(permut); + Free(all_disks); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Indel_Hit_Serial(t_tree *tree) +{ + t_dsk *disk,*new_disk,*target_disk,*young_disk,*old_disk,**valid_disks; + t_ldsk *young_ldsk, *old_ldsk, *new_ldsk; + int i,j,n_trials,dir_old_young,err,block; + phydbl ratio, u, alpha, hr, type; + phydbl cur_glnL, new_glnL; + phydbl T,t,pindel; + int n_valid_disks,num_prec_issue; + + cur_glnL = tree->mmod->c_lnL; + new_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + type = -1.0; + n_trials = 1 + (int)(0.1*PHYREX_Total_Number_Of_Intervals(tree)); + T = PHYREX_Tree_Height(tree); + pindel = 0.5; + block = 50; + num_prec_issue = NO; + + for(i=0;imcmc->run_move[tree->mcmc->num_move_phyrex_indel_hit_serial]++; + + cur_glnL = tree->mmod->c_lnL; + new_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + + type = Uni(); + + if(type < pindel) /* Insert */ + { + do + { + num_prec_issue = NO; + t = Uni()*(tree->young_disk->time-T) + T; + disk = tree->young_disk->prev; + while(disk && disk->time > t) disk = disk->prev; + + if(!(disk->time != t)) + { + PhyML_Printf("\n. Numerical precision issue in indel_hit_serial"); + PhyML_Printf("\n. t=%g disk->time=%g",t,disk->time); + num_prec_issue = YES; + } + }while(num_prec_issue == YES); + + assert(disk->next); + + hr -= log(1./(tree->young_disk->time-T)); + + young_disk = disk->next; + assert(young_disk->n_ldsk_a); + + old_disk = disk; + assert(old_disk->n_ldsk_a); + + new_disk = PHYREX_Make_Disk_Event(tree->mmod->n_dim,tree->n_otu); + PHYREX_Init_Disk_Event(new_disk,tree->mmod->n_dim,tree->mmod); + new_disk->time = t; + + /* Which lineage is going to be hit ? */ + hr -= log(1./PHYREX_Number_Of_Outgoing_Ldsks(young_disk)); + + /* young_ldsk = old_disk->ldsk_a[hit_ldsk_idx]; */ + young_ldsk = PHYREX_Random_Select_Outgoing_Ldsk(young_disk); + old_ldsk = young_ldsk->prev; + + assert(young_disk != old_ldsk->disk); + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) new_glnL -= PHYREX_Lk_Range(young_ldsk->disk,old_ldsk->disk,tree); + + /* Direction from old to young ldsk */ + dir_old_young = PHYREX_Get_Next_Direction(young_ldsk,old_ldsk); + assert(dir_old_young != -1); + + /* Make and initialize new ldsk */ + new_ldsk = PHYREX_Make_Lindisk_Node(tree->mmod->n_dim); + PHYREX_Init_Lindisk_Node(new_ldsk,new_disk,tree->mmod->n_dim); + PHYREX_Make_Lindisk_Next(new_ldsk); + new_disk->ldsk = new_ldsk; + + /* Connect it */ + new_ldsk->prev = old_ldsk; + new_ldsk->next[0] = young_ldsk; + young_ldsk->prev = new_ldsk; + old_ldsk->next[dir_old_young] = new_ldsk; + + /* Insert disk */ + PHYREX_Insert_Disk(new_disk,tree); + + assert(new_disk->next == young_disk); + assert(new_disk->prev == old_disk); + + for(j=0;jmmod->n_dim;j++) + { + new_disk->centr->lonlat[j] = Uni()*(tree->mmod->lim_up->lonlat[j]-tree->mmod->lim_do->lonlat[j])+tree->mmod->lim_do->lonlat[j]; + hr -= log(1./(tree->mmod->lim_up->lonlat[j]-tree->mmod->lim_do->lonlat[j])); + + err = NO; + new_ldsk->coord->lonlat[j] = Rnorm_Trunc(new_disk->centr->lonlat[j], + 1.0*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + hr -= Log_Dnorm_Trunc(new_ldsk->coord->lonlat[j], + new_disk->centr->lonlat[j], + 1.0*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + } + + + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Range(young_ldsk->disk,old_ldsk->disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + + n_valid_disks = 0; + disk = tree->young_disk; + while(disk->prev) + { + if(disk->ldsk && disk->ldsk->n_next == 1) n_valid_disks++; + disk = disk->prev; + } + + assert(n_valid_disks); + hr += log(1./n_valid_disks); + + ratio = (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* PhyML_Printf("\n+ new_glnL: %f cur_glnL: %f hr: %f alpha: %f",new_glnL,cur_glnL,hr,alpha); */ + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + old_ldsk->next[dir_old_young] = young_ldsk; + young_ldsk->prev = old_ldsk; + + PHYREX_Remove_Disk(new_disk); + + assert(old_disk->next == young_disk); + assert(young_disk->prev == old_disk); + + PHYREX_Lk_Range(young_ldsk->disk,old_ldsk->disk,tree); + tree->mmod->c_lnL = cur_glnL; + /* PHYREX_Lk(tree); */ + + Free_Disk(new_disk); + Free_Ldisk(new_ldsk); + + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_indel_hit_serial]++; + } + } + + else /* Remove hit */ + + { + + disk = tree->young_disk->prev; + valid_disks = NULL; + n_valid_disks = 0; + do + { + if(disk->ldsk && disk->ldsk->n_next == 1) + { + if(!n_valid_disks) valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_valid_disks%block)) valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + valid_disks[n_valid_disks] = disk; + n_valid_disks++; + } + disk = disk->prev; + } + while(disk); + + if(n_valid_disks == 0) continue; + hr -= log(1./n_valid_disks); + + target_disk = valid_disks[Rand_Int(0,n_valid_disks-1)]; + Free(valid_disks); + + young_disk = target_disk->next; + old_disk = target_disk->prev; + + assert(target_disk->age_fixed == NO); + + old_ldsk = target_disk->ldsk->prev; + young_ldsk = target_disk->ldsk->next[0]; + + dir_old_young = PHYREX_Get_Next_Direction(target_disk->ldsk,old_ldsk); + assert(dir_old_young != -1); + + /* Part of the Hastings ratio corresponding to the probability of selecting */ + /* one of target_disk->n_ldsk_a to be hit (reverse move) */ + hr += log(1./target_disk->next->n_ldsk_a); + + + /* Density for position of the displaced ldsk */ + for(j=0;jmmod->n_dim;j++) + { + hr += log(1./(tree->mmod->lim_up->lonlat[j]-tree->mmod->lim_do->lonlat[j])); + + hr += Log_Dnorm_Trunc(target_disk->ldsk->coord->lonlat[j], + target_disk->centr->lonlat[j], + 1.0*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + } + + + assert(target_disk->next); + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) new_glnL -= PHYREX_Lk_Range(target_disk->next,target_disk->ldsk->prev->disk,tree); + + /* New connections between old_ldsk and young_ldsk */ + old_ldsk->next[dir_old_young] = young_ldsk; + young_ldsk->prev = old_ldsk; + + hr += log(1./(tree->young_disk->time-T)); + + PHYREX_Remove_Disk(target_disk); + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Range(target_disk->next,target_disk->ldsk->prev->disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + + ratio = (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* PhyML_Printf("\n- new_glnL: %f cur_glnL: %f hr: %f alpha: %f target->time: %f",new_glnL,cur_glnL,hr,alpha,target_disk->time); */ + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + PHYREX_Insert_Disk(target_disk,tree); + + assert(target_disk->next == young_disk); + assert(target_disk->prev == old_disk); + + old_ldsk->next[dir_old_young] = target_disk->ldsk; + young_ldsk->prev = target_disk->ldsk; + + PHYREX_Lk_Range(target_disk->next,target_disk->ldsk->prev->disk,tree); + tree->mmod->c_lnL = cur_glnL; + /* PHYREX_Lk(tree); */ + } + else + { + Free_Ldisk(target_disk->ldsk); + Free_Disk(target_disk); + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_indel_hit_serial]++; + } + } + } + +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Indel_Disk_Serial(t_tree *tree) +{ + t_dsk *disk,*new_disk,*target_disk,**valid_disks,*young_disk,*old_disk; + int i,j,n_trials,n_valid_disks,block,num_prec_issue; + phydbl ratio, u, alpha, hr, type; + phydbl cur_glnL, new_glnL; + phydbl log_lk_centr; + phydbl T,t,pindel; + + cur_glnL = tree->mmod->c_lnL; + new_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + type = -1.0; + n_trials = (int)(1.+0.1*PHYREX_Total_Number_Of_Intervals(tree)); + T = PHYREX_Tree_Height(tree); + pindel = 0.5; + disk = NULL; + new_disk = NULL; + target_disk = NULL; + young_disk = NULL; + old_disk = NULL; + block = 50; + num_prec_issue = NO; + disk = NULL; + + log_lk_centr = 0.0; + for(j=0;jmmod->n_dim;j++) log_lk_centr += log(1./(tree->mmod->lim_up->lonlat[j]-tree->mmod->lim_do->lonlat[j])); + + for(i=0;imcmc->run_move[tree->mcmc->num_move_phyrex_indel_disk_serial]++; + + cur_glnL = tree->mmod->c_lnL; + new_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + + type = Uni(); + + if(type < pindel) /* Insert */ + { + do + { + num_prec_issue = NO; + t = Uni()*(tree->young_disk->time-T) + T; + disk = tree->young_disk->prev; + while(disk && disk->time > t) disk = disk->prev; + + if(!(disk->time != t)) + { + PhyML_Printf("\n. Numerical precision issue in indel_disk_serial"); + PhyML_Printf("\n. t=%g disk->time=%g diff=%d",t,disk->time,t-disk->time); + num_prec_issue = YES; + } + }while(num_prec_issue == YES); + + young_disk = disk->next; + old_disk = disk; + + assert(disk->next); + + hr -= log(1./(tree->young_disk->time-T)); + hr -= log_lk_centr; + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) new_glnL -= PHYREX_Lk_Range(young_disk,old_disk,tree); + + new_disk = PHYREX_Make_Disk_Event(tree->mmod->n_dim,tree->n_otu); + PHYREX_Init_Disk_Event(new_disk,tree->mmod->n_dim,tree->mmod); + new_disk->time = t; + PHYREX_Insert_Disk(new_disk,tree); + + assert(new_disk->next == young_disk); + assert(new_disk->prev == old_disk); + + for(j=0;jmmod->n_dim;j++) new_disk->centr->lonlat[j] = Uni()*(tree->mmod->lim_up->lonlat[j]-tree->mmod->lim_do->lonlat[j])+tree->mmod->lim_do->lonlat[j]; + + n_valid_disks = 0; + disk = tree->young_disk->prev; + do + { + if(!disk->ldsk && disk->age_fixed == NO) n_valid_disks++; + disk = disk->prev; + } + while(disk); + + assert(n_valid_disks); + hr += log(1./n_valid_disks); + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Range(young_disk,old_disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + ratio = (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + PHYREX_Remove_Disk(new_disk); + Free_Disk(new_disk); + tree->mmod->c_lnL = cur_glnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_indel_disk_serial]++; + } + } + else /* Remove disk */ + { + disk = tree->young_disk->prev; + valid_disks = NULL; + n_valid_disks = 0; + do + { + if(!disk->ldsk && disk->age_fixed == NO) + { + if(!n_valid_disks) valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_valid_disks%block)) valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + valid_disks[n_valid_disks] = disk; + n_valid_disks++; + } + disk = disk->prev; + } + while(disk); + + if(n_valid_disks == 0) continue; + + assert(n_valid_disks); + hr -= log(1./n_valid_disks); + + target_disk = valid_disks[Rand_Int(0,n_valid_disks-1)]; + Free(valid_disks); + + hr += log(1./(tree->young_disk->time-T)); + hr += log_lk_centr; + + assert(target_disk->next->prev); + + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) new_glnL -= PHYREX_Lk_Range(target_disk->next,target_disk->prev,tree); + + PHYREX_Remove_Disk(target_disk); + assert(target_disk->next->prev); + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Range(target_disk->next,target_disk->prev,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + ratio = (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + PHYREX_Insert_Disk(target_disk,tree); + tree->mmod->c_lnL = cur_glnL; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_indel_disk_serial]++; + Free_Disk(target_disk); + } + } + } +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// Add or remove hit but leave corresponding disk unchanged +#ifdef PHYREX +void MCMC_PHYREX_Add_Remove_Jump(t_tree *tree) +{ + t_dsk *disk,*target_disk,**valid_disks; + int i,j,n_trials,n_valid_disks,block,err; + phydbl ratio, u, alpha, hr; + phydbl cur_glnL, new_glnL; + int target_ldsk_idx,dir_next; + t_ldsk *new_ldsk,*target_ldsk; + + n_trials = (int)(1.+0.1*PHYREX_Total_Number_Of_Intervals(tree)); + block = 50; + + for(i=0;imcmc->run_move[tree->mcmc->num_move_phyrex_add_remove_jump]++; + + + cur_glnL = tree->mmod->c_lnL; + new_glnL = tree->mmod->c_lnL; + hr = 0.0; + ratio = 0.0; + disk = NULL; + target_disk = NULL; + target_ldsk = NULL; + new_ldsk = NULL; + + disk = tree->young_disk->prev; + valid_disks = NULL; + n_valid_disks = 0; + do + { + if(disk->prev != NULL && + disk->age_fixed == NO && + ((disk->ldsk != NULL && disk->ldsk->n_next == 1) || disk->ldsk == NULL)) + { + if(!n_valid_disks) valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_valid_disks%block)) valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + valid_disks[n_valid_disks] = disk; + n_valid_disks++; + } + disk = disk->prev; + } + while(disk); + + if(n_valid_disks == 0) return; + + target_disk = valid_disks[Rand_Int(0,n_valid_disks-1)]; + Free(valid_disks); + + + if(target_disk->ldsk == NULL) // Add jump + { + target_ldsk_idx = Rand_Int(0,target_disk->n_ldsk_a-1); + target_ldsk = target_disk->ldsk_a[target_ldsk_idx]; + + hr -= log(1./(phydbl)target_disk->n_ldsk_a); + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) + { + assert(target_disk->next); + assert(target_disk->prev); + new_glnL -= PHYREX_Lk_Range(target_disk,target_ldsk->prev->disk,tree); + } + + + dir_next = PHYREX_Get_Next_Direction(target_ldsk,target_ldsk->prev); + assert(dir_next != -1); + + /* Make and initialize new ldsk */ + new_ldsk = PHYREX_Make_Lindisk_Node(tree->mmod->n_dim); + PHYREX_Init_Lindisk_Node(new_ldsk,target_disk,tree->mmod->n_dim); + PHYREX_Make_Lindisk_Next(new_ldsk); + target_disk->ldsk = new_ldsk; + + + + new_ldsk->prev = target_ldsk->prev;; + new_ldsk->next[0] = target_ldsk; + new_ldsk->prev->next[dir_next] = new_ldsk; + target_ldsk->prev = new_ldsk; + + + for(j=0;jmmod->n_dim;j++) + { + err = NO; + new_ldsk->coord->lonlat[j] = Rnorm_Trunc(target_disk->centr->lonlat[j], + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + hr -= Log_Dnorm_Trunc(new_ldsk->coord->lonlat[j], + target_disk->centr->lonlat[j], + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + } + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Range(target_disk,new_ldsk->prev->disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + ratio = (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + target_ldsk->prev = new_ldsk->prev; + new_ldsk->prev->next[dir_next] = target_ldsk; + target_disk->ldsk = NULL; + + PHYREX_Lk_Range(target_disk,target_ldsk->prev->disk,tree); + tree->mmod->c_lnL = cur_glnL; + /* PHYREX_Lk(tree); */ + + Free_Ldisk(new_ldsk); + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_add_remove_jump]++; + } + } + else // Remove jump + { + target_ldsk = target_disk->ldsk; + + hr += log(1./(phydbl)target_disk->n_ldsk_a); + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) + { + assert(target_disk->next); + assert(target_disk->prev); + new_glnL -= PHYREX_Lk_Range(target_disk,target_ldsk->prev->disk,tree); + } + + for(j=0;jmmod->n_dim;j++) + { + hr += Log_Dnorm_Trunc(target_ldsk->coord->lonlat[j], + target_disk->centr->lonlat[j], + 1.*tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + } + + dir_next = PHYREX_Get_Next_Direction(target_ldsk,target_ldsk->prev); + assert(dir_next != -1); + + target_ldsk->prev->next[dir_next] = target_ldsk->next[0]; + target_ldsk->next[0]->prev = target_ldsk->prev; + target_disk->ldsk = NULL; + + + if(tree->eval_glnL == YES) + { + new_glnL += PHYREX_Lk_Range(target_disk,target_ldsk->prev->disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + ratio = (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES && new_glnL > UNLIKELY) alpha = 1.0; + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + target_ldsk->prev->next[dir_next] = target_ldsk; + target_ldsk->next[0]->prev = target_ldsk; + target_disk->ldsk = target_ldsk; + + PHYREX_Lk_Range(target_disk,target_ldsk->prev->disk,tree); + tree->mmod->c_lnL = cur_glnL; + /* PHYREX_Lk(tree); */ + } + else + { + Free_Ldisk(target_ldsk); + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_add_remove_jump]++; + } + } + } +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Simulate_Backward(t_tree *tree) +{ + phydbl u,alpha,ratio,hr,t; + phydbl Told,Tyoung; + phydbl cur_alnL, new_alnL; + phydbl cur_glnL, new_glnL; + phydbl cur_rlnL, new_rlnL; + t_dsk *disk,*bkp_disk,*target_disk; + t_ldsk **bkp_ldsk; + int i; + t_node *n; + + tree->mcmc->run_move[tree->mcmc->num_move_phyrex_sim]++; + + disk = NULL; + bkp_disk = NULL; + target_disk = NULL; + bkp_ldsk = NULL; + + new_alnL = tree->c_lnL; + cur_alnL = tree->c_lnL; + cur_glnL = tree->mmod->c_lnL; + new_glnL = tree->mmod->c_lnL; + new_rlnL = tree->rates->c_lnL_rates; + cur_rlnL = tree->rates->c_lnL_rates; + hr = 0.0; + ratio = 0.0; + t = 0.0; + + + Get_Node_Ranks_From_Tip_Times(tree); + + // Get to the oldest sampled disk + n = tree->a_nodes[0]; + while(n->rk_prev && n->rk_prev->tax == YES) n = n->rk_prev; + Tyoung = n->ldsk->disk->time; + + + + /* Chop off the tree at time t and simulate upwards from here */ + Told = PHYREX_Tree_Height(tree); + + t = Uni()*(Tyoung-Told) + Told; + + disk = tree->young_disk->prev; + while(disk && disk->time > t) disk = disk->prev; + target_disk = disk->next; + + hr -= log(fabs((target_disk->prev->time - target_disk->time)/(Tyoung-Told))); + + bkp_disk = target_disk->prev; + + bkp_ldsk = (t_ldsk **)mCalloc(target_disk->n_ldsk_a,sizeof(t_ldsk *)); + for(i=0;in_ldsk_a;i++) bkp_ldsk[i] = target_disk->ldsk_a[i]->prev; + + + PHYREX_Simulate_Backward_Core(target_disk,NO,tree); + PHYREX_Ldsk_To_Tree(tree); + + + Told = PHYREX_Tree_Height(tree); + hr += log(fabs((target_disk->prev->time - target_disk->time)/(Tyoung-Told))); + + + if(tree->eval_alnL == YES) new_alnL = Lk(NULL,tree); + if(tree->eval_rlnL == YES) new_rlnL = RATES_Lk_Rates(tree); + + ratio += (new_alnL - cur_alnL); + ratio += (new_rlnL - cur_rlnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + /* Always accept move */ + if(tree->mcmc->always_yes == YES) alpha = 1.0; + + u = Uni(); + + if(u > alpha) /* Reject */ + { + disk = target_disk->prev; + while(disk->prev) + { + disk = disk->prev; + if(disk->next->ldsk != NULL) Free_Ldisk(disk->next->ldsk); + Free_Disk(disk->next); + } + + /* Root */ + Free_Ldisk(disk->ldsk); + Free_Disk(disk); + + target_disk->prev = bkp_disk; + for(i=0;in_ldsk_a;i++) target_disk->ldsk_a[i]->prev = bkp_ldsk[i]; + + if(tree->mmod->safe_phyrex == YES) + { + new_alnL = Lk(NULL,tree); + if(Are_Equal(new_alnL,cur_alnL,1.E-3) == NO) + { + PhyML_Fprintf(stderr,"\n. new_alnL: %f cur_alnL: %f",new_alnL,cur_alnL); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + + new_glnL = PHYREX_Lk(tree); + + if(Are_Equal(new_glnL,cur_glnL,1.E-3) == NO) + { + PhyML_Fprintf(stderr,"\n. new_glnL: %f cur_glnL: %f",new_glnL,cur_glnL); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + else + { + PHYREX_Lk(tree); + tree->c_lnL = cur_alnL; + tree->mmod->c_lnL = cur_glnL; + } + } + else + { + /* Accept */ + disk = bkp_disk; + while(disk->prev) + { + disk = disk->prev; + if(disk->next->ldsk != NULL) Free_Ldisk(disk->next->ldsk); + Free_Disk(disk->next); + } + + /* Root */ + Free_Ldisk(disk->ldsk); + Free_Disk(disk); + + /* Likelihood needs to be updated */ + PHYREX_Lk(tree); + + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_sim]++; + } + + + Free(bkp_ldsk); +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +#ifdef PHYREX +void MCMC_PHYREX_Ldsk_Tip_To_Root(t_tree *tree) +{ + phydbl u,alpha,ratio,hr,c; + phydbl cur_glnL, new_glnL; + t_dsk *disk,**all_disks; + int i,j,err,n_all_disks,block,n_move_ldsk,*permut; + t_geo_coord *mean; + phydbl K; + + block = 100; + all_disks = NULL; + n_all_disks = 0; + c = -1.; + mean = NULL; + K = tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_ldsk_tip_to_root]; + + disk = tree->young_disk->prev; + do + { + if(disk->ldsk != NULL) + { + if(!n_all_disks) all_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_all_disks%block)) all_disks = (t_dsk **)mRealloc(all_disks,n_all_disks+block,sizeof(t_dsk *)); + all_disks[n_all_disks] = disk; + n_all_disks++; + } + disk = disk->prev; + } + while(disk); + + if(!n_all_disks) return; + + n_move_ldsk = (int)(n_all_disks); + + permut = Permutate(n_all_disks); + cur_glnL = tree->mmod->c_lnL; + new_glnL = tree->mmod->c_lnL; + for(i=0;imcmc->run_move[tree->mcmc->num_move_phyrex_ldsk_tip_to_root]++; + + disk = all_disks[permut[i]]; + + hr = 0.0; + ratio = 0.0; + + PHYREX_Store_Geo_Coord(disk->ldsk->coord); + + + new_glnL = cur_glnL; + if(tree->eval_glnL == YES) + { + if(disk->ldsk->prev != NULL) new_glnL -= PHYREX_Lk_Range(disk,disk->ldsk->prev->disk,tree); + else new_glnL -= PHYREX_Lk_Core(disk,tree); + } + + mean = PHYREX_Mean_Next_Loc(disk->ldsk,tree); + + for(j=0;jmmod->n_dim;j++) + { + if(disk->ldsk->prev != NULL) + c = 0.5*(mean->lonlat[j] + disk->ldsk->prev->coord->lonlat[j]); + else + c = mean->lonlat[j]; + + err = NO; + disk->ldsk->coord->lonlat[j] = + Rnorm_Trunc(c, + (1./K)*(tree->mmod->lim_up->lonlat[j] - tree->mmod->lim_do->lonlat[j]), + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + if(err == YES) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + hr -= Log_Dnorm_Trunc(disk->ldsk->coord->lonlat[j], + c, + (1./K)*(tree->mmod->lim_up->lonlat[j] - tree->mmod->lim_do->lonlat[j]), + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + hr += Log_Dnorm_Trunc(disk->ldsk->coord->cpy->lonlat[j], + c, + (1./K)*(tree->mmod->lim_up->lonlat[j] - tree->mmod->lim_do->lonlat[j]), + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + + } + + Free_Geo_Coord(mean); + + if(tree->eval_glnL == YES) + { + if(disk->ldsk->prev != NULL) new_glnL += PHYREX_Lk_Range(disk,disk->ldsk->prev->disk,tree); + else new_glnL += PHYREX_Lk_Core(disk,tree); + tree->mmod->c_lnL = new_glnL; + /* new_glnL = PHYREX_Lk(tree); */ + } + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + assert(isnan(u) == NO && isinf(fabs(u)) == NO); + + if(u > alpha) /* Reject */ + { + PHYREX_Restore_Geo_Coord(disk->ldsk->coord); + tree->mmod->c_lnL = cur_glnL; + } + else + { + cur_glnL = new_glnL; + tree->mcmc->acc_move[tree->mcmc->num_move_phyrex_ldsk_tip_to_root]++; + } + } + + Free(permut); + Free(all_disks); + + +} +#endif + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ diff --git a/phyml/mcmc.h b/phyml/mcmc.h new file mode 100644 index 0000000..8159e0a --- /dev/null +++ b/phyml/mcmc.h @@ -0,0 +1,180 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef MCMC_H +#define MCMC_H + +#include "utilities.h" + +void MCMC_Lexp(t_tree *tree); +void MCMC_Print_Param(t_mcmc *mcmc, t_tree *tree); +t_mcmc *MCMC_Make_MCMC_Struct(); +void MCMC_Free_MCMC(t_mcmc *mcmc); +void MCMC_Alpha(t_tree *tree); +void MCMC_Randomize_Branch_Lengths(t_tree *tree); +void MCMC_Randomize_Node_Times(t_tree *tree); +void MCMC_Randomize_Node_Times_Pre(t_node *a, t_node *d, t_tree *tree); +void MCMC_Randomize_Lexp(t_tree *tree); +void MCMC_Randomize_Jumps(t_tree *tree); +void MCMC_Randomize_Alpha(t_tree *tree); +void MCMC_One_Rate(t_node *a, t_node *d, int traversal, t_tree *tree); +void MCMC_No_Change(t_tree *tree); +void MCMC_Nu(t_tree *tree); +void MCMC_Randomize_Nu(t_tree *tree); +t_node *MCMC_Select_Random_Node_Pair(phydbl t_sup, t_tree *tree); +void MCMC_Modify_Rates(t_tree *tree); +void MCMC_Modify_Subtree_Rate(t_node *a, t_node *d, phydbl new_rate, t_tree *tree); +void MCMC_Randomize_Rates(t_tree *tree); +void MCMC_Stick_Rates(t_tree *tree); +void MCMC_Stick_Rates_Pre(t_node *a, t_node *d, t_tree *tree); +void MCMC_Times_Global(t_tree *tree); +void MCMC_Times_Local(t_tree *tree); +void MCMC_Time_Recur(t_node *a, t_node *d, int traversal, t_tree *tree); +void MCMC_Rates_Global(t_tree *tree); +void MCMC_Rates_Local(t_tree *tree); +void MCMC_Rates_Pre(t_node *a, t_node *d, t_tree *tree); +void MCMC_Mixing_Step(t_tree *tree); +void MCMC_Jumps_Local(t_tree *tree); +void MCMC_Jumps_Pre(t_node *a, t_node *d, int local, t_tree *tree); +void MCMC_Randomize_Clock_Rate(t_tree *tree); +void MCMC_Clock_Rate(t_tree *tree); +void MCMC_Time_Root(t_tree *tree); +void MCMC_Randomize_Node_Times_Bottom_Up(t_node *a, t_node *d, t_tree *tree); +void MCMC_Randomize_Node_Times_Top_Down(t_node *a, t_node *d, t_tree *tree); +void MCMC_Randomize_Rates_Pre(t_node *a, t_node *d, t_tree *tree); +void MCMC_Print_Means(t_mcmc *mcmc, t_tree *tree); +void MCMC_Print_Last(t_mcmc *mcmc, t_tree *tree); +void MCMC_Close_MCMC(t_mcmc *mcmc); +void MCMC_Rates_Global(t_tree *tree); +void MCMC_Omega(t_tree *tree); +void MCMC_Adjust_Tuning_Parameter(int move, t_mcmc *mcmc); +void MCMC_Copy_MCMC_Struct(t_mcmc *ori, t_mcmc *cpy, char *filename); +void MCMC_Randomize_Node_Times_Bottom_Up(t_node *a, t_node *d, t_tree *tree); +void MCMC_One_Length(t_edge *b, t_tree *tree); +void MCMC_Br_Lens(t_tree *tree); +void MCMC_Br_Lens_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void MCMC_Tree_Height(t_tree *tree); +void MCMC_Subtree_Height(t_tree *tree); +void MCMC_Swing(t_tree *tree); +void MCMC_Single_Param_Generic(phydbl *val, + phydbl lim_inf, + phydbl lim_sup, + int move_num, + phydbl *lnPrior, + phydbl *lnLike, + phydbl (*prior_func)(t_edge *,t_tree *,supert_tree *), + phydbl (*like_func)(t_edge *,t_tree *,supert_tree *), + int move_type, int _log, + t_edge *branch, t_tree *tree, supert_tree *stree); +void MCMC_Scale_Br_Lens(t_tree *tree); +void MCMC_Update_Mean_Br_Len(t_tree *tree); +void MCMC_Update_Cov_Br_Len(t_tree *tree); +void MCMC_Sim_Rate(t_node *a, t_node *d, t_tree *tree); +void Fill_All_Param(t_mcmc *mcmc, t_rate *rate, t_tree *tree); +int Get_Param_Num(t_mcmc *mcmc, phydbl *param); +void MCMC_Complete_MCMC(t_mcmc *mcmc, t_tree *tree); +void MCMC_Sample_Joint_Rates_Prior(t_tree *tree); +void MCMC_Sample_Joint_Rates_Posterior(t_tree *tree); +void MCMC_Pair_Rates_Constraint(t_node *a, t_node *d, int random, int traversal, t_tree *tree); +void MCMC_Times_And_Rates(t_node *a, t_node *d, int random, int traversal, t_tree *tree); +void MCMC_Tree_Rates(t_tree *tree); +void MCMC_Pause(t_mcmc *mcmc); +void MCMC_Print_Param_Stdin(t_mcmc *mcmc, t_tree *tree); +void MCMC_Subtree_Rates(t_tree *tree); +void MCMC_Get_Acc_Rates(t_mcmc *mcmc); +void MCMC_Update_Effective_Sample_Size(int move_num, t_mcmc *mcmc, t_tree *tree); +void MCMC_Initialize_Param_Val(t_mcmc *mcmc, t_tree *tree); +void MCMC_Terminate(); +void MCMC_Copy_To_New_Param_Val(t_mcmc *mcmc, t_tree *tree); +void MCMC_Randomize_Node_Rates(t_tree *tree); +void MCMC_One_Node_Rate(t_node *a, t_node *d, int traversal, t_tree *tree); +void MCMC_Tree_Rates_Bis(t_tree *tree); +void MCMC_Slice_One_Rate(t_node *a, t_node *d, int traversal, t_tree *tree); +void MCMC_Updown_Nu_Cr(t_tree *tree); +void MCMC_All_Rates(t_tree *tree); +void MCMC_Alpha(t_tree *tree); +void MCMC_Kappa(t_tree *tree); +void MCMC_Rate_Across_Sites(t_tree *tree); +void MCMC_Free_Mixt_Rate(t_tree *tree); +void MCMC_Make_Move(phydbl *cur, phydbl *new, phydbl inf, phydbl sup, phydbl *loghr, phydbl tune, int move_type); +void MCMC_Randomize_Rate_Across_Sites(t_tree *tree); +void MCMC_Randomize_Kappa(t_tree *tree); +void MCMC_Updown_T_Cr(t_tree *tree); +void MCMC_Linreg_Par(t_tree *tree); +void MCMC_Covarion_Rates(t_tree *tree); +void MCMC_Covarion_Switch(t_tree *tree); +void MCMC_Randomize_Covarion_Rates(t_tree *tree); +void MCMC_Randomize_Covarion_Switch(t_tree *tree); +void MCMC_Read_Param_Vals(t_tree *tree); +void MCMC_Birth_Rate(t_tree *tree); +void MCMC_Randomize_Birth(t_tree *tree); +void MCMC_Clock_R(t_tree *mixt_tree); +void MCMC_Free_MCMC(t_mcmc *mcmc); +void MCMC_Updown_T_Br(t_tree *tree); +void MCMC_Root_Time(t_tree *tree); +void MCMC_Jump_Calibration(t_tree *tree); +void MCMC_GEO_Lbda(t_tree *mixt_tree); +void MCMC_GEO_Sigma(t_tree *mixt_tree); +void MCMC_GEO_Tau(t_tree *mixt_tree); +void MCMC_GEO_Loc(t_tree *tree); +void MCMC_GEO_Dum(t_tree *mixt_tree); +void MCMC_PHYREX_Lbda(t_tree *mixt_tree); +void MCMC_PHYREX_Mu(t_tree *mixt_tree); +void MCMC_PHYREX_Radius(t_tree *mixt_tree); +void MCMC_PHYREX_Triplet(t_tree *tree); +void MCMC_PHYREX_Move_Disk_Updown(t_tree *tree); +void MCMC_PHYREX_Swap_Disk(t_tree *tree); +void MCMC_PHYREX_Prune_Regraft(t_tree *tree); +void MCMC_PHYREX_Scale_Times(t_tree *tree); +void MCMC_PHYREX_Ldscape_Limits(t_tree *tree); +void MCMC_PHYREX_Indel_Disk(t_tree *tree); +void MCMC_PHYREX_Delete_Disk(phydbl hr, int n_delete_disks, phydbl cur_lbda, phydbl cur_mu, phydbl cur_rad, t_tree *tree); +void MCMC_PHYREX_Insert_Disk(phydbl hr, int n_insert_disks, phydbl cur_lbda, phydbl cur_mu, phydbl cur_rad, t_tree *tree); +void MCMC_PHYREX_Indel_Hit(t_tree *tree); +void MCMC_PHYREX_Insert_Hit(phydbl hr, int n_delete_disks, phydbl cur_lbda, phydbl cur_rad, phydbl cur_mu, t_tree *tree); +void MCMC_PHYREX_Delete_Hit(phydbl hr, int n_delete_disks, phydbl cur_lbda, phydbl cur_rad, phydbl cur_mu, t_tree *tree); +void MCMC_PHYREX_Simulate_Backward(t_tree *tree); +void MCMC_Update_Mode(int move_num, t_mcmc *mcmc, t_tree *tree); +void MCMC_PHYREX_Lineage_Traj(t_tree *tree); +void MCMC_PHYREX_Delete_Disk_Serial(t_tree *tree); +void MCMC_PHYREX_Insert_Disk_Serial(t_tree *tree); +void MCMC_PHYREX_Indel_Disk_Serial(t_tree *tree); +void MCMC_PHYREX_Simulate_Backward_Plus(t_tree *tree); +void MCMC_PHYREX_Indel_Hit_Serial(t_tree *tree); +void MCMC_PHYREX_Disk_Multi(t_tree *tree); +void MCMC_PHYREX_Ldsk_Multi(t_tree *tree); +void MCMC_PHYREX_Ldsk_Given_Disk(t_tree *tree); +void MCMC_PHYREX_Disk_Given_Ldsk(t_tree *tree); +void MCMC_PHYREX_Ldsk_And_Disk(t_tree *tree); +void MCMC_PHYREX_Add_Remove_Jump(t_tree *tree); +void MCMC_Death_Rate(t_tree *tree); +void MCMC_Times_All(t_tree *tree); +void MCMC_Prune_Regraft(t_tree *tree); +void MCMC_Randomize_Death(t_tree *tree); +void MCMC_Time_Slice(t_tree *tree); +void MCMC_Prune_Regraft_Local(t_tree *tree); +void MCMC_Prune_Regraft_Weighted(t_tree *tree); +void MCMC_Prune_Regraft_Root(t_tree *tree); +void MCMC_Birth_Death_Updown(t_tree *tree); +void MCMC_Rates_All(t_tree *tree); +void MCMC_Times_And_Rates_Recur(t_node *a, t_node *d, int traversal, t_tree *tree); +void MCMC_Times_And_Rates_All(t_tree *tree); +void MCMC_Times_And_Rates_Root(t_tree *tree); +void MCMC_Clade_Change(t_tree *tree); +void MCMC_PHYREX_Prune_Regraft_Local(t_tree *tree); +void MCMC_PHYREX_Simulate_Backward(t_tree *tree); +void MCMC_RR(t_tree *mixt_tree); +void MCMC_PHYREX_Ldsk_Tip_To_Root(t_tree *tree); + +#endif diff --git a/phyml/mg.c b/phyml/mg.c index 3abc728..a9c51c7 100644 --- a/phyml/mg.c +++ b/phyml/mg.c @@ -10,10 +10,11 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include #include "mg.h" #include "free.h" -#include "options.h" +#include "help.h" #include "utilities.h" #include "optimiz.h" #include "models.h" @@ -22,2812 +23,7 @@ the GNU public licence. See http://www.opensource.org for details. #include "pars.h" #include "interface.h" -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int MG_main(int argc, char **argv) -{ - option *io; - char *s_tree; - FILE *fp_phyml_tree,*fp_phyml_stats,*fp_phyml_lk; - int set; - time_t t_beg,t_end; - div_t hour,min; - int r_seed; - int i; - fflush(NULL); - io = (option *)Get_Input(argc,argv); - r_seed = (io->r_seed < 0)?(time(NULL)):(io->r_seed); - srand(r_seed); - Make_Model_Complete(io->mod); - fp_phyml_stats = Openfile(io->out_stats_file,io->out_stats_file_open_mode); - fprintf(fp_phyml_stats,"\n- PHYML %s -\n\n", VERSION); - fp_phyml_tree = Openfile(io->out_tree_file,io->out_tree_file_open_mode); - fp_phyml_lk = fopen(io->out_lk_file,"w"); - - time(&t_beg); - - if(io->multigene) - { - seq ***data; - allseq **alldata; - model **mod; - matrix **mat; - arbrelist *treelist; - superarbre *st; - - data = (seq ***) mCalloc(io->n_gt,sizeof(seq **)); - alldata = (allseq **)mCalloc(io->n_gt,sizeof(allseq *)); - mod = (model **) mCalloc(io->n_gt,sizeof(model *)); - mat = (matrix **)mCalloc(io->n_gt,sizeof(matrix *)); - - - - /* Read the sequences (for each subdataset) */ - For(set,io->n_gt) - { - Make_Model_Complete(io->st->optionlist[set]->mod); /* Complete model for each data set */ - mod[set] = io->st->optionlist[set]->mod; - data[set] = Get_Seq(io->st->optionlist[set],0); - printf("\n. Data set [#%d]\n",set+1); - printf("\n. Compressing sequences...\n"); - alldata[set] = Compact_Seq(data[set],io->st->optionlist[set]); - fclose(io->st->optionlist[set]->fp_in_seq); - Free_Seq(data[set],alldata[set]->n_otu); - Init_Model(alldata[set],mod[set]); - Check_Ambiguities(alldata[set], - io->st->optionlist[set]->mod->datatype, - io->st->optionlist[set]->mod->stepsize); - } - - Mg_Make_Superarbre_Full(io->st,io,alldata); - st = io->st; - treelist = st->treelist; - Fill_Dir_Table(st->tree); - Update_Dirs(st->tree); - - For(set,io->n_gt) - { - st->data_of_interest = alldata[set]; - if(!Mg_Get_Species_Found_In_St(st,alldata[set])) break; - treelist->tree[set] = Make_Tree_From_Scratch(st->tree->n_otu,NULL); - Copy_Tree_Topology_With_Labels(st->tree,treelist->tree[set]); - treelist->tree[set]->num_curr_branch_available = 0; - Connect_Edges_To_Nodes_Recur(treelist->tree[set]->noeud[0], - treelist->tree[set]->noeud[0]->v[0], - treelist->tree[set]); - Mg_Prune_St_Topo(treelist->tree[set],alldata[set],st); - - if(treelist->tree[set]->n_otu != alldata[set]->n_otu) - { - printf("\n. Problem with sequence file '%s'\n",io->st->optionlist[set]->in_seq_file); - printf("\n. # taxa found in supertree restricted to '%s' taxa = %d\n", - io->st->optionlist[set]->in_seq_file, - treelist->tree[set]->n_otu); - printf("\n. # sequences in '%s' = %d\n", - io->st->optionlist[set]->in_seq_file, - alldata[set]->n_otu); - Exit("\n"); - } - - treelist->tree[set]->dp = set; - treelist->tree[set]->n_otu = alldata[set]->n_otu; - treelist->tree[set]->mod = mod[set]; - treelist->tree[set]->io = io->st->optionlist[set]; - treelist->tree[set]->data = alldata[set]; - treelist->tree[set]->both_sides = 1; - treelist->tree[set]->n_pattern = treelist->tree[set]->data->crunch_len/ - treelist->tree[set]->mod->stepsize; - - Order_Tree_CSeq(treelist->tree[set],alldata[set]); - Fill_Dir_Table(treelist->tree[set]); - Update_Dirs(treelist->tree[set]); - Make_Tree_4_Lk(treelist->tree[set],alldata[set],alldata[set]->init_len); - Make_Tree_4_Pars(treelist->tree[set],alldata[set],alldata[set]->init_len); - treelist->tree[set]->triplet_struct = Make_Triplet_Struct(treelist->tree[set]->mod); - } - - if(set != io->n_gt) - { - printf("\n. Sequence data set found in '%s' has one or more taxa not found in the '%s' tree file\n", - io->st->optionlist[set]->in_seq_file, - io->in_tree_file); - Exit("\n"); - } - - Mg_Check_Extra_Taxa(st); - - st->tree->c_lnL = .0; - For(set,io->n_gt) - { - Lk(treelist->tree[set]); - Get_List_Of_Reachable_Tips(treelist->tree[set]); - Mg_Match_St_Nodes_In_Gt(treelist->tree[set],st); - Mg_Match_St_Edges_In_Gt(treelist->tree[set],st); - Mg_Map_St_Nodes_In_Gt(treelist->tree[set],st); - Mg_Map_St_Edges_In_Gt(treelist->tree[set],st); - Mg_Map_Gt_Edges_In_St(treelist->tree[set],st); - st->tree->c_lnL += treelist->tree[set]->c_lnL; - } - - Mg_Initialise_Bl_Partition(st); - Mg_Set_Bl(st->bl,st); - - time(&(st->tree->t_beg)); - time(&(st->tree->t_current)); - printf("\n. (%5d sec) [00] [%10.2f] [%5d]\n", - (int)(st->tree->t_current-st->tree->t_beg), - Mg_Lk(st), - Mg_Pars(st)); - - -/* int n_iter=0; */ -/* do */ -/* { */ -/* Mg_Optimize_Br_Len_Serie(st->tree->noeud[0], */ -/* st->tree->noeud[0]->v[0], */ -/* st->tree->noeud[0]->b[0], */ -/* st); */ - -/* st->tree->both_sides = 1; */ -/* Mg_Lk(st); */ -/* printf("\n. %f",st->tree->c_lnL); */ -/* /\* For(set,st->n_gt) printf("\n. %s",Write_Tree(st->treelist->tree[set])); *\/ */ -/* n_iter++; */ -/* }while(n_iter < 5); */ - - -/* Mg_Lk(st); */ -/* printf("\n> %f",st->tree->c_lnL); */ -/* For(i,2*st->tree->n_otu-3) */ -/* { */ -/* if((!st->tree->t_edges[i]->left->tax) && (!st->tree->t_edges[i]->rght->tax)) */ -/* { */ -/* Mg_NNI(st->tree->t_edges[i],st); */ -/* } */ -/* } */ - - -/* if(io->mod->s_opt->topo_search == NNI_MOVE) */ - Mg_Simu(st); -/* else */ -/* Mg_Speed_Spr(st); */ - - - time(&t_end); - - hour = div(t_end-t_beg,3600); - min = div(t_end-t_beg,60 ); - - min.quot -= hour.quot*60; - - - fprintf(fp_phyml_stats,"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); - fprintf(fp_phyml_stats,"\n. Number of partitions = %d\n\n",st->n_gt); - fprintf(fp_phyml_stats,"\n. Full data set -- lnL = %f\n\n",st->tree->c_lnL); - fprintf(fp_phyml_stats,"\n. Tree search algorithm : %s\n\n",(io->mod->s_opt->topo_search == NNI_MOVE)?("NNIs"):("SPRs")); - fprintf(fp_phyml_stats,"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n"); - For(set,io->n_gt) - { - Print_Fp_Out(fp_phyml_stats,t_beg,t_end,st->treelist->tree[set], - io->st->optionlist[set],1,1); - } - - - printf("\n\n. Time used %dh%dm%ds\n", hour.quot,min.quot,(int)(t_end-t_beg)%60); - printf("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"); - - For(i,2*st->tree->n_otu-3) st->tree->t_edges[i]->l = 0.1; - s_tree = Write_Tree(st->tree); - fprintf(fp_phyml_tree,"Supertree\n"); - fprintf(fp_phyml_tree,"%s\n",s_tree); - Free(s_tree); - For(set,st->n_gt) - { - fprintf(fp_phyml_tree,"Gene tree number %d\n",set+1); - s_tree = Write_Tree(st->treelist->tree[set]); - fprintf(fp_phyml_tree,"%s\n",s_tree); - Free(s_tree); - } - - - For(set,st->n_gt) - { - if(io->mod->s_opt->topo_search == SPR_MOVE) Free_Spr_List(treelist->tree[set]); - Free_Tree_Lk(treelist->tree[set]); - Free_Tree_Pars(treelist->tree[set]); - Free_Triplet(treelist->tree[set]->triplet_struct); - Free_Tree(treelist->tree[set]); - Free_Cseq(alldata[set]); - Free_Model(mod[set]); - Free_Input(io->st->optionlist[set]); - - } - - if(io->mod->s_opt->topo_search == SPR_MOVE) Free_Spr_List(st->tree); - Free(mat); - Free(mod); - Free(data); - Free(alldata); - Free(treelist->tree); - Free(treelist); - Free_St(st); - } - - - if(io->fp_in_seq ) fclose(io->fp_in_seq); - if(io->fp_in_tree) fclose(io->fp_in_tree); - - - Free_Model(io->mod); - Free_Input(io); - - fclose(fp_phyml_lk); - fclose(fp_phyml_tree); - fclose(fp_phyml_stats); - - - return 0; -} - -/*********************************************************/ - -void Mg_Print_Nodes(node *a, node *d, superarbre *st) -{ - int i; - printf(">>>>>>>>>>>>>>>>>>>>\n"); - printf("num node = %d\n",d->num); - if(d->tax) printf("name='%s'\n",d->name); - else - { - printf("n_of_reachable_tips : \n"); - For(i,3) - { -/* printf("dir%d=%d; ",i,st->n_of_reachable_tips[st->num_data_of_interest][d->num][i]); */ -/* For(j,st->n_of_reachable_tips[st->num_data_of_interest][d->num][i]) */ -/* { */ -/* printf("%s ", */ -/* st->list_of_reachable_tips[st->num_data_of_interest][d->num][i][j]->name); */ -/* } */ - - printf("\n"); - } - } - printf("<<<<<<<<<<<<<<<<<<<\n\n"); - if(d->tax) return; - else - { - For(i,3) if(d->v[i] != a) Mg_Print_Nodes(d,d->v[i],st); - } -} - -/*********************************************************/ - -superarbre *Mg_Make_Superarbre_Light(option *input) -{ - superarbre *st; - - st = (superarbre *)mCalloc(1,sizeof(superarbre)); - st->optionlist = (option **)mCalloc(input->n_gt,sizeof(option *)); - st->bl_partition = (int *)mCalloc(input->n_gt,sizeof(int )); - return st; -} - -/*********************************************************/ - -void Mg_Make_Superarbre_Full(superarbre *st, option *io, allseq **data) -{ - int i,j,k; - - if(io->in_tree) - { - printf("\n. Reading user tree...\n"); - rewind(io->fp_in_tree); - - st->tree = Read_Tree_File(io->fp_in_tree); - - if(!st->tree->has_branch_lengths) - { - printf("\n. Branch lengths are all set to 0.1...\n"); - For(i,2*st->tree->n_otu-3) st->tree->t_edges[i]->l = 0.1; - } - } - else - { - Warn_And_Exit("\n. A user-defined input tree is needed\n"); - } - - st->tree->io = io; - st->treelist = (arbrelist *)Make_Treelist(io->n_gt); - st->n_gt = io->n_gt; - st->tree->mod = io->mod; - st->lock_br_len = 0; - - st->map_st_node_in_gt = (node *****)mCalloc(st->n_gt,sizeof(node ****)); - For(i,st->n_gt) - { - st->map_st_node_in_gt[i] = (node ****)mCalloc(2*st->tree->n_otu-2,sizeof(node ***)); - For(j,2*st->tree->n_otu-2) - { - st->map_st_node_in_gt[i][j] = (node ***)mCalloc(3,sizeof(node **)); - For(k,3) st->map_st_node_in_gt[i][j][k] = (node **)mCalloc(2,sizeof(node *)); - } - } - - st->map_st_edge_in_gt = (edge ***)mCalloc(st->n_gt,sizeof(edge **)); - For(i,st->n_gt) st->map_st_edge_in_gt[i] = (edge **)mCalloc(2*st->tree->n_otu-3,sizeof(edge *)); - - st->map_gt_edge_in_st = (edge ****)mCalloc(st->n_gt,sizeof(edge ***)); - For(i,st->n_gt) - { - st->map_gt_edge_in_st[i] = (edge ***)mCalloc(2*st->tree->n_otu-3,sizeof(edge **)); - For(j,2*st->tree->n_otu-3) st->map_gt_edge_in_st[i][j] = (edge **)mCalloc(2*st->tree->n_otu-3,sizeof(edge *)); - } - - st->size_map_gt_edge_in_st = (int **)mCalloc(st->n_gt,sizeof(int *)); - For(i,st->n_gt) st->size_map_gt_edge_in_st[i] = (int *)mCalloc(2*st->tree->n_otu-3,sizeof(int)); - - - st->match_st_edge_in_gt = (edge ***)mCalloc(st->n_gt,sizeof(edge **)); - For(i,st->n_gt) st->match_st_edge_in_gt[i] = (edge **)mCalloc(2*st->tree->n_otu-3,sizeof(edge *)); - - st->match_gt_edge_in_st = (edge ***)mCalloc(st->n_gt,sizeof(edge **)); - For(i,st->n_gt) st->match_gt_edge_in_st[i] = (edge **)mCalloc(2*st->tree->n_otu-3,sizeof(edge *)); - - st->bl = (phydbl **)mCalloc(st->n_gt,sizeof(phydbl *)); - For(i,st->n_gt) st->bl[i] = (phydbl *)mCalloc(2*st->tree->n_otu-3,sizeof(phydbl)); - - st->bl_cpy = (phydbl **)mCalloc(st->n_gt,sizeof(phydbl *)); - For(i,st->n_gt) st->bl_cpy[i] = (phydbl *)mCalloc(2*st->tree->n_otu-3,sizeof(phydbl)); - - st->bl0 = (phydbl **)mCalloc(st->n_gt,sizeof(phydbl *)); - For(i,st->n_gt) st->bl0[i] = (phydbl *)mCalloc(2*st->tree->n_otu-3,sizeof(phydbl)); - - st->bl1 = (phydbl **)mCalloc(st->n_gt,sizeof(phydbl *)); - For(i,st->n_gt) st->bl1[i] = (phydbl *)mCalloc(2*st->tree->n_otu-3,sizeof(phydbl)); - - st->bl2 = (phydbl **)mCalloc(st->n_gt,sizeof(phydbl *)); - For(i,st->n_gt) st->bl2[i] = (phydbl *)mCalloc(2*st->tree->n_otu-3,sizeof(phydbl)); - - st->s_mod = (model **)mCalloc(st->n_gt,sizeof(model *)); - - For(i,2*st->tree->n_otu-3) Make_Edge_NNI(st->tree->t_edges[i]); - - Get_List_Of_Reachable_Tips(st->tree); - - st->match_st_node_in_gt = (node ***)mCalloc(io->n_gt,sizeof(node **)); - For(i,io->n_gt) st->match_st_node_in_gt[i] = (node **)mCalloc(2*st->tree->n_otu-2,sizeof(node *)); -} - -/*********************************************************/ - -void Mg_Prune_St_Topo(arbre *tree, allseq *data, superarbre *st) -{ - int i,j,not_found; - int curr_ext_node, curr_int_node, curr_br, n_pruned_nodes;; - node **pruned_nodes; - edge **residual_edges; - - pruned_nodes = (node **)mCalloc(st->tree->n_otu,sizeof(node *)); - residual_edges = (edge **)mCalloc(st->tree->n_otu,sizeof(edge *)); - - n_pruned_nodes = 0; - For(i,st->tree->n_otu) - { - For(j,data->n_otu) - { - if(!strcmp(data->c_seq[j]->name,st->tree->noeud[i]->name)) - break; - } - - not_found = 1; - if(j == data->n_otu) - { - For(j,tree->n_otu) - { - if(!strcmp(tree->noeud[j]->name,st->tree->noeud[i]->name)) - { - Prune_Subtree(tree->noeud[j]->v[0], - tree->noeud[j], - NULL,&(residual_edges[n_pruned_nodes]), - tree); - - pruned_nodes[n_pruned_nodes] = tree->noeud[j]; - n_pruned_nodes++; - not_found = 0; - break; - } - } - - - if(not_found) - { - printf("\n. Taxon '%s'",st->tree->noeud[i]->name); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - } - } - - For(i,2*tree->n_otu-2) Free(tree->t_dir[i]); Free(tree->t_dir); - - tree->n_otu -= n_pruned_nodes; - - curr_ext_node = 0; - curr_int_node = tree->n_otu; - curr_br = 0; - For(i,st->tree->n_otu) - { - For(j,n_pruned_nodes) - { - if(!strcmp(pruned_nodes[j]->name,st->tree->noeud[i]->name)) - break; - } - if(j == n_pruned_nodes) /* That node still belongs to the tree */ - { - Reassign_Node_Nums(tree->noeud[i],tree->noeud[i]->v[0], - &curr_ext_node, &curr_int_node,tree); - break; - } - } - - Reassign_Edge_Nums(tree->noeud[0],tree->noeud[0]->v[0],&curr_br,tree); - - tree->t_dir = (int **)mCalloc(2*tree->n_otu-2,sizeof(int *)); - For(i,2*tree->n_otu-2) tree->t_dir[i] = (int *)mCalloc(2*tree->n_otu-2,sizeof(int)); - - For(i,n_pruned_nodes) - { - Free_Edge(residual_edges[i]); - Free_Edge(pruned_nodes[i]->b[0]); - Free_Node(pruned_nodes[i]->v[0]); - Free_Node(pruned_nodes[i]); - } - - Free(pruned_nodes); - Free(residual_edges); - -} - -/*********************************************************/ - -void Mg_Match_St_Nodes_In_Gt(arbre *gt, superarbre *st) -{ - int i,j; - - For(i,2*st->tree->n_otu-2) st->match_st_node_in_gt[gt->dp][i] = NULL; /* don't forget that step ! */ - - /* Map tips */ - For(i,st->tree->n_otu) - { - For(j,gt->n_otu) - { - if(!strcmp(st->tree->noeud[i]->name,gt->noeud[j]->name)) - { - st->match_st_node_in_gt[gt->dp][st->tree->noeud[i]->num] = gt->noeud[j]; - break; - } - } - } - -#ifdef DEBUG - /* Checking that the results are correct so far */ - int n_matches; - n_matches = 0; - For(i,2*st->tree->n_otu-2) - if(st->match_st_node_in_gt[gt->dp][i]) - n_matches++; - - if(n_matches != gt->n_otu) - { - printf("\n"); - printf("\n. n_matches = %d 2*gt->n_otu-2 = %d\n",n_matches,2*gt->n_otu-2); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } -#endif - - - /* Map internal nodes */ - For(i,st->tree->n_otu) - { - if(st->match_st_node_in_gt[gt->dp][st->tree->noeud[i]->num]) - { - Mg_Match_St_Nodes_In_Gt_Recurr(st->match_st_node_in_gt[gt->dp][st->tree->noeud[i]->num], - st->match_st_node_in_gt[gt->dp][st->tree->noeud[i]->num]->v[0], - st->tree->noeud[i], - st->tree->noeud[i]->v[0], - gt, - st); - break; - } - } - - - -#ifdef DEBUG - /* Checking that the results are correct */ - n_matches = 0; - For(i,2*st->tree->n_otu-2) - if(st->match_st_node_in_gt[gt->dp][st->tree->noeud[i]->num]) - n_matches++; - - if(n_matches != 2*gt->n_otu-2) - { - int j; - printf("\n"); - printf("\n. n_matches = %d 2*gt->n_otu-2 = %d\n",n_matches,2*gt->n_otu-2); - For(j,2*gt->n_otu-2) - { - For(i,2*st->tree->n_otu-2) - if(st->match_st_node_in_gt[gt->dp][i] == gt->noeud[j]) - break; - - if(i == 2*st->tree->n_otu-2) - { - printf("\n. Gt %3d node %3d (%3d %3d %3d) (%s %s %s) (%f %f %f) does not match\n", - gt->dp, - gt->noeud[j]->num, - gt->noeud[j]->v[0] ? gt->noeud[j]->v[0]->num : -1, - gt->noeud[j]->v[1] ? gt->noeud[j]->v[1]->num : -1, - gt->noeud[j]->v[2] ? gt->noeud[j]->v[2]->num : -1, - gt->noeud[j]->v[0]->tax ? gt->noeud[j]->v[0]->name : NULL, - gt->noeud[j]->v[1]->tax ? gt->noeud[j]->v[1]->name : NULL, - gt->noeud[j]->v[2]->tax ? gt->noeud[j]->v[2]->name : NULL, - gt->noeud[j]->v[0] ? gt->noeud[j]->b[0]->l : -1., - gt->noeud[j]->v[1] ? gt->noeud[j]->b[1]->l : -1., - gt->noeud[j]->v[2] ? gt->noeud[j]->b[2]->l : -1.); - } - } - - printf("oooooooo\n"); - Print_Node(st->tree->noeud[0], - st->tree->noeud[0]->v[0], - st->tree); - printf(">>>>>>>\n"); - For(i,st->n_gt) - { - Print_Node(st->treelist->tree[i]->noeud[0], - st->treelist->tree[i]->noeud[0]->v[0], - st->treelist->tree[i]); - printf("<<<<<<<\n"); - } - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } -#endif -} - -/*********************************************************/ - -void Mg_Match_St_Nodes_In_Gt_Recurr(node *a_gt, node *d_gt, node *a_st, node *d_st, arbre *gt, superarbre *st) -{ - int i,j,k; - int *score_d_st; - - - if((d_gt->tax) || (d_st->tax)) return; - else - { - score_d_st = (int *)mCalloc(3,sizeof(int)); - - For(i,3) - { - For(j,3) - { - For(k,d_st->n_of_reachable_tips[j]) - { - if(!strcmp(d_gt->list_of_reachable_tips[i][0]->name,d_st->list_of_reachable_tips[j][k]->name)) - break; - } - if(k != d_st->n_of_reachable_tips[j]) score_d_st[j] += 1; - } - } - - - if((score_d_st[0] == 1) && (score_d_st[1] == 1) && (score_d_st[2] == 1)) - { - st->match_st_node_in_gt[gt->dp][d_st->num] = d_gt; - - For(i,3) - { - if(d_gt->v[i] != a_gt) - { - For(j,3) - { - For(k,d_st->n_of_reachable_tips[j]) - if(!strcmp(d_gt->list_of_reachable_tips[i][0]->name, - d_st->list_of_reachable_tips[j][k]->name)) - { - Mg_Match_St_Nodes_In_Gt_Recurr(d_gt,d_gt->v[i],d_st,d_st->v[j],gt,st); - break; - } - if(k != d_st->n_of_reachable_tips[j]) break; - } - } - } - } - else - { - For(i,3) - if(d_st->v[i] != a_st) - Mg_Match_St_Nodes_In_Gt_Recurr(a_gt,d_gt,d_st,d_st->v[i],gt,st); - } - Free(score_d_st); - } -} - -/*********************************************************/ - -void Mg_Match_St_Edges_In_Gt(arbre *gt, superarbre *st) -{ - int i; - - For(i,2*st->tree->n_otu-3) - { - st->match_st_edge_in_gt[gt->dp][i] = NULL; - st->match_gt_edge_in_st[gt->dp][i] = NULL; - } - - For(i,st->tree->n_otu) - if(st->match_st_node_in_gt[gt->dp][i]) - { - Mg_Match_St_Edges_In_Gt_Recurr(st->match_st_node_in_gt[gt->dp][i], - st->match_st_node_in_gt[gt->dp][i]->v[0], - st->tree->noeud[i], - st->tree->noeud[i]->v[0], - gt,st); - break; - } - -} - -/*********************************************************/ - -void Mg_Match_St_Edges_In_Gt_Recurr(node *a_gt, node *d_gt, node *a_st, node *d_st, arbre *gt, superarbre *st) -{ - edge *b_gt, *b_st; - int i,j,k; - - b_gt = b_st = NULL; - - if((st->match_st_node_in_gt[gt->dp][a_st->num] == a_gt) && - (st->match_st_node_in_gt[gt->dp][d_st->num] == d_gt)) - { - For(i,3) if((a_st->v[i]) && (a_st->v[i] == d_st)) {b_st = a_st->b[i]; break;} - For(i,3) if((a_gt->v[i]) && (a_gt->v[i] == d_gt)) {b_gt = a_gt->b[i]; break;} - - st->match_st_edge_in_gt[gt->dp][b_st->num] = b_gt; - st->match_gt_edge_in_st[gt->dp][b_gt->num] = b_st; - } - - - if(!d_gt) - { - printf("\n"); - printf("\n. a_gt->num = %d\n",a_gt->num); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - - if(d_gt->tax || d_st->tax) return; - else - { - if(st->match_st_node_in_gt[gt->dp][d_st->num] == d_gt) - { - For(i,3) - { - if(d_gt->v[i] != a_gt) - { - For(j,3) - { - For(k,d_st->n_of_reachable_tips[j]) - if(!strcmp(d_gt->list_of_reachable_tips[i][0]->name,d_st->list_of_reachable_tips[j][k]->name)) - { - Mg_Match_St_Edges_In_Gt_Recurr(d_gt,d_gt->v[i],d_st,d_st->v[j],gt,st); - break; - } - if(k != d_st->n_of_reachable_tips[j]) break; - } - } - } - } - else - { - For(i,3) - if(d_st->v[i] != a_st) - Mg_Match_St_Edges_In_Gt_Recurr(a_gt,d_gt,d_st,d_st->v[i],gt,st); - } - } -} - -/*********************************************************/ - -void Mg_Simu(superarbre *st) -{ - int i,j,step,n_without_swap,it_lim_without_swap; - edge **sorted_b,*st_b,**tested_b; - int n_neg,n_tested,each; - phydbl lambda,old_loglk; - - sorted_b = (edge **)mCalloc(st->tree->n_otu-3,sizeof(edge *)); - tested_b = (edge **)mCalloc(st->tree->n_otu-3,sizeof(edge *)); - - For(i,st->n_gt) Update_Dirs(st->treelist->tree[i]); - Update_Dirs(st->tree); - - each = 4; - step = 0; - lambda = .75; - n_tested = 0; - n_without_swap = 0; - old_loglk = UNLIKELY; - it_lim_without_swap = 2; - st_b = NULL; - do - { - For(i,st->n_gt) Check_Dirs(st->treelist->tree[i]); - - ++step; - each--; - - Mg_Print_Bl(st); - - /* Compute the likelihood of the supertreee */ - st->tree->c_lnL = Mg_Lk(st); - st->tree->c_pars = Mg_Pars(st); -/* For(i,st->n_gt) printf("\n. %s",Write_Tree(st->treelist->tree[i])); */ -/* printf("\n"); */ - - time(&(st->tree->t_current)); - printf("\n. (%5d sec) [tot lnL=%15.5f] [# swaps=%3d]", - (int)(st->tree->t_current-st->tree->t_beg), - st->tree->c_lnL,n_tested); -/* For(i,st->n_gt) printf("\n[gt %3d lnL=%15.5f]",i,st->treelist->tree[i]->c_lnL); */ - - if((fabs(old_loglk-st->tree->c_lnL) < st->tree->mod->s_opt->min_diff_lk_global) || - (n_without_swap > it_lim_without_swap)) break; - - if(st->tree->c_lnL < old_loglk) - { - printf("\n. Moving backward (topology + branch lengths) \n"); - - if(!Mg_Mov_Backward_Topo_Bl(st,old_loglk,tested_b,n_tested)) - Warn_And_Exit("\n. Err: mov_back failed\n"); - - if(!st->tree->n_swap) n_neg = 0; - - Mg_Record_Br_Len(st); - For(i,st->n_gt) Optimiz_All_Free_Param(st->treelist->tree[i],0); - } - else - { - if(!each) - { - each = 4; - /* Markov model parameters are free to vary across data partitions */ - For(i,st->n_gt) Optimiz_All_Free_Param(st->treelist->tree[i],0); - For(i,st->n_gt) st->treelist->tree[i]->both_sides = 1; - st->tree->c_lnL = Mg_Lk(st); - st->tree->c_pars = Mg_Pars(st); - } - - old_loglk = st->tree->c_lnL; - - - For(i,2*st->tree->n_otu-3) Init_NNI(st->tree->t_edges[i]->nni); - - /* Test NNIs */ - For(i,2*st->tree->n_otu-3) - { - st_b = st->tree->t_edges[i]; - if((!st_b->left->tax) && (!st_b->rght->tax)) Mg_NNI(st_b,st); - } - - /* Optimise external branch lengths */ - For(i,2*st->tree->n_otu-3) - { - st_b = st->tree->t_edges[i]; - if((st_b->left->tax) || (st_b->rght->tax)) - { - Mg_Record_Br_Len(st); - Mg_Br_Len_Brent(st_b,st); - For(j,st->n_gt) st->bl0[st->bl_partition[j]][st_b->num] = st->bl[st->bl_partition[j]][st_b->num]; - st_b->nni->score = .0; - st_b->nni->best_conf = 0; - Mg_Restore_Br_Len(st); - Mg_Lk_At_Given_Edge(st_b,st); - } - } - - /* Select and sort swaps */ - n_neg = 0; - Select_Edges_To_Swap(st->tree,sorted_b,&n_neg); - Sort_Edges_NNI_Score(st->tree,sorted_b,n_neg); - - n_tested = 0; - For(i,(int)ceil((phydbl)n_neg*(lambda))) - tested_b[n_tested++] = sorted_b[i]; - - if(n_tested > 0) n_without_swap = 0; - else n_without_swap++; - - Mg_Record_Br_Len(st); - - /* Apply swaps */ - Mg_Make_N_Swap(tested_b,0,n_tested,st); - - /* Update branch lengths (all edges first and then swaped edges) */ - Mg_Update_Bl(lambda,st); - Mg_Update_Bl_Swaped(tested_b,n_tested,st); - - - } - } - while(1); - - printf("\n\n. End of Mg_Simu \n"); - Free(sorted_b); - Free(tested_b); - - if((n_without_swap > it_lim_without_swap)) - { - printf("\n. Last optimization step...\n"); - For(i,st->n_gt) Round_Optimize(st->treelist->tree[i],st->treelist->tree[i]->data); - st->tree->c_lnL = Mg_Lk(st); - Mg_Simu(st); - } -} - - -/*********************************************************/ - -int Mg_Mov_Backward_Topo_Bl(superarbre *st, phydbl lk_old, edge **tested_b, int n_tested) -{ - int i,j,step,beg,end; - edge *st_b; - phydbl **l_init; - - l_init = (phydbl **)mCalloc(st->n_gt,sizeof(phydbl *)); - For(i,st->n_gt) l_init[i] = (phydbl *)mCalloc(2*st->tree->n_otu-3,sizeof(phydbl )); - - For(i,2*st->tree->n_otu-3) For(j,st->n_gt) l_init[st->bl_partition[j]][i] = st->bl[st->bl_partition[j]][i]; - - step = 2; - do - { - For(i,2*st->tree->n_otu-3) - { - For(j,st->n_gt) - { - st->bl[st->bl_partition[j]][i] = st->bl_cpy[st->bl_partition[j]][i] + - (1./step) * (l_init[st->bl_partition[j]][i] - st->bl_cpy[st->bl_partition[j]][i]); -/* st->bl[st->bl_partition[j]][i] = st->bl_cpy[st->bl_partition[j]][i]; */ - } - } - - beg = (int)floor((phydbl)n_tested/(step-1)); - end = 0; - st_b = NULL; - - for(i=beg-1;i>=end;i--) - { - st_b = tested_b[i]; - - Mg_Swap(st_b->nni->swap_node_v2->v[st->tree->t_dir[st_b->nni->swap_node_v2->num][st_b->nni->swap_node_v1->num]], - st_b->nni->swap_node_v2, - st_b->nni->swap_node_v3, - st_b->nni->swap_node_v3->v[st->tree->t_dir[st_b->nni->swap_node_v3->num][st_b->nni->swap_node_v4->num]], - st); - - Swap(st_b->nni->swap_node_v2->v[st->tree->t_dir[st_b->nni->swap_node_v2->num][st_b->nni->swap_node_v1->num]], - st_b->nni->swap_node_v2, - st_b->nni->swap_node_v3, - st_b->nni->swap_node_v3->v[st->tree->t_dir[st_b->nni->swap_node_v3->num][st_b->nni->swap_node_v4->num]], - st->tree); - - Mg_Do_Mapping(st); - - } - - beg = 0; - end = (int)floor((phydbl)n_tested/step); - st_b = NULL; - - for(i=beg;inni->swap_node_v2->v[st->tree->t_dir[st_b->nni->swap_node_v2->num][st_b->nni->swap_node_v1->num]], - st_b->nni->swap_node_v2, - st_b->nni->swap_node_v3, - st_b->nni->swap_node_v3->v[st->tree->t_dir[st_b->nni->swap_node_v3->num][st_b->nni->swap_node_v4->num]], - st); - - Swap(st_b->nni->swap_node_v2->v[st->tree->t_dir[st_b->nni->swap_node_v2->num][st_b->nni->swap_node_v1->num]], - st_b->nni->swap_node_v2, - st_b->nni->swap_node_v3, - st_b->nni->swap_node_v3->v[st->tree->t_dir[st_b->nni->swap_node_v3->num][st_b->nni->swap_node_v4->num]], - st->tree); - - Mg_Do_Mapping(st); - - } - - if(!end) st->tree->n_swap = 0; - - Mg_Lk(st); - - printf("\n. lnL = %15.5f",st->tree->c_lnL); - step++; - } - while((st->tree->c_lnL < lk_old) && (step < 100)); - - if(step == 100) - { - For(i,2*st->tree->n_otu-3) For(j,st->n_gt) - st->bl[st->bl_partition[j]][i] = st->bl_cpy[st->bl_partition[j]][i]; - } - - st->tree->n_swap = 0; - For(i,2*st->tree->n_otu-3) - { - if(st->tree->t_edges[i]->nni->score < 0.0) st->tree->n_swap++; - st->tree->t_edges[i]->nni->score = +1.0; - } - - Mg_Lk(st); - - if(st->tree->c_lnL > lk_old) return 1; - else if(fabs(st->tree->c_lnL-lk_old) < st->tree->mod->s_opt->min_diff_lk_local) return -1; - else return 0; - - For(i,st->n_gt) Free(l_init[i]); - Free(l_init); -} - -/*********************************************************/ - -void Mg_Check_Extra_Taxa(superarbre *st) -{ - int i,j,k; - int sum; - int *st_taxa; - - st_taxa = (int *)mCalloc(st->tree->n_otu,sizeof(int)); - - For(i,st->tree->n_otu) - { - For(j,st->n_gt) - { - For(k,st->treelist->tree[j]->n_otu) - if(!strcmp(st->treelist->tree[j]->noeud[k]->name,st->tree->noeud[i]->name)) break; - if(k != st->treelist->tree[j]->n_otu) { st_taxa[i] = 1; break; } - } - } - - sum = 0; - For(i,st->tree->n_otu) if(st_taxa[i]) sum++; - if(sum != st->tree->n_otu) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - Free(st_taxa); -} - -/*********************************************************/ - -int Mg_Get_Species_Found_In_St(superarbre *st, allseq *data) -{ - int i,j; - - For(i,data->n_otu) - { - For(j,st->tree->n_otu) - { - if(!strcmp(data->c_seq[i]->name,st->tree->noeud[j]->name)) - { - break; - } - } - if(j == st->tree->n_otu) return 0; - } - return 1; - -} - -/*********************************************************/ - -void Mg_Map_St_Nodes_In_Gt(arbre *gt, superarbre *st) -{ - int i; - - For(i,2*st->tree->n_otu-2) - { - st->map_st_node_in_gt[gt->dp][i][0][0] = NULL; - st->map_st_node_in_gt[gt->dp][i][1][0] = NULL; - st->map_st_node_in_gt[gt->dp][i][2][0] = NULL; - - st->map_st_node_in_gt[gt->dp][i][0][1] = NULL; - st->map_st_node_in_gt[gt->dp][i][1][1] = NULL; - st->map_st_node_in_gt[gt->dp][i][2][1] = NULL; - } - - - /* Root */ - Mg_Map_St_Nodes_In_Gt_One_Edge(st->tree->noeud[0]->v[0], - st->tree->noeud[0], - st->tree->noeud[0]->b[0], - gt,st); - - /* Internal nodes */ - Mg_Map_St_Nodes_In_Gt_Post(st->tree->noeud[0],st->tree->noeud[0]->v[0],gt,st); - Mg_Map_St_Nodes_In_Gt_Pre (st->tree->noeud[0],st->tree->noeud[0]->v[0],gt,st); - - /* Root */ - Mg_Map_St_Nodes_In_Gt_One_Edge(st->tree->noeud[0], - st->tree->noeud[0]->v[0], - st->tree->noeud[0]->b[0], - gt,st); - -} - -/*********************************************************/ - -void Mg_Map_St_Nodes_In_Gt_Post(node *a_st, node *d_st, arbre *gt, superarbre *st) -{ - int i,dir; - - dir = -1; - - if(d_st->tax) return; - else - { - For(i,3) - if(d_st->v[i] != a_st) - Mg_Map_St_Nodes_In_Gt_Post(d_st,d_st->v[i],gt,st); - - For(i,3) - if(d_st->v[i] != a_st) - { - Mg_Map_St_Nodes_In_Gt_One_Edge(d_st,d_st->v[i],d_st->b[i],gt,st); - } - } -} - -/*********************************************************/ - -void Mg_Map_St_Nodes_In_Gt_Pre(node *a_st, node *d_st, arbre *gt, superarbre *st) -{ - int i; - - if(d_st->tax) return; - else - { - For(i,3) - { - if(d_st->v[i] != a_st) - { - Mg_Map_St_Nodes_In_Gt_One_Edge(d_st->v[i],d_st,d_st->b[i],gt,st); - Mg_Map_St_Nodes_In_Gt_Pre(d_st,d_st->v[i],gt,st); - } - } - } -} - -/*********************************************************/ - -void Mg_Map_St_Nodes_In_Gt_One_Edge(node *a_st, node *d_st, edge *b_st, arbre *gt, superarbre *st) -{ - if(d_st->tax) - { -#ifdef DEBUG - if(b_st->rght != d_st) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } -#endif - - st->map_st_node_in_gt[gt->dp][d_st->num][0][0] = st->match_st_node_in_gt[gt->dp][d_st->num]; - } - else - { - node **list_of_nodes_d, **list_of_nodes_v1, **list_of_nodes_v2; - int dir1, dir2; - int i; - - list_of_nodes_d = NULL; - list_of_nodes_v1 = NULL; - list_of_nodes_v2 = NULL; - - dir1 = dir2 = -1; - For(i,3) - { - if(d_st->v[i] != a_st) (dir1 < 0)?(dir1 = i):(dir2 = i); - else list_of_nodes_d = st->map_st_node_in_gt[gt->dp][d_st->num][i]; - } - - For(i,3) - if((d_st->v[dir1]->v[i]) && (d_st->v[dir1]->v[i] == d_st)) - { - list_of_nodes_v1 = st->map_st_node_in_gt[gt->dp][d_st->v[dir1]->num][i]; - break; - } - - For(i,3) - if((d_st->v[dir2]->v[i]) && (d_st->v[dir2]->v[i] == d_st)) - { - list_of_nodes_v2 = st->map_st_node_in_gt[gt->dp][d_st->v[dir2]->num][i]; - break; - } - - /* d_st matches one node in gt */ - if(st->match_st_node_in_gt[gt->dp][d_st->num]) - { - list_of_nodes_d[0] = st->match_st_node_in_gt[gt->dp][d_st->num]; - list_of_nodes_d[1] = NULL; - } - else - { - /* list_of_nodes = union of list_of_nodes_v1 & list_of_nodes_v2 */ - - if(!list_of_nodes_v1[0]) - { - list_of_nodes_d[0] = list_of_nodes_v2[0]; - list_of_nodes_d[1] = list_of_nodes_v2[1]; - } - else if(!list_of_nodes_v2[0]) - { - list_of_nodes_d[0] = list_of_nodes_v1[0]; - list_of_nodes_d[1] = list_of_nodes_v1[1]; - } - else - { - list_of_nodes_d[0] = list_of_nodes_v1[0]; - list_of_nodes_d[1] = list_of_nodes_v2[0]; - - if(list_of_nodes_v1[1] || list_of_nodes_v2[1]) - { - Print_Node(st->tree->noeud[0], - st->tree->noeud[0]->v[0], - st->tree); - - printf("\n\n--------------------------\n\n"); - Print_Node(gt->noeud[0], - gt->noeud[0]->v[0], - gt); - - printf("\n\n--------------------------\n\n"); - - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - } - } - } -} - -/*********************************************************/ - -void Mg_Map_St_Edges_In_Gt(arbre *gt, superarbre *st) -{ - int i,j; - edge *st_b; - node *gt_a, *gt_d; - - gt_a = NULL; - gt_d = NULL; - - For(i,2*st->tree->n_otu-3) st->map_st_edge_in_gt[gt->dp][i] = NULL; - - For(i,2*st->tree->n_otu-3) - { - st_b = st->tree->t_edges[i]; - - if(!st->map_st_node_in_gt[gt->dp][st_b->left->num][st_b->l_r][0]) - { - gt_a = st->map_st_node_in_gt[gt->dp][st_b->rght->num][st_b->r_l][0]; - gt_d = st->map_st_node_in_gt[gt->dp][st_b->rght->num][st_b->r_l][1]; - - For(j,3) - { - if((gt_a->v[j]) && (gt_a->v[j] == gt_d)) - { - st->map_st_edge_in_gt[gt->dp][st_b->num] = gt_a->b[j]; - break; - } - } - } - else if(!st->map_st_node_in_gt[gt->dp][st_b->rght->num][st_b->r_l][0]) - { - gt_a = st->map_st_node_in_gt[gt->dp][st_b->left->num][st_b->l_r][0]; - gt_d = st->map_st_node_in_gt[gt->dp][st_b->left->num][st_b->l_r][1]; - - For(j,3) - { - if((gt_a->v[j]) && (gt_a->v[j] == gt_d)) - { - st->map_st_edge_in_gt[gt->dp][st_b->num] = gt_a->b[j]; - break; - } - } - } - else - { - gt_a = st->map_st_node_in_gt[gt->dp][st_b->left->num][st_b->l_r][0]; - gt_d = st->map_st_node_in_gt[gt->dp][st_b->rght->num][st_b->r_l][0]; - - #ifdef DEBUG - if((!gt_a) || (!gt_d)) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - #endif - - For(j,3) - { - if((gt_a->v[j]) && (gt_a->v[j] == gt_d)) - { - st->map_st_edge_in_gt[gt->dp][st_b->num] = gt_a->b[j]; - break; - } - } - } - } -} - -/*********************************************************/ - -void Mg_Map_Gt_Edges_In_St(arbre *gt, superarbre *st) -{ - int i; - edge *st_b, *gt_b; - - For(i,2*st->tree->n_otu-3) st->size_map_gt_edge_in_st[gt->dp][i] = 0; - - st_b = NULL; - gt_b = NULL; - For(i,2*st->tree->n_otu-3) - { - st_b = st->tree->t_edges[i]; - gt_b = st->map_st_edge_in_gt[gt->dp][st_b->num]; - - if(gt_b) - { - st->map_gt_edge_in_st[gt->dp][gt_b->num][st->size_map_gt_edge_in_st[gt->dp][gt_b->num]] = st_b; - st->size_map_gt_edge_in_st[gt->dp][gt_b->num]++; - } - } -} - -/*********************************************************/ - -int Mg_Pars(superarbre *st) -{ - int i; - - st->tree->c_pars = 0; - For(i,st->n_gt) - { - st->treelist->tree[i]->both_sides = 1; - Pars(st->treelist->tree[i]); -/* printf("\n. Tree %3d pars = %d",i+1,st->treelist->tree[i]->c_pars); */ - st->tree->c_pars += st->treelist->tree[i]->c_pars; - } - - return st->tree->c_pars; -} - -/*********************************************************/ - -int Mg_Spr(phydbl init_lnL, superarbre *st) -{ - int gt; - int i; - edge *target, *pruned; - int move,best_move; - node *gt_a, *gt_d; - - st->tree->root = st->tree->noeud[0]; - st->tree->both_sides = 1; - pruned = NULL; - target = NULL; - move = -2; - gt_a = NULL; - gt_d = NULL; - - - For(i,2*st->tree->n_otu-3) - { - pruned = st->tree->t_edges[i]; - st->tree->n_moves = 0; - - Reset_Spr_List(st->tree); - For(gt,st->n_gt) Reset_Spr_List(st->treelist->tree[gt]); - - if(!pruned->rght->tax) - { - For(gt,st->n_gt) - { - /* Check constraints at prune site on gt tree */ - gt_a = st->map_st_node_in_gt[gt][pruned->rght->num][pruned->r_l][0]; - gt_d = st->map_st_node_in_gt[gt][pruned->left->num][pruned->l_r][0]; - - if((gt_a) && (gt_d) && (!st->map_st_edge_in_gt[gt][pruned->num]->rght->tax)) - { - Test_All_Spr_Targets(st->map_st_edge_in_gt[gt][pruned->num], - st->map_st_edge_in_gt[gt][pruned->num]->rght, - st->treelist->tree[gt]); - } - } - } - - if(!pruned->left->tax) - { - For(gt,st->n_gt) - { - /* Check constraints at prune site on gt tree */ - gt_a = st->map_st_node_in_gt[gt][pruned->rght->num][pruned->r_l][0]; - gt_d = st->map_st_node_in_gt[gt][pruned->left->num][pruned->l_r][0]; - - if((gt_a) && (gt_d) && (!st->map_st_edge_in_gt[gt][pruned->num]->left->tax)) - { - Test_All_Spr_Targets(st->map_st_edge_in_gt[gt][pruned->num], - st->map_st_edge_in_gt[gt][pruned->num]->left, - st->treelist->tree[gt]); - } - } - } - - - if(!pruned->left->tax) - { - Mg_Test_All_Spr_Targets(st->tree->t_edges[i], - st->tree->t_edges[i]->left, - st); - } - - if(!pruned->rght->tax) - { - Mg_Test_All_Spr_Targets(st->tree->t_edges[i], - st->tree->t_edges[i]->rght, - st); - } - - - if(st->tree->n_moves) - { - best_move = Mg_Test_List_Of_Regraft_Pos(st->tree->spr_list, - (int)ceil(0.1*(st->tree->n_moves)), - st); - - if(st->tree->spr_list[best_move]->lnL > init_lnL) - { - Mg_Try_One_Spr_Move(st->tree->spr_list[best_move],st); - } - else - { - st->tree->both_sides = 1; - st->tree->c_lnL = Mg_Lk(st); - st->tree->c_pars = Mg_Pars(st); - } - } - } - return 1; -} - -/*********************************************************/ - -void Mg_Speed_Spr(superarbre *st) -{ - int step; - int gt; - phydbl old_lnL; - - Make_Spr_List(st->tree); - For(gt,st->n_gt) Make_Spr_List(st->treelist->tree[gt]); - - st->tree->both_sides = 1; - For(gt,st->n_gt) - { - st->treelist->tree[gt]->both_sides = 1; - Record_Br_Len(st->treelist->tree[gt]); - } - - st->tree->c_pars = Mg_Pars(st); - st->tree->c_lnL = Mg_Lk(st); - - - st->tree->best_lnL = st->tree->c_lnL; - old_lnL = st->tree->c_lnL; - step = 0; - do - { - ++step; - - printf("\n. Starting a SPR cycle... \n"); - - old_lnL = st->tree->c_lnL; - - st->tree->n_improvements = 0; - st->tree->perform_spr_right_away = 1; - Mg_Spr(UNLIKELY,st); - - - time(&(st->tree->t_current)); - printf("\n. (%5d sec) [00] [%10.2f] [%5d]\n", - (int)(st->tree->t_current-st->tree->t_beg), - Mg_Lk(st),Mg_Pars(st)); - - /* Optimise parameters of the Markov model */ - For(gt,st->n_gt) Optimiz_All_Free_Param(st->treelist->tree[gt], - st->treelist->tree[gt]->mod->s_opt->print); - - time(&(st->tree->t_current)); - printf("\n. (%5d sec) [ 0] [%10.2f] [%5d]\n", - (int)(st->tree->t_current-st->tree->t_beg), - Mg_Lk(st),Mg_Pars(st)); - - /* Optimise branch lengths */ - For(gt,st->n_gt) - { - Optimize_Br_Len_Serie(st->treelist->tree[gt]->noeud[0], - st->treelist->tree[gt]->noeud[0]->v[0], - st->treelist->tree[gt]->noeud[0]->b[0], - st->treelist->tree[gt], - st->treelist->tree[gt]->data); - } - - - /* Update partial likelihoods & parsimony */ - st->tree->both_sides = 1; - st->tree->c_pars = Mg_Pars(st); - st->tree->c_lnL = Mg_Lk(st); - - - time(&(st->tree->t_current)); - printf("\n. (%5d sec) [**] [%10.2f] [%5d]\n", - (int)(st->tree->t_current-st->tree->t_beg), - st->tree->c_lnL,st->tree->c_pars); - - /* Record the current best log-likleihood */ - st->tree->best_lnL = st->tree->c_lnL; - - if(st->tree->c_lnL < old_lnL) - { - printf("\n. old_lnL = %f c_lnL = %f\n",old_lnL,st->tree->c_lnL); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - - /* Record the current best branch lengths */ - For(gt,st->n_gt) Record_Br_Len(st->treelist->tree[gt]); - - /* Exit if no improvements after complete optimization */ - if((!st->tree->n_improvements) || - (fabs(old_lnL-st->tree->c_lnL) < st->tree->mod->s_opt->min_diff_lk_global)) break; - - }while(1); - -} - -/*********************************************************/ - - -void Mg_Test_All_Spr_Targets(edge *pruned, node *n_link, superarbre *st) -{ - int i,j; - - For(i,3) - { - if(n_link->b[i] != pruned) - { - For(j,3) - { - if((n_link->v[i]->v[j]) && (n_link->v[i]->v[j] != n_link)) - { - Mg_Test_One_Spr_Target_Recur(n_link->v[i],n_link->v[i]->v[j],n_link->v[i]->b[j],pruned,n_link,st); - } - } - } - } -} - -/*********************************************************/ - -void Mg_Test_One_Spr_Target_Recur(node *a, node *d, edge *target, edge *pruned, node *n_link, superarbre *st) -{ - - Mg_Test_One_Spr_Target(pruned,target,n_link,st); - - if(d->tax) return; - else - { - int i; - - For(i,3) - if(d->v[i] != a) - { - Mg_Test_One_Spr_Target_Recur(d,d->v[i],d->b[i],pruned,n_link,st); - } - } -} - -/*********************************************************/ - -void Mg_Test_One_Spr_Target(edge *st_p, edge *st_t, node *n_link, superarbre *st) -{ - int gt, move; - - st->tree->n_moves++; - st->tree->spr_list[st->tree->size_spr_list]->b_target = st_t; - st->tree->spr_list[st->tree->size_spr_list]->n_link = n_link; - st->tree->spr_list[st->tree->size_spr_list]->n_opp_to_link = (n_link == st_p->left)?(st_p->rght):(st_p->left); - st->tree->spr_list[st->tree->size_spr_list]->b_opp_to_link = st_p; - st->tree->spr_list[st->tree->size_spr_list]->pars = 0; - - For(gt,st->n_gt) - { - move = Map_Spr_Move(st_p,st_t,n_link,st->treelist->tree[gt],st); - - if(move > -1) - st->tree->spr_list[st->tree->size_spr_list]->pars += st->treelist->tree[gt]->spr_list[move]->pars; - else if(move == -1 || move == -2) - st->tree->spr_list[st->tree->size_spr_list]->pars += st->treelist->tree[gt]->c_pars; - } - - Include_One_Spr_To_List_Of_Spr(st->tree->spr_list[st->tree->size_spr_list],st->tree); -} - -/*********************************************************/ - -int Map_Spr_Move(edge *st_pruned, edge *st_target, node *st_link, arbre *gt, superarbre *st) -{ - int i; - edge *gt_pruned, *gt_target; - node *gt_link, *gt_a, *gt_d; - - gt_pruned = NULL; - gt_target = NULL; - gt_link = NULL; - gt_a = NULL; - gt_d = NULL; - - /* Check contraints at prune and regraft sites on the gt tree */ - - /* st_pruned is not on a path that matches a branch in gt */ - gt_a = st->map_st_node_in_gt[gt->dp][st_pruned->left->num][st_pruned->l_r][0]; - gt_d = st->map_st_node_in_gt[gt->dp][st_pruned->rght->num][st_pruned->r_l][0]; - - if((!gt_a) || (!gt_d)) return -1; - else - { - /* which gt nodes matches st_link ? */ - gt_link = (st_pruned->left == st_link)?(gt_a):(gt_d); - - if(gt_link->tax) return -1; - else - { - gt_pruned = st->map_st_edge_in_gt[gt->dp][st_pruned->num]; - gt_target = st->map_st_edge_in_gt[gt->dp][st_target->num]; - - if((gt_pruned->left == gt_target->left) || - (gt_pruned->left == gt_target->rght) || - (gt_pruned->rght == gt_target->left) || - (gt_pruned->rght == gt_target->rght)) return -1; - else - { - For(i,gt->size_spr_list) - { - if((gt_pruned == gt->spr_list[i]->b_opp_to_link) && (gt_target == gt->spr_list[i]->b_target)) - return i; - } - } - } - } - return -2; -} - -/*********************************************************/ - -int Mg_Test_List_Of_Regraft_Pos(spr **st_spr_list, int list_size, superarbre *st) -{ - - int i,j,best_move; - spr *move; - edge *init_target, *b_residual; - phydbl best_lnL, init_lnL; - int dir_v0, dir_v1, dir_v2; - int gt; - int move_num; - - - best_lnL = UNLIKELY; - init_target = b_residual = NULL; - best_move = -1; - -#ifdef DEBUG - if(!list_size) - { - printf("\n\n. List size is 0 !"); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } -#endif - - init_lnL = UNLIKELY; - - For(i,list_size) - { - st->tree->spr_list[i]->lnL = .0; - - For(gt,st->n_gt) - { - move_num = Map_Spr_Move(st->tree->spr_list[i]->b_opp_to_link, - st->tree->spr_list[i]->b_target, - st->tree->spr_list[i]->n_link, - st->treelist->tree[gt],st); - - if(move_num > -1) - { - move = st->treelist->tree[gt]->spr_list[move_num]; - - if(move->b_target) - { - init_lnL = st->treelist->tree[gt]->c_lnL; - - /* Record edge lengths */ - Record_Br_Len(st->treelist->tree[gt]); - - /* Prune subtree */ - Prune_Subtree(move->n_link, - move->n_opp_to_link, - &init_target, - &b_residual, - st->treelist->tree[gt]); - - /* Rough optimisation of the branch length */ - Fast_Br_Len(init_target,st->treelist->tree[gt]); - - /* Update the change proba matrix at prune position */ - Update_PMat_At_Given_Edge(init_target,st->treelist->tree[gt]); - - /* Update partial likelihood along the path from the prune to - the regraft position */ - Update_P_Lk_Along_A_Path(move->path,move->depth_path,st->treelist->tree[gt]); - - /* Regraft subtree */ - Graft_Subtree(move->b_target,move->n_link,b_residual,st->treelist->tree[gt]); - - /* Estimate the three edge lengths at the regraft site */ - Triple_Dist(move->n_link,st->treelist->tree[gt]); - - /* Update the transition proba matrices along edges defining - the regraft site */ - For(j,3) - if(move->n_link->v[j] != move->n_opp_to_link) - Update_PMat_At_Given_Edge(move->n_link->b[j],st->treelist->tree[gt]); - - /* Compute the likelihood */ - Update_P_Lk(st->treelist->tree[gt], - move->b_opp_to_link, - move->n_link); - - move->lnL = Lk_At_Given_Edge(move->b_opp_to_link,st->treelist->tree[gt]); - - - st->tree->spr_list[i]->lnL += move->lnL; - - /* Record branch lengths */ - dir_v1 = dir_v2 = dir_v0 = -1; - For(j,3) - { - if(move->n_link->v[j] == move->n_opp_to_link) dir_v0 = j; - else if(dir_v1 < 0) dir_v1 = j; - else dir_v2 = j; - } - - move->l0 = move->n_link->b[dir_v0]->l; - - if(move->n_link->v[dir_v1]->num > move->n_link->v[dir_v2]->num) - { - move->l1 = move->n_link->b[dir_v2]->l; - move->l2 = move->n_link->b[dir_v1]->l; - } - else - { - move->l1 = move->n_link->b[dir_v1]->l; - move->l2 = move->n_link->b[dir_v2]->l; - } - - /* Regraft the subtree at its original position */ - Prune_Subtree(move->n_link, - move->n_opp_to_link, - &move->b_target, - &b_residual, - st->treelist->tree[gt]); - - Graft_Subtree(init_target, - move->n_link, - b_residual, - st->treelist->tree[gt]); - - /* Restore branch lengths */ - Restore_Br_Len(st->treelist->tree[gt]); - - /* Update relevant change proba matrices */ - Update_PMat_At_Given_Edge(move->b_target,st->treelist->tree[gt]); - For(j,3) Update_PMat_At_Given_Edge(move->n_link->b[j],st->treelist->tree[gt]); - - /* Update relevant partial likelihoods */ - For(j,3) Update_P_Lk(st->treelist->tree[gt],move->n_link->b[j],move->n_link); - - st->treelist->tree[gt]->c_lnL = init_lnL; - } - } - else - { - st->tree->spr_list[i]->lnL += st->treelist->tree[gt]->c_lnL; - } - } - - if(st->tree->spr_list[i]->lnL > best_lnL) - { - best_lnL = st->tree->spr_list[i]->lnL; - best_move = i; - } - } - - return best_move; - -} - - -/*********************************************************/ - -int Mg_Try_One_Spr_Move(spr *st_move, superarbre *st) -{ - int j; - spr **gt_move; - edge **init_target, **b_residual; - int dir_v0, dir_v1, dir_v2; - int gt; - int gt_move_num; - int n_moves; - - - init_target = (edge **)mCalloc(st->n_gt,sizeof(edge *)); - b_residual = (edge **)mCalloc(st->n_gt,sizeof(edge *)); - gt_move = (spr **)mCalloc(st->n_gt,sizeof(spr *)); - - - n_moves = 0; - For(gt,st->n_gt) - { - gt_move_num = Map_Spr_Move(st_move->b_opp_to_link, - st_move->b_target, - st_move->n_link, - st->treelist->tree[gt],st); - - if(gt_move_num > -1) - { - n_moves++; - - gt_move[gt] = st->treelist->tree[gt]->spr_list[gt_move_num]; - - if(gt_move[gt]->b_target) - { - /* Record edge lengths */ - Record_Br_Len(st->treelist->tree[gt]); - - /* Prune subtree */ - Prune_Subtree(gt_move[gt]->n_link, - gt_move[gt]->n_opp_to_link, - &(init_target[gt]), - &(b_residual[gt]), - st->treelist->tree[gt]); - - /* Rough optimisation of the branch length */ - Fast_Br_Len(init_target[gt],st->treelist->tree[gt]); - - /* Update the change proba matrix at prune position */ - Update_PMat_At_Given_Edge(init_target[gt],st->treelist->tree[gt]); /* TO DO : NECESSARY ?? */ - - /* Update partial likelihood along the path from the prune to - the regraft position */ - Update_P_Lk_Along_A_Path(gt_move[gt]->path,gt_move[gt]->depth_path,st->treelist->tree[gt]); /* TO DO : NECESSARY ?? */ - - /* Regraft subtree */ - Graft_Subtree(gt_move[gt]->b_target,gt_move[gt]->n_link,b_residual[gt],st->treelist->tree[gt]); - - dir_v1 = dir_v2 = dir_v0 = -1; - For(j,3) - { - if(gt_move[gt]->n_link->v[j] == gt_move[gt]->n_opp_to_link) dir_v0 = j; - else if(dir_v1 < 0) dir_v1 = j; - else dir_v2 = j; - } - - gt_move[gt]->n_link->b[dir_v0]->l = gt_move[gt]->l0; - - if(gt_move[gt]->n_link->v[dir_v1]->num > gt_move[gt]->n_link->v[dir_v2]->num) - { - gt_move[gt]->n_link->b[dir_v2]->l = gt_move[gt]->l1; - gt_move[gt]->n_link->b[dir_v1]->l = gt_move[gt]->l2; - } - else - { - gt_move[gt]->n_link->b[dir_v1]->l = gt_move[gt]->l1; - gt_move[gt]->n_link->b[dir_v2]->l = gt_move[gt]->l2; - } - } - } - } - - - if(n_moves) - { - if(st_move->lnL > st->tree->best_lnL) - { - edge *st_target, *st_residual; - - /* Apply the move on the super-tree */ - Prune_Subtree(st_move->n_link, - st_move->n_opp_to_link, - &st_target, - &st_residual, - st->tree); - - Graft_Subtree(st_move->b_target, - st_move->n_link, - st_residual, - st->tree); - - - /* Map gt and st nodes and edges */ - Mg_Do_Mapping(st); - - time(&(st->tree->t_current)); - st->tree->both_sides = 1; - - st->tree->both_sides = 1; - st->tree->c_lnL = Mg_Lk(st); - st->tree->c_pars = Mg_Pars(st); - - - if(fabs(st->tree->c_lnL - st_move->lnL) > st->tree->mod->s_opt->min_diff_lk_local) - { - printf("\n. st->tree->c_lnL = %f st_move->lnL = %f\n", - st->tree->c_lnL,st_move->lnL); - - For(gt,st->n_gt) - { - printf("\n. truth -> %f ; move -> %f", - Return_Lk(st->treelist->tree[gt]), - gt_move[gt] ? gt_move[gt]->lnL : -1.); - } - } - - printf("\n. (%5d sec) [+ ] [%10.2f] [%5d] -- ", - (int)(st->tree->t_current - st->tree->t_beg), - st->tree->c_lnL,st->tree->c_pars); - - For(gt,st->n_gt) - printf("[%10.2f] ",st->treelist->tree[gt]->c_lnL); - - - st->tree->n_improvements++; - st->tree->best_lnL = st->tree->c_lnL; - For(gt,st->n_gt) Record_Br_Len(st->treelist->tree[gt]); - - Free(init_target); - Free(b_residual); - Free(gt_move); - - return 1; - } - else - { - For(gt,st->n_gt) - { - if(gt_move[gt]) - { - Return_Lk(st->treelist->tree[gt]); - Fast_Br_Len_Recur(st->treelist->tree[gt]->noeud[0], - st->treelist->tree[gt]->noeud[0]->v[0], - st->treelist->tree[gt]->noeud[0]->b[0], - st->treelist->tree[gt]); - } - } - - time(&(st->tree->t_current)); - st->tree->both_sides = 1; - st->tree->c_lnL = Mg_Lk(st); - - if(st->tree->c_lnL > st->tree->best_lnL) - { - edge *st_target, *st_residual; - - /* Apply the move on the super-tree */ - Prune_Subtree(st_move->n_link, - st_move->n_opp_to_link, - &st_target, - &st_residual, - st->tree); - - Graft_Subtree(st_move->b_target, - st_move->n_link, - st_residual, - st->tree); - - - /* Map gt and st nodes and edges */ - Mg_Do_Mapping(st); - - - st->tree->c_pars = Mg_Pars(st); - printf("\n. (%5d sec) [++] [%10.2f] [%5d] -- ", - (int)(st->tree->t_current-st->tree->t_beg), - st->tree->c_lnL, - st->tree->c_pars); - For(gt,st->n_gt) - printf("[%10.2f] ",st->treelist->tree[gt]->c_lnL); - - st->tree->n_improvements++; - st->tree->best_lnL = st->tree->c_lnL; - For(gt,st->n_gt) Record_Br_Len(st->treelist->tree[gt]); - - Free(init_target); - Free(b_residual); - Free(gt_move); - - return 1; - } - } - } - - For(gt,st->n_gt) - { - if(gt_move[gt]) - { - /* Regraft the subtree at its original position */ - Prune_Subtree(gt_move[gt]->n_link, - gt_move[gt]->n_opp_to_link, - &(gt_move[gt]->b_target), - &(b_residual[gt]), - st->treelist->tree[gt]); - - Graft_Subtree(init_target[gt], - gt_move[gt]->n_link, - b_residual[gt], - st->treelist->tree[gt]); - - /* Restore branch lengths */ - Restore_Br_Len(st->treelist->tree[gt]); - } - } - - st->tree->both_sides = 1; - st->tree->c_lnL = Mg_Lk(st); - st->tree->c_pars = Mg_Pars(st); - - time(&(st->tree->t_current)); - - printf("\n. (%5d sec) [--] [%10.2f] [%5d] -- ", - (int)(st->tree->t_current - st->tree->t_beg), - st->tree->c_lnL,st->tree->c_pars); - - For(gt,st->n_gt) printf("[%10.2f] ",st->treelist->tree[gt]->c_lnL); - - Free(init_target); - Free(b_residual); - Free(gt_move); - - return 0; - -} - -/*********************************************************/ - -void Mg_NNI(edge *st_b, superarbre *st) -{ - node *v1, *v2, *v3, *v4; - phydbl lk_init; - phydbl lk0_init, lk1_init, lk2_init; - phydbl lk0_opt, lk1_opt, lk2_opt; - int i,j; - double *init_bl; - edge **map_edge_bef_swap, **map_edge_aft_swap; - - - init_bl = (double *)mCalloc(st->n_bl_partition,sizeof(double)); - map_edge_bef_swap = (edge **)mCalloc(st->n_gt,sizeof(edge *)); - map_edge_aft_swap = (edge **)mCalloc(st->n_gt,sizeof(edge *)); - - - v1 = st_b->left->v[st_b->l_v1]; - v2 = st_b->left->v[st_b->l_v2]; - v3 = st_b->rght->v[st_b->r_v1]; - v4 = st_b->rght->v[st_b->r_v2]; - - lk0_init = lk1_init = lk2_init = UNLIKELY; - lk0_opt = lk1_opt = lk2_opt = UNLIKELY; - - if(v1->num < v2->num) - { - Check_Dirs(st->tree); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - - if(v3->num < v4->num) - { - Check_Dirs(st->tree); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - - lk_init = st->tree->c_lnL; - -/* printf("oooooooo\n"); */ -/* Print_Node(st->tree->noeud[0], */ -/* st->tree->noeud[0]->v[0], */ -/* st->tree); */ -/* printf(">>>>>>>\n"); */ -/* For(i,st->n_gt) */ -/* { */ -/* Print_Node(st->treelist->tree[i]->noeud[0], */ -/* st->treelist->tree[i]->noeud[0]->v[0], */ -/* st->treelist->tree[i]); */ -/* printf("<<<<<<<\n"); */ -/* } */ - - - Mg_Record_Br_Len(st); - - For(i,st->n_gt) map_edge_bef_swap[i] = NULL; - For(i,st->n_gt) if(st->map_st_edge_in_gt[i][st_b->num]) map_edge_bef_swap[i] = st->map_st_edge_in_gt[i][st_b->num]; - - /* First alternative topological configuration */ - /* Swap */ - Mg_Swap(v2,st_b->left,st_b->rght,v3,st); - Swap(v2,st_b->left,st_b->rght,v3,st->tree); - Mg_Do_Mapping(st); - Mg_Set_Bl(st->bl,st); - For(i,st->n_gt) map_edge_aft_swap[i] = NULL; - For(i,st->n_gt) if(st->map_st_edge_in_gt[i][st_b->num]) map_edge_aft_swap[i] = st->map_st_edge_in_gt[i][st_b->num]; - For(i,st->n_gt) if(map_edge_bef_swap[i]) Update_PMat_At_Given_Edge(map_edge_bef_swap[i],st->treelist->tree[i]); - For(i,st->n_gt) if(map_edge_aft_swap[i]) Update_PMat_At_Given_Edge(map_edge_aft_swap[i],st->treelist->tree[i]); - For(i,st->n_gt) if(map_edge_bef_swap[i] && map_edge_aft_swap[i]) - { - For(j,3) if((map_edge_aft_swap[i]->left->v[j]) && - (map_edge_aft_swap[i]->left->b[j] == map_edge_bef_swap[i]) && - (map_edge_aft_swap[i] != map_edge_bef_swap[i])) - Update_P_Lk(st->treelist->tree[i], - map_edge_aft_swap[i], - map_edge_aft_swap[i]->left); - For(j,3) if((map_edge_aft_swap[i]->rght->v[j]) && - (map_edge_aft_swap[i]->rght->b[j] == map_edge_bef_swap[i]) && - (map_edge_aft_swap[i] != map_edge_bef_swap[i])) - Update_P_Lk(st->treelist->tree[i], - map_edge_aft_swap[i], - map_edge_aft_swap[i]->rght); - } - lk1_init = Mg_Update_Lk_At_Given_Edge(st_b,st); - lk1_opt = Mg_Br_Len_Brent(st_b,st); - For(i,st->n_gt) st->bl1[st->bl_partition[i]][st_b->num] = st->bl[st->bl_partition[i]][st_b->num]; - /* Unswap */ - Mg_Swap(v3,st_b->left,st_b->rght,v2,st); - Swap(v3,st_b->left,st_b->rght,v2,st->tree); - Mg_Do_Mapping(st); - Mg_Restore_Br_Len(st); - Mg_Set_Bl(st->bl,st); - For(i,st->n_gt) if(map_edge_bef_swap[i]) Update_PMat_At_Given_Edge(map_edge_bef_swap[i],st->treelist->tree[i]); - For(i,st->n_gt) if(map_edge_aft_swap[i]) Update_PMat_At_Given_Edge(map_edge_aft_swap[i],st->treelist->tree[i]); - For(i,st->n_gt) if(map_edge_bef_swap[i] && map_edge_aft_swap[i]) - { - For(j,3) if((map_edge_aft_swap[i]->left->v[j]) && - (map_edge_aft_swap[i]->left->b[j] == map_edge_bef_swap[i]) && - (map_edge_aft_swap[i] != map_edge_bef_swap[i])) - Update_P_Lk(st->treelist->tree[i], - map_edge_aft_swap[i], - map_edge_aft_swap[i]->left); - For(j,3) if((map_edge_aft_swap[i]->rght->v[j]) && - (map_edge_aft_swap[i]->rght->b[j] == map_edge_bef_swap[i]) && - (map_edge_aft_swap[i] != map_edge_bef_swap[i])) - Update_P_Lk(st->treelist->tree[i], - map_edge_aft_swap[i], - map_edge_aft_swap[i]->rght); - } - - - - - /* Second alternative topological configuration */ - /* Swap */ - Mg_Swap(v2,st_b->left,st_b->rght,v4,st); - Swap(v2,st_b->left,st_b->rght,v4,st->tree); - Mg_Do_Mapping(st); - Mg_Set_Bl(st->bl,st); - For(i,st->n_gt) map_edge_aft_swap[i] = NULL; - For(i,st->n_gt) if(st->map_st_edge_in_gt[i][st_b->num]) map_edge_aft_swap[i] = st->map_st_edge_in_gt[i][st_b->num]; - For(i,st->n_gt) if(map_edge_bef_swap[i]) Update_PMat_At_Given_Edge(map_edge_bef_swap[i],st->treelist->tree[i]); - For(i,st->n_gt) if(map_edge_aft_swap[i]) Update_PMat_At_Given_Edge(map_edge_aft_swap[i],st->treelist->tree[i]); - For(i,st->n_gt) if(map_edge_bef_swap[i] && map_edge_aft_swap[i]) - { - For(j,3) if((map_edge_aft_swap[i]->left->v[j]) && - (map_edge_aft_swap[i]->left->b[j] == map_edge_bef_swap[i]) && - (map_edge_aft_swap[i] != map_edge_bef_swap[i])) - Update_P_Lk(st->treelist->tree[i], - map_edge_aft_swap[i], - map_edge_aft_swap[i]->left); - For(j,3) if((map_edge_aft_swap[i]->rght->v[j]) && - (map_edge_aft_swap[i]->rght->b[j] == map_edge_bef_swap[i]) && - (map_edge_aft_swap[i] != map_edge_bef_swap[i])) - Update_P_Lk(st->treelist->tree[i], - map_edge_aft_swap[i], - map_edge_aft_swap[i]->rght); - } - - lk2_init = Mg_Update_Lk_At_Given_Edge(st_b,st); - lk2_opt = Mg_Br_Len_Brent(st_b,st); - For(i,st->n_gt) st->bl2[st->bl_partition[i]][st_b->num] = st->bl[st->bl_partition[i]][st_b->num]; - /* printf("\n. lk2_init = %f lk2_opt = %f",lk2_init,lk2_opt); */ - /* Unswap */ - Mg_Swap(v4,st_b->left,st_b->rght,v2,st); - Swap(v4,st_b->left,st_b->rght,v2,st->tree); - Mg_Do_Mapping(st); - Mg_Restore_Br_Len(st); - Mg_Set_Bl(st->bl,st); - For(i,st->n_gt) if(map_edge_bef_swap[i]) Update_PMat_At_Given_Edge(map_edge_bef_swap[i],st->treelist->tree[i]); - For(i,st->n_gt) if(map_edge_aft_swap[i]) Update_PMat_At_Given_Edge(map_edge_aft_swap[i],st->treelist->tree[i]); - For(i,st->n_gt) if(map_edge_bef_swap[i] && map_edge_aft_swap[i]) - { - For(j,3) if((map_edge_aft_swap[i]->left->v[j]) && - (map_edge_aft_swap[i]->left->b[j] == map_edge_bef_swap[i]) && - (map_edge_aft_swap[i] != map_edge_bef_swap[i])) - Update_P_Lk(st->treelist->tree[i], - map_edge_aft_swap[i], - map_edge_aft_swap[i]->left); - For(j,3) if((map_edge_aft_swap[i]->rght->v[j]) && - (map_edge_aft_swap[i]->rght->b[j] == map_edge_bef_swap[i]) && - (map_edge_aft_swap[i] != map_edge_bef_swap[i])) - Update_P_Lk(st->treelist->tree[i], - map_edge_aft_swap[i], - map_edge_aft_swap[i]->rght); - } - - - /* Back to the initial topological configuration - * and branch lengths. - */ - Mg_Do_Mapping(st); - Mg_Set_Bl(st->bl,st); - Mg_Restore_Br_Len(st); - For(i,st->n_gt) map_edge_aft_swap[i] = NULL; - For(i,st->n_gt) if(st->map_st_edge_in_gt[i][st_b->num]) map_edge_aft_swap[i] = st->map_st_edge_in_gt[i][st_b->num]; - For(i,st->n_gt) if(map_edge_bef_swap[i]) Update_PMat_At_Given_Edge(map_edge_bef_swap[i],st->treelist->tree[i]); - For(i,st->n_gt) if(map_edge_aft_swap[i]) Update_PMat_At_Given_Edge(map_edge_aft_swap[i],st->treelist->tree[i]); - lk0_init = Mg_Update_Lk_At_Given_Edge(st_b,st); - lk0_opt = Mg_Br_Len_Brent(st_b,st); - For(i,st->n_gt) st->bl0[st->bl_partition[i]][st_b->num] = st->bl[st->bl_partition[i]][st_b->num]; - - Mg_Restore_Br_Len(st); - Mg_Set_Bl(st->bl,st); - For(i,st->n_gt) if(map_edge_bef_swap[i]) Update_PMat_At_Given_Edge(map_edge_bef_swap[i],st->treelist->tree[i]); - For(i,st->n_gt) if(map_edge_aft_swap[i]) Update_PMat_At_Given_Edge(map_edge_aft_swap[i],st->treelist->tree[i]); - Mg_Update_Lk_At_Given_Edge(st_b,st); - - - -/* For(i,2*st->tree->n_otu-3) */ -/* printf("\n. 3 Edge %3d --> lnL=%f",i,Mg_Lk_At_Given_Edge(st->tree->t_edges[i],st)); */ - - - - st_b->nni->lk0 = lk0_opt; - st_b->nni->lk1 = lk1_opt; - st_b->nni->lk2 = lk2_opt; - - st_b->nni->score = lk0_opt - MAX(lk1_opt,lk2_opt); - - if((st_b->nni->score < st->tree->mod->s_opt->min_diff_lk_local) && - (st_b->nni->score > -st->tree->mod->s_opt->min_diff_lk_local)) - { - st_b->nni->score = .0; - st_b->nni->lk1 = st_b->nni->lk0; - st_b->nni->lk2 = st_b->nni->lk0; - } - - Mg_Restore_Br_Len(st); - Mg_Update_Lk_At_Given_Edge(st_b,st); /* to replace by Mg_Update_PMat_At_Given_Edge(st_b,st); */ -/* printf("\n. lk_end = %f",st->tree->c_lnL); */ -/* For(i,2*st->tree->n_otu-3) printf("\n. %f",Mg_Lk_At_Given_Edge(st->tree->t_edges[i],st)); */ -/* printf("\n. lk_end = %f",Mg_Lk(st)); */ -/* printf("\n"); */ - -/* printf("\n. Edge %3d, score = %20f",st_b->num,st_b->nni->score); */ - - if(st_b->num == 90) - printf("\n. v1=%d v2=%d v3=%d v4=%d left-%d right-%d", - v1->num, - v2->num, - v3->num, - v4->num, - st_b->left->num, - st_b->rght->num); - - - - if(lk0_opt > MAX(lk1_opt,lk2_opt)) - { - st_b->nni->best_conf = 0; - st_b->nni->swap_node_v1 = NULL; - st_b->nni->swap_node_v2 = NULL; - st_b->nni->swap_node_v3 = NULL; - st_b->nni->swap_node_v4 = NULL; - } - else if(lk1_opt > MAX(lk0_opt,lk2_opt)) - { - st_b->nni->best_conf = 1; - st_b->nni->swap_node_v1 = v2; - st_b->nni->swap_node_v2 = st_b->left; - st_b->nni->swap_node_v3 = st_b->rght; - st_b->nni->swap_node_v4 = v3; - } - else if(lk2_opt > MAX(lk0_opt,lk1_opt)) - { - st_b->nni->best_conf = 2; - st_b->nni->swap_node_v1 = v2; - st_b->nni->swap_node_v2 = st_b->left; - st_b->nni->swap_node_v3 = st_b->rght; - st_b->nni->swap_node_v4 = v4; - } - else - { - st_b->nni->score = +1.0; - st_b->nni->best_conf = 0; - st_b->nni->swap_node_v1 = NULL; - st_b->nni->swap_node_v2 = NULL; - st_b->nni->swap_node_v3 = NULL; - st_b->nni->swap_node_v4 = NULL; - } - - Free(init_bl); - Free(map_edge_aft_swap); - Free(map_edge_bef_swap); -} - -/*********************************************************/ - -void Mg_Swap(node *st_a, node *st_b, node *st_c, node *st_d, superarbre *st) -{ - int i,j; - node *gt_a, *gt_b, *gt_c, *gt_d; - int ab, ba, cd, dc, bc; - - ab = ba = cd = dc = bc = -1; - - For(i,3) if(st_a->v[i] == st_b) { ab = i; break; } - For(i,3) if(st_b->v[i] == st_a) { ba = i; break; } - For(i,3) if(st_c->v[i] == st_d) { cd = i; break; } - For(i,3) if(st_d->v[i] == st_c) { dc = i; break; } - For(i,3) if(st_b->v[i] == st_c) { bc = i; break; } - - if(ab < 0 || ba < 0 || cd < 0 || dc < 0) - { - printf("\n. Nodes %d %d %d %d\n",st_a->num,st_b->num,st_c->num,st_d->num); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - - gt_a = gt_b = gt_c = gt_d = NULL; - - For(i,st->n_gt) - { - gt_b = st->match_st_node_in_gt[i][st_b->num]; - gt_c = st->match_st_node_in_gt[i][st_c->num]; - - if(gt_b && gt_c) /* The st edge with st_b and st_c at its extremities - * matches an edge in gt - */ - { -#ifdef DEBUG - For(j,3) if((gt_b->v[j]) && (gt_b->v[j] == gt_c)) break; - if(j == 3) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } -#endif - gt_a = st->map_st_node_in_gt[i][st_a->num][ab][0]; - gt_d = st->map_st_node_in_gt[i][st_d->num][dc][0]; - Swap(gt_a,gt_b,gt_c,gt_d,st->treelist->tree[i]); - } - } -} - -/*********************************************************/ - -void Mg_Set_Bl(double **bl, superarbre *st) -{ - int i,j; - edge *gt_b; - - gt_b = NULL; - - /* Set all the actual branch lengths to 0.0 - */ - For(i,st->n_gt) - { - For(j,2*st->treelist->tree[i]->n_otu-3) - { - gt_b = st->treelist->tree[i]->t_edges[j]; - gt_b->l = .0; - } - } - - /* Update every branch length - */ - For(i,2*st->tree->n_otu-3) - { - For(j,st->n_gt) - { - gt_b = st->map_st_edge_in_gt[j][i]; - - /* Need to make sure that st->tree->t_edges[i] is on an existing path in gt */ - if((st->map_st_node_in_gt[j][st->tree->t_edges[i]->left->num][st->tree->t_edges[i]->l_r][0]) && - (st->map_st_node_in_gt[j][st->tree->t_edges[i]->rght->num][st->tree->t_edges[i]->r_l][0])) - { - gt_b->l += bl[st->bl_partition[j]][i]; - } - } - } -} - -/*********************************************************/ - -void Mg_Record_Br_Len(superarbre *st) -{ - int i,j; - For(i,st->n_gt) For(j,2*st->tree->n_otu-3) st->bl_cpy[i][j] = st->bl[i][j]; -} - -/*********************************************************/ - -void Mg_Restore_Br_Len(superarbre *st) -{ - int i,j; - For(i,st->n_gt) For(j,2*st->tree->n_otu-3) st->bl[i][j] = st->bl_cpy[i][j]; -} - -/*********************************************************/ - -phydbl Mg_Lk(superarbre *st) -{ - int i; - - Mg_Do_Mapping(st); - Mg_Set_Bl(st->bl,st); - - st->tree->c_lnL = .0; - For(i,st->n_gt) - { - st->treelist->tree[i]->both_sides = 1; - Lk(st->treelist->tree[i]); -/* printf("\n. Tree %3d lnL = %f",i+1,st->treelist->tree[i]->c_lnL); */ - st->tree->c_lnL += st->treelist->tree[i]->c_lnL; - } - return st->tree->c_lnL; -} - -/*********************************************************/ - -phydbl Mg_Lk_At_Given_Edge(edge *st_b, superarbre *st) -{ - int i; - edge *gt_b; - phydbl lnL; - - Mg_Set_Bl(st->bl,st); - - gt_b = NULL; - st->tree->c_lnL = .0; - lnL = .0; - For(i,st->n_gt) - { - gt_b = st->map_st_edge_in_gt[i][st_b->num]; - lnL = Lk_At_Given_Edge(gt_b,st->treelist->tree[i]); - st->tree->c_lnL += lnL; -/* printf("\n. gt %d st edge %d gt edge %d lnL=%f l=%f ",i,st_b->num,gt_b->num,lnL,gt_b->l); */ - } - return st->tree->c_lnL; -} - -/*********************************************************/ - -phydbl Mg_Update_Lk_At_Given_Edge(edge *st_b, superarbre *st) -{ - int i; - edge *gt_b; - - Mg_Set_Bl(st->bl,st); - - gt_b = NULL; - st->tree->c_lnL = .0; - For(i,st->n_gt) - { - gt_b = st->map_st_edge_in_gt[i][st_b->num]; - if(gt_b) st->tree->c_lnL += Update_Lk_At_Given_Edge(gt_b,st->treelist->tree[i]); - else st->tree->c_lnL += st->treelist->tree[i]->c_lnL; - } - return st->tree->c_lnL; -} - - -/*********************************************************/ - -void Mg_Fill_Model_Partitions_Table(superarbre *st) -{ - int i,j; - char *c; - char *abc; - int lig, col; - int n_groups; - int *encountered_vals; - - c = (char *)mCalloc(10,sizeof(char)); - abc = (char *)mCalloc(20,sizeof(char)); - encountered_vals = (int *)mCalloc(st->n_gt,sizeof(int)); - - strcpy(abc,"ABCDEFGHIJKLMNOP\0"); - - printf("\n\n\n"); - lig = col = 0; - while(1) - { - printf("\n\n"); - For(i,st->n_gt) - printf(". Data set %3d : %s\n",i+1,st->optionlist[i]->in_seq_file); - - printf("\n. Data set "); - For(i,st->n_gt) printf("%3d ",i+1); - printf("\n. -A- edge lengths "); - For(i,st->n_gt) printf("%3d ",st->bl_partition[i]); - - if(lig == 1) break; - - printf("\n. (%c-%2d)> ",abc[lig],col+1); - Getstring_Stdin(c); - - switch(lig) - { - case 0 : - { - st->bl_partition[col] = atoi(c); - break; - } - default : - { - break; - } - } - - col++; - - if(col == st->n_gt) - { - col = 0; - lig++; - } - } - - n_groups = 0; - For(i,st->n_gt) - { - For(j,n_groups) - if(encountered_vals[j] == st->bl_partition[i]) - break; - - if(j == n_groups) - { - encountered_vals[n_groups] = st->bl_partition[i]; - n_groups++; - } - st->bl_partition[i] = j; - } - - st->n_bl_partition = n_groups; - - Free(encountered_vals); - Free(c); - Free(abc); -} - -/*********************************************************/ - -phydbl Mg_Br_Len_Brent(edge *st_b, superarbre *st) -{ - int iter, n_iter_max; - phydbl a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; - phydbl e=0.0; - phydbl old_lnL, init_lnL; - phydbl ax, bx, cx; - int bl_part; - phydbl *param; - double tol; - - tol = st->tree->mod->s_opt->min_diff_lk_local; - n_iter_max = 1000; - - For(bl_part,st->n_bl_partition) - { - param = &(st->bl[bl_part][st_b->num]); - - ax = 10.*(*param); - bx = *param; - cx = 0.01*(*param); - - d=0.0; - a=((ax < cx) ? ax : cx); - b=((ax > cx) ? ax : cx); - x=w=v=bx; - old_lnL = UNLIKELY; - (*param) = fabs(bx); - fw=fv=fx=fu=-Mg_Lk_At_Given_Edge(st_b,st); - init_lnL = -fw; - - for(iter=1;iter<=BRENT_ITMAX;iter++) - { - xm=0.5*(a+b); - tol2=2.0*(tol1=tol*fabs(x)+BRENT_ZEPS); - if( - ((fabs(st->tree->c_lnL-old_lnL) < tol) && - (st->tree->c_lnL > init_lnL - tol)) || - (iter > n_iter_max - 1)) - { - (*param)=x; - Mg_Lk_At_Given_Edge(st_b,st); - break; - } - - if(fabs(e) > tol1) - { - r=(x-w)*(fx-fv); - q=(x-v)*(fx-fw); - p=(x-v)*q-(x-w)*r; - q=2.0*(q-r); - if(q > 0.0) p = -p; - q=fabs(q); - etemp=e; - e=d; - if(fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - else - { - d=p/q; - u=x+d; - if (u-a < tol2 || b-u < tol2) - d=SIGN(tol1,xm-x); - } - } - else - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - } - u=(fabs(d) >= tol1 ? x+d : x+SIGN(tol1,d)); - if(utree->c_lnL; - fu=-Mg_Lk_At_Given_Edge(st_b,st); - - /* printf("\n. BRENT edge %3d l=%f lnL=%20f iter=%3d",b_fcus->num,(*param),fu,iter); */ - - if(fu <= fx) - { - if(u >= x) a=x; else b=x; - SHFT(v,w,x,u) - SHFT(fv,fw,fx,fu) - } - else - { - if (u < x) a=u; else b=u; - if (fu <= fw || w == x) - { - v=w; - w=u; - fv=fw; - fw=fu; - } - else if (fu <= fv || v == x || v == w) - { - v=u; - fv=fu; - } - } - } - if(iter > BRENT_ITMAX) printf("\n. Too many iterations in BRENT (%d) (%f)",iter,(*param)); - /* Not Reached ?? *xmin=x; */ - /* Not Reached ?? return fx; */ - } - return st->tree->c_lnL; -} - -/*********************************************************/ - -void Mg_Initialise_Bl_Partition(superarbre *st) -{ - int i,j; - - For(i,st->n_bl_partition) - { - For(j,2*st->tree->n_otu-3) - { - st->bl[i][j] = .1; - } - } -} - -/*********************************************************/ - -void Mg_Optimize_Br_Len_Serie(node *st_a, node *st_d, edge *st_b, superarbre *st) -{ - phydbl lk_init; - int i; - - lk_init = st->tree->c_lnL; - - Mg_Br_Len_Brent(st_b,st); - - if(st->tree->c_lnL < lk_init - st->tree->mod->s_opt->min_diff_lk_local) - { - printf("\n. %f -- %f",lk_init,st->tree->c_lnL); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - - if(st_d->tax) return; - else For(i,3) if(st_d->v[i] != st_a) - { - Mg_Update_P_Lk(st_d->b[i],st_d,st); - Mg_Optimize_Br_Len_Serie(st_d,st_d->v[i],st_d->b[i],st); - } - - For(i,3) if((st_d->v[i] == st_a) && (!st_d->v[i]->tax)) Mg_Update_P_Lk(st_d->b[i],st_d,st); - -} - -/*********************************************************/ - -void Mg_Update_P_Lk(edge *st_b, node *st_n, superarbre *st) -{ - int i,dir; - - dir = -1; - For(i,3) if((st_n->b[i]) && (st_n->b[i] == st_b)) {dir = i; break;} - - if(dir < 0) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - - For(i,st->n_gt) - { - if((st->map_st_node_in_gt[i][st_n->num][dir][0]) && (!st->map_st_node_in_gt[i][st_n->num][dir][0]->tax)) - { - Update_P_Lk(st->treelist->tree[i], - st->map_st_edge_in_gt[i][st_b->num], - st->map_st_node_in_gt[i][st_n->num][dir][0]); - } - } -} - -/*********************************************************/ - -void Mg_Make_N_Swap(edge **st_b, int beg, int end, superarbre *st) -{ - int i; - - st->tree->n_swap = 0; - for(i=beg;ileft->tax || st_b[i]->rght->tax) - { - printf("\n. Edge %d is external.",st_b[i]->num); - printf("\n. Err in file %s at line %d.",__FILE__,__LINE__); - Warn_And_Exit(""); - } - - Mg_Swap(st_b[i]->nni->swap_node_v2->v[st->tree->t_dir[st_b[i]->nni->swap_node_v2->num][st_b[i]->nni->swap_node_v1->num]], - st_b[i]->nni->swap_node_v2, - st_b[i]->nni->swap_node_v3, - st_b[i]->nni->swap_node_v3->v[st->tree->t_dir[st_b[i]->nni->swap_node_v3->num][st_b[i]->nni->swap_node_v4->num]], - st); - - Swap(st_b[i]->nni->swap_node_v2->v[st->tree->t_dir[st_b[i]->nni->swap_node_v2->num][st_b[i]->nni->swap_node_v1->num]], - st_b[i]->nni->swap_node_v2, - st_b[i]->nni->swap_node_v3, - st_b[i]->nni->swap_node_v3->v[st->tree->t_dir[st_b[i]->nni->swap_node_v3->num][st_b[i]->nni->swap_node_v4->num]], - st->tree); - - Mg_Do_Mapping(st); - - st->tree->n_swap++; - } -} - -/*********************************************************/ - -void Mg_Update_Bl(phydbl fact, superarbre *st) -{ - int i,j; - - For(i,2*st->tree->n_otu-3) - { - For(j,st->n_gt) - st->bl[st->bl_partition[j]][i] = - st->bl_cpy[st->bl_partition[j]][i] + - (st->bl0[st->bl_partition[j]][i] - st->bl_cpy[st->bl_partition[j]][i]) * fact; - } - Mg_Set_Bl(st->bl,st); -} - -/*********************************************************/ - -void Mg_Update_Bl_Swaped(edge **st_b, int n, superarbre *st) -{ - int i,j; - - For(i,n) - { - For(j,st->n_gt) - { - st->bl[st->bl_partition[j]][st_b[i]->num] = - (st_b[i]->nni->best_conf == 1)? - (st->bl1[st->bl_partition[j]][st_b[i]->num]): - (st->bl2[st->bl_partition[j]][st_b[i]->num]); - } - } - Mg_Set_Bl(st->bl,st); -} - -/*********************************************************/ - -void Mg_Do_Mapping(superarbre *st) -{ - int k; - - Fill_Dir_Table(st->tree); - For(k,st->n_gt) - { - Fill_Dir_Table(st->treelist->tree[k]); - Mg_Match_St_Nodes_In_Gt(st->treelist->tree[k],st); - Mg_Match_St_Edges_In_Gt(st->treelist->tree[k],st); - Mg_Map_St_Nodes_In_Gt(st->treelist->tree[k],st); - Mg_Map_St_Edges_In_Gt(st->treelist->tree[k],st); - Mg_Map_Gt_Edges_In_St(st->treelist->tree[k],st); - } -} - -/*********************************************************/ - -void Mg_Print_Bl(superarbre *st) -{ - int i,j; - - For(j,2*st->tree->n_otu-3) - { - printf("\n. edge %4d ",j); - For(i,st->n_bl_partition) - { - printf("%f ",st->bl[i][j]); - } - } -} - -/*********************************************************/ -/*********************************************************/ diff --git a/phyml/mg.h b/phyml/mg.h index 83cb127..63079f9 100644 --- a/phyml/mg.h +++ b/phyml/mg.h @@ -1,58 +1,9 @@ -#ifndef MULTIGENE_H -#define MULTIGENE_H +#include + +#ifndef PART_H +#define PART_H #include "utilities.h" -void Menu_Supertree(option *input); -void Mg_Print_Nodes(node *a, node *d, superarbre *st); -superarbre *Mg_Make_Superarbre_Light(option *input); -void Mg_Make_Superarbre_Full(superarbre *st, option *input, allseq **data); -void Mg_Get_List_Of_Reachable_Tips(node *a, node *d, allseq **data, superarbre *st); -void Mg_Get_List_Of_Reachable_Tips_Pre(node *a, node *d, superarbre *st); -void Mg_Get_List_Of_Reachable_Tips_Post(node *a, node *d, superarbre *st); -void Mg_Prune_St_Topo(arbre *tree, allseq *data, superarbre *st); -void Mg_Match_St_Nodes_In_Gt_Recurr(node *a_gt, node *d_gt, node *a_st, node *d_st, arbre *gt, superarbre *st); -void Mg_Match_St_Nodes_In_Gt(arbre *tree, superarbre *st); -void Mg_Match_St_Edges_In_Gt(arbre *gt, superarbre *st); -void Mg_Match_St_Edges_In_Gt_Recurr(node *a, node *d, node *a_st, node *d_st, arbre *gt, superarbre *st); -void Mg_Simu(superarbre *tr); -int Mg_Mov_Backward_Topo_Bl(superarbre *st, phydbl lk_old, edge **tested_b, int n_tested); -int Mg_Get_Species_Found_In_St(superarbre *st, allseq *data); -void Mg_Map_St_Nodes_In_Gt_Pre(node *a_st, node *d_st, arbre *gt, superarbre *st); -void Mg_Map_St_Nodes_In_Gt_Post(node *a_st, node *d_st, arbre *gt, superarbre *st); -void Mg_Map_St_Nodes_In_Gt(arbre *gt, superarbre *st); -void Mg_Map_St_Nodes_In_Gt_One_Edge(node *a_st, node *d_st, edge *b_st, arbre *gt, superarbre *st); -void Mg_Map_St_Edges_In_Gt(arbre *gt, superarbre *st); -phydbl Mg_Lk(superarbre *st); -int Mg_Pars(superarbre *st); -int Mg_Spr(phydbl init_lnL, superarbre *st); -void Mg_Speed_Spr(superarbre *st); -int Map_Spr_Move(edge *st_pruned, edge *st_target, node *st_link, arbre *gt, superarbre *st); -void Mg_Test_All_Spr_Targets(edge *pruned, node *n_link, superarbre *st); -void Mg_Test_One_Spr_Target_Recur(node *a, node *d, edge *target, edge *pruned, node *n_link, superarbre *st); -void Mg_Test_One_Spr_Target(edge *st_p, edge *st_t, node *n_link, superarbre *st); -int Mg_Test_List_Of_Regraft_Pos(spr **st_spr_list, int list_size, superarbre *st); -int Mg_Try_One_Spr_Move(spr *st_move, superarbre *st); -void Mg_Map_Gt_Edges_In_St(arbre *gt, superarbre *st); -void Mg_NNI(edge *st_b, superarbre *st); -void Mg_Swap(node *st_a, node *st_b, node *st_c, node *st_d, superarbre *st); -void Mg_Set_Bl(double **bl, superarbre *st); -void Mg_Restore_Br_Len(superarbre *st); -void Mg_Record_Br_Len(superarbre *st); -phydbl Mg_Lk_At_Given_Edge(edge *st_b, superarbre *st); -phydbl Mg_Update_Lk_At_Given_Edge(edge *st_b, superarbre *st); -void Mg_Fill_Model_Partitions_Table(superarbre *st); -phydbl Mg_Br_Len_Brent(edge *st_b, superarbre *tree); -void Mg_Initialise_Bl_Partition(superarbre *st); -void Mg_Update_P_Lk(edge *st_b, node *st_n, superarbre *st); -void Mg_Optimize_Br_Len_Serie(node *st_a, node *st_d, edge *st_b, superarbre *st); -void Mg_Update_Bl_Swaped(edge **st_b, int n, superarbre *st); -void Mg_Update_Bl(phydbl fact, superarbre *st); -void Mg_Make_N_Swap(edge **st_b, int beg, int end, superarbre *st); -void Mg_Do_Mapping(superarbre *st); -void Mg_Update_PMat(edge *st_b, superarbre *st); -void Mg_Print_Bl(superarbre *st); -void Mg_Check_Extra_Taxa(superarbre *st); -int MG_main(int argc, char **argv); #endif diff --git a/phyml/mixt.c b/phyml/mixt.c new file mode 100644 index 0000000..61f394b --- /dev/null +++ b/phyml/mixt.c @@ -0,0 +1,3807 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "mixt.h" + +int n_sec1 = 0; + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_All(t_tree *mixt_tree) +{ + t_tree *curr, *next; + int i; + + curr = mixt_tree; + next = mixt_tree->next; + + do + { + MIXT_Chain_String(curr->mod->aa_rate_mat_file,next->mod->aa_rate_mat_file); + MIXT_Chain_String(curr->mod->modelname,next->mod->modelname); + MIXT_Chain_String(curr->mod->custom_mod_string,next->mod->custom_mod_string); + MIXT_Chain_Scalar_Dbl(curr->mod->kappa,next->mod->kappa); + MIXT_Chain_Scalar_Dbl(curr->mod->lambda,next->mod->lambda); + MIXT_Chain_Scalar_Dbl(curr->mod->br_len_mult,next->mod->br_len_mult); + MIXT_Chain_Scalar_Dbl(curr->mod->br_len_mult_unscaled,next->mod->br_len_mult_unscaled); + MIXT_Chain_Scalar_Dbl(curr->mod->mr,next->mod->mr); + MIXT_Chain_Vector_Dbl(curr->mod->Pij_rr,next->mod->Pij_rr); + MIXT_Chain_Vector_Dbl(curr->mod->e_frq->user_b_freq,next->mod->e_frq->user_b_freq); + for(i=0;i<2*mixt_tree->n_otu-1;++i) MIXT_Chain_Scalar_Dbl(curr->a_edges[i]->l,next->a_edges[i]->l); + for(i=0;i<2*mixt_tree->n_otu-1;++i) MIXT_Chain_Scalar_Dbl(curr->a_edges[i]->l_old,next->a_edges[i]->l_old); + for(i=0;i<2*mixt_tree->n_otu-1;++i) MIXT_Chain_Scalar_Dbl(curr->a_edges[i]->l_var,next->a_edges[i]->l_var); + for(i=0;i<2*mixt_tree->n_otu-1;++i) MIXT_Chain_Scalar_Dbl(curr->a_edges[i]->l_var_old,next->a_edges[i]->l_var_old); + MIXT_Chain_Rmat(curr->mod->r_mat,next->mod->r_mat); + MIXT_Chain_RAS(curr->mod->ras,next->mod->ras); + MIXT_Chain_Efrq(curr->mod->e_frq,next->mod->e_frq); + MIXT_Chain_Eigen(curr->mod->eigen,next->mod->eigen); + + curr = next; + next = next->next; + } + while(next); + + MIXT_Chain_Edges(mixt_tree); + MIXT_Chain_Nodes(mixt_tree); + MIXT_Chain_Sprs(mixt_tree); + Make_Rmat_Weight(mixt_tree); + Make_Efrq_Weight(mixt_tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_Edges(t_tree *mixt_tree) +{ + int i; + t_edge *b; + t_tree *tree; + + tree = mixt_tree; + do + { + for(i=0;i<2*tree->n_otu-1;++i) + { + b = tree->a_edges[i]; + + if(tree->next) b->next = tree->next->a_edges[i]; + if(tree->prev) b->prev = tree->prev->a_edges[i]; + if(tree->next_mixt) b->next_mixt = tree->next_mixt->a_edges[i]; + if(tree->prev_mixt) b->prev_mixt = tree->prev_mixt->a_edges[i]; + } + + if(tree->e_root != NULL) + { + b = tree->e_root; + + if(tree->next) b->next = tree->next->e_root; + if(tree->prev) b->prev = tree->prev->e_root; + if(tree->next_mixt) b->next_mixt = tree->next_mixt->e_root; + if(tree->prev_mixt) b->prev_mixt = tree->prev_mixt->e_root; + } + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_Nodes(t_tree *mixt_tree) +{ + int i; + t_node *n; + t_tree *tree; + + tree = mixt_tree; + do + { + for(i=0;i<2*tree->n_otu-2;++i) + { + n = tree->a_nodes[i]; + + if(tree->next) n->next = tree->next->a_nodes[i]; + if(tree->prev) n->prev = tree->prev->a_nodes[i]; + if(tree->next_mixt) n->next_mixt = tree->next_mixt->a_nodes[i]; + if(tree->prev_mixt) n->prev_mixt = tree->prev_mixt->a_nodes[i]; + } + + if(tree->n_root != NULL) + { + n = tree->n_root; + if(tree->next) n->next = tree->next->n_root; + if(tree->prev) n->prev = tree->prev->n_root; + if(tree->next_mixt) n->next_mixt = tree->next_mixt->n_root; + if(tree->prev_mixt) n->prev_mixt = tree->prev_mixt->n_root; + } + tree = tree->next; + } + while(tree); +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_Sprs(t_tree *mixt_tree) +{ + int i; + t_tree *tree; + + tree = mixt_tree; + do + { + if(tree->next) tree->best_spr->next = tree->next->best_spr; + if(tree->prev) tree->best_spr->prev = tree->prev->best_spr; + if(tree->next_mixt) tree->best_spr->next_mixt = tree->next_mixt->best_spr; + if(tree->prev_mixt) tree->best_spr->prev_mixt = tree->prev_mixt->best_spr; + + for(i=0;i<2*tree->n_otu-2;++i) + { + if(tree->next) tree->spr_list_one_edge[i]->next = tree->next->spr_list_one_edge[i]; + if(tree->prev) tree->spr_list_one_edge[i]->prev = tree->prev->spr_list_one_edge[i]; + if(tree->next_mixt) tree->spr_list_one_edge[i]->next_mixt = tree->next_mixt->spr_list_one_edge[i]; + if(tree->prev_mixt) tree->spr_list_one_edge[i]->prev_mixt = tree->prev_mixt->spr_list_one_edge[i]; + + if(tree->next) tree->spr_list_all_edge[i]->next = tree->next->spr_list_all_edge[i]; + if(tree->prev) tree->spr_list_all_edge[i]->prev = tree->prev->spr_list_all_edge[i]; + if(tree->next_mixt) tree->spr_list_all_edge[i]->next_mixt = tree->next_mixt->spr_list_all_edge[i]; + if(tree->prev_mixt) tree->spr_list_all_edge[i]->prev_mixt = tree->prev_mixt->spr_list_all_edge[i]; + + } + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_String(t_string *curr, t_string *next) +{ + if(!next) + { + return; + } + else + { + t_string *buff,*last; + + last = NULL; + + /*! Search backward */ + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->prev; + } + + /*! Search forward */ + if(!buff) + { + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->next; + } + } + + + if(!buff) + { + last = curr; + while(last->next) { last = last->next; } + + last->next = next; + next->prev = last; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_Vector_Dbl(vect_dbl *curr, vect_dbl *next) +{ + if(!next) + { + return; + } + else + { + vect_dbl *buff,*last; + + last = NULL; + + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->prev; + } + + /*! Search forward */ + if(!buff) + { + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->next; + } + } + + if(!buff) + { + last = curr; + while(last->next) { last = last->next; } + + last->next = next; + next->prev = last; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_Scalar_Dbl(scalar_dbl *curr, scalar_dbl *next) +{ + if(!next) + { + return; + } + else + { + scalar_dbl *buff, *last; + + last = NULL; + + /*! Search backward */ + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->prev; + } + + /*! Search forward */ + if(!buff) + { + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->next; + } + } + + /*! Not chained yet. Add next at the end of chained list */ + if(!buff) + { + last = curr; + while(last->next) { last = last->next; } + + last->next = next; + next->prev = last; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_Rmat(t_rmat *curr, t_rmat *next) +{ + if(!next) + { + return; + } + else + { + t_rmat *buff, *last; + + last = NULL; + + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->prev; + } + + /*! Search forward */ + if(!buff) + { + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->next; + } + } + + if(!buff) + { + last = curr; + while(last->next) { last = last->next; } + + last->next = next; + next->prev = last; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_Efrq(t_efrq *curr, t_efrq *next) +{ + if(!next) + { + return; + } + else + { + t_efrq *buff,*last; + + last = NULL; + + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->prev; + } + + /*! Search forward */ + if(!buff) + { + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->next; + } + } + + if(!buff) + { + last = curr; + while(last->next) { last = last->next; } + + last->next = next; + next->prev = last; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_Eigen(eigen *curr, eigen *next) +{ + if(!next) + { + return; + } + else + { + eigen *buff,*last; + + last = NULL; + + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->prev; + } + + /*! Search forward */ + if(!buff) + { + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->next; + } + } + + if(!buff) + { + last = curr; + while(last->next) { last = last->next; } + + last->next = next; + next->prev = last; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_RAS(t_ras *curr, t_ras *next) +{ + if(!next) return; + else + { + t_ras *buff,*last; + + last = NULL; + + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->prev; + } + + /*! Search forward */ + if(!buff) + { + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->next; + } + } + + if(!buff) + { + last = curr; + while(last->next) { last = last->next; } + + last->next = next; + next->prev = last; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_Rates(t_rate *curr, t_rate *next) +{ + if(!next) return; + else + { + t_rate *buff,*last; + + last = NULL; + + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->prev; + } + + /*! Search forward */ + if(!buff) + { + buff = curr; + while(buff) + { + if(buff == next) break; + buff = buff->next; + } + } + + if(!buff) + { + last = curr; + while(last->next) { last = last->next; } + + last->next = next; + next->prev = last; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Chain_Cal(t_tree *mixt_tree) +{ + int i; + + for(i=0;irates->n_cal-1;i++) + { + mixt_tree->rates->a_cal[i]->next = mixt_tree->rates->a_cal[i+1]; + mixt_tree->rates->a_cal[i+1]->prev = mixt_tree->rates->a_cal[i]; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Turn_Branches_OnOff_In_All_Elem(int onoff, t_tree *mixt_tree) +{ + t_tree *tree; + + /*! Turn all branches to ON state */ + tree = mixt_tree; + do + { + MIXT_Turn_Branches_OnOff_In_One_Elem(ON,tree); + tree = tree->next_mixt; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Turn_Branches_OnOff_In_One_Elem(int onoff, t_tree *mixt_tree) +{ + int i; + t_tree *tree; + + if(mixt_tree->is_mixt_tree == NO) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } + + tree = mixt_tree; + + do + { + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->l->onoff = onoff; + tree = tree->next; + } + while(tree && tree->is_mixt_tree == NO); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Post_Order_Lk(t_node *mixt_a, t_node *mixt_d, t_tree *mixt_tree) +{ + t_tree *tree; + t_node *a,*d; + + + tree = mixt_tree; + a = mixt_a; + d = mixt_d; + + assert(a); + assert(d); + assert(tree); + + do + { + if(tree->is_mixt_tree) + { + tree = tree->next; + a = a->next; + d = d->next; + } + + assert(a); + assert(d); + assert(tree); + + if(tree->mod->ras->invar == NO) Post_Order_Lk(a,d,tree); + + tree = tree->next; + a = a->next; + d = d->next; + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Pre_Order_Lk(t_node *mixt_a, t_node *mixt_d, t_tree *mixt_tree) +{ + t_tree *tree; + t_node *a,*d; + + tree = mixt_tree; + a = mixt_a; + d = mixt_d; + + assert(a); + assert(d); + assert(tree); + + do + { + if(tree->is_mixt_tree) + { + tree = tree->next; + a = a->next; + d = d->next; + } + + + assert(a); + assert(d); + assert(tree); + + if(tree->mod->ras->invar == NO) Pre_Order_Lk(a,d,tree); + + tree = tree->next; + a = a->next; + d = d->next; + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl MIXT_Lk(t_edge *mixt_b, t_tree *mixt_tree) +{ + t_tree *tree,*cpy_mixt_tree; + t_edge *b,*cpy_mixt_b; + phydbl sum_lnL; + unsigned int site, br, ns; + phydbl *sum_scale_left_cat,*sum_scale_rght_cat; + phydbl sum; + phydbl site_lk_cat,site_lk,log_site_lk,inv_site_lk; + int num_prec_issue; + int ambiguity_check,state; + int l; + phydbl r_mat_weight_sum, e_frq_weight_sum, sum_probas; + phydbl len; + phydbl *expl,*dot_prod; + + tree = NULL; + b = NULL; + expl = NULL; + cpy_mixt_tree = mixt_tree; + cpy_mixt_b = mixt_b; + len = -1.; + ns = 0; + + /* MIXT_Update_Br_Len_Multipliers(mixt_tree->mod); */ + +#if (defined PHYTIME || defined INVITEE || defined PHYREX || defined DATE) + if((mixt_tree->rates) && (mixt_tree->rates->bl_from_rt)) RATES_Update_Cur_Bl(mixt_tree); +#endif + + + /* Update RAS structure (mixt_tree level) */ + tree = mixt_tree; + do + { + Update_RAS(tree->mod); + tree = tree->next_mixt; + } + while(tree); + + /* Update other model structure (tree level) */ + tree = mixt_tree->next; + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + + if(!cpy_mixt_b) + { + if(!Update_Boundaries(tree->mod) || + !Update_Efrq(tree->mod) || + !Update_Eigen(tree->mod)) + { + PhyML_Fprintf(stderr,"\n. move: %s",mixt_tree->mcmc->move_name[mixt_tree->mcmc->move_idx]); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + + tree = tree->next; + } + while(tree); + + + if(!cpy_mixt_b) + { + for(br=0;br<2*mixt_tree->n_otu-3;++br) MIXT_Update_PMat_At_Given_Edge(mixt_tree->a_edges[br],mixt_tree); + + if(mixt_tree->n_root && mixt_tree->ignore_root == NO) + { + MIXT_Update_PMat_At_Given_Edge(mixt_tree->n_root->b[1],mixt_tree); + MIXT_Update_PMat_At_Given_Edge(mixt_tree->n_root->b[2],mixt_tree); + } + } + else + { + MIXT_Update_PMat_At_Given_Edge(mixt_b,mixt_tree); + } + + if(!cpy_mixt_b) + { + if(mixt_tree->n_root != NULL) + { + if(mixt_tree->ignore_root == NO) + { + MIXT_Post_Order_Lk(mixt_tree->n_root,mixt_tree->n_root->v[1],mixt_tree); + MIXT_Post_Order_Lk(mixt_tree->n_root,mixt_tree->n_root->v[2],mixt_tree); + + MIXT_Update_Partial_Lk(mixt_tree,mixt_tree->n_root->b[1],mixt_tree->n_root); + MIXT_Update_Partial_Lk(mixt_tree,mixt_tree->n_root->b[2],mixt_tree->n_root); + + if(mixt_tree->both_sides == YES) + { + MIXT_Pre_Order_Lk(mixt_tree->n_root,mixt_tree->n_root->v[1],mixt_tree); + MIXT_Pre_Order_Lk(mixt_tree->n_root,mixt_tree->n_root->v[2],mixt_tree); + } + } + else + { + MIXT_Post_Order_Lk(mixt_tree->e_root->rght,mixt_tree->e_root->left,mixt_tree); + MIXT_Post_Order_Lk(mixt_tree->e_root->left,mixt_tree->e_root->rght,mixt_tree); + + if(mixt_tree->both_sides == YES) + { + MIXT_Pre_Order_Lk(mixt_tree->e_root->rght,mixt_tree->e_root->left,mixt_tree); + MIXT_Pre_Order_Lk(mixt_tree->e_root->left,mixt_tree->e_root->rght,mixt_tree); + } + } + } + else + { + MIXT_Post_Order_Lk(mixt_tree->a_nodes[0],mixt_tree->a_nodes[0]->v[0],mixt_tree); + if(mixt_tree->both_sides == YES) + { + MIXT_Pre_Order_Lk(mixt_tree->a_nodes[0],mixt_tree->a_nodes[0]->v[0],mixt_tree); + } + } + } + + do /*! Consider each element of the data partition */ + { + mixt_tree->c_lnL = 0.0; + tree = mixt_tree->next; + do + { + tree->c_lnL = 0.0; + tree = tree->next; + } + while(tree && tree->is_mixt_tree == NO); + + Set_Br_Len_Var(mixt_b,mixt_tree); + + if(!cpy_mixt_b) + { + if(mixt_tree->n_root) + { + if(mixt_tree->ignore_root == NO) + mixt_b = (mixt_tree->n_root->v[1]->tax == NO)?(mixt_tree->n_root->b[2]):(mixt_tree->n_root->b[1]); + else + mixt_b = mixt_tree->e_root; + } + else + { + mixt_b = mixt_tree->a_nodes[0]->b[0]; + } + } + + sum_scale_left_cat = (phydbl *)mCalloc(MAX(mixt_tree->mod->ras->n_catg,mixt_tree->mod->n_mixt_classes),sizeof(phydbl)); + sum_scale_rght_cat = (phydbl *)mCalloc(MAX(mixt_tree->mod->ras->n_catg,mixt_tree->mod->n_mixt_classes),sizeof(phydbl)); + + r_mat_weight_sum = MIXT_Get_Sum_Chained_Scalar_Dbl(mixt_tree->next->mod->r_mat_weight); + e_frq_weight_sum = MIXT_Get_Sum_Chained_Scalar_Dbl(mixt_tree->next->mod->e_frq_weight); + sum_probas = MIXT_Get_Sum_Of_Probas_Across_Mixtures(r_mat_weight_sum,e_frq_weight_sum,mixt_tree); + + + b = mixt_b->next; + tree = mixt_tree->next; + do + { + while(tree->mod->ras->invar == YES) + { + tree = tree->next; + b = b->next; + + if(tree == NULL || tree->is_mixt_tree == YES) + { + PhyML_Fprintf(stderr,"\n. %p",(void *)tree); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } + } + + if(tree->update_eigen_lr == YES) Update_Eigen_Lr(b,tree); + + if(tree->use_eigen_lr == YES) + { + len = b->l->v; + len *= tree->mod->br_len_mult->v; + len *= tree->mixt_tree->mod->ras->gamma_rr->v[tree->mod->ras->parent_class_number]; + if(len < tree->mod->l_min) len = tree->mod->l_min; + else if(len > tree->mod->l_max) len = tree->mod->l_max; + expl = tree->expl; + for(l=0;lmod->ns;l++) expl[l] = (phydbl)POW(tree->mod->eigen->e_val[l],len); + } + + tree = tree->next; + b = b->next; + + } + while(tree && tree->is_mixt_tree == NO); + + tree = mixt_tree; + do + { + tree->numerical_warning = NO; + tree = tree->next; + } + while(tree); + + mixt_tree->c_lnL = .0; + + for(site=0;siten_pattern;++site) + { + b = mixt_b->next; + tree = mixt_tree->next; + + /*! Skip calculations if model has zero rate */ + while(tree->mod->ras->invar == YES) + { + tree = tree->next; + b = b->next; + + if(tree == NULL || tree->is_mixt_tree == YES) + { + PhyML_Fprintf(stderr,"\n. %p",(void *)tree); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } + } + + ambiguity_check = -1; + state = -1; + + if((b->rght->tax) && + (!mixt_tree->mod->s_opt->greedy) && + (mixt_tree->data->wght[site] > SMALL)) + { + ambiguity_check = b->rght->c_seq->is_ambigu[site]; + if(!ambiguity_check) state = b->rght->c_seq->d_state[site]; + } + + /*! For all classes in the mixture */ + do + { + if(tree->is_mixt_tree == YES) + { + tree = tree->next; + b = b->next; + } + + ns = tree->mod->ns; + tree->curr_site = site; + tree->apply_lk_scaling = NO; + site_lk_cat = 0.0; + expl = tree->expl; + dot_prod = tree->dot_prod; + + if(!(tree->mod->ras->invar == YES && mixt_tree->is_mixt_tree == YES) && (tree->data->wght[tree->curr_site] > SMALL)) + { + if((b->rght->tax) && (tree->mod->s_opt->greedy == NO)) + { + ambiguity_check = b->rght->c_seq->is_ambigu[tree->curr_site]; + if(ambiguity_check == NO) state = b->rght->c_seq->d_state[tree->curr_site]; + } + + if(tree->use_eigen_lr == YES) + { + site_lk_cat = Lk_Core_Eigen_Lr(expl,dot_prod + site*ns,b,tree); + } + else + { + if(b->rght->tax == YES) + site_lk_cat = Lk_Core(state,ambiguity_check, + b->p_lk_left + site*ns, + b->p_lk_tip_r + site*ns, + b->Pij_rr,b->tPij_rr,b,tree); + else + site_lk_cat = Lk_Core(state,ambiguity_check, + b->p_lk_left + site*ns, + b->p_lk_rght + site*ns, + b->Pij_rr,b->tPij_rr,b,tree); + } + } + + + tree->apply_lk_scaling = YES; + + sum_scale_left_cat[tree->mod->ras->parent_class_number] = + (b->sum_scale_left)? + (b->sum_scale_left[site]): + (0.0); + + sum_scale_rght_cat[tree->mod->ras->parent_class_number] = + (b->sum_scale_rght)? + (b->sum_scale_rght[site]): + (0.0); + + sum = + sum_scale_left_cat[tree->mod->ras->parent_class_number] + + sum_scale_rght_cat[tree->mod->ras->parent_class_number]; + + if(sum > 1024.) + { + /* PhyML_Fprintf(stderr,"\n. Numerical precision issue detected (sum = %g)!!!",sum); */ + sum = 1023.; + tree->mixt_tree->numerical_warning = YES; + tree->numerical_warning = YES; + } + + tree->unscaled_site_lk_cat[site] = site_lk_cat; + + site_lk_cat /= pow(2,sum); + + tree->site_lk_cat[0] = site_lk_cat; + + tree = tree->next; + b = b->next; + } + while(tree && tree->is_mixt_tree == NO); + // done with all trees in the mixture for this partition element. + // All likelihood values are in site_lk_cat[0] + + + tree = mixt_tree->next; + b = mixt_b->next; + site_lk = .0; + + do + { + if(tree->mod->ras->invar == YES) + { + tree = tree->next; + b = b->next; + if(!(tree && tree->is_mixt_tree == NO)) break; + } + + site_lk += + tree->site_lk_cat[0] * + mixt_tree->mod->ras->gamma_r_proba->v[tree->mod->ras->parent_class_number] * + tree->mod->r_mat_weight->v / r_mat_weight_sum * + tree->mod->e_frq_weight->v / e_frq_weight_sum / + sum_probas; + + tree = tree->next; + b = b->next; + } + while(tree && tree->is_mixt_tree == NO); + + + /* Scaling for invariants */ + if(mixt_tree->mod->ras->invar == YES) + { + num_prec_issue = NO; + + tree = mixt_tree->next; + while(tree->mod->ras->invar == NO) + { + tree = tree->next; + if(tree == NULL || tree->is_mixt_tree == YES) + { + PhyML_Fprintf(stderr,"\n. tree: %p",tree); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d",__FILE__,__LINE__); + Exit("\n"); + } + } + + /*! 'tree' will give the correct state frequencies (as opposed to mixt_tree) */ + inv_site_lk = Invariant_Lk(0,site,&num_prec_issue,tree); + + if(num_prec_issue == YES) // inv_site_lk >> site_lk + { + site_lk = inv_site_lk * mixt_tree->mod->ras->pinvar->v; + } + else + { + site_lk = site_lk * (1. - mixt_tree->mod->ras->pinvar->v) + inv_site_lk * mixt_tree->mod->ras->pinvar->v; + } + } + + if(site_lk < SMALL) + { + /* PhyML_Fprintf(stderr,"\n. site = %d",site); */ + /* PhyML_Fprintf(stderr,"\n. invar = %d",mixt_tree->data->invar[site]); */ + /* PhyML_Fprintf(stderr,"\n. mixt = %d",mixt_tree->is_mixt_tree); */ + /* PhyML_Fprintf(stderr,"\n. lk = %G log(lk) = %f < %G",site_lk,log_site_lk,-BIG); */ + /* for(class=0;classmod->ras->n_catg;class++) PhyML_Fprintf(stderr,"\n. rr=%f p=%f",mixt_tree->mod->ras->gamma_rr->v[class],mixt_tree->mod->ras->gamma_r_proba->v[class]); */ + /* PhyML_Fprintf(stderr,"\n. pinv = %G",mixt_tree->mod->ras->pinvar->v); */ + /* PhyML_Fprintf(stderr,"\n. bl mult = %G",mixt_tree->mod->br_len_mult->v); */ + /* PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d.\n",__FILE__,__LINE__); */ + /* Exit("\n"); */ + + site_lk = SMALL; + mixt_tree->numerical_warning = YES; + } + + log_site_lk = log(site_lk); + + + + // ... or using the log-likelihood + if(isinf(site_lk) || isnan(site_lk)) + { + mixt_tree->cur_site_lk[site] = exp(log_site_lk); + } + else + { + mixt_tree->cur_site_lk[site] = site_lk; + } + + + /* Multiply log likelihood by the number of times this site pattern is found in the data */ + mixt_tree->c_lnL_sorted[site] = mixt_tree->data->wght[site]*log_site_lk; + + + mixt_tree->c_lnL += mixt_tree->data->wght[site]*log_site_lk; + + } + + Free(sum_scale_left_cat); + Free(sum_scale_rght_cat); + + mixt_tree = mixt_tree->next_mixt; + mixt_b = mixt_b->next_mixt; + } + while(mixt_tree); + + mixt_tree = cpy_mixt_tree; + mixt_b = cpy_mixt_b; + + sum_lnL = .0; + do + { + sum_lnL += mixt_tree->c_lnL; + mixt_tree = mixt_tree->next_mixt; + } + while(mixt_tree); + + mixt_tree = cpy_mixt_tree; + do + { + mixt_tree->c_lnL = sum_lnL; + mixt_tree = mixt_tree->next_mixt; + } + while(mixt_tree); + + mixt_tree = cpy_mixt_tree; + + return mixt_tree->c_lnL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Update_Partial_Lk(t_tree *mixt_tree, t_edge *mixt_b, t_node *mixt_d) +{ + t_tree *tree; + t_edge *b; + t_node *d; + + tree = mixt_tree; + b = mixt_b; + d = mixt_d; + + do + { + if(tree->is_mixt_tree) + { + tree = tree->next; + b = b->next; + d = d->next; + } + + if(tree->mod->ras->invar == NO) Update_Partial_Lk(tree,b,d); + + tree = tree->next; + b = b->next; + d = d->next; + + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Update_Partial_Pars(t_tree *mixt_tree, t_edge *mixt_b, t_node *mixt_d) +{ + t_tree *tree; + t_edge *b; + t_node *d; + + tree = mixt_tree; + b = mixt_b; + d = mixt_d; + + do + { + if(tree->is_mixt_tree) + { + tree = tree->next; + b = b->next; + d = d->next; + } + + Update_Partial_Pars(tree,b,d); + + tree = tree->next; + b = b->next; + d = d->next; + + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Update_PMat_At_Given_Edge(t_edge *mixt_b, t_tree *mixt_tree) +{ + t_tree *tree; + t_edge *b; + + tree = mixt_tree; + b = mixt_b; + + do + { + if(tree->is_mixt_tree) + { + tree = tree->next; + b = b->next; + } + + if(tree->mod->ras->invar == NO) Update_PMat_At_Given_Edge(b,tree); + + tree = tree->next; + b = b->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int *MIXT_Get_Number_Of_Classes_In_All_Mixtures(t_tree *mixt_tree) +{ + int *n_catg; + t_tree *tree; + int class; + + if(mixt_tree->is_mixt_tree == YES) + { + n_catg = NULL; + tree = mixt_tree; + class = 0; + do + { + if(!class) n_catg = (int *)mCalloc(1,sizeof(int)); + else n_catg = (int *)realloc(n_catg,(class+1)*sizeof(int)); + + tree = tree->next; + + n_catg[class]=0; + do + { + n_catg[class]++; + tree = tree->next; + } + while(tree && tree->is_mixt_tree == NO); + + class++; + } + while(tree); + } + else + { + n_catg = (int *)mCalloc(1,sizeof(int)); + n_catg[0] = mixt_tree->mod->ras->n_catg; + if(mixt_tree->mod->ras->invar == YES) n_catg[0]++; + } + return(n_catg); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_tree **MIXT_Record_All_Mixtures(t_tree *mixt_tree) +{ + t_tree **tree_list; + int n_trees; + t_tree *tree; + + tree_list = NULL; + n_trees = 0; + tree = mixt_tree; + do + { + if(!tree_list) tree_list = (t_tree **)mCalloc(1,sizeof(t_tree *)); + else tree_list = (t_tree **)realloc(tree_list,(n_trees+1)*sizeof(t_tree *)); + + tree_list[n_trees] = tree; + n_trees++; + tree = tree->next; + } + while(tree); + + tree_list = (t_tree **)realloc(tree_list,(n_trees+1)*sizeof(t_tree *)); + tree_list[n_trees] = NULL; + + return(tree_list); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Break_All_Mixtures(int *c_max, t_tree *mixt_tree) +{ + t_tree *tree; + int c,i,n; + + if(mixt_tree->is_mixt_tree == NO) return; + + c = 0; + n = -1; + tree = mixt_tree; + do + { + if(tree->is_mixt_tree == YES) + { + c = 0; + n++; + tree = tree->next; + } + + if(c == (c_max[n]-1) && + tree->next != NULL && + tree->next->is_mixt_tree == NO) + { + if(tree->mixt_tree->next_mixt == NULL) + { + tree->next = NULL; + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->next = NULL; + for(i=0;i<2*tree->n_otu-1;++i) tree->a_nodes[i]->next = NULL; + for(i=0;i<2*tree->n_otu-2;++i) tree->spr_list_one_edge[i]->next = NULL; + } + else + { + tree->next = tree->mixt_tree->next_mixt; + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->next = tree->mixt_tree->next_mixt->a_edges[i]; + for(i=0;i<2*tree->n_otu-1;++i) tree->a_nodes[i]->next = tree->mixt_tree->next_mixt->a_nodes[i]; + for(i=0;i<2*tree->n_otu-2;++i) tree->spr_list_one_edge[i]->next = tree->mixt_tree->next_mixt->spr_list_one_edge[i]; + } + } + + tree = tree->next; + c++; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Reconnect_All_Mixtures(t_tree **tree_list, t_tree *mixt_tree) +{ + t_tree *tree; + int n_trees; + + if(mixt_tree->is_mixt_tree == NO) return; + + tree = mixt_tree; + n_trees = 0; + do + { + tree = tree_list[n_trees]; + if(tree->is_mixt_tree == NO) tree->next = tree_list[n_trees+1]; + n_trees++; + tree = tree->next; + } + while(tree); + + MIXT_Chain_All(mixt_tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int *MIXT_Record_Has_Invariants(t_tree *mixt_tree) +{ + int *has_invariants; + t_tree *tree; + int n_trees; + + has_invariants = NULL; + tree = mixt_tree; + n_trees = 0; + do + { + if(!n_trees) has_invariants = (int *)mCalloc(1,sizeof(int)); + else has_invariants = (int *)realloc(has_invariants,(n_trees+1)*sizeof(int)); + has_invariants[n_trees] = (tree->mod->ras->invar == YES)?1:0; + n_trees++; + tree = tree->next; + } + while(tree); + + return(has_invariants); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Reset_Has_Invariants(int *has_invariants, t_tree *mixt_tree) +{ + t_tree *tree; + int n_trees; + + tree = mixt_tree; + n_trees = 0; + do + { + tree->mod->ras->invar = has_invariants[n_trees]; + n_trees++; + tree = tree->next; + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Check_Invar_Struct_In_Each_Partition_Elem(t_tree *mixt_tree) +{ + if(mixt_tree->is_mixt_tree == NO) return; + else + { + t_tree *tree; + int n_inv; + + n_inv = 0; + tree = mixt_tree; + do + { + if(tree->is_mixt_tree) + { + tree = tree->next; + n_inv = 0; + } + + if(tree->mod->ras->invar == YES) n_inv++; + + if(n_inv > 1) + { + PhyML_Fprintf(stderr,"\n. Found %d classes of the mixture for file '%s' set to",n_inv,tree->mixt_tree->io->in_align_file); + PhyML_Fprintf(stderr,"\n. invariable. Only one such class per mixture is allowed."); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit("\n"); + } + + if(tree->mixt_tree->mod->ras->invar == NO && + tree->mod->ras->invar == YES) + { + PhyML_Fprintf(stderr,"\n. Unexpected settings for 'siterates' in a partition element (file '%s')",tree->mixt_tree->io->in_align_file); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit("\n"); + } + + tree = tree->next; + } + while(tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Check_RAS_Struct_In_Each_Partition_Elem(t_tree *mixt_tree) +{ + if(mixt_tree->is_mixt_tree == NO) return; + else + { + t_tree *tree; + int n_classes; + + n_classes = 0; + tree = mixt_tree; + do + { + if(tree->is_mixt_tree) + { + if(tree->mod->ras->invar == YES) + { + if(tree->next->mod->ras->invar == NO) + { + PhyML_Fprintf(stderr,"\n. The invariant site class has to be the first element in"); + PhyML_Fprintf(stderr,"\n. each component. Please amend you XML"); + PhyML_Fprintf(stderr,"\n. file accordingly.\n"); + Exit("\n."); + } + } + tree = tree->next; + n_classes = 0; + } + + if(tree && tree->mod->ras->invar == NO) n_classes++; + + if((tree->next && tree->next->is_mixt_tree == YES) || (!tree->next)) /*! current tree is the last element of this mixture */ + { + if(n_classes < tree->mixt_tree->mod->ras->n_catg) + { + PhyML_Fprintf(stderr,"\n. %d class%s found in 'partitionelem' for file '%s' while", + n_classes, + (n_classes>1)?"es\0":"\0", + tree->mixt_tree->io->in_align_file); + PhyML_Fprintf(stderr,"\n. the corresponding 'siterates' element defined %d class%s.", + tree->mixt_tree->mod->ras->n_catg, + (tree->mixt_tree->mod->ras->n_catg>1)?"es\0":"\0"); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit("\n"); + } + } + + tree = tree->next; + } + while(tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Prune_Subtree(t_node *mixt_a, t_node *mixt_d, t_edge **mixt_target, t_edge **mixt_residual, t_tree *mixt_tree) +{ + t_node *a,*d; + t_edge *target, *residual; + t_tree *tree; + + MIXT_Turn_Branches_OnOff_In_One_Elem(OFF,mixt_tree); + + tree = mixt_tree; + a = mixt_a; + d = mixt_d; + target = (mixt_target) ? (*mixt_target) : NULL; + residual = (mixt_residual) ? (*mixt_residual) : NULL; + + do + { + if(tree->is_mixt_tree == YES) + { + tree = tree->next; + a = a->next; + d = d->next; + target = target ? target->next : NULL; + residual = residual ? residual->next : NULL; + } + + Prune_Subtree(a,d,&target,&residual,tree); + + tree = tree->next; + a = a->next; + d = d->next; + target = target ? target->next : NULL; + residual = residual ? residual->next : NULL; + } + while(tree && tree->is_mixt_tree == NO); + + if(tree) Prune_Subtree(a,d,&target,&residual,tree); + + /*! Turn branches of this mixt_tree to ON after recursive call + to Prune_Subtree such that, if branches of mixt_tree->next + point to those of mixt_tree, they are set to OFF when calling + Prune */ + MIXT_Turn_Branches_OnOff_In_One_Elem(ON,mixt_tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Graft_Subtree(t_edge *mixt_target, t_node *mixt_link, t_node *mixt_link_daughter, t_edge *mixt_residual, t_node *mixt_target_nd, t_tree *mixt_tree) +{ + t_edge *target,*residual; + t_node *link,*link_daughter,*target_nd; + t_tree *tree; + + MIXT_Turn_Branches_OnOff_In_One_Elem(OFF,mixt_tree); + + tree = mixt_tree; + target = mixt_target; + residual = mixt_residual; + link = mixt_link; + link_daughter = mixt_link_daughter; + target_nd = mixt_target_nd; + + do + { + if(tree->is_mixt_tree == YES) + { + tree = tree->next; + target = target->next; + residual = residual->next; + link = link->next; + link_daughter = link_daughter ? link_daughter->next : NULL; + target_nd = target_nd ? target_nd->next : NULL; + } + + Graft_Subtree(target,link,link_daughter,residual,target_nd,tree); + + tree = tree->next; + target = target->next; + residual = residual->next; + link = link->next; + link_daughter = link_daughter ? link_daughter->next : NULL; + target_nd = target_nd ? target_nd->next : NULL; + } + while(tree && tree->is_mixt_tree == NO); + + if(tree) Graft_Subtree(target,link,link_daughter,residual,target_nd,tree); + + /*! Turn branches of this mixt_tree to ON after recursive call + to Graft_Subtree such that, if branches of mixt_tree->next + point to those of mixt_tree, they are set to OFF when calling + Graft */ + MIXT_Turn_Branches_OnOff_In_One_Elem(ON,mixt_tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Multiply_Scalar_Dbl(scalar_dbl *this, phydbl scalar) +{ + if(this == NULL) return; + else + { + scalar_dbl *buff; + buff = this; + do + { + buff->v *= scalar; + buff = buff->next; + } + while(buff); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Br_Len_Opt(t_edge *mixt_b, t_tree *mixt_tree) +{ + t_edge *b; + t_tree *tree; + scalar_dbl *l; + + MIXT_Turn_Branches_OnOff_In_All_Elem(ON,mixt_tree); + + mixt_tree->ignore_mixt_info = YES; + + b = mixt_b; + tree = mixt_tree; + l = NULL; + + do + { + while(tree->is_mixt_tree == YES) + { + tree = tree->next; + b = b->next; + } + + l = b->l; + do + { + if(l->onoff == ON) + { + Br_Len_Opt(&(l->v),mixt_b,mixt_tree); + l->onoff = OFF; + } + l = l->next; + } + while(l); + + tree = tree->next; + b = b->next; + } + while(tree); + + mixt_tree->ignore_mixt_info = NO; +} + + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void MIXT_Br_Len_Involving_Invar(t_tree *mixt_tree) +{ + int i; + scalar_dbl *l; + + for(i=0;i<2*mixt_tree->n_otu-1;++i) + { + l = mixt_tree->a_edges[i]->l; + do + { + l->v *= (1.-mixt_tree->mod->ras->pinvar->v); + l = l->next; + } + while(l); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Br_Len_Not_Involving_Invar(t_tree *mixt_tree) +{ + int i; + scalar_dbl *l; + + for(i=0;i<2*mixt_tree->n_otu-1;++i) + { + l = mixt_tree->a_edges[i]->l; + do + { + l->v /= (1.-mixt_tree->mod->ras->pinvar->v); + l = l->next; + } + while(l); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl MIXT_Unscale_Br_Len_Multiplier_Tree(t_tree *mixt_tree) +{ + int i; + scalar_dbl *l; + + for(i=0;i<2*mixt_tree->n_otu-1;++i) + { + l = mixt_tree->a_edges[i]->l; + do + { + l->v /= mixt_tree->mod->br_len_mult->v; + l = l->next; + } + while(l); + } + return(-1); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl MIXT_Rescale_Br_Len_Multiplier_Tree(t_tree *mixt_tree) +{ + int i; + scalar_dbl *l; + + for(i=0;i<2*mixt_tree->n_otu-1;++i) + { + l = mixt_tree->a_edges[i]->l; + do + { + l->v *= mixt_tree->mod->br_len_mult->v; + l = l->next; + } + while(l); + } + return(-1); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl MIXT_Rescale_Free_Rate_Tree(t_tree *mixt_tree) +{ + int i,side_effect,at_boundary; + t_edge *b; + + side_effect = NO; + for(i=0;i<2*mixt_tree->n_otu-1;++i) + { + b = mixt_tree->a_edges[i]->next; + + at_boundary = NO; + if(b->l->v > mixt_tree->mod->l_max-1.E-100 && b->l->v < mixt_tree->mod->l_max+1.E-100) at_boundary = YES; + if(b->l->v > mixt_tree->mod->l_min-1.E-100 && b->l->v < mixt_tree->mod->l_min+1.E-100) at_boundary = YES; + + b->l->v *= mixt_tree->mod->ras->free_rate_mr->v; + + if(b->l->v > mixt_tree->mod->l_max && at_boundary == NO) side_effect = YES; + if(b->l->v < mixt_tree->mod->l_min && at_boundary == NO) side_effect = YES; + } + + return side_effect; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Ignore_Root(int yesno, t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + tree->ignore_root = yesno; + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Alias_Subpatt(int onoff, t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + tree->update_alias_subpatt = onoff; + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Check_Edge_Lens_In_All_Elem(t_tree *mixt_tree) +{ + t_tree *tree; + + /*! Check that all the edges in a mixt_tree at pointing + to a single set of lengths + */ + tree = mixt_tree; + do + { + MIXT_Check_Edge_Lens_In_One_Elem(tree); + tree = tree->next_mixt; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Check_Edge_Lens_In_One_Elem(t_tree *mixt_tree) +{ + t_tree *tree; + int i; + + tree = mixt_tree->next; + do + { + if(tree->next && tree->next->is_mixt_tree == NO) + { + for(i=0;i<2*tree->n_otu-1;++i) + { + if(tree->a_edges[i]->l != tree->next->a_edges[i]->l) + { + PhyML_Fprintf(stderr,"\n. %p %p",tree->a_edges[i]->l,tree->next->a_edges[i]->l); + PhyML_Fprintf(stderr,"\n. Only one set of edge lengths is allowed "); + PhyML_Fprintf(stderr,"\n. in a 'partitionelem'. Please fix your XML file."); + Exit("\n"); + } + } + } + tree = tree->next; + } + while(tree && tree->next && tree->next->is_mixt_tree == NO); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int MIXT_Pars(t_edge *mixt_b, t_tree *mixt_tree) +{ + t_edge *b; + t_tree *tree; + + b = mixt_b; + tree = mixt_tree; + mixt_tree->c_pars = 0; + + do + { + if(tree->next) + { + Pars(b?b->next:NULL,tree->next); + mixt_tree->c_pars += tree->next->c_pars; + } + + if(mixt_b != NULL) b = b->next_mixt; + tree = tree->next_mixt; + } + while(tree); + + tree = mixt_tree; + do + { + tree->c_pars = mixt_tree->c_pars; + tree = tree->next_mixt; + } + while(tree); + + return(mixt_tree->c_pars); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Bootstrap(char *best_tree, xml_node *root) +{ + xml_node *n,*p_elem; + char *bootstrap; + + assert(root); + + n = XML_Search_Node_Name("phyml",NO,root); + + bootstrap = XML_Get_Attribute_Value(n,"bootstrap"); + + if(!bootstrap) return; + else + { + int n_boot,i,j,k; + xml_attr *boot_attr,*seqfile_attr,*out_attr,*boot_out_attr; + char *orig_align,*boot_out_file_name,*xml_boot_file_name,*buff; + FILE *boot_fp_in_align,*xml_boot_file_fp; + option *io,*dum; + align **boot_data,**orig_data; + int position,elem; + xml_node *boot_root; + int pid; + char *s; + + orig_align = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + xml_boot_file_name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + strcpy(xml_boot_file_name,"phyml_boot_config."); + pid = (int)getpid(); + sprintf(xml_boot_file_name+strlen(xml_boot_file_name),"%d",pid); + strcat(xml_boot_file_name,".xml"); + + out_attr = XML_Search_Attribute(root,"output.file"); + assert(out_attr); + boot_out_file_name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + strcpy(boot_out_file_name,out_attr->value); + s = XML_Get_Attribute_Value(root,"run.id"); + if(s) + { + strcat(boot_out_file_name,"_"); + strcat(boot_out_file_name,s); + } + + n_boot = atoi(bootstrap); + + io = NULL; + for(i=0;ivalue,"0"); + + /*! Set the output file name for each bootstrap analysis */ + boot_out_attr = XML_Search_Attribute(boot_root,"output.file"); + assert(boot_out_attr); + buff = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + strcpy(buff,boot_out_attr->value); + Free(boot_out_attr->value); + boot_out_attr->value = buff; + sprintf(boot_out_attr->value+strlen(boot_out_attr->value),"_boot.%d",pid); + + p_elem = boot_root; + elem = 0; + do + { + p_elem = XML_Search_Node_Name("partitionelem",YES,p_elem); + if(!p_elem) break; + + io = (option *)Make_Input(); + Set_Defaults_Input(io); + + /*! Get the original sequence file name and the corresponding + attribute in the XML graph + */ + seqfile_attr = NULL; + seqfile_attr = XML_Search_Attribute(p_elem,"file.name"); + assert(seqfile_attr); + + strcpy(orig_align,seqfile_attr->value); + + /*! Open the original sequence file */ + io->fp_in_align = Openfile(orig_align,0); + + /*! Read in the original sequence file */ + orig_data = Get_Seq(io); + rewind(io->fp_in_align); + + /*! Read in the original sequence file and put + it in 'boot_data' structure */ + boot_data = Get_Seq(io); + + fclose(io->fp_in_align); + + /*! Bootstrap resampling: sample from original and put in boot */ + for(j=0;jlen;++j) + { + position = Rand_Int(0,(int)(boot_data[0]->len-1.0)); + for(k=0;kn_otu;++k) boot_data[k]->state[j] = orig_data[k]->state[position]; + } + + /*! Modify the sequence file attribute in the original XML + graph */ + buff = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + Free(seqfile_attr->value); + seqfile_attr->value = buff; + sprintf(seqfile_attr->value,"%s_%d_%d",orig_align,elem,i); + + /*! Open a new sequence file with the modified attribute name */ + boot_fp_in_align = Openfile(seqfile_attr->value,1); + + /*! Print the bootstrap data set in it */ + Print_Seq(boot_fp_in_align,boot_data,io->n_otu); + fclose(boot_fp_in_align); + + Free_Seq(orig_data,io->n_otu); + Free_Seq(boot_data,io->n_otu); + + Free_Input(io); + elem++; + } + while(p_elem); + + /*! Open bootstrap XML file in writing mode */ + xml_boot_file_fp = Openfile(xml_boot_file_name,1); + + /*! Write the bootstrap XML graph */ + XML_Write_XML_Graph(xml_boot_file_fp,boot_root); + fclose(xml_boot_file_fp); + + /*! Reconstruct the tree */ + dum = PhyML_XML(xml_boot_file_name); + Free(dum); + + /*! Remove the bootstrap alignment files */ + p_elem = boot_root; + do + { + p_elem = XML_Search_Node_Name("partitionelem",YES,p_elem); + if(!p_elem) break; + seqfile_attr = XML_Search_Attribute(p_elem,"file.name"); + unlink(seqfile_attr->value); + } + while(p_elem); + + XML_Free_XML_Tree(boot_root); + } + + Free(xml_boot_file_name); + Free(orig_align); + Free(boot_out_file_name); + } + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Pars_Thresh(t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + tree->mod->s_opt->pars_thresh = (tree->io->datatype == AA)?(15):(5); + tree = tree->next_mixt; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl MIXT_Get_Mean_Edge_Len(t_edge *mixt_b, t_tree *mixt_tree) +{ + phydbl sum; + int n; + t_tree *tree; + t_edge *b; + + if(mixt_tree->is_mixt_tree == NO) return mixt_b->l->v; + + b = mixt_b; + tree = mixt_tree; + sum = .0; + n = 0 ; + do + { + if(tree->is_mixt_tree == YES) + { + tree = tree->next; + b = b->next; + } + + sum += b->l->v * (tree->mixt_tree ? tree->mixt_tree->mod->br_len_mult->v : 1.0); + n++; + b = b->next; + tree = tree->next; + } + while(b); + + return(sum / (phydbl)n); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl MIXT_Get_Sum_Chained_Scalar_Dbl(scalar_dbl *s) +{ + scalar_dbl *s_buff; + phydbl sum; + + s_buff = s; + sum = .0; + do + { + sum += s_buff->v; + s_buff = s_buff->next; + } + while(s_buff); + + return sum; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl MIXT_Get_Sum_Of_Probas_Across_Mixtures(phydbl r_mat_weight_sum, phydbl e_frq_weight_sum, t_tree *mixt_tree) +{ + t_tree *tree; + phydbl sum; + + sum = .0; + tree = mixt_tree->next; + do + { + // e.g., if mixture has two classes, one of these + // corresponding to invariable sites. We need to skip it. + if(tree->mod->ras->invar == YES) tree = tree->next; + + sum += + mixt_tree->mod->ras->gamma_r_proba->v[tree->mod->ras->parent_class_number] * + tree->mod->r_mat_weight->v / r_mat_weight_sum * + tree->mod->e_frq_weight->v / e_frq_weight_sum; + + + tree = tree->next; + + } + while(tree && tree->is_mixt_tree == NO); + + return(sum); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Br_Len_Var(t_edge *mixt_b, t_tree *mixt_tree) +{ + t_tree *tree; + + if(mixt_b != NULL) + { + t_edge *b; + + tree = mixt_tree->next; + b = mixt_b->next; + + do + { + Set_Br_Len_Var(b,tree); + tree = tree->next; + b = b->next; + } + while(tree); + } + else + { + tree = mixt_tree->next; + + do + { + Set_Br_Len_Var(NULL,tree); + tree = tree->next; + } + while(tree); + + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Br_Len(phydbl val, t_edge *mixt_b, t_tree *mixt_tree) +{ + scalar_dbl *l; + + l = mixt_b->l; + do + { + l->v = val; + l = l->next; + } + while(l); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Add_Root(t_edge *mixt_b, t_tree *mixt_tree) +{ + t_tree *tree; + t_edge *b; + + tree = mixt_tree; + b = mixt_b; + do + { + if(tree->is_mixt_tree) + { + tree = tree->next; + b = b->next; + } + + // Condition is true when tree is not chained + if(b == NULL) break; + + Add_Root(b,tree); + + tree = tree->next; + b = b->next; + } + while(tree); + + tree = mixt_tree; + do + { + assert(tree->n_root != NULL); + + if(tree->next) tree->n_root->next = tree->next->n_root; + if(tree->prev) tree->n_root->prev = tree->prev->n_root; + if(tree->next_mixt) tree->n_root->next_mixt = tree->next_mixt->n_root; + if(tree->prev_mixt) tree->n_root->prev_mixt = tree->prev_mixt->n_root; + + tree = tree->next; + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_RATES_Update_Cur_Bl(t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree->next; + do + { + RATES_Update_Cur_Bl(tree); + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Update_Br_Len_Multipliers(t_mod *mod) +{ + phydbl sum; + t_mod *loc; + int n_mixt; + + loc = mod; + sum = 0.0; + n_mixt = 0; + do + { + /* if(loc->s_opt->opt_br_len_mult == YES) */ + /* { */ + sum += loc->br_len_mult_unscaled->v; + n_mixt++; + /* } */ + loc = loc->next_mixt; + } + while(loc); + + loc = mod; + do + { + if(loc->s_opt->opt_br_len_mult == YES) + { + loc->br_len_mult->v = loc->br_len_mult_unscaled->v / sum; + loc->br_len_mult->v *= (phydbl)(n_mixt); + /* printf("\n. HERE %f %f\n",loc->br_len_mult_unscaled->v,loc->br_len_mult->v); */ + } + loc = loc->next_mixt; + } + while(loc); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Init_Model(t_tree *mixt_tree) +{ + t_mod *mod,*mixt_mod; + option *io; + t_tree *tree; + + assert(mixt_tree); + + mixt_mod = mixt_tree->mod; + io = mixt_tree->io; + + mod = mixt_mod; + do + { + Init_Model(mod->io->cdata,mod,io); + mod = mod->next; + } + while(mod); + + tree = mixt_tree; + do + { + if(tree->next_mixt != NULL) + { + tree->mod->next_mixt = tree->next_mixt->mod; + tree->next_mixt->mod->prev_mixt = tree->mod; + } + tree = tree->next_mixt; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Check_Model_Validity(t_tree *mixt_tree) +{ + // Verify that models associated to distinct data partition elements do not + // share the same empirical character frequencies. + + t_mod *mod_in, *mod_out; + + mod_out = mixt_tree->mod; + + do + { + mod_in = mod_out; + do + { + if(mod_in->io->cdata != mod_out->io->cdata) + { + if(mod_in->e_frq == mod_out->e_frq) + { + if(mod_in->io->datatype == NT && + mod_in->e_frq->user_state_freq == NO && + mod_in->whichmodel != JC69 && + mod_in->whichmodel != K80) + { + PhyML_Fprintf(stderr,"\n. A vector of observed nucleotide frequencies should correspond "); + PhyML_Fprintf(stderr,"\n. to one data set only. If you are using the XML interface, "); + PhyML_Fprintf(stderr,"\n. please amend your file accordingly."); + Exit("\n"); + } + else if(mod_in->io->datatype == AA && mod_in->e_frq->empirical_state_freq == YES) + { + PhyML_Fprintf(stderr,"\n. A vector of observed amino-acid frequencies should correspond "); + PhyML_Fprintf(stderr,"\n. to one data set only. If you are using the XML interface, "); + PhyML_Fprintf(stderr,"\n. please amend your file accordingly."); + Exit("\n"); + } + } + } + mod_in = mod_in->next; + } + while(mod_in); + mod_out = mod_out->next; + } + while(mod_out); + + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_tree *MIXT_Starting_Tree(t_tree *mixt_tree) +{ + t_tree *tree; + + tree = NULL; + + if(mixt_tree->io->mod->s_opt->random_input_tree == NO) + { + switch(mixt_tree->io->in_tree) + { + case 2: // user-defined input tree + { + assert(mixt_tree->io->fp_in_tree); + + tree = Read_User_Tree(mixt_tree->io->cdata, + mixt_tree->mod, + mixt_tree->io); + + break; + } + case 1: case 0: + { + // Build a BioNJ tree from the analysis of + // the first partition element + tree = Dist_And_BioNJ(mixt_tree->data, + mixt_tree->mod, + mixt_tree->io); + break; + } + default : assert(FALSE); + } + } + else + { + tree = Make_Tree_From_Scratch(mixt_tree->n_otu,mixt_tree->data); + Random_Tree(tree); + } + + return tree; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Connect_Cseqs_To_Nodes(t_tree *mixt_tree) +{ + t_tree *tree; + + Copy_Tree(mixt_tree,mixt_tree->next); + + tree = mixt_tree; + do + { + Connect_CSeqs_To_Nodes(tree->data,mixt_tree->io,tree); + tree = tree->next; + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Init_T_Beg(t_tree *mixt_tree) +{ + t_tree *tree; + + /*! Initialize t_beg in each mixture tree */ + tree = mixt_tree; + do + { + time(&(tree->t_beg)); + tree = tree->next_mixt; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Init_T_End(t_tree *mixt_tree) +{ + t_tree *tree; + + /*! Initialize t_beg in each mixture tree */ + tree = mixt_tree; + do + { + time(&(tree->t_current)); + tree = tree->next_mixt; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Prepare_All(int num_rand_tree, t_tree *mixt_tree) +{ + t_tree *tree; + + MIXT_Check_Model_Validity(mixt_tree); + MIXT_Init_Model(mixt_tree); + Print_Data_Structure(NO,stdout,mixt_tree); + tree = MIXT_Starting_Tree(mixt_tree); + Copy_Tree(tree,mixt_tree); + Free_Tree(tree); + + if(mixt_tree->io->mod->s_opt->random_input_tree) + { + PhyML_Printf("\n\n. [%3d/%3d]",num_rand_tree+1,mixt_tree->io->mod->s_opt->n_rand_starts); + Random_Tree(mixt_tree); + } + + MIXT_Connect_Cseqs_To_Nodes(mixt_tree); + MIXT_Init_T_Beg(mixt_tree); + + MIXT_Make_Tree_For_Pars(mixt_tree); + MIXT_Make_Tree_For_Lk(mixt_tree); + MIXT_Make_Spr(mixt_tree); + + MIXT_Chain_All(mixt_tree); + MIXT_Check_Edge_Lens_In_All_Elem(mixt_tree); + MIXT_Turn_Branches_OnOff_In_All_Elem(ON,mixt_tree); + MIXT_Check_Invar_Struct_In_Each_Partition_Elem(mixt_tree); + MIXT_Check_RAS_Struct_In_Each_Partition_Elem(mixt_tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Make_Spr(t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + Make_Spr(tree); + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Make_Tree_For_Pars(t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + if(tree->is_mixt_tree == NO) Make_Tree_For_Pars(tree); + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Make_Tree_For_Lk(t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + if(tree->is_mixt_tree == NO) Make_Tree_For_Lk(tree); + else + { + tree->c_lnL_sorted = (phydbl *)mCalloc(tree->n_pattern,sizeof(phydbl)); + tree->cur_site_lk = (phydbl *)mCalloc(tree->n_pattern,sizeof(phydbl)); + tree->old_site_lk = (phydbl *)mCalloc(tree->n_pattern,sizeof(phydbl)); + tree->site_lk_cat = (phydbl *)mCalloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes),sizeof(phydbl)); + tree->unscaled_site_lk_cat = (phydbl *)mCalloc(MAX(tree->mod->ras->n_catg,tree->mod->n_mixt_classes)*tree->n_pattern,sizeof(phydbl)); + tree->fact_sum_scale = (int *)mCalloc(tree->n_pattern,sizeof(int)); + + +#if (defined(__AVX__) || defined(__SSE3__)) +#ifndef WIN32 + if(posix_memalign((void **)&tree->expl,BYTE_ALIGN,(size_t)2*tree->mod->n_mixt_classes*tree->mod->ns*sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + tree->expl = _aligned_malloc(2*tree->mod->n_mixt_classes*tree->mod->ns*sizeof(phydbl),BYTE_ALIGN); +#endif +#else + tree->expl = (phydbl *)mCalloc(2*tree->mod->n_mixt_classes*tree->mod->ns,sizeof(phydbl)); +#endif + + for(int i=0;i<2*tree->n_otu-1;++i) Make_Edge_NNI(tree->a_edges[i]); + + tree->log_lks_aLRT = (phydbl **)mCalloc(3,sizeof(phydbl *)); + for(int i=0;i<3;i++) tree->log_lks_aLRT[i] = (phydbl *)mCalloc(tree->data->init_len,sizeof(phydbl)); + } + + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Ancestral_Sequences_One_Node(t_node *mixt_d, t_tree *mixt_tree, int print) +{ + if(mixt_d->tax) return; + else + { + t_node *v0,*v1,*v2; // three neighbours of d + t_edge *b0,*b1,*b2; + int i,j; + int catg; + phydbl p0, p1, p2; + phydbl *p; + t_node *d,*curr_mixt_d; + t_tree *tree, *curr_mixt_tree; + int site,csite; + phydbl *p_lk0, *p_lk1, *p_lk2; + int *sum_scale0, *sum_scale1, *sum_scale2; + phydbl r_mat_weight_sum, e_frq_weight_sum, sum_probas; + phydbl *Pij0, *Pij1, *Pij2; + int NsNs, Ns, NsNg; + FILE *fp; + + if(!mixt_d) return; + + curr_mixt_tree = mixt_tree; + curr_mixt_d = mixt_d; + fp = mixt_tree->io->fp_out_ancestral_seq; + + + do /* For each partition element */ + { + if(curr_mixt_tree->next) + { + r_mat_weight_sum = MIXT_Get_Sum_Chained_Scalar_Dbl(curr_mixt_tree->next->mod->r_mat_weight); + e_frq_weight_sum = MIXT_Get_Sum_Chained_Scalar_Dbl(curr_mixt_tree->next->mod->e_frq_weight); + sum_probas = MIXT_Get_Sum_Of_Probas_Across_Mixtures(r_mat_weight_sum, e_frq_weight_sum, curr_mixt_tree); + } + else + { + r_mat_weight_sum = 1.; + e_frq_weight_sum = 1.; + sum_probas = 1.; + } + + Ns = curr_mixt_tree->next ? curr_mixt_tree->next->mod->ns : curr_mixt_tree->mod->ns; + NsNs = Ns*Ns; + NsNg = Ns*curr_mixt_tree->mod->ras->n_catg; + + p = (phydbl *)mCalloc(Ns,sizeof(phydbl)); + + /* for(site=0;siten_pattern;site++) // For each site in the current partition element */ + for(site=0;sitedata->init_len;site++) // For each site in the current partition element + { + csite = curr_mixt_tree->data->sitepatt[site]; + + d = curr_mixt_d->next ? curr_mixt_d->next : curr_mixt_d; + tree = curr_mixt_tree->next ? curr_mixt_tree->next : curr_mixt_tree; + + for(i=0;imod->ns;i++) p[i] = .0; + + do // For each class of the mixture model that applies to the current partition element + { + if(tree->is_mixt_tree == YES) + { + tree = tree->next; + d = d->next; + } + + v0 = d->v[0]; + v1 = d->v[1]; + v2 = d->v[2]; + + b0 = d->b[0]; + b1 = d->b[1]; + b2 = d->b[2]; + + Pij0 = b0->Pij_rr; + Pij1 = b1->Pij_rr; + Pij2 = b2->Pij_rr; + + if(v0 == b0->left) + { + p_lk0 = b0->p_lk_left; + sum_scale0 = b0->sum_scale_left; + } + else + { + p_lk0 = b0->p_lk_rght; + sum_scale0 = b0->sum_scale_rght; + } + + if(v1 == b1->left) + { + p_lk1 = b1->p_lk_left; + sum_scale1 = b1->sum_scale_left; + } + else + { + p_lk1 = b1->p_lk_rght; + sum_scale1 = b1->sum_scale_rght; + } + + if(v2 == b2->left) + { + p_lk2 = b2->p_lk_left; + sum_scale2 = b2->sum_scale_left; + } + else + { + p_lk2 = b2->p_lk_rght; + sum_scale2 = b2->sum_scale_rght; + } + + + for(catg=0;catgmod->ras->n_catg;catg++) + { + for(i=0;itax) + for(j=0;jmod->ns;j++) + { + p0 += v0->b[0]->p_lk_tip_r[csite*Ns+j] * Pij0[catg*NsNs+i*Ns+j]; + + /* printf("\n. p0 %d %f", */ + /* v0->b[0]->p_lk_tip_r[site*Ns+j], */ + /* Pij0[catg*NsNs+i*Ns+j]); */ + } + else + for(j=0;jmod->ns;j++) + { + p0 += p_lk0[csite*NsNg+catg*Ns+j] * Pij0[catg*NsNs+i*Ns+j] / (phydbl)POW(2,sum_scale0[catg*curr_mixt_tree->n_pattern+csite]); + + /* p0 += p_lk0[site*NsNg+catg*Ns+j] * Pij0[catg*NsNs+i*Ns+j]; */ + + /* printf("\n. p0 %f %f", */ + /* p_lk0[site*NsNg+catg*Ns+j], */ + /* Pij0[catg*NsNs+i*Ns+j]); */ + } + p1 = .0; + if(v1->tax) + for(j=0;jmod->ns;j++) + { + p1 += v1->b[0]->p_lk_tip_r[csite*Ns+j] * Pij1[catg*NsNs+i*Ns+j]; + + /* printf("\n. p1 %d %f", */ + /* v1->b[0]->p_lk_tip_r[site*Ns+j], */ + /* Pij1[catg*NsNs+i*Ns+j]); */ + } + + else + for(j=0;jmod->ns;j++) + { + p1 += p_lk1[csite*NsNg+catg*Ns+j] * Pij1[catg*NsNs+i*Ns+j] / (phydbl)POW(2,sum_scale1[catg*curr_mixt_tree->n_pattern+csite]); + + /* p1 += p_lk1[site*NsNg+catg*Ns+j] * Pij1[catg*NsNs+i*Ns+j]; */ + + /* printf("\n. p1 %f %f", */ + /* p_lk1[site*NsNg+catg*Ns+j], */ + /* Pij1[catg*NsNs+i*Ns+j]); */ + } + + + p2 = .0; + if(v2->tax) + for(j=0;jmod->ns;j++) + { + p2 += v2->b[0]->p_lk_tip_r[csite*Ns+j] * Pij2[catg*NsNs+i*Ns+j]; + /* printf("\n. p2 %d %f", */ + /* v2->b[0]->p_lk_tip_r[site*Ns+j], */ + /* Pij2[catg*NsNs+i*Ns+j]); */ + } + else + for(j=0;jmod->ns;j++) + { + p2 += p_lk2[csite*NsNg+catg*Ns+j] * Pij2[catg*NsNs+i*Ns+j] / (phydbl)POW(2,sum_scale2[catg*curr_mixt_tree->n_pattern+csite]); + + /* p2 += p_lk2[site*NsNg+catg*Ns+j] * Pij2[catg*NsNs+i*Ns+j]; */ + + /* printf("\n. p2 %f %f", */ + /* p_lk2[site*NsNg+catg*Ns+j], */ + /* Pij2[catg*NsNs+i*Ns+j]); */ + } + + p[i] += + p0*p1*p2* + tree->mod->e_frq->pi->v[i] / + tree->cur_site_lk[csite] * + curr_mixt_tree->mod->ras->gamma_r_proba->v[tree->mod->ras->parent_class_number] * + tree->mod->r_mat_weight->v / r_mat_weight_sum * + tree->mod->e_frq_weight->v / e_frq_weight_sum / + sum_probas; + + if(print == YES) + printf("\n class: %d prob: %f", + tree->mod->ras->parent_class_number, + curr_mixt_tree->mod->ras->gamma_r_proba->v[tree->mod->ras->parent_class_number]); + } + } + + if(print == YES) + { + PhyML_Fprintf(fp,"%4d\t%4d\t",site+1,d->num); + for(i=0;inext; + d = d->next; + + + } + while(tree && d && tree->is_mixt_tree == NO); + } + + Free(p); + curr_mixt_tree = curr_mixt_tree->next_mixt; + curr_mixt_d = curr_mixt_d->next_mixt; + } + while(curr_mixt_tree != NULL); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// First and second derivative of the log-likelihood with respect +// to the length of edge b +phydbl MIXT_dLk(phydbl *l, t_edge *mixt_b, t_tree *mixt_tree) +{ + t_tree *tree,*cpy_mixt_tree; + t_edge *b,*cpy_mixt_b; + unsigned int site, class, nclasses, ns, state; + phydbl *sum_scale_left_cat,*sum_scale_rght_cat; + phydbl sum,mult; + phydbl *lk,*dlk; + phydbl site_lk,site_dlk; + phydbl log_site_lk,inv_site_lk; + int num_prec_issue; + phydbl r_mat_weight_sum, e_frq_weight_sum, sum_probas; + phydbl len; + phydbl *expl,*dot_prod; + phydbl rr; + phydbl ev,expevlen; + phydbl one_m_pinv; + short int length_found; + + tree = NULL; + b = NULL; + expl = NULL; + lk = NULL; + dlk = NULL; + cpy_mixt_tree = mixt_tree; + cpy_mixt_b = mixt_b; + len = -1.; + + if(mixt_tree->update_eigen_lr == YES) + { + MIXT_Update_Eigen_Lr(mixt_b,mixt_tree); + } + + /*! Make sure that l is one of the lengths of mixt_b */ + b = mixt_b; + while(b) { if(&(b->l->v) == l) break; b = b->next; } + assert(b != NULL); + + + do /*! Consider each element of the data partition */ + { + b = mixt_b; + tree = mixt_tree; + length_found = NO; + do + { + if(&(b->l->v) == l) + { + length_found = YES; + break; + } + + b = b->next; + tree = tree->next; + } + while(tree && tree->is_mixt_tree == NO); + + /*! For computational efficiency, the dlk and lk computation for + data partition elements corresponding to trees in which l is not + found could be skipped. We compute dlk and lk nonetheless so that + these two values are the derivative and lielihood computed for the + whole data set, not juste the data partitions that "contain" l + */ + + tree = mixt_tree; + do + { + tree->c_lnL = .0; + tree->c_dlnL = .0; + tree = tree->next; + } + while(tree); + + ns = mixt_tree->mod->ns; + nclasses = MIXT_Mixt_Size(mixt_tree); + + lk = (phydbl *)mCalloc(nclasses,sizeof(phydbl)); + dlk = (phydbl *)mCalloc(nclasses,sizeof(phydbl)); + + sum_scale_left_cat = (phydbl *)mCalloc(nclasses,sizeof(phydbl)); + sum_scale_rght_cat = (phydbl *)mCalloc(nclasses,sizeof(phydbl)); + + r_mat_weight_sum = MIXT_Get_Sum_Chained_Scalar_Dbl(mixt_tree->next->mod->r_mat_weight); + e_frq_weight_sum = MIXT_Get_Sum_Chained_Scalar_Dbl(mixt_tree->next->mod->e_frq_weight); + sum_probas = MIXT_Get_Sum_Of_Probas_Across_Mixtures(r_mat_weight_sum,e_frq_weight_sum,mixt_tree); + + // Fill in expl vector for each rate class + tree = mixt_tree->next; + b = mixt_b->next; + class = 0; + do + { + if(tree->mod->ras->invar == YES) rr = 0.0; + else + { + rr = 1.0; + rr *= tree->mod->br_len_mult->v; + rr *= mixt_tree->mod->ras->gamma_rr->v[tree->mod->ras->parent_class_number]; + } + + + if(length_found == YES) len = (*l) * rr; + else len = b->l->v * rr; + + if(isinf(len) || isnan(len)) + { + PhyML_Fprintf(stderr,"\n. len=%f rr=%f l=%f",len,rr,*l); + assert(FALSE); + } + + if(tree->mod->ras->invar == NO) + { + if(len < tree->mod->l_min) len = tree->mod->l_min; + else if(len > tree->mod->l_max) len = tree->mod->l_max; + } + else + { + len = 0.0; + } + + + expl = mixt_tree->expl; + + for(state=0;statemod->ns;++state) + { + ev = tree->mod->eigen->e_val[state]; + expevlen = exp(ev*len); + + expl[class*2*ns + 2*state] = expevlen; + expl[class*2*ns + 2*state + 1] = expevlen*ev*rr; + } + + class++; + + tree = tree->next; + b = b->next; + } + while(tree && tree->is_mixt_tree == NO); + + assert(class == nclasses); + + mixt_tree->c_lnL = .0; + mixt_tree->c_dlnL = .0; + + for(site=0;siten_pattern;++site) + { + for(class=0;classnext; + tree = mixt_tree->next; + class = 0; + /*! For all classes in the mixture */ + do + { + if(tree->mod->ras->invar == NO && tree->data->wght[tree->curr_site] > SMALL) + { + tree->curr_site = site; + dot_prod = tree->dot_prod + site * ns; + expl = mixt_tree->expl + 2*ns*class; + + if(tree->mod->io->datatype == NT || tree->mod->io->datatype == AA) + { +#if (defined(__AVX__)) + AVX_Lk_dLk_Core_One_Class_Eigen_Lr(dot_prod, + expl ? expl : NULL, + ns,lk+class,dlk+class); +#elif (defined(__SSE3__)) + SSE_Lk_dLk_Core_One_Class_Eigen_Lr(dot_prod, + expl ? expl : NULL, + ns,lk+class,dlk+class); +#else + Lk_dLk_Core_One_Class_Eigen_Lr(dot_prod, + expl ? expl : NULL, + ns,lk+class,dlk+class); +#endif + } + else + { + Lk_dLk_Core_One_Class_Eigen_Lr(dot_prod, + expl ? expl : NULL, + ns,lk+class,dlk+class); + } + + tree->apply_lk_scaling = YES; + + + sum_scale_left_cat[tree->mod->ras->parent_class_number] = + (b->sum_scale_left)? + (b->sum_scale_left[site]): + (0.0); + + sum_scale_rght_cat[tree->mod->ras->parent_class_number] = + (b->sum_scale_rght)? + (b->sum_scale_rght[site]): + (0.0); + + sum = + sum_scale_left_cat[tree->mod->ras->parent_class_number] + + sum_scale_rght_cat[tree->mod->ras->parent_class_number]; + + if(sum > 1024.) + { + /* PhyML_Fprintf(stderr,"\n. Numerical precision issue detected (sum = %g)!!!",sum); */ + sum = 1023.; + tree->mixt_tree->numerical_warning = YES; + tree->numerical_warning = YES; + } + + mult = pow(2,sum); + + /* PhyML_Printf("\n> tree: %p class: %d lk: %f dlk: %g sum: %g site: %d dot_prod[0]: %g expl[0]: %g expl[1]: %g expl[2]: %g",tree,class,log(lk[class]),dlk[class],sum,site,dot_prod[0],expl[0],expl[1],expl[2]); */ + + lk[class] /= mult; + dlk[class] /= mult; + + } + + tree = tree->next; + b = b->next; + class++; + + } + while(tree && tree->is_mixt_tree == NO); + // done with all trees in the mixture for this partition element. + + tree = mixt_tree->next; + class = 0; + site_lk = .0; + site_dlk = .0; + + if(mixt_tree->mod->ras->invar == YES) one_m_pinv = 1. - mixt_tree->mod->ras->pinvar->v; + else one_m_pinv = 1.; + + + do + { + if(tree->mod->ras->invar == NO && mixt_tree->data->wght[tree->curr_site] > SMALL) + { + site_lk += + lk[class] * + mixt_tree->mod->ras->gamma_r_proba->v[tree->mod->ras->parent_class_number] * + tree->mod->r_mat_weight->v / r_mat_weight_sum * + tree->mod->e_frq_weight->v / e_frq_weight_sum / + sum_probas; + + + site_dlk += + dlk[class] * + one_m_pinv * + mixt_tree->mod->ras->gamma_r_proba->v[tree->mod->ras->parent_class_number] * + tree->mod->r_mat_weight->v / r_mat_weight_sum * + tree->mod->e_frq_weight->v / e_frq_weight_sum / + sum_probas; + + /* PhyML_Printf("\n. MIXT_DLK site: %d mixt_tree: %p tree: %p class: %d l: %p lk: %g dlk: %g", */ + /* site, */ + /* mixt_tree, */ + /* tree, */ + /* class, */ + /* l, */ + /* lk[class], */ + /* dlk[class]); */ + + } + + class++; + tree = tree->next; + } + while(tree && tree->is_mixt_tree == NO); + + + + /* Scaling for invariants */ + if(mixt_tree->mod->ras->invar == YES) + { + num_prec_issue = NO; + + tree = mixt_tree->next; + while(tree->mod->ras->invar == NO) + { + tree = tree->next; + if(!tree || tree->is_mixt_tree == YES) + { + PhyML_Fprintf(stderr,"\n. tree: %p",tree); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d",__FILE__,__LINE__); + Exit("\n"); + } + } + + tree->apply_lk_scaling = YES; + + /*! 'tree' will give the correct state frequencies (as opposed to mixt_tree) */ + inv_site_lk = Invariant_Lk(0,site,&num_prec_issue,tree); + + + if(num_prec_issue == YES) // inv_site_lk >> site_lk + { + site_lk = inv_site_lk * mixt_tree->mod->ras->pinvar->v; + } + else + { + site_lk = site_lk * (1. - mixt_tree->mod->ras->pinvar->v) + inv_site_lk * mixt_tree->mod->ras->pinvar->v; + } + } + + + log_site_lk = log(site_lk); + + if(isinf(log_site_lk) || isnan(log_site_lk)) + { + PhyML_Fprintf(stderr,"\n. site = %d",site); + PhyML_Fprintf(stderr,"\n. invar = %d",mixt_tree->data->invar[site]); + PhyML_Fprintf(stderr,"\n. mixt = %d",mixt_tree->is_mixt_tree); + PhyML_Fprintf(stderr,"\n. lk = %G log(lk) = %f < %G",site_lk,log_site_lk,-BIG); + for(class=0;classmod->ras->n_catg;++class) PhyML_Printf("\n. rr=%f p=%f",mixt_tree->mod->ras->gamma_rr->v[class],mixt_tree->mod->ras->gamma_r_proba->v[class]); + PhyML_Fprintf(stderr,"\n. pinv = %G",mixt_tree->mod->ras->pinvar->v); + PhyML_Fprintf(stderr,"\n. bl mult = %G",mixt_tree->mod->br_len_mult->v); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d.\n",__FILE__,__LINE__); + Exit("\n"); + } + + + mixt_tree->c_lnL += mixt_tree->data->wght[site] * log_site_lk; + mixt_tree->c_dlnL += mixt_tree->data->wght[site] * ( site_dlk / site_lk ); + + /* PhyML_Printf("\n. site: %4d lnL: %15f dlnL: %15f",site,site_lk,site_dlk); */ + } + + Free(sum_scale_left_cat); + Free(sum_scale_rght_cat); + + Free(lk); + Free(dlk); + + mixt_tree = mixt_tree->next_mixt; + mixt_b = mixt_b->next_mixt; + } + while(mixt_tree); + + + // Sum c_dlnL across all partition element and set each c_dlnL equal to + // this sum + + sum = .0; + mixt_tree = cpy_mixt_tree; + do + { + sum += mixt_tree->c_dlnL; + mixt_tree = mixt_tree->next_mixt; + } + while(mixt_tree); + + mixt_tree = cpy_mixt_tree; + do + { + mixt_tree->c_dlnL = sum; + mixt_tree = mixt_tree->next_mixt; + } + while(mixt_tree); + + + + // Do the same with likelihood values + sum = .0; + mixt_tree = cpy_mixt_tree; + do + { + sum += mixt_tree->c_lnL; + mixt_tree = mixt_tree->next_mixt; + } + while(mixt_tree); + + mixt_tree = cpy_mixt_tree; + do + { + mixt_tree->c_lnL = sum; + mixt_tree = mixt_tree->next_mixt; + } + while(mixt_tree); + + mixt_tree = cpy_mixt_tree; + mixt_b = cpy_mixt_b; + + return mixt_tree->c_lnL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Returns the number of trees (including mixt_trees) in the +// whole model. +int MIXT_Part_Mixt_Size(t_tree *mixt_tree) +{ + if(mixt_tree->is_mixt_tree == NO) return 1; + else + { + int num; + t_tree *tree; + + num = 0; + tree = mixt_tree; + do + { + num++; + tree = tree->next; + } + while(tree); + return num; + } + return -1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// Returns the number of trees in the partition element corresponding to mixt_tree. +int MIXT_Mixt_Size(t_tree *mixt_tree) +{ + if(mixt_tree->is_mixt_tree == NO) return 1; + else + { + int num; + t_tree *tree; + + num = 0; + tree = mixt_tree->next; + do + { + num++; + tree = tree->next; + } + while(tree && tree->is_mixt_tree == NO); + + return num; + } + return -1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Both_Sides(int yesno, t_tree *mixt_tree) +{ + t_tree *tree; + + assert(mixt_tree->is_mixt_tree == YES); + + tree = mixt_tree; + + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + Set_Both_Sides(yesno,tree); + tree = tree->next; + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Model_Parameters(t_mod *mixt_mod) +{ + t_mod *mod = mixt_mod->next; + + if(mod != NULL) + { + do + { + Set_Model_Parameters(mod); + mod = mod->next; + } + while(mod); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Update_Eigen(t_mod *mixt_mod) +{ + t_mod *mod; + + mod = mixt_mod; + + do + { + if(mod->is_mixt_mod) mod = mod->next; + if(!Update_Boundaries(mod)) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(!Update_Eigen(mod)) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + mod = mod->next; + } + while(mod); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Update_Eigen_Lr(t_edge *mixt_b, t_tree *mixt_tree) +{ + t_edge *b; + t_tree *tree; + + tree = mixt_tree; + b = mixt_b; + + do + { + if(tree->is_mixt_tree == YES) + { + tree = tree->next; + b = b->next; + } + + Update_Eigen_Lr(b,tree); + + tree = tree->next; + b = b->next; + } + while(tree); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Update_Eigen(int yn, t_mod *mixt_mod) +{ + t_mod *mod; + + mod = mixt_mod; + do + { + mod->update_eigen = yn; + mod = mod->next; + } + while(mod); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Update_Eigen_Lr(int yn, t_tree *mixt_tree) +{ + t_tree *tree; + int dum; + + tree = mixt_tree->next; + do + { + dum = mixt_tree->is_mixt_tree; + mixt_tree->is_mixt_tree = NO; + + Set_Update_Eigen_Lr(yn,tree); + + mixt_tree->is_mixt_tree = dum; + + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Use_Eigen_Lr(int yn, t_tree *mixt_tree) +{ + t_tree *tree; + int dum; + + tree = mixt_tree->next; + do + { + dum = mixt_tree->is_mixt_tree; + mixt_tree->is_mixt_tree = NO; + + Set_Use_Eigen_Lr(yn,tree); + + mixt_tree->is_mixt_tree = dum; + + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Sample_Ancestral_Seq(int fullmutmap, int fromprior, t_tree *mixt_tree) +{ + t_tree *tree,*loc_mixt_tree; + phydbl r_mat_weight_sum, e_frq_weight_sum, sum_probas, *class_proba; + int i; + + r_mat_weight_sum = MIXT_Get_Sum_Chained_Scalar_Dbl(mixt_tree->next->mod->r_mat_weight); + e_frq_weight_sum = MIXT_Get_Sum_Chained_Scalar_Dbl(mixt_tree->next->mod->e_frq_weight); + sum_probas = MIXT_Get_Sum_Of_Probas_Across_Mixtures(r_mat_weight_sum,e_frq_weight_sum,mixt_tree); + + + tree = mixt_tree; + loc_mixt_tree = tree; + + // For each element in the partition (i.e., each gene), select a + // class of the mixture according to its post prob. + do + { + tree = loc_mixt_tree->next; + + class_proba = NULL; + i = 0; + do + { + if(i == 0) class_proba = (phydbl *)mCalloc(1,sizeof(phydbl)); + else class_proba = (phydbl *)mRealloc(class_proba,i+1,sizeof(phydbl)); + + class_proba[i] = + tree->site_lk_cat[0] * + loc_mixt_tree->mod->ras->gamma_r_proba->v[tree->mod->ras->parent_class_number] * + tree->mod->r_mat_weight->v / r_mat_weight_sum * + tree->mod->e_frq_weight->v / e_frq_weight_sum / + sum_probas; + + tree = tree->next; + i++; + } + while(tree && tree->is_mixt_tree == NO); + + tree = loc_mixt_tree->next; + i = Sample_i_With_Proba_pi(class_proba,i); + + do + { + i--; + if(i < 0) break; + tree = tree->next; + assert(tree); + } + while(1); + + assert(tree->is_mixt_tree == NO); + + Sample_Ancestral_Seq(fullmutmap,fromprior,tree); + + Free(class_proba); + + loc_mixt_tree = loc_mixt_tree->next_mixt; + } + while(loc_mixt_tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Propagate changes in the "master" tree to other trees. Partial +// likelihood vectors (and scaling stuff) is not update here so +// requires full tree traversal to be updated properly. +void MIXT_Propagate_Tree_Update(t_tree *mixt_tree) +{ + t_tree *tree; + int i; + + assert(!mixt_tree->prev); + + tree = mixt_tree->next; + if(!tree) return; + + do + { + for(i=0;i<2*mixt_tree->n_otu-1;++i) + { + tree->a_nodes[i]->v[0] = mixt_tree->a_nodes[i]->v[0] ? tree->a_nodes[mixt_tree->a_nodes[i]->v[0]->num] : NULL; + tree->a_nodes[i]->v[1] = mixt_tree->a_nodes[i]->v[1] ? tree->a_nodes[mixt_tree->a_nodes[i]->v[1]->num] : NULL; + tree->a_nodes[i]->v[2] = mixt_tree->a_nodes[i]->v[2] ? tree->a_nodes[mixt_tree->a_nodes[i]->v[2]->num] : NULL; + + if(tree->rates != NULL) tree->rates->nd_t[i] = mixt_tree->rates->nd_t[i]; + } + + Connect_Edges_To_Nodes_Serial(tree); + + Reorganize_Edges_Given_Lk_Struct(tree); + Init_Partial_Lk_Tips_Double(tree); + + if(mixt_tree->n_root != NULL) + { + assert(mixt_tree->e_root); + assert(mixt_tree->n_root->v[1]); + assert(mixt_tree->n_root->v[2]); + assert(mixt_tree->n_root->b[1]); + assert(mixt_tree->n_root->b[2]); + + tree->n_root = tree->a_nodes[mixt_tree->n_root->num]; + tree->e_root = tree->a_edges[mixt_tree->e_root->num]; + + tree->n_root->v[1] = tree->a_nodes[mixt_tree->n_root->v[1]->num]; + tree->n_root->v[2] = tree->a_nodes[mixt_tree->n_root->v[2]->num]; + + tree->n_root->b[1] = tree->a_edges[mixt_tree->n_root->b[1]->num]; + tree->n_root->b[2] = tree->a_edges[mixt_tree->n_root->b[2]->num]; + + tree->n_root->b[1]->left = tree->n_root; + tree->n_root->b[2]->left = tree->n_root; + tree->n_root->b[1]->rght = tree->n_root->v[1]; + tree->n_root->b[2]->rght = tree->n_root->v[2]; + } + + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + + tree = tree->next; + + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Set_Bl_From_Rt(int yn, t_tree *mixt_tree) +{ + t_tree *tree; + + tree = mixt_tree; + do + { + assert(tree->rates); + tree->rates->bl_from_rt = yn; + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Copy_Tree(t_tree *ori, t_tree *cpy) +{ + int ori_is_mixt_tree,cpy_is_mixt_tree; + + assert(!((cpy && !ori) || (!cpy && ori))); + + if(cpy == NULL || ori == NULL) return; + + if(ori->is_mixt_tree == YES && cpy->is_mixt_tree == YES) + { + do + { + ori_is_mixt_tree = ori->is_mixt_tree; + ori->is_mixt_tree = NO; + cpy_is_mixt_tree = cpy->is_mixt_tree; + cpy->is_mixt_tree = NO; + + Copy_Tree(ori,cpy); + + cpy->is_mixt_tree = cpy_is_mixt_tree; + ori->is_mixt_tree = ori_is_mixt_tree; + + ori = ori->next; + cpy = cpy->next; + } + while(cpy); + } + else if(ori->is_mixt_tree == NO && cpy->is_mixt_tree == YES) + { + do + { + cpy_is_mixt_tree = cpy->is_mixt_tree; + cpy->is_mixt_tree = NO; + + Copy_Tree(ori,cpy); + + cpy->is_mixt_tree = cpy_is_mixt_tree; + + cpy = cpy->next; + } + while(cpy); + } + else if(ori->is_mixt_tree == YES && cpy->is_mixt_tree == NO) + { + ori_is_mixt_tree = ori->is_mixt_tree; + ori->is_mixt_tree = NO; + Copy_Tree(ori,cpy); + ori->is_mixt_tree = ori_is_mixt_tree; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Init_NNI_Score(phydbl val, t_edge *mixt_b, t_tree *mixt_tree) +{ + t_edge *b; + t_tree *tree; + + tree = mixt_tree->next; + b = mixt_b->next; + do + { + if(tree->is_mixt_tree) + { + tree = tree->next; + b = b->next; + } + + Init_NNI_Score(val,b,tree); + tree = tree->next; + b = b->next; + } + while(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_tree *MIXT_Duplicate_Tree(t_tree *ori) +{ + t_tree *cpy,*first,*prev; + int dum; + + ori->is_mixt_tree = NO; + first = Duplicate_Tree(ori); + first->prev = NULL; + first->is_mixt_tree = YES; + ori->is_mixt_tree = YES; + + ori = ori->next; + prev = cpy = first; + do + { + dum = ori->is_mixt_tree; + ori->is_mixt_tree = NO; + + prev = cpy; + + cpy = Duplicate_Tree(ori); + + ori->is_mixt_tree = dum; + cpy->is_mixt_tree = ori->is_mixt_tree; + + cpy->prev = prev; + prev->next = cpy; + + ori = ori->next; + } + while(ori); + + cpy->next = NULL; + + return(first); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void MIXT_Print_Site_Lk(t_tree *mixt_tree, FILE *fp) +{ + t_tree *tree; + int site,catg; + char *s; + phydbl postmean,sum; + + assert(mixt_tree->is_mixt_tree == YES); + assert(mixt_tree->io->print_site_lnl == YES); + + + if(!mixt_tree->io->print_trace) + { + tree = mixt_tree; + do + { + PhyML_Fprintf(fp,"Note : P(D|M) is the probability of site D given the model M (i.e., the site likelihood)\n"); + if(tree->mod->ras->n_catg > 1 || tree->mod->ras->invar) + { + PhyML_Fprintf(fp,"P*(D|M,rr[x]) is the scaled probability of site D given the model M and the relative rate\n"); + PhyML_Fprintf(fp,"of evolution rr[x], where x is the class of rate to be considered.\n"); + PhyML_Fprintf(fp,"The actual conditional probability is given by P*(D|M,rr[x])/2^F, where\n"); + PhyML_Fprintf(fp,"F is the scaling factor (see column 'Scaler').\n"); + PhyML_Fprintf(fp,"For invariant sites, P(D|M,rr[0]=0) is the actual conditional probability\n"); + PhyML_Fprintf(fp,"(i.e., it is not scaled).\n"); + break; + } + tree = tree->next_mixt; + } + while(tree); + PhyML_Fprintf(fp,"\n"); + + + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + + do + { + PhyML_Fprintf(fp,"Alignment file name: %s\n\n",mixt_tree->io->in_align_file); + + sprintf(s,"Site"); + PhyML_Fprintf(fp, "%-12s",s); + + sprintf(s,"P(D|M)"); + PhyML_Fprintf(fp,"%-15s",s); + + sprintf(s,"Scaler"); + PhyML_Fprintf(fp,"%-7s",s); + + sprintf(s,"Pattern"); + PhyML_Fprintf(fp, "%-9s",s); + + if(mixt_tree->mod->ras->n_catg > 1) + { + for(catg=0;catgmod->ras->n_catg;catg++) + { + sprintf(s,"P*(D|M,rr[%d]=%5.4f)",catg+1,mixt_tree->mod->ras->gamma_rr->v[catg]); + PhyML_Fprintf(fp,"%-23s",s); + } + + sprintf(s,"Posterior mean"); + PhyML_Fprintf(fp,"%-22s",s); + } + + + if(mixt_tree->mod->ras->invar) + { + sprintf(s,"P(D|M,rr[0]=0)"); + PhyML_Fprintf(fp,"%-16s",s); + } + + sprintf(s,"NDistinctStates"); + PhyML_Fprintf(fp,"%-16s",s); + + PhyML_Fprintf(fp,"\n"); + + assert(mixt_tree->next->is_mixt_tree == NO); + Init_Ui_Tips(mixt_tree->next); + + for(site=0;sitedata->init_len;site++) + { + PhyML_Fprintf(fp,"%-12d",site+1); + + PhyML_Fprintf(fp,"%-15g",mixt_tree->cur_site_lk[mixt_tree->data->sitepatt[site]]); + + PhyML_Fprintf(fp,"%-7d",mixt_tree->fact_sum_scale[mixt_tree->data->sitepatt[site]]); + + PhyML_Fprintf(fp,"%-9d",mixt_tree->data->sitepatt[site]); + + if(mixt_tree->mod->ras->n_catg > 1) + { + tree = mixt_tree->next; + do + { + PhyML_Fprintf(fp,"%-23g",tree->unscaled_site_lk_cat[tree->data->sitepatt[site]]); + tree = tree->next; + } + while(tree && tree->is_mixt_tree == NO); + + + tree = mixt_tree->next; + postmean = .0; + sum = .0; + do + { + postmean += + mixt_tree->mod->ras->gamma_rr->v[tree->mod->ras->parent_class_number] * + tree->unscaled_site_lk_cat[tree->data->sitepatt[site]] * + mixt_tree->mod->ras->gamma_r_proba->v[tree->mod->ras->parent_class_number]; + + sum += + tree->unscaled_site_lk_cat[tree->data->sitepatt[site]] * + mixt_tree->mod->ras->gamma_r_proba->v[tree->mod->ras->parent_class_number]; + + tree = tree->next; + } + while(tree && tree->is_mixt_tree == NO); + + postmean /= sum; + + PhyML_Fprintf(fp,"%-22g",postmean); + } + + if(mixt_tree->mod->ras->invar) + { + if((phydbl)mixt_tree->data->invar[mixt_tree->data->sitepatt[site]] > -0.5) + PhyML_Fprintf(fp,"%-16g",mixt_tree->mod->e_frq->pi->v[mixt_tree->data->invar[mixt_tree->data->sitepatt[site]]]); + else + PhyML_Fprintf(fp,"%-16g",0.0); + } + + assert(mixt_tree->next != NULL); + PhyML_Fprintf(fp,"%-16d",Number_Of_Diff_States_One_Site(mixt_tree->data->sitepatt[site],mixt_tree->next)); + + PhyML_Fprintf(fp,"\n"); + } + Free(s); + + mixt_tree = mixt_tree->next_mixt; + } + while(mixt_tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + + diff --git a/phyml/mixt.h b/phyml/mixt.h new file mode 100644 index 0000000..bb65d48 --- /dev/null +++ b/phyml/mixt.h @@ -0,0 +1,121 @@ +/* + +PHYML : a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences + +Copyright (C) Stephane Guindon. Oct 2003 onward + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef MIXT_H +#define MIXT_H + +#include "utilities.h" + +void MIXT_Connect_Edges_To_Next_Prev_Child_Parent(t_tree *tree); +void MIXT_Connect_Nodes_To_Next_Prev_Child_Parent(t_tree *tree); +void MIXT_Connect_Sprs_To_Next_Prev_Child_Parent(t_tree *tree); +void MIXT_Turn_Branches_OnOff(int onoff,t_tree *tree); +phydbl *MIXT_Get_Lengths_Of_This_Edge(t_edge *mixt_b, t_tree *tree); +void MIXT_Set_Lengths_Of_This_Edge(phydbl *lens,t_edge *mixt_b, t_tree *tree); +void MIXT_Post_Order_Lk(t_node *mixt_a,t_node *mixt_d,t_tree *mixt_tree); +void MIXT_Pre_Order_Lk(t_node *mixt_a,t_node *mixt_d,t_tree *mixt_tree); +phydbl MIXT_Lk(t_edge *mixt_b,t_tree *mixt_tree); +void MIXT_Update_Partial_Lk(t_tree *mixt_tree,t_edge *mixt_b,t_node *mixt_d); +void MIXT_Update_PMat_At_Given_Edge(t_edge *mixt_b,t_tree *mixt_tree); +int *MIXT_Get_Number_Of_Classes_In_All_Mixtures(t_tree *mixt_tree); +t_tree **MIXT_Record_All_Mixtures(t_tree *mixt_tree); +void MIXT_Break_All_Mixtures(int *c_max,t_tree *mixt_tree); +void MIXT_Reconnect_All_Mixtures(t_tree **tree_list,t_tree *mixt_tree); +int *MIXT_Record_Has_Invariants(t_tree *mixt_tree); +void MIXT_Reset_Has_Invariants(int *has_invariants,t_tree *mixt_tree); +void MIXT_Check_Invar_Setup(t_tree *mixt_tree); +void MIXT_Prune_Subtree(t_node *mixt_a,t_node *mixt_d,t_edge **mixt_target,t_edge **mixt_residual,t_tree *mixt_tree); +void MIXT_Graft_Subtree(t_edge *mixt_target, t_node *mixt_link, t_node *mixt_link_daughter, t_edge *mixt_residual, t_node *mixt_target_nd, t_tree *mixt_tree); +void MIXT_Br_Len_Opt(t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Check_Number_Of_Invar_Classes(t_tree *mixt_tree); +void MIXT_Prepare_Tree_For_Lk(t_tree *tree); +void MIXT_Check_Invar_Struct_In_Each_Partition_Elem(t_tree *mixt_tree); +void MIXT_Check_RAS_Struct_In_Each_Partition_Elem(t_tree *mixt_tree); +void MIXT_Br_Len_Involving_Invar(t_tree *mixt_tree); +void MIXT_Br_Len_Not_Involving_Invar(t_tree *mixt_tree); +phydbl MIXT_Unscale_Br_Len_Multiplier_Tree(t_tree *mixt_tree); +phydbl MIXT_Rescale_Br_Len_Multiplier_Tree(t_tree *mixt_tree); +void MIXT_Set_Alias_Subpatt(int onoff, t_tree *mixt_tree); +void MIXT_Check_Single_Edge_Lens(t_tree *mixt_tree); +void MIXT_Update_Eigen(t_mod *mixt_mod); +int MIXT_Pars(t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Set_Pars_Thresh(t_tree *mixt_tree); +void MIXT_Bootstrap(char *best_tree, xml_node *root); +void MIXT_Chain_All(t_tree *mixt_tree); +void MIXT_Chain_String(t_string *curr, t_string *next); +void MIXT_Chain_Scalar_Dbl(scalar_dbl *curr, scalar_dbl *next); +void MIXT_Chain_Rmat(t_rmat *curr, t_rmat *next); +void MIXT_Chain_Rmat(t_rmat *curr, t_rmat *next); +void MIXT_Chain_Efrq(t_efrq *curr, t_efrq *next); +void MIXT_Chain_RAS(t_ras *curr, t_ras *next); +void MIXT_Chain_Eigen(eigen *curr, eigen *next); +void MIXT_Chain_Vector_Dbl(vect_dbl *curr, vect_dbl *next); +void MIXT_Chain_Sprs(t_tree *tree); +void MIXT_Chain_Nodes(t_tree *tree); +void MIXT_Chain_Edges(t_tree *tree); +phydbl MIXT_Get_Mean_Edge_Len(t_edge *mixt_b, t_tree *tree); +phydbl MIXT_Get_Sum_Chained_Scalar_Dbl(scalar_dbl *s); +phydbl MIXT_Get_Sum_Of_Probas_Across_Mixtures(phydbl r_mat_weight_sum, phydbl e_frq_weight_sum, t_tree *mixt_tree); +phydbl MIXT_Rescale_Free_Rate_Tree(t_tree *mixt_tree); +void MIXT_Set_Br_Len_Var(t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Optimize_Br_Len_Multiplier(t_tree *mixt_tree); +void MIXT_Update_Br_Len_Multipliers(t_mod *mod); +void MIXT_Init_Model(t_tree *mixt_tree); +t_tree *MIXT_Starting_Tree(t_tree *mixt_tree); +void MIXT_Connect_Cseqs_To_Nodes(t_tree *mixt_tree); +void MIXT_Check_Edge_Lens_In_One_Elem(t_tree *mixt_tree); +void MIXT_Check_Edge_Lens_In_All_Elem(t_tree *mixt_tree); +void MIXT_Turn_Branches_OnOff_In_One_Elem(int onoff, t_tree *mixt_tree); +void MIXT_Turn_Branches_OnOff_In_All_Elem(int onoff, t_tree *mixt_tree); +void MIXT_Init_T_Beg(t_tree *mixt_tree); +void MIXT_Prepare_All(int num_rand_tree, t_tree *mixt_tree); +void MIXT_Init_T_End(t_tree *mixt_tree); +void MIXT_Add_Root(t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Check_Model_Validity(t_tree *mixt_tree); +void MIXT_Ancestral_Sequences_One_Node(t_node *mixt_d, t_tree *mixt_tree, int print); +void MIXT_Update_Partial_Pars(t_tree *mixt_tree, t_edge *mixt_b, t_node *mixt_d); +void MIXT_Chain_Cal(t_tree *mixt_tree); +void MIXT_Chain_Rates(t_rate *curr, t_rate *next); +void MIXT_RATES_Update_Cur_Bl(t_tree *mixt_tree); +phydbl MIXT_dLk(phydbl *l, t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Update_Eigen_Lr(t_edge *mixt_b, t_tree *mixt_tree); +int MIXT_Part_Mixt_Size(t_tree *mixt_tree); +int MIXT_Mixt_Size(t_tree *mixt_tree); +void MIXT_Set_Use_Eigen_Lr(int yn, t_tree *mixt_tree); +void MIXT_Set_Update_Eigen_Lr(int yn, t_tree *mixt_tree); +void MIXT_Backup_Partial_Pars(t_node *mixt_d, t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Restore_Partial_Pars(t_node *mixt_d, t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Backup_Partial_Lk(t_node *mixt_d, t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Restore_Partial_Lk(t_node *mixt_d, t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Backup_Partial_Scale(t_node *mixt_d, t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Restore_Partial_Scale(t_node *mixt_d, t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Set_Both_Sides(int yesno, t_tree *mixt_tree); +void MIXT_Set_Br_Len(phydbl val, t_edge *mixt_b, t_tree *mixt_tree); +void MIXT_Multiply_Scalar_Dbl(scalar_dbl *this, phydbl scalar); +void MIXT_Sample_Ancestral_Seq(int mutmap, int fromprior, t_tree *mixt_tree); +void MIXT_Set_Update_Eigen(int yn, t_mod *mixt_mod); +void MIXT_Set_Ignore_Root(int yesno, t_tree *mixt_tree); +void MIXT_Make_Spr(t_tree *mixt_tree); +void MIXT_Make_Tree_For_Lk(t_tree *mixt_tree); +void MIXT_Make_Tree_For_Pars(t_tree *mixt_tree); +void MIXT_Connect_Tip_Disks(t_tree *mixt_tree); +void MIXT_Propagate_Tree_Update(t_tree *mixt_tree); +void MIXT_Set_Bl_From_Rt(int yn, t_tree *mixt_tree); +void MIXT_Copy_Tree(t_tree *ori, t_tree *cpy); +void MIXT_Init_NNI_Score(phydbl val, t_edge *mixt_b, t_tree *mixt_tree); +t_tree *MIXT_Duplicate_Tree(t_tree *ori); +void MIXT_Set_Model_Parameters(t_mod *mixt_mod); +void MIXT_Print_Site_Lk(t_tree *mixt_tree, FILE *fp); + +#endif diff --git a/phyml/models.c b/phyml/models.c index a1c737d..2d0d00c 100644 --- a/phyml/models.c +++ b/phyml/models.c @@ -1,7 +1,7 @@ /* -PHYML : a program that computes maximum likelihood phylogenies from -DNA or AA homologous sequences +PhyML : a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences Copyright (C) Stephane Guindon. Oct 2003 onward @@ -10,19 +10,42 @@ the GNU public licence. See http://www.opensource.org for details. */ -#include "utilities.h" #include "models.h" -#include "eigen.h" -/* #include "eigenmb.h" */ -#include "free.h" -#include "m4.h" -/*********************************************************/ +#ifdef BEAGLE +#include "beagle_utils.h" +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void PMat_K80(phydbl l,phydbl kappa, double ***Pij) +/* Handle any number of states (>1) */ +void PMat_JC69(phydbl l, int pos, phydbl *Pij, t_mod *mod) { - phydbl Ts,Tv,e1,e2,aux; + int ns; + int i,j; + + ns = mod->ns; + + for(i=0;i A*/ /*1 => C*/ /*2 => G*/ @@ -31,78 +54,56 @@ void PMat_K80(phydbl l,phydbl kappa, double ***Pij) /* Ts -> transition*/ /* Tv -> transversion*/ + aux = -2*l/(kappa+2); e1 = (phydbl)exp(aux *2); - if (1.0!=kappa) - { - e2 = (phydbl)exp(aux *(kappa+1)); - Tv = .25*(1-e1); - Ts = .25*(1+e1-2*e2); - } - else - { - Ts = Tv = .25*(1-e1); - } + e2 = (phydbl)exp(aux *(kappa+1)); + Tv = .25*(1-e1); + Ts = .25*(1+e1-2*e2); - (*Pij)[0][1] = (*Pij)[1][0] = Tv; - (*Pij)[0][2] = (*Pij)[2][0] = Ts; - (*Pij)[0][3] = (*Pij)[3][0] = Tv; + Pij[pos+ 4*0+0] = Pij[pos+ 4*1+1] = + Pij[pos+ 4*2+2] = Pij[pos+ 4*3+3] = 1.-Ts-2.*Tv; - (*Pij)[1][2] = (*Pij)[2][1] = Tv; - (*Pij)[1][3] = (*Pij)[3][1] = Ts; - - (*Pij)[2][3] = (*Pij)[3][2] = Tv; + Pij[pos+ 4*0+1] = Pij[pos+ 4*1+0] = Tv; + Pij[pos+ 4*0+2] = Pij[pos+ 4*2+0] = Ts; + Pij[pos+ 4*0+3] = Pij[pos+ 4*3+0] = Tv; - (*Pij)[0][0] = (*Pij)[1][1] = - (*Pij)[2][2] = (*Pij)[3][3] = 1.-Ts-2.*Tv; -} + Pij[pos+ 4*1+2] = Pij[pos+ 4*2+1] = Tv; + Pij[pos+ 4*1+3] = Pij[pos+ 4*3+1] = Ts; -/*********************************************************/ + Pij[pos+ 4*2+3] = Pij[pos+ 4*3+2] = Tv; + for(i=0;i<4;i++) for(j=0;j<4;j++) + if(Pij[pos + 4*i+j] < SMALL_PIJ) Pij[pos + 4*i+j] = SMALL_PIJ; -void PMat_TN93(phydbl l, model *mod, double ***Pij) +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void PMat_TN93(phydbl l, t_mod *mod, int pos, phydbl *Pij) { int i,j; phydbl e1,e2,e3; phydbl a1t,a2t,bt; phydbl A,C,G,T,R,Y; phydbl kappa1,kappa2; - int kappa_has_changed; - A = mod->pi[0]; C = mod->pi[1]; G = mod->pi[2]; T = mod->pi[3]; + A = mod->e_frq->pi->v[0]; C = mod->e_frq->pi->v[1]; G = mod->e_frq->pi->v[2]; T = mod->e_frq->pi->v[3]; R = A+G; Y = T+C; - kappa_has_changed = 0; - if(mod->kappa < .0) mod->kappa = 1.0e-5; + if(mod->kappa->v < .0) mod->kappa->v = 1.0e-5; - if((mod->whichmodel != F84) && (mod->whichmodel != TN93)) mod->lambda = 1.; + if((mod->whichmodel != F84) && (mod->whichmodel != TN93)) mod->lambda->v = 1.; else if(mod->whichmodel == F84) { - do - { - mod->lambda = (Y+(R-Y)/(2.*mod->kappa))/(R-(R-Y)/(2.*mod->kappa)); - - if(mod->lambda < .0) - { - mod->kappa += mod->kappa/10.; - kappa_has_changed = 1; - } - }while(mod->lambda < .0); - } - - - if((!mod->s_opt->opt_kappa) && (kappa_has_changed)) - { - printf("\n. WARNING: This transition/transversion ratio\n"); - printf(" is impossible with these base frequencies!\n"); - printf(" The ratio is now set to %.3f\n",mod->kappa); + mod->lambda->v = Get_Lambda_F84(mod->e_frq->pi->v,&mod->kappa->v); } - kappa2 = mod->kappa*2./(1.+mod->lambda); - kappa1 = kappa2 * mod->lambda; + kappa2 = mod->kappa->v*2./(1.+mod->lambda->v); + kappa1 = kappa2 * mod->lambda->v; - bt = l/(2.*(A*G*kappa1+C*T*kappa2+R*Y)); a1t = kappa1; @@ -113,113 +114,103 @@ void PMat_TN93(phydbl l, model *mod, double ***Pij) e2 = (phydbl)exp(-a2t*Y-bt*R); e3 = (phydbl)exp(-bt); + /*A->A*/Pij[pos + 4*0+0] = A+Y*A/R*e3+G/R*e1; + /*A->C*/Pij[pos + 4*0+1] = C*(1-e3); + /*A->G*/Pij[pos + 4*0+2] = G+Y*G/R*e3-G/R*e1; + /*A->T*/Pij[pos + 4*0+3] = T*(1-e3); - /*A->A*/(*Pij)[0][0] = A+Y*A/R*e3+G/R*e1; - /*A->C*/(*Pij)[0][1] = C*(1-e3); - /*A->G*/(*Pij)[0][2] = G+Y*G/R*e3-G/R*e1; - /*A->T*/(*Pij)[0][3] = T*(1-e3); + /*C->A*/Pij[pos + 4*1+0] = A*(1-e3); + /*C->C*/Pij[pos + 4*1+1] = C+R*C/Y*e3+T/Y*e2; + /*C->G*/Pij[pos + 4*1+2] = G*(1-e3); + /*C->T*/Pij[pos + 4*1+3] = T+R*T/Y*e3-T/Y*e2; - /*C->A*/(*Pij)[1][0] = A*(1-e3); - /*C->C*/(*Pij)[1][1] = C+R*C/Y*e3+T/Y*e2; - /*C->G*/(*Pij)[1][2] = G*(1-e3); - /*C->T*/(*Pij)[1][3] = T+R*T/Y*e3-T/Y*e2; + /*G->A*/Pij[pos + 4*2+0] = A+Y*A/R*e3-A/R*e1; + /*G->C*/Pij[pos + 4*2+1] = C*(1-e3); + /*G->G*/Pij[pos + 4*2+2] = G+Y*G/R*e3+A/R*e1; + /*G->T*/Pij[pos + 4*2+3] = T*(1-e3); - /*G->A*/(*Pij)[2][0] = A+Y*A/R*e3-A/R*e1; - /*G->C*/(*Pij)[2][1] = C*(1-e3); - /*G->G*/(*Pij)[2][2] = G+Y*G/R*e3+A/R*e1; - /*G->T*/(*Pij)[2][3] = T*(1-e3); + /*T->A*/Pij[pos + 4*3+0] = A*(1-e3); + /*T->C*/Pij[pos + 4*3+1] = C+R*C/Y*e3-C/Y*e2; + /*T->G*/Pij[pos + 4*3+2] = G*(1-e3); + /*T->T*/Pij[pos + 4*3+3] = T+R*T/Y*e3+C/Y*e2; - /*T->A*/(*Pij)[3][0] = A*(1-e3); - /*T->C*/(*Pij)[3][1] = C+R*C/Y*e3-C/Y*e2; - /*T->G*/(*Pij)[3][2] = G*(1-e3); - /*T->T*/(*Pij)[3][3] = T+R*T/Y*e3+C/Y*e2; - - For(i,4) For(j,4) - if((*Pij)[i][j] < MDBL_MIN) (*Pij)[i][j] = MDBL_MIN; + for(i=0;i<4;i++) for(j=0;j<4;j++) + if(Pij[pos + 4*i+j] < SMALL_PIJ) Pij[pos + 4*i+j] = SMALL_PIJ; + +/* /\*A->A*\/(*Pij)[0][0] = A+Y*A/R*e3+G/R*e1; */ +/* /\*A->C*\/(*Pij)[0][1] = C*(1-e3); */ +/* /\*A->G*\/(*Pij)[0][2] = G+Y*G/R*e3-G/R*e1; */ +/* /\*A->T*\/(*Pij)[0][3] = T*(1-e3); */ + +/* /\*C->A*\/(*Pij)[1][0] = A*(1-e3); */ +/* /\*C->C*\/(*Pij)[1][1] = C+R*C/Y*e3+T/Y*e2; */ +/* /\*C->G*\/(*Pij)[1][2] = G*(1-e3); */ +/* /\*C->T*\/(*Pij)[1][3] = T+R*T/Y*e3-T/Y*e2; */ + +/* /\*G->A*\/(*Pij)[2][0] = A+Y*A/R*e3-A/R*e1; */ +/* /\*G->C*\/(*Pij)[2][1] = C*(1-e3); */ +/* /\*G->G*\/(*Pij)[2][2] = G+Y*G/R*e3+A/R*e1; */ +/* /\*G->T*\/(*Pij)[2][3] = T*(1-e3); */ + +/* /\*T->A*\/(*Pij)[3][0] = A*(1-e3); */ +/* /\*T->C*\/(*Pij)[3][1] = C+R*C/Y*e3-C/Y*e2; */ +/* /\*T->G*\/(*Pij)[3][2] = G*(1-e3); */ +/* /\*T->T*\/(*Pij)[3][3] = T+R*T/Y*e3+C/Y*e2; */ + +/* for(i=0;i<4;i++) for(j=0;j<4;j++) */ +/* if((*Pij)[i][j] < SMALL) (*Pij)[i][j] = SMALL; */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Matinv(double *x, int n, int m, double *space) +phydbl Get_Lambda_F84(phydbl *pi, phydbl *kappa) { + phydbl A,C,G,T,R,Y,lambda; + int kappa_has_changed; -/* x[n*m] ... m>=n -*/ + A = pi[0]; C = pi[1]; G = pi[2]; T = pi[3]; + R = A+G; Y = T+C; - int i,j,k; - int *irow; - double ee, t,t1,xmax; - double det; - - ee = 1.0E-10; - det = 1.0; + if(*kappa < .0) *kappa = 1.0e-5; - irow = (int *)mCalloc(n,sizeof(int)); + kappa_has_changed = NO; - For (i,n) - { - xmax = 0.; - for (j=i; j=0; i--) - { - if (irow[i] == i) continue; - For(j,n) - { - t = x[j*m+i]; - x[j*m+i] = x[j*m + irow[i]]; - x[j*m + irow[i]] = t; - } - } + do + { + lambda = (Y+(R-Y)/(2.*(*kappa)))/(R-(R-Y)/(2.*(*kappa))); + + if(lambda < .0) + { + *kappa += *kappa/10.; + kappa_has_changed = YES; + } + }while(lambda < .0); - Free(irow); - return (1); + if(kappa_has_changed) + { + PhyML_Printf("\n. WARNING: This transition/transversion ratio\n"); + PhyML_Printf(" is impossible with these base frequencies!\n"); + PhyML_Printf(" The ratio is now set to %.3f\n",*kappa); + } + + return lambda; } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + /********************************************************************/ -/* void PMat_Empirical(phydbl l, model *mod, phydbl ***Pij) */ +/* void PMat_Empirical(phydbl l, t_mod *mod, phydbl ***Pij) */ /* */ /* Computes the substitution probability matrix */ /* from the initial substitution rate matrix and frequency vector */ /* and one specific branch length */ /* */ /* input : l , branch length */ -/* input : mod , choosen model parameters, qmat and pi */ +/* input : mod , choosen model parameters, qmat and pi */ /* ouput : Pij , substitution probability matrix */ /* */ /* matrix P(l) is computed as follows : */ @@ -241,12 +232,12 @@ int Matinv(double *x, int n, int m, double *space) /* */ /* the Taylor development of exp(Q*t) gives : */ /* P(l) = Vr*exp(D*t) *inverse(Vr) */ -/* = Vr*pow(exp(D/mr),l)*inverse(Vr) */ +/* = Vr*POW(exp(D/mr),l)*inverse(Vr) */ /* */ /* for performance we compute only once the following matrixes : */ /* Vr, inverse(Vr), exp(D/mr) */ /* thus each time we compute P(l) we only have to : */ -/* make 20 times the operation pow() */ +/* make 20 times the operation POW() */ /* make 2 20x20 matrix multiplications , that is : */ /* 16000 = 2x20x20x20 times the operation * */ /* 16000 = 2x20x20x20 times the operation + */ @@ -255,153 +246,202 @@ int Matinv(double *x, int n, int m, double *space) /* 8000 = 20x20x20 times the operation + */ /********************************************************************/ -void PMat_Empirical(phydbl l, model *mod, double ***Pij) +void PMat_Empirical(const phydbl l, const t_mod *mod, const int pos, phydbl *Pij, phydbl *tPij) { - int n = mod->ns; - int i, j, k; - double *U,*V,*R; - double *expt; - double *uexpt; + const unsigned int ns = mod->ns; + unsigned int i, j, k; + const phydbl *U,*V,*R; + phydbl *expt; + phydbl *uexpt; + phydbl sum; + assert(Pij); + expt = mod->eigen->e_val_im; uexpt = mod->eigen->r_e_vect_im; U = mod->eigen->r_e_vect; V = mod->eigen->l_e_vect; R = mod->eigen->e_val; /* exponential of the eigen value matrix */ - For(i,n) For(k,n) (*Pij)[i][k] = .0; + for(k=0;kns; + expt = mod->eigen->e_val_im; + uexpt = mod->eigen->r_e_vect_im; + U = mod->eigen->r_e_vect; + V = mod->eigen->l_e_vect; + R = mod->eigen->e_val; /* exponential of the eigen value matrix */ + + if(mod->ras->n_catg == 1) shape = 1.E+4; + else shape = mod->ras->alpha->v; + + + for(i=0;ins*i+k] = .0; + + if(shape < 1.E-10) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + /* Formula 13.42, page 220 of Felsenstein's book ``Inferring Phylogenies'' */ + for(k=0;kns*i+j] += (uexpt[i*n+k] * V[k*n+j]); + } + if(Pij[pos+mod->ns*i+j] < SMALL_PIJ) Pij[pos+mod->ns*i+j] = SMALL_PIJ; + } + +#ifdef DEBUG phydbl sum; sum = .0; - For (j,n) sum += (*Pij)[i][j]; + For (j,n) sum += Pij[pos+mod->ns*i+j]; if((sum > 1.+.0001) || (sum < 1.-.0001)) - { - printf("\n"); - printf("\n. Q\n"); - For(i,n) { For(j,n) printf("%7.3f ",mod->eigen->q[i*n+j]); printf("\n"); } - printf("\n. U\n"); - For(i,n) { For(j,n) printf("%7.3f ",U[i*n+j]); printf("\n"); } - printf("\n"); - printf("\n. V\n"); - For(i,n) { For(j,n) printf("%7.3f ",V[i*n+j]); printf("\n"); } - printf("\n"); - printf("\n. Eigen\n"); - For(i,n) printf("%E ",expt[i]); - printf("\n"); - printf("\n. Pij\n"); - For(i,n) { For (j,n) printf("%f ",(*Pij)[i][j]); printf("\n"); } - printf("\n. sum = %f",sum); - if(mod->m4mod) - { - int i; - printf("\n. mod->m4mod->alpha = %f",mod->m4mod->alpha); - printf("\n. mod->m4mod->delta = %f",mod->m4mod->delta); - For(i,mod->m4mod->n_h) - { - printf("\n. mod->m4mod->multipl[%d] = %f",i,mod->m4mod->multipl[i]); - } - } - printf("\n. l=%f",l); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } + { + PhyML_Printf("\n"); + PhyML_Printf("\n. Q\n"); + for(i=0;ieigen->q[i*n+j]); PhyML_Printf("\n"); } + PhyML_Printf("\n. U\n"); + for(i=0;ins*i+j]); PhyML_Printf("\n"); } + PhyML_Printf("\n. sum = %f",sum); + PhyML_Fprintf(stderr,"\n. l=%f",l); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } #endif } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void PMat_Zero_Br_Len(model *mod, double ***Pij) +void PMat_Zero_Br_Len(t_mod *mod, int pos, phydbl *Pij) { int n = mod->ns; int i, j; - For (i,n) For (j,n) (*Pij)[i][j] = .0; - For (i,n) (*Pij)[i][i] = 1.0; + For (i,n) For (j,n) Pij[pos+mod->ns*i+j] = .0; + For (i,n) Pij[pos+mod->ns*i+i] = 1.0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void PMat(phydbl l, model *mod, double ***Pij) +/* + *Update a rate specific Transition Prob matrix for a given branch-length(already adjusted + *with the rate prior to this function being called) + * + * Pij: the P-matrix that will be adjusted + * l : branch length * rate + * pos: offset into a specific rate-category + * + */ +void PMat(phydbl l, t_mod *mod, int pos, phydbl *Pij, phydbl *tPij) { - if(l < BL_MIN) + /* Warning: l is never the log of branch length here */ + if(l < 0.0) { - PMat_Zero_Br_Len(mod,Pij); +#ifdef BEAGLE + Warn_And_Exit(TODO_BEAGLE); +#endif + PMat_Zero_Br_Len(mod,pos,Pij); } else { - switch(mod->datatype) - { - case NT : - { - if(mod->use_m4mod) - { - PMat_Empirical(l,mod,Pij); - } - else - { - if((mod->whichmodel == JC69) || - (mod->whichmodel == K80)) - { - PMat_K80(l,mod->kappa,Pij); - } - else - { - if( - (mod->whichmodel == F81) || - (mod->whichmodel == HKY85) || - (mod->whichmodel == F84) || - (mod->whichmodel == TN93)) - { - PMat_TN93(l,mod,Pij); - } - else - { - PMat_Empirical(l,mod,Pij); - } - } - break; - } - case AA : - { - PMat_Empirical(l,mod,Pij); - break; - } - } - } +#ifdef BEAGLE + //when there is no active instance (i.e. when we are building the initial tree) + if(UNINITIALIZED == mod->b_inst) PMat_Empirical(l,mod,pos,Pij,tPij); +#else + PMat_Empirical(l,mod,pos,Pij,tPij); +#endif } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + int GetDaa (phydbl *daa, phydbl *pi, char *file_name) { -/* Get the amino acid distance (or substitution rate) matrix +/* Get the amino acid distance (or substitution rate) matrix (grantham, dayhoff, jones, etc). */ FILE * fdaa; int i,j, naa; phydbl dmax,dmin; - phydbl sum; + phydbl sum; + double val; naa = 20; dmax = .0; @@ -409,2019 +449,121 @@ int GetDaa (phydbl *daa, phydbl *pi, char *file_name) fdaa = (FILE *)Openfile(file_name,0); - for(i=0; idaa[i*naa+j]) dmin=daa[i*naa+j]; +/* if(fscanf(fdaa, "%lf", &daa[i*naa+j])) Exit("\n. err aaRatefile"); */ + if(fscanf(fdaa, "%lf", &val)) Exit("\n. err aaRatefile"); + daa[i*naa+j] = (phydbl)val; + daa[j*naa+i]=daa[i*naa+j]; + if (dmaxdaa[i*naa+j]) dmin=daa[i*naa+j]; } - - For(i,naa) { - if(fscanf(fdaa,"%lf",&pi[i])!=1) Exit("err aaRatefile"); - } + + for(i=0;i1e-4) { - printf("\nSum of freq. = %.6f != 1 in aaRateFile\n",sum); + if (FABS(1-sum)>1e-4) { + PhyML_Printf("\nSum of freq. = %.6f != 1 in aaRateFile\n",sum); exit(-1); } - + fclose (fdaa); return (0); } -/*********************************************************/ - -int Init_Qmat_Dayhoff(double *daa, phydbl *pi) -{ - /* Dayhoff's model data - * Dayhoff, M.O., Schwartz, R.M., Orcutt, B.C. (1978) - * "A model of evolutionary change in proteins." - * Dayhoff, M.O.(ed.) Atlas of Protein Sequence Structur., Vol5, Suppl3. - * National Biomedical Research Foundation, Washington DC, pp.345-352. - */ - int i,j,naa; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - naa = 20; -/* printf("\n\n. REMINDER : THIS IS NOT DAYHOFF !!!\n\n"); */ - -/* daa[1*20 + 0] = 0.538903; */ -/* daa[2*20 + 0] = 0.412504; */ -/* daa[2*20 + 1] = 0.736081; */ -/* daa[3*20 + 0] = 0.586915; */ -/* daa[3*20 + 1] = 0.108051; */ -/* daa[3*20 + 2] = 5.446642; */ -/* daa[4*20 + 0] = 2.189718; */ -/* daa[4*20 + 1] = 0.830604; */ -/* daa[4*20 + 2] = 0.573426; */ -/* daa[4*20 + 3] = 0.077565; */ -/* daa[5*20 + 0] = 1.08213; */ -/* daa[5*20 + 1] = 2.950693; */ -/* daa[5*20 + 2] = 1.739514; */ -/* daa[5*20 + 3] = 0.559035; */ -/* daa[5*20 + 4] = 0.111314; */ -/* daa[6*20 + 0] = 1.386865; */ -/* daa[6*20 + 1] = 0.358434; */ -/* daa[6*20 + 2] = 0.541447; */ -/* daa[6*20 + 3] = 5.406871; */ -/* daa[6*20 + 4] = 0.003738; */ -/* daa[6*20 + 5] = 4.124043; */ -/* daa[7*20 + 0] = 2.085747; */ -/* daa[7*20 + 1] = 0.453132; */ -/* daa[7*20 + 2] = 1.815844; */ -/* daa[7*20 + 3] = 1.08647; */ -/* daa[7*20 + 4] = 0.526418; */ -/* daa[7*20 + 5] = 0.347693; */ -/* daa[7*20 + 6] = 0.438476; */ -/* daa[8*20 + 0] = 0.407898; */ -/* daa[8*20 + 1] = 2.689322; */ -/* daa[8*20 + 2] = 5.386808; */ -/* daa[8*20 + 3] = 0.884563; */ -/* daa[8*20 + 4] = 0.658583; */ -/* daa[8*20 + 5] = 4.588358; */ -/* daa[8*20 + 6] = 0.386218; */ -/* daa[8*20 + 7] = 0.368668; */ -/* daa[9*20 + 0] = 0.10177; */ -/* daa[9*20 + 1] = 0.104875; */ -/* daa[9*20 + 2] = 0.16239; */ -/* daa[9*20 + 3] = 0.011698; */ -/* daa[9*20 + 4] = 0.253282; */ -/* daa[9*20 + 5] = 0.083872; */ -/* daa[9*20 + 6] = 0.041767; */ -/* daa[9*20 + 7] = 0.009778; */ -/* daa[9*20 + 8] = 0.1042; */ -/* daa[10*20 + 0] = 0.248202; */ -/* daa[10*20 + 1] = 0.375742; */ -/* daa[10*20 + 2] = 0.093863; */ -/* daa[10*20 + 3] = 0.019241; */ -/* daa[10*20 + 4] = 0.572688; */ -/* daa[10*20 + 5] = 0.703538; */ -/* daa[10*20 + 6] = 0.071961; */ -/* daa[10*20 + 7] = 0.03006; */ -/* daa[10*20 + 8] = 0.418222; */ -/* daa[10*20 + 9] = 3.702051; */ -/* daa[11*20 + 0] = 0.652019; */ -/* daa[11*20 + 1] = 5.940478; */ -/* daa[11*20 + 2] = 2.352253; */ -/* daa[11*20 + 3] = 0.231001; */ -/* daa[11*20 + 4] = 0.027995; */ -/* daa[11*20 + 5] = 3.646743; */ -/* daa[11*20 + 6] = 1.507981; */ -/* daa[11*20 + 7] = 0.331175; */ -/* daa[11*20 + 8] = 0.698362; */ -/* daa[11*20 + 9] = 0.140326; */ -/* daa[11*20 + 10] = 0.171396; */ -/* daa[12*20 + 0] = 0.694226; */ -/* daa[12*20 + 1] = 0.419899; */ -/* daa[12*20 + 2] = 0.326927; */ -/* daa[12*20 + 3] = 0.039488; */ -/* daa[12*20 + 4] = 0.844827; */ -/* daa[12*20 + 5] = 1.394214; */ -/* daa[12*20 + 6] = 0.133235; */ -/* daa[12*20 + 7] = 0.085075; */ -/* daa[12*20 + 8] = 0.347092; */ -/* daa[12*20 + 9] = 4.051255; */ -/* daa[12*20 + 10] = 6.650794; */ -/* daa[12*20 + 11] = 0.617549; */ -/* daa[13*20 + 0] = 0.155206; */ -/* daa[13*20 + 1] = 0.057971; */ -/* daa[13*20 + 2] = 0.09816; */ -/* daa[13*20 + 3] = 0.020441; */ -/* daa[13*20 + 4] = 0.904305; */ -/* daa[13*20 + 5] = 0.052719; */ -/* daa[13*20 + 6] = 0.0219; */ -/* daa[13*20 + 7] = 0.046668; */ -/* daa[13*20 + 8] = 0.890005; */ -/* daa[13*20 + 9] = 0.844963; */ -/* daa[13*20 + 10] = 2.348881; */ -/* daa[13*20 + 11] = 0.028372; */ -/* daa[13*20 + 12] = 1.671635; */ -/* daa[14*20 + 0] = 1.433475; */ -/* daa[14*20 + 1] = 0.328393; */ -/* daa[14*20 + 2] = 0.173181; */ -/* daa[14*20 + 3] = 0.431874; */ -/* daa[14*20 + 4] = 0.09902; */ -/* daa[14*20 + 5] = 0.592324; */ -/* daa[14*20 + 6] = 0.488352; */ -/* daa[14*20 + 7] = 0.23865; */ -/* daa[14*20 + 8] = 0.462856; */ -/* daa[14*20 + 9] = 0.057048; */ -/* daa[14*20 + 10] = 0.233532; */ -/* daa[14*20 + 11] = 0.387808; */ -/* daa[14*20 + 12] = 0.096377; */ -/* daa[14*20 + 13] = 0.079912; */ -/* daa[15*20 + 0] = 4.887126; */ -/* daa[15*20 + 1] = 0.883923; */ -/* daa[15*20 + 2] = 4.627163; */ -/* daa[15*20 + 3] = 1.122164; */ -/* daa[15*20 + 4] = 3.186667; */ -/* daa[15*20 + 5] = 1.085947; */ -/* daa[15*20 + 6] = 0.569339; */ -/* daa[15*20 + 7] = 1.993432; */ -/* daa[15*20 + 8] = 0.867972; */ -/* daa[15*20 + 9] = 0.070512; */ -/* daa[15*20 + 10] = 0.163009; */ -/* daa[15*20 + 11] = 0.718913; */ -/* daa[15*20 + 12] = 0.301103; */ -/* daa[15*20 + 13] = 0.32579; */ -/* daa[15*20 + 14] = 1.449582; */ -/* daa[16*20 + 0] = 2.030538; */ -/* daa[16*20 + 1] = 0.639463; */ -/* daa[16*20 + 2] = 2.076294; */ -/* daa[16*20 + 3] = 0.377239; */ -/* daa[16*20 + 4] = 1.42848; */ -/* daa[16*20 + 5] = 0.979403; */ -/* daa[16*20 + 6] = 0.647562; */ -/* daa[16*20 + 7] = 0.145556; */ -/* daa[16*20 + 8] = 0.493329; */ -/* daa[16*20 + 9] = 0.973405; */ -/* daa[16*20 + 10] = 0.271824; */ -/* daa[16*20 + 11] = 1.20033; */ -/* daa[16*20 + 12] = 1.659187; */ -/* daa[16*20 + 13] = 0.1217; */ -/* daa[16*20 + 14] = 0.571399; */ -/* daa[16*20 + 15] = 6.641034; */ -/* daa[17*20 + 0] = 0.131405; */ -/* daa[17*20 + 1] = 0.552911; */ -/* daa[17*20 + 2] = 0.079985; */ -/* daa[17*20 + 3] = 0.060514; */ -/* daa[17*20 + 4] = 0.633662; */ -/* daa[17*20 + 5] = 0.21823; */ -/* daa[17*20 + 6] = 0.074988; */ -/* daa[17*20 + 7] = 0.169114; */ -/* daa[17*20 + 8] = 0.847725; */ -/* daa[17*20 + 9] = 0.10627; */ -/* daa[17*20 + 10] = 0.622044; */ -/* daa[17*20 + 11] = 0.060755; */ -/* daa[17*20 + 12] = 0.719575; */ -/* daa[17*20 + 13] = 3.14824; */ -/* daa[17*20 + 14] = 0.077123; */ -/* daa[17*20 + 15] = 0.276716; */ -/* daa[17*20 + 16] = 0.148883; */ -/* daa[18*20 + 0] = 0.165179; */ -/* daa[18*20 + 1] = 0.224883; */ -/* daa[18*20 + 2] = 0.528334; */ -/* daa[18*20 + 3] = 0.121252; */ -/* daa[18*20 + 4] = 1.174118; */ -/* daa[18*20 + 5] = 0.177062; */ -/* daa[18*20 + 6] = 0.074715; */ -/* daa[18*20 + 7] = 0.042356; */ -/* daa[18*20 + 8] = 5.911187; */ -/* daa[18*20 + 9] = 0.192481; */ -/* daa[18*20 + 10] = 0.321454; */ -/* daa[18*20 + 11] = 0.090556; */ -/* daa[18*20 + 12] = 0.406415; */ -/* daa[18*20 + 13] = 10.908861; */ -/* daa[18*20 + 14] = 0.070752; */ -/* daa[18*20 + 15] = 0.328483; */ -/* daa[18*20 + 16] = 0.181539; */ -/* daa[18*20 + 17] = 3.823886; */ -/* daa[19*20 + 0] = 1.78517; */ -/* daa[19*20 + 1] = 0.166975; */ -/* daa[19*20 + 2] = 0.106482; */ -/* daa[19*20 + 3] = 0.041707; */ -/* daa[19*20 + 4] = 1.876812; */ -/* daa[19*20 + 5] = 0.22421; */ -/* daa[19*20 + 6] = 0.247356; */ -/* daa[19*20 + 7] = 0.06688; */ -/* daa[19*20 + 8] = 0.1436; */ -/* daa[19*20 + 9] = 9.60184; */ -/* daa[19*20 + 10] = 1.599119; */ -/* daa[19*20 + 11] = 0.17319; */ -/* daa[19*20 + 12] = 1.645134; */ -/* daa[19*20 + 13] = 0.438571; */ -/* daa[19*20 + 14] = 0.252486; */ -/* daa[19*20 + 15] = 0.105536; */ -/* daa[19*20 + 16] = 1.789097; */ -/* daa[19*20 + 17] = 0.147951; */ -/* daa[19*20 + 18] = 0.200571; */ - - - -/* for (i=0; i 2664 (67% of the original 3933 positions) - - The species included in the analysis were: - Harpiosquilla harpax [NCBI_TaxID 287944] - Ixodes uriae [NCBI_TaxID 59655] - Heptathela hangzhouensis [NCBI_TaxID 216259] - Triops longicaudatus [NCBI_TaxID 58777] - Gryllotalpa orientalis [NCBI_TaxID 213494] - lepidopsocid RS-2001 [NCBI_TaxID 159971] - Locusta migratoria [NCBI_TaxID 7004] - Drosophila yakuba [NCBI_TaxID 7245] - Ostrinia furnacalis [NCBI_TaxID 93504] - Megabalanus volcano [NCBI_TaxID 266495] - Periplaneta fuliginosa [NCBI_TaxID 36977] - Thermobia domestica [NCBI_TaxID 89055] - Aleurochiton aceris [NCBI_TaxID 266942] - Schizaphis graminum [NCBI_TaxID 13262] - Pteronarcys princeps [NCBI_TaxID 285953] - Aleurodicus dugesii [NCBI_TaxID 30099] - Pollicipes polymerus [NCBI_TaxID 36137] - Gomphiocephalus hodgsoni [NCBI_TaxID 221270] - Habronattus oregonensis [NCBI_TaxID 130930] - Speleonectes tulumensis [NCBI_TaxID 84346] - Hutchinsoniella macracantha [NCBI_TaxID 84335] - Haemaphysalis flava [NCBI_TaxID 181088] - Scutigera coleoptrata [NCBI_TaxID 29022] - Vargula hilgendorfii [NCBI_TaxID 6674] - Tricholepidion gertschi [NCBI_TaxID 89825] - Varroa destructor [NCBI_TaxID 109461] - Bombyx mandarina [NCBI_TaxID 7092] - Thyropygus sp. [NCBI_TaxID 174155] - Tribolium castaneum [NCBI_TaxID 7070] - Pagurus longicarpus [NCBI_TaxID 111067] - Limulus polyphemus [NCBI_TaxID 6850] - Tetrodontophora bielanensis [NCBI_TaxID 48717] - Penaeus monodon [NCBI_TaxID 6687] - Daphnia pulex [NCBI_TaxID 6669] - Apis mellifera [NCBI_TaxID 7469] - Anopheles gambiae [NCBI_TaxID 7165] - - The topology used for inferring the model was: - (((Daph_pulex,Trio_longi),((((((Aleu_aceri,Aleu_duges),Schi_grami),lepi_RS_20), - ((((Ostr_furna,Bomb_manda),(Dros_yakub,Anop_gambi)),Apis_melli),Trib_casta)), - ((Gryl_orien,Locu_migra),(Pter_princ,Peri_fulig))),(Tric_gerts,Ther_domes)), - (Scut_coleo,Thyr_sp),Varg_hilge,Hutc_macra,((((Ixod_uriae,Haem_flava),Varr_destr), - (Habr_orego,Hept_hangz)),Limu_polyp),(Poll_polym,Mega_volca),(Gomp_hodgs,Tetr_biela), - ((Pagu_longi,Pena_monod),Harp_harpa),Spel_tulum)); - - Note this is not the ML topology but the consensus one (based on morphological data, - phylogenetic reconstruction using nuclear genes, etc). Where relationships are - not clear, a polytomy was introduced (it contains quite a lot of polytomies!). - - The model was estimated using (the great and helpful) Ziheng Yang's Paml software package. - A four-categorized gamma distribution was used to account for heterogeneity (alpha - was estimated to be 0.47821). Sites with ambiguity data were taken into account. - - If you would like the data related to this matrix, please contact fabascal@uvigo.es. - Federico Abascal (c)2005. - */ - - int i,j,naa; - naa = 20; - daa[1*20+ 0] = 0.2; daa[2*20+ 0] = 0.2; daa[2*20+ 1] = 0.2; daa[3*20+ 0] = 0.6; - daa[3*20+ 1] = 4.3; daa[3*20+ 2] = 500.2; daa[4*20+ 0] = 253.5; daa[4*20+ 1] = 35.5; - daa[4*20+ 2] = 98.2; daa[4*20+ 3] = 10.6; daa[5*20+ 0] = 0.2; daa[5*20+ 1] = 154.0; - daa[5*20+ 2] = 261.8; daa[5*20+ 3] = 0.2; daa[5*20+ 4] = 0.2; daa[6*20+ 0] = 0.2; - daa[6*20+ 1] = 0.2; daa[6*20+ 2] = 183.0; daa[6*20+ 3] = 861.8; daa[6*20+ 4] = 0.2; - daa[6*20+ 5] = 261.6; daa[7*20+ 0] = 199.8; daa[7*20+ 1] = 0.2; daa[7*20+ 2] = 120.5; - daa[7*20+ 3] = 12.5; daa[7*20+ 4] = 80.5; daa[7*20+ 5] = 2.6; daa[7*20+ 6] = 43.9; - daa[8*20+ 0] = 0.2; daa[8*20+ 1] = 41.3; daa[8*20+ 2] = 179.5; daa[8*20+ 3] = 0.2; - daa[8*20+ 4] = 12.4; daa[8*20+ 5] = 313.5; daa[8*20+ 6] = 15.2; daa[8*20+ 7] = 0.2; - daa[9*20+ 0] = 25.7; daa[9*20+ 1] = 1.8; daa[9*20+ 2] = 21.3; daa[9*20+ 3] = 6.6; - daa[9*20+ 4] = 63.0; daa[9*20+ 5] = 10.5; daa[9*20+ 6] = 6.8; daa[9*20+ 7] = 2.7; - daa[9*20+ 8] = 0.2; daa[10*20+ 0] = 3.7; daa[10*20+ 1] = 1.8; daa[10*20+ 2] = 12.6; - daa[10*20+ 3] = 1.2; daa[10*20+ 4] = 78.7; daa[10*20+ 5] = 16.3; daa[10*20+ 6] = 1.7; - daa[10*20+ 7] = 1.4; daa[10*20+ 8] = 5.5; daa[10*20+ 9] = 514.5; daa[11*20+ 0] = 0.2; - daa[11*20+ 1] = 208.6; daa[11*20+ 2] = 467.3; daa[11*20+ 3] = 1.7; daa[11*20+ 4] = 0.2; - daa[11*20+ 5] = 349.3; daa[11*20+ 6] = 106.3; daa[11*20+ 7] = 0.2; daa[11*20+ 8] = 0.2; - daa[11*20+ 9] = 3.5; daa[11*20+ 10] = 3.8; daa[12*20+ 0] = 120.6; daa[12*20+ 1] = 5.2; - daa[12*20+ 2] = 78.8; daa[12*20+ 3] = 0.2; daa[12*20+ 4] = 312.3; daa[12*20+ 5] = 67.3; - daa[12*20+ 6] = 0.2; daa[12*20+ 7] = 55.7; daa[12*20+ 8] = 0.2; daa[12*20+ 9] = 514.8; - daa[12*20+ 10] = 885.5; daa[12*20+ 11] = 105.6; daa[13*20+ 0] = 13.1; daa[13*20+ 1] = 4.7; - daa[13*20+ 2] = 19.7; daa[13*20+ 3] = 0.2; daa[13*20+ 4] = 184.1; daa[13*20+ 5] = 0.2; - daa[13*20+ 6] = 0.2; daa[13*20+ 7] = 0.8; daa[13*20+ 8] = 13.8; daa[13*20+ 9] = 117.9; - daa[13*20+ 10] = 262.6; daa[13*20+ 11] = 10.7; daa[13*20+ 12] = 321.6; daa[14*20+ 0] = 49.3; - daa[14*20+ 1] = 0.2; daa[14*20+ 2] = 16.5; daa[14*20+ 3] = 0.2; daa[14*20+ 4] = 0.2; - daa[14*20+ 5] = 39.3; daa[14*20+ 6] = 7.9; daa[14*20+ 7] = 0.2; daa[14*20+ 8] = 0.8; - daa[14*20+ 9] = 0.2; daa[14*20+ 10] = 12.2; daa[14*20+ 11] = 16.8; daa[14*20+ 12] = 5.3; - daa[14*20+ 13] = 14.6; daa[15*20+ 0] = 673.0; daa[15*20+ 1] = 2.7; daa[15*20+ 2] = 398.4; - daa[15*20+ 3] = 44.4; daa[15*20+ 4] = 664.2; daa[15*20+ 5] = 52.4; daa[15*20+ 6] = 31.5; - daa[15*20+ 7] = 226.0; daa[15*20+ 8] = 10.6; daa[15*20+ 9] = 7.2; daa[15*20+ 10] = 8.2; - daa[15*20+ 11] = 144.2; daa[15*20+ 12] = 111.7; daa[15*20+ 13] = 36.1; daa[15*20+ 14] = 86.5; - daa[16*20+ 0] = 243.9; daa[16*20+ 1] = 0.2; daa[16*20+ 2] = 165.9; daa[16*20+ 3] = 0.2; - daa[16*20+ 4] = 182.8; daa[16*20+ 5] = 43.7; daa[16*20+ 6] = 43.4; daa[16*20+ 7] = 0.2; - daa[16*20+ 8] = 18.6; daa[16*20+ 9] = 203.7; daa[16*20+ 10] = 47.8; daa[16*20+ 11] = 69.5; - daa[16*20+ 12] = 288.6; daa[16*20+ 13] = 13.5; daa[16*20+ 14] = 46.8; daa[16*20+ 15] = 660.4; - daa[17*20+ 0] = 0.2; daa[17*20+ 1] = 0.2; daa[17*20+ 2] = 7.7; daa[17*20+ 3] = 0.2; - daa[17*20+ 4] = 21.6; daa[17*20+ 5] = 6.7; daa[17*20+ 6] = 11.0; daa[17*20+ 7] = 1.9; - daa[17*20+ 8] = 0.2; daa[17*20+ 9] = 0.2; daa[17*20+ 10] = 21.1; daa[17*20+ 11] = 16.0; - daa[17*20+ 12] = 70.7; daa[17*20+ 13] = 53.7; daa[17*20+ 14] = 0.2; daa[17*20+ 15] = 2.4; - daa[17*20+ 16] = 0.2; daa[18*20+ 0] = 1.2; daa[18*20+ 1] = 3.9; daa[18*20+ 2] = 251.2; - daa[18*20+ 3] = 0.2; daa[18*20+ 4] = 72.0; daa[18*20+ 5] = 86.7; daa[18*20+ 6] = 7.7; - daa[18*20+ 7] = 8.6; daa[18*20+ 8] = 191.4; daa[18*20+ 9] = 12.3; daa[18*20+ 10] = 19.8; - daa[18*20+ 11] = 117.1; daa[18*20+ 12] = 70.9; daa[18*20+ 13] = 791.6; daa[18*20+ 14] = 18.4; - daa[18*20+ 15] = 30.5; daa[18*20+ 16] = 46.0; daa[18*20+ 17] = 37.7; daa[19*20+ 0] = 339.9; - daa[19*20+ 1] = 0.2; daa[19*20+ 2] = 22.6; daa[19*20+ 3] = 0.2; daa[19*20+ 4] = 350.4; - daa[19*20+ 5] = 0.2; daa[19*20+ 6] = 13.6; daa[19*20+ 7] = 2.6; daa[19*20+ 8] = 0.2; - daa[19*20+ 9] = 1854.5; daa[19*20+ 10] = 84.7; daa[19*20+ 11] = 26.1; daa[19*20+ 12] = 281.3; - daa[19*20+ 13] = 51.9; daa[19*20+ 14] = 31.7; daa[19*20+ 15] = 60.6; daa[19*20+ 16] = 544.1; - daa[19*20+ 17] = 0.2; daa[19*20+ 18] = 1.6; - -/* MtArt.old: esta es la MtArt que hice con 26 secuencias (2 outgroups) con una topologia incorrecta - daa[1*20+ 0] = 0.2; daa[2*20+ 0] = 0.2; daa[2*20+ 1] = 8.0; daa[3*20+ 0] = 0.2; - daa[3*20+ 1] = 0.2; daa[3*20+ 2] = 441.7; daa[4*20+ 0] = 287.9; daa[4*20+ 1] = 48.4; - daa[4*20+ 2] = 82.4; daa[4*20+ 3] = 0.2; daa[5*20+ 0] = 0.2; daa[5*20+ 1] = 149.9; - daa[5*20+ 2] = 278.6; daa[5*20+ 3] = 0.2; daa[5*20+ 4] = 21.7; daa[6*20+ 0] = 6.6; - daa[6*20+ 1] = 0.2; daa[6*20+ 2] = 213.9; daa[6*20+ 3] = 760.8; daa[6*20+ 4] = 0.2; - daa[6*20+ 5] = 292.9; daa[7*20+ 0] = 228.2; daa[7*20+ 1] = 0.2; daa[7*20+ 2] = 97.1; - daa[7*20+ 3] = 10.4; daa[7*20+ 4] = 98.4; daa[7*20+ 5] = 4.0; daa[7*20+ 6] = 48.7; - daa[8*20+ 0] = 0.2; daa[8*20+ 1] = 56.7; daa[8*20+ 2] = 156.4; daa[8*20+ 3] = 24.5; - daa[8*20+ 4] = 15.5; daa[8*20+ 5] = 328.6; daa[8*20+ 6] = 7.0; daa[8*20+ 7] = 8.4; - daa[9*20+ 0] = 26.4; daa[9*20+ 1] = 1.6; daa[9*20+ 2] = 40.1; daa[9*20+ 3] = 0.2; - daa[9*20+ 4] = 22.1; daa[9*20+ 5] = 13.8; daa[9*20+ 6] = 0.2; daa[9*20+ 7] = 3.6; - daa[9*20+ 8] = 0.2; daa[10*20+ 0] = 3.4; daa[10*20+ 1] = 0.6; daa[10*20+ 2] = 13.8; - daa[10*20+ 3] = 0.7; daa[10*20+ 4] = 76.9; daa[10*20+ 5] = 12.1; daa[10*20+ 6] = 5.4; - daa[10*20+ 7] = 2.5; daa[10*20+ 8] = 2.9; daa[10*20+ 9] = 542.6; daa[11*20+ 0] = 0.2; - daa[11*20+ 1] = 240.2; daa[11*20+ 2] = 602.8; daa[11*20+ 3] = 35.5; daa[11*20+ 4] = 0.2; - daa[11*20+ 5] = 357.6; daa[11*20+ 6] = 62.6; daa[11*20+ 7] = 0.2; daa[11*20+ 8] = 3.3; - daa[11*20+ 9] = 0.2; daa[11*20+ 10] = 17.5; daa[12*20+ 0] = 119.0; daa[12*20+ 1] = 0.2; - daa[12*20+ 2] = 91.4; daa[12*20+ 3] = 6.4; daa[12*20+ 4] = 332.3; daa[12*20+ 5] = 65.4; - daa[12*20+ 6] = 0.2; daa[12*20+ 7] = 60.4; daa[12*20+ 8] = 2.4; daa[12*20+ 9] = 492.5; - daa[12*20+ 10] = 815.8; daa[12*20+ 11] = 67.3; daa[13*20+ 0] = 8.2; daa[13*20+ 1] = 6.4; - daa[13*20+ 2] = 31.5; daa[13*20+ 3] = 3.4; daa[13*20+ 4] = 174.4; daa[13*20+ 5] = 5.7; - daa[13*20+ 6] = 5.7; daa[13*20+ 7] = 2.1; daa[13*20+ 8] = 11.0; daa[13*20+ 9] = 94.4; - daa[13*20+ 10] = 243.3; daa[13*20+ 11] = 12.3; daa[13*20+ 12] = 357.8; daa[14*20+ 0] = 62.5; - daa[14*20+ 1] = 0.4; daa[14*20+ 2] = 17.5; daa[14*20+ 3] = 0.2; daa[14*20+ 4] = 0.2; - daa[14*20+ 5] = 48.6; daa[14*20+ 6] = 17.7; daa[14*20+ 7] = 2.7; daa[14*20+ 8] = 0.2; - daa[14*20+ 9] = 0.2; daa[14*20+ 10] = 11.2; daa[14*20+ 11] = 21.7; daa[14*20+ 12] = 5.2; - daa[14*20+ 13] = 12.6; daa[15*20+ 0] = 659.0; daa[15*20+ 1] = 5.2; daa[15*20+ 2] = 469.8; - daa[15*20+ 3] = 52.3; daa[15*20+ 4] = 570.7; daa[15*20+ 5] = 47.8; daa[15*20+ 6] = 37.3; - daa[15*20+ 7] = 227.8; daa[15*20+ 8] = 12.7; daa[15*20+ 9] = 12.3; daa[15*20+ 10] = 7.4; - daa[15*20+ 11] = 189.0; daa[15*20+ 12] = 155.3; daa[15*20+ 13] = 43.8; daa[15*20+ 14] = 103.4; - daa[16*20+ 0] = 276.4; daa[16*20+ 1] = 1.6; daa[16*20+ 2] = 175.6; daa[16*20+ 3] = 0.2; - daa[16*20+ 4] = 96.2; daa[16*20+ 5] = 71.4; daa[16*20+ 6] = 37.4; daa[16*20+ 7] = 0.2; - daa[16*20+ 8] = 14.2; daa[16*20+ 9] = 212.5; daa[16*20+ 10] = 38.5; daa[16*20+ 11] = 97.4; - daa[16*20+ 12] = 254.7; daa[16*20+ 13] = 2.1; daa[16*20+ 14] = 41.6; daa[16*20+ 15] = 670.6; - daa[17*20+ 0] = 6.2; daa[17*20+ 1] = 0.2; daa[17*20+ 2] = 0.2; daa[17*20+ 3] = 5.6; - daa[17*20+ 4] = 0.2; daa[17*20+ 5] = 0.2; daa[17*20+ 6] = 3.1; daa[17*20+ 7] = 0.4; - daa[17*20+ 8] = 0.2; daa[17*20+ 9] = 15.2; daa[17*20+ 10] = 11.5; daa[17*20+ 11] = 32.6; - daa[17*20+ 12] = 82.4; daa[17*20+ 13] = 81.9; daa[17*20+ 14] = 0.2; daa[17*20+ 15] = 9.7; - daa[17*20+ 16] = 0.2; daa[18*20+ 0] = 1.6; daa[18*20+ 1] = 7.7; daa[18*20+ 2] = 242.5; - daa[18*20+ 3] = 0.2; daa[18*20+ 4] = 88.0; daa[18*20+ 5] = 93.1; daa[18*20+ 6] = 0.2; - daa[18*20+ 7] = 6.0; daa[18*20+ 8] = 113.7; daa[18*20+ 9] = 22.1; daa[18*20+ 10] = 17.2; - daa[18*20+ 11] = 138.5; daa[18*20+ 12] = 37.6; daa[18*20+ 13] = 770.2; daa[18*20+ 14] = 5.3; - daa[18*20+ 15] = 25.0; daa[18*20+ 16] = 55.5; daa[18*20+ 17] = 69.3; daa[19*20+ 0] = 307.8; - daa[19*20+ 1] = 2.2; daa[19*20+ 2] = 6.9; daa[19*20+ 3] = 0.2; daa[19*20+ 4] = 405.7; - daa[19*20+ 5] = 0.8; daa[19*20+ 6] = 20.2; daa[19*20+ 7] = 5.7; daa[19*20+ 8] = 0.2; - daa[19*20+ 9] = 1687.9; daa[19*20+ 10] = 49.4; daa[19*20+ 11] = 23.4; daa[19*20+ 12] = 329.9; - daa[19*20+ 13] = 86.3; daa[19*20+ 14] = 27.3; daa[19*20+ 15] = 95.0; daa[19*20+ 16] = 443.0; - daa[19*20+ 17] = 2.4; daa[19*20+ 18] = 0.2; -3*/ - for (i=0; iseq_len = data->init_len; - - if(!mod->invar) - { - For(i,data->crunch_len) data->invar[i] = 0; - } - else - { - if(mod->s_opt->opt_pinvar) mod->pinvar = data->obs_pinvar; - } + phydbl sum,mr; - ns = mod->ns; + for(i=0;ipi[i] = data->b_frq[i]; - mod->pi_unscaled[i] = mod->pi[i] * 100.; - } - - if(mod->datatype == NT) /* Nucleotides */ - { - /* init for nucleotides */ - mod->lambda = 1.; - - if((mod->whichmodel == JC69) || (mod->whichmodel == K80)) - { - mod->pi[0] = mod->pi[1] = mod->pi[2] = mod->pi[3] = .25; - } - - if((mod->whichmodel == JC69) || - (mod->whichmodel == F81) || - (mod->whichmodel == GTR) || - (mod->whichmodel == CUSTOM)) - { - mod->kappa = 1.; - } - - if(mod->whichmodel == F84) - { - aux = ((mod->pi[0]+mod->pi[2])-(mod->pi[1]+mod->pi[3]))/(2.*mod->kappa); - mod->lambda = ((mod->pi[1]+mod->pi[3]) + aux)/((mod->pi[0]+mod->pi[2]) - aux); - } - - if(mod->whichmodel == HKY85) mod->update_eigen = 1; - - if(mod->whichmodel == GTR) - { - mod->custom_mod_string[0] = '0'; - mod->custom_mod_string[1] = '1'; - mod->custom_mod_string[2] = '2'; - mod->custom_mod_string[3] = '3'; - mod->custom_mod_string[4] = '4'; - mod->custom_mod_string[5] = '5'; - Translate_Custom_Mod_String(mod); - mod->update_eigen = 1; - } - - if(mod->whichmodel == CUSTOM) - { - if(mod->s_opt->user_state_freq) For(i,4) mod->pi[i] = mod->user_b_freq[i]; - mod->update_eigen = 1; - } - /* wash. error checking */ - if(!mod->use_m4mod) { - if (Set_Model_Parameters(mod)==0){ - return 0; - } - } + PhyML_Fprintf(stderr,"\n. rr[%d]=%f",(int)(ns*(ns-1)/2)-1,rr[(int)(ns*(ns-1)/2)-1]); + assert(FALSE); } - else - { /* init for amino-acids */ - /* see comments of PMat_Empirical for details */ - /* read pi and Q from file */ - - /* These initialisations are needed when analysing multiple - * data sets - */ - For(i,ns*ns) mod->qmat[i] = .0; - For(i,ns ) mod->pi[i] = .0; - - - switch(mod->whichmodel) - { - case DAYHOFF : - { - Init_Qmat_Dayhoff(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case JTT : - { - Init_Qmat_JTT(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case MTREV : - { - Init_Qmat_MtREV(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case LG : - { - Init_Qmat_LG(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case WAG : - { - Init_Qmat_WAG(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case DCMUT : - { - Init_Qmat_DCMut(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case RTREV : - { - Init_Qmat_RtREV(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case CPREV : - { - Init_Qmat_CpREV(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case VT : - { - Init_Qmat_VT(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case BLOSUM62 : - { - Init_Qmat_Blosum62(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case MTMAM : - { - Init_Qmat_MtMam(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case MTART : - { - Init_Qmat_MtArt(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case HIVW : - { - Init_Qmat_HIVw(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case HIVB : - { - Init_Qmat_HIVb(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - break; - } - case CUSTOMAA : - { - FILE *fp; - char *filename; - - filename = (char *)mCalloc(T_MAX_NAME,sizeof(char)); - - fflush(NULL); - printf("\n"); - printf("\n. Enter the rate matrix file name > "); fflush(NULL); - Getstring_Stdin(filename); - fp = Openfile(filename,0); - printf("\n"); - fflush(NULL); - - Read_Qmat(mod->qmat,mod->pi,fp); - Print_Qmat_AA(mod->qmat,mod->pi); - if(mod->s_opt->opt_state_freq) - For(i,ns) mod->pi[i] = data->b_frq[i]; - Free(filename); - break; - } - default : break; - } - - - /* multiply the nth col of Q by the nth term of pi/100 just as in PAML */ - For(i,ns) For(j,ns) mod->qmat[i*ns+j] *= mod->pi[j] / 100.0; - - - /* compute diagonal terms of Q and mean rate mr = l/t */ - mod->mr = .0; - For (i,ns) - { - sum=.0; - For(j, ns) sum += mod->qmat[i*ns+j]; - mod->qmat[i*ns+i] = -sum; - mod->mr += mod->pi[i] * sum; - } - - /* scale instantaneous rate matrix so that mu=1 */ - For (i,ns*ns) mod->qmat[i] /= mod->mr; - - - /* compute eigenvectors/values */ - result = 0; - - For(i,ns*ns) mod->qmat_buff[i] = mod->qmat[i]; - - if(!Eigen(1,mod->qmat_buff,mod->eigen->size,mod->eigen->e_val, - mod->eigen->e_val_im,mod->eigen->r_e_vect, - mod->eigen->r_e_vect_im,mod->eigen->space)) - { - /* compute inverse(Vr) into Vi */ - For (i,ns*ns) mod->eigen->l_e_vect[i] = mod->eigen->r_e_vect[i]; - Matinv(mod->eigen->l_e_vect,mod->eigen->size,mod->eigen->size, mod->eigen->space); - - /* compute the diagonal terms of exp(D) */ - For(i,ns) mod->eigen->e_val[i] = (double)exp(mod->eigen->e_val[i]); - } - else - { - if (result==-1) printf("\n. Eigenvalues/vectors computation does not converge : computation cancelled"); - else if (result==1) printf("\n. Complex eigenvalues/vectors : computation cancelled"); - } - } - - - mod->alpha_old = mod->alpha; - mod->kappa_old = mod->kappa; - mod->lambda_old = mod->lambda; - mod->pinvar_old = mod->pinvar; - - free(dr);free(di);free(space); - - return(1); -} - -/*********************************************************/ - -void Update_Qmat_Generic(double *rr, double *pi, int ns, double *qmat) -{ - int i,j; - phydbl sum,mr; - - For(i,ns*ns) qmat[i] = .0; - if(rr[(int)(ns*(ns-1)/2)-1] < 0.00001) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } + /* PhyML_Printf("\n"); */ + /* For(i,(int)(ns*(ns-1)/2)) */ + /* { */ + /* PhyML_Printf("\n> rr %d = %f",i,rr[i]); */ + /* } */ -/* printf("\n"); */ -/* For(i,(int)(ns*(ns-1)/2)) */ -/* { */ -/* printf("\n> rr %d = %f",i,rr[i]); */ -/* } */ - - For(i,(int)(ns*(ns-1)/2)) - { + for(i=0;i<(int)(ns*(ns-1)/2);++i) + { rr[i] /= rr[(int)(ns*(ns-1)/2)-1]; } - + /* Fill the non-diagonal parts */ - For(i,ns) + for(i=0;i RR_MAX) rr[i] = RR_MAX; qmat[0*4+1] = (rr[0]*pi[1]); qmat[0*4+2] = (rr[1]*pi[2]); qmat[0*4+3] = (rr[2]*pi[3]); - + qmat[1*4+0] = (rr[0]*pi[0]); qmat[1*4+2] = (rr[3]*pi[2]); qmat[1*4+3] = (rr[4]*pi[3]); @@ -2441,318 +583,571 @@ void Update_Qmat_GTR(double *rr, phydbl *rr_val, int *rr_num, double *pi, double /* compute diagonal terms of Q and mean rate mr = l/t */ mr = .0; - For (i,4) mr += pi[i] * (-qmat[i*4+i]); - For(i,16) qmat[i] /= mr; + for(i=0;i<4;i++) mr += pi[i] * (-qmat[i*4+i]); + for(i=0;i<16;i++) qmat[i] /= mr; + /* PhyML_Printf("\n. rr[0]=%f rr[1]=%f rr[2]=%f rr[3]=%f rr[4]=%f rr[5]=%f", */ + /* rr[0], */ + /* rr[1], */ + /* rr[2], */ + /* rr[3], */ + /* rr[4], */ + /* rr[5]); */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Update_Qmat_HKY(double kappa, double *pi, double *qmat) + +void Update_Qmat_HKY(phydbl kappa, phydbl *pi, phydbl *qmat) { int i; phydbl mr; - - /* A -> C */ qmat[0*4+1] = (double)(pi[1]); - /* A -> G */ qmat[0*4+2] = (double)(kappa*pi[2]); - /* A -> T */ qmat[0*4+3] = (double)(pi[3]); - - /* C -> A */ qmat[1*4+0] = (double)(pi[0]); - /* C -> G */ qmat[1*4+2] = (double)(pi[2]); - /* C -> T */ qmat[1*4+3] = (double)(kappa*pi[3]); - /* G -> A */ qmat[2*4+0] = (double)(kappa*pi[0]); - /* G -> C */ qmat[2*4+1] = (double)(pi[1]); - /* G -> T */ qmat[2*4+3] = (double)(pi[3]); + /* A -> C */ qmat[0*4+1] = (phydbl)(pi[1]); + /* A -> G */ qmat[0*4+2] = (phydbl)(kappa*pi[2]); + /* A -> T */ qmat[0*4+3] = (phydbl)(pi[3]); - /* T -> A */ qmat[3*4+0] = (double)(pi[0]); - /* T -> C */ qmat[3*4+1] = (double)(kappa*pi[1]); - /* T -> G */ qmat[3*4+2] = (double)(pi[2]); + /* C -> A */ qmat[1*4+0] = (phydbl)(pi[0]); + /* C -> G */ qmat[1*4+2] = (phydbl)(pi[2]); + /* C -> T */ qmat[1*4+3] = (phydbl)(kappa*pi[3]); - qmat[0*4+0] = (double)(-(qmat[0*4+1]+qmat[0*4+2]+qmat[0*4+3])); - qmat[1*4+1] = (double)(-(qmat[1*4+0]+qmat[1*4+2]+qmat[1*4+3])); - qmat[2*4+2] = (double)(-(qmat[2*4+0]+qmat[2*4+1]+qmat[2*4+3])); - qmat[3*4+3] = (double)(-(qmat[3*4+0]+qmat[3*4+1]+qmat[3*4+2])); + /* G -> A */ qmat[2*4+0] = (phydbl)(kappa*pi[0]); + /* G -> C */ qmat[2*4+1] = (phydbl)(pi[1]); + /* G -> T */ qmat[2*4+3] = (phydbl)(pi[3]); + + /* T -> A */ qmat[3*4+0] = (phydbl)(pi[0]); + /* T -> C */ qmat[3*4+1] = (phydbl)(kappa*pi[1]); + /* T -> G */ qmat[3*4+2] = (phydbl)(pi[2]); + + qmat[0*4+0] = (phydbl)(-(qmat[0*4+1]+qmat[0*4+2]+qmat[0*4+3])); + qmat[1*4+1] = (phydbl)(-(qmat[1*4+0]+qmat[1*4+2]+qmat[1*4+3])); + qmat[2*4+2] = (phydbl)(-(qmat[2*4+0]+qmat[2*4+1]+qmat[2*4+3])); + qmat[3*4+3] = (phydbl)(-(qmat[3*4+0]+qmat[3*4+1]+qmat[3*4+2])); /* compute diagonal terms of Q and mean rate mr = l/t */ mr = .0; For (i,4) mr += pi[i] * (-qmat[i*4+i]); - For(i,16) qmat[i] /= mr; + for(i=0;i<16;i++) qmat[i] /= mr; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Translate_Custom_Mod_String(model *mod) +void Translate_Custom_Mod_String(t_mod *mod) { int i,j; - For(i,6) mod->n_rr_per_cat[i] = 0; + for(i=0;i<6;i++) mod->r_mat->n_rr_per_cat->v[i] = 0; - mod->n_diff_rr = 0; + mod->r_mat->n_diff_rr = 0; - For(i,6) + for(i=0;i<6;i++) { - For(j,i) - { - if((mod->custom_mod_string[i] == mod->custom_mod_string[j])) - { - break; - } - } - + for(j=0;jcustom_mod_string->s[i] == mod->custom_mod_string->s[j]) + { + break; + } + } + if(i == j) - { - mod->rr_num[i] = mod->n_diff_rr; - mod->n_diff_rr++; - } + { + mod->r_mat->rr_num->v[i] = mod->r_mat->n_diff_rr; + mod->r_mat->n_diff_rr++; + } else - { - mod->rr_num[i] = mod->rr_num[j]; - } - - mod->n_rr_per_cat[mod->rr_num[j]]++; + { + mod->r_mat->rr_num->v[i] = mod->r_mat->rr_num->v[j]; + } + + mod->r_mat->n_rr_per_cat->v[mod->r_mat->rr_num->v[j]]++; } - -/* printf("\n"); */ -/* For(i,6) printf("%d ",mod->rr_param_num[i]); */ -/* For(i,mod->n_diff_rr_param) printf("\n. Class %d size %d",i+1,mod->n_rr_param_per_cat[i]); */ + + /* PhyML_Printf("\n"); */ + /* for(i=0;i<6;i++) PhyML_Printf("%d ",mod->r_mat->rr_num->v[i]); */ + /* for(i=0;ir_mat->n_diff_rr;i++) PhyML_Printf("\n. Class %d size %d",i+1,mod->r_mat->n_rr_per_cat->v[i]); */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// Update rate across sites distribution settings. -int Set_Model_Parameters(model *mod) +int Update_RAS(t_mod *mod) { phydbl sum; int i; - int result, n_iter; - phydbl scalar; - - DiscreteGamma(mod->gamma_r_proba, mod->gamma_rr, mod->alpha, mod->alpha, mod->n_catg,1); - - if(mod->n_rr_branch > 0) - DiscreteGamma(mod->p_rr_branch, mod->rr_branch, - mod->rr_branch_alpha, mod->rr_branch_alpha, - mod->n_rr_branch,1); - - if((mod->datatype == NT) && (mod->s_opt->opt_state_freq)) + if(mod->ras->free_mixt_rates == NO) { - sum = .0; - For(i,mod->ns) sum += fabs(mod->pi_unscaled[i]); - For(i,mod->ns) mod->pi[i] = fabs(mod->pi_unscaled[i])/sum; + DiscreteGamma(mod->ras->gamma_r_proba->v, + mod->ras->gamma_rr->v, + mod->ras->alpha->v, + mod->ras->alpha->v, + mod->ras->n_catg, + mod->ras->gamma_median); + } + else + { + // Update class frequencies +#ifndef PHYML + Qksort(mod->ras->gamma_r_proba_unscaled->v,NULL,0,mod->ras->n_catg-1); // Unscaled class frequencies sorted in increasing order +#endif + mod->ras->gamma_r_proba->v[0] = mod->ras->gamma_r_proba_unscaled->v[0] / mod->ras->gamma_r_proba_unscaled->v[mod->ras->n_catg-1]; + for(i=1;iras->n_catg;i++) + { + mod->ras->gamma_r_proba->v[i] = + (mod->ras->gamma_r_proba_unscaled->v[i] - + mod->ras->gamma_r_proba_unscaled->v[i-1]) / + mod->ras->gamma_r_proba_unscaled->v[mod->ras->n_catg-1]; + } + do - { - sum = .0; - For(i,mod->ns) - { - if(mod->pi[i] < 0.01) mod->pi[i]=0.01; - if(mod->pi[i] > 0.99) mod->pi[i]=0.99; - sum += mod->pi[i]; - } - For(i,mod->ns) mod->pi[i]/=sum; - } + { + sum = .0; + for(i=0;iras->n_catg;i++) + { + if(mod->ras->gamma_r_proba->v[i] < 0.01) mod->ras->gamma_r_proba->v[i]=0.01; + if(mod->ras->gamma_r_proba->v[i] > 0.99) mod->ras->gamma_r_proba->v[i]=0.99; + sum += mod->ras->gamma_r_proba->v[i]; + } + for(i=0;iras->n_catg;i++) mod->ras->gamma_r_proba->v[i]/=sum; + } while((sum > 1.01) || (sum < 0.99)); + + + // Update class rates + + if(mod->ras->normalise_rr == YES) + { + sum = .0; + for(i=0;iras->n_catg;i++) sum += mod->ras->gamma_r_proba->v[i] * mod->ras->gamma_rr_unscaled->v[i]; + for(i=0;iras->n_catg;i++) mod->ras->gamma_rr->v[i] = mod->ras->gamma_rr_unscaled->v[i]/sum; + } + else + { + for(i=0;iras->n_catg;i++) mod->ras->gamma_rr->v[i] = mod->ras->gamma_rr_unscaled->v[i] * mod->ras->free_rate_mr->v; + } + + /* printf("\n"); */ + /* for(i=0;iras->n_catg;i++) */ + /* printf("\nx %3d %12f %12f xx %12f %12f", */ + /* mod->ras->normalise_rr, */ + /* mod->ras->gamma_r_proba->v[i], */ + /* mod->ras->gamma_rr->v[i], */ + /* mod->ras->gamma_r_proba_unscaled->v[i], */ + /* mod->ras->gamma_rr_unscaled->v[i]); */ } +#ifdef BEAGLE + if(UNINITIALIZED != mod->b_inst) + update_beagle_ras(mod); +#endif - if(mod->update_eigen) + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Update_Efrq(t_mod *mod) +{ + unsigned int i; + phydbl sum; + + if((mod->io->datatype == NT) && (mod->s_opt->opt_state_freq == YES)) { - if(!mod->use_m4mod) - { - if(mod->datatype == NT) - { - if(mod->whichmodel == GTR) - Update_Qmat_GTR(mod->rr, mod->rr_val, mod->rr_num, mod->pi, mod->qmat); - else if(mod->whichmodel == CUSTOM) - Update_Qmat_GTR(mod->rr, mod->rr_val, mod->rr_num, mod->pi, mod->qmat); - else if(mod->whichmodel == HKY85) - Update_Qmat_HKY(mod->kappa, mod->pi, mod->qmat); - } - } -#ifndef PHYML - else - { - M4_Update_Qmat(mod->m4mod,mod); - } + for(i=0;ins;++i) mod->e_frq->pi->v[i] = exp(mod->e_frq->pi_unscaled->v[i]); + sum = 0.0; + for(i=0;ins;++i) sum += mod->e_frq->pi->v[i]; + for(i=0;ins;++i) mod->e_frq->pi->v[i] = mod->e_frq->pi->v[i]/sum; + +#ifdef BEAGLE + if(UNINITIALIZED != mod->b_inst) + update_beagle_efrqs(mod); #endif + for(i=0;ins;++i) if(mod->e_frq->pi->v[i] < E_FRQ_MIN) mod->e_frq->pi->v[i] = E_FRQ_MIN; + for(i=0;ins;++i) if(mod->e_frq->pi->v[i] > E_FRQ_MAX) mod->e_frq->pi->v[i] = E_FRQ_MAX; + } + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Set_Model_Parameters(t_mod *mod) +{ + if(!Update_Boundaries(mod)) return 0; + if(!Update_RAS(mod)) return 0; + if(!Update_Efrq(mod)) return 0; + if(!Update_Eigen(mod)) return 0; + if(mod->is_mixt_mod == YES) MIXT_Set_Model_Parameters(mod); + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Update_Boundaries(t_mod *mod) +{ + int i; + + if(mod->kappa->v > TSTV_MAX) mod->kappa->v = TSTV_MAX; + if(mod->kappa->v < TSTV_MIN) mod->kappa->v = TSTV_MIN; + + if(mod->ras->alpha->v < ALPHA_MIN) mod->ras->alpha->v = ALPHA_MIN; + if(mod->ras->alpha->v > ALPHA_MAX) mod->ras->alpha->v = ALPHA_MAX; + + if(mod->ras->free_mixt_rates == YES) + { + for(i=0;iras->n_catg;i++) + { + if(mod->ras->gamma_rr_unscaled->v[i] < GAMMA_RR_UNSCALED_MIN) + mod->ras->gamma_rr_unscaled->v[i] = GAMMA_RR_UNSCALED_MIN; + + if(mod->ras->gamma_rr_unscaled->v[i] > GAMMA_RR_UNSCALED_MAX) + mod->ras->gamma_rr_unscaled->v[i] = GAMMA_RR_UNSCALED_MAX; + + if(mod->ras->gamma_r_proba_unscaled->v[i] < GAMMA_R_PROBA_UNSCALED_MIN) + mod->ras->gamma_r_proba_unscaled->v[i] = GAMMA_R_PROBA_UNSCALED_MIN; + + if(mod->ras->gamma_r_proba_unscaled->v[i] > GAMMA_R_PROBA_UNSCALED_MAX) + mod->ras->gamma_r_proba_unscaled->v[i] = GAMMA_R_PROBA_UNSCALED_MAX; + } + } + + if(mod->whichmodel == CUSTOM || mod->whichmodel == GTR) + { + for(i=0;i<6;i++) if(mod->r_mat->rr_val->v[i] < UNSCALED_RR_MIN) mod->r_mat->rr_val->v[i] = UNSCALED_RR_MIN; + for(i=0;i<6;i++) if(mod->r_mat->rr_val->v[i] > UNSCALED_RR_MAX) mod->r_mat->rr_val->v[i] = UNSCALED_RR_MAX; + + for(i=0;i<6;i++) if(mod->r_mat->rr->v[i] < RR_MIN) mod->r_mat->rr->v[i] = RR_MIN; + for(i=0;i<6;i++) if(mod->r_mat->rr->v[i] > RR_MAX) mod->r_mat->rr->v[i] = RR_MAX; + } + + for(i=0;ins;i++) + { + if(mod->e_frq->pi_unscaled->v[i] < UNSCALED_E_FRQ_MIN) + mod->e_frq->pi_unscaled->v[i] = UNSCALED_E_FRQ_MIN; + + if(mod->e_frq->pi_unscaled->v[i] > UNSCALED_E_FRQ_MAX) + mod->e_frq->pi_unscaled->v[i] = UNSCALED_E_FRQ_MAX; + + if(mod->e_frq->pi->v[i] < E_FRQ_MIN) + mod->e_frq->pi->v[i] = E_FRQ_MIN; + + if(mod->e_frq->pi->v[i] > E_FRQ_MAX) + mod->e_frq->pi->v[i] = E_FRQ_MAX; + } + + if(mod->r_mat_weight->v < R_MAT_WEIGHT_MIN) mod->r_mat_weight->v = R_MAT_WEIGHT_MIN; + if(mod->r_mat_weight->v > R_MAT_WEIGHT_MAX) mod->r_mat_weight->v = R_MAT_WEIGHT_MAX; + + if(mod->e_frq_weight->v < E_FRQ_WEIGHT_MIN) mod->e_frq_weight->v = E_FRQ_WEIGHT_MIN; + if(mod->e_frq_weight->v > E_FRQ_WEIGHT_MAX) mod->e_frq_weight->v = E_FRQ_WEIGHT_MAX; + + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Update_Eigen(t_mod *mod) +{ + int result, n_iter; + phydbl scalar,eig_res; + int i; + + if(mod->update_eigen == YES) + { + //Update the Q-matrix first before computing the Eigen(because the Eigen is computed based on the Q-matrix) + if(mod->io->datatype == NT) + { + if(mod->whichmodel == GTR) + Update_Qmat_GTR(mod->r_mat->rr->v, mod->r_mat->rr_val->v, mod->r_mat->rr_num->v, mod->e_frq->pi->v, mod->r_mat->qmat->v, mod->s_opt->opt_rr); + else if(mod->whichmodel == CUSTOM) + Update_Qmat_GTR(mod->r_mat->rr->v, mod->r_mat->rr_val->v, mod->r_mat->rr_num->v, mod->e_frq->pi->v, mod->r_mat->qmat->v, mod->s_opt->opt_rr); + else if(mod->whichmodel == HKY85) + Update_Qmat_HKY(mod->kappa->v, mod->e_frq->pi->v, mod->r_mat->qmat->v); + else /* Any other nucleotide-based t_mod */ + Update_Qmat_HKY(mod->kappa->v, mod->e_frq->pi->v, mod->r_mat->qmat->v); + } + else if(mod->io->datatype == GENERIC) + { + Update_Qmat_Generic(mod->r_mat->rr_val->v,mod->e_frq->pi->v,mod->ns,mod->r_mat->qmat->v); + } + + //Now compute the eigen vectors and values scalar = 1.0; n_iter = 0; result = 0; - - For(i,mod->ns*mod->ns) mod->qmat_buff[i] = mod->qmat[i]; + + for(i=0;ins*mod->ns;++i) + { + mod->r_mat->qmat_buff->v[i] = mod->r_mat->qmat->v[i]; + } + + /* For(i,mod->eigen->size*mod->eigen->size) PhyML_Printf("\n. qmat [%d,%d]=%f",i/mod->eigen->size,i%mod->eigen->size,mod->r_mat->qmat->v[i]); */ + /* for(i=0;i<6;i++) PhyML_Printf("\n. rr: %f rr_Val: %f",mod->r_mat->rr_val->v[i],mod->r_mat->rr->v[i]); */ + /* for(i=0;i<4;i++) PhyML_Printf("\n. f: %f %f",mod->e_frq->pi->v[i],mod->e_frq->pi_unscaled->v[i]); */ + /* PhyML_Printf("\n"); */ + /* compute eigenvectors/values */ - /* if(!EigenRealGeneral(mod->eigen->size,mod->qmat,mod->eigen->e_val, */ + /* if(!EigenRealGeneral(mod->eigen->size,mod->r_mat->qmat,mod->eigen->e_val, */ /* mod->eigen->e_val_im, mod->eigen->r_e_vect, */ /* mod->eigen->space_int,mod->eigen->space)) */ - if(!Eigen(1,mod->qmat_buff,mod->eigen->size,mod->eigen->e_val, - mod->eigen->e_val_im,mod->eigen->r_e_vect, - mod->eigen->r_e_vect_im,mod->eigen->space)) - { - /* compute inverse(Vr) into Vi */ - For (i,mod->ns*mod->ns) mod->eigen->l_e_vect[i] = mod->eigen->r_e_vect[i]; - while(!Matinv(mod->eigen->l_e_vect, mod->eigen->size, mod->eigen->size, mod->eigen->space)) - { - printf("\n. Trying Q<-Q*scalar and then Root<-Root/scalar to fix this...\n"); - scalar += scalar / 3.; - For(i,mod->eigen->size*mod->eigen->size) mod->qmat_buff[i] = mod->qmat[i]; - For(i,mod->eigen->size*mod->eigen->size) mod->qmat_buff[i] *= scalar; - result = Eigen(1,mod->qmat_buff,mod->eigen->size,mod->eigen->e_val, - mod->eigen->e_val_im,mod->eigen->r_e_vect, - mod->eigen->r_e_vect_im,mod->eigen->space); - if (result == -1){ - fprintf(stderr,"\n. Eigenvalues/vectors computation did not converge : computation cancelled\n"); - return 0; + eig_res = Eigen(1,mod->r_mat->qmat_buff->v,mod->eigen->size,mod->eigen->e_val, + mod->eigen->e_val_im, + mod->eigen->r_e_vect, + mod->eigen->r_e_vect_im, + mod->eigen->space); + if(eig_res == 0) + { + /* compute inverse(Vr) into Vi */ + for (i=0;ins*mod->ns;++i) mod->eigen->l_e_vect[i] = mod->eigen->r_e_vect[i]; + while(!Matinv(mod->eigen->l_e_vect, mod->eigen->size, mod->eigen->size,YES)) + { + PhyML_Printf("\n. Trying Q<-Q*scalar and then Root<-Root/scalar to fix this...\n"); + scalar += scalar / 3.; + For(i,mod->eigen->size*mod->eigen->size) PhyML_Printf("\n. qmat [%d,%d]=%f",i/mod->eigen->size,i%mod->eigen->size,mod->r_mat->qmat->v[i]); + For(i,mod->eigen->size*mod->eigen->size) mod->r_mat->qmat_buff->v[i] = mod->r_mat->qmat->v[i]; + For(i,mod->eigen->size*mod->eigen->size) mod->r_mat->qmat_buff->v[i] *= scalar; + result = Eigen(1,mod->r_mat->qmat_buff->v,mod->eigen->size,mod->eigen->e_val, + mod->eigen->e_val_im,mod->eigen->r_e_vect, + mod->eigen->r_e_vect_im,mod->eigen->space); + if (result == -1) + { + PhyML_Fprintf(stderr,"\n. Eigenvalues/vectors computation did not converge: computation cancelled."); + Exit("\n"); + } + else if (result == 1) + { + PhyML_Fprintf(stderr,"\n. Complex eigenvalues/vectors: computation cancelled."); + Exit("\n"); + } + + For (i,mod->eigen->size*mod->eigen->size) mod->eigen->l_e_vect[i] = mod->eigen->r_e_vect[i]; + n_iter++; + if(n_iter > 100) + { + PhyML_Fprintf(stderr,"\n. Cannot work out eigen vectors."); + Exit("\n"); + } + } + for(i=0;ieigen->size;i++) mod->eigen->e_val[i] /= scalar; + +#ifdef BEAGLE + //Recall that BEAGLE is initialized *after* all the model parameters are set + //IOW, this function may be called before BEAGLE is initialized ("chicken-egg") + if(UNINITIALIZED != mod->b_inst) + update_beagle_eigen(mod); +#endif } - else if (result == 1){ - fprintf(stderr,"\n. Complex eigenvalues/vectors : computation cancelled\n"); + else if(eig_res == -1) + { + PhyML_Fprintf(stderr,"\n. kappa: %f",mod->kappa->v); + for(int i=0;ins;++i) + { + for(int j=0;jns;++j) + { + PhyML_Fprintf(stderr,"\n. Q[%d,%d]=%g",i,j,mod->r_mat->qmat->v[i*mod->ns+j]); + } + } + + PhyML_Fprintf(stderr,"\n. Eigenvalues/vectors computation does not converge. Computation cancelled."); return 0; } - - For (i,mod->eigen->size*mod->eigen->size) mod->eigen->l_e_vect[i] = mod->eigen->r_e_vect[i]; - n_iter++; - if(n_iter > 100) { - fprintf(stderr, "\n. Cannot work out eigen vectors\n"); - } - }; - For(i,mod->eigen->size) mod->eigen->e_val[i] /= scalar; - - /* compute the diagonal terms of exp(D) */ - For(i,mod->ns) mod->eigen->e_val[i] = (double)exp(mod->eigen->e_val[i]); - } - else + else if(eig_res == 1) { - fprintf(stderr, "\n. Eigenvalues/vectors computation does not converge : computation cancelled"); - //Warn_And_Exit("\n"); - return 0; + PhyML_Fprintf(stderr,"\n. WARNING: imaginary eigenvectors not null."); } } - return(1); + return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Switch_From_M4mod_To_Mod(model *mod) +void Switch_From_M4mod_To_Mod(t_mod *mod) { int i; mod->use_m4mod = 0; mod->ns = mod->m4mod->n_o; - For(i,mod->ns) mod->pi[i] = mod->m4mod->o_fq[i]; + for(i=0;ins;i++) mod->e_frq->pi->v[i] = mod->m4mod->o_fq[i]; mod->eigen->size = mod->ns; - mod->update_eigen = 1; + Set_Update_Eigen(YES,mod); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void PMat_MGF_Gamma(phydbl *Pij, phydbl shape, phydbl scale, phydbl scaling_fact, t_mod *mod) +{ + int dim; + int i,j,k; + phydbl *uexpt,*imbd; + + dim = mod->eigen->size; + uexpt = mod->eigen->r_e_vect_im; + imbd = mod->eigen->e_val_im; + + /* Get the eigenvalues of Q (not the exponentials) */ + for(i=0;ieigen->e_val[i]); + + /* Multiply them by the scaling factor */ + for(i=0;ieigen->r_e_vect[i*dim+k] * imbd[k]; + + for(i=0;ieigen->l_e_vect[k*dim+j]); + } + if(Pij[dim*i+j] < SMALL_PIJ) Pij[dim*i+j] = SMALL_PIJ; + } + } + + /* printf("\n. shape = %G scale = %G %f",shape,scale,Pij[1]); */ + /* printf("\n. Pij: %f",Pij[1]); */ + + /* printf("\n. Pmat"); */ + /* for(i=0;iuse_m4mod = 1; mod->ns = mod->m4mod->n_o * mod->m4mod->n_h; - For(i,mod->ns) mod->pi[i] = mod->m4mod->o_fq[i%mod->m4mod->n_o] * mod->m4mod->h_fq[i/mod->m4mod->n_o]; + for(i=0;ins;i++) mod->e_frq->pi->v[i] = mod->m4mod->o_fq[i%mod->m4mod->n_o] * mod->m4mod->h_fq[i/mod->m4mod->n_o]; mod->eigen->size = mod->ns; - mod->update_eigen = 1; + Set_Update_Eigen(YES,mod); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl General_Dist(phydbl *F, model *mod, eigen *eigen_struct) +phydbl General_Dist(phydbl *F, t_mod *mod, eigen *eigen_struct) { phydbl *pi,*mod_pi; int i,j,k; phydbl dist; phydbl sum; phydbl sum_ev; - double *F_double; + phydbl *F_phydbl; /* TO DO : call eigen decomposition function for all nt models */ - F_double = (double *)mCalloc(eigen_struct->size*eigen_struct->size,sizeof(double)); + F_phydbl = (phydbl *)mCalloc(eigen_struct->size*eigen_struct->size,sizeof(phydbl)); pi = (phydbl *)mCalloc(eigen_struct->size,sizeof(phydbl)); mod_pi = (phydbl *)mCalloc(eigen_struct->size,sizeof(phydbl)); - For(i,mod->ns) mod_pi[i] = mod->pi[i]; + for(i=0;ins;i++) mod_pi[i] = mod->e_frq->pi->v[i]; sum = .0; - For(i,eigen_struct->size) + for(i=0;isize;i++) { - For(j,eigen_struct->size) - { - pi[i] += (F[eigen_struct->size*i+j] + F[eigen_struct->size*j+i])/2.; - sum += F[eigen_struct->size*i+j]; - } + for(j=0;jsize;j++) + { + pi[i] += (F[eigen_struct->size*i+j] + F[eigen_struct->size*j+i])/2.; + sum += F[eigen_struct->size*i+j]; + } } - + Make_Symmetric(&F,eigen_struct->size); - Divide_Mat_By_Vect(&F,mod->pi,eigen_struct->size); + Divide_Mat_By_Vect(&F,mod->e_frq->pi->v,eigen_struct->size); /* Eigen decomposition of pi^{-1} x F */ - For(i,eigen_struct->size) For(j,eigen_struct->size) F_double[eigen_struct->size*i+j] = F[eigen_struct->size*i+j]; + for(i=0;isize;i++) for(j=0;jsize;j++) F_phydbl[eigen_struct->size*i+j] = F[eigen_struct->size*i+j]; - if(Eigen(1,F_double,mod->eigen->size,mod->eigen->e_val, - mod->eigen->e_val_im,mod->eigen->r_e_vect, - mod->eigen->r_e_vect_im,mod->eigen->space)) + if(Eigen(1,F_phydbl,mod->eigen->size,mod->eigen->e_val, + mod->eigen->e_val_im,mod->eigen->r_e_vect, + mod->eigen->r_e_vect_im,mod->eigen->space)) { - For(i,mod->ns) mod->pi[i] = mod_pi[i]; - Update_Qmat_GTR(mod->rr, mod->rr_val, mod->rr_num, mod->pi, mod->qmat); - Free(pi); - Free(mod_pi); + for(i=0;ins;i++) mod->e_frq->pi->v[i] = mod_pi[i]; + Update_Qmat_GTR(mod->r_mat->rr->v, mod->r_mat->rr_val->v, mod->r_mat->rr_num->v, mod->e_frq->pi->v, mod->r_mat->qmat->v, mod->s_opt->opt_rr); + Free(pi); + Free(mod_pi); return -1.; } /* Get the left eigen vector of pi^{-1} x F */ For(i,eigen_struct->size*eigen_struct->size) eigen_struct->l_e_vect[i] = eigen_struct->r_e_vect[i]; - if(!Matinv(eigen_struct->l_e_vect,eigen_struct->size,eigen_struct->size,eigen_struct->space)<0) + if(!Matinv(eigen_struct->l_e_vect,eigen_struct->size,eigen_struct->size,YES)) { - For(i,mod->ns) mod->pi[i] = mod_pi[i]; - Update_Qmat_GTR(mod->rr, mod->rr_val, mod->rr_num, mod->pi, mod->qmat); - Free(pi); - Free(mod_pi); + for(i=0;ins;i++) mod->e_frq->pi->v[i] = mod_pi[i]; + Update_Qmat_GTR(mod->r_mat->rr->v, mod->r_mat->rr_val->v, mod->r_mat->rr_num->v, mod->e_frq->pi->v, mod->r_mat->qmat->v, mod->s_opt->opt_rr); + Free(pi); + Free(mod_pi); return -1.; } /* log of eigen values */ - For(i,eigen_struct->size) + for(i=0;isize;i++) { /* if(eigen_struct->e_val[i] < 0.0) eigen_struct->e_val[i] = 0.0001; */ eigen_struct->e_val[i] = (phydbl)log(eigen_struct->e_val[i]); } - + /* Matrix multiplications log(pi^{-1} x F) */ - For(i,eigen_struct->size) For(j,eigen_struct->size) - eigen_struct->r_e_vect[eigen_struct->size*i+j] = - eigen_struct->r_e_vect[eigen_struct->size*i+j] * + for(i=0;isize;i++) for(j=0;jsize;j++) + eigen_struct->r_e_vect[eigen_struct->size*i+j] = + eigen_struct->r_e_vect[eigen_struct->size*i+j] * eigen_struct->e_val[j]; - For(i,eigen_struct->size) For(j,eigen_struct->size) F[eigen_struct->size*i+j] = .0; - For(i,eigen_struct->size) For(j,eigen_struct->size) For(k,eigen_struct->size) + for(i=0;isize;i++) for(j=0;jsize;j++) F[eigen_struct->size*i+j] = .0; + for(i=0;isize;i++) for(j=0;jsize;j++) for(k=0;ksize;k++) F[eigen_struct->size*i+j] += eigen_struct->r_e_vect[eigen_struct->size*i+k] * eigen_struct->l_e_vect[eigen_struct->size*k+j]; /* Trace */ dist = .0; - For(i,eigen_struct->size) dist+=F[eigen_struct->size*i+i]; + for(i=0;isize;i++) dist+=F[eigen_struct->size*i+i]; sum_ev = .0; - For(i,mod->ns) sum_ev += mod->eigen->e_val[i]; + for(i=0;ins;i++) sum_ev += mod->eigen->e_val[i]; /* dist /= sum_ev; */ dist /= -4.; - -/* For(i,mod->ns) mod->pi[i] = mod_pi[i]; */ -/* Update_Qmat_GTR(mod); */ - Free(pi); - Free(mod_pi); - Free(F_double); + Free(pi); + Free(mod_pi); + Free(F_phydbl); if(isnan(dist)) return -1.; return dist; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// phydbl GTR_Dist(phydbl *F, phydbl alpha, eigen *eigen_struct) { @@ -2760,10 +1155,10 @@ phydbl GTR_Dist(phydbl *F, phydbl alpha, eigen *eigen_struct) int i,j,k; phydbl dist; phydbl sum; - double *F_double; + phydbl *F_phydbl; pi = (phydbl *)mCalloc(eigen_struct->size,sizeof(phydbl)); - F_double = (double *)mCalloc(eigen_struct->size*eigen_struct->size,sizeof(double)); + F_phydbl = (phydbl *)mCalloc(eigen_struct->size*eigen_struct->size,sizeof(phydbl)); /* /\* Waddell and Steel's example *\/ */ /* F[4*0+0] = 1415./4898.; F[4*0+1] = 8./4898.; F[4*0+2] = 55./4898.; F[4*0+3] = 2./4898.; */ @@ -2771,23 +1166,23 @@ phydbl GTR_Dist(phydbl *F, phydbl alpha, eigen *eigen_struct) /* F[4*2+0] = 73./4898.; F[4*2+1] = 0./4898.; F[4*2+2] = 578./4898.; F[4*2+3] = 0./4898.; */ /* F[4*3+0] = 3./4898.; F[4*3+1] = 117./4898.; F[4*3+2] = 1./4898.; F[4*3+3] = 1126./4898.; */ - - For(i,eigen_struct->size) + sum = 0.0; + for(i=0;isize;i++) { - For(j,eigen_struct->size) - { - pi[i] += (F[eigen_struct->size*i+j] + F[eigen_struct->size*j+i])/2.; - sum += F[eigen_struct->size*i+j]; - } + for(j=0;jsize;j++) + { + pi[i] += (F[eigen_struct->size*i+j] + F[eigen_struct->size*j+i])/2.; + sum += F[eigen_struct->size*i+j]; + } } /* /\* Jukes and Cantor correction *\/ */ /* sum = .0; */ -/* For(i,eigen_struct->size) sum += F[eigen_struct->size*i+i]; */ +/* for(i=0;isize;i++) sum += F[eigen_struct->size*i+i]; */ /* sum = 1.-sum; */ /* For(i,eigen_struct->size*eigen_struct->size) F[i] = sum/12.; */ -/* For(i,eigen_struct->size) F[eigen_struct->size*i+i] = (1.-sum)/4.; */ -/* For(i,eigen_struct->size) pi[i] = 1./(phydbl)eigen_struct->size; */ +/* for(i=0;isize;i++) F[eigen_struct->size*i+i] = (1.-sum)/4.; */ +/* for(i=0;isize;i++) pi[i] = 1./(phydbl)eigen_struct->size; */ Make_Symmetric(&F,eigen_struct->size); @@ -2795,49 +1190,48 @@ phydbl GTR_Dist(phydbl *F, phydbl alpha, eigen *eigen_struct) /* Eigen decomposition of pi^{-1} x F */ - For(i,eigen_struct->size) For(j,eigen_struct->size) F_double[eigen_struct->size*i+j] = F[eigen_struct->size*i+j]; - if(Eigen(1,F_double,eigen_struct->size,eigen_struct->e_val, - eigen_struct->e_val_im,eigen_struct->r_e_vect, - eigen_struct->r_e_vect_im,eigen_struct->space)) + for(i=0;isize;i++) for(j=0;jsize;j++) F_phydbl[eigen_struct->size*i+j] = F[eigen_struct->size*i+j]; + if(Eigen(1,F_phydbl,eigen_struct->size,eigen_struct->e_val, + eigen_struct->e_val_im,eigen_struct->r_e_vect, + eigen_struct->r_e_vect_im,eigen_struct->space)) { - Free(pi); + Free(pi); return -1.; } /* Get the left eigen vector of pi^{-1} x F */ For(i,eigen_struct->size*eigen_struct->size) eigen_struct->l_e_vect[i] = eigen_struct->r_e_vect[i]; - if(!Matinv(eigen_struct->l_e_vect,eigen_struct->size,eigen_struct->size,eigen_struct->space)<0) {Free(pi); return -1.;} + if(!Matinv(eigen_struct->l_e_vect,eigen_struct->size,eigen_struct->size,YES)) {Free(pi); return -1.;} /* Equation (3) + inverse of the moment generating function for the gamma distribution (see Waddell & Steel, 1997) */ - For(i,eigen_struct->size) + for(i=0;isize;i++) { - if(eigen_struct->e_val[i] < 0.0) - { - eigen_struct->e_val[i] = 0.0001; - } + if(eigen_struct->e_val[i] < 0.0) + { + eigen_struct->e_val[i] = 0.0001; + } if(alpha < .0) - eigen_struct->e_val[i] = (phydbl)log(eigen_struct->e_val[i]); + eigen_struct->e_val[i] = (phydbl)log(eigen_struct->e_val[i]); else - eigen_struct->e_val[i] = alpha * (1. - (double)pow(eigen_struct->e_val[i],-1./alpha)); + eigen_struct->e_val[i] = alpha * (1. - (phydbl)POW(eigen_struct->e_val[i],-1./alpha)); } - + /* Matrix multiplications pi x log(pi^{-1} x F) */ - For(i,eigen_struct->size) For(j,eigen_struct->size) - eigen_struct->r_e_vect[eigen_struct->size*i+j] = + for(i=0;isize;i++) for(j=0;jsize;j++) + eigen_struct->r_e_vect[eigen_struct->size*i+j] = eigen_struct->r_e_vect[eigen_struct->size*i+j] * eigen_struct->e_val[j]; - For(i,eigen_struct->size) For(j,eigen_struct->size) F[eigen_struct->size*i+j] = .0; - For(i,eigen_struct->size) For(j,eigen_struct->size) For(k,eigen_struct->size) + for(i=0;isize;i++) for(j=0;jsize;j++) F[eigen_struct->size*i+j] = .0; + for(i=0;isize;i++) for(j=0;jsize;j++) for(k=0;ksize;k++) F[eigen_struct->size*i+j] += eigen_struct->r_e_vect[eigen_struct->size*i+k] * eigen_struct->l_e_vect[eigen_struct->size*k+j]; - For(i,eigen_struct->size) For(j,eigen_struct->size) F[eigen_struct->size*i+j] *= pi[i]; + for(i=0;isize;i++) for(j=0;jsize;j++) F[eigen_struct->size*i+j] *= pi[i]; /* Trace */ dist = .0; - For(i,eigen_struct->size) dist-=F[eigen_struct->size*i+i]; + for(i=0;isize;i++) dist-=F[eigen_struct->size*i+i]; + -/* printf("\nDIST = %f\n",dist); Exit("\n"); */ - Free(pi); - Free(F_double); + Free(F_phydbl); if(isnan(dist)) return -1.; return dist; diff --git a/phyml/models.h b/phyml/models.h index 8f85192..6341211 100644 --- a/phyml/models.h +++ b/phyml/models.h @@ -10,41 +10,39 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef MODELS_H #define MODELS_H -void PMat(phydbl l, model *mod, double ***Pij); -void PMat_K80(phydbl l,phydbl kappa, double ***Pij); -void PMat_TN93(phydbl l, model *mod, double ***Pij); -void PMat_Empirical(phydbl l, model *mod, double ***Pij); +#include "utilities.h" +#include "eigen.h" +#include "free.h" +#include "stats.h" +#include "mixt.h" + +void PMat(phydbl l, t_mod *mod, int pos, phydbl *Pij, phydbl *tPij); +void PMat_K80(phydbl l,phydbl kappa, int pos, phydbl *Pij); +void PMat_TN93(phydbl l, t_mod *mod, int pos, phydbl *Pij); +void PMat_Empirical(const phydbl l, const t_mod *mod, const int pos, phydbl *Pij, phydbl *tPij); +void PMat_Zero_Br_Len(t_mod *mod, int pos, phydbl *Pij); +void PMat_Gamma(phydbl l, t_mod *mod, int pos, phydbl *Pij); int GetDaa (phydbl *daa, phydbl *pi, char *file_name); -int Matinv (double *x, int n, int m, double *space); - -/* add error checking, return value is set to int instead of void */ -int Init_Model(allseq *data, model *mod); -void Update_Qmat_GTR(double *rr, phydbl *rr_val, int *rr_num, double *pi, double *qmat); -void Update_Qmat_HKY(double kappa, double *pi, double *qmat); -void Update_Qmat_Generic(double *rr, double *pi, int ns, double *qmat); -void Translate_Custom_Mod_String(model *mod); - -/* add error checking, return value is set to int instead of void */ -int Set_Model_Parameters(model *mod); -void PMat_Zero_Br_Len(model *mod, double ***Pij); +void Update_Qmat_GTR(phydbl *rr, phydbl *rr_val, int *rr_num, phydbl *pi, phydbl *qmat, int opt_rr); +void Update_Qmat_HKY(phydbl kappa, phydbl *pi, phydbl *qmat); +void Update_Qmat_Generic(phydbl *rr, phydbl *pi, int ns, phydbl *qmat); +void Translate_Custom_Mod_String(t_mod *mod); +int Set_Model_Parameters(t_mod *mod); phydbl GTR_Dist(phydbl *F, phydbl alpha, eigen *eigen_struct); -phydbl General_Dist(phydbl *F, model *mod, eigen *eigen_struct); - -int Init_Qmat_WAG(double *daa, phydbl *pi); -int Init_Qmat_Dayhoff(double *daa, phydbl *pi); -int Init_Qmat_JTT(double *daa, phydbl *pi); -int Init_Qmat_RtREV(double *daa, phydbl *pi); -int Init_Qmat_CpREV(double *daa, phydbl *pi); -int Init_Qmat_VT(double *daa, phydbl *pi); -int Init_Qmat_Blosum62(double *daa, phydbl *pi); -int Init_Qmat_MtMam(double *daa, phydbl *pi); -int Init_Qmat_MtArt(double *daa, double *pi); // Added by Federico Abascal -int Init_Qmat_HIVb(double *daa, double *pi); //added by Federic Abascal -int Init_Qmat_HIVw(double *daa, double *pi); //added by Federico Abascal -void Switch_From_Mod_To_M4mod(model *mod); -void Switch_From_M4mod_To_Mod(model *mod); +phydbl General_Dist(phydbl *F, t_mod *mod, eigen *eigen_struct); +void Switch_From_Mod_To_M4mod(t_mod *mod); +void Switch_From_M4mod_To_Mod(t_mod *mod); +void PMat_JC69(phydbl l, int pos, phydbl *Pij, t_mod *mod); +phydbl Get_Lambda_F84(phydbl *pi, phydbl *kappa); +int Update_Eigen(t_mod *mod); +int Update_RAS(t_mod *mod); +int Update_Efrq(t_mod *mod); +void PMat_MGF_Gamma(phydbl *Pij, phydbl shape, phydbl scale, phydbl scaling_fact, t_mod *mod); +int Update_Boundaries(t_mod *mod); #endif diff --git a/phyml/mpi_boot.c b/phyml/mpi_boot.c new file mode 100644 index 0000000..0c5bca8 --- /dev/null +++ b/phyml/mpi_boot.c @@ -0,0 +1,563 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "mpi_boot.h" + +/* #ifdef MPI */ + +/*********************************************************/ + +/* + if tbe_bootstrap == 0 => Classical FBP (Felsenstein bootstrap proportions) + else => TBE (Transfer bootstrap expectation) +*/ +void Bootstrap_MPI(t_tree *tree) +{ + int *site_num, n_site; + int replicate,j,k; + int position, init_len, nbRep; + + calign *boot_data; + t_tree *boot_tree; + t_mod *boot_mod; + matrix *boot_mat; + char *s; + + MPI_Status Stat; + int randomRecv, bootRecv, nbElem, i; + int *score_par, *score_tot; + char *bootStr, *t; + + if(tree->is_mixt_tree == YES) + { + PhyML_Printf("\n== Bootstrap option not yet available for partition/mixture analysis."); + assert(FALSE); + } + + randomRecv = nbElem = bootRecv = 0; + + tree->io->print_support_val = YES; + + boot_tree = NULL; + + site_num = (int *)mCalloc(tree->data->init_len,sizeof(int)); + + Free_Bip(tree); + Alloc_Bip(tree); + Get_Bip(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + + n_site = 0; + for(j=0;jdata->crunch_len;j++) For(k,tree->data->wght[j]) + { + site_num[n_site] = j; + n_site++; + } + + boot_data = Copy_Cseq(tree->data,tree->io); + + if(Global_numTask <= 1) + { + PhyML_Printf("\n\n. The number of CPUs used in the MPI bootstrap analysis should be"); + PhyML_Printf("\n. strictly greater than 1 (it is equal to %d here).",Global_numTask); + assert(FALSE); + } + + //number of bootstraps for each process + if (tree->io->n_boot_replicates%Global_numTask != 0) + { + nbRep = (tree->io->n_boot_replicates / Global_numTask) + 1; + tree->io->n_boot_replicates = nbRep * Global_numTask; + if (Global_myRank == 0) { + PhyML_Printf("\n\n. The number of replicates is not a multiple of %d CPUs.\n", Global_numTask); + PhyML_Printf("\n. Will run %d replicates.\n", tree->io->n_boot_replicates); + } + } + else + nbRep = tree->io->n_boot_replicates/Global_numTask; + + //Bip score + if (Global_myRank == 0) + { + score_tot = (int *)mCalloc((2*tree->n_otu - 3),sizeof(int)); + For(i,2*tree->n_otu-3) + score_tot[i] = 0; + } + else + score_tot = NULL; + + score_par = (int *)mCalloc((2*tree->n_otu - 3),sizeof(int)); + For(i,2*tree->n_otu-3) + score_par[i] = 0; + + if (Global_myRank == 0) + PhyML_Printf("\n ["); + + for(replicate=0;replicatecrunch_len;j++) boot_data->wght[j] = 0; + + // Send random data to other process + if (Global_myRank == 0) + { + // Compute number of data to send + if (tree->io->n_boot_replicates - randomRecv > Global_numTask) + nbElem = Global_numTask; + else + nbElem = tree->io->n_boot_replicates - randomRecv; + + for(i=0;icrunch_len;j++) boot_data->wght[j] = 0; + + init_len = 0; + // Create random data + for(j=0;jinit_len;j++) + { + position = Rand_Int(0,(int)(tree->data->init_len-1.0)); + boot_data->wght[site_num[position]] += 1; + init_len++; + } + + + if (init_len != tree->data->init_len) + { + PhyML_Printf("\n== thread: %d || init: %d %d here\n",Global_myRank,init_len,tree->data->init_len); + fflush(NULL); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + // Send random data to other process, not to current process + if (i < nbElem-1) + { + MPI_Ssend (boot_data->wght, boot_data->crunch_len, MPI_DOUBLE, i+1, Global_myRank, MPI_COMM_WORLD); +#ifdef MPI_DEBUG + fprintf (stderr, "\ntask %d, sending random to %d done\n", Global_myRank, i+1); + fflush(stderr); +#endif + } + randomRecv++; + } + } + else + { + MPI_Recv(boot_data->wght, boot_data->crunch_len, MPI_DOUBLE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &Stat); +#ifdef MPI_DEBUG + fprintf (stderr, "\ntask %d, receiving random from task %d done\n", Global_myRank, Stat.MPI_SOURCE); + fflush(stderr); +#endif + + + } + + init_len = 0; + for(j=0;jcrunch_len;j++) init_len += boot_data->wght[j]; + + + if(init_len != tree->data->init_len) + { + printf("\n== thread: %d init: %d %d\n",Global_myRank,init_len,tree->data->init_len); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + + (tree->mod->io->datatype == NT)? + (Get_Base_Freqs(boot_data)): + (Get_AA_Freqs(boot_data)); + + + if(tree->io->random_boot_seq_order) Randomize_Sequence_Order(boot_data); + + Set_D_States(boot_data,tree->io->datatype,tree->io->state_len); + + boot_mod = Copy_Model(tree->mod); + boot_mod->s_opt = tree->mod->s_opt; /* WARNING: re-using the same address here instead of creating a copying + requires to leave the value of s_opt unchanged during the boostrap. */ + boot_mod->io = tree->io; /* WARNING: re-using the same address here instead of creating a copying + requires to leave the value of io unchanged during the boostrap. */ + Init_Model(boot_data,boot_mod,tree->io); + + if(tree->io->in_tree == 2) + { + switch(tree->io->tree_file_format) + { + case PHYLIP: + { + rewind(tree->io->fp_in_tree); + boot_tree = Read_Tree_File_Phylip(tree->io->fp_in_tree); + break; + } + case NEXUS: + { + PhyML_Printf("\n== Unfortunately, PhyML cannot read NEXUS files and perform a bootstrap analysis."); + PhyML_Printf("\n== Please use the PHYLIP format."); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + break; + } + default: + { + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + break; + } + } + } + else + { + boot_mat = ML_Dist(boot_data,boot_mod); + boot_mat->tree = Make_Tree_From_Scratch(boot_data->n_otu,boot_data); + Fill_Missing_Dist(boot_mat); + Bionj(boot_mat); + boot_tree = boot_mat->tree; + boot_tree->mat = boot_mat; + } + + boot_tree->mod = boot_mod; + boot_tree->io = tree->io; + boot_tree->data = boot_data; + boot_tree->verbose = VL0; + boot_tree->n_pattern = boot_tree->data->crunch_len; + boot_tree->io->print_site_lnl = 0; + boot_tree->io->print_trace = 0; + + Set_Both_Sides(YES,boot_tree); + + if((boot_tree->mod->s_opt->random_input_tree) && (boot_tree->mod->s_opt->topo_search == SPR_MOVE)) Random_Tree(boot_tree); + + Connect_CSeqs_To_Nodes(boot_data,boot_tree->io,boot_tree); + Share_Lk_Struct(tree,boot_tree); + Share_Spr_Struct(tree,boot_tree); + Share_Pars_Struct(tree,boot_tree); + Fill_Dir_Table(boot_tree); + Update_Dirs(boot_tree); + + Init_Partial_Lk_Tips_Double(boot_tree); + Init_Ui_Tips(boot_tree); + Init_Partial_Pars_Tips(boot_tree); + Br_Len_Not_Involving_Invar(boot_tree); + + Set_Update_Eigen(YES,boot_tree->mod); + Lk(NULL,boot_tree); + Set_Update_Eigen(NO,boot_tree->mod); + + if(boot_tree->mod->s_opt->opt_topo) + { + Global_Spr_Search(boot_tree); + } + else + { + if(boot_tree->mod->s_opt->opt_subst_param || boot_tree->mod->s_opt->opt_bl) + Round_Optimize(boot_tree,ROUND_MAX); + else + Lk(NULL,boot_tree); + } + + Free_Bip(boot_tree); + + Alloc_Bip(boot_tree); + + Match_Tip_Numbers(tree,boot_tree); + + Get_Bip(boot_tree->a_nodes[0], + boot_tree->a_nodes[0]->v[0], + boot_tree); + + if(tree->io->do_boot) + { + Compare_Bip(tree,boot_tree,NO); + } + else if(tree->io->do_tbe) + { + Compare_Bip_Distance(tree, boot_tree); + } + else assert(FALSE); + + + Br_Len_Involving_Invar(boot_tree); + + if(tree->io->print_boot_trees) + { + /* Insert_Duplicates(boot_tree); */ + s = Write_Tree(boot_tree); + t=(char *)mCalloc(T_MAX_LINE,sizeof(char)); + Print_Fp_Out_Lines_MPI(boot_tree, tree->io, replicate+1, t); + + // Get bootstrap trees from other process and write to boot file + if (Global_myRank == 0) { + fprintf(tree->io->fp_out_boot_tree,"%s\n",s); + fprintf(tree->io->fp_out_boot_stats,"%s\n",t); + bootRecv++; + PhyML_Printf("."); + if(!((bootRecv)%tree->io->boot_prog_every)) + { + PhyML_Printf("] %4d/%4d\n ",bootRecv,tree->io->n_boot_replicates); + if(bootRecv != tree->io->n_boot_replicates) PhyML_Printf("["); + } + + // Compute number of bootstraps to receive + if (tree->io->n_boot_replicates - bootRecv > Global_numTask) + nbElem = Global_numTask; + else + nbElem = tree->io->n_boot_replicates - bootRecv + 1; + + bootStr=(char *)mCalloc(T_MAX_LINE,sizeof(char)); + for (i=1; iio->fp_out_boot_tree,"%s\n", bootStr); + if (Stat.MPI_TAG == BootStatTag) + fprintf(tree->io->fp_out_boot_stats,"%s\n", bootStr); + + MPI_Recv (bootStr, T_MAX_LINE, MPI_CHAR, i, MPI_ANY_TAG, MPI_COMM_WORLD, &Stat); +#ifdef MPI_DEBUG + fprintf (stderr, "\ntask %d, receiving bootstrap from task %d tag %d done\n", Global_myRank, Stat.MPI_SOURCE, Stat.MPI_TAG); + fflush(stderr); +#endif + if (Stat.MPI_TAG == BootTreeTag) + fprintf(tree->io->fp_out_boot_tree,"%s\n", bootStr); + if (Stat.MPI_TAG == BootStatTag) + fprintf(tree->io->fp_out_boot_stats,"%s\n", bootStr); + + bootRecv++; + PhyML_Printf("."); + if(!((bootRecv)%tree->io->boot_prog_every)) { + PhyML_Printf("] %4d/%4d\n ",bootRecv,tree->io->n_boot_replicates); + if(bootRecv != tree->io->n_boot_replicates) PhyML_Printf("["); + } + } + Free(bootStr); + } + else { + MPI_Ssend (s, T_MAX_LINE, MPI_CHAR, 0, BootTreeTag, MPI_COMM_WORLD); + MPI_Ssend (t, T_MAX_LINE, MPI_CHAR, 0, BootStatTag, MPI_COMM_WORLD); +#ifdef MPI_DEBUG +fprintf (stderr, "\ntask %d, sending bootstraps done\n", Global_myRank); +fflush(stderr); +#endif + } + Free(t); + Free(s); + } + +#ifndef QUIET +fflush(stdout); +#endif + + /* if(boot_tree->mat) Free_Mat(boot_tree->mat); */ + Free_Tree(boot_tree); + Free_Model(boot_mod); + + //Each process computes the Bip score sum for all its bootstrap trees + For(i,2*tree->n_otu-3) score_par[i] = tree->a_edges[i]->bip_score; + + //Each process sends its Bip score sum. The sums are summed. + MPI_Reduce(score_par, score_tot, 2*tree->n_otu - 3, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + } + + + if (Global_myRank == 0) + { + For(i,2*tree->n_otu-3) + tree->a_edges[i]->bip_score = score_tot[i]; + Free (score_tot); + } + Free (score_par); + + if (Global_myRank == 0) + if(((bootRecv)%tree->io->boot_prog_every)) PhyML_Printf("] %4d/%4d\n ",bootRecv,tree->io->n_boot_replicates); + + PhyML_Printf("\n\n. Exiting bootstrap function normally."); fflush(NULL); + tree->lock_topo = 1; /* Topology should not be modified afterwards */ + + if(tree->io->print_boot_trees) + { + fclose(tree->io->fp_out_boot_tree); + fclose(tree->io->fp_out_boot_stats); + } + + Free_Calign(boot_data); + Free(site_num); +} + +/*********************************************************/ + +void Print_Fp_Out_Lines_MPI(t_tree *tree, option *io, int n_data_set, char *bootStr) +{ + char *s, *tmp; + + // Build a string to be sent to the writing process + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + tmp=(char *)mCalloc(T_MAX_LINE,sizeof(char)); + + if (Global_myRank == 0 && n_data_set == 1) { + snprintf(tmp, T_MAX_LINE, ". Sequence file : [%s]\n\n", Basename(io->in_align_file)); strncat (s, tmp, T_MAX_LINE); + + (tree->mod->io->datatype == NT)? + (snprintf(tmp, T_MAX_LINE, ". Model of nucleotides substitution : %s\n\n", io->mod->modelname->s)): + (snprintf(tmp, T_MAX_LINE, ". Model of amino acids substitution : %s\n\n", io->mod->modelname->s)); + strncat (s, tmp, T_MAX_LINE); + + switch(io->in_tree) + { + case 0: { snprintf(tmp, T_MAX_LINE, ". Initial tree : [BioNJ]\n\n"); break; } + case 1: { snprintf(tmp, T_MAX_LINE, ". Initial tree : [parsimony]\n\n"); break; } + case 2: { snprintf(tmp, T_MAX_LINE, ". Initial tree : [%s]\n\n",io->in_tree_file); break; } + } + strncat (s, tmp, T_MAX_LINE); + + strncat (s, "\n", T_MAX_LINE); + + /*headline 1*/ + strncat (s, ". Data\t", T_MAX_LINE); + + strncat (s, "Nb of \t", T_MAX_LINE); + + strncat (s, "Likelihood\t", T_MAX_LINE); + + strncat (s, "Discrete \t", T_MAX_LINE); + + if(tree->mod->ras->n_catg > 1) + strncat (s, "Number of \tGamma shape\t", T_MAX_LINE); + + strncat (s, "Proportion of\t", T_MAX_LINE); + + if(tree->mod->whichmodel <= 6) + strncat (s, "Transition/ \t", T_MAX_LINE); + + strncat (s, "Nucleotides frequencies \t", T_MAX_LINE); + + if((tree->mod->whichmodel == GTR) || + (tree->mod->whichmodel == CUSTOM)) + strncat (s, "Instantaneous rate matrix \t", T_MAX_LINE); + + strncat (s, "\n", T_MAX_LINE); + + /*headline 2*/ + strncat (s, " set\t", T_MAX_LINE); + + strncat (s, "taxa\t", T_MAX_LINE); + + strncat (s, "loglk \t", T_MAX_LINE); + + strncat (s, "gamma model\t", T_MAX_LINE); + + if(tree->mod->ras->n_catg > 1) + strncat (s, "categories\tparameter \t", T_MAX_LINE); + + strncat (s, "invariant \t", T_MAX_LINE); + + if(tree->mod->whichmodel <= 6) + strncat (s, "transversion\t", T_MAX_LINE); + + strncat (s, "f(A) f(C) f(G) f(T) \t", T_MAX_LINE); + + if((tree->mod->whichmodel == GTR) || + (tree->mod->whichmodel == CUSTOM)) + strncat (s, "[A---------C---------G---------T------]\t", T_MAX_LINE); + + strncat (s, "\n", T_MAX_LINE); + + /*headline 3*/ + if(tree->mod->whichmodel == TN93) { + strncat (s, " \t \t \t \t", T_MAX_LINE); + if(tree->mod->ras->n_catg > 1) + strncat (s, " \t \t", T_MAX_LINE); + strncat (s, " \t", T_MAX_LINE); + strncat (s, "purines pyrimid.\t", T_MAX_LINE); + strncat (s, "\n", T_MAX_LINE); + } + + strncat (s, "\n", T_MAX_LINE); + } + + /*line items*/ + + snprintf(tmp, T_MAX_LINE, " #%d\t", (((n_data_set-1)*Global_numTask)+Global_myRank+1)); + strncat (s, tmp, T_MAX_LINE); + + snprintf(tmp, T_MAX_LINE, "%d \t",tree->n_otu); strncat (s, tmp, T_MAX_LINE); + + snprintf(tmp, T_MAX_LINE, "%.5f\t",tree->c_lnL); strncat (s, tmp, T_MAX_LINE); + + snprintf(tmp, T_MAX_LINE, "%s \t", + (tree->mod->ras->n_catg>1)?("Yes"):("No ")); strncat (s, tmp, T_MAX_LINE); + + if(tree->mod->ras->n_catg > 1) + { + snprintf(tmp, T_MAX_LINE, "%d \t",tree->mod->ras->n_catg); strncat (s, tmp, T_MAX_LINE); + snprintf(tmp, T_MAX_LINE, "%.3f \t",tree->mod->ras->alpha->v); strncat (s, tmp, T_MAX_LINE); + } + + snprintf(tmp, T_MAX_LINE, "%.3f \t",tree->mod->ras->pinvar->v); strncat (s, tmp, T_MAX_LINE); + + if(tree->mod->whichmodel <= 5) + { + snprintf(tmp, T_MAX_LINE, "%.3f \t",tree->mod->kappa->v); strncat (s, tmp, T_MAX_LINE); + } + else if(tree->mod->whichmodel == TN93) + { + snprintf(tmp, T_MAX_LINE, "%.3f ", + tree->mod->kappa->v*2.*tree->mod->lambda->v/(1.+tree->mod->lambda->v)); + strncat (s, tmp, T_MAX_LINE); + snprintf(tmp, T_MAX_LINE, "%.3f\t", + tree->mod->kappa->v*2./(1.+tree->mod->lambda->v)); + strncat (s, tmp, T_MAX_LINE); + } + + if(tree->mod->io->datatype == NT) + { + snprintf(tmp, T_MAX_LINE, "%8.5f ",tree->mod->e_frq->pi->v[0]); strncat (s, tmp, T_MAX_LINE); + snprintf(tmp, T_MAX_LINE, "%8.5f ",tree->mod->e_frq->pi->v[1]); strncat (s, tmp, T_MAX_LINE); + snprintf(tmp, T_MAX_LINE, "%8.5f ",tree->mod->e_frq->pi->v[2]); strncat (s, tmp, T_MAX_LINE); + snprintf(tmp, T_MAX_LINE, "%8.5f\t",tree->mod->e_frq->pi->v[3]); strncat (s, tmp, T_MAX_LINE); + } + + if((tree->mod->whichmodel == GTR) || (tree->mod->whichmodel == CUSTOM)) + { + int i,j; + + for(i=0;i<4;i++) + { + if (i!=0) { + /*format*/ + snprintf(tmp, T_MAX_LINE, " \t \t \t \t"); + strncat (s, tmp, T_MAX_LINE); + if(tree->mod->ras->n_catg > 1) { + snprintf(tmp, T_MAX_LINE, " \t \t"); + strncat (s, tmp, T_MAX_LINE); + } + snprintf(tmp, T_MAX_LINE, " \t \t"); + strncat (s, tmp, T_MAX_LINE); + } + for(j=0;j<4;j++) { + snprintf(tmp, T_MAX_LINE, "%8.5f ",tree->mod->r_mat->qmat->v[i*4+j]); + strncat (s, tmp, T_MAX_LINE); + } + if (i<3) { + snprintf(tmp, T_MAX_LINE, "\n"); + strncat (s, tmp, T_MAX_LINE); + } + } + } + + Free (tmp); + strncpy (bootStr, s, T_MAX_LINE); + Free (s); + + return; +} +/* #endif */ diff --git a/phyml/mpi_boot.h b/phyml/mpi_boot.h new file mode 100644 index 0000000..5743fbd --- /dev/null +++ b/phyml/mpi_boot.h @@ -0,0 +1,37 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef MPI_H +#define MPI_H + +#include "mpi.h" +#include "utilities.h" +#include "bionj.h" +#include "lk.h" +#include "pars.h" +#include "free.h" +#include "models.h" +#include "simu.h" +#include "spr.h" + +#define BootTreeTag 0 +#define BootStatTag 1 + +int Global_numTask, Global_myRank; + + +void Bootstrap_MPI(t_tree *tree); +void Print_Fp_Out_Lines_MPI(t_tree *tree, option *io, int n_data_set, char *bootStr); + +#endif // MPI diff --git a/phyml/mxml.h b/phyml/mxml.h new file mode 100644 index 0000000..d020158 --- /dev/null +++ b/phyml/mxml.h @@ -0,0 +1,329 @@ +/* + * "$Id: mxml.h 427 2011-01-03 02:03:29Z mike $" + * + * Header file for Mini-XML, a small XML-like file parsing library. + * + * Copyright 2003-2011 by Michael R Sweet. + * + * These coded instructions, statements, and computer programs are the + * property of Michael R Sweet and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "COPYING" + * which should have been included with this file. If this file is + * missing or damaged, see the license at: + * + * http://www.minixml.org/ + */ + +/* + * Prevent multiple inclusion... + */ + +#ifndef _mxml_h_ +# define _mxml_h_ + +/* + * Include necessary headers... + */ + +# include +# include +# include +# include +# include + + +/* + * Constants... + */ + +# define MXML_TAB 8 /* Tabs every N columns */ + +# define MXML_NO_CALLBACK 0 /* Don't use a type callback */ +# define MXML_INTEGER_CALLBACK mxml_integer_cb + /* Treat all data as integers */ +# define MXML_OPAQUE_CALLBACK mxml_opaque_cb + /* Treat all data as opaque */ +# define MXML_REAL_CALLBACK mxml_real_cb + /* Treat all data as real numbers */ +# define MXML_TEXT_CALLBACK 0 /* Treat all data as text */ +# define MXML_IGNORE_CALLBACK mxml_ignore_cb + /* Ignore all non-element content */ + +# define MXML_NO_PARENT 0 /* No prev for the node */ + +# define MXML_DESCEND 1 /* Descend when finding/walking */ +# define MXML_NO_DESCEND 0 /* Don't descend when finding/walking */ +# define MXML_DESCEND_FIRST -1 /* Descend for first find */ + +# define MXML_WS_BEFORE_OPEN 0 /* Callback for before open tag */ +# define MXML_WS_AFTER_OPEN 1 /* Callback for after open tag */ +# define MXML_WS_BEFORE_CLOSE 2 /* Callback for before close tag */ +# define MXML_WS_AFTER_CLOSE 3 /* Callback for after close tag */ + +# define MXML_ADD_BEFORE 0 /* Add node before specified node */ +# define MXML_ADD_AFTER 1 /* Add node after specified node */ +# define MXML_ADD_TO_PARENT NULL /* Add node relative to prev */ + + +/* + * Data types... + */ + +typedef enum mxml_sax_event_e /**** SAX event type. ****/ +{ + MXML_SAX_CDATA, /* CDATA node */ + MXML_SAX_COMMENT, /* Comment node */ + MXML_SAX_DATA, /* Data node */ + MXML_SAX_DIRECTIVE, /* Processing directive node */ + MXML_SAX_ELEMENT_CLOSE, /* Element closed */ + MXML_SAX_ELEMENT_OPEN /* Element opened */ +} mxml_sax_event_t; + +typedef enum mxml_type_e /**** The XML node type. ****/ +{ + MXML_IGNORE = -1, /* Ignore/throw away node @since Mini-XML 2.3@ */ + MXML_ELEMENT, /* XML element with attributes */ + MXML_INTEGER, /* Integer value */ + MXML_OPAQUE, /* Opaque string */ + MXML_REAL, /* Real value */ + MXML_TEXT, /* Text fragment */ + MXML_CUSTOM /* Custom data @since Mini-XML 2.1@ */ +} mxml_type_t; + +typedef void (*mxml_custom_destroy_cb_t)(void *); + /**** Custom data destructor ****/ + +typedef void (*mxml_error_cb_t)(const char *); + /**** Error callback function ****/ + +typedef struct mxml_attr_s /**** An XML element attribute value. @private@ ****/ +{ + char *name; /* Attribute name */ + char *value; /* Attribute value */ +} mxml_attr_t; + +typedef struct mxml_element_s /**** An XML element value. @private@ ****/ +{ + char *name; /* Name of element */ + int num_attrs; /* Number of attributes */ + mxml_attr_t *attrs; /* Attributes */ +} mxml_element_t; + +typedef struct mxml_text_s /**** An XML text value. @private@ ****/ +{ + int whitespace; /* Leading whitespace? */ + char *string; /* Fragment string */ +} mxml_text_t; + +typedef struct mxml_custom_s /**** An XML custom value. @private@ ****/ +{ + void *data; /* Pointer to (allocated) custom data */ + mxml_custom_destroy_cb_t destroy; /* Pointer to destructor function */ +} mxml_custom_t; + +typedef union mxml_value_u /**** An XML node value. @private@ ****/ +{ + mxml_element_t element; /* Element */ + int integer; /* Integer number */ + char *opaque; /* Opaque string */ + double real; /* Real number */ + mxml_text_t text; /* Text fragment */ + mxml_custom_t custom; /* Custom data @since Mini-XML 2.1@ */ +} mxml_value_t; + +struct mxml_node_s /**** An XML node. @private@ ****/ +{ + mxml_type_t type; /* Node type */ + struct mxml_node_s *next; /* Next node under same prev */ + struct mxml_node_s *prev; /* Previous node under same prev */ + struct mxml_node_s *prev; /* Parent node */ + struct mxml_node_s *next; /* First next node */ + struct mxml_node_s *last_next; /* Last next node */ + mxml_value_t value; /* Node value */ + int ref_count; /* Use count */ + void *user_data; /* User data */ +}; + +typedef struct mxml_node_s mxml_node_t; /**** An XML node. ****/ + +struct mxml_index_s /**** An XML node index. @private@ ****/ +{ + char *attr; /* Attribute used for indexing or NULL */ + int num_nodes; /* Number of nodes in index */ + int alloc_nodes; /* Allocated nodes in index */ + int cur_node; /* Current node */ + mxml_node_t **nodes; /* Node array */ +}; + +typedef struct mxml_index_s mxml_index_t; + /**** An XML node index. ****/ + +typedef int (*mxml_custom_load_cb_t)(mxml_node_t *, const char *); + /**** Custom data load callback function ****/ + +typedef char *(*mxml_custom_save_cb_t)(mxml_node_t *); + /**** Custom data save callback function ****/ + +typedef int (*mxml_entity_cb_t)(const char *); + /**** Entity callback function */ + +typedef mxml_type_t (*mxml_load_cb_t)(mxml_node_t *); + /**** Load callback function ****/ + +typedef const char *(*mxml_save_cb_t)(mxml_node_t *, int); + /**** Save callback function ****/ + +typedef void (*mxml_sax_cb_t)(mxml_node_t *, mxml_sax_event_t, void *); + /**** SAX callback function ****/ + + +/* + * C++ support... + */ + +# ifdef __cplusplus +extern "C" { +# endif /* __cplusplus */ + +/* + * Prototypes... + */ + +extern void mxmlAdd(mxml_node_t *prev, int where, + mxml_node_t *next, mxml_node_t *node); +extern void mxmlDelete(mxml_node_t *node); +extern void mxmlElementDeleteAttr(mxml_node_t *node, + const char *name); +extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name); +extern void mxmlElementSetAttr(mxml_node_t *node, const char *name, + const char *value); +extern void mxmlElementSetAttrf(mxml_node_t *node, const char *name, + const char *format, ...) +# ifdef __GNUC__ +__attribute__ ((__format__ (__printf__, 3, 4))) +# endif /* __GNUC__ */ +; +extern int mxmlEntityAddCallback(mxml_entity_cb_t cb); +extern const char *mxmlEntityGetName(int val); +extern int mxmlEntityGetValue(const char *name); +extern void mxmlEntityRemoveCallback(mxml_entity_cb_t cb); +extern mxml_node_t *mxmlFindElement(mxml_node_t *node, mxml_node_t *top, + const char *name, const char *attr, + const char *value, int descend); +extern mxml_node_t *mxmlFindPath(mxml_node_t *node, const char *path); +extern const char *mxmlGetCDATA(mxml_node_t *node); +extern const void *mxmlGetCustom(mxml_node_t *node); +extern const char *mxmlGetElement(mxml_node_t *node); +extern mxml_node_t *mxmlGetFirstChild(mxml_node_t *node); +extern int mxmlGetInteger(mxml_node_t *node); +extern mxml_node_t *mxmlGetLastChild(mxml_node_t *node); +extern mxml_node_t *mxmlGetNextSibling(mxml_node_t *node); +extern const char *mxmlGetOpaque(mxml_node_t *node); +extern mxml_node_t *mxmlGetParent(mxml_node_t *node); +extern mxml_node_t *mxmlGetPrevSibling(mxml_node_t *node); +extern double mxmlGetReal(mxml_node_t *node); +extern int mxmlGetRefCount(mxml_node_t *node); +extern const char *mxmlGetText(mxml_node_t *node, int *whitespace); +extern mxml_type_t mxmlGetType(mxml_node_t *node); +extern void *mxmlGetUserData(mxml_node_t *node); +extern void mxmlIndexDelete(mxml_index_t *ind); +extern mxml_node_t *mxmlIndexEnum(mxml_index_t *ind); +extern mxml_node_t *mxmlIndexFind(mxml_index_t *ind, + const char *element, + const char *value); +extern int mxmlIndexGetCount(mxml_index_t *ind); +extern mxml_index_t *mxmlIndexNew(mxml_node_t *node, const char *element, + const char *attr); +extern mxml_node_t *mxmlIndexReset(mxml_index_t *ind); +extern mxml_node_t *mxmlLoadFd(mxml_node_t *top, int fd, + mxml_type_t (*cb)(mxml_node_t *)); +extern mxml_node_t *mxmlLoadFile(mxml_node_t *top, FILE *fp, + mxml_type_t (*cb)(mxml_node_t *)); +extern mxml_node_t *mxmlLoadString(mxml_node_t *top, const char *s, + mxml_type_t (*cb)(mxml_node_t *)); +extern mxml_node_t *mxmlNewCDATA(mxml_node_t *prev, const char *string); +extern mxml_node_t *mxmlNewCustom(mxml_node_t *prev, void *data, + mxml_custom_destroy_cb_t destroy); +extern mxml_node_t *mxmlNewElement(mxml_node_t *prev, const char *name); +extern mxml_node_t *mxmlNewInteger(mxml_node_t *prev, int integer); +extern mxml_node_t *mxmlNewOpaque(mxml_node_t *prev, const char *opaque); +extern mxml_node_t *mxmlNewReal(mxml_node_t *prev, double real); +extern mxml_node_t *mxmlNewText(mxml_node_t *prev, int whitespace, + const char *string); +extern mxml_node_t *mxmlNewTextf(mxml_node_t *prev, int whitespace, + const char *format, ...) +# ifdef __GNUC__ +__attribute__ ((__format__ (__printf__, 3, 4))) +# endif /* __GNUC__ */ +; +extern mxml_node_t *mxmlNewXML(const char *version); +extern int mxmlRelease(mxml_node_t *node); +extern void mxmlRemove(mxml_node_t *node); +extern int mxmlRetain(mxml_node_t *node); +extern char *mxmlSaveAllocString(mxml_node_t *node, + mxml_save_cb_t cb); +extern int mxmlSaveFd(mxml_node_t *node, int fd, + mxml_save_cb_t cb); +extern int mxmlSaveFile(mxml_node_t *node, FILE *fp, + mxml_save_cb_t cb); +extern int mxmlSaveString(mxml_node_t *node, char *buffer, + int bufsize, mxml_save_cb_t cb); +extern mxml_node_t *mxmlSAXLoadFd(mxml_node_t *top, int fd, + mxml_type_t (*cb)(mxml_node_t *), + mxml_sax_cb_t sax, void *sax_data); +extern mxml_node_t *mxmlSAXLoadFile(mxml_node_t *top, FILE *fp, + mxml_type_t (*cb)(mxml_node_t *), + mxml_sax_cb_t sax, void *sax_data); +extern mxml_node_t *mxmlSAXLoadString(mxml_node_t *top, const char *s, + mxml_type_t (*cb)(mxml_node_t *), + mxml_sax_cb_t sax, void *sax_data); +extern int mxmlSetCDATA(mxml_node_t *node, const char *data); +extern int mxmlSetCustom(mxml_node_t *node, void *data, + mxml_custom_destroy_cb_t destroy); +extern void mxmlSetCustomHandlers(mxml_custom_load_cb_t load, + mxml_custom_save_cb_t save); +extern int mxmlSetElement(mxml_node_t *node, const char *name); +extern void mxmlSetErrorCallback(mxml_error_cb_t cb); +extern int mxmlSetInteger(mxml_node_t *node, int integer); +extern int mxmlSetOpaque(mxml_node_t *node, const char *opaque); +extern int mxmlSetReal(mxml_node_t *node, double real); +extern int mxmlSetText(mxml_node_t *node, int whitespace, + const char *string); +extern int mxmlSetTextf(mxml_node_t *node, int whitespace, + const char *format, ...) +# ifdef __GNUC__ +__attribute__ ((__format__ (__printf__, 3, 4))) +# endif /* __GNUC__ */ +; +extern int mxmlSetUserData(mxml_node_t *node, void *data); +extern void mxmlSetWrapMargin(int column); +extern mxml_node_t *mxmlWalkNext(mxml_node_t *node, mxml_node_t *top, + int descend); +extern mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top, + int descend); + + +/* + * Semi-private functions... + */ + +extern void mxml_error(const char *format, ...); +extern mxml_type_t mxml_ignore_cb(mxml_node_t *node); +extern mxml_type_t mxml_integer_cb(mxml_node_t *node); +extern mxml_type_t mxml_opaque_cb(mxml_node_t *node); +extern mxml_type_t mxml_real_cb(mxml_node_t *node); + + +/* + * C++ support... + */ + +# ifdef __cplusplus +} +# endif /* __cplusplus */ +#endif /* !_mxml_h_ */ + + +/* + * End of "$Id: mxml.h 427 2011-01-03 02:03:29Z mike $". + */ diff --git a/phyml/nexus.c b/phyml/nexus.c new file mode 100644 index 0000000..8e6813b --- /dev/null +++ b/phyml/nexus.c @@ -0,0 +1,493 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "nexus.h" + +void Find_Nexus_Com(char *token, nexcom **found_com, nexparm **default_parm, nexcom **com_list) +{ + int i,j,tokenlen,ndiff; + + for(i=0;iname))) + { + ndiff = 0; + for(j=0;jname+j); + if(token[j] != com_list[i]->name[j]) ndiff++; + } + } + if(!ndiff) { *found_com = com_list[i]; break; } + } + + if(*found_com && (*found_com)->nparm) *default_parm = (*found_com)->parm[0]; + + /* if(*found_com) PhyML_Printf("\n. Found command '%s'.\n",(*found_com)->name); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Find_Nexus_Parm(char *token, nexparm **found_parm, nexcom *curr_com) +{ + int i,j; + int tokenlen; + int ndiff; + + if(!curr_com) + { + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + for(i=0;inparm;i++) + { + tokenlen = strlen(token); + ndiff = -1; + if(tokenlen == strlen(curr_com->parm[i]->name)) + { + ndiff = 0; + for(j=0;jparm[i]->name+j); + if(token[j] != curr_com->parm[i]->name[j]) ndiff++; + } + } + if(!ndiff) { *found_parm = curr_com->parm[i]; break; } + } + + /* if(*found_parm) PhyML_Printf("\n. Found parameter '%s'.\n",(*found_parm)->name); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Taxa(char *token, nexparm *curr_parm, option *io) +{ + + PhyML_Printf("\n. Skipping 'taxa' block"); + + do + { + Get_Token(io->fp_in_align,token); + if(token[0] == ';') break; + }while(strlen(token) > 0); + + fseek(io->fp_in_align,-1*sizeof(char),SEEK_CUR); + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Translate(char *token, nexparm *curr_parm, option *io) +{ + int tax_num; + char *end; + + PhyML_Printf("\n. Reading 'translate' block"); + io->size_tax_names = 0; + + do + { + Get_Token(io->fp_in_tree,token); + if(token[0] == ';') break; + tax_num = (int)strtol(token,&end,10); + if(*end =='\0' && token[0]) + { + io->size_tax_names++; + + io->short_tax_names = (char **)realloc(io->short_tax_names,io->size_tax_names*sizeof(char *)); + io->short_tax_names[io->size_tax_names-1] = (char *)mCalloc(strlen(token)+1,sizeof(char)); + sprintf(io->short_tax_names[io->size_tax_names-1],"%d",tax_num); + + Get_Token(io->fp_in_tree,token); + + io->long_tax_names = (char **)realloc(io->long_tax_names,io->size_tax_names*sizeof(char *)); + io->long_tax_names[io->size_tax_names-1] = (char *)mCalloc(strlen(token)+1,sizeof(char)); + strcpy(io->long_tax_names[io->size_tax_names-1],token); + +/* printf("\n. Copying %s number %d",io->long_tax_names[io->size_long_tax_names-1],tax_num-1); */ + } + }while(strlen(token) > 0); + + fseek(io->fp_in_tree,-1*sizeof(char),SEEK_CUR); + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Matrix(char *token, nexparm *curr_parm, option *io) +{ + + if(io->interleaved) io->data = Read_Seq_Interleaved(io); + else io->data = Read_Seq_Sequential(io); + + fseek(io->fp_in_align,-1*sizeof(char),SEEK_CUR); + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Tree(char *token, nexparm *curr_parm, option *io) +{ + io->treelist->tree = (t_tree **)realloc(io->treelist->tree,(io->treelist->list_size+1)*sizeof(t_tree *)); + io->tree = Read_Tree_File_Phylip(io->fp_in_tree); + if(!(io->treelist->list_size%10) && io->treelist->list_size > 1) + { + PhyML_Printf("\n. Reading tree %d",io->treelist->list_size); + if(io->tree->n_root) PhyML_Printf(" (that is a rooted tree)"); + else PhyML_Printf(" (that is an unrooted tree)"); + } + io->treelist->tree[io->treelist->list_size] = io->tree; + io->treelist->list_size++; + fseek(io->fp_in_tree,-1*sizeof(char),SEEK_CUR); + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Begin(char *token, nexparm *curr_parm, option *io) +{ + if(token[0] == '=') return 0; + + if(!curr_parm) + { + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + if(!strcmp(curr_parm->name,"data") || !strcmp(curr_parm->name,"trees")) + PhyML_Printf("\n. Reading '%s' block.\n",curr_parm->value); + else + { + PhyML_Printf("\n. The '%s' block type is not supported by PhyML. Sorry.\n",curr_parm->name); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Dimensions(char *token, nexparm *curr_parm, option *io) +{ + if(token[0] == '=') return 0; + + if(!curr_parm) + { + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + strcpy(curr_parm->value,token); + + if(!strcmp(curr_parm->name,"ntax")) + { + sscanf(curr_parm->value,"%d",&(io->n_otu)); + } + + if(!strcmp(curr_parm->name,"nchar")) + { + sscanf(curr_parm->value,"%d",&(io->init_len)); + } + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Format(char *token, nexparm *curr_parm, option *io) +{ + int i; + + if(token[0] == '=') return 0; + + if(!curr_parm) + { + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + For(i,strlen(token)) Lowercase(token+i); + + strcpy(curr_parm->value,token); + + + /* printf("\n. >> %s",curr_parm->value); */ + + if(!strcmp(curr_parm->name,"datatype")) + { + if(!strcmp(curr_parm->value,"standard")) + { + io->datatype = GENERIC; + io->mod->whichmodel = JC69; + io->mod->s_opt->opt_kappa = NO; + io->mod->s_opt->opt_lambda = NO; + io->mod->ns = 2; + io->alphabet[0][0] = '0'; io->alphabet[0][1] = '\0'; + io->alphabet[1][0] = '1'; io->alphabet[1][1] = '\0'; + } + + else if(!strcmp(curr_parm->value,"dna")) + { + io->datatype = NT; + io->mod->ns = 4; + } + + else if(!strcmp(curr_parm->value,"rna")) + { + io->datatype = NT; + io->mod->ns = 4; + } + + else if(!strcmp(curr_parm->value,"nucleotide")) + { + io->datatype = NT; + io->mod->ns = 4; + } + + else if(!strcmp(curr_parm->value,"protein")) + { + io->datatype = AA; + io->mod->ns = 20; + } + + else if(!strcmp(curr_parm->value,"continuous")) + { + PhyML_Printf("\n== The 'continuous' format is not supported by PhyML. Sorry.\n"); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + } + + else if(!strcmp(curr_parm->name,"missing")) + { + PhyML_Printf("\n== The 'missing' subcommand is not supported by PhyML. Please remove it from the NEXUS file."); + PhyML_Printf("\n== Note that the characters 'X', '?' and '-' will be considered as indels by default."); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + else if(!strcmp(curr_parm->name,"gap")) + { + PhyML_Printf("\n== The 'gap' subcommand is not supported by PhyML. Please remove it from the NEXUS file."); + PhyML_Printf("\n== Note that the characters 'X', '?' and '-' will be considered as indels by default."); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + else if(!strcmp(curr_parm->name,"symbols")) + { + if(*token != '"' || *(token+strlen(token)-1) != '"') + { + PhyML_Printf("\n== Symbols list is supposed to be displayed between quotation marks (e.g., \"ACTG\").\n"); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + + int i,has_spaces,state_len; + + i = 0; + has_spaces = 0; + token++; /* Get rid of the first '"' character */ + while(token[i] != '"') { if(token[i] == ' ') { has_spaces = 1; break; } i++; } + + io->mod->ns = 0; + if(!has_spaces) + { + while(token[i] != '"') + { + io->alphabet[io->mod->ns][0] = token[i]; + io->alphabet[io->mod->ns][1] = '\0'; + io->mod->ns++; + i++; + if(io->mod->ns > T_MAX_ALPHABET) + { + PhyML_Printf("\n== The alphabet cannot contain more than %d characters. Sorry.",T_MAX_ALPHABET); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + } + } + else + { + i = 0; + do + { + state_len = 0; + while(token[i] != ' ' && token[i] != '"') + { + io->alphabet[io->mod->ns][state_len] = token[i]; + state_len++; + i++; + if(state_len > T_MAX_STATE) + { + PhyML_Printf("\n== A state cannot contain more than %d characters. Sorry.\n",T_MAX_STATE); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + } + + io->alphabet[io->mod->ns][state_len] = '\0'; + io->mod->ns++; + if(token[i] != '"') i++; + } + while(token[i] != '"'); + } + + int len; + len = strlen(io->alphabet[0]); + for(i=0;imod->ns;i++) + { + if(strlen(io->alphabet[i]) != len) + { + PhyML_Printf("\n== All character states defined in the symbol list are supposed to have the same length.\n"); + PhyML_Printf("\n== Er.r in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + } + io->state_len = len; + +/* for(i=0;imod->ns;i++) PhyML_Printf("\n. '%s'",io->alphabet[i]); */ + } + + else if(!strcmp(curr_parm->name,"equate")) + { + PhyML_Printf("\n== PhyML does not recognize the command '%s' yet. Sorry.",curr_parm->name); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + else if(!strcmp(curr_parm->name,"matchchar")) + { + PhyML_Printf("\n== PhyML does not recognize the command '%s' yet. Sorry.",curr_parm->name); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + else if(!strcmp(curr_parm->name,"items")) + { + PhyML_Printf("\n== PhyML does not recognize the command '%s' yet. Sorry.",curr_parm->name); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + else if(!strcmp(curr_parm->name,"interleave")) + { + io->interleaved = YES; + } + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Eliminate(char *token, nexparm *curr_parm, option *io) +{ + if(token[0] == '=') return 0; + + PhyML_Printf("\n== 'Eliminate' command is not supported by PhyML. Sorry."); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Taxlabel(char *token, nexparm *curr_parm, option *io) +{ + if(token[0] == '=') return 0; + + PhyML_Printf("\n== 'Taxlabels' command is not supported by PhyML. Sorry."); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Charstatelabels(char *token, nexparm *curr_parm, option *io) +{ + + if(token[0] == '=') return 0; + + PhyML_Printf("\n== 'CharStateLabels' command is not supported by PhyML. Sorry."); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Charlabels(char *token, nexparm *curr_parm, option *io) +{ + if(token[0] == '=') return 0; + + PhyML_Printf("\n== 'CharLabels' command is not supported by PhyML. Sorry."); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Read_Nexus_Statelabels(char *token, nexparm *curr_parm, option *io) +{ + if(token[0] == '=') return 0; + + PhyML_Printf("\n== 'StateLabels' command is not supported by PhyML. Sorry."); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + diff --git a/phyml/nexus.h b/phyml/nexus.h new file mode 100644 index 0000000..a7bbc13 --- /dev/null +++ b/phyml/nexus.h @@ -0,0 +1,35 @@ +/* + +PHYML : a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences + +Copyright (C) Stephane Guindon. Oct 2003 onward + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef NEXUS_H +#define NEXUS_H + +#include "utilities.h" + +void Find_Nexus_Com(char *token,nexcom **found_com,nexparm **default_parm,nexcom **com_list); +void Find_Nexus_Parm(char *token,nexparm **found_parm,nexcom *curr_com); +int Read_Nexus_Taxa(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Translate(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Matrix(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Tree(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Begin(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Dimensions(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Format(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Eliminate(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Taxlabel(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Charstatelabels(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Charlabels(char *token,nexparm *curr_parm,option *io); +int Read_Nexus_Statelabels(char *token,nexparm *curr_parm,option *io); + +#endif diff --git a/phyml/optimiz.c b/phyml/optimiz.c index af16fb4..3501589 100644 --- a/phyml/optimiz.c +++ b/phyml/optimiz.c @@ -1,54 +1,52 @@ /* - -PHYML : a program that computes maximum likelihood phylogenies from -DNA or AA homologous sequences - +PhyML : a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences Copyright (C) Stephane Guindon. Oct 2003 onward - All parts of the source except where indicated are distributed under the GNU public licence. See http://www.opensource.org for details. - */ -#include "utilities.h" #include "optimiz.h" -#include "lk.h" -#include "free.h" -#include "models.h" -#include "mc.h" -/*********************************************************/ +static phydbl Br_Len_Spline(phydbl *l, t_edge *b, int n_iter_max, phydbl tol, t_tree *tree); -void Optimize_Single_Param_Generic(arbre *tree, phydbl *param, phydbl lim_inf, phydbl lim_sup, phydbl tol, int n_max_iter) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_Single_Param_Generic(t_tree *tree, phydbl *param, phydbl lim_inf, phydbl lim_sup, phydbl tol, int n_max_iter, int quickdirty) { - phydbl ax,bx,cx; phydbl lk_init; lk_init = tree->c_lnL; - ax = lim_inf; - bx = (*param); - cx = lim_sup; - - Generic_Brent(ax,bx,cx,tol,param,tree,n_max_iter); + Generic_Brent_Lk(param, + lim_inf, + lim_sup, + tol, + n_max_iter, + quickdirty, + Wrap_Lk, + NULL, + tree, + NULL, + NO); + - if(tree->c_lnL < lk_init - tree->mod->s_opt->min_diff_lk_global) + if(tree->c_lnL < lk_init - tree->mod->s_opt->min_diff_lk_global) { - printf("\n. %.10f < %.10f --> diff=%.10f param value = %f initial value = %f\n", - tree->c_lnL,lk_init, - tree->c_lnL-lk_init, - *param,bx); - Exit("\n. Optimisation failed !\n"); + PhyML_Fprintf(stderr,"\n. %.10f < %.10f --> diff=%.10f param value = %f\n",tree->c_lnL,lk_init,tree->c_lnL-lk_init,*param); + assert(FALSE); } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// int Generic_Brak(phydbl *param, - phydbl *ax, phydbl *bx, phydbl *cx, - phydbl *fa, phydbl *fb, phydbl *fc, - phydbl lim_inf, phydbl lim_sup, - arbre *tree) + phydbl *ax, phydbl *bx, phydbl *cx, + phydbl *fa, phydbl *fb, phydbl *fc, + phydbl lim_inf, phydbl lim_sup, + t_tree *tree) { phydbl ulim,u,r,q,fu,dum; @@ -57,23 +55,23 @@ int Generic_Brak(phydbl *param, if(*param > lim_sup) *param = lim_sup; if(*param < lim_inf) *param = lim_inf; - *fa=-Return_Lk(tree); + *fa=-Lk(NULL,tree); *param = *bx; if(*param > lim_sup) *param = lim_sup; if(*param < lim_inf) *param = lim_inf; - *fb=-Return_Lk(tree); + *fb=-Lk(NULL,tree); if (*fb > *fa) { - SHFT(dum,*ax,*bx,dum) - SHFT(dum,*fb,*fa,dum) - } + SHFT(dum,*ax,*bx,dum) + SHFT(dum,*fb,*fa,dum) + } *cx=(*bx)+MNBRAK_GOLD*(*bx-*ax); - *param = fabs(*cx); + *param = FABS(*cx); if(*param > lim_sup) *param = lim_sup; if(*param < lim_inf) *param = lim_inf; - *fc=-Return_Lk(tree); - while (*fb > *fc) + *fc=-Lk(NULL,tree); + while (*fb > *fc) { - + if(*ax > lim_sup) *ax = lim_sup; if(*ax < lim_inf) *ax = lim_inf; if(*bx > lim_sup) *bx = lim_sup; @@ -82,200 +80,308 @@ int Generic_Brak(phydbl *param, if(*cx < lim_inf) *cx = lim_inf; if(u > lim_sup) u = lim_sup; if(u < lim_inf) u = lim_inf; - + r=(*bx-*ax)*(*fb-*fc); q=(*bx-*cx)*(*fb-*fa); u=(*bx)-((*bx-*cx)*q-(*bx-*ax)*r)/ - (2.0*SIGN(MAX(fabs(q-r),MNBRAK_TINY),q-r)); + (2.0*SIGN(MAX(FABS(q-r),MNBRAK_TINY),q-r)); ulim=(*bx)+MNBRAK_GLIMIT*(*cx-*bx); - if ((*bx-u)*(u-*cx) > lim_inf) - { - *param = fabs(u); - if(*param > lim_sup) {*param = u = lim_sup;} - if(*param < lim_inf) {*param = u = lim_inf;} - fu=-Return_Lk(tree); - if (fu < *fc) - { - *ax=(*bx); - *bx=u; - *fa=(*fb); - *fb=fu; - (*ax)=fabs(*ax); - (*bx)=fabs(*bx); - (*cx)=fabs(*cx); - return(0); - } - else if (fu > *fb) - { - *cx=u; - *fc=fu; - (*ax)=fabs(*ax); - (*bx)=fabs(*bx); - (*cx)=fabs(*cx); - return(0); - } - u=(*cx)+MNBRAK_GOLD*(*cx-*bx); - *param = fabs(u); - if(*param > lim_sup) {*param = u = lim_sup;} - if(*param < lim_inf) {*param = u = lim_inf;} - fu=-Return_Lk(tree); - } - else if ((*cx-u)*(u-ulim) > lim_inf) - { - *param = fabs(u); - if(*param > lim_sup) {*param = u = lim_sup;} - if(*param < lim_inf) {*param = u = lim_inf;} - fu=-Return_Lk(tree); - if (fu < *fc) - { - SHFT(*bx,*cx,u,*cx+MNBRAK_GOLD*(*cx-*bx)) - *param = fabs(u); - SHFT(*fb,*fc,fu,-Return_Lk(tree)) - } - } - else if ((u-ulim)*(ulim-*cx) >= lim_inf) - { - u=ulim; - *param = fabs(u); - if(*param > lim_sup) {*param = u = lim_sup;} - if(*param < lim_inf) {*param = u = lim_inf;} - fu=-Return_Lk(tree); - } - else - { - u=(*cx)+MNBRAK_GOLD*(*cx-*bx); - *param = fabs(u); - if(*param > lim_sup) {*param = u = lim_sup;} - if(*param < lim_inf) {*param = u = lim_inf;} - fu=-Return_Lk(tree); - } + if ((*bx-u)*(u-*cx) > lim_inf) + { + *param = FABS(u); + if(*param > lim_sup) {*param = u = lim_sup;} + if(*param < lim_inf) {*param = u = lim_inf;} + fu=-Lk(NULL,tree); + if (fu < *fc) + { + *ax=(*bx); + *bx=u; + *fa=(*fb); + *fb=fu; + (*ax)=FABS(*ax); + (*bx)=FABS(*bx); + (*cx)=FABS(*cx); + return(0); + } + else if (fu > *fb) + { + *cx=u; + *fc=fu; + (*ax)=FABS(*ax); + (*bx)=FABS(*bx); + (*cx)=FABS(*cx); + return(0); + } + u=(*cx)+MNBRAK_GOLD*(*cx-*bx); + *param = FABS(u); + if(*param > lim_sup) {*param = u = lim_sup;} + if(*param < lim_inf) {*param = u = lim_inf;} + fu=-Lk(NULL,tree); + } + else if ((*cx-u)*(u-ulim) > lim_inf) + { + *param = FABS(u); + if(*param > lim_sup) {*param = u = lim_sup;} + if(*param < lim_inf) {*param = u = lim_inf;} + fu=-Lk(NULL,tree); + if (fu < *fc) + { + SHFT(*bx,*cx,u,*cx+MNBRAK_GOLD*(*cx-*bx)) + *param = FABS(u); + SHFT(*fb,*fc,fu,-Lk(NULL,tree)) + } + } + else if ((u-ulim)*(ulim-*cx) >= lim_inf) + { + u=ulim; + *param = FABS(u); + if(*param > lim_sup) {*param = u = lim_sup;} + if(*param < lim_inf) {*param = u = lim_inf;} + fu=-Lk(NULL,tree); + } + else + { + u=(*cx)+MNBRAK_GOLD*(*cx-*bx); + *param = FABS(u); + if(*param > lim_sup) {*param = u = lim_sup;} + if(*param < lim_inf) {*param = u = lim_inf;} + fu=-Lk(NULL,tree); + } SHFT(*ax,*bx,*cx,u) - SHFT(*fa,*fb,*fc,fu) + SHFT(*fa,*fb,*fc,fu) + + + } + (*ax)=FABS(*ax); + (*bx)=FABS(*bx); + (*cx)=FABS(*cx); + return(0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Generic_Brak_Lk(phydbl *param, + phydbl *ax, phydbl *bx, phydbl *cx, + phydbl *fa, phydbl *fb, phydbl *fc, + phydbl min, phydbl max, + phydbl (*obj_func)(t_edge *,t_tree *,supert_tree *), + t_edge *branch, t_tree *tree, supert_tree *stree) +{ + phydbl ulim,u,r,q,fu,dum; + + *param = *ax; + if(*param < min) *param = min; + if(*param > max) *param = max; + *fa = -(*obj_func)(branch,tree,stree); + *param = *bx; + if(*param < min) *param = min; + if(*param > max) *param = max; + *fb = -(*obj_func)(branch,tree,stree); + if (*fb > *fa) + { + SHFT(dum,*ax,*bx,dum) + SHFT(dum,*fb,*fa,dum) } - (*ax)=fabs(*ax); - (*bx)=fabs(*bx); - (*cx)=fabs(*cx); + + *cx=(*bx)+MNBRAK_GOLD*(*bx-*ax); + *param = *cx; + if(*param < min) *param = min; + if(*param > max) *param = max; + *fc = -(*obj_func)(branch,tree,stree); + + /* printf("\nx la: %f lb: %f lc: %f fa: %f fb: %f fc: %f",*ax,*bx,*cx,*fa,*fb,*fc); */ + while (*fb > *fc) + { + /* printf("\nx la: %f lb: %f lc: %f fa: %f fb: %f fc: %f",*ax,*bx,*cx,*fa,*fb,*fc); */ + r=(*bx-*ax)*(*fb-*fc); + q=(*bx-*cx)*(*fb-*fa); + u=(*bx)-((*bx-*cx)*q-(*bx-*ax)*r)/ + (2.0*SIGN(MAX(FABS(q-r),MNBRAK_TINY),q-r)); + ulim=(*bx)+MNBRAK_GLIMIT*(*cx-*bx); + + if((*bx-u)*(u-*cx) > 0.0) + { + *param = u; + if(*param < min) *param = min; + if(*param > max) *param = max; + fu = -(*obj_func)(branch,tree,stree); + + if (fu < *fc) + { + *ax=(*bx); + *bx=u; + *fa=(*fb); + *fb=fu; + return(0); + } + else if (fu > *fb) + { + *cx=u; + *fc=fu; + return(0); + } + u=(*cx)+MNBRAK_GOLD*(*cx-*bx); + *param = u; + if(*param < min) *param = min; + if(*param > max) *param = max; + fu = -(*obj_func)(branch,tree,stree); + } + else if ((*cx-u)*(u-ulim) > 0.0) + { + *param = u; + if(*param < min) *param = min; + if(*param > max) *param = max; + fu = -(*obj_func)(branch,tree,stree); + + if (fu < *fc) + { + SHFT(*bx,*cx,u,*cx+MNBRAK_GOLD*(*cx-*bx)) + *param = u; + if(*param < min) *param = min; + if(*param > max) *param = max; + SHFT(*fb,*fc,fu,-(*obj_func)(branch,tree,stree)) + } + } + else if ((u-ulim)*(ulim-*cx) >= 0.0) + { + u=ulim; + *param = u; + if(*param < min) *param = min; + if(*param > max) *param = max; + fu = -(*obj_func)(branch,tree,stree); + } + else + { + u=(*cx)+MNBRAK_GOLD*(*cx-*bx); + *param = u; + if(*param < min) *param = min; + if(*param > max) *param = max; + fu = -(*obj_func)(branch,tree,stree); + } + SHFT(*ax,*bx,*cx,u) + SHFT(*fa,*fb,*fc,fu) + } + return(0); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Generic_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, arbre *tree, int n_iter_max) +phydbl Generic_Brent(phydbl *param, phydbl ax, phydbl cx, phydbl tol, + int n_iter_max, + phydbl (*obj_func)(t_tree *), + t_tree *tree) { int iter; phydbl a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; phydbl e=0.0; - phydbl old_lnL,init_lnL; - phydbl best_fu, best_x; - + phydbl old_score; + phydbl bx = *param; + int n_opt_step; + n_opt_step = 0; d=0.0; a=((ax < cx) ? ax : cx); b=((ax > cx) ? ax : cx); x=w=v=bx; - old_lnL = UNLIKELY; - (*xmin) = fabs(bx); - fw=fv=fx=-Return_Lk(tree); - init_lnL = -fw; - best_fu = fw; - best_x = fabs(bx);; - -/* printf("init_lnL = %f\n",init_lnL); */ - - for(iter=1;iter<=BRENT_ITMAX;iter++) + (*param) = bx; + fw=fv=fx=fu=(*obj_func)(tree); + old_score = fw; + + /* PhyML_Printf("\n. %p init_score=%f fu=%f ax=%f cx=%f param=%f",tree,init_score,fu,ax,cx,*param); */ + + for(iter=1;iter<=BRENT_IT_MAX;iter++) { xm=0.5*(a+b); - tol2=2.0*(tol1=tol*fabs(x)+BRENT_ZEPS); - if( - ((fabs(tree->c_lnL-old_lnL) < tol) && (tree->c_lnL > init_lnL - tol)) || (iter > n_iter_max - 1)) - { - (*xmin) = best_x; - Lk(tree); -/* printf("\n> iter=%3d max=%3d v=%f lnL=%f init_lnL=%f",iter,n_iter_max,(*xmin),tree->c_lnL,init_lnL); */ - return tree->c_lnL; - } + tol2=2.0*(tol1=tol*x+BRENT_ZEPS); - if(fabs(e) > tol1) - { - r=(x-w)*(fx-fv); - q=(x-v)*(fx-fw); - p=(x-v)*q-(x-w)*r; - q=2.0*(q-r); - if(q > 0.0) p = -p; - q=fabs(q); - etemp=e; - e=d; - if(fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - /* printf("Golden section step\n"); */ - } - else - { - d=p/q; - u=x+d; - if (u-a < tol2 || b-u < tol2) - d=SIGN(tol1,xm-x); - /* printf("Parabolic step\n"); */ - } + if((fabs(fu-old_score) < tol && iter > 1) || (iter > n_iter_max - 1)) + { + (*param) = x; + fu = (*obj_func)(tree); + /* printf("\n. return %f [%f] %d",*param,fu,iter); */ + return fu; + } + + if(fabs(e) > tol1) + { + r=(x-w)*(fx-fv); + q=(x-v)*(fx-fw); + p=(x-v)*q-(x-w)*r; + q=2.0*(q-r); + if(q > 0.0) p = -p; + q=fabs(q); + etemp=e; + e=d; + if(fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) + { + d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); + /* PhyML_Printf("\n. Golden section step"); */ + } + else + { + d=p/q; + u=x+d; + if (u-a < tol2 || b-u < tol2) d=SIGN(tol1,xm-x); + /* PhyML_Printf("\n. Parabolic step [e=%f]",e); */ + } } else - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - /* printf("Golden section step (default)\n"); */ - } - + { + d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); + /* PhyML_Printf("\n. Golden section step (default) [e=%f tol1=%f a=%f b=%f d=%f x=%f]",e,tol1,a,b,d,x); */ + } + u=(fabs(d) >= tol1 ? x+d : x+SIGN(tol1,d)); - (*xmin) = fabs(u); - old_lnL = tree->c_lnL; - fu = -Return_Lk(tree); - - if(fu < best_fu) - { - best_fu = fu; - best_x = fabs(u); - } - -/* printf("\n. iter=%d/%d param=%f loglk=%f (best=%f %f)",iter,BRENT_ITMAX,*xmin,tree->c_lnL,best_fu,best_x); */ - - if(fu <= fx) - { - if(u >= x) a=x; else b=x; - SHFT(v,w,x,u) - SHFT(fv,fw,fx,fu) - } + (*param) = u; + n_opt_step++; + old_score = fu; + fu = (*obj_func)(tree); + /* PhyML_Printf("\n. iter=%d/%d param=%f lnL=%f u: %f x: %f d: %f logt: %d",iter,BRENT_IT_MAX,*param,fu,u,x,d,logt); */ + + if(fu <= fx) + { + if(u >= x) a=x; else b=x; + SHFT(v,w,x,u) + SHFT(fv,fw,fx,fu) + } else - { - if (u < x) a=u; else b=u; - if (fu <= fw || w == x) - { - v=w; - w=u; - fv=fw; - fw=fu; - } - else if (fu <= fv || v == x || v == w) - { - v=u; - fv=fu; - } - } + { + if (u < x) a=u; else b=u; + if (fu < fw || fabs(w-x) < SMALL) + { + v=w; + w=u; + fv=fw; + fw=fu; + } + /* else if (fu <= fv || v == x || v == w) */ + else if (fu < fv || fabs(v-x) < SMALL || fabs(v-w) < SMALL) + { + v=u; + fv=fu; + } + } } - Exit("\n. Too many iterations in BRENT !"); - return(-1); - /* Not Reached ?? *xmin=x; */ + PhyML_Printf("\n. Too many iterations in Generic_Brent !"); + assert(FALSE); + return((*obj_func)(tree)); + /* Not Reached ?? *param=x; */ /* Not Reached ?? return fx; */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -phydbl RRparam_GTR_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, arbre *tree, allseq *alldata, phydbl *param, int n_iter_max) +phydbl RRparam_GTR_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, + phydbl *xmin, t_tree *tree, calign *cdata, phydbl *param, int n_iter_max) { phydbl f1,f2,x0,x1,x2,x3; int n_iter; @@ -283,1302 +389,984 @@ phydbl RRparam_GTR_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, x0=ax; x3=cx; - if (fabs(cx-bx) > fabs(bx-ax)) + if (FABS(cx-bx) > FABS(bx-ax)) { x1=bx; x2=bx+GOLDEN_C*(cx-bx); - } - else + } + else { x2=bx; x1=bx-GOLDEN_C*(bx-ax); } (*param)=x1; - Lk(tree); + Lk(NULL,tree); f1=-tree->c_lnL; (*param)=x2; - Lk(tree); + Lk(NULL,tree); f2=-tree->c_lnL; n_iter = 0; - while (fabs(x3-x0) > tol*(fabs(x1)+fabs(x2))) + while (FABS(x3-x0) > tol*(FABS(x1)+FABS(x2))) { - if (f2 < f1) - { - SHFT3(x0,x1,x2,GOLDEN_R*x1+GOLDEN_C*x3) - (*param)=x2; - Lk(tree); - SHFT2(f1,f2,-tree->c_lnL) - } - else - { - SHFT3(x3,x2,x1,GOLDEN_R*x2+GOLDEN_C*x0) - (*param)=x1; - Lk(tree); - SHFT2(f2,f1,-tree->c_lnL) - } - + if (f2 < f1) + { + SHFT3(x0,x1,x2,GOLDEN_R*x1+GOLDEN_C*x3) + (*param)=x2; + Lk(NULL,tree); + SHFT2(f1,f2,-tree->c_lnL) + } + else + { + SHFT3(x3,x2,x1,GOLDEN_R*x2+GOLDEN_C*x0) + (*param)=x1; + Lk(NULL,tree); + SHFT2(f2,f1,-tree->c_lnL) + } + if(n_iter++ > n_iter_max) break; - -/* printf("p=%E %f\n",(*param),tree->c_lnL); */ + +/* PhyML_Printf("p=%E %f\n",(*param),tree->c_lnL); */ } - if (f1 < f2) + if (f1 < f2) { *xmin=x1; return f1; - } - else + } + else { *xmin=x2; return f2; } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Br_Len_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, edge *b_fcus, arbre *tree) + +phydbl Br_Len_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, + phydbl *xmin, t_edge *b_fcus, t_tree *tree) { phydbl f1,f2,x0,x1,x2,x3; x0=ax; x3=cx; - if (fabs(cx-bx) > fabs(bx-ax)) + if(FABS(cx-bx) > FABS(bx-ax)) { x1=bx; x2=bx+GOLDEN_C*(cx-bx); - } - else + } + else { x2=bx; x1=bx-GOLDEN_C*(bx-ax); } - b_fcus->l=x1; - f1 = -Lk_At_Given_Edge(b_fcus,tree); - b_fcus->l=x2; - f2 = -Lk_At_Given_Edge(b_fcus,tree); - while (fabs(x3-x0) > tol*(fabs(x1)+fabs(x2))) + b_fcus->l->v = x1; + f1 = -Lk(b_fcus,tree); + b_fcus->l->v = x2; + f2 = -Lk(b_fcus,tree); + + while (FABS(x3-x0) > tol*(FABS(x1)+FABS(x2))) { - if (f2 < f1) - { - SHFT3(x0,x1,x2,GOLDEN_R*x1+GOLDEN_C*x3) - b_fcus->l=x2; - SHFT2(f1,f2,-Lk_At_Given_Edge(b_fcus,tree)) - } - else - { - SHFT3(x3,x2,x1,GOLDEN_R*x2+GOLDEN_C*x0) - b_fcus->l=x1; - SHFT2(f2,f1,-Lk_At_Given_Edge(b_fcus,tree)) - } + if (f2 < f1) + { + SHFT3(x0,x1,x2,GOLDEN_R*x1+GOLDEN_C*x3) + b_fcus->l->v = x2; + SHFT2(f1,f2,-Lk(b_fcus,tree)) + } + else + { + SHFT3(x3,x2,x1,GOLDEN_R*x2+GOLDEN_C*x0) + b_fcus->l->v = x1; + SHFT2(f2,f1,-Lk(b_fcus,tree)) + } } - if (f1 < f2) + + if (f1 < f2) { - *xmin=fabs(x1); + *xmin = x1; return -f1; - } - else + } + else { - *xmin=fabs(x2); + *xmin = x2; return -f2; } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -int Br_Len_Brak(phydbl *ax, phydbl *bx, phydbl *cx, - phydbl *fa, phydbl *fb, phydbl *fc, - edge *b_fcus, arbre *tree) +int Br_Len_Brak(phydbl *ax, phydbl *bx, phydbl *cx, + phydbl *fa, phydbl *fb, phydbl *fc, + t_edge *b_fcus, t_tree *tree) { phydbl ulim,u,r,q,fu,dum; - b_fcus->l = *ax; - *fa=-Lk_At_Given_Edge(b_fcus,tree); - b_fcus->l = *bx; - *fb=-Lk_At_Given_Edge(b_fcus,tree); + b_fcus->l->v = *ax; + *fa=-Lk(b_fcus,tree); + b_fcus->l->v = *bx; + *fb=-Lk(b_fcus,tree); if (*fb > *fa) { SHFT(dum,*ax,*bx,dum) SHFT(dum,*fb,*fa,dum) } *cx=(*bx)+MNBRAK_GOLD*(*bx-*ax); - b_fcus->l = *cx; - *fc=-Lk_At_Given_Edge(b_fcus,tree); - while (*fb > *fc + tree->mod->s_opt->min_diff_lk_local) + b_fcus->l->v = *cx; + *fc=-Lk(b_fcus,tree); + while (*fb > *fc + tree->mod->s_opt->min_diff_lk_local) { - printf("fb=%f fc=%f\n",*fb,*fc); + PhyML_Printf("fb=%f fc=%f\n",*fb,*fc); r=(*bx-*ax)*(*fb-*fc); q=(*bx-*cx)*(*fb-*fa); u=(*bx)-((*bx-*cx)*q-(*bx-*ax)*r)/ - (2.0*SIGN(MAX(fabs(q-r),MNBRAK_TINY),q-r)); + (2.0*SIGN(MAX(FABS(q-r),MNBRAK_TINY),q-r)); ulim=(*bx)+MNBRAK_GLIMIT*(*cx-*bx); - - if ((*bx-u)*(u-*cx) > 0.0) - { - b_fcus->l = u; - fu=-Lk_At_Given_Edge(b_fcus,tree); - if (fu < *fc) - { - *ax=(*bx); - *bx=u; - *fa=(*fb); - *fb=fu; -/* (*ax)=fabs(*ax); */ -/* (*bx)=fabs(*bx); */ -/* (*cx)=fabs(*cx); */ - return(0); - } - else if (fu > *fb) - { - *cx=u; - *fc=fu; -/* (*ax)=fabs(*ax); */ -/* (*bx)=fabs(*bx); */ -/* (*cx)=fabs(*cx); */ - return(0); - } - u=(*cx)+MNBRAK_GOLD*(*cx-*bx); - b_fcus->l = u; - fu=-Lk_At_Given_Edge(b_fcus,tree); - } - else if ((*cx-u)*(u-ulim) > 0.0) - { - b_fcus->l = fabs(u); - fu=-Lk_At_Given_Edge(b_fcus,tree); - if (fu < *fc) - { - SHFT(*bx,*cx,u,*cx+MNBRAK_GOLD*(*cx-*bx)) - b_fcus->l = u; - SHFT(*fb,*fc,fu,-Lk_At_Given_Edge(b_fcus,tree)) - } - } - else if ((u-ulim)*(ulim-*cx) >= 0.0) - { - u=ulim; - b_fcus->l = u; - fu=-Lk_At_Given_Edge(b_fcus,tree); - } - else - { - u=(*cx)+MNBRAK_GOLD*(*cx-*bx); - b_fcus->l = u; - fu=-Lk_At_Given_Edge(b_fcus,tree); - } + + if ((*bx-u)*(u-*cx) > 0.0) + { + b_fcus->l->v = u; + fu=-Lk(b_fcus,tree); + if (fu < *fc) + { + *ax=(*bx); + *bx=u; + *fa=(*fb); + *fb=fu; +/* (*ax)=FABS(*ax); */ +/* (*bx)=FABS(*bx); */ +/* (*cx)=FABS(*cx); */ + return(0); + } + else if (fu > *fb) + { + *cx=u; + *fc=fu; +/* (*ax)=FABS(*ax); */ +/* (*bx)=FABS(*bx); */ +/* (*cx)=FABS(*cx); */ + return(0); + } + u=(*cx)+MNBRAK_GOLD*(*cx-*bx); + b_fcus->l->v = u; + fu=-Lk(b_fcus,tree); + } + else if ((*cx-u)*(u-ulim) > 0.0) + { + b_fcus->l->v = FABS(u); + fu=-Lk(b_fcus,tree); + if (fu < *fc) + { + SHFT(*bx,*cx,u,*cx+MNBRAK_GOLD*(*cx-*bx)) + b_fcus->l->v = u; + SHFT(*fb,*fc,fu,-Lk(b_fcus,tree)) + } + } + else if ((u-ulim)*(ulim-*cx) >= 0.0) + { + u=ulim; + b_fcus->l->v = u; + fu=-Lk(b_fcus,tree); + } + else + { + u=(*cx)+MNBRAK_GOLD*(*cx-*bx); + b_fcus->l->v = u; + fu=-Lk(b_fcus,tree); + } SHFT(*ax,*bx,*cx,u) SHFT(*fa,*fb,*fc,fu) } - (*ax)=fabs(*ax); - (*bx)=fabs(*bx); - (*cx)=fabs(*cx); + (*ax)=FABS(*ax); + (*bx)=FABS(*bx); + (*cx)=FABS(*cx); return(0); } -/*********************************************************/ - -phydbl Br_Len_Brent_Default(edge *b_fcus, arbre *tree) -{ - return Br_Len_Brent(10.*b_fcus->l,b_fcus->l,.10*b_fcus->l,tree->mod->s_opt->min_diff_lk_local,b_fcus,tree,1000); -} - -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Br_Len_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - edge *b_fcus, arbre *tree, int n_iter_max) +phydbl Fast_Br_Len(t_edge *b, t_tree *tree, int approx) { - int iter; - phydbl a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; - phydbl e=0.0; - phydbl old_lnL, init_lnL; + phydbl init_min_diff_lk_local = tree->mod->s_opt->min_diff_lk_local; - d=0.0; - a=((ax < cx) ? ax : cx); - b=((ax > cx) ? ax : cx); - x=w=v=bx; - old_lnL = UNLIKELY; - b_fcus->l = fabs(bx); - fw=fv=fx=fu=-Lk_At_Given_Edge(b_fcus,tree); - init_lnL = -fw; + tree->mod->s_opt->min_diff_lk_local = 1.E-1; - for(iter=1;iter<=BRENT_ITMAX;iter++) - { - xm=0.5*(a+b); - tol2=2.0*(tol1=tol*fabs(x)+BRENT_ZEPS); - if( - ((fabs(tree->c_lnL-old_lnL) < tol) && - (tree->c_lnL > init_lnL - tol)) || - (iter > n_iter_max - 1)) - { - b_fcus->l=x; - Lk_At_Given_Edge(b_fcus,tree); -/* printf("\n. iter=%3d max=%3d l=%f lnL=%f init_lnL=%f",iter,n_iter_max,b_fcus->l,tree->c_lnL,init_lnL); */ - return tree->c_lnL; - } - - if(fabs(e) > tol1) - { - r=(x-w)*(fx-fv); - q=(x-v)*(fx-fw); - p=(x-v)*q-(x-w)*r; - q=2.0*(q-r); - if(q > 0.0) p = -p; - q=fabs(q); - etemp=e; - e=d; - if(fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - else{ - d=p/q; - u=x+d; - if (u-a < tol2 || b-u < tol2) - d=SIGN(tol1,xm-x); - } - } - else - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - } - u=(fabs(d) >= tol1 ? x+d : x+SIGN(tol1,d)); - if(ul=fabs(u); - old_lnL = tree->c_lnL; - fu=-Lk_At_Given_Edge(b_fcus,tree); + if(tree->is_mixt_tree) MIXT_Br_Len_Opt(b,tree); + else Br_Len_Opt(&(b->l->v),b,tree); -/* printf("\n. BRENT edge %3d l=%f lnL=%20f iter=%3d",b_fcus->num,b_fcus->l,fu,iter); */ + tree->mod->s_opt->min_diff_lk_local = init_min_diff_lk_local; - if(fu <= fx) - { - if(u >= x) a=x; else b=x; - SHFT(v,w,x,u) - SHFT(fv,fw,fx,fu) - } - else - { - if (u < x) a=u; else b=u; - if (fu <= fw || w == x) - { - v=w; - w=u; - fv=fw; - fw=fu; - } - else if (fu <= fv || v == x || v == w) - { - v=u; - fv=fu; - } - } - } - if(iter > BRENT_ITMAX) printf("\n. Too many iterations in BRENT (%d) (%f)",iter,b_fcus->l); - return(-1); - /* Not Reached ?? *xmin=x; */ - /* Not Reached ?? return fx; */ + return tree->c_lnL; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Node_Time_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - node *anc, node *des, arbre *tree, int n_iter_max) +phydbl Br_Len_Opt(phydbl *l, t_edge *b, t_tree *tree) { - int iter; - phydbl a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; - phydbl e=0.0; - phydbl old_lnL, init_lnL; + phydbl lk_begin, lk_end; - d=0.0; - a=((ax < cx) ? ax : cx); - b=((ax > cx) ? ax : cx); - x=w=v=bx; - old_lnL = UNLIKELY; - des->t = fabs(bx); - fw=fv=fx=fu=-Lk_Triplet(anc,des,tree); - init_lnL = -fw; - - for(iter=1;iter<=BRENT_ITMAX;iter++) + + if(tree->is_mixt_tree == YES && tree->ignore_mixt_info == NO) { - xm=0.5*(a+b); - tol2=2.0*(tol1=tol*fabs(x)+BRENT_ZEPS); - if( - ((fabs(tree->c_lnL-old_lnL) < tol) && - (tree->c_lnL > init_lnL - tol)) || - (iter > n_iter_max - 1)) - { - des->t=x; - Lk_Triplet(anc,des,tree); -/* printf("\n. iter=%3d max=%3d l=%f lnL=%f init_lnL=%f",iter,n_iter_max,des->t,tree->c_lnL,init_lnL); */ - return tree->c_lnL; - } - - if(fabs(e) > tol1) - { - r=(x-w)*(fx-fv); - q=(x-v)*(fx-fw); - p=(x-v)*q-(x-w)*r; - q=2.0*(q-r); - if(q > 0.0) p = -p; - q=fabs(q); - etemp=e; - e=d; - if(fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - else{ - d=p/q; - u=x+d; - if (u-a < tol2 || b-u < tol2) - d=SIGN(tol1,xm-x); - } - } - else - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - } - u=(fabs(d) >= tol1 ? x+d : x+SIGN(tol1,d)); - if(ut=fabs(u); - old_lnL = tree->c_lnL; - fu=-Lk_Triplet(anc,des,tree); + MIXT_Br_Len_Opt(b,tree); + return tree->c_lnL; + } -/* printf("\n. BRENT node %3d t=%f lnL=%20f iter=%3d",des->num,des->t,fu,iter); */ + if(b->l->onoff == OFF) return tree->c_lnL; - if(fu <= fx) - { - if(u >= x) a=x; else b=x; - SHFT(v,w,x,u) - SHFT(fv,fw,fx,fu) - } - else - { - if (u < x) a=u; else b=u; - if (fu <= fw || w == x) - { - v=w; - w=u; - fv=fw; - fw=fu; - } - else if (fu <= fv || v == x || v == w) - { - v=u; - fv=fu; - } - } + lk_begin = UNLIKELY; + lk_end = UNLIKELY; + + Set_Update_Eigen_Lr(YES,tree); + Set_Use_Eigen_Lr(NO,tree); + + lk_begin = Lk(b,tree); /* We can't assume that the log-lk value is up-to-date */ + + Set_Update_Eigen_Lr(NO,tree); + Set_Use_Eigen_Lr(YES,tree); + + Br_Len_Spline(l,b,tree->mod->s_opt->brent_it_max,tree->mod->s_opt->min_diff_lk_local,tree); + + Update_PMat_At_Given_Edge(b,tree); + + Set_Update_Eigen_Lr(NO,tree); + Set_Use_Eigen_Lr(NO,tree); + + /* lk_begin = Lk(b,tree); */ + /* tree->n_tot_bl_opt += Generic_Brent_Lk(l, */ + /* tree->mod->l_min, */ + /* tree->mod->l_max, */ + /* tree->mod->s_opt->min_diff_lk_local, */ + /* tree->mod->s_opt->brent_it_max, */ + /* tree->mod->s_opt->quickdirty, */ + /* Wrap_Lk_At_Given_Edge, */ + /* b,tree,NULL,NO); */ + + /* printf("\n. b->num: %4d l=%12G lnL: %12G",b->num,b->l->v,tree->c_lnL); */ + + + /* lk_end = Lk(b,tree); /\* We can't assume that the log-lk value is up-to-date *\/ */ + lk_end = tree->c_lnL; + + if(lk_end < lk_begin - tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Fprintf(stderr,"\n. lk_beg = %f lk_end = %f",lk_begin, lk_end); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d",__FILE__,__LINE__); + Exit("\n"); } - if(iter > BRENT_ITMAX) printf("\n. Too many iterations in BRENT (%d) (%f)",iter,des->t); - return(-1); - /* Not Reached ?? *xmin=x; */ - /* Not Reached ?? return fx; */ + + return tree->c_lnL; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Time_Stamps_Mult_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - arbre *tree, int n_iter_max) +void Round_Optimize(t_tree *tree, int n_round_max) { - int iter; - phydbl a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; - phydbl e=0.0; - phydbl old_lnL, init_lnL; + int n_round,each,freq; + phydbl lk_old, lk_new; - d=0.0; - a=((ax < cx) ? ax : cx); - b=((ax > cx) ? ax : cx); - x=w=v=bx; - old_lnL = UNLIKELY; - tree->mod->s_opt->tree_size_mult = fabs(bx); - MC_Mult_Time_Stamps(tree); - tree->both_sides = 1; - fw=fv=fx=fu=-Return_Lk(tree); - MC_Div_Time_Stamps(tree); - init_lnL = -fw; - - for(iter=1;iter<=BRENT_ITMAX;iter++) + lk_new = tree->c_lnL; + lk_old = UNLIKELY; + n_round = 0; + each = 0; + freq = 1; + + while(n_round < n_round_max) { - xm=0.5*(a+b); - tol2=2.0*(tol1=tol*fabs(x)+BRENT_ZEPS); - if( - ((fabs(tree->c_lnL-old_lnL) < tol) && - (tree->c_lnL > init_lnL - tol)) || - (iter > n_iter_max - 1)) - { - tree->mod->s_opt->tree_size_mult=fabs(x); - MC_Mult_Time_Stamps(tree); - tree->both_sides = 1; - Lk(tree); - tree->mod->s_opt->tree_size_mult = 1.0; - return tree->c_lnL; - } + if(tree->mod->s_opt->opt_bl || tree->mod->s_opt->constrained_br_len) Optimize_Br_Len_Serie(n_round_max,tree); + - if(fabs(e) > tol1) - { - r=(x-w)*(fx-fv); - q=(x-v)*(fx-fw); - p=(x-v)*q-(x-w)*r; - q=2.0*(q-r); - if(q > 0.0) p = -p; - q=fabs(q); - etemp=e; - e=d; - if(fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - else{ - d=p/q; - u=x+d; - if (u-a < tol2 || b-u < tol2) - d=SIGN(tol1,xm-x); - } - } - else - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - } - u=(fabs(d) >= tol1 ? x+d : x+SIGN(tol1,d)); - old_lnL = tree->c_lnL; + if((tree->mod->s_opt->opt_bl || tree->mod->s_opt->constrained_br_len) && + (tree->verbose > VL2) && + (tree->io->quiet == NO)) Print_Lk(tree,"[Branch lengths ]"); - tree->mod->s_opt->tree_size_mult = fabs(u); - MC_Mult_Time_Stamps(tree); - tree->both_sides = 1; - fu=-Return_Lk(tree); - MC_Div_Time_Stamps(tree); + if(!each) + { + each = freq; + Optimiz_All_Free_Param(tree,(tree->io->quiet)?(0):(tree->verbose > VL2)); + } -/* printf("\n. BRENT mult=%f lnL=%20f", */ -/* tree->mod->s_opt->tree_size_mult, */ -/* tree->c_lnL); */ + lk_new = tree->c_lnL; + + if(lk_new < lk_old - tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Fprintf(stderr,"\n. lk_new = %f lk_old = %f diff = %f",lk_new,lk_old,lk_new-lk_old); + assert(FALSE); + } + + if((fabs(lk_new - lk_old) < tree->mod->s_opt->min_diff_lk_local) && (each == freq)) break; + /* if(fabs(lk_new - lk_old) < tree->mod->s_opt->min_diff_lk_local) break; */ + lk_old = lk_new; - if(fu <= fx) - { - if(u >= x) a=x; else b=x; - SHFT(v,w,x,u) - SHFT(fv,fw,fx,fu) - } - else - { - if (u < x) a=u; else b=u; - if (fu <= fw || w == x) - { - v=w; - w=u; - fv=fw; - fw=fu; - } - else if (fu <= fv || v == x || v == w) - { - v=u; - fv=fu; - } - } + n_round++; + each--; } - tree->mod->s_opt->tree_size_mult = 1.0; - if(iter > BRENT_ITMAX) printf("\n. Too many iterations in BRENT (%d)",iter); - return(-1); - /* Not Reached ?? *xmin=x; */ - /* Not Reached ?? return fx; */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Branch_Rate_Shape_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, arbre *tree, int n_iter_max) +void Optimize_Br_Len_Serie(int n_max_iter, t_tree *tree) { + phydbl lk_init,lk_end; int iter; - phydbl a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; - phydbl e=0.0; - phydbl old_fu,init_fu; - phydbl best_fu, best_x; - - d=0.0; - a=((ax < cx) ? ax : cx); - b=((ax > cx) ? ax : cx); - x=w=v=bx; - old_fu = UNLIKELY; - (*xmin) = fabs(bx); - fw=fv=fx=-Lk_With_MAP_Branch_Rates(tree); - init_fu = fw; - best_fu = fw; - fu = fw; - best_x = fabs(bx);; - printf("init_lnL = %f\n",fw); + /* if(tree->n_tot_bl_opt == 0) */ + /* { */ + /* for(int i=0;i<2*tree->n_otu-3;++i) Set_Scalar_Dbl(1.E-6,tree->a_edges[i]->l); */ + /* for(int i=0;i<2*tree->n_otu-3;++i) Set_Scalar_Dbl_Min_Thresh(tree->mod->l_min,tree->a_edges[i]->l); */ + /* for(int i=0;i<2*tree->n_otu-3;++i) Set_Scalar_Dbl_Max_Thresh(tree->mod->l_max,tree->a_edges[i]->l); */ + /* } */ - for(iter=1;iter<=BRENT_ITMAX;iter++) + + + Set_Both_Sides(NO,tree); + Lk(NULL,tree); + + lk_init = tree->c_lnL; + + if(tree->mod->gamma_mgf_bl == YES) { - xm=0.5*(a+b); - tol2=2.0*(tol1=tol*fabs(x)+BRENT_ZEPS); - if( - ((fabs(fu-old_fu) < tol) && (fu < init_fu-tol)) || (iter > n_iter_max - 1)) - { - (*xmin) = best_x; - printf("\n> iter=%d/%d param val=%f fu=%f (best_fu=%f best_x=%f old_fu=%f)",iter,BRENT_ITMAX,*xmin,fu,best_fu,best_x,old_fu); - return Lk_With_MAP_Branch_Rates(tree); - } - - if(fabs(e) > tol1) - { - r=(x-w)*(fx-fv); - q=(x-v)*(fx-fw); - p=(x-v)*q-(x-w)*r; - q=2.0*(q-r); - if(q > 0.0) p = -p; - q=fabs(q); - etemp=e; - e=d; - if(fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - /* printf("Golden section step\n"); */ - } - else - { - d=p/q; - u=x+d; - if (u-a < tol2 || b-u < tol2) - d=SIGN(tol1,xm-x); - /* printf("Parabolic step\n"); */ - } + Generic_Brent_Lk(&(tree->mod->l_var_sigma), + tree->mod->l_var_min, + tree->mod->l_var_max, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + + if(tree->c_lnL < lk_init - tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Printf("\n. %f -- %f",lk_init,tree->c_lnL); + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + } + + if((tree->io->quiet)?(0):(tree->verbose > VL2)) + { + Print_Lk(tree,"[Branch len. var. ]"); + PhyML_Printf("[%10f]",tree->mod->l_var_sigma); + } + } + + iter = 0; + do + { + lk_init = tree->c_lnL; + if(tree->n_root && tree->ignore_root == NO) + { + Update_Partial_Lk(tree,tree->n_root->b[1],tree->n_root); + Optimize_Br_Len_Serie_Post(tree->n_root,tree->n_root->v[1],tree->n_root->b[1],tree); + Update_Partial_Lk(tree,tree->n_root->b[2],tree->n_root); + Optimize_Br_Len_Serie_Post(tree->n_root,tree->n_root->v[2],tree->n_root->b[2],tree); + } + else if(tree->n_root && tree->ignore_root == YES) + { + Optimize_Br_Len_Serie_Post(tree->e_root->rght, + tree->e_root->left, + tree->e_root,tree); + + Optimize_Br_Len_Serie_Post(tree->e_root->left, + tree->e_root->rght, + tree->e_root,tree); } else - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - /* printf("Golden section step (default)\n"); */ - } + { + Optimize_Br_Len_Serie_Post(tree->a_nodes[tree->tip_root], + tree->a_nodes[tree->tip_root]->v[0], + tree->a_nodes[tree->tip_root]->b[0], + tree); + } - u=(fabs(d) >= tol1 ? x+d : x+SIGN(tol1,d)); - (*xmin) = fabs(u); - old_fu = fu; - fu = -Lk_With_MAP_Branch_Rates(tree); + lk_end = tree->c_lnL; - if(fu < best_fu) - { - best_fu = fu; - best_x = fabs(u); - } - - printf("\n. iter=%d/%d param val=%f fu=%f (best_fu=%f best_x=%f old_fu=%f)",iter,BRENT_ITMAX,*xmin,fu,best_fu,best_x,old_fu); - - if(fu <= fx) - { - if(u >= x) a=x; else b=x; - SHFT(v,w,x,u) - SHFT(fv,fw,fx,fu) - } - else - { - if (u < x) a=u; else b=u; - if (fu <= fw || w == x) - { - v=w; - w=u; - fv=fw; - fw=fu; - } - else if (fu <= fv || v == x || v == w) - { - v=u; - fv=fu; - } - } - } - - Exit("\n. Too many iterations in BRENT !"); - return(-1); - /* Not Reached ?? *xmin=x; */ - /* Not Reached ?? return fx; */ -} - -/*********************************************************/ + if(lk_end < lk_init - tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Fprintf(stderr,"\n. lk_init: %f lk_end: %f",lk_init,lk_end); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } -int Dist_Seq_Brak(phydbl *ax, phydbl *bx, phydbl *cx, - phydbl *fa, phydbl *fb, phydbl *fc, - allseq *data, int numseq1, int numseq2, - model *mod) -{ - phydbl ulim,u,r,q,fu,dum; - phydbl dist; - phydbl lk; + iter++; - dist = *ax; - *fa=-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk); - dist = *bx; - *fb=-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk); - if (*fb > *fa) { - SHFT(dum,*ax,*bx,dum) - SHFT(dum,*fb,*fa,dum) - } - *cx=(*bx)+MNBRAK_GOLD*(*bx-*ax); - dist = fabs(*cx); - *fc=-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk); - while (*fb > *fc) - { - r=(*bx-*ax)*(*fb-*fc); - q=(*bx-*cx)*(*fb-*fa); - u=(*bx)-((*bx-*cx)*q-(*bx-*ax)*r)/ - (2.0*SIGN(MAX(fabs(q-r),MNBRAK_TINY),q-r)); - ulim=(*bx)+MNBRAK_GLIMIT*(*cx-*bx); - - if ((*bx-u)*(u-*cx) > 0.0) - { - dist = fabs(u); - fu=-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk); - if (fu < *fc) - { - *ax=(*bx); - *bx=u; - *fa=(*fb); - *fb=fu; - return(0); - } - else if (fu > *fb) - { - *cx=u; - *fc=fu; - return(0); - } - u=(*cx)+MNBRAK_GOLD*(*cx-*bx); - dist = fabs(u); - fu=-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk); - } - else if ((*cx-u)*(u-ulim) > 0.0) - { - dist = fabs(u); - fu=-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk); - if (fu < *fc) - { - SHFT(*bx,*cx,u,*cx+MNBRAK_GOLD*(*cx-*bx)) - dist = fabs(u); - SHFT(*fb,*fc,fu,-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk)) - } - } - else if ((u-ulim)*(ulim-*cx) >= 0.0) - { - u=ulim; - dist = fabs(u); - fu=-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk); - } - else - { - u=(*cx)+MNBRAK_GOLD*(*cx-*bx); - dist = fabs(u); - fu=-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk); - } - SHFT(*ax,*bx,*cx,u) - SHFT(*fa,*fb,*fc,fu) - } - return(0); -} -/*********************************************************/ + /* PhyML_Printf("\n. lnL: %f %f %f %d",tree->c_lnL,Rgamma((phydbl)(iter+1),(phydbl)(1./(iter+1))),(phydbl)(iter+1)*(phydbl)(1./(iter+1))*(phydbl)(1./(iter+1)),iter); */ -phydbl Dist_Seq_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, allseq *data, - int numseq1, int numseq2, model *mod) -{ - int iter; - phydbl a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; - phydbl e=0.0; - phydbl dist; - phydbl lk; - - d=0.0; - a=((ax < cx) ? ax : cx); - b=((ax > cx) ? ax : cx); - x=w=v=bx; - dist = fabs(bx); - fw=fv=fx=-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk); - for(iter=1;iter<=BRENT_ITMAX;iter++) - { - xm=0.5*(a+b); - tol2=2.0*(tol1=tol*fabs(x)+BRENT_ZEPS); - if(fabs(x-xm) <= (tol2-0.5*(b-a))) - { - *xmin=x; - return -fx; - } - - if(fabs(e) > tol1) - { - r=(x-w)*(fx-fv); - q=(x-v)*(fx-fw); - p=(x-v)*q-(x-w)*r; - q=2.0*(q-r); - if(q > 0.0) p = -p; - q=fabs(q); - etemp=e; - e=d; - if(fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - else{ - d=p/q; - u=x+d; - if (u-a < tol2 || b-u < tol2) - d=SIGN(tol1,xm-x); - } - } else - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - } - u=(fabs(d) >= tol1 ? x+d : x+SIGN(tol1,d)); - dist=fabs(u); - fu=-Lk_Given_Two_Seq(data,numseq1,numseq2,dist,mod,&lk); - if(fu <= fx) { - if(u >= x) a=x; else b=x; - SHFT(v,w,x,u) - SHFT(fv,fw,fx,fu) - } - else - { - if (u < x) a=u; else b=u; - if (fu <= fw || w == x) - { - v=w; - w=u; - fv=fw; - fw=fu; - } - else if (fu <= fv || v == x || v == w) { - v=u; - fv=fu; - } - } } - printf("\n . BRENT method failed, trying Newton-Raphson"); - return(+1.0); - /* Not Reached ?? *xmin=x; */ - /* Not Reached ?? return fx; */ + /* while(lk_end - lk_init > tree->mod->s_opt->min_diff_lk_local && iter < n_max_iter); */ + while(iter < 1); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -phydbl Optimize_Dist(model *mod, phydbl init, allseq *twoseqs) +void Optimize_Br_Len_Multiplier(t_tree *mixt_tree, int verbose) { - phydbl d_infa,d_max,d_infb; - phydbl lk_infa, lk_max, lk_infb, lk; - - d_infa = 100.*BL_MIN; - d_max = init; - d_infb = 3.*init; - if(init <= BL_MIN) {d_infa = -BL_START; d_max = .0; d_infb = BL_START;} - lk_infa = lk_max = lk_infb = .0; + phydbl lk_init; + t_tree *tree; - Dist_Seq_Brak(&d_infa, &d_max, &d_infb, - &lk_infa,&lk_max,&lk_infb, - twoseqs,0,1,mod); - lk = (phydbl) Dist_Seq_Brent(d_infa,d_max,d_infb, - 1.e-5,&d_max,twoseqs,0,1,mod); - if(lk > .0) return -1.0; - else return d_max; + tree = mixt_tree; + + do + { + if(tree->mod->s_opt->opt_br_len_mult == YES) + { + lk_init = Get_Lk(tree); + /* Generic_Brent_Lk(&(tree->mod->br_len_mult_unscaled->v), */ + Generic_Brent_Lk(&(tree->mod->br_len_mult->v), + 1.E-2,1.E+1, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + + if(Get_Lk(tree) < lk_init - tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Fprintf(stderr,"\n. %f -- %f",lk_init,tree->c_lnL); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + tree = tree->next_mixt; + } + while(tree); + + tree = mixt_tree; + do + { + if(verbose && tree->mod->s_opt->opt_br_len_mult == YES) + { + Print_Lk(tree,"[Tree scale ]"); + PhyML_Printf("[%10f]",tree->mod->br_len_mult->v); + } + tree = tree->next_mixt; + } + while(tree); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Round_Optimize(arbre *tree, allseq *data) +void Optimize_Br_Len_Serie_Post(t_node *a, t_node *d, t_edge *b_fcus, t_tree *tree) { - int n_round,each; - phydbl lk_old, lk_new, tol; - node *root; + int i; + phydbl lk_init; - lk_new = tree->c_lnL; - lk_old = UNLIKELY; - n_round = 0; - each = 1; - tol = 1.e-2; - root = tree->noeud[0]; - tree->both_sides = 1; - Lk(tree); - - while(n_round < ROUND_MAX) + lk_init = tree->c_lnL; + + if(tree->mod->s_opt->constrained_br_len == YES) { + Generic_Brent_Lk(&(tree->mod->br_len_mult->v), + 1.E-2,1.E+1, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + + if(tree->c_lnL < lk_init - tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Fprintf(stderr,"\n. %f -- %f",lk_init,tree->c_lnL); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } - (!((n_round+2)%2))?(root=tree->noeud[0]):(root=tree->noeud[tree->n_otu-1]); - - if(tree->mod->s_opt->opt_bl) Optimize_Br_Len_Serie(root,root->v[0],root->b[0],tree,data); - - tree->both_sides = 1; - Lk(tree); - - if(tree->mod->s_opt->print) Print_Lk(tree,"[Branch lengths ]"); - - if(!each) - { - each = 1; - Optimiz_All_Free_Param(tree,tree->mod->s_opt->print); - tree->both_sides = 1; - Lk(tree); - } - - lk_new = tree->c_lnL; - if(lk_new < lk_old - tree->mod->s_opt->min_diff_lk_global) Exit("\n. Optimisation failed ! (Round_Optimize)\n"); - if(fabs(lk_new - lk_old) < tree->mod->s_opt->min_diff_lk_global) break; -/* if(fabs(lk_new - lk_old) < tree->mod->s_opt->min_diff_lk_local) break; */ - else lk_old = lk_new; - n_round++; - each--; + return; } - - Optimiz_All_Free_Param(tree,tree->mod->s_opt->print); -} - -/*********************************************************/ - -void Optimize_Br_Len_Serie(node *a, node *d, edge *b_fcus, arbre *tree, allseq *alldata) -{ - int i; - phydbl l_infa,l_max,l_infb; - phydbl lk_init; - - - lk_init = tree->c_lnL; - - l_infa = l_max = l_infb = BL_MIN; - - l_infa = 10.*b_fcus->l; - l_max = b_fcus->l; - l_infb = BL_MIN; - -/* Br_Len_Brent(l_infa,l_max,l_infb, */ -/* 1.e-3, */ -/* &(b_fcus->l), */ -/* b_fcus,tree,500); */ - Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus,tree, - tree->mod->s_opt->brent_it_max); + if(tree->io->mod->s_opt->opt_bl == YES) Br_Len_Opt(&(b_fcus->l->v),b_fcus,tree); if(tree->c_lnL < lk_init - tree->mod->s_opt->min_diff_lk_local) { - printf("\n. %f %f %f %f",l_infa,l_max,l_infb,b_fcus->l); - printf("\n. %f -- %f",lk_init,tree->c_lnL); - Warn_And_Exit("\n. Err. in Optimize_Br_Len_Serie\n"); + PhyML_Fprintf(stderr,"\n. %f -- %f",lk_init,tree->c_lnL); + PhyML_Fprintf(stderr,"\n. Edge: %d",b_fcus->num); + PhyML_Fprintf(stderr,"\n. is_mixt_tree: %d",tree->is_mixt_tree); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); } - + if(d->tax) return; - else For(i,3) if(d->v[i] != a) + + if(tree->n_root && tree->ignore_root == NO) + { + for(i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + Update_Partial_Lk(tree,d->b[i],d); + Optimize_Br_Len_Serie_Post(d,d->v[i],d->b[i],tree); + } + } + + for(i=0;i<3;++i) + if(d->v[i] == a || d->b[i] == tree->e_root) + { + Update_Partial_Lk(tree,d->b[i],d); + if(tree->io->mod->s_opt->opt_bl == YES) Br_Len_Opt(&(d->b[i]->l->v),d->b[i],tree); + } + } + else { - Update_P_Lk(tree,d->b[i],d); - Optimize_Br_Len_Serie(d,d->v[i],d->b[i],tree,alldata); + // Ok if root exists but requires traversal to be initiated from a node != root + for(i=0;i<3;++i) + { + if(d->v[i] != a) + { + Update_Partial_Lk(tree,d->b[i],d); + Optimize_Br_Len_Serie_Post(d,d->v[i],d->b[i],tree); + } + } + Update_Partial_Lk(tree,b_fcus,d); + if(tree->io->mod->s_opt->opt_bl == YES) Br_Len_Opt(&(b_fcus->l->v),b_fcus,tree); } - For(i,3) if((d->v[i] == a) && !(d->v[i]->tax)) Update_P_Lk(tree,d->b[i],d); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Optimiz_Ext_Br(arbre *tree) +void Optimiz_Ext_Br(t_tree *tree) { int i; - edge *b; - phydbl l_infa,l_max,l_infb; - phydbl lk, lk_init,l_init; - + t_edge *b; + phydbl lk_init; + scalar_dbl *l_init,*v_init; + lk_init = tree->c_lnL; - For(i,2*tree->n_otu-3) { - b = tree->t_edges[i]; + b = tree->a_edges[i]; if((b->left->tax) || (b->rght->tax)) - { - - l_init = b->l; - -/* Fast_Br_Len(b,tree); */ -/* lk = Lk_At_Given_Edge(tree,b); */ - - l_infa = 10.*b->l; - l_max = b->l; - l_infb = BL_MIN; - - lk = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b,tree, - tree->mod->s_opt->brent_it_max); - - b->nni->best_l = b->l; - b->nni->l0 = b->l; - b->nni->best_conf = 0; - b->l = l_init; - - } + { + + l_init = Duplicate_Scalar_Dbl(b->l); + v_init = Duplicate_Scalar_Dbl(b->l_var); + + Br_Len_Opt(&(b->l->v),b,tree); + + if(b->nni->best_l == NULL) + { + b->nni->best_l = Duplicate_Scalar_Dbl(b->l); + b->nni->best_v = Duplicate_Scalar_Dbl(b->l_var); + } + else + { + Copy_Scalar_Dbl(b->l,b->nni->best_l); + Copy_Scalar_Dbl(b->l_var,b->nni->best_v); + } + + if(b->nni->l0 == NULL) + { + b->nni->l0 = Duplicate_Scalar_Dbl(b->l); + b->nni->v0 = Duplicate_Scalar_Dbl(b->l_var); + } + else + { + Copy_Scalar_Dbl(b->l,b->nni->l0); + Copy_Scalar_Dbl(b->l_var,b->nni->v0); + } + + // Revert of original edge lengths + Copy_Scalar_Dbl(l_init,b->l); + Copy_Scalar_Dbl(v_init,b->l_var); + + Free_Scalar_Dbl(l_init); + Free_Scalar_Dbl(v_init); + + /* ori = b; */ + /* do */ + /* { */ + /* b->nni->best_l->v = b->l->v; */ + /* b->nni->l0->v = b->l->v; */ + /* b->nni->best_conf = 0; */ + /* b->l->v = l_init; */ + /* b = b->next; */ + /* } */ + /* while(b); */ + /* b = ori; */ + } } - tree->c_lnL = lk_init; + tree->c_lnL = lk_init; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Optimiz_All_Free_Param(arbre *tree, int verbose) +void Optimiz_All_Free_Param(t_tree *tree, int verbose) { int init_both_sides; + + if(!tree) return; + + if(tree->mixt_tree && tree->mod->ras->invar == YES) return; init_both_sides = tree->both_sides; - tree->both_sides = 0; - if((tree->mod->whichmodel == GTR) || - ((tree->mod->whichmodel == CUSTOM) && (tree->mod->s_opt->opt_rr) && (tree->mod->n_diff_rr > 1))) - { - int failed; - - failed = 0; - - tree->mod->update_eigen = 1; - BFGS(tree,tree->mod->rr_val,tree->mod->n_diff_rr,1.e-5,1.e-7, - &Return_Abs_Lk, - &Num_Derivative_Several_Param, - &Lnsrch_RR_Param,&failed); - - if(failed) - { - int i; - -/* if(verbose) printf("\n. Optimising one-by-one...\n"); */ - For(i,tree->mod->n_diff_rr) - if(i != 5) - { - Optimize_Single_Param_Generic(tree,&(tree->mod->rr_val[i]), - 1.E-20,1.E+10, - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - } - } - if(verbose) Print_Lk(tree,"[GTR parameters ]"); - tree->mod->update_eigen = 0; - } - - if(tree->mod->s_opt->opt_kappa) - { - tree->mod->update_eigen = 1; - Optimize_Single_Param_Generic(tree,&(tree->mod->kappa), - .1,100., - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - if(verbose) - { - Print_Lk(tree,"[Ts/ts ratio ]"); - printf("[%10f]",tree->mod->kappa); - } - tree->mod->update_eigen = 0; - } - - if(tree->mod->s_opt->opt_lambda) - { - Optimize_Single_Param_Generic(tree,&(tree->mod->lambda),.001,100., - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - if(verbose) - { - Print_Lk(tree,"[Lambda ]"); - printf("[%10f]",tree->mod->lambda); - } - } - - if((tree->mod->s_opt->opt_pinvar) && (tree->mod->s_opt->opt_alpha)) - { - Optimiz_Alpha_And_Pinv(tree); - if(verbose) - { - Print_Lk(tree,"[Alpha ]"); - printf("[%10f]",tree->mod->alpha); - Print_Lk(tree,"[P-inv ]"); - printf("[%10f]",tree->mod->pinvar); - } - } - else - { - if(tree->mod->s_opt->opt_pinvar) - { - Optimize_Single_Param_Generic(tree,&(tree->mod->pinvar), - .0001,0.9999, - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - if(verbose) - { - Print_Lk(tree,"[P-inv ]"); - printf("[%10f]",tree->mod->pinvar); - } - } - - if(tree->mod->s_opt->opt_alpha) - { - Optimize_Single_Param_Generic(tree,&(tree->mod->alpha), - .01,100., - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - if(verbose) - { - Print_Lk(tree,"[Alpha ]"); - printf("[%10f]",tree->mod->alpha); - } - } - } - if((tree->mod->s_opt->opt_state_freq) && (tree->mod->datatype == NT)) - { - int failed,i; - - failed = 0; - tree->mod->update_eigen = 1; - BFGS(tree,tree->mod->pi,4,1.e-5,1.e-7,&Return_Abs_Lk,&Num_Derivative_Several_Param,&Lnsrch_Nucleotide_Frequencies,&failed); - - if(failed) - { - For(i,4) - Optimize_Single_Param_Generic(tree,&(tree->mod->pi_unscaled[i]), - -1000.,1000., - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - } - if(verbose) Print_Lk(tree,"[Nucleotide freqs. ]"); - tree->mod->update_eigen = 0; - } + Set_Both_Sides(NO,tree); + Lk(NULL,tree); + + Optimize_RR_Params(tree,verbose); + Optimize_TsTv(tree,verbose); + Optimize_Lambda(tree,verbose); + Optimiz_Alpha_And_Pinv(tree,verbose); + Optimize_Pinv(tree,verbose); + Optimize_Alpha(tree,verbose); + Optimize_State_Freqs(tree,verbose); + Optimize_Rmat_Weights(tree,verbose); + Optimize_Efrq_Weights(tree,verbose); + Optimize_Free_Rate(tree,verbose); + Optimize_Br_Len_Multiplier(tree,verbose); + + if(tree->io->print_json_trace == YES) JSON_Tree_Io(tree,tree->io->fp_out_json_trace); if(tree->mod->use_m4mod) { - int failed,i; - - if(tree->mod->s_opt->opt_cov_delta) - { - tree->mod->update_eigen = 1; - Optimize_Single_Param_Generic(tree,&(tree->mod->m4mod->delta), - 0.01,10., - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - if(verbose) - { - Print_Lk(tree,"[Switching param. ]"); - printf("[%10f]",tree->mod->m4mod->delta); - } - tree->mod->update_eigen = 0; - } + int i; + + if(tree->mod->s_opt->opt_cov_delta) + { + Set_Update_Eigen(YES,tree->mod); + + Generic_Brent_Lk(&(tree->mod->m4mod->delta), + 0.01,10., + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + + if(verbose) + { + Print_Lk(tree,"[Switching param. ]"); + PhyML_Printf("[%10f]",tree->mod->m4mod->delta); + } + + Set_Update_Eigen(NO,tree->mod); + + } + - if(tree->mod->s_opt->opt_cov_free_rates) - { - int rcat; - - tree->mod->update_eigen = 1; - For(rcat,tree->mod->m4mod->n_h) - { - Optimize_Single_Param_Generic(tree,&(tree->mod->m4mod->multipl_unscaled[rcat]), - .01,10., - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - - if(verbose) - { - Print_Lk(tree,"[Rel. subst. rate ]"); - printf("[%10f]",tree->mod->m4mod->multipl[rcat]); - } - } - - For(rcat,tree->mod->m4mod->n_h) - { - Optimize_Single_Param_Generic(tree,&(tree->mod->m4mod->h_fq_unscaled[rcat]), - .01,100., - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - - if(verbose) - { - Print_Lk(tree,"[Subst. class freq ]"); - printf("[%10f]",tree->mod->m4mod->h_fq[rcat]); - } - } - tree->mod->update_eigen = 0; - } + if(tree->mod->s_opt->opt_cov_free_rates) + { + int rcat; + + Set_Update_Eigen(YES,tree->mod); + + for(rcat=0;rcatmod->m4mod->n_h;rcat++) + { + /* Optimize_Single_Param_Generic(tree,&(tree->mod->m4mod->multipl_unscaled[rcat]), */ + /* .01,10., */ + /* tree->mod->s_opt->min_diff_lk_local, */ + /* tree->mod->s_opt->brent_it_max, */ + /* tree->mod->s_opt->quickdirty); */ + + Generic_Brent_Lk(&(tree->mod->m4mod->multipl_unscaled[rcat]), + 0.1,100., + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + + if(verbose) + { + Print_Lk(tree,"[Rel. subst. rate ]"); + PhyML_Printf("[%10f]",tree->mod->m4mod->multipl[rcat]); + } + } + + for(rcat=0;rcatmod->m4mod->n_h;rcat++) + { + + /* Optimize_Single_Param_Generic(tree,&(tree->mod->m4mod->h_fq_unscaled[rcat]), */ + /* .01,100., */ + /* tree->mod->s_opt->min_diff_lk_local, */ + /* tree->mod->s_opt->brent_it_max, */ + /* tree->mod->s_opt->quickdirty); */ + + Generic_Brent_Lk(&(tree->mod->m4mod->h_fq_unscaled[rcat]), + 0.1,100., + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + + + if(verbose) + { + Print_Lk(tree,"[Subst. class freq ]"); + PhyML_Printf("[%10f]",tree->mod->m4mod->h_fq[rcat]); + } + } + + Set_Update_Eigen(NO,tree->mod); + + } - if(tree->mod->s_opt->opt_cov_alpha) - { - tree->mod->update_eigen = 1; - Optimize_Single_Param_Generic(tree,&(tree->mod->m4mod->alpha), - .01,10., - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - if(verbose) - { - Print_Lk(tree,"[Alpha (covarion) ]"); - printf("[%10f]",tree->mod->m4mod->alpha); - } - tree->mod->update_eigen = 0; - } + if(tree->mod->s_opt->opt_cov_alpha) + { + + Set_Update_Eigen(YES,tree->mod); + + /* Optimize_Single_Param_Generic(tree,&(tree->mod->m4mod->ras->alpha), */ + /* .01,10., */ + /* tree->mod->s_opt->min_diff_lk_local, */ + /* tree->mod->s_opt->brent_it_max, */ + /* tree->mod->s_opt->quickdirty); */ + + Generic_Brent_Lk(&(tree->mod->m4mod->alpha), + 0.01,10., + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + + + if(verbose) + { + Print_Lk(tree,"[Alpha (covarion) ]"); + PhyML_Printf("[%10f]",tree->mod->m4mod->alpha); + } + + Set_Update_Eigen(NO,tree->mod); + + } - - /* Substitutions between nucleotides are considered to follow a - GTR model */ - failed = 0; - tree->mod->update_eigen = 1; - BFGS(tree,tree->mod->m4mod->o_rr,5,1.e-5,1.e-7, - &Return_Abs_Lk, - &Num_Derivative_Several_Param, - &Lnsrch_RR_Cov_Param,&failed); + /* Substitutions between nucleotides are considered to follow a + GTR model */ - if(failed) - { - For(i,5) - { - Optimize_Single_Param_Generic(tree,&(tree->mod->m4mod->o_rr[i]), - 1.E-20,1.E+10, - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - } - } - if(verbose) Print_Lk(tree,"[GTR parameters ]"); - tree->mod->update_eigen = 0; + if(tree->mod->io->datatype == NT) + { + if(tree->mod->whichmodel == GTR || tree->mod->whichmodel == CUSTOM) + { + Set_Update_Eigen(YES,tree->mod); + + int *permut = Permutate(tree->mod->r_mat->n_diff_rr); + + for(i=0;i<5;i++) + if(permut[i] != 5) + { + Generic_Brent_Lk(&(tree->mod->m4mod->o_rr[permut[i]]), + 1.E-4,1.E+4, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + + } + + Free(permut); + + if(verbose) Print_Lk(tree,"[GTR parameters ]"); + + Set_Update_Eigen(NO,tree->mod); + } + } } + + Set_Both_Sides(init_both_sides,tree); + + if(tree->both_sides == YES) Lk(NULL,tree); /* Needed to update all partial likelihoods */ - tree->both_sides = init_both_sides; -} + /* if(tree->next) Optimiz_All_Free_Param(tree->next,verbose); */ + /* else Optimiz_All_Free_Param(tree->next,verbose); */ + + /* if(tree->nextree) Optimiz_All_Free_Param(tree->nextree,verbose); */ +} #define ITMAX 200 #define EPS 3.0e-8 #define TOLX (4*EPS) #define STPMX 100.0 -static double sqrarg; -#define SQR(a) ((sqrarg=(a)) == 0.0 ? 0.0 : sqrarg*sqrarg) - -void BFGS(arbre *tree, phydbl *p, int n, phydbl gtol, phydbl step_size, - phydbl(*func)(), void (*dfunc)(), void (*lnsrch)(),int *failed) +static phydbl sqrarg; +#define SQR(a) ((sqrarg=(a)) < SMALL ? 0.0 : sqrarg*sqrarg) + +void BFGS(t_tree *tree, + phydbl *p, + int n, + phydbl gtol, + phydbl difff, + phydbl step_size, + int logt, + int is_positive, + phydbl(*func)(t_tree *tree), + int(*dfunc)(t_tree *tree,phydbl *param,int n_param,phydbl stepsize,int logt, phydbl(*func)(t_tree *tree),phydbl *derivatives, int is_positive), + int(*lnsrch)(t_tree *tree, int n, phydbl *xold, phydbl fold, phydbl *g, phydbl *p, phydbl *x,phydbl *f, phydbl stpmax, int *check, int logt, int is_positive), + int *failed) { - + int check,i,its,j; phydbl den,fac,fad,fae,fp,stpmax,sum=0.0,sumdg,sumxi,temp,test,fret; phydbl *dg,*g,*hdg,**hessin,*pnew,*xi; - + phydbl fp_old; + phydbl *init; + hessin = (phydbl **)mCalloc(n,sizeof(phydbl *)); - For(i,n) hessin[i] = (phydbl *)mCalloc(n,sizeof(phydbl)); + for(i=0;i %f\n",tree->c_lnL); */ + + lnsrch(tree,n,p,fp,g,xi,pnew,&fret,stpmax,&check,logt,is_positive); + + /* PhyML_Printf("\n. BFGS: %f stpmax: %f fret: %g\n",tree->c_lnL,stpmax,fret); */ + fp_old = fp; fp = fret; - for (i=0;i test) test=temp; - } - if (test < TOLX) - { - (*func)(tree); - For(i,n) Free(hessin[i]); - free(hessin); - free(xi); - free(pnew); - free(hdg); - free(g); - free(dg); - - if(its == 1) - { -/* printf("\n. WARNING : BFGS failed ! \n"); */ - *failed = 1; - } - return; - } - + for (i=0;i test) test=temp; + } + + if (test < TOLX || (fabs(fp-fp_old) < difff && its > 1)) + { + if(fp > fp_old) + { + for(i=0;i test) test=temp; - } - if (test < gtol) - { - (*func)(tree); - For(i,n) Free(hessin[i]); - free(hessin); - free(xi); - free(pnew); - free(hdg); - free(g); - free(dg); - return; - } + for (i=0;i test) test=temp; + } + if (test < gtol) + { + *failed = NO; + if(logt == YES) for(i=0;i EPS*sumdg*sumxi) + if(fac*fac > EPS*sumdg*sumxi) { - fac=1.0/fac; - fad=1.0/fae; - for (i=0;i stpmax) - for(i=0;i test) test=temp; + for (j=0;jmod->rr_val[i] = fabs(local_xold[i]+alam*p[i]); - } - /**/ - - if(i==n) - { - *f=Return_Abs_Lk(tree); -/* printf("loglk = %f\n",*f); */ - } - else *f=1.+fold+ALF*alam*slope; - if (alam < alamin) - { - for (i=0;imod->rr_val[i] = fabs(local_xold[i]); - } - /**/ - - *check=1; - For(i,n) xold[i] = local_xold[i]; - Free(local_xold); - return; - } - else if (*f <= fold+ALF*alam*slope) - { - For(i,n) xold[i] = local_xold[i]; - Free(local_xold); - return; - } - else - { - if (alam == 1.0) - tmplam = -slope/(2.0*(*f-fold-slope)); - else - { - rhs1 = *f-fold-alam*slope; - rhs2=f2-fold2-alam2*slope; - a=(rhs1/(alam*alam)-rhs2/(alam2*alam2))/(alam-alam2); - b=(-alam2*rhs1/(alam*alam)+alam*rhs2/(alam2*alam2))/(alam-alam2); - if (a == 0.0) tmplam = -slope/(2.0*b); - else - { - disc=b*b-3.0*a*slope; - if (disc<0.0) tmplam = 0.5*alam; - else if(b <= 0.0) tmplam=(-b+sqrt(disc))/(3.0*a); - else tmplam = -slope/(b+sqrt(disc)); - } - if (tmplam>0.5*alam) tmplam=0.5*alam; - } - } - alam2=alam; - f2 = *f; - fold2=fold; - alam=MAX(tmplam,0.1*alam); + /* PhyML_Printf("\n. BFGS -> %f\n",tree->c_lnL); */ + + fp_old = fp; + fp = fret; + + for (i=0;i test) test=temp; + } + + if (test < TOLX || (FABS(fp_old-fp) < difff && its > 1)) + { + + if(fp > fp_old) + { + for(i=0;i .0 ? 1. : -1.; + if(is_positive == YES) for(i=0;i test) test=temp; + } + + if (test < gtol) + { + if(logt == YES) for(i=0;i .0 ? 1. : -1.; + if(is_positive == YES) for(i=0;i EPS*sumdg*sumxi) + { + fac=1.0/fac; + fad=1.0/fae; + for (i=0;i stpmax) - for(i=0;i stpmax) for(i=0;i test) test=temp; } alamin=TOLX/test; alam=1.0; - for (;;) + for (;;) { - for(i=0;imod->m4mod->o_rr[i] = fabs(local_xold[i]+alam*p[i]); - } - /**/ - - if(i==n) - { - *f=Return_Abs_Lk(tree); -/* printf("loglk = %f\n",*f); */ - } + { + x[i]=local_xold[i]+alam*p[i]; + xold[i] = x[i]; + /* PhyML_Printf("\n. lnsrch x[i]: %f",x[i]); */ + } + + /* PhyML_Printf("\n. lnsrch loop slope: %f alam: %f alam2: %f",slope,alam,alam2); */ + + if(i==n) + { + if(logt == YES) for(i=0;i> %f",xold[i]); */ + *f=Return_Abs_Lk(tree); + if(is_positive == YES) for(i=0;imod->m4mod->o_rr[i] = fabs(local_xold[i]); - } - /**/ - - *check=1; - For(i,n) xold[i] = local_xold[i]; - Free(local_xold); - return; - } - else if (*f <= fold+ALF*alam*slope) - { - For(i,n) xold[i] = local_xold[i]; - Free(local_xold); - return; - } - else - { - if (alam == 1.0) - tmplam = -slope/(2.0*(*f-fold-slope)); - else - { - rhs1 = *f-fold-alam*slope; - rhs2=f2-fold2-alam2*slope; - a=(rhs1/(alam*alam)-rhs2/(alam2*alam2))/(alam-alam2); - b=(-alam2*rhs1/(alam*alam)+alam*rhs2/(alam2*alam2))/(alam-alam2); - if (a == 0.0) tmplam = -slope/(2.0*b); - else - { - disc=b*b-3.0*a*slope; - if (disc<0.0) tmplam = 0.5*alam; - else if(b <= 0.0) tmplam=(-b+sqrt(disc))/(3.0*a); - else tmplam = -slope/(b+sqrt(disc)); - } - if (tmplam>0.5*alam) tmplam=0.5*alam; - } - } + { + *check=1; + for(i=0;i 1.0-SMALL)) + tmplam = -slope/(2.0*(*f-fold-slope)); + else + { + rhs1 = *f-fold-alam*slope; + rhs2=f2-fold2-alam2*slope; + a=(rhs1/(alam*alam)-rhs2/(alam2*alam2))/(alam-alam2); + b=(-alam2*rhs1/(alam*alam)+alam*rhs2/(alam2*alam2))/(alam-alam2); + if (a < SMALL && a > -SMALL) tmplam = -slope/(2.0*b); + else + { + disc=b*b-3.0*a*slope; + if (disc<0.0) tmplam = 0.5*alam; + else if(b <= 0.0) tmplam=(-b+SQRT(disc))/(3.0*a); + else tmplam = -slope/(b+SQRT(disc)); + } + if (tmplam>0.5*alam) tmplam=0.5*alam; + } + } alam2=alam; f2 = *f; fold2=fold; alam=MAX(tmplam,0.1*alam); } + Free(sign); Free(local_xold); + return 1; } #undef ALF #undef TOLX #undef NRANSI -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// #define ALF 1.0e-4 #define TOLX 1.0e-7 -void Lnsrch_Nucleotide_Frequencies(arbre *tree, int n, phydbl *xold, phydbl fold, phydbl *g, phydbl *p, phydbl *x, - phydbl *f, phydbl stpmax, int *check) +int Lnsrch_Nonaligned(t_tree *tree, int n, phydbl **xold, phydbl fold, + phydbl *g, phydbl *p, phydbl *x, + phydbl *f, phydbl stpmax, int *check, int logt, int is_positive) { int i; phydbl a,alam,alam2,alamin,b,disc,f2,fold2,rhs1,rhs2,slope,sum,temp,test,tmplam; - phydbl *local_xold; + phydbl *local_xold,*sign; + alam = alam2 = f2 = fold2 = tmplam = .0; local_xold = (phydbl *)mCalloc(n,sizeof(phydbl)); - For(i,n) local_xold[i] = xold[i]; + sign = (phydbl *)mCalloc(n,sizeof(phydbl)); + for(i=0;i stpmax) for(i=0;i test) test=temp; } alamin=TOLX/test; alam=1.0; - for (;;) + for (;;) + { + for(i=0;imod->pi[i]=fabs(local_xold[i]+alam*p[i]); -/* if( */ -/* (tree->mod->pi[i] < 0.001) || */ -/* (tree->mod->pi[i] > 0.999) */ -/* ) */ -/* break; */ - } - /**/ - if(i==n) - { - *f=Return_Abs_Lk(tree); - } - else *f=1.+fold+ALF*alam*slope; + if(logt == YES) for(i=0;imod->pi[i]=local_xold[i]; - *check=1; - For(i,n) xold[i] = local_xold[i]; - Free(local_xold); - return; - } - else if (*f <= fold+ALF*alam*slope) - { - For(i,n) xold[i] = local_xold[i]; - Free(local_xold); - return; - } - else - { - if (alam == 1.0) - tmplam = -slope/(2.0*(*f-fold-slope)); - else - { - rhs1 = *f-fold-alam*slope; - rhs2=f2-fold2-alam2*slope; - a=(rhs1/(alam*alam)-rhs2/(alam2*alam2))/(alam-alam2); - b=(-alam2*rhs1/(alam*alam)+alam*rhs2/(alam2*alam2))/(alam-alam2); - if (a == 0.0) tmplam = -slope/(2.0*b); - else - { - disc=b*b-3.0*a*slope; - if (disc<0.0) - { - disc=b*b-3.0*a*slope; - if (disc<0.0) tmplam = 0.5*alam; - else if(b <= 0.0) tmplam=(-b+sqrt(disc))/(3.0*a); - else tmplam = -slope/(b+sqrt(disc)); - } - else tmplam=(-b+sqrt(disc))/(3.0*a); - } - if (tmplam>0.5*alam) tmplam=0.5*alam; - } - } + { + *check=1; + for(i=0;i 1.0-SMALL)) + tmplam = -slope/(2.0*(*f-fold-slope)); + else + { + rhs1 = *f-fold-alam*slope; + rhs2=f2-fold2-alam2*slope; + a=(rhs1/(alam*alam)-rhs2/(alam2*alam2))/(alam-alam2); + b=(-alam2*rhs1/(alam*alam)+alam*rhs2/(alam2*alam2))/(alam-alam2); + if (a < SMALL && a > -SMALL) tmplam = -slope/(2.0*b); + else + { + disc=b*b-3.0*a*slope; + if (disc<0.0) tmplam = 0.5*alam; + else if(b <= 0.0) tmplam=(-b+SQRT(disc))/(3.0*a); + else tmplam = -slope/(b+SQRT(disc)); + } + if (tmplam>0.5*alam) tmplam=0.5*alam; + } + } alam2=alam; f2 = *f; fold2=fold; alam=MAX(tmplam,0.1*alam); } Free(local_xold); + Free(sign); + return 1; } -/*********************************************************/ - -/* void Optimize_Global_Rate(arbre *tree) */ -/* { */ -/* printf("\n. Global rate (%f->)",tree->c_lnL); */ -/* Optimize_Single_Param_Generic(tree,&(tree->tbl),tree->tbl,BL_MIN,1.E+4,100); */ -/* printf("%f)\n",tree->c_lnL); */ -/* } */ - - #undef ALF #undef TOLX #undef NRANSI -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void EM_Dist(model *mod, allseq *data) +int Dist_F_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *F, phydbl *param, t_mod *mod) { - phydbl sum; - phydbl **prob, *F; - int i,j,site; - phydbl d; - phydbl ***Pij; - int n_iter; - phydbl p_diff; - phydbl **p_lk_left,**p_lk_rght; - phydbl *pi; - - - p_lk_left = (phydbl **)mCalloc(data->c_seq[0]->len,sizeof(phydbl *)); - p_lk_rght = (phydbl **)mCalloc(data->c_seq[0]->len,sizeof(phydbl *)); - F = (phydbl *)mCalloc(mod->ns*mod->ns, sizeof(phydbl)); - pi = (phydbl *)mCalloc(mod->ns, sizeof(phydbl)); - prob = (phydbl **)mCalloc(mod->ns,sizeof(phydbl *)); - For(i,mod->ns) prob[i] = (phydbl *)mCalloc(mod->ns,sizeof(phydbl)); - Pij = mod->Pij_rr; + phydbl ulim,u,r,q,dum; + phydbl fa, fb, fc, fu; - For(i,data->c_seq[0]->len) - { - p_lk_left[i] = (phydbl *)mCalloc(mod->ns,sizeof(phydbl)); - p_lk_rght[i] = (phydbl *)mCalloc(mod->ns,sizeof(phydbl)); - } + fa = -Lk_Dist(F,FABS(*ax),mod); + fb = -Lk_Dist(F,FABS(*bx),mod); - - For(i,mod->ns) pi[i] = 0.25; - d = 0.1; - n_iter = 0; - do - { - PMat(d,mod,Pij); - - For(i,mod->ns) For(j,mod->ns) F[mod->ns*i+j] = .0; - - For(site,data->c_seq[0]->len) - { - For(i,mod->ns) For(j,mod->ns) - prob[i][j] = - pi[i] * - Pij[0][i][j] * - p_lk_left[site][i] * - p_lk_rght[site][j] ; - - sum = .0; - For(i,mod->ns) For(j,mod->ns) - sum += prob[i][j]; - For(i,mod->ns) For(j,mod->ns) - prob[i][j] /= sum; - - - For(i,mod->ns) For(j,mod->ns) - F[mod->ns*i+j] += - data->wght[site] * - prob[i][j]; - } - - For(i,mod->ns) For(j,mod->ns) - F[mod->ns*i+j] /= (phydbl)data->init_len; - - For(i,mod->ns) For(j,mod->ns) - F[mod->ns*i+j] = (F[mod->ns*i+j] +F[mod->ns*j+i])/2.; - - p_diff = .0; - For(i,mod->ns) p_diff += F[mod->ns*i+i]; - p_diff = 1. - p_diff; - d = -(3./4.)*log(1.-(4./3.)*p_diff); - printf("\n. d = %f\n",d); - n_iter++; - }while(n_iter < 10); + if(fb > fa) + { + SHFT(dum,*ax,*bx,dum) + SHFT(dum,fb,fa,dum) + } + *cx=(*bx)+MNBRAK_GOLD*(*bx-*ax); + fc = -Lk_Dist(F,FABS(*cx),mod); - For(i,data->c_seq[0]->len) - { - Free(p_lk_left[i]); - Free(p_lk_rght[i]); - } - Free(p_lk_left); Free(p_lk_rght); - Free(pi); -} - -/*********************************************************/ - -int Dist_F_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *F, phydbl *param, model *mod) -{ - phydbl ulim,u,r,q,dum; - phydbl fa, fb, fc, fu; - - fa = -Lk_Dist(F,fabs(*ax),mod); - fb = -Lk_Dist(F,fabs(*bx),mod); - - if(fb > fa) - { - SHFT(dum,*ax,*bx,dum) - SHFT(dum,fb,fa,dum) - } - - *cx=(*bx)+MNBRAK_GOLD*(*bx-*ax); - fc = -Lk_Dist(F,fabs(*cx),mod); - - while (fb > fc) + while (fb > fc) { r=(*bx-*ax)*(fb-fc); q=(*bx-*cx)*(fb-fa); u=(*bx)-((*bx-*cx)*q-(*bx-*ax)*r)/ - (2.0*SIGN(MAX(fabs(q-r),MNBRAK_TINY),q-r)); + (2.0*SIGN(MAX(FABS(q-r),MNBRAK_TINY),q-r)); ulim=(*bx)+MNBRAK_GLIMIT*(*cx-*bx); - - if ((*bx-u)*(u-*cx) > 0.0) - { - fu = -Lk_Dist(F,fabs(u),mod); - if (fu < fc) - { - *ax=(*bx); - *bx=u; - fa=fb; - fb=fu; - return(0); - } - else if (fu > fb) - { - *cx=u; - fc=fu; - return(0); - } - u=(*cx)+MNBRAK_GOLD*(*cx-*bx); - fu = -Lk_Dist(F,fabs(u),mod); - } - else if ((*cx-u)*(u-ulim) > 0.0) - { - fu = -Lk_Dist(F,fabs(u),mod); - if (fu < fc) - { - SHFT(*bx,*cx,u,*cx+MNBRAK_GOLD*(*cx-*bx)) - SHFT(fb,fc,fu,-Lk_Dist(F,fabs(u),mod)) - } - } - else if ((u-ulim)*(ulim-*cx) >= 0.0) - { - u = ulim; - fu = -Lk_Dist(F,fabs(u),mod); - } - else - { - u =(*cx)+MNBRAK_GOLD*(*cx-*bx); - fu = -Lk_Dist(F,fabs(u),mod); - } + + if ((*bx-u)*(u-*cx) > 0.0) + { + fu = -Lk_Dist(F,FABS(u),mod); + if (fu < fc) + { + *ax=(*bx); + *bx=u; + fa=fb; + fb=fu; + return(0); + } + else if (fu > fb) + { + *cx=u; + fc=fu; + return(0); + } + u=(*cx)+MNBRAK_GOLD*(*cx-*bx); + fu = -Lk_Dist(F,FABS(u),mod); + } + else if ((*cx-u)*(u-ulim) > 0.0) + { + fu = -Lk_Dist(F,FABS(u),mod); + if (fu < fc) + { + SHFT(*bx,*cx,u,*cx+MNBRAK_GOLD*(*cx-*bx)) + SHFT(fb,fc,fu,-Lk_Dist(F,FABS(u),mod)) + } + } + else if ((u-ulim)*(ulim-*cx) >= 0.0) + { + u = ulim; + fu = -Lk_Dist(F,FABS(u),mod); + } + else + { + u =(*cx)+MNBRAK_GOLD*(*cx-*bx); + fu = -Lk_Dist(F,FABS(u),mod); + } SHFT(*ax,*bx,*cx,u) SHFT(fa,fb,fc,fu) @@ -2082,16 +1876,17 @@ int Dist_F_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *F, phydbl *param, mo return(0); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Dist_F_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, int n_iter_max, - phydbl *param, phydbl *F, model *mod) +phydbl Dist_F_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, int n_iter_max, + phydbl *param, phydbl *F, t_mod *mod) { int iter; phydbl a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; phydbl e=0.0; phydbl old_lnL,init_lnL, curr_lnL; - + d=0.0; a=((ax < cx) ? ax : cx); b=((ax > cx) ? ax : cx); @@ -2099,175 +1894,185 @@ phydbl Dist_F_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, int n_iter_max, old_lnL = UNLIKELY; fw = fv = fx = -Lk_Dist(F,fabs(bx),mod); curr_lnL = init_lnL = -fw; + + /* PhyML_Printf("\n. bx=%f f: %f %f %f %f fx: %f",bx,mod->e_frq->pi->v[0],mod->e_frq->pi->v[1],mod->e_frq->pi->v[2],mod->e_frq->pi->v[3],fx); */ + assert(isnan(fx) == FALSE); + assert(isinf(fx) == FALSE); - for(iter=1;iter<=BRENT_ITMAX;iter++) + for(iter=1;iter<=BRENT_IT_MAX;iter++) { xm=0.5*(a+b); - - tol2=2.0*(tol1=tol*fabs(x)+BRENT_ZEPS); - + + tol2=2.0*(tol1=tol*FABS(x)+BRENT_ZEPS); + if( - ((fabs(curr_lnL-old_lnL) < mod->s_opt->min_diff_lk_local) && - (curr_lnL > init_lnL - mod->s_opt->min_diff_lk_local)) || - (iter > n_iter_max - 1) - ) - { - *param = x; - curr_lnL = Lk_Dist(F,*param,mod); - return -curr_lnL; - } + ((FABS(curr_lnL-old_lnL) < mod->s_opt->min_diff_lk_local) && + (curr_lnL > init_lnL - mod->s_opt->min_diff_lk_local)) || + (iter > n_iter_max - 1) + ) + { + *param = x; + curr_lnL = Lk_Dist(F,*param,mod); + return -curr_lnL; + } - if(fabs(e) > tol1) - { - r=(x-w)*(fx-fv); - q=(x-v)*(fx-fw); - p=(x-v)*q-(x-w)*r; - q=2.0*(q-r); - if(q > 0.0) p = -p; - q=fabs(q); - etemp=e; - e=d; - if(fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - /* printf("Golden section step\n"); */ - } - else - { - d=p/q; - u=x+d; - if (u-a < tol2 || b-u < tol2) - d=SIGN(tol1,xm-x); - /* printf("Parabolic step\n"); */ - } + if(FABS(e) > tol1) + { + r=(x-w)*(fx-fv); + q=(x-v)*(fx-fw); + p=(x-v)*q-(x-w)*r; + q=2.0*(q-r); + if(q > 0.0) p = -p; + q=FABS(q); + etemp=e; + e=d; + if(FABS(p) >= FABS(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) + { + d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); + /* PhyML_Printf("Golden section step\n"); */ + } + else + { + d=p/q; + u=x+d; + if (u-a < tol2 || b-u < tol2) + d=SIGN(tol1,xm-x); + /* PhyML_Printf("Parabolic step\n"); */ + } } else - { - d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); - /* printf("Golden section step (default)\n"); */ - } + { + d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); + /* PhyML_Printf("Golden section step (default)\n"); */ + } - u=(fabs(d) >= tol1 ? x+d : x+SIGN(tol1,d)); - if(u= tol1 ? x+d : x+SIGN(tol1,d)); + (*param) = FABS(u); old_lnL = curr_lnL; - fu = -Lk_Dist(F,fabs(u),mod); - curr_lnL = -fu; -/* printf("param=%f loglk=%f\n",*param,fu); */ + fu = -Lk_Dist(F,FABS(u),mod); + curr_lnL = -fu; + /* PhyML_Printf("param=%f loglk=%f\n",*param,fu); */ - if(fu <= fx) - { - if(iter > n_iter_max) return -fu; - - if(u >= x) a=x; else b=x; - SHFT(v,w,x,u) - SHFT(fv,fw,fx,fu) - } + /* if(fu <= fx) */ + if(fu < fx) + { + if(iter > n_iter_max) return -fu; + + if(u >= x) a=x; else b=x; + SHFT(v,w,x,u) + SHFT(fv,fw,fx,fu) + } else - { - if (u < x) a=u; else b=u; - if (fu <= fw || w == x) - { - v=w; - w=u; - fv=fw; - fw=fu; - } - else if (fu <= fv || v == x || v == w) { - v=u; - fv=fu; - } - } + { + if (u < x) a=u; else b=u; + /* if (fu <= fw || w == x) */ + if (fu < fw || FABS(w-x) < SMALL) + { + v=w; + w=u; + fv=fw; + fw=fu; + } + /* else if (fu <= fv || v == x || v == w) */ + else if (fu < fv || FABS(v-x) < SMALL || FABS(v-w) < SMALL) + { + v=u; + fv=fu; + } + } } - Exit("\n. Too many iterations in BRENT !"); + + Exit("\n. Too many iterations in Dist_F_Brent !\n"); return(-1); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Opt_Dist_F(phydbl *dist, phydbl *F, model *mod) +void Opt_Dist_F(phydbl *dist, phydbl *F, t_mod *mod) { phydbl ax,bx,cx; - if(*dist < BL_MIN) *dist = BL_MIN; - - ax = *dist; - bx = 1.5*(*dist); + if(*dist < mod->l_min) *dist = mod->l_min; - ax = 10.*(*dist); - bx = (*dist); - cx = .10*(*dist); + ax = mod->l_min; + bx = (*dist); + cx = mod->l_max; + /* PhyML_Printf("\n. bx: %g",bx); */ + /* Dist_F_Brak(&ax,&bx,&cx,F,dist,mod); */ Dist_F_Brent(ax,bx,cx,1.E-10,1000,dist,F,mod); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + int Missing_Dist_Brak(phydbl *ax, phydbl *bx, phydbl *cx, int x, int y, matrix *mat) { phydbl ulim,u,r,q,dum; phydbl fa, fb, fc, fu; - fa = Least_Square_Missing_Dist_XY(x,y,fabs(*ax),mat); - fb = Least_Square_Missing_Dist_XY(x,y,fabs(*bx),mat); + fa = Least_Square_Missing_Dist_XY(x,y,FABS(*ax),mat); + fb = Least_Square_Missing_Dist_XY(x,y,FABS(*bx),mat); - if(fb > fa) + if(fb > fa) { SHFT(dum,*ax,*bx,dum) SHFT(dum,fb,fa,dum) } *cx=(*bx)+MNBRAK_GOLD*((*bx)-(*ax)); - fc = Least_Square_Missing_Dist_XY(x,y,fabs(*cx),mat); + fc = Least_Square_Missing_Dist_XY(x,y,FABS(*cx),mat); - while (fb > fc) + while (fb > fc) { r=((*bx)-(*ax))*(fb-fc); q=((*bx)-(*cx))*(fb-fa); u=(*bx)-(((*bx)-(*cx))*q-((*bx)-(*ax))*r)/ - (2.0*SIGN(MAX(fabs(q-r),MNBRAK_TINY),q-r)); + (2.0*SIGN(MAX(FABS(q-r),MNBRAK_TINY),q-r)); ulim=(*bx)+MNBRAK_GLIMIT*(*cx-*bx); - - if ((*bx-u)*(u-*cx) > 0.0) - { - fu = Least_Square_Missing_Dist_XY(x,y,fabs(u),mat); - if (fu < fc) - { - *ax=(*bx); - *bx=u; - fa=fb; - fb=fu; - return(0); - } - else if (fu > fb) - { - *cx=u; - fc=fu; - return(0); - } - u=(*cx)+MNBRAK_GOLD*(*cx-*bx); - fu = Least_Square_Missing_Dist_XY(x,y,fabs(u),mat); - } - else if ((*cx-u)*(u-ulim) > 0.0) - { - fu = Least_Square_Missing_Dist_XY(x,y,fabs(u),mat); - if (fu < fc) - { - SHFT(*bx,*cx,u,*cx+MNBRAK_GOLD*(*cx-*bx)) - SHFT(fb,fc,fu,Least_Square_Missing_Dist_XY(x,y,fabs(u),mat)) - } - } - else if ((u-ulim)*(ulim-*cx) >= 0.0) - { - u = ulim; - fu = Least_Square_Missing_Dist_XY(x,y,fabs(u),mat); - } - else - { - u =(*cx)+MNBRAK_GOLD*(*cx-*bx); - fu = Least_Square_Missing_Dist_XY(x,y,fabs(u),mat); - } + + if ((*bx-u)*(u-*cx) > 0.0) + { + fu = Least_Square_Missing_Dist_XY(x,y,FABS(u),mat); + if (fu < fc) + { + *ax=(*bx); + *bx=u; + fa=fb; + fb=fu; + return(0); + } + else if (fu > fb) + { + *cx=u; + fc=fu; + return(0); + } + u=(*cx)+MNBRAK_GOLD*(*cx-*bx); + fu = Least_Square_Missing_Dist_XY(x,y,FABS(u),mat); + } + else if ((*cx-u)*(u-ulim) > 0.0) + { + fu = Least_Square_Missing_Dist_XY(x,y,FABS(u),mat); + if (fu < fc) + { + SHFT(*bx,*cx,u,*cx+MNBRAK_GOLD*(*cx-*bx)) + SHFT(fb,fc,fu,Least_Square_Missing_Dist_XY(x,y,FABS(u),mat)) + } + } + else if ((u-ulim)*(ulim-*cx) >= 0.0) + { + u = ulim; + fu = Least_Square_Missing_Dist_XY(x,y,FABS(u),mat); + } + else + { + u =(*cx)+MNBRAK_GOLD*(*cx-*bx); + fu = Least_Square_Missing_Dist_XY(x,y,FABS(u),mat); + } SHFT(*ax,*bx,*cx,u) SHFT(fa,fb,fc,fu) @@ -2275,103 +2080,106 @@ int Missing_Dist_Brak(phydbl *ax, phydbl *bx, phydbl *cx, int x, int y, matrix * return(0); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -phydbl Missing_Dist_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, int n_iter_max, - int x, int y, matrix *mat) +phydbl Missing_Dist_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, int n_iter_max, + int x, int y, matrix *mat) { int iter; phydbl a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,xx,xm; phydbl e=0.0; - phydbl init_loglk, max_loglk; - phydbl bestx; d=0.0; a=((ax < cx) ? ax : cx); b=((ax > cx) ? ax : cx); xx=w=v=bx; - fx=Least_Square_Missing_Dist_XY(x,y,fabs(bx),mat); + fx=Least_Square_Missing_Dist_XY(x,y,FABS(bx),mat); fw=fv=-fx; - init_loglk = fw; - max_loglk = UNLIKELY; - bestx = bx; - for(iter=1;iter<=BRENT_ITMAX;iter++) + for(iter=1;iter<=BRENT_IT_MAX;iter++) { xm=0.5*(a+b); - tol2=2.0*(tol1=tol*fabs(xx)+BRENT_ZEPS); - - if(fabs(xx-xm) <= (tol2-0.5*(b-a))) - { - mat->dist[x][y] = xx; - Least_Square_Missing_Dist_XY(x,y,mat->dist[x][y],mat); - return -fx; - } - - if(fabs(e) > tol1) - { - r=(xx-w)*(fx-fv); - q=(xx-v)*(fx-fw); - p=(xx-v)*q-(xx-w)*r; - q=2.0*(q-r); - if(q > 0.0) p = -p; - q=fabs(q); - etemp=e; - e=d; - if(fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-xx) || p >= q*(b-xx)) - { - d=BRENT_CGOLD*(e=(xx >= xm ? a-xx : b-xx)); - /* printf("Golden section step\n"); */ - } - else - { - d=p/q; - u=xx+d; - if (u-a < tol2 || b-u < tol2) - d=SIGN(tol1,xm-xx); - /* printf("Parabolic step\n"); */ - } + tol2=2.0*(tol1=tol*FABS(xx)+BRENT_ZEPS); + + if(FABS(xx-xm) <= (tol2-0.5*(b-a))) + { + mat->dist[x][y] = xx; + Least_Square_Missing_Dist_XY(x,y,mat->dist[x][y],mat); + return -fx; + } + + if(FABS(e) > tol1) + { + r=(xx-w)*(fx-fv); + q=(xx-v)*(fx-fw); + p=(xx-v)*q-(xx-w)*r; + q=2.0*(q-r); + if(q > 0.0) p = -p; + q=FABS(q); + etemp=e; + e=d; + if(FABS(p) >= FABS(0.5*q*etemp) || p <= q*(a-xx) || p >= q*(b-xx)) + { + d=BRENT_CGOLD*(e=(xx >= xm ? a-xx : b-xx)); + /* PhyML_Printf("Golden section step\n"); */ } else - { - d=BRENT_CGOLD*(e=(xx >= xm ? a-xx : b-xx)); - /* printf("Golden section step (default)\n"); */ - } - - u=(fabs(d) >= tol1 ? xx+d : xx+SIGN(tol1,d)); - fu = Least_Square_Missing_Dist_XY(x,y,fabs(u),mat); - -/* printf("param=%f loglk=%f\n",u,fu); */ - - if(fu <= fx) - { - if(iter > n_iter_max) return -fu; - - if(u >= xx) a=xx; else b=xx; - SHFT(v,w,xx,u) - SHFT(fv,fw,fx,fu) - } + { + d=p/q; + u=xx+d; + if (u-a < tol2 || b-u < tol2) + d=SIGN(tol1,xm-xx); + /* PhyML_Printf("Parabolic step\n"); */ + } + } else - { - if (u < xx) a=u; else b=u; - if (fu <= fw || w == xx) - { - v=w; - w=u; - fv=fw; - fw=fu; - } - else if (fu <= fv || v == xx || v == w) { - v=u; - fv=fu; - } - } + { + d=BRENT_CGOLD*(e=(xx >= xm ? a-xx : b-xx)); + /* PhyML_Printf("Golden section step (default)\n"); */ } - Exit("\n. Too many iterations in BRENT !"); + + u=(FABS(d) >= tol1 ? xx+d : xx+SIGN(tol1,d)); + fu = Least_Square_Missing_Dist_XY(x,y,FABS(u),mat); + +/* PhyML_Printf("param=%f loglk=%f\n",u,fu); */ + +/* if(fu <= fx) */ + if(fu < fx) + { + if(iter > n_iter_max) return -fu; + + if(u >= xx) a=xx; else b=xx; + SHFT(v,w,xx,u) + SHFT(fv,fw,fx,fu) + } + else + { + if (u < xx) a=u; else b=u; +/* if (fu <= fw || w == xx) */ + if (fu < fw || FABS(w-xx) < SMALL) + { + v=w; + w=u; + fv=fw; + fw=fu; + } +/* else if (fu <= fv || v == xx || v == w) */ + else if (fu < fv || FABS(v-xx) < SMALL || FABS(v-w) < SMALL) + { + v=u; + fv=fu; + } + } + } + Exit("\n. Too many iterations in Missing_Dist_Brent !"); return(-1); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + void Opt_Missing_Dist(int x, int y, matrix *mat) { @@ -2381,295 +2189,1556 @@ void Opt_Missing_Dist(int x, int y, matrix *mat) bx = DIST_MAX/4.; Missing_Dist_Brak(&ax,&bx,&cx,x,y,mat); - printf("ax=%f bx=%f cx=%f\n",fabs(ax),fabs(bx),fabs(cx)); - Missing_Dist_Brent(fabs(ax),fabs(bx),fabs(cx),1.E-5,100,x,y,mat); + PhyML_Printf("ax=%f bx=%f cx=%f\n",FABS(ax),FABS(bx),FABS(cx)); + Missing_Dist_Brent(FABS(ax),FABS(bx),FABS(cx),1.E-5,100,x,y,mat); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Optimiz_Alpha_And_Pinv(arbre *tree) +int Optimiz_Alpha_And_Pinv(t_tree *mixt_tree, int verbose) { + scalar_dbl **alpha; + int n_alpha; + t_tree *tree; + int i; - int iter; - phydbl best_alpha, best_pinv; - phydbl slope, intercept; - phydbl lk_b, lk_a; - phydbl lk_init, lk_final; - phydbl f0,f1,f2,f3,x0,x1,x2,x3; - phydbl pinv0, pinv1; - phydbl a, b, c; - phydbl fa, fb, fc; - phydbl K; - phydbl alpha0, alpha1; - phydbl best_lnL; - - - lk_final = UNLIKELY; - lk_b = UNLIKELY; - lk_a = UNLIKELY; - - -/* printf("\n\n. Init lnL = %f alpha=%f pinv=%f", */ -/* tree->c_lnL, */ -/* tree->mod->alpha, */ -/* tree->mod->pinvar); */ - - /* Two (full) steps to compute pinv_alpha_slope & pinv_alpha_intercept */ + Set_Update_Eigen(NO,mixt_tree->mod); + + alpha = NULL; + n_alpha = 0; + tree = mixt_tree; - tree->both_sides = 1; - Lk(tree); - lk_b = tree->c_lnL; + do + { + if(tree->mod->s_opt->opt_alpha == YES && tree->mod->ras->n_catg > 1 && tree->mod->s_opt->opt_pinvar == YES) + { + for(i=0;imod->ras->alpha == alpha[i]) break; + + if(i == n_alpha) + { + if(!alpha) alpha = (scalar_dbl **)mCalloc(1,sizeof(scalar_dbl *)); + else alpha = (scalar_dbl **)mRealloc(alpha,n_alpha+1,sizeof(scalar_dbl *)); + alpha[n_alpha] = tree->mod->ras->alpha; + n_alpha++; + + if(tree->mod->s_opt->opt_alpha == YES && + tree->mod->ras->free_mixt_rates == NO) + { + if(tree->mod->ras->n_catg > 1) + { + Generic_Brent_Lk(&(tree->mod->ras->alpha->v), + ALPHA_MIN,ALPHA_MAX, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + } + if(verbose == YES) + { + Print_Lk(mixt_tree,"[Alpha ]"); + PhyML_Printf("[%10f]",tree->mod->ras->alpha->v); + } + } + + if(tree->mod->s_opt->opt_pinvar == YES && + tree->mod->ras->free_mixt_rates == NO) + { + tree->mod->s_opt->skip_tree_traversal = YES; + + Optimize_Single_Param_Generic(mixt_tree,&(tree->mod->ras->pinvar->v),.0001,0.9999, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty); + + tree->mod->s_opt->skip_tree_traversal = NO; + + if(verbose == YES) + { + Print_Lk(mixt_tree,"[P-inv ]"); + PhyML_Printf("[%10f]",tree->mod->ras->pinvar->v); + } + } + } + } + tree = tree->next_mixt; + } + while(tree); + + if(alpha) Free(alpha); + + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - Optimize_Br_Len_Serie(tree->noeud[0],tree->noeud[0]->v[0], - tree->noeud[0]->b[0],tree,tree->data); +static phydbl Br_Len_Spline(phydbl *l, t_edge *b, int n_iter_max, phydbl tol, t_tree *tree) +{ + short int converged; + phydbl init_lnL,old_lnL; + int iter; + phydbl best_l, new_l, init_l, init_dl, best_lnL; + phydbl u, v; + phydbl fu, fv; + phydbl dfu, dfv; + phydbl mult; + phydbl a_,b_,A_,B_,C_,D_,root1,root2; + short int ok1, ok2; + // Warning: make sure eigen_lr vectors are already up-to-date - tree->both_sides = 0; - Optimize_Single_Param_Generic(tree,&(tree->mod->pinvar),.0001,0.9999, - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - Optimize_Single_Param_Generic(tree,&(tree->mod->alpha),.01,100., - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); + Set_Use_Eigen_Lr(YES,tree); + + + best_l = init_l = *l; + best_lnL = old_lnL = init_lnL = tree->c_lnL; + mult = 1.2; + ok1 = ok2 = NO; + a_ = b_ = A_ = B_ = D_ = root1 = root2 = -1.; + u = v = fu = fv = dfu = dfv = -1.; + new_l = -1.; + + dLk(l,b,tree); + init_dl = tree->c_dlnL; - pinv0 = tree->mod->pinvar; - alpha0 = tree->mod->alpha; - f0 = tree->c_lnL; + if(*l > tree->mod->l_max) *l = 0.5; + if(*l < tree->mod->l_min) *l = 0.001; + + // Find value of l where first derivative is < 0; + tree->c_dlnL = init_dl; + while(tree->c_dlnL < 0.0) + { + *l /= mult; + tree->n_tot_bl_opt++; + if(*l < tree->mod->l_min) + { + *l = best_l; + tree->c_lnL = best_lnL; + return best_lnL; + } + dLk(l,b,tree); + if(tree->c_lnL > best_lnL) + { + best_lnL = tree->c_lnL; + best_l = *l; + } + } + u = *l; + fu = tree->c_lnL; + dfu = tree->c_dlnL; + + + + // Find good upper bound + *l = init_l; + tree->c_dlnL = init_dl; + tree->c_lnL = init_lnL; + while(tree->c_dlnL > 0.0) + { + *l *= mult; + tree->n_tot_bl_opt++; + if(*l > tree->mod->l_max) + { + *l = best_l; + tree->c_lnL = best_lnL; + return best_lnL; + } + dLk(l,b,tree); + if(tree->c_lnL > best_lnL) + { + best_lnL = tree->c_lnL; + best_l = *l; + } + } + v = *l; + fv = tree->c_lnL; + dfv = tree->c_dlnL; - tree->both_sides = 1; - Lk(tree); - Optimize_Br_Len_Serie(tree->noeud[0],tree->noeud[0]->v[0], - tree->noeud[0]->b[0],tree,tree->data); + + /* PhyML_Printf("\n Begin NR loop (lnL: %12G dlnL: %12G) l: %12G num: %d",tree->c_lnL,tree->c_dlnL,*l,b->num); */ - tree->both_sides = 0; - Optimize_Single_Param_Generic(tree,&(tree->mod->pinvar),.0001,0.9999, - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); - Optimize_Single_Param_Generic(tree,&(tree->mod->alpha),.01,100., - tree->mod->s_opt->min_diff_lk_global, - tree->mod->s_opt->brent_it_max); + converged = NO; + iter = 0; + do + { + /* PhyML_Printf("\n. l=%12f lnL=%12f iter:%d u=%12f v=%12f root1=%12f root2=%12f dfu=%12f dfv=%12f fu=%12f fv=%12f diff=%12f tol=%12f init=%12f", */ + /* *l,tree->c_lnL,iter, */ + /* u,v, */ + /* root1,root2, */ + /* dfu,dfv, */ + /* fu,fv, */ + /* tree->c_lnL-old_lnL, */ + /* tol,init_l); */ + + /* PhyML_Printf("\n. l: %f dlnL: %f lnL: %f",*l,tree->c_dlnL,tree->c_lnL); */ + // Spline interpolation (https://en.wikipedia.org/wiki/Spline_interpolation) + a_ = dfu*(v-u) - (fv-fu); + b_ = -dfv*(v-u) + (fv-fu); + + A_ = 3.*a_ - 3.*b_; + B_ = -4.*a_ + 2.*b_; + C_ = fv-fu+a_; + D_ = sqrt(B_*B_-4.*A_*C_); - lk_a = tree->c_lnL; + root1 = (-B_-D_)/(2.*A_); + root2 = (-B_+D_)/(2.*A_); - pinv1 = tree->mod->pinvar; - alpha1 = tree->mod->alpha; - f1 = tree->c_lnL; - best_lnL = f1; + root1 = root1*(v-u) + u; + root2 = root2*(v-u) + u; + + ok1 = NO; + ok2 = NO; + if(root1 > u && root1 < v) ok1 = YES; + if(root2 > u && root2 < v) ok2 = YES; + + if(Are_Equal(root1,u,1.E-5) == YES) ok1 = YES; + if(Are_Equal(root2,u,1.E-5) == YES) ok2 = YES; + if(Are_Equal(root1,v,1.E-5) == YES) ok1 = YES; + if(Are_Equal(root2,v,1.E-5) == YES) ok2 = YES; + + + if(ok1 == YES && ok2 == YES) new_l = root1 < root2 ? root1 : root2; + else if(ok1 == YES) new_l = root1; + else if(ok2 == YES) new_l = root2; + else if(u/v > 1.1 || u/v < 0.9) + { + PhyML_Printf("\n. iter=%4d u=%12G fu=%12G dfu=%12G v=%12G fv=%12G dfv=%12G root1=%12G root2=%12G\n",iter,u,fu,dfu,v,fv,dfv,root1,root2); + assert(FALSE); + } + + *l = new_l; + tree->n_tot_bl_opt++; + + old_lnL = tree->c_lnL; + dLk(l,b,tree); + if(tree->c_lnL > best_lnL) + { + best_lnL = tree->c_lnL; + best_l = *l; + } + + if(tree->c_dlnL > 0.0) + { + u = new_l; + fu = tree->c_lnL; + dfu = tree->c_dlnL; + } + else + { + v = new_l; + fv = tree->c_lnL; + dfv = tree->c_dlnL; + } - if(lk_a < lk_b - tree->mod->s_opt->min_diff_lk_local) + + + if(u - v < DBL_MIN) converged = YES; + if(fabs(tree->c_lnL-old_lnL) < tol) converged = YES; + if(++iter == n_iter_max+20) converged = YES; + if(iter >= n_iter_max) PhyML_Fprintf(stderr,"\n. Edge length optimization took too long... l=%G lnL=%G iter:%d u=%G v=%G root1=%G root2=%G dfu=%G dfv=%G fu=%G fv=%G diff=%G tol=%G", + *l,tree->c_lnL,iter, + u,v, + root1,root2, + dfu,dfv, + fu,fv, + tree->c_lnL-old_lnL, + tol); + + if(converged == NO) + { + if(!(u < v)) PhyML_Printf("\n. u=%g v=%g.\n",u,v); + if(!(dfu > 0.0)) PhyML_Printf("\n. dfu=%g l=%g u=%g v=%g\n",dfu,*l,u,v); + if(!(dfv < 0.0)) PhyML_Printf("\n. dfv=%g l=%g u=%g v=%g\n",dfv,*l); + + assert(u < v); + assert(dfu > 0.0); + assert(dfv < 0.0); + } + } + while(converged == NO); + + /* PhyML_Printf("\n. l = %g l_max = %g diff=%g",*l,tree->mod->l_max,*l-tree->mod->l_max); */ + + assert(!(*l > tree->mod->l_max)); + assert(!(*l < tree->mod->l_min)); + + /* if(dfu > 1.) */ + /* { */ + /* PhyML_Printf("\n> [%4d] l=%f lnL=%f iter:%d u=%f v=%f root1=%f root2=%f dfu=%f dfv=%f fu=%f fv=%f diff=%f tol=%f init=%f", */ + /* tree->n_tot_bl_opt, */ + /* *l,tree->c_lnL,iter, */ + /* u,v, */ + /* root1,root2, */ + /* dfu,dfv, */ + /* fu,fv, */ + /* tree->c_lnL-old_lnL, */ + /* tol,init_l); */ + /* } */ + /* if(dfv < -1) */ + /* { */ + /* PhyML_Printf("\n< [%4d] l=%f lnL=%f iter:%d u=%f v=%f root1=%f root2=%f dfu=%f dfv=%f fu=%f fv=%f diff=%f tol=%f init=%f", */ + /* tree->n_tot_bl_opt, */ + /* *l,tree->c_lnL,iter, */ + /* u,v, */ + /* root1,root2, */ + /* dfu,dfv, */ + /* fu,fv, */ + /* tree->c_lnL-old_lnL, */ + /* tol,init_l); */ + /* } */ + + *l = best_l; + tree->c_lnL = best_lnL; + + if(iter == n_iter_max) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + PhyML_Printf("\n. Too many iterations in edge length optimization routine (l=%G init=%G).\n",best_l,init_l); + assert(FALSE); } - else if(fabs(lk_a - lk_b) < tree->mod->s_opt->min_diff_lk_local) + + return tree->c_lnL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Generic_Brent_Lk(phydbl *param, phydbl ax, phydbl cx, phydbl tol, + int n_iter_max, int quickdirty, + phydbl (*obj_func)(t_edge *,t_tree *,supert_tree *), + t_edge *branch, t_tree *tree, supert_tree *stree, int logt) +{ + int iter; + phydbl a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; + phydbl e=0.0; + phydbl old_lnL,init_lnL; + phydbl bx = *param; + int n_opt_step; + + n_opt_step = 0; + d=0.0; + a=((ax < cx) ? ax : cx); + b=((ax > cx) ? ax : cx); + x=w=v=bx; + (*param) = bx; + if(logt == YES) (*param) = exp(MIN(1.E+2,*param)); + fw=fv=fx=fu=-(*obj_func)(branch,tree,stree); + if(logt == YES) (*param) = log(*param); + init_lnL = old_lnL = fw; + + /* PhyML_Printf("\n. %p %p %p init_lnL=%f fu=%f ax=%f cx=%f param=%f",branch,tree,stree,init_lnL,fu,ax,cx,*param); */ + + for(iter=1;iter<=BRENT_IT_MAX;iter++) { - return 1; + xm=0.5*(a+b); + tol2=2.0*(tol1=tol*x+BRENT_ZEPS); + + if((fu < init_lnL + tol) && (quickdirty == YES) && (iter > 1)) + { + (*param) = x; + if(logt == YES) (*param) = exp(MIN(1.E+2,*param)); + fu = (*obj_func)(branch,tree,stree); + if(logt == YES) (*param) = log(*param); + /* printf("\n. return %f [%f] %d",fu,*param,iter); */ + return n_opt_step; + } + + if((FABS(fu-old_lnL) < tol && iter > 1) || (iter > n_iter_max - 1)) + { + (*param) = x; + if(logt == YES) (*param) = exp(MIN(1.E+2,*param)); + fu = (*obj_func)(branch,tree,stree); + if(logt == YES) (*param) = log(*param); + /* printf("\n. return %f [%f] %d",*param,fu,iter); */ + return n_opt_step; + } + + if(FABS(e) > tol1) + { + r=(x-w)*(fx-fv); + q=(x-v)*(fx-fw); + p=(x-v)*q-(x-w)*r; + q=2.0*(q-r); + if(q > 0.0) p = -p; + q=FABS(q); + etemp=e; + e=d; + if(FABS(p) >= FABS(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) + { + d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); + /* PhyML_Printf("\n. Golden section step"); */ + } + else + { + d=p/q; + u=x+d; + if (u-a < tol2 || b-u < tol2) d=SIGN(tol1,xm-x); + /* PhyML_Printf("\n. Parabolic step [e=%f]",e); */ + } + } + else + { + d=BRENT_CGOLD*(e=(x >= xm ? a-x : b-x)); + /* PhyML_Printf("\n. Golden section step (default) [e=%f tol1=%f a=%f b=%f d=%f x=%f]",e,tol1,a,b,d,x); */ + } + + u=(FABS(d) >= tol1 ? x+d : x+SIGN(tol1,d)); + (*param) = u; + n_opt_step++; + old_lnL = fu; + if(logt == YES) (*param) = exp(MIN(1.E+2,*param)); + fu = -(*obj_func)(branch,tree,stree); + if(logt == YES) (*param) = log(*param); + /* PhyML_Printf("\n. iter=%d/%d param=%f lnL=%f u: %f x: %f d: %f logt: %d",iter,BRENT_IT_MAX,*param,fu,u,x,d,logt); */ + + if(fu <= fx) + { + if(u >= x) a=x; else b=x; + SHFT(v,w,x,u) + SHFT(fv,fw,fx,fu) + } + else + { + if (u < x) a=u; else b=u; + if (fu < fw || FABS(w-x) < SMALL) + { + v=w; + w=u; + fv=fw; + fw=fu; + } + /* else if (fu <= fv || v == x || v == w) */ + else if (fu < fv || FABS(v-x) < SMALL || FABS(v-w) < SMALL) + { + v=u; + fv=fu; + } + } } - - Record_Br_Len(tree); - best_alpha = tree->mod->alpha; - best_pinv = tree->mod->pinvar; - lk_init = tree->c_lnL; -/* printf("\n\n. Init lnL after std opt = %f",tree->c_lnL); */ + PhyML_Printf("\n. Too many iterations in Generic_Brent_Lk !"); + assert(FALSE); + return(n_opt_step); + /* Not Reached ?? *param=x; */ + /* Not Reached ?? return fx; */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/* find ML erstimates of node heights given fixed substitution + rates on branches. Also optimizes the overall substitution + rate */ +void Round_Optimize_Node_Heights(t_tree *tree) +{ + phydbl cur_lnL, new_lnL; + int n_iter; + + + cur_lnL = UNLIKELY; + new_lnL = Lk(NULL,tree); + + + n_iter = 0; + while(fabs(new_lnL - cur_lnL) > tree->mod->s_opt->min_diff_lk_local) + { + cur_lnL = tree->c_lnL; + + Opt_Node_Heights_Recurr(tree); + + Generic_Brent_Lk(&(tree->rates->clock_r), + tree->rates->min_clock, + tree->rates->max_clock, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); - slope = (pinv1 - pinv0)/(alpha1 - alpha0); - intercept = pinv1 - slope * alpha1; + printf("\n. cur_lnL=%f new_lnL=%f clock_r=%G root height=%f", + cur_lnL,new_lnL,tree->rates->clock_r,tree->rates->nd_t[tree->n_root->num]); + new_lnL = tree->c_lnL; + n_iter++; + if(n_iter > 100) break; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Opt_Node_Heights_Recurr(t_tree *tree) +{ + Opt_Node_Heights_Recurr_Pre(tree->n_root,tree->n_root->v[2],tree); + Opt_Node_Heights_Recurr_Pre(tree->n_root,tree->n_root->v[1],tree); + + Generic_Brent_Lk(&(tree->rates->nd_t[tree->n_root->num]), + MIN(tree->rates->t_prior_max[tree->n_root->num], + MIN(tree->rates->nd_t[tree->n_root->v[2]->num], + tree->rates->nd_t[tree->n_root->v[1]->num])), + tree->rates->t_prior_min[tree->n_root->num], + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Opt_Node_Heights_Recurr_Pre(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax) return; + else + { + int i; + phydbl t0,t2,t3; + phydbl t_min,t_max; + t_node *v2,*v3; + + v2 = v3 = NULL; + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(!v2) { v2 = d->v[i]; } + else { v3 = d->v[i]; } + } + + Opt_Node_Heights_Recurr_Pre(d,v2,tree); + Opt_Node_Heights_Recurr_Pre(d,v3,tree); + + t0 = tree->rates->nd_t[a->num]; + t2 = tree->rates->nd_t[v2->num]; + t3 = tree->rates->nd_t[v3->num]; + + t_min = t0; + t_max = MIN(t2,t3); + + t_min = MAX(t_min,tree->rates->t_prior_min[d->num]); + t_max = MIN(t_max,tree->rates->t_prior_max[d->num]); + + t_min += tree->rates->min_dt; + t_max -= tree->rates->min_dt; + + if(t_min > t_max) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + Generic_Brent_Lk(&(tree->rates->nd_t[d->num]), + t_min,t_max, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + + /* printf("\n. t%d = %f [%f;%f] lnL = %f",d->num,tree->rates->nd_t[d->num],t_min,t_max,tree->c_lnL); */ + + } +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_RR_Params(t_tree *mixt_tree, int verbose) +{ + t_tree *tree; + t_rmat **r_mat; + int *permut; + int n_r_mat; + int i; + phydbl lk_new,lk_old; + phydbl a,b; + phydbl *opt_val; + + Set_Update_Eigen(YES,mixt_tree->mod); + + n_r_mat = 0; + tree = mixt_tree; + r_mat = NULL; + permut = NULL; + lk_old = UNLIKELY; + lk_new = UNLIKELY; - if((slope > 0.001) && (slope < 1./0.001)) + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + + for(i=0;imod->r_mat == r_mat[i]) break; + + if(i == n_r_mat) // tree->mod->r_mat was not found before + { + if(!r_mat) r_mat = (t_rmat **)mCalloc(1,sizeof(t_rmat *)); + else r_mat = (t_rmat **)mRealloc(r_mat,n_r_mat+1,sizeof(t_rmat *)); + r_mat[n_r_mat] = tree->mod->r_mat; + n_r_mat++; + + if((tree->mod->s_opt->opt_rr) && + ((tree->mod->whichmodel == GTR) || + ((tree->mod->whichmodel == CUSTOM) && + (tree->mod->r_mat->n_diff_rr > 1)))) + { + int i,iter; + + opt_val = (phydbl *)mCalloc(tree->mod->r_mat->n_diff_rr,sizeof(phydbl)); + + iter = 0; + do + { + lk_old = mixt_tree->c_lnL; + int failed = NO; + + if(tree->mod->r_mat->n_diff_rr > 2) + { + for(i=0;imod->r_mat->n_diff_rr;i++) opt_val[i] = tree->mod->r_mat->rr_val->v[i]; + + BFGS(mixt_tree,tree->mod->r_mat->rr_val->v,tree->mod->r_mat->n_diff_rr,1.e-5,tree->mod->s_opt->min_diff_lk_local,1.e-3,NO,NO, + &Return_Abs_Lk, + &Num_Derivative_Several_Param, + &Lnsrch,&failed); + + + if(failed == YES) for(i=0;imod->r_mat->n_diff_rr;i++) tree->mod->r_mat->rr_val->v[i] = opt_val[i]; + } + + permut = Permutate(tree->mod->r_mat->n_diff_rr); + + for(i=0;imod->r_mat->n_diff_rr;i++) opt_val[i] = tree->mod->r_mat->rr_val->v[i]; + + /* for(i=0;imod->r_mat->n_diff_rr;i++) tree->mod->r_mat->rr_val->v[i] = 0.0; */ + + + for(i=0;imod->r_mat->n_diff_rr;i++) + { + a = tree->mod->r_mat->rr_val->v[permut[i]]/2.; + b = tree->mod->r_mat->rr_val->v[permut[i]]*2.+1.; + + Generic_Brent_Lk(&(tree->mod->r_mat->rr_val->v[permut[i]]), + a,b, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + } + + + if(mixt_tree->c_lnL < lk_old) + { + for(i=0;imod->r_mat->n_diff_rr;i++) tree->mod->r_mat->rr_val->v[i] = opt_val[i]; + Lk(NULL,mixt_tree); + } + + + if(verbose) Print_Lk(tree->mixt_tree? + tree->mixt_tree: + tree,"[GTR parameters ]"); + + lk_new = mixt_tree->c_lnL; + + Free(permut); + + + if(lk_new < lk_old - tree->mod->s_opt->min_diff_lk_global) + { + PhyML_Printf("\n. lk_new: %f lk_old: %f",lk_new,lk_old); + assert(FALSE); + } + + if(fabs(lk_new-lk_old) < tree->mod->s_opt->min_diff_lk_local) break; + } + /* while(++iter < tree->mod->s_opt->brent_it_max); */ + while(++iter < 1); + + Free(opt_val); + + if(iter == tree->mod->s_opt->brent_it_max) + { + if(tree->verbose > VL0) + { + PhyML_Printf("\n. Failed to optimize GTR parameters this round..."); + } + } + } + } + + tree = tree->next; + if(!tree) break; + + } + while(1); + + if(r_mat) Free(r_mat); + + + Set_Update_Eigen(NO,mixt_tree->mod); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_TsTv(t_tree *mixt_tree, int verbose) +{ + scalar_dbl **tstv; + int n_tstv; + t_tree *tree; + int i; + + Set_Update_Eigen(YES,mixt_tree->mod); + + tstv = NULL; + n_tstv = 0; + tree = mixt_tree; + + do { -/* printf("\n. pinv0 = %f, pinv1 = %f, alpha0 = %f, alpha1 = %f",pinv0,pinv1,alpha0,alpha1); */ -/* printf("\n. slope = %f intercept = %f",slope,intercept); */ + if(tree->is_mixt_tree == YES) tree = tree->next; - K = 0.381966; + for(i=0;imod->kappa == tstv[i]) break; - if(alpha1 < alpha0) - { - c = alpha0; - b = alpha1; - fc = f0; - fb = f1; - - a = (0.1 < alpha1)?(0.1):(0.5*alpha1); - tree->mod->alpha = a; - tree->mod->pinvar = slope * tree->mod->alpha + intercept; - if(tree->mod->pinvar > 1.0) tree->mod->pinvar = 0.9; - if(tree->mod->pinvar < 0.0) tree->mod->pinvar = 0.001; - tree->both_sides = 1; - Lk(tree); - Optimize_Br_Len_Serie(tree->noeud[0],tree->noeud[0]->v[0], - tree->noeud[0]->b[0],tree,tree->data); - fa = tree->c_lnL; - - iter = 0; - -/* printf("\n. a=%f, b=%f, c=%f, fa=%f, fb=%f, fc=%f (alpha=%f pinv=%f)",a,b,c,fa,fb,fc,tree->mod->alpha,tree->mod->pinvar); */ - - while(fa > fb) - { - a = a/5.; - tree->mod->alpha = a; - tree->mod->pinvar = slope * tree->mod->alpha + intercept; - if(tree->mod->pinvar > 1.0) tree->mod->pinvar = 0.9; - if(tree->mod->pinvar < 0.0) tree->mod->pinvar = 0.001; - tree->both_sides = 1; - Lk(tree); - Optimize_Br_Len_Serie(tree->noeud[0],tree->noeud[0]->v[0], - tree->noeud[0]->b[0],tree,tree->data); - fa = tree->c_lnL; -/* printf("\n+ a=%f, b=%f, c=%f, fa=%f, fb=%f, fc=%f",a,b,c,fa,fb,fc); */ - if(iter++ > 10) return 0; - } - } - else - { - a = alpha0; - b = alpha1; - fa = f0; - fb = f1; - - c = (alpha1 < 2.)?(2.0):(2.*alpha1); - tree->mod->alpha = c; - tree->mod->pinvar = slope * tree->mod->alpha + intercept; - if(tree->mod->pinvar > 1.0) tree->mod->pinvar = 0.9; - if(tree->mod->pinvar < 0.0) tree->mod->pinvar = 0.001; - tree->both_sides = 1; - Lk(tree); - Optimize_Br_Len_Serie(tree->noeud[0],tree->noeud[0]->v[0], - tree->noeud[0]->b[0],tree,tree->data); - fc = tree->c_lnL; - -/* printf("\n. a=%f, b=%f, c=%f, fa=%f, fb=%f, fc=%f (alpha=%f pinv=%f)",a,b,c,fa,fb,fc,tree->mod->alpha,tree->mod->pinvar); */ - - iter = 0; - while(fc > fb) - { - c = c*2.; - tree->mod->alpha = c; - tree->mod->pinvar = slope * tree->mod->alpha + intercept; - if(tree->mod->pinvar > 1.0) tree->mod->pinvar = 0.9; - if(tree->mod->pinvar < 0.0) tree->mod->pinvar = 0.001; - tree->both_sides = 1; - Lk(tree); - Optimize_Br_Len_Serie(tree->noeud[0],tree->noeud[0]->v[0], - tree->noeud[0]->b[0],tree,tree->data); - fc = tree->c_lnL; -/* printf("\n+ a=%f, b=%f, c=%f, fa=%f, fb=%f, fc=%f",a,b,c,fa,fb,fc); */ - if(iter++ > 10) return 0; - } - } + if(i == n_tstv) + { + if(!tstv) tstv = (scalar_dbl **)mCalloc(1,sizeof(scalar_dbl *)); + else tstv = (scalar_dbl **)mRealloc(tstv,n_tstv+1,sizeof(scalar_dbl *)); + tstv[n_tstv] = tree->mod->kappa; + n_tstv++; + + if(tree->mod->s_opt->opt_kappa == YES) + { + phydbl a,c; + + /* a = tree->mod->kappa->v * .1; */ + /* c = tree->mod->kappa->v * 10.; */ + a = TSTV_MIN; + c = TSTV_MAX; + + Generic_Brent_Lk(&(tree->mod->kappa->v), + a,c, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + + if(verbose) + { + Print_Lk(mixt_tree,"[Ts/ts ratio ]"); + PhyML_Printf("[%10f]",tree->mod->kappa->v); + } + } + } + + tree = tree->next; + + } + while(tree); + + if(tstv) Free(tstv); + + Set_Update_Eigen(NO,mixt_tree->mod); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_Pinv(t_tree *mixt_tree, int verbose) +{ + scalar_dbl **pinv; + int n_pinv; + t_tree *tree; + int i; + + Set_Update_Eigen(NO,mixt_tree->mod); + + pinv = NULL; + n_pinv = 0; + tree = mixt_tree; + + do + { + for(i=0;imod->ras->pinvar == pinv[i]) break; + + if(i == n_pinv) + { + if(!pinv) pinv = (scalar_dbl **)mCalloc(1,sizeof(scalar_dbl *)); + else pinv = (scalar_dbl **)mRealloc(pinv,n_pinv+1,sizeof(scalar_dbl *)); + pinv[n_pinv] = tree->mod->ras->pinvar; + n_pinv++; + + if(tree->mod->s_opt->opt_pinvar == YES && (tree->mod->s_opt->opt_alpha == NO || tree->mod->ras->n_catg == 1)) + { + Generic_Brent_Lk(&(tree->mod->ras->pinvar->v), + PINV_MIN,PINV_MAX, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + + if(verbose) + { + Print_Lk(tree,"[P-inv ]"); + PhyML_Printf("[%10f]",tree->mod->ras->pinvar->v); + } + } + } + + tree = tree->next_mixt; + + } + while(tree); + + if(pinv) Free(pinv); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_Alpha(t_tree *mixt_tree, int verbose) +{ + scalar_dbl **alpha; + int n_alpha; + t_tree *tree; + int i; + + Set_Update_Eigen(NO,mixt_tree->mod); + + alpha = NULL; + n_alpha = 0; + tree = mixt_tree; + + do + { + + if(tree->mod->s_opt->opt_alpha == YES && tree->mod->ras->n_catg > 1) + { + for(i=0;imod->ras->alpha == alpha[i]) break; + + if(i == n_alpha) + { + if(!alpha) alpha = (scalar_dbl **)mCalloc(1,sizeof(scalar_dbl *)); + else alpha = (scalar_dbl **)mRealloc(alpha,n_alpha+1,sizeof(scalar_dbl *)); + alpha[n_alpha] = tree->mod->ras->alpha; + n_alpha++; + + if(tree->mod->s_opt->opt_alpha == YES && + tree->mod->ras->free_mixt_rates == NO && + tree->mod->s_opt->opt_pinvar == NO) + { + + if(tree->mod->ras->n_catg > 1) + { + Generic_Brent_Lk(&(tree->mod->ras->alpha->v), + ALPHA_MIN,ALPHA_MAX, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + } + if(verbose) + { + Print_Lk(mixt_tree,"[Alpha ]"); + PhyML_Printf("[%10f]",tree->mod->ras->alpha->v); + } + } + } + } + tree = tree->next_mixt; + } + while(tree); + + if(alpha) Free(alpha); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_Free_Rate(t_tree *mixt_tree, int verbose) +{ + t_tree *tree; + int fast; + int i,pos,failed; + int *permut; + phydbl lk_before, lk_after; + tree = mixt_tree; + + lk_before = lk_after = UNLIKELY; + + do + { + if((tree->mod->s_opt->opt_free_mixt_rates) && (tree->mod->ras->free_mixt_rates == YES) && (tree->mod->ras->n_catg > 1)) + { + if(tree->mod->s_opt->serial_free_rates == YES) + { + fast = YES; + lk_before = tree->c_lnL; + Optimize_Free_Rate_Weights(tree,fast,verbose); + lk_after = tree->c_lnL; + Optimize_Free_Rate_Rr(tree,fast,verbose); + lk_after = tree->c_lnL; + + if(lk_after < lk_before - tree->mod->s_opt->min_diff_lk_global) + { + PhyML_Fprintf(stderr,"\n. lk_before: %f lk_after: %f diff: %G",lk_before,lk_after,lk_before-lk_after); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + } + + if(FABS(lk_before - lk_after) > 0.001) + { + phydbl **x,*cpy; + + x = (phydbl **)mCalloc(2*tree->mod->ras->n_catg,sizeof(phydbl *)); + cpy = (phydbl *)mCalloc(2*tree->mod->ras->n_catg,sizeof(phydbl)); + + + lk_before = tree->c_lnL; + + pos = 0; + for(i=0;imod->ras->n_catg;i++) x[pos++] = tree->mod->ras->gamma_rr_unscaled->v+i; + for(i=0;imod->ras->n_catg;i++) x[pos++] = tree->mod->ras->gamma_r_proba_unscaled->v+i; + + pos = 0; + for(i=0;imod->ras->n_catg;i++) cpy[pos++] = tree->mod->ras->gamma_rr_unscaled->v[i]; + for(i=0;imod->ras->n_catg;i++) cpy[pos++] = tree->mod->ras->gamma_r_proba_unscaled->v[i]; + + + for(i=0;i<2*tree->mod->ras->n_catg;++i) *(x[i]) = log(MAX(1.E-10,*(x[i]))); + + failed = YES; + BFGS_Nonaligned(tree,x,2*tree->mod->ras->n_catg,1.e-5,tree->mod->s_opt->min_diff_lk_global,1.e-5,YES,NO, + &Return_Abs_Lk, + &Num_Derivative_Several_Param_Nonaligned, + &Lnsrch_Nonaligned,&failed); + + + for(i=0;i<2*tree->mod->ras->n_catg;++i) *(x[i]) = exp(MIN(1.E+2,*(x[i]))); + + + if(failed == YES) + { + pos = 0; + for(i=0;imod->ras->n_catg;i++) tree->mod->ras->gamma_rr_unscaled->v[i] = cpy[pos++]; + for(i=0;imod->ras->n_catg;i++) tree->mod->ras->gamma_r_proba_unscaled->v[i] = cpy[pos++]; + + permut = Permutate(tree->mod->ras->n_catg); + + + for(i=0;imod->ras->n_catg;++i) + { + phydbl a,c; + + a = tree->mod->ras->gamma_rr_unscaled->v[permut[i]] / 2.; + c = tree->mod->ras->gamma_rr_unscaled->v[permut[i]] * 2.+1; + + Generic_Brent_Lk(&(tree->mod->ras->gamma_rr_unscaled->v[permut[i]]), + a,c, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + /* PhyML_Printf("\n. ++ lk=%f",mixt_tree->c_lnL); */ + } + + for(i=0;imod->ras->n_catg;++i) + { + phydbl a,c; + + a = tree->mod->ras->gamma_r_proba_unscaled->v[permut[i]] / 2.; + c = tree->mod->ras->gamma_r_proba_unscaled->v[permut[i]] * 2.; + + Generic_Brent_Lk(&(tree->mod->ras->gamma_r_proba_unscaled->v[permut[i]]), + a,c, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + /* PhyML_Printf("\n. ++ lk=%f",mixt_tree->c_lnL); */ + } + + Free(permut); + + } + + + lk_after = tree->c_lnL; + + if(lk_after < lk_before - tree->mod->s_opt->min_diff_lk_global) + { + PhyML_Fprintf(stderr,"\n. lk_before: %f lk_after: %f diff: %G",lk_before,lk_after,lk_before-lk_after); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + Free(x); + Free(cpy); + } + + + } + tree = tree->next_mixt; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_Free_Rate_Rr(t_tree *tree, int fast, int verbose) +{ + phydbl lk_before, lk_after; + + lk_before = tree->c_lnL; + + + if(tree->prev == NULL && tree->next == NULL) + { + int i; + phydbl wm; + + /* tree->mod->s_opt->curr_opt_free_rates = YES; */ + + if(fast == YES) + { + for(i=0;imod->ras->n_catg;i++) tree->mod->ras->skip_rate_cat[i] = YES; + tree->mod->ras->normalise_rr = NO; + + wm = Weighted_Mean(tree->mod->ras->gamma_rr_unscaled->v, + tree->mod->ras->gamma_r_proba->v, + tree->mod->ras->n_catg); + + tree->mod->ras->free_rate_mr->v = 100.; + For(i,2*tree->n_otu-1) tree->a_edges[i]->l->v /= (wm * tree->mod->ras->free_rate_mr->v); + } + + + for(i=0;imod->ras->n_catg-1;i++) + { + if(fast == YES) tree->mod->ras->skip_rate_cat[i] = NO; + + phydbl a,c; + + a = tree->mod->ras->gamma_rr_unscaled->v[i] * .1; + c = tree->mod->ras->gamma_rr_unscaled->v[i] * 10.+1; + + Generic_Brent_Lk(&(tree->mod->ras->gamma_rr_unscaled->v[i]), + a,c, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + + if(fast == YES) tree->mod->ras->skip_rate_cat[i] = YES; + + lk_after = tree->c_lnL; + + if(lk_after < lk_before - tree->mod->s_opt->min_diff_lk_global) + { + PhyML_Fprintf(stderr,"\n. lk_before: %f lk_after: %f diff: %G",lk_before,lk_after,lk_before-lk_after); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + } + + if(fast == YES) + { + for(i=0;imod->ras->n_catg;i++) tree->mod->ras->skip_rate_cat[i] = NO; + tree->mod->ras->normalise_rr = YES; + + wm = Weighted_Mean(tree->mod->ras->gamma_rr_unscaled->v, + tree->mod->ras->gamma_r_proba->v, + tree->mod->ras->n_catg); + + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->l->v *= (wm * tree->mod->ras->free_rate_mr->v); + } + + /* tree->mod->s_opt->curr_opt_free_rates = NO; */ + + } + else + { + int i; + for(i=0;imod->ras->n_catg-1;i++) + { + phydbl a,c; + + a = tree->mod->ras->gamma_rr_unscaled->v[i] * .1; + c = tree->mod->ras->gamma_rr_unscaled->v[i] * 10.+1.; + + Generic_Brent_Lk(&(tree->mod->ras->gamma_rr_unscaled->v[i]), + a,c, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + } + } + + lk_after = tree->c_lnL; + + if(lk_after < lk_before - tree->mod->s_opt->min_diff_lk_global) + { + PhyML_Fprintf(stderr,"\n. lk_before: %f lk_after: %f diff: %G",lk_before,lk_after,lk_before-lk_after); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + if(verbose) Print_Lk(tree,"[Rate class values ]"); + + /* int i; */ + /* for(i=0;imod->ras->n_catg;i++) */ + /* { */ + /* printf("\n+ c %2d p: %15f r: %15f up: %15f ur: %5f", */ + /* i+1, */ + /* tree->mod->ras->gamma_r_proba->v[i], */ + /* tree->mod->ras->gamma_rr->v[i], */ + /* tree->mod->ras->gamma_r_proba_unscaled->v[i], */ + /* tree->mod->ras->gamma_rr_unscaled->v[i]); */ + /* } */ + /* fflush(NULL); */ + + /* printf("\n. LK: %f",Lk(NULL,tree)); */ + + /* int i; */ + /* printf("\n"); */ + /* printf("X*X %f ",tree->c_lnL); */ + /* /\* for(i=0;imod->ras->n_catg;i++) printf("%f ",tree->mod->ras->gamma_rr_unscaled->v[i]); *\/ */ + /* for(i=0;imod->ras->n_catg;i++) printf("%f ",tree->mod->ras->gamma_rr->v[i]); */ + /* for(i=0;imod->ras->n_catg;i++) printf("%f ",tree->mod->ras->gamma_r_proba->v[i]); */ + /* For(i,2*tree->n_otu-3) printf("%f ",tree->a_edges[i]->l->v); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_Free_Rate_Weights(t_tree *tree, int fast, int verbose) +{ + int i; + phydbl wm; + phydbl lk_before, lk_after; + + + lk_before = tree->c_lnL; + + /*! Only skip tree traversal when data is not partitionned */ + if(tree->prev == NULL && tree->next == NULL && fast == YES) + { + tree->mod->s_opt->skip_tree_traversal = YES; + tree->mod->ras->normalise_rr = NO; + + wm = Weighted_Mean(tree->mod->ras->gamma_rr_unscaled->v, + tree->mod->ras->gamma_r_proba->v, + tree->mod->ras->n_catg); + + tree->mod->ras->free_rate_mr->v = 100.; + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->l->v /= (wm * tree->mod->ras->free_rate_mr->v); + } + + for(i=0;imod->ras->n_catg-1;i++) + { + phydbl a,c; + a = tree->mod->ras->gamma_r_proba_unscaled->v[i] * .1; + c = tree->mod->ras->gamma_r_proba_unscaled->v[i] * 10.+1; + + Generic_Brent_Lk(&(tree->mod->ras->gamma_r_proba_unscaled->v[i]), + a,c, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,tree,NULL,NO); + } + + if(tree->mod->s_opt->skip_tree_traversal == YES && fast == YES) + { + tree->mod->s_opt->skip_tree_traversal = NO; + tree->mod->ras->normalise_rr = YES; + + wm = Weighted_Mean(tree->mod->ras->gamma_rr_unscaled->v, + tree->mod->ras->gamma_r_proba->v, + tree->mod->ras->n_catg); + + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->l->v *= (wm * tree->mod->ras->free_rate_mr->v); + } + + lk_after = tree->c_lnL; + + if(lk_after < lk_before - tree->mod->s_opt->min_diff_lk_global) + { + PhyML_Fprintf(stderr,"\n. lk_before: %f lk_after: %f diff: %G",lk_before,lk_after,lk_before-lk_after); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit(""); + } + + if(verbose) Print_Lk(tree,"[Rate class freqs. ]"); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_State_Freqs(t_tree *mixt_tree, int verbose) +{ + /* vect_dbl **freqs; */ + /* int n_freqs; */ + t_tree *tree; + int i; + phydbl lk_new,lk_old; + int *permut; + phydbl *opt_val; + + Set_Update_Eigen(YES,mixt_tree->mod); + + /* freqs = NULL; */ + /* n_freqs = 0; */ + tree = mixt_tree; + lk_old = UNLIKELY; + lk_new = UNLIKELY; + opt_val = NULL; + + do + { + if(tree->next) tree = tree->next; + + if((tree->mod->s_opt->opt_state_freq) && (tree->io->datatype == NT)) + { + int iter; + + opt_val = (phydbl *)mCalloc(tree->mod->ns,sizeof(phydbl)); + + iter = 0; + do + { + lk_old = mixt_tree->c_lnL; + int failed = NO; + + for(i=0;imod->ns;i++) opt_val[i] = tree->mod->e_frq->pi_unscaled->v[i]; + + /* PhyML_Printf("\n. -- BFGS lk=%f",mixt_tree->c_lnL); */ + BFGS(mixt_tree,tree->mod->e_frq->pi_unscaled->v,tree->mod->ns,1.e-5,tree->mod->s_opt->min_diff_lk_local,1.e-2,NO,NO, + &Return_Abs_Lk, + &Num_Derivative_Several_Param, + &Lnsrch,&failed); + /* PhyML_Printf("\n. ++ BFGS lk=%f",mixt_tree->c_lnL); */ + + + if(failed == YES) for(i=0;imod->ns;i++) tree->mod->e_frq->pi_unscaled->v[i] = opt_val[i]; + + + permut = Permutate(tree->mod->ns); + + for(i=0;imod->ns;++i) + { + phydbl a,c; + + a = tree->mod->e_frq->pi_unscaled->v[permut[i]] / 2.; + c = tree->mod->e_frq->pi_unscaled->v[permut[i]] * 2.+1; + + /* PhyML_Printf("\n. -- lk=%f",mixt_tree->c_lnL); */ + Generic_Brent_Lk(&(tree->mod->e_frq->pi_unscaled->v[permut[i]]), + /* UNSCALED_E_FRQ_MIN,UNSCALED_E_FRQ_MAX, */ + a,c, + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + /* PhyML_Printf("\n. ++ lk=%f",mixt_tree->c_lnL); */ + } + + Free(permut); + + if(verbose) + { + Print_Lk(mixt_tree,"[Nucleotide freqs. ]"); + } + + lk_new = mixt_tree->c_lnL; + + /* PhyML_Printf("\n. lk_new=%f lk_old=%f",lk_new,lk_old); */ + assert(lk_new > lk_old - tree->mod->s_opt->min_diff_lk_local); + if(fabs(lk_new-lk_old) < tree->mod->s_opt->min_diff_lk_local) break; + } + /* while(++iter < tree->mod->s_opt->brent_it_max); */ + while(++iter < 1); + + Free(opt_val); + + if(iter == tree->mod->s_opt->brent_it_max) + { + if(tree->verbose > VL0) + { + PhyML_Printf("\n. Failed to optimize frequency parameters this round..."); + } + } + } + - if(fabs(b - c) > fabs(a - b)) - { - x0 = a; x1 = b; x3 = c; - x2 = b + K * fabs(b - c); - - f0 = fa; - f1 = fb; - f3 = fc; - tree->mod->alpha = x2; - tree->mod->pinvar = slope * tree->mod->alpha + intercept; - if(tree->mod->pinvar > 1.0) tree->mod->pinvar = 0.9; - if(tree->mod->pinvar < 0.0) tree->mod->pinvar = 0.001; - tree->both_sides = 1; - Lk(tree); - Optimize_Br_Len_Serie(tree->noeud[0],tree->noeud[0]->v[0], - tree->noeud[0]->b[0],tree,tree->data); - f2 = tree->c_lnL; - } - else /* |b -c| < |a - b| */ - { - x0 = a; x2 = b; x3 = c; - x1 = b - K * fabs(b - a); - - f0 = fa; - f2 = fb; - f3 = fc; - tree->mod->alpha = x1; - tree->mod->pinvar = slope * tree->mod->alpha + intercept; - if(tree->mod->pinvar > 1.0) tree->mod->pinvar = 0.9; - if(tree->mod->pinvar < 0.0) tree->mod->pinvar = 0.001; - tree->both_sides = 1; - Lk(tree); - Optimize_Br_Len_Serie(tree->noeud[0],tree->noeud[0]->v[0], - tree->noeud[0]->b[0],tree,tree->data); - f1 = tree->c_lnL; - } + tree = tree->next; - iter = 0; + } + while(tree); + + + Set_Update_Eigen(NO,mixt_tree->mod); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_Rmat_Weights(t_tree *mixt_tree, int verbose) +{ + scalar_dbl *r_mat_weight; + + Set_Update_Eigen(NO,mixt_tree->mod); + + if(mixt_tree->is_mixt_tree == NO) return; + + r_mat_weight = mixt_tree->next->mod->r_mat_weight; + + if(mixt_tree->next->mod->s_opt->opt_rmat_weight == YES) + { do - { -/* printf("\n. x0=%f, x1=%f, x2=%f, x3=%f, f0=%f, f1=%f, f2=%f, f3=%f", */ -/* x0,x1,x2,x3,f0,f1,f2,f3); */ - - if(f1 > f2) - { - x3 = x2; - x2 = x1; - x1 = x2 - K * fabs(x2 - x0); - - f3 = f2; - f2 = f1; - - tree->mod->alpha = x1; - tree->mod->pinvar = slope * tree->mod->alpha + intercept; - if(tree->mod->pinvar > 1.0) tree->mod->pinvar = 0.9; - if(tree->mod->pinvar < 0.0) tree->mod->pinvar = 0.001; - tree->both_sides = 1; - Lk(tree); - Optimize_Br_Len_Serie(tree->noeud[0],tree->noeud[0]->v[0], - tree->noeud[0]->b[0],tree,tree->data); - f1 = tree->c_lnL; - if(f1 > best_lnL) - { - Record_Br_Len(tree); - best_alpha = tree->mod->alpha; - best_pinv = tree->mod->pinvar; - } -/* printf("\n> f1=%f",f1); */ - } - else /* f1 < f2 */ - { - x0 = x1; - x1 = x2; - x2 = x2 + K * fabs(x3 - x2); - - f0 = f1; - f1 = f2; - - tree->mod->alpha = x2; - tree->mod->pinvar = slope * tree->mod->alpha + intercept; - if(tree->mod->pinvar > 1.0) tree->mod->pinvar = 0.9; - if(tree->mod->pinvar < 0.0) tree->mod->pinvar = 0.001; - tree->both_sides = 1; - Lk(tree); - Optimize_Br_Len_Serie(tree->noeud[0],tree->noeud[0]->v[0], - tree->noeud[0]->b[0],tree,tree->data); - f2 = tree->c_lnL; - if(f2 > best_lnL) - { - Record_Br_Len(tree); - best_alpha = tree->mod->alpha; - best_pinv = tree->mod->pinvar; - } -/* printf("\n> f2=%f",f2); */ - } - - if(fabs(f1 - f2) < 0.01) break; - - iter++; - - }while(iter < 100); + { + phydbl a,c; + + a = r_mat_weight->v * .1; + c = r_mat_weight->v * 10.; + + Generic_Brent_Lk(&(r_mat_weight->v), + a,c, + mixt_tree->mod->s_opt->min_diff_lk_local, + mixt_tree->mod->s_opt->brent_it_max, + mixt_tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + + if(verbose) + { + Print_Lk(mixt_tree,"[Rate mat. weights ]"); + } + + r_mat_weight = r_mat_weight->next; + } + while(r_mat_weight); } + + Set_Update_Eigen(NO,mixt_tree->mod); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Optimize_Efrq_Weights(t_tree *mixt_tree, int verbose) +{ + scalar_dbl *e_frq_weight; + + Set_Update_Eigen(NO,mixt_tree->mod); + + if(mixt_tree->is_mixt_tree == NO) return; + + e_frq_weight = mixt_tree->next->mod->e_frq_weight; + + + if(mixt_tree->next->mod->s_opt->opt_efrq_weight == YES) + { + do + { + phydbl a,c; + + a = e_frq_weight->v * .1; + c = e_frq_weight->v * 10.+1; + + Generic_Brent_Lk(&(e_frq_weight->v), + a,c, + mixt_tree->mod->s_opt->min_diff_lk_local, + mixt_tree->mod->s_opt->brent_it_max, + mixt_tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + + if(verbose) + { + Print_Lk(mixt_tree,"[Equ. frq. weights ]"); + } + + e_frq_weight = e_frq_weight->next; + } + while(e_frq_weight); + } + + Set_Update_Eigen(NO,mixt_tree->mod); + +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Optimize_Lambda(t_tree *mixt_tree, int verbose) +{ + scalar_dbl **lambda; + int n_lambda; + t_tree *tree; + int i; + + Set_Update_Eigen(YES,mixt_tree->mod); + + lambda = NULL; + n_lambda = 0; + tree = mixt_tree; + + do + { + if(tree->next) tree = tree->next; + + for(i=0;imod->lambda == lambda[i]) break; + + if(i == n_lambda) + { + if(!lambda) lambda = (scalar_dbl **)mCalloc(1,sizeof(scalar_dbl *)); + else lambda = (scalar_dbl **)mRealloc(lambda,n_lambda+1,sizeof(scalar_dbl *)); + lambda[n_lambda] = tree->mod->lambda; + n_lambda++; + + if(tree->mod->s_opt->opt_lambda) + { + Generic_Brent_Lk(&(tree->mod->lambda->v), + 0.001,100., + tree->mod->s_opt->min_diff_lk_local, + tree->mod->s_opt->brent_it_max, + tree->mod->s_opt->quickdirty, + Wrap_Lk,NULL,mixt_tree,NULL,NO); + + if(verbose) + { + Print_Lk(mixt_tree,"[Lambda ]"); + PhyML_Printf("[%10f]",tree->mod->lambda->v); + } + } + } + + tree = tree->next; + + } + while(tree); + + if(lambda) Free(lambda); + + Set_Update_Eigen(NO,mixt_tree->mod); - tree->mod->alpha = best_alpha; - tree->mod->pinvar = best_pinv; - Restore_Br_Len(tree); - tree->both_sides = 1; - Lk(tree); -/* printf("\n\n. Init lnL after golden opt = %f",tree->c_lnL); */ - return 1; } + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Least_Square_Node_Ages(t_tree *tree) +{ + + phydbl new_error,cur_error,sum_error; + int i,j; + phydbl young,old; + int dir1,dir2; + t_node *n; + + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + + TIMES_Randomize_Node_Ages(tree); + + assert(fabs(tree->rates->nd_t[tree->n_root->num]) > SMALL); + + cur_error = BIG; + new_error = BIG; + do + { + cur_error = new_error; + + sum_error = 0.0; + for(i=0;i<2*tree->n_otu-1;++i) + { + if(tree->a_nodes[i]->tax == NO) + { + n = tree->a_nodes[i]; + old = -1.; + + dir1 = dir2 = -1; + for(j=0;j<3;++j) + { + if(n->v[j] != n->anc && n->b[j] != tree->e_root) + { + if(dir1 < 0) dir1 = j; + else dir2 = j; + } + else + { + if(n != tree->n_root) old = tree->rates->nd_t[n->anc->num]; + else old = 2.*tree->rates->nd_t[tree->n_root->num]; + } + } + + young = MIN(tree->rates->nd_t[n->v[dir1]->num], + tree->rates->nd_t[n->v[dir2]->num]); + + sum_error += Generic_Brent(tree->rates->nd_t + i, + young,old,1.E-10,10000, + TIMES_Least_Square_Criterion, + tree); + + /* PhyML_Printf("\n. Node %3d%c time: %15f err: %15f young: %15f old: %15f %15f %15f", */ + /* i, */ + /* (n == tree->n_root)?'*':' ', */ + /* tree->rates->nd_t[i], */ + /* sum_error, */ + /* young,old, */ + /* tree->rates->nd_t[n->v[dir1]->num], */ + /* tree->rates->nd_t[n->v[dir2]->num]); */ + } + if(RATES_Check_Node_Times(tree)) Exit("\n"); + } + + sum_error += Generic_Brent(&(tree->rates->clock_r), + tree->rates->min_clock, + tree->rates->max_clock, + 1.E-10,10000, + TIMES_Least_Square_Criterion, + tree); + + /* PhyML_Printf("\n clock_r: %g",tree->rates->clock_r); */ + + new_error = sum_error; + /* assert(new_error < cur_error+SMALL); */ + } + while(fabs(new_error-cur_error) > 1.E-10); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// diff --git a/phyml/optimiz.h b/phyml/optimiz.h index da77563..196a128 100644 --- a/phyml/optimiz.h +++ b/phyml/optimiz.h @@ -10,118 +10,175 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef OPTIMIZ_H #define OPTIMIZ_H -void Optimiz_Ext_Br(arbre *tree); -void Optimize_Alpha(arbre *tree); -void Optimize_Kappa(arbre *tree); -void Optimize_Lambda(arbre *tree); -void Optimize_Param_Parall(arbre *tree); -phydbl Optimize_Branch_Quad(arbre *tree, allseq *alldata, edge *b_fcus); -void Optimize_After_Hide(arbre *tree, allseq *alldata, node *h); -void Round_Optimize(arbre *tree, allseq *data); +#include "utilities.h" +#include "lk.h" +#include "free.h" +#include "models.h" +#include "mg.h" +#include "tiporder.h" + + +void Optimize_Br_Len_Serie(int n_max_iter, t_tree *tree); +void Optimiz_Ext_Br(t_tree *tree); +void Optimize_Param_Parall(t_tree *tree); +phydbl Optimize_Branch_Quad(t_tree *tree, calign *cdata, t_edge *b_fcus); +void Optimize_After_Hide(t_tree *tree, calign *cdata, t_node *h); +void Round_Optimize(t_tree *tree, int n_round_max); int Dist_Seq_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *fa, phydbl *fb, phydbl *fc, - allseq *data, int num1, int num2, model *mod); + calign *data, int num1, int num2, t_mod *mod); phydbl Dist_Seq_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, allseq *data, - int num1, int num2, model *mod); + phydbl *xmin, calign *data, + int num1, int num2, t_mod *mod); phydbl Kappa_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, arbre *tree, allseq *alldata); + phydbl *xmin, t_tree *tree, calign *cdata); phydbl Lambda_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, arbre *tree, allseq *alldata); + phydbl *xmin, t_tree *tree, calign *cdata); phydbl Alpha_Golden_Br_Opt(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, arbre *tree, allseq *alldata, + phydbl *xmin, t_tree *tree, calign *cdata, int n_opt, phydbl *init_l); phydbl Alpha_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol,phydbl *xmin, - arbre *tree, allseq *alldata); + t_tree *tree, calign *cdata); phydbl Br_Len_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, edge *b_fcus, arbre *tree); -phydbl Br_Len_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - edge *b_fcus, arbre *tree, int n_iter_max); + phydbl *xmin, t_edge *b_fcus, t_tree *tree); +phydbl Br_Len_Opt(phydbl *l, t_edge *b, t_tree *tree); int Br_Len_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *fa, phydbl *fb, phydbl *fc, - edge *b_fcus, arbre *tree); -phydbl Optimize_Path_Length(model *mod, allseq *alldata, edge *a, - int lra, edge *b, int lrb, phydbl i_len); -void Optimize_Param_Serie(node *a, node *d, edge *b_fcus, arbre *tree, - allseq *alldata, int n_passes); -phydbl Optimize_Dist(model *mod, phydbl init, allseq *twoseqs); + t_edge *b_fcus, t_tree *tree); +phydbl Optimize_Path_Length(t_mod *mod, calign *cdata, t_edge *a, + int lra, t_edge *b, int lrb, phydbl i_len); +void Optimize_Param_Serie(t_node *a, t_node *d, t_edge *b_fcus, t_tree *tree, + calign *cdata, int n_passes); +phydbl Optimize_Dist(t_mod *mod, phydbl init, calign *twoseqs); phydbl Pinvar_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, arbre *tree, allseq *alldata, int n_iter_max); -void Optimize_Pinvar(arbre *tree); + phydbl *xmin, t_tree *tree, calign *cdata, int n_iter_max); +void Optimize_Pinvar(t_tree *tree); int Lambda_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *fa, phydbl *fb, phydbl *fc, - arbre *tree); + t_tree *tree); int Kappa_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *fa, phydbl *fb, phydbl *fc, - arbre *tree); + t_tree *tree); int Alpha_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *fa, phydbl *fb, phydbl *fc, - arbre *tree); + t_tree *tree); int Pinvar_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *fa, phydbl *fb, phydbl *fc, - arbre *tree); -void Optimiz_All_Free_Param(arbre *tree, int verbose); -void Optimiz_RRparam_GTR(arbre *tree, int num_param); + t_tree *tree); +void Optimiz_All_Free_Param(t_tree *tree, int verbose); +void Optimiz_RRparam_GTR(t_tree *tree, int num_param); phydbl RRparam_GTR_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, arbre *tree, allseq *alldata, phydbl *param, int n_iter_max); + phydbl *xmin, t_tree *tree, calign *cdata, phydbl *param, int n_iter_max); -int Powell_GTR_Param(arbre *tree, phydbl *p, int n, phydbl ftol); -phydbl Linmin_GTR_Param(arbre *tree,phydbl *p, phydbl *xi, int n); -phydbl F1dim(arbre *tree, phydbl x, phydbl *p, phydbl *xi, phydbl n); +int Powell_GTR_Param(t_tree *tree, phydbl *p, int n, phydbl ftol); +phydbl Linmin_GTR_Param(t_tree *tree,phydbl *p, phydbl *xi, int n); +phydbl F1dim(t_tree *tree, phydbl x, phydbl *p, phydbl *xi, phydbl n); int Mnbrak_1dim(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *fa, phydbl *fb, phydbl *fc, - arbre *tree, + t_tree *tree, phydbl *p, phydbl *xi, phydbl n); phydbl Brent_1dim(phydbl ax, phydbl bx, phydbl cx, phydbl tol, phydbl *xmin, - arbre *tree, + t_tree *tree, phydbl *p, phydbl *xi, phydbl n); -int Min_With_Derivatives(arbre *tree, phydbl *p, int n, phydbl ftol, phydbl step_size, +int Min_With_Derivatives(t_tree *tree, phydbl *p, int n, phydbl ftol, phydbl step_size, phydbl (*func) (), void (*dfunc)(), phydbl (*linmin)()); -void BFGS(arbre *tree, phydbl *p, int n, phydbl gtol, phydbl step_size, - phydbl(*func)(), void (*dfunc)(), void (*lnsrch)(),int *failed); -void Lnsrch_RR_Param(arbre *tree, int n, phydbl *xold, phydbl fold, phydbl *g, phydbl *p, phydbl *x, - phydbl *f, phydbl stpmax, int *check); -void Optimize_Single_Param_Generic(arbre *tree, phydbl *param, phydbl lim_inf, phydbl lim_sup, phydbl tol, int n_max_iter); +void BFGS(t_tree *tree, + phydbl *p, + int n, + phydbl gtol, + phydbl difff, + phydbl step_size, + int logt, + int is_positive, + phydbl(*func)(t_tree *tree), + int(*dfunc)(t_tree *tree,phydbl *param,int n_param,phydbl stepsize,int logt,phydbl(*func)(t_tree *tree),phydbl *derivatives, int is_positive), + int(*lnsrch)(t_tree *tree, int n, phydbl *xold, phydbl fold,phydbl *g, phydbl *p, phydbl *x,phydbl *f, phydbl stpmax, int *check, int logt, int is_positive), + int *failed); + +void BFGS_Nonaligned(t_tree *tree, + phydbl **p, + int n, + phydbl gtol, + phydbl difff, + phydbl step_size, + int logt, + int is_positive, + phydbl(*func)(t_tree *tree), + int(*dfunc_nonaligned)(t_tree *tree,phydbl **param,int n_param,phydbl stepsize,int logt,phydbl(*func)(t_tree *tree),phydbl *derivatives, int is_positive), + int(*lnsrch_nonaligned)(t_tree *tree, int n, phydbl **xold, phydbl fold,phydbl *g, phydbl *p, phydbl *x,phydbl *f, phydbl stpmax, int *check, int logt, int is_positive), + int *failed); + + +void Optimize_Single_Param_Generic(t_tree *tree, phydbl *param, phydbl lim_inf, phydbl lim_sup, phydbl tol, int n_max_iter, int quickdirty); +int Generic_Brak_Lk(phydbl *param, + phydbl *ax, phydbl *bx, phydbl *cx, + phydbl *fa, phydbl *fb, phydbl *fc, + phydbl min, phydbl max, + phydbl (*obj_func)(t_edge *,t_tree *,supert_tree *), + t_edge *branch, t_tree *tree, supert_tree *stree); int Generic_Brak(phydbl *param, phydbl *ax, phydbl *bx, phydbl *cx, phydbl *fa, phydbl *fb, phydbl *fc, phydbl lim_inf, phydbl lim_sup, - arbre *tree); -phydbl Generic_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, arbre *tree, int n_iter_max); -void Optimize_Br_Len_Serie(node *a, node *d, edge *b_fcus, arbre *tree,allseq *alldata); -void Lnsrch_Nucleotide_Frequencies(arbre *tree, int n, phydbl *xold, - phydbl fold, phydbl *g, phydbl *p, phydbl *x, - phydbl *f, phydbl stpmax, int *check); - -void Optimize_Global_Rate(arbre *tree); -phydbl Br_Len_Brent_Default(edge *b_fcus, arbre *tree); - -void EM_Dist(model *mod, allseq *data); + t_tree *tree); +void Optimize_Br_Len_Serie_Post(t_node *a, t_node *d, t_edge *b_fcus, t_tree *tree); +void Optimize_Global_Rate(t_tree *tree); +phydbl Fast_Br_Len(t_edge *b, t_tree *tree, int approx); + +void EM_Dist(t_mod *mod, calign *data); phydbl Dist_F_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, int n_iter_max, - phydbl *param, phydbl *F, model *mod); -int Dist_F_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *F, phydbl *param, model *mod); -void Opt_Dist_F(phydbl *dist, phydbl *F, model *mod); + phydbl *param, phydbl *F, t_mod *mod); +int Dist_F_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *F, phydbl *param, t_mod *mod); +void Opt_Dist_F(phydbl *dist, phydbl *F, t_mod *mod); phydbl Missing_Dist_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, int n_iter_max, int x, int y, matrix *mat); int Missing_Dist_Brak(phydbl *ax, phydbl *bx, phydbl *cx, int x, int y, matrix *mat); void Opt_Missing_Dist(int x, int y, matrix *mat); -int Optimiz_Alpha_And_Pinv(arbre *tree); -void Lnsrch_RR_Cov_Param(arbre *tree, int n, phydbl *xold, phydbl fold, - phydbl *g, phydbl *p, phydbl *x, - phydbl *f, phydbl stpmax, int *check); +int Optimiz_Alpha_And_Pinv(t_tree *tree, int verbose); phydbl Node_Time_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - node *anc, node *des, arbre *tree, int n_iter_max); + t_node *anc, t_node *des, t_tree *tree, int n_iter_max); phydbl Time_Stamps_Mult_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - arbre *tree, int n_iter_max); + t_tree *tree, int n_iter_max); phydbl Branch_Rate_Shape_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, - phydbl *xmin, arbre *tree, int n_iter_max); + phydbl *xmin, t_tree *tree, int n_iter_max); +phydbl Node_Time_Brent_Fixed_Br_Len(phydbl ax, phydbl bx, phydbl cx, phydbl tol, + t_node *n, t_tree *tree, int n_iter_max); + +int Generic_Brent_Lk(phydbl *param, phydbl ax, phydbl cx, phydbl tol, + int n_iter_max, int quickdirty, + phydbl (*obj_func)(t_edge *,t_tree *,supert_tree *), + t_edge *branch, t_tree *tree, supert_tree *stree, int logt); +void Round_Optimize_Node_Heights(t_tree *tree); +void Opt_Node_Heights_Recurr_Pre(t_node *a, t_node *d, t_tree *tree); +void Opt_Node_Heights_Recurr(t_tree *tree); + +int Lnsrch(t_tree *tree, int n, phydbl *xold, phydbl fold, phydbl *g, phydbl *p, phydbl *x, + phydbl *f, phydbl stpmax, int *check, int logt, int is_positive); + +int Lnsrch_Nonaligned(t_tree *tree, int n, phydbl **xold, phydbl fold, phydbl *g, phydbl *p, phydbl *x, + phydbl *f, phydbl stpmax, int *check, int logt, int is_positive); +void Optimize_RR_Params(t_tree *mixt_tree, int verbose); +void Optimize_TsTv(t_tree *mixt_tree, int verbose); +void Optimize_Lambda(t_tree *mixt_tree, int verbose); +void Optimize_Alpha(t_tree *mixt_tree, int verbose); +void Optimize_Pinv(t_tree *mixt_tree, int verbose); +void Optimize_State_Freqs(t_tree *mixt_tree, int verbose); +void Optimize_Rmat_Weights(t_tree *mixt_tree, int verbose); +void Optimize_Efrq_Weights(t_tree *mixt_tree, int verbose); +void Optimize_Free_Rate(t_tree *mixt_tree, int verbose); +void Optimize_Free_Rate_Weights(t_tree *tree, int fast, int verbose); +void Optimize_Free_Rate_Rr(t_tree *tree, int fast, int verbose); +void Optimize_Br_Len_Multiplier(t_tree *tree, int verbose); +phydbl Generic_Brent(phydbl *param, phydbl ax, phydbl cx, phydbl tol,int n_iter_max,phydbl (*obj_func)(t_tree *),t_tree *tree); +void Least_Square_Node_Ages(t_tree *tree); #endif diff --git a/phyml/options.c b/phyml/options.c deleted file mode 100644 index bb21c94..0000000 --- a/phyml/options.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - -PhyML: a program that computes maximum likelihood phylogenies from -DNA or AA homologous sequences. - -Copyright (C) Stephane Guindon. Oct 2003 onward. - -All parts of the source except where indicated are distributed under -the GNU public licence. See http://www.opensource.org for details. - -*/ - -#include -#include "cl.h" -#include "utilities.h" -#include "options.h" -#include "models.h" -#include "free.h" -#include "interface.h" -#ifdef MG -#include "mg.h" -#endif - -/* int T_MAX_FILE; */ -/* phydbl MDBL_MIN; */ -/* phydbl UNLIKELY; */ - -/*********************************************************/ - -void Usage() -{ - - char *BOLD=(char *)mCalloc(10,sizeof(char)); - char *FLAT=(char *)mCalloc(10,sizeof(char)); - char *LINE=(char *)mCalloc(10,sizeof(char)); - char *cha; - - - cha =getenv("OS"); - - if(cha!=NULL) - { - strcpy(BOLD, ""); - strcpy(FLAT, ""); - strcpy(LINE, ""); - } - else - { - strcpy(BOLD, "\033[00;01m"); - strcpy(FLAT, "\033[00;00m"); - strcpy(LINE, "\033[00;04m"); - } - - printf("%sNAME\n" - "%s\t- PhyML %s - \n\n" - "%s\t\''A simple, fast, and accurate algorithm to estimate\n" - "%s\tlarge phylogenies by maximum likelihood.\''\n\n" - "%s\tStephane Guindon and Olivier Gascuel,\n" - "%s\tSystematic Biology 52(5):696-704, 2003.\n\n" - "%s\tPlease cite this paper if you use this software in your publications.\n",BOLD,FLAT,VVERSION,FLAT,FLAT,FLAT,FLAT,FLAT); - - - - printf("%s\nSYNOPSIS:\n\n" - "%s\tphyml %s[command args]\n",BOLD,BOLD,BOLD); - - printf("%s\nCommand options:\n%s",BOLD,FLAT); - - printf("\n\t%s-i (or --input) %sseq_file_name%s\n",BOLD,LINE,FLAT); - printf("\t\t%sseq_file_name%s is the name of the nucleotide or amino-acid sequence file in PHYLIP format.\n",LINE,FLAT); - - printf("\n"); - - printf("%s\n\t-d (or --datatype) ""%sdata_type%s\n",BOLD,LINE,FLAT); - printf("%s\t\tdata_type%s is 'nt' for nucleotide (default) and 'aa' for amino-acid sequences.\n",LINE,FLAT); - - printf("\n"); - - printf("%s\n\t-q (or --sequential)\n",BOLD); - printf("%s\t\tChanges interleaved format (default) to sequential format.\n",FLAT); - - printf("\n"); - - printf("%s\n\t-n (or --multiple) ""%snb_data_sets%s\n",BOLD,LINE,FLAT); - printf("%s\t\tnb_data_sets%s is an integer corresponding to the number of data sets to analyse.\n",LINE,FLAT); - - printf("\n"); - - printf("%s\n\t-b (or --bootstrap) %sint%s\n",BOLD,LINE,FLAT); - printf("\t\t%sint%s > 0 : %sint%s is the number of bootstrap replicates.\n",LINE,FLAT,LINE,FLAT); - printf("\t\t%sint%s = 0 : neither approximate likelihood ratio test nor bootstrap values are computed.\n",LINE,FLAT); - printf("\t\t%sint%s = -1 : approximate likelihood ratio test returning aLRT statistics.\n",LINE,FLAT); - printf("\t\t%sint%s = -2 : approximate likelihood ratio test returning Chi2-based parametric branch supports.\n",LINE,FLAT); - printf("\t\t%sint%s = -3 : minimum of Chi2-based parametric and SH-like branch supports.\n",LINE,FLAT); - printf("\t\t%sint%s = -4 : SH-like branch supports alone.\n",LINE,FLAT); - - printf("\n"); - - printf("%s\n\t-m (or --model) %smodel%s\n",BOLD,LINE,FLAT); - printf("\t\tmodel%s : substitution model name.\n",FLAT); - printf("\t\t%s- %sNucleotide%s-based models : %sHKY85%s (default) | %sJC69%s | %sK80%s | %sF81%s | %sF84%s | %sTN93%s | %sGTR%s | %scustom (*)%s\n", - FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT,LINE,FLAT); - printf("\t\t(*) : for the custom option, a string of six digits identifies the model. For instance, 000000\n"); - printf("\t\t corresponds to F81 (or JC69 provided the distribution of nucleotide frequencies is uniform).\n"); - printf("\t\t 012345 corresponds to GTR. This option can be used for encoding any model that is a nested within GTR.\n"); - printf("\n"); - printf("\t\t%s- %sAmino-acid%s based models : %sWAG%s (default) | %sJTT%s | %sMtREV%s | %sDayhoff%s | %sDCMut%s | %sRtREV%s | %sCpREV%s | %sVT%s\n", - FLAT,LINE,FLAT, - LINE,FLAT, - LINE,FLAT, - LINE,FLAT, - LINE,FLAT, - LINE,FLAT, - LINE,FLAT, - LINE,FLAT, - LINE,FLAT); - printf("\t\t %sBlosum62%s | %sMtMam%s | %sMtArt%s | %sHIVw%s | %sHIVb%s | %scustom%s\n", - LINE,FLAT, - LINE,FLAT, - LINE,FLAT, - LINE,FLAT, - LINE,FLAT, - LINE,FLAT); - - printf("\n"); - - printf("%s\n\t-f %se%s, %sd%s, or %s\"fA fC fG fT\"%s\n",BOLD,LINE,BOLD,LINE,BOLD,LINE,FLAT); - printf("\t\t%se%s : the character frequencies are determined as follows : \n",LINE,FLAT); - printf("%s\t\t- %sNucleotide%s sequences: the equilibrium base frequencies are estimated using maximum likelihood \n",FLAT,LINE,FLAT); - printf("%s\t\t- %sAmino-acid%s sequences: the equilibrium amino-acid frequencies are estimated by counting the\n" -"\t\t occurence of the different amino-acids in the data.\n",FLAT,LINE,FLAT); - printf("\n"); - printf("\t\t%sd%s : the character frequencies are determined as follows : \n",LINE,FLAT); - printf("%s\t\t- %sNucleotide%s sequences: the equilibrium base frequencies are estimated by counting the occurence\n" - "\t\t of the different bases in the alignment.\n",FLAT,LINE,FLAT); - printf("%s\t\t- %sAmino-acid%s sequences: the equilibrium amino-acid frequencies are estimated using the frequencies\n" -"\t\t defined by the substitution model.\n",FLAT,LINE,FLAT); - printf("\n"); - printf("\t\t%s\"fA fC fG fT\"%s : only valid for nucleotide-based models. fA, fC, fG and fT are floating numbers that \n",LINE,FLAT); - printf("\t\t correspond to the frequencies of A, C, G and T respectively.\n"); - - printf("\n"); - - printf("%s\n\t-t (or --ts/tv) %sts/tv_ratio%s\n",BOLD,LINE,FLAT); - printf("\t\tts/tv_ratio%s : transition/transversion ratio. DNA sequences only.\n",FLAT); - printf("\t\tCan be a fixed positive value (ex:4.0) or %se%s to get the maximum likelihood estimate.\n",LINE,FLAT); - - printf("\n"); - - printf("%s\n\t-v (or --pinv) %sprop_invar%s\n",BOLD,LINE,FLAT); - printf("\t\tprop_invar%s : proportion of invariable sites.\n",FLAT); - printf("\t\tCan be a fixed value in the [0,1] range or %se%s to get the maximum likelihood estimate.\n",LINE,FLAT); - - printf("\n"); - - printf("%s\n\t-c (or --nclasses) %snb_subst_cat%s\n",BOLD,LINE,FLAT); - printf("\t\tnb_subst_cat%s : number of relative substitution rate categories. Default : %snb_subst_cat%s=1.\n", - FLAT,LINE,FLAT); - printf("\t\tMust be a positive integer.\n"); - - printf("\n"); - - printf("%s\n\t-a (or --alpha) %sgamma%s\n",BOLD,LINE,FLAT); - printf("\t\tgamma%s : distribution of the gamma distribution shape parameter.\n",FLAT); - printf("\t\tCan be a fixed positive value or %se%s to get the maximum likelihood estimate.\n",LINE,FLAT); - - printf("\n"); - - printf("%s\n\t-s (or --search) %smove%s\n",BOLD,LINE,FLAT); - printf("\t\tTree topology search operation option.\n"); - printf("\t\tCan be either %sNNI%s (default) or %sNNI+SPR%s or %sSPR%s.\n",LINE,FLAT,LINE,FLAT,LINE,FLAT); - - printf("\n"); - - printf("%s\n\t-u (or --inputtree) %suser_tree_file%s\n",BOLD,LINE,FLAT); - printf("\t\tuser_tree_file%s : starting tree filename. The tree must be in Newick format.\n",FLAT); - - printf("\n"); - - printf("%s\n\t-o %sparams%s\n",BOLD,LINE,FLAT); - printf("\t\tThis option focuses on specific parameter optimisation.\n"); - printf("\t\t%sparams%s=tlr : tree topology (t), branch length (l) and rate parameters (r) are optimised.\n",LINE,FLAT); - printf("\t\t%sparams%s=tl : tree topology and branch length are optimised.\n",LINE,FLAT); - printf("\t\t%sparams%s=lr : branch length and rate parameters are optimised.\n",LINE,FLAT); - printf("\t\t%sparams%s=l : branch length are optimised.\n",LINE,FLAT); - printf("\t\t%sparams%s=r : rate parameters are optimised.\n",LINE,FLAT); - printf("\t\t%sparams%s=n : no parameter is optimised.\n",LINE,FLAT); - - printf("\n"); - - printf("%s\n\t--rand_start%s\n",BOLD,FLAT); - printf("\t\tThis option sets the initial tree to random.\n"); - printf("\t\tIt is only valid if SPR searches are to be performed.\n"); - - printf("\n"); - - printf("%s\n\t--n_rand_starts %snum%s\n",BOLD,LINE,FLAT); - printf("\t\tnum%s is the number of initial random trees to be used.\n",FLAT); - printf("\t\tIt is only valid if SPR searches are to be performed.\n"); - - printf("\n"); - - printf("%s\n\t--r_seed %snum%s\n",BOLD,LINE,FLAT); - printf("\t\tnum%s is the seed used to initiate the random number generator.\n",FLAT); - printf("\t\tMust be an integer.\n"); - - printf("\n"); - - printf("%s\n\t--print_site_lnl%s\n",BOLD,FLAT); - printf("\t\t%sPrint the likelihood for each site in file *_phyml_lk.txt.\n",FLAT); - - printf("\n"); - - printf("%s\n\t--print_trace%s\n",BOLD,FLAT); - printf("\t\t%sPrint each phylogeny explored during the tree search process\n",FLAT); - printf("\t\t%sin file *_phyml_trace.txt.\n",FLAT); - - printf("\n"); - - printf("%sPHYLIP-LIKE INTERFACE\n""%s\n\tYou can use phyml with no arguments, in this case change the value of\n",BOLD,FLAT); - printf("%s\ta parameter by typing its corresponding character as shown on screen.\n\n",FLAT); - - printf("%sEXAMPLES\n\n" - "%s\tDNA interleaved sequence file, default parameters : ""%s ./phyml -i seqs1" - "%s\n\tAA interleaved sequence file, default parameters : ""%s ./phyml -i seqs2 -d aa" - "%s\n\tAA sequential sequence file, with customization : ""%s ./phyml -i seqs3 -q -d aa -m JTT -c 4 -a e\n",BOLD,FLAT,BOLD,FLAT,BOLD,FLAT,BOLD); - Exit(""); -} - -/*********************************************************/ - -#define N_SEQUENCEFILE 1 -#define N_DATATYPE 2 -#define N_FORMAT 3 -#define N_DATASETS 4 -#define N_BOOTSTRAPSETS 5 -#define N_MODELNAME 6 -#define N_KAPPA 7 -#define N_PROPORTIONINVAR 7 /*same as kappa*/ -#define N_NBCATG 8 -#define N_ALPHA 9 -#define N_STARTINGTREE 10 -#define N_OPT_TOPO 11 -#define N_OPT_LENGTHSRATES 12 - -#define N_NB_PARAMS_DNA 13 -#define N_NB_PARAMS_AA 12 - -option *Get_Input(int argc, char **argv) -{ - - option *io; - - io = (option *)Make_Input(); - Set_Defaults_Input(io); - Set_Defaults_Model(io->mod); - Set_Defaults_Optimiz(io->mod->s_opt); - - putchar('\n'); - - switch (argc) - { - case 1: -/* #if defined(MG) || defined(USE_OLD_INTERFACE) */ -/* Get_Input_Interactive(io); */ -/* #else */ - Launch_Interface(io); -/* #endif */ - - break; - case 2: - Usage(); - break; - default: - Read_Command_Line(io,argc,argv); - } - - Print_Settings(io); - return io; -} - -/*********************************************************/ - - diff --git a/phyml/pars.c b/phyml/pars.c index 3a06907..cad35d0 100644 --- a/phyml/pars.c +++ b/phyml/pars.c @@ -1,7 +1,7 @@ /* PHYML : a program that computes maximum likelihood phylogenies from -DNA or AA homologous sequences +DNA or AA homologous sequences Copyright (C) Stephane Guindon. Oct 2003 onward @@ -10,50 +10,42 @@ the GNU public licence. See http://www.opensource.org for details. */ -#include "utilities.h" + #include "pars.h" -#include "lk.h" -#include "optimiz.h" -#include "models.h" -#include "free.h" /*********************************************************/ -void Make_Tree_4_Pars(arbre *tree, allseq *alldata, int n_site) -{ - int i; - - tree->site_pars = (int *)mCalloc(tree->n_pattern, sizeof(int)); - tree->step_mat = (int *)mCalloc(tree->mod->ns * tree->mod->ns, sizeof(int)); - For(i,2*tree->n_otu-3) Make_Edge_Pars(tree->t_edges[i],tree); - - Init_Ui_Tips(tree); - Init_P_Pars_Tips(tree); /* Must be called after Init_Ui_Tips is called */ - - Get_Step_Mat(tree); -} - -/*********************************************************/ -int Pars(arbre *tree) +int Pars(t_edge *b, t_tree *tree) { int site,n_patterns; -/* n_patterns = (int)floor(tree->n_pattern*tree->prop_of_sites_to_consider); */ + if(tree->is_mixt_tree == YES) + { + MIXT_Pars(b,tree); + return tree->c_pars; + } n_patterns = tree->n_pattern; - Post_Order_Pars(tree->noeud[0],tree->noeud[0]->v[0],tree); - if(tree->both_sides) Pre_Order_Pars(tree->noeud[0],tree->noeud[0]->v[0],tree); + if(b == NULL) + { + Post_Order_Pars(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + if(tree->both_sides == YES) Pre_Order_Pars(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + } + + if(b == NULL) b = tree->a_nodes[0]->b[0]; + tree->c_pars = 0; - For(site,n_patterns) + for(site=0;sitesite_pars[site] = 0; tree->curr_site = site; - Site_Pars(tree); + tree->site_pars[site] = Pars_Core(b,tree); tree->c_pars += tree->site_pars[site] * tree->data->wght[site]; + /* printf("\n. site %d pars: %d",site,tree->c_pars); */ } return tree->c_pars; @@ -61,7 +53,7 @@ int Pars(arbre *tree) /*********************************************************/ -void Post_Order_Pars(node *a, node *d, arbre *tree) +void Post_Order_Pars(t_node *a, t_node *d, t_tree *tree) { int i,dir; @@ -70,189 +62,254 @@ void Post_Order_Pars(node *a, node *d, arbre *tree) if(d->tax) return; else { - For(i,3) - { - if(d->v[i] != a) - Post_Order_Pars(d,d->v[i],tree); - else dir = i; - } + for(i=0;i<3;i++) + { + if(d->v[i] != a) + Post_Order_Pars(d,d->v[i],tree); + else dir = i; + } Get_All_Partial_Pars(tree,d->b[dir],a,d); } } /*********************************************************/ -void Pre_Order_Pars(node *a, node *d, arbre *tree) +void Pre_Order_Pars(t_node *a, t_node *d, t_tree *tree) { int i; if(d->tax) return; else { - For(i,3) - { - if(d->v[i] != a) - { - Get_All_Partial_Pars(tree,d->b[i],d->v[i],d); - Pre_Order_Pars(d,d->v[i],tree); - } - } + for(i=0;i<3;i++) + { + if(d->v[i] != a) + { + Get_All_Partial_Pars(tree,d->b[i],d->v[i],d); + Pre_Order_Pars(d,d->v[i],tree); + } + } } } /*********************************************************/ -void Get_All_Partial_Pars(arbre *tree, edge *b_fcus, node *a, node *d) +void Get_All_Partial_Pars(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d) { - if(d->tax) return; - else Update_P_Pars(tree,b_fcus,d); + Update_Partial_Pars(tree,b_fcus,d); } /*********************************************************/ -void Site_Pars(arbre *tree) +void Site_Pars(t_tree *tree) { - tree->site_pars[tree->curr_site] = Pars_Core(tree->noeud[0]->b[0],tree); + tree->site_pars[tree->curr_site] = Pars_Core(tree->a_nodes[0]->b[0],tree); } /*********************************************************/ -void Init_P_Pars_Tips(arbre *tree) +void Init_Partial_Pars_Tips(t_tree *tree) { int curr_site,i,j; short int *state_v; + int dim1; + + dim1 = tree->mod->ns; state_v = (short int *)mCalloc(tree->mod->ns,sizeof(short int)); - - Fors(curr_site,tree->data->crunch_len,tree->mod->stepsize) + + for(curr_site=0;curr_sitedata->crunch_len;curr_site++) { - For(i,tree->n_otu) - { - if(tree->mod->datatype == NT) - { - if(tree->noeud[i]->b[0]->rght->tax != 1) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit("\n"); - } - Init_Tips_At_One_Site_Nucleotides_Int(tree->data->c_seq[i]->state[curr_site],state_v); - For(j,tree->mod->ns) tree->noeud[i]->b[0]->p_pars_r[curr_site][j] = MAX_PARS; - For(j,tree->mod->ns) if(state_v[j] > 0.5) tree->noeud[i]->b[0]->p_pars_r[curr_site][j] = 0; - } - else - { - Init_Tips_At_One_Site_AA_Int(tree->data->c_seq[i]->state[curr_site],state_v); - For(j,tree->mod->ns) tree->noeud[i]->b[0]->p_pars_r[curr_site][j] = MAX_PARS; - For(j,tree->mod->ns) if(state_v[j] > 0.5) tree->noeud[i]->b[0]->p_pars_r[curr_site][j] = 0; - } - } + for(i=0;in_otu;i++) + { + if(tree->a_nodes[i]->b[0]->rght->tax != 1) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + if(tree->io->datatype == NT) + { + Init_Tips_At_One_Site_Nucleotides_Int(tree->a_nodes[i]->c_seq->state[curr_site], + 0, + state_v); + for(j=0;jmod->ns;j++) tree->a_nodes[i]->b[0]->p_pars_r[curr_site*dim1+j] = MAX_PARS; + for(j=0;jmod->ns;j++) if(state_v[j] > 0.5) tree->a_nodes[i]->b[0]->p_pars_r[curr_site*dim1+j] = 0; + } + else if(tree->io->datatype == AA) + { + Init_Tips_At_One_Site_AA_Int(tree->a_nodes[i]->c_seq->state[curr_site], + 0, + state_v); + for(j=0;jmod->ns;j++) tree->a_nodes[i]->b[0]->p_pars_r[curr_site*dim1+j] = MAX_PARS; + for(j=0;jmod->ns;j++) if(state_v[j] > 0.5) tree->a_nodes[i]->b[0]->p_pars_r[curr_site*dim1+j] = 0; + } + else if(tree->io->datatype == GENERIC) + { + Init_Tips_At_One_Site_Generic_Int(tree->a_nodes[i]->c_seq->state+curr_site*tree->mod->io->state_len, + tree->mod->ns, + tree->mod->io->state_len, + 0, + state_v); + for(j=0;jmod->ns;j++) tree->a_nodes[i]->b[0]->p_pars_r[curr_site*dim1+j] = MAX_PARS; + for(j=0;jmod->ns;j++) if(state_v[j] > 0.5) tree->a_nodes[i]->b[0]->p_pars_r[curr_site*dim1+j] = 0; + } + } } Free(state_v); } /*********************************************************/ -void Init_Ui_Tips(arbre *tree) -{ - int curr_site,i,j; +void Init_Ui_Tips(t_tree *tree) +{ + int curr_site,i,j,br; short int *state_v; state_v = (short int *)mCalloc(tree->mod->ns,sizeof(short int)); + + for(curr_site=0;curr_sitedata->crunch_len;curr_site++) + { + for(i=0;in_otu;++i) + { + if(tree->io->datatype == NT) + { + if(tree->a_nodes[i]->b[0]->rght->tax != 1) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + assert(FALSE); + } + + Init_Tips_At_One_Site_Nucleotides_Int(tree->a_nodes[i]->c_seq->state[curr_site], + 0, + state_v); + /* Init_Tips_At_One_Site_Nucleotides_Int(tree->data->c_seq[i]->state[curr_site], */ + /* 0, */ + /* state_v); */ + tree->a_nodes[i]->b[0]->ui_r[curr_site] = 0; + for(j=0;jmod->ns;j++) tree->a_nodes[i]->b[0]->ui_r[curr_site] += (int)(state_v[j] * POW(2,j)); + } + else if(tree->io->datatype == AA) + { + Init_Tips_At_One_Site_AA_Int(tree->a_nodes[i]->c_seq->state[curr_site], + 0, + state_v); + /* Init_Tips_At_One_Site_AA_Int(tree->data->c_seq[i]->state[curr_site], */ + /* 0, */ + /* state_v); */ + tree->a_nodes[i]->b[0]->ui_r[curr_site] = 0; + for(j=0;jmod->ns;j++) tree->a_nodes[i]->b[0]->ui_r[curr_site] += (int)(state_v[j] * POW(2,j)); + } + else if(tree->io->datatype == GENERIC) + { + Init_Tips_At_One_Site_Generic_Int(tree->a_nodes[i]->c_seq->state+curr_site*tree->mod->io->state_len, + tree->mod->ns, + tree->mod->io->state_len, + 0, + state_v); + /* Init_Tips_At_One_Site_Generic_Int(tree->data->c_seq[i]->state+curr_site*tree->mod->io->state_len, */ + /* tree->mod->ns, */ + /* tree->mod->io->state_len, */ + /* 0, */ + /* state_v); */ + tree->a_nodes[i]->b[0]->ui_r[curr_site] = 0; + for(j=0;jmod->ns;j++) tree->a_nodes[i]->b[0]->ui_r[curr_site] += (int)(state_v[j] * POW(2,j)); + } + } + } + - Fors(curr_site,tree->data->crunch_len,tree->mod->stepsize) + for(br=0;br<2*tree->n_otu-3;++br) { - For(i,tree->n_otu) - { - if(tree->mod->datatype == NT) - { - if(tree->noeud[i]->b[0]->rght->tax != 1) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit("\n"); - } - - Init_Tips_At_One_Site_Nucleotides_Int(tree->data->c_seq[i]->state[curr_site],state_v); - tree->noeud[i]->b[0]->ui_r[curr_site] = 0; - For(j,tree->mod->ns) tree->noeud[i]->b[0]->ui_r[curr_site] += (unsigned int)(state_v[j] * pow(2,j)); - } - else - { - Init_Tips_At_One_Site_AA_Int(tree->data->c_seq[i]->state[curr_site],state_v); - tree->noeud[i]->b[0]->ui_r[curr_site] = 0; - For(j,tree->mod->ns) tree->noeud[i]->b[0]->ui_r[curr_site] += (unsigned int)(state_v[j] * pow(2,j)); - } - } + for(curr_site=0;curr_sitedata->crunch_len;++curr_site) + { + tree->a_edges[br]->pars_r[curr_site] = 0; + tree->a_edges[br]->pars_l[curr_site] = 0; + } } + + Free(state_v); } /*********************************************************/ -void Update_P_Pars(arbre *tree, edge *b_fcus, node *n) +void Update_Partial_Pars(t_tree *tree, t_edge *b_fcus, t_node *n) { -/* +/* + | + |<- b_fcus | - |<- b_cus - | - n + n / \ - / \ - / \ + / \ + / \ */ - int i,j; - int site; - unsigned int *ui, *ui_v1, *ui_v2; - int **p_pars_v1, **p_pars_v2, **p_pars; + unsigned int i,j; + unsigned int site; + int *ui, *ui_v1, *ui_v2; + int *p_pars_v1, *p_pars_v2, *p_pars; int *pars, *pars_v1, *pars_v2; - int n_patterns,matches; int min_v1,min_v2; int v; - matches = 0; + const unsigned int ns = tree->mod->ns; + const unsigned int n_patterns = tree->n_pattern; + + if(tree->is_mixt_tree) + { + MIXT_Update_Partial_Pars(tree,b_fcus,n); + return; + } + + if((tree->io->do_alias_subpatt == YES) && + (tree->update_alias_subpatt == YES)) + Alias_One_Subpatt((n==b_fcus->left)?(b_fcus->rght):(b_fcus->left),n,tree); + + if(n->tax) return; + ui = ui_v1 = ui_v2 = NULL; p_pars = p_pars_v1 = p_pars_v2 = NULL; pars = pars_v1 = pars_v2 = NULL; -/* n_patterns = (int)floor(tree->n_pattern*tree->prop_of_sites_to_consider); */ - n_patterns = tree->n_pattern; - + if(n == b_fcus->left) - { + { ui = b_fcus->ui_l; - + pars = b_fcus->pars_l; p_pars = b_fcus->p_pars_l; - - ui_v1 = - (n == n->b[b_fcus->l_v1]->left)? - (n->b[b_fcus->l_v1]->ui_r): - (n->b[b_fcus->l_v1]->ui_l); - - ui_v2 = - (n == n->b[b_fcus->l_v2]->left)? - (n->b[b_fcus->l_v2]->ui_r): - (n->b[b_fcus->l_v2]->ui_l); - - p_pars_v1 = - (n == n->b[b_fcus->l_v1]->left)? - (n->b[b_fcus->l_v1]->p_pars_r): - (n->b[b_fcus->l_v1]->p_pars_l); - - p_pars_v2 = - (n == n->b[b_fcus->l_v2]->left)? - (n->b[b_fcus->l_v2]->p_pars_r): - (n->b[b_fcus->l_v2]->p_pars_l); - - pars_v1 = - (n == n->b[b_fcus->l_v1]->left)? - (n->b[b_fcus->l_v1]->pars_r): - (n->b[b_fcus->l_v1]->pars_l); - - pars_v2 = - (n == n->b[b_fcus->l_v2]->left)? - (n->b[b_fcus->l_v2]->pars_r): - (n->b[b_fcus->l_v2]->pars_l); + + ui_v1 = + (n == n->b[b_fcus->l_v1]->left)? + (n->b[b_fcus->l_v1]->ui_r): + (n->b[b_fcus->l_v1]->ui_l); + + ui_v2 = + (n == n->b[b_fcus->l_v2]->left)? + (n->b[b_fcus->l_v2]->ui_r): + (n->b[b_fcus->l_v2]->ui_l); + + p_pars_v1 = + (n == n->b[b_fcus->l_v1]->left)? + (n->b[b_fcus->l_v1]->p_pars_r): + (n->b[b_fcus->l_v1]->p_pars_l); + + p_pars_v2 = + (n == n->b[b_fcus->l_v2]->left)? + (n->b[b_fcus->l_v2]->p_pars_r): + (n->b[b_fcus->l_v2]->p_pars_l); + + pars_v1 = + (n == n->b[b_fcus->l_v1]->left)? + (n->b[b_fcus->l_v1]->pars_r): + (n->b[b_fcus->l_v1]->pars_l); + + pars_v2 = + (n == n->b[b_fcus->l_v2]->left)? + (n->b[b_fcus->l_v2]->pars_r): + (n->b[b_fcus->l_v2]->pars_l); } else { @@ -260,160 +317,161 @@ void Update_P_Pars(arbre *tree, edge *b_fcus, node *n) pars = b_fcus->pars_r; p_pars = b_fcus->p_pars_r; - - ui_v1 = - (n == n->b[b_fcus->r_v1]->left)? - (n->b[b_fcus->r_v1]->ui_r): - (n->b[b_fcus->r_v1]->ui_l); - - ui_v2 = - (n == n->b[b_fcus->r_v2]->left)? - (n->b[b_fcus->r_v2]->ui_r): - (n->b[b_fcus->r_v2]->ui_l); - - p_pars_v1 = - (n == n->b[b_fcus->r_v1]->left)? - (n->b[b_fcus->r_v1]->p_pars_r): - (n->b[b_fcus->r_v1]->p_pars_l); - - p_pars_v2 = - (n == n->b[b_fcus->r_v2]->left)? - (n->b[b_fcus->r_v2]->p_pars_r): - (n->b[b_fcus->r_v2]->p_pars_l); - - pars_v1 = - (n == n->b[b_fcus->r_v1]->left)? - (n->b[b_fcus->r_v1]->pars_r): - (n->b[b_fcus->r_v1]->pars_l); - - pars_v2 = - (n == n->b[b_fcus->r_v2]->left)? - (n->b[b_fcus->r_v2]->pars_r): - (n->b[b_fcus->r_v2]->pars_l); + + ui_v1 = + (n == n->b[b_fcus->r_v1]->left)? + (n->b[b_fcus->r_v1]->ui_r): + (n->b[b_fcus->r_v1]->ui_l); + + ui_v2 = + (n == n->b[b_fcus->r_v2]->left)? + (n->b[b_fcus->r_v2]->ui_r): + (n->b[b_fcus->r_v2]->ui_l); + + p_pars_v1 = + (n == n->b[b_fcus->r_v1]->left)? + (n->b[b_fcus->r_v1]->p_pars_r): + (n->b[b_fcus->r_v1]->p_pars_l); + + p_pars_v2 = + (n == n->b[b_fcus->r_v2]->left)? + (n->b[b_fcus->r_v2]->p_pars_r): + (n->b[b_fcus->r_v2]->p_pars_l); + + pars_v1 = + (n == n->b[b_fcus->r_v1]->left)? + (n->b[b_fcus->r_v1]->pars_r): + (n->b[b_fcus->r_v1]->pars_l); + + pars_v2 = + (n == n->b[b_fcus->r_v2]->left)? + (n->b[b_fcus->r_v2]->pars_r): + (n->b[b_fcus->r_v2]->pars_l); } - - + + if(tree->mod->s_opt->general_pars) { - For(site,n_patterns) - { - For(i,tree->mod->ns) - { - min_v1 = MAX_PARS; - For(j,tree->mod->ns) - { - v = p_pars_v1[site][j] + tree->step_mat[i*tree->mod->ns+j]; - if(v < min_v1) min_v1 = v; - } - - min_v2 = MAX_PARS; - For(j,tree->mod->ns) - { - v = p_pars_v2[site][j] + tree->step_mat[i*tree->mod->ns+j]; - if(v < min_v2) min_v2 = v; - } - p_pars[site][i] = min_v1 + min_v2; - } - } + for(site=0;sitestep_mat[i*ns+j]; + if(v < min_v1) min_v1 = v; + } + + min_v2 = MAX_PARS; + for(j=0;jstep_mat[i*ns+j]; + if(v < min_v2) min_v2 = v; + } + p_pars[site*ns+i] = min_v1 + min_v2; + } + } } else { - For(site,n_patterns) - { - pars[site] = pars_v1[site] + pars_v2[site]; - - ui[site] = ui_v1[site] & ui_v2[site]; - - if(!ui[site]) - { - pars[site]++; - ui[site] = ui_v1[site] | ui_v2[site]; - } - } + for(site=0;sitemod->ns; site = tree->curr_site; site_pars = MAX_PARS; if(tree->mod->s_opt->general_pars) { - For(i,tree->mod->ns) - { - min_l = MAX_PARS; - For(j,tree->mod->ns) - { - v = b->p_pars_l[site][j] + tree->step_mat[i*tree->mod->ns+j]; - if(v < min_l) min_l = v; - } - - min_r = MAX_PARS; - For(j,tree->mod->ns) - { - v = b->p_pars_r[site][j] + tree->step_mat[i*tree->mod->ns+j]; - if(v < min_r) min_r = v; - } - - if((min_l + min_r) < site_pars) site_pars = min_l + min_r; - } + for(i=0;ip_pars_l[site*ns+j] + tree->step_mat[i*ns+j]; + if(v < min_l) min_l = v; + } + + min_r = MAX_PARS; + for(j=0;jp_pars_r[site*ns+j] + tree->step_mat[i*ns+j]; + if(v < min_r) min_r = v; + } + + if((min_l + min_r) < site_pars) site_pars = min_l + min_r; + } } else { - site_pars = b->pars_l[site] + b->pars_r[site]; + site_pars = b->pars_l[site] + b->pars_r[site]; if(!(b->ui_l[site] & b->ui_r[site])) site_pars++; } - + return site_pars; } /*********************************************************/ -/* Is there one or more parsimoniy step(s) along this edge ? +/* Is there one or more parsimoniy step(s) along this t_edge ? 0 -> NO; 1 -> YES */ -int One_Pars_Step(edge *b,arbre *tree) +int One_Pars_Step(t_edge *b,t_tree *tree) { int site; int init_general_pars; init_general_pars = tree->mod->s_opt->general_pars; - + tree->mod->s_opt->general_pars = 0; - tree->both_sides = 1; - Pars(tree); + Set_Both_Sides(YES,tree); + Pars(NULL,tree); - For(site,tree->n_pattern) + for(site=0;siten_pattern;site++) { if(!(b->ui_l[site] & b->ui_r[site])) break; } tree->mod->s_opt->general_pars = init_general_pars; if(site == tree->n_pattern) return 0; - else - { - printf("\n. One parsimony step ocurred at site %4d",site); + else + { + PhyML_Printf("\n. One parsimony step ocurred at site %4d",site); return 1; } } /*********************************************************/ -int Pars_At_Given_Edge(edge *b, arbre *tree) +int Pars_At_Given_Edge(t_edge *b, t_tree *tree) { int site,n_patterns; - -/* n_patterns = (int)floor(tree->n_pattern*tree->prop_of_sites_to_consider); */ + +/* n_patterns = (int)FLOOR(tree->n_pattern*tree->prop_of_sites_to_consider); */ n_patterns = tree->n_pattern; tree->c_pars = .0; - For(site,n_patterns) + for(site=0;sitesite_pars[site] = 0; tree->curr_site = site; @@ -425,21 +483,21 @@ int Pars_At_Given_Edge(edge *b, arbre *tree) /*********************************************************/ -int Update_Pars_At_Given_Edge(edge *b_fcus, arbre *tree) +int Update_Pars_At_Given_Edge(t_edge *b_fcus, t_tree *tree) { - Update_P_Pars(tree,b_fcus,b_fcus->left); - Update_P_Pars(tree,b_fcus,b_fcus->rght); - tree->c_pars = Pars_At_Given_Edge(b_fcus,tree); + Update_Partial_Pars(tree,b_fcus,b_fcus->left); + Update_Partial_Pars(tree,b_fcus,b_fcus->rght); + tree->c_pars = Pars(b_fcus,tree); return tree->c_pars; } /*********************************************************/ -void Get_Step_Mat(arbre *tree) +void Get_Step_Mat(t_tree *tree) { int i; - if(tree->mod->datatype == AA) + if(tree->io->datatype == AA) { tree->step_mat[ 0*tree->mod->ns+ 0] = 0 ; tree->step_mat[ 0*tree->mod->ns+ 1] = 3 ; @@ -842,7 +900,7 @@ void Get_Step_Mat(arbre *tree) tree->step_mat[19*tree->mod->ns+18] = 3 ; tree->step_mat[19*tree->mod->ns+19] = 0 ; } - else + else if(tree->io->datatype == NT) { tree->step_mat[0*tree->mod->ns+0] = 0; tree->step_mat[0*tree->mod->ns+1] = 2; @@ -863,32 +921,155 @@ void Get_Step_Mat(arbre *tree) tree->step_mat[3*tree->mod->ns+1] = 1; tree->step_mat[3*tree->mod->ns+2] = 2; tree->step_mat[3*tree->mod->ns+3] = 0; + } + else if(tree->io->datatype == GENERIC) + { + int j; + for(i=0;imod->ns;i++) + for(j=0;jmod->ns;j++) + if(j!=i) tree->step_mat[i*tree->mod->ns+j] = 1; + } + + for(i=0;imod->ns;i++) tree->step_mat[i*tree->mod->ns+i] = 0; +} + +/*********************************************************/ +/*********************************************************/ +/*********************************************************/ +/*********************************************************/ +/*********************************************************/ +/*********************************************************/ +/*********************************************************/ -/* tree->step_mat[0*tree->mod->ns+0] = 0; */ -/* tree->step_mat[0*tree->mod->ns+1] = 1; */ -/* tree->step_mat[0*tree->mod->ns+2] = 1; */ -/* tree->step_mat[0*tree->mod->ns+3] = 1; */ +// Tree should be ready for likelihood analysis when calling +// this function. +void Stepwise_Add_Pars(t_tree *tree) +{ + t_edge **residuals,**targets,*best_target; + int *nd_idx,i,j,n_targets,*tg_idx; -/* tree->step_mat[1*tree->mod->ns+0] = 1; */ -/* tree->step_mat[1*tree->mod->ns+1] = 0; */ -/* tree->step_mat[1*tree->mod->ns+2] = 1; */ -/* tree->step_mat[1*tree->mod->ns+3] = 1; */ + residuals = (t_edge **)mCalloc(tree->n_otu-3,sizeof(t_edge *)); + targets = (t_edge **)mCalloc(2*tree->n_otu-3,sizeof(t_edge *)); + best_target = NULL; + nd_idx = Permutate(tree->n_otu-3); -/* tree->step_mat[2*tree->mod->ns+0] = 1; */ -/* tree->step_mat[2*tree->mod->ns+1] = 1; */ -/* tree->step_mat[2*tree->mod->ns+2] = 0; */ -/* tree->step_mat[2*tree->mod->ns+3] = 1; */ + // Remove all tips except that corresponding to a_nodes[0], + // a_nodes[1] and a_nodes[2]. + for(i=0;in_otu-3;++i) + { + Prune_Subtree(tree->a_nodes[i+3]->v[0], + tree->a_nodes[i+3], + NULL, + residuals+i, + tree); + } -/* tree->step_mat[3*tree->mod->ns+0] = 1; */ -/* tree->step_mat[3*tree->mod->ns+1] = 1; */ -/* tree->step_mat[3*tree->mod->ns+2] = 1; */ -/* tree->step_mat[3*tree->mod->ns+3] = 0; */ + // Initial targets + n_targets = 3; + for(i=0;ia_nodes[i]->b[0]; + // Regraft each tip on the tree at most parsimonious position + for(i=0;in_otu-3;++i) + { + Set_Both_Sides(YES,tree); + Pars(NULL,tree); + + /* printf("\n. [%d/%d]",i,tree->n_otu-3); */ + + tree->best_pars = 1E+8; + best_target = NULL; + tg_idx = Permutate(n_targets); + + for(j=0;ja_nodes[nd_idx[i]+3]->v[0], + NULL, + residuals[i], + NULL, + tree); + + Update_Partial_Pars(tree, + tree->a_nodes[nd_idx[i]+3]->b[0], + tree->a_nodes[nd_idx[i]+3]->v[0]); + Pars(tree->a_nodes[nd_idx[i]+3]->b[0],tree); + + + if(tree->c_pars < tree->best_pars) + { + tree->best_pars = tree->c_pars; + best_target = targets[tg_idx[j]]; + } + + Prune_Subtree(tree->a_nodes[nd_idx[i]+3]->v[0], + tree->a_nodes[nd_idx[i]+3], + NULL, + residuals+i, + tree); + } + + assert(best_target); + + Graft_Subtree(best_target, + tree->a_nodes[nd_idx[i]+3]->v[0], + NULL, + residuals[i], + NULL, + tree); + + targets[n_targets] = residuals[i]; + targets[n_targets+1] = tree->a_nodes[nd_idx[i]+3]->b[0]; + + Free(tg_idx); + n_targets+=2; } - - For(i,tree->mod->ns) tree->step_mat[i*tree->mod->ns+i] = 0; + + /* printf("\n. pars: %d",tree->c_pars); */ + /* Exit("\n"); */ + + Free(nd_idx); + Free(residuals); + Free(targets); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// diff --git a/phyml/pars.h b/phyml/pars.h index bb0200f..ce3c86e 100644 --- a/phyml/pars.h +++ b/phyml/pars.h @@ -10,23 +10,33 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef PARS_H #define PARS_H -void Make_Tree_4_Pars(arbre *tree, allseq *alldata, int n_site); -int Pars(arbre *tree); -void Post_Order_Pars(node *a, node *d, arbre *tree); -void Pre_Order_Pars(node *a, node *d, arbre *tree); -void Get_Partial_Pars(arbre *tree, edge *b_fcus, node *a, node *d); -void Site_Pars(arbre *tree); -void Init_Ui_Tips(arbre *tree); -void Update_P_Pars(arbre *tree, edge *b_fcus, node *n); -int Pars_At_Given_Edge(edge *b, arbre *tree); -void Get_All_Partial_Pars(arbre *tree, edge *b_fcus, node *a, node *d); -int Update_Pars_At_Given_Edge(edge *b_fcus, arbre *tree); -void Init_P_Pars_Tips(arbre *tree); -void Get_Step_Mat(arbre *tree); -int Pars_Core(edge *b, arbre *tree); -int One_Pars_Step(edge *b,arbre *tree); +#include "utilities.h" +#include "lk.h" +#include "optimiz.h" +#include "models.h" +#include "free.h" + +int Pars(t_edge *b, t_tree *tree); +void Post_Order_Pars(t_node *a, t_node *d, t_tree *tree); +void Pre_Order_Pars(t_node *a, t_node *d, t_tree *tree); +void Get_Partial_Pars(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d); +void Site_Pars(t_tree *tree); +void Init_Ui_Tips(t_tree *tree); +void Update_Partial_Pars(t_tree *tree, t_edge *b_fcus, t_node *n); +int Pars_At_Given_Edge(t_edge *b, t_tree *tree); +void Get_All_Partial_Pars(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d); +int Update_Pars_At_Given_Edge(t_edge *b_fcus, t_tree *tree); +void Init_Partial_Pars_Tips(t_tree *tree); +void Get_Step_Mat(t_tree *tree); +int Pars_Core(t_edge *b, t_tree *tree); +int One_Pars_Step(t_edge *b,t_tree *tree); +void Stepwise_Add_Pars(t_tree *tree); +void Backup_Partial_Pars(t_node *d, t_edge *b, t_tree *tree); +void Restore_Partial_Pars(t_node *d, t_edge *b, t_tree *tree); #endif diff --git a/phyml/phyml b/phyml/phyml new file mode 100755 index 0000000..88d2dce Binary files /dev/null and b/phyml/phyml differ diff --git a/phyml/phyrex.c b/phyml/phyrex.c new file mode 100644 index 0000000..4a66499 --- /dev/null +++ b/phyml/phyrex.c @@ -0,0 +1,6439 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +/* Routines that implement Etheridge and Barton's model of continuous-space + coalescent. +*/ + +#include "phyrex.h" + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int PHYREX_Main(int argc, char *argv[]) +{ +#if (defined PHYREXSIM) + PHYREX_Main_Simulate(argc,argv); +#elif (defined PHYREX) + option *io; + io = Get_Input(argc,argv); + Free(io); +#endif + return(0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#if (defined PHYREX) +void PHYREX_XML(char *xml_filename) +{ + FILE *fp_xml_in; + xml_node *xnd,*xroot; + t_tree *mixt_tree,*tree; + phydbl *res; + int seed; + char *dum_string; + + mixt_tree = XML_Process_Base(xml_filename); + assert(mixt_tree); + + + mixt_tree->rates = RATES_Make_Rate_Struct(mixt_tree->n_otu); + RATES_Init_Rate_Struct(mixt_tree->rates,NULL,mixt_tree->n_otu); + + + tree = mixt_tree; + do + { + // All rate stuctures point to the same object + tree->rates = mixt_tree->rates; + tree = tree->next; + } + while(tree); + + + fp_xml_in = fopen(xml_filename,"r"); + if(!fp_xml_in) + { + PhyML_Fprintf(stderr,"\n. Could not find the XML file '%s'.\n",xml_filename); + Exit("\n"); + } + + /* xroot = XML_Load_File(fp_xml_in); */ + xroot = mixt_tree->xml_root; + + if(xroot == NULL) + { + PhyML_Fprintf(stderr,"\n. Encountered an issue while loading the XML file.\n"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + xnd = XML_Search_Node_Name("phyrex",NO,xroot); + + if(xnd == NULL) + { + PhyML_Fprintf(stderr,"\n. Cound not find the \"root\" of the XML file (it should have \'phyrex\' as tag name).\n"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + dum_string = XML_Get_Attribute_Value(xnd,"mcmc.chain.len"); + if(dum_string != NULL) mixt_tree->io->mcmc->chain_len = (int)String_To_Dbl(dum_string); + + dum_string = XML_Get_Attribute_Value(xnd,"mcmc.sample.every"); + if(dum_string != NULL) mixt_tree->io->mcmc->sample_interval = (int)String_To_Dbl(dum_string); + + dum_string = XML_Get_Attribute_Value(xnd,"mcmc.print.every"); + if(dum_string != NULL) mixt_tree->io->mcmc->print_every = (int)String_To_Dbl(dum_string); + + dum_string = XML_Get_Attribute_Value(xnd,"mcmc.burnin"); + if(dum_string != NULL) mixt_tree->io->mcmc->chain_len_burnin = (int)String_To_Dbl(dum_string); + + + dum_string = XML_Get_Attribute_Value(xnd,"ignore.sequences"); + if(!dum_string) dum_string = XML_Get_Attribute_Value(xnd,"ignore.seq"); + if(!dum_string) dum_string = XML_Get_Attribute_Value(xnd,"ignore.data"); + + if(dum_string != NULL) + { + int select = XML_Validate_Attr_Int(dum_string,6, + "true","yes","y", + "false","no","n"); + if(select < 3) mixt_tree->eval_alnL = NO; + else mixt_tree->eval_alnL = YES; + } + + dum_string = XML_Get_Attribute_Value(xnd,"mutmap"); + if(dum_string != NULL) + { + int select = XML_Validate_Attr_Int(dum_string,6, + "true","yes","y", + "false","no","n"); + if(select < 3) mixt_tree->io->mutmap = YES; + else mixt_tree->io->mutmap = NO; + } + + + // Looking for XML node with rate-across-lineage info + xnd = XML_Search_Node_Name("lineagerates",YES,xroot); + + if(xnd == NULL) + { + PhyML_Fprintf(stdout,"\n. The model of rate variation across lineages is not specified."); + PhyML_Fprintf(stdout,"\n. Using the geometric Brownian model (see Guindon, 2012, Syst. Biol.).\n"); + mixt_tree->rates->model = GUINDON; + mixt_tree->mod->gamma_mgf_bl = YES; + strcpy(mixt_tree->rates->model_name,"geometric Brownian"); + } + else + { + char *model_name; + model_name = XML_Get_Attribute_Value(xnd,"model"); + + if(model_name == NULL) + { + PhyML_Fprintf(stderr,"\n. Please specify a model of rate variation across lineages,"); + PhyML_Fprintf(stderr,"\n. e.g., ."); + PhyML_Fprintf(stderr,"\n. See the manual for more options."); + assert(FALSE); + } + else + { + if(!strcmp(model_name,"geometricbrownian")) + { + mixt_tree->rates->model = GUINDON; + mixt_tree->mod->gamma_mgf_bl = YES; + strcpy(mixt_tree->rates->model_name,"geometric Brownian"); + } + else if(!strcmp(model_name,"geometric")) + { + mixt_tree->rates->model = GUINDON; + mixt_tree->mod->gamma_mgf_bl = YES; + strcpy(mixt_tree->rates->model_name,"geometric Brownian"); + } + else if(!strcmp(model_name,"brownian")) + { + mixt_tree->rates->model = GUINDON; + mixt_tree->mod->gamma_mgf_bl = YES; + strcpy(mixt_tree->rates->model_name,"geometric Brownian"); + } + else if(!strcmp(model_name,"geo")) + { + mixt_tree->rates->model = GUINDON; + mixt_tree->mod->gamma_mgf_bl = YES; + strcpy(mixt_tree->rates->model_name,"geometric Brownian"); + } + else if(!strcmp(model_name,"lognormal")) + { + mixt_tree->rates->model = LOGNORMAL; + mixt_tree->mod->gamma_mgf_bl = NO; + strcpy(mixt_tree->rates->model_name,"lognormal (uncorrelated)"); + } + else if(!strcmp(model_name,"normal")) + { + mixt_tree->rates->model = LOGNORMAL; + mixt_tree->mod->gamma_mgf_bl = NO; + strcpy(mixt_tree->rates->model_name,"lognormal (uncorrelated)"); + } + else if(!strcmp(model_name,"strictclock")) + { + mixt_tree->rates->model = STRICTCLOCK; + mixt_tree->mod->gamma_mgf_bl = NO; + strcpy(mixt_tree->rates->model_name,"strict clock"); + } + else if(!strcmp(model_name,"clock")) + { + mixt_tree->rates->model = STRICTCLOCK; + mixt_tree->mod->gamma_mgf_bl = NO; + strcpy(mixt_tree->rates->model_name,"strict clock"); + } + else + { + assert(FALSE); + } + } + + } + + // Looking for XML node with rate-across-lineage info + xnd = XML_Search_Node_Name("clockrate",YES,xroot); + + if(xnd != NULL) + { + char *clock_r; + clock_r = XML_Get_Attribute_Value(xnd,"value"); + if(clock_r == NULL) clock_r = XML_Get_Attribute_Value(xnd,"clock.val"); + if(clock_r == NULL) clock_r = XML_Get_Attribute_Value(xnd,"val"); + if(clock_r != NULL) + { + mixt_tree->rates->clock_r = String_To_Dbl(clock_r); + } + + char *opt_clock; + opt_clock = XML_Get_Attribute_Value(xnd,"optimise.clock"); + if(opt_clock == NULL) opt_clock = XML_Get_Attribute_Value(xnd,"optimize.clock"); + if(opt_clock == NULL) opt_clock = XML_Get_Attribute_Value(xnd,"optimize.rate"); + if(opt_clock == NULL) opt_clock = XML_Get_Attribute_Value(xnd,"opt.clock"); + + if(opt_clock != NULL) + { + int select = XML_Validate_Attr_Int(opt_clock,6, + "true","yes","y", + "false","no","n"); + if(select < 3) mixt_tree->mod->s_opt->opt_clock_r = YES; + else mixt_tree->mod->s_opt->opt_clock_r = NO; + } + } + + + // Looking for calibration info + xnd = XML_Search_Node_Name("calibration",YES,xroot); + + if(xnd == NULL) + { + PhyML_Fprintf(stderr,"\n. No calibration information seems to be provided."); + PhyML_Fprintf(stderr,"\n. Please amend your XML file. \n"); + assert(FALSE); + } + else + { + assert(xnd->child); + if(XML_Search_Node_Name("upper",NO,xnd->child) == NULL && XML_Search_Node_Name("lower",NO,xnd->child) == NULL) + { + PhyML_Fprintf(stderr,"\n. There is no calibration information provided. \n"); + PhyML_Fprintf(stderr,"\n. Please check your data. \n"); + assert(FALSE); + } + } + + + + // Looking for coordinate file + xnd = XML_Search_Node_Name("coordinates",YES,xroot); + + if(xnd == NULL) + { + PhyML_Fprintf(stderr,"\n. No spatial information (i.e., coordinates) seems to be provided."); + PhyML_Fprintf(stderr,"\n. Please amend your XML file. \n"); + Exit("\n"); + } + else + { + char *coord_file; + coord_file = XML_Get_Attribute_Value(xnd,"file.name"); + + strcpy(mixt_tree->io->in_coord_file,coord_file); + mixt_tree->io->fp_in_coord = Openfile(mixt_tree->io->in_coord_file,READ); + } + + seed = (mixt_tree->io->r_seed < 0)?(time(NULL)):(mixt_tree->io->r_seed); + srand(seed); + mixt_tree->io->r_seed = seed; + + mixt_tree->mmod = PHYREX_Make_Migrep_Model(2); + mixt_tree->mmod->n_dim = 2; + + + MIXT_Check_Model_Validity(mixt_tree); + MIXT_Init_Model(mixt_tree); + Print_Data_Structure(NO,stdout,mixt_tree); + tree = MIXT_Starting_Tree(mixt_tree); + if(mixt_tree->io->in_tree < 2) Add_Root(tree->a_edges[0],tree); + Copy_Tree(tree,mixt_tree); + Free_Tree(tree); + MIXT_Connect_Cseqs_To_Nodes(mixt_tree); + MIXT_Init_T_Beg(mixt_tree); + MIXT_Make_Tree_For_Lk(mixt_tree); + MIXT_Make_Tree_For_Pars(mixt_tree); + MIXT_Make_Spr(mixt_tree); + MIXT_Chain_All(mixt_tree); + MIXT_Check_Edge_Lens_In_All_Elem(mixt_tree); + MIXT_Turn_Branches_OnOff_In_All_Elem(ON,mixt_tree); + MIXT_Check_Invar_Struct_In_Each_Partition_Elem(mixt_tree); + MIXT_Check_RAS_Struct_In_Each_Partition_Elem(mixt_tree); + + + XML_Read_Calibration(xroot,mixt_tree); + MIXT_Chain_Cal(mixt_tree); + + + if(TIMES_Calibrations_Apply_To_Tips_Only(mixt_tree) == YES && + mixt_tree->mod->s_opt->opt_topo == NO) + { + TIMES_Randomize_Tip_Times_Given_Calibrations(mixt_tree); // Topology is unchanged + TIMES_Bl_To_Times(mixt_tree); + Update_Ancestors(mixt_tree->n_root,mixt_tree->n_root->v[2],mixt_tree); + Update_Ancestors(mixt_tree->n_root,mixt_tree->n_root->v[1],mixt_tree); + } + else + { + TIMES_Randomize_Tree_With_Time_Constraints(mixt_tree->rates->a_cal[0],mixt_tree); + } + + MIXT_Propagate_Tree_Update(mixt_tree); + + /* Create ldsks and connect tree tips to them */ + /* once tip dates have been set properly (in */ + /* TIMES_Randomize_Tree_With_Time_Constraints) */ + PHYREX_Make_And_Connect_Tip_Disks(mixt_tree); + + + /* Read spatial coordinates */ + PHYREX_Read_Tip_Coordinates(mixt_tree); + PHYREX_Init_Migrep_Mod(mixt_tree->mmod,2, + mixt_tree->mmod->lim_do->lonlat[0], + mixt_tree->mmod->lim_do->lonlat[1], + mixt_tree->mmod->lim_up->lonlat[0], + mixt_tree->mmod->lim_up->lonlat[1]); + + /* Initialize parameters of migrep model */ + /* mixt_tree->mmod->lbda = Uni()*(mixt_tree->mmod->max_lbda - mixt_tree->mmod->min_lbda) + mixt_tree->mmod->min_lbda; */ + /* mixt_tree->mmod->mu = Uni()*(mixt_tree->mmod->max_mu - mixt_tree->mmod->min_mu) + mixt_tree->mmod->min_mu; */ + /* mixt_tree->mmod->rad = Uni()*(mixt_tree->mmod->max_rad - mixt_tree->mmod->min_rad) + mixt_tree->mmod->min_rad; */ + mixt_tree->mmod->lbda = 1.; + mixt_tree->mmod->mu = 0.8; + mixt_tree->mmod->rad = mixt_tree->mmod->max_rad; + + mixt_tree->mmod->sigsq = PHYREX_Update_Sigsq(mixt_tree); + + + /* Random genealogy or user-defined tree */ + switch(mixt_tree->io->in_tree) + { + case 0 : case 1 : + { + PHYREX_Simulate_Backward_Core(mixt_tree->young_disk,YES,mixt_tree); + PHYREX_Ldsk_To_Tree(mixt_tree); + break; + } + case 2: + { + PHYREX_Tree_To_Ldsk(mixt_tree); + break; + } + } + + + Update_Ancestors(mixt_tree->n_root,mixt_tree->n_root->v[2],mixt_tree); + Update_Ancestors(mixt_tree->n_root,mixt_tree->n_root->v[1],mixt_tree); + + + MIXT_Set_Ignore_Root(YES,mixt_tree); + MIXT_Set_Bl_From_Rt(YES,mixt_tree); + + PHYREX_Oldest_Sampled_Disk(mixt_tree); + + assert(PHYREX_Check_Struct(mixt_tree)); + PHYREX_Lk(mixt_tree); + Set_Update_Eigen(YES,mixt_tree->mod); + Lk(NULL,mixt_tree); + Set_Update_Eigen(NO,mixt_tree->mod); + PhyML_Printf("\n. Init lnPr(seq|phylo): %f lnPr(coor|phylo): %f",mixt_tree->c_lnL,mixt_tree->mmod->c_lnL); + PhyML_Printf("\n. Random seed: %d",mixt_tree->io->r_seed); + + res = PHYREX_MCMC(mixt_tree); + Free(res); + + // Cleaning up... + RATES_Free_Rates(mixt_tree->rates); + RATES_Free_Rates(mixt_tree->extra_tree->rates); + MCMC_Free_MCMC(mixt_tree->mcmc); + MCMC_Free_MCMC(mixt_tree->extra_tree->mcmc); + Free_Mmod(mixt_tree->mmod); + Free_Spr_List_One_Edge(mixt_tree); + Free_Tree_Pars(mixt_tree); + Free_Tree_Lk(mixt_tree); + + if(mixt_tree->io->fp_out_trees) fclose(mixt_tree->io->fp_out_trees); + if(mixt_tree->io->fp_out_tree) fclose(mixt_tree->io->fp_out_tree); + if(mixt_tree->io->fp_out_stats) fclose(mixt_tree->io->fp_out_stats); + if(mixt_tree->io->fp_out_json_trace) fclose(mixt_tree->io->fp_out_json_trace); + Free_Input(mixt_tree->io); + + + tree = mixt_tree; + do + { + Free_Calign(tree->data); + tree = tree->next_mixt; + } + while(tree); + + tree = mixt_tree; + do + { + Free_Optimiz(tree->mod->s_opt); + tree = tree->next; + } + while(tree); + + + Free_Model_Complete(mixt_tree->mod); + Free_Model_Basic(mixt_tree->mod); + Free_Tree(mixt_tree->extra_tree); + Free_Tree(mixt_tree); + Free(res); + XML_Free_XML_Tree(xroot); + fclose(fp_xml_in); +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int PHYREX_Main_Simulate(int argc, char *argv[]) +{ + t_tree *tree; + int seed,i; + char *s; + t_dsk *disk; + int n_sites,n_otus; + phydbl width,height; + phydbl lbda, rad,mu; + + s = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + n_otus = (int)atoi(argv[1]); + n_sites = 1; + width = (phydbl)atof(argv[2]); + height = (phydbl)atof(argv[3]); + lbda = (phydbl)atof(argv[4]); + rad = (phydbl)atof(argv[5]); + mu = (phydbl)atof(argv[6]); + seed = (int)atoi(argv[7]); + + + printf("\n. seed: %d",seed); + srand(seed); + + tree = PHYREX_Simulate(n_otus,n_sites,width,height,lbda,rad,mu,seed); + /* tree = PHYREX_Simulate_Independent_Loci(n_otus,500,20.,20.,seed); */ + + disk = tree->young_disk; + for(i=0;in_ldsk_a;i++) Free_Ldisk(disk->ldsk_a[i]); + while(disk->prev) + { + disk = disk->prev; + if(disk->next->ldsk != NULL) Free_Ldisk(disk->next->ldsk); + Free_Disk(disk->next); + } + + /* Root */ + Free_Ldisk(disk->ldsk); + Free_Disk(disk); + + RATES_Free_Rates(tree->rates); + /* MCMC_Free_MCMC(tree->mcmc); */ + Free_Mmod(tree->mmod); + Free_Spr_List_One_Edge(tree); + Free_Spr_List_All_Edge(tree); + Free_Tree_Pars(tree); + Free_Tree_Lk(tree); + Free_Input(tree->io); + Free_Optimiz(tree->mod->s_opt); + Free_Model_Complete(tree->mod); + Free_Model_Basic(tree->mod); + Free_Calign(tree->data); + Free_Tree(tree); + Free(s); + + return 0; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_tree *PHYREX_Simulate_Independent_Loci(int n_otu, int n_loci, phydbl w, phydbl h, int r_seed) +{ + t_tree *tree; + int n_dim,i; + t_phyrex_mod *mmod; + option *io; + t_mod *mod; + t_opt *s_opt; + calign *cdata; + phydbl area; + phydbl subst_rate; + int locus_idx; + + n_dim = 2; // 2-dimensional landscape + area = w * h; + + io = (option *)Make_Input(); + mod = (t_mod *)Make_Model_Basic(); + s_opt = (t_opt *)Make_Optimiz(); + + Set_Defaults_Input(io); + Set_Defaults_Model(mod); + Set_Defaults_Optimiz(s_opt); + + + // io stuff + io->mod = mod; + mod->io = io; + mod->s_opt = s_opt; + io->r_seed = r_seed; + io->n_otu = n_otu; + io->init_len = n_loci; /* sequence length */ + io->data = Make_Empty_Alignment(io); + io->colalias = NO; + + Make_Model_Complete(io->mod); + Set_Model_Name(io->mod); + + cdata = Compact_Data(io->data,io); + Free_Seq(io->data,io->n_otu); + + Print_Settings(io); + + + // tree stuff + tree = Make_Tree_From_Scratch(n_otu,cdata); + Random_Tree(tree); + Connect_CSeqs_To_Nodes(cdata,io,tree); + tree->rates = RATES_Make_Rate_Struct(tree->n_otu); + io->rates->model = STRICTCLOCK; + RATES_Init_Rate_Struct(tree->rates,io->rates,tree->n_otu); + + tree->data = cdata; + tree->mod = mod; + tree->io = io; + tree->n_pattern = tree->data->crunch_len; + + Init_Model(cdata,mod,io); + + tree->mod->ras->n_catg = 1; + tree->mod->whichmodel = HKY85; + tree->mod->kappa->v = 4.0; + + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); + Make_Spr(tree); + + // migrep model stuff */ + mmod = PHYREX_Make_Migrep_Model(n_dim); + tree->mmod = mmod; + PHYREX_Init_Migrep_Mod(mmod,n_dim,0.0,0.0,w,h); + + + /* /\* Death proba param *\/ */ + /* mmod->mu = Uni(); */ + /* /\* Theta (radius) *\/ */ + /* mmod->rad = Uni()*(1.0 - 0.2) + 0.2; */ + /* /\* Rate of events *\/ */ + /* mmod->lbda = 1.0; */ + /* /\* Population density *\/ */ + /* mmod->rho = Uni()*(3.0 - 0.1) + 0.1; */ + + + /* Death proba param */ + mmod->mu = 0.8; + /* Theta (radius) */ + mmod->rad = 0.3; + /* Rate of events */ + mmod->lbda = 10.*w*h; + /* (Actual, not effective) population density */ + mmod->rho = 1.; + + + + // Duration of a generation in number of events + mmod->gen_cal_time = 1./(2.*mmod->mu*pow(mmod->rad,2)/pow(w*h,2)* + (sqrt(2.)*mmod->rad*exp(-.5*pow(h/mmod->rad,2)) + h*sqrt(PI)*erf(sqrt(2.)*h/(2.*mmod->rad)) - sqrt(2.)*mmod->rad)* + (sqrt(2.)*mmod->rad*exp(-.5*pow(w/mmod->rad,2)) + w*sqrt(PI)*erf(sqrt(2.)*w/(2.*mmod->rad)) - sqrt(2.)*mmod->rad)); + // Divide by rate of events per calendar time unit to get duration of gen. in calendar time unit + mmod->gen_cal_time *= 1./mmod->lbda; + + /* Dispersal parameter (per generation) */ + mmod->sigsq = 4.*pow(mmod->rad,4)*mmod->lbda*PI*mmod->mu/area * mmod->gen_cal_time; + + + phydbl p = Prob_Two_Random_Lineages_Coal_One_Event(w,h,mmod->mu,mmod->rad); + printf("\n. p.sim: %G p.appx: %G",p,4.*pow(mmod->mu,2)*pow(PI,2)*pow(mmod->rad,4)/(pow(w*h,2))); + phydbl rhoe = 1./(1.-exp(-mmod->lbda*p*mmod->gen_cal_time)); + rhoe /= area; + + PhyML_Printf("\n. lambda=%G; mu=%G; rad=%G; clockr=%G; sigsq=%G; neigh=%G; rhoe(small rad)=%G rhoe(numerical)=%G rhoe(large rad)=%G one_gen=%G", + mmod->lbda, + mmod->mu, + mmod->rad, + tree->rates->clock_r, + mmod->sigsq, + 2./mmod->mu, + (1./(1.-exp(-4.*pow(mmod->mu,2)*pow(PI,2)*pow(mmod->rad,4)/(pow(w*h,2))*mmod->lbda*mmod->gen_cal_time)))/area, + rhoe, + /* (1./(1.-exp(-mmod->lbda*mmod->mu/(w*h))))/area, */ + (1./(1.-exp(-mmod->mu)))/area, + mmod->gen_cal_time); + fflush(NULL); + /* Exit("\n"); */ + + + // Initialize position of sampled individuals + tree->young_disk = PHYREX_Make_Disk_Event(mmod->n_dim,tree->n_otu); + PHYREX_Init_Disk_Event(tree->young_disk,mmod->n_dim,NULL); + tree->young_disk->time = 0.0; + tree->young_disk->mmod = mmod; + tree->young_disk->centr->lonlat[0] = .5*(mmod->lim_up->lonlat[0]-mmod->lim_do->lonlat[0]); + tree->young_disk->centr->lonlat[1] = .5*(mmod->lim_up->lonlat[1]-mmod->lim_do->lonlat[1]); + tree->young_disk->n_ldsk_a = tree->n_otu; + + for(i=0;in_otu;++i) + { + char *s; + tree->young_disk->ldsk_a[i] = PHYREX_Make_Lindisk_Node(mmod->n_dim); + PHYREX_Init_Lindisk_Node(tree->young_disk->ldsk_a[i],tree->young_disk,mmod->n_dim); + s = (char *)mCalloc(strlen(tree->young_disk->ldsk_a[i]->coord->id)+1+20,sizeof(char)); + strcpy(s,tree->young_disk->ldsk_a[i]->coord->id); + strcat(s,"_deme0\0"); + Free(tree->young_disk->ldsk_a[i]->coord->id); + tree->young_disk->ldsk_a[i]->coord->id = s; + } + + for(i=0;in_otu;i++) + { + tree->young_disk->ldsk_a[i]->coord->lonlat[0] = Uni()*(tree->mmod->lim_up->lonlat[0]-tree->mmod->lim_do->lonlat[0]) + tree->mmod->lim_do->lonlat[0]; // longitude + tree->young_disk->ldsk_a[i]->coord->lonlat[1] = Uni()*(tree->mmod->lim_up->lonlat[1]-tree->mmod->lim_do->lonlat[1]) + tree->mmod->lim_do->lonlat[1]; // latitude + } + + + + // Generate sequences + subst_rate = .0; + locus_idx = 0; + do + { + PHYREX_Simulate_Backward_Core(tree->young_disk,NO,tree); + + // Random selection of a pair. Print out physical distances + // between tips and time of coalescence for this pair, at this + // particular locus + { + int *permut = Permutate(tree->n_otu); + t_ldsk *lin1 = tree->young_disk->ldsk_a[permut[0]]; + t_ldsk *lin2 = tree->young_disk->ldsk_a[permut[1]]; + phydbl dist = + sqrt(pow(lin1->coord->lonlat[0]-lin2->coord->lonlat[0],2) + + pow(lin1->coord->lonlat[1]-lin2->coord->lonlat[1],2)); + + t_dsk *disk = tree->young_disk; + do + { + if(disk->ldsk == lin1->prev) lin1 = lin1->prev; + if(disk->ldsk == lin2->prev) lin2 = lin2->prev; + if(lin1 == lin2) break; // found MRCA + disk = disk->prev; + } + while(disk); + + assert(lin1 && lin2); + + PhyML_Printf("\n. #$# locus %4d ; physical distance: %G time to coalescence: %G",locus_idx,dist,lin1->disk->time); + } + + PHYREX_Ldsk_To_Tree(tree); + + + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + RATES_Fill_Lca_Table(tree); + + + tree->rates->bl_from_rt = YES; + /* tree->rates->clock_r = 1.E-3/FABS(T); // slow */ + /* tree->rates->clock_r = 1.E-0/FABS(T); // fast */ + /* tree->rates->clock_r = 1.E-1/FABS(T); // medium */ + /* tree->rates->clock_r = 1.E-7; // slow; */ + tree->rates->clock_r = 1.E-3; // medium; + /* tree->rates->clock_r = 1.E-2; // fast; */ + + + PhyML_Printf("\n. #!# mutation rate at that locus: %G subst. per time unit",tree->rates->clock_r); + subst_rate += tree->rates->clock_r; + + RATES_Update_Cur_Bl(tree); + + char *s = Write_Tree(tree); + PhyML_Printf("\n. #@# tree: %s",s); + Free(s); + + Evolve(tree->data,tree->mod,locus_idx,tree); + + t_dsk *disk = tree->young_disk->prev; + while(disk->prev) + { + disk = disk->prev; + if(disk->next->ldsk != NULL) Free_Ldisk(disk->next->ldsk); + Free_Disk(disk->next); + } + + locus_idx++; + } + while(locus_idx < n_loci); + + PhyML_Printf("\n. #s# average rate of mutation : %G",subst_rate/(phydbl)n_loci); + + tree->data->format = IBDSIM; + PhyML_Printf("\n\n"); + Print_CSeq(stdout,NO,tree->data,tree); + + + Exit("\n"); + + return tree; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Simulate Etheridge-Barton model backwards in time, following n_otu lineages +// on a rectangle of dimension width w x h +// See Kelleher, Barton & Etheridge, Bioinformatics, 2013. +t_tree *PHYREX_Simulate(int n_otu, int n_sites, phydbl w, phydbl h, phydbl lbda, phydbl rad, phydbl mu, int r_seed) +{ + t_tree *tree; + int n_dim,i; + t_phyrex_mod *mmod; + t_dsk *disk; + option *io; + t_mod *mod; + t_opt *s_opt; + calign *cdata; + /* phydbl T; */ + + n_dim = 2; // 2-dimensional landscape + + io = (option *)Make_Input(); + mod = (t_mod *)Make_Model_Basic(); + s_opt = (t_opt *)Make_Optimiz(); + + Set_Defaults_Input(io); + Set_Defaults_Model(mod); + Set_Defaults_Optimiz(s_opt); + + io->mod = mod; + mod->io = io; + mod->s_opt = s_opt; + io->r_seed = r_seed; + + io->n_otu = n_otu; + io->init_len = 500; /* sequence length */ + + io->data = Make_Empty_Alignment(io); + + Make_Model_Complete(io->mod); + Set_Model_Name(io->mod); + + io->colalias = NO; + cdata = Compact_Data(io->data,io); + Free_Seq(io->data,io->n_otu); + + tree = Make_Tree_From_Scratch(n_otu,cdata); + + Connect_CSeqs_To_Nodes(cdata,io,tree); + + tree->rates = RATES_Make_Rate_Struct(tree->n_otu); + RATES_Init_Rate_Struct(tree->rates,io->rates,tree->n_otu); + + tree->data = cdata; + tree->mod = mod; + tree->io = io; + tree->n_pattern = tree->data->crunch_len; + + + /* Allocate migrep model */ + mmod = PHYREX_Make_Migrep_Model(n_dim); + tree->mmod = mmod; + PHYREX_Init_Migrep_Mod(mmod,n_dim,0.0,0.0,w,h); + + mmod->lbda = lbda; + mmod->rad = rad; + mmod->mu = mu; + + if(mmod->lbda > mmod->max_lbda) mmod->lbda = mmod->max_lbda; + if(mmod->rad > mmod->max_rad) mmod->rad = mmod->max_rad; + if(mmod->mu > mmod->max_mu) mmod->mu = mmod->max_mu; + + if(mmod->lbda < mmod->min_lbda) mmod->lbda = mmod->min_lbda; + if(mmod->rad < mmod->min_rad) mmod->rad = mmod->min_rad; + if(mmod->mu < mmod->min_mu) mmod->mu = mmod->min_mu; + + + mmod->sigsq = PHYREX_Update_Sigsq(tree); + + + + // Duration of a generation in number of events + mmod->gen_cal_time = 1./(2.*mmod->mu*pow(mmod->rad,2)/pow(w*h,2)* + (sqrt(2.)*mmod->rad*exp(-.5*pow(h/mmod->rad,2)) + h*sqrt(PI)*erf(sqrt(2.)*h/(2.*mmod->rad)) - sqrt(2.)*mmod->rad)* + (sqrt(2.)*mmod->rad*exp(-.5*pow(w/mmod->rad,2)) + w*sqrt(PI)*erf(sqrt(2.)*w/(2.*mmod->rad)) - sqrt(2.)*mmod->rad)); + // Divide by rate of events per calendar time unit to get duration of gen. in calendar time unit + mmod->gen_cal_time *= 1./mmod->lbda; + + + /* Prepare start disk */ + tree->young_disk = PHYREX_Make_Disk_Event(tree->mmod->n_dim,tree->n_otu); + tree->young_disk->time = 0.0; + tree->young_disk->age_fixed = YES; + tree->young_disk->centr->lonlat[0] = .5*(tree->mmod->lim_up->lonlat[0]-tree->mmod->lim_do->lonlat[0]); + tree->young_disk->centr->lonlat[1] = .5*(tree->mmod->lim_up->lonlat[1]-tree->mmod->lim_do->lonlat[1]); + tree->young_disk->n_ldsk_a = tree->n_otu; + + for(i=0;in_otu;++i) + { + char *s; + tree->young_disk->ldsk_a[i] = PHYREX_Make_Lindisk_Node(tree->mmod->n_dim); + PHYREX_Init_Lindisk_Node(tree->young_disk->ldsk_a[i],tree->young_disk,tree->mmod->n_dim); + s = (char *)mCalloc(strlen(tree->young_disk->ldsk_a[i]->coord->id)+1+20,sizeof(char)); + strcpy(s,tree->young_disk->ldsk_a[i]->coord->id); + strcat(s,"_deme0\0"); + Free(tree->young_disk->ldsk_a[i]->coord->id); + tree->young_disk->ldsk_a[i]->coord->id = s; + } + + /* Generate coordinates for the tip nodes (uniform distribution on the rectangle) */ + for(i=0;in_otu;i++) + { + tree->young_disk->ldsk_a[i]->coord->lonlat[0] = Uni()*(tree->mmod->lim_up->lonlat[0]-tree->mmod->lim_do->lonlat[0])+tree->mmod->lim_do->lonlat[0]; // longitude + tree->young_disk->ldsk_a[i]->coord->lonlat[1] = Uni()*(tree->mmod->lim_up->lonlat[1]-tree->mmod->lim_do->lonlat[1])+tree->mmod->lim_do->lonlat[1]; // latitude + } + + /* /\* !!!!!!!!!!!!!!!!!!!!!!!!!! *\/ */ + /* /\* Fix coordinates of first two tips *\/ */ + /* tree->young_disk->ldsk_a[0]->coord->lonlat[0] = (tree->mmod->lim_up->lonlat[0]+tree->mmod->lim_do->lonlat[0])/2; // longitude */ + /* tree->young_disk->ldsk_a[0]->coord->lonlat[1] = (tree->mmod->lim_up->lonlat[1]+tree->mmod->lim_do->lonlat[1])/2; // latitude */ + /* tree->young_disk->ldsk_a[1]->coord->lonlat[0] = (tree->mmod->lim_up->lonlat[1]+tree->mmod->lim_do->lonlat[1])/2 + 1; // longitude */ + /* tree->young_disk->ldsk_a[1]->coord->lonlat[1] = (tree->mmod->lim_up->lonlat[1]+tree->mmod->lim_do->lonlat[1])/2 + 1; // latitude */ + + + for(i=0;in_otu;i++) + { + tree->young_disk->ldsk_a[i]->nd = tree->a_nodes[i]; + tree->a_nodes[i]->ldsk = tree->young_disk->ldsk_a[i]; + } + + PHYREX_Simulate_Backward_Core(tree->young_disk,NO,tree); + + PHYREX_Ldsk_To_Tree(tree); + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + RATES_Fill_Lca_Table(tree); + + + /* min_rate = 1.E-5; */ + /* max_rate = 1.E-4; */ + + phydbl T = PHYREX_Tree_Height(tree); + + tree->rates->bl_from_rt = YES; + tree->rates->clock_r = 0.1/fabs(2.*T); + tree->rates->model = STRICTCLOCK; + + RATES_Update_Cur_Bl(tree); + + Init_Model(cdata,mod,io); + + tree->mod->ras->n_catg = 1; + tree->mod->whichmodel = HKY85; + tree->mod->kappa->v = 4.0; + + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); + Make_Spr(tree); + Evolve(tree->data,tree->mod,0,tree); + + PhyML_Printf("@@@ %G %G %G : ",mmod->lbda,mmod->mu,mmod->rad); + for(int i=0;in_otu-1;++i) for(int j=i+1;jn_otu;++j) PhyML_Printf("%G ",PHYREX_Dist_Between_Two_Ldsk(tree->a_nodes[i]->ldsk,tree->a_nodes[j]->ldsk,tree)); + PhyML_Printf(" : "); + for(int i=0;in_otu-1;++i) for(int j=i+1;jn_otu;++j) PhyML_Printf("%G ",Euclidean_Dist(tree->a_nodes[i]->ldsk->coord,tree->a_nodes[j]->ldsk->coord)); + PhyML_Printf("\n"); + for(int i=0;in_otu;++i) PhyML_Printf("\n%20s %12G %12G", + tree->a_nodes[i]->name, + tree->a_nodes[i]->ldsk->coord->lonlat[0], + tree->a_nodes[i]->ldsk->coord->lonlat[1]); + PhyML_Printf("\n\n"); + PhyML_Printf(">> SEQUENCES\n"); + Print_CSeq(stdout,NO,tree->data,tree); + PhyML_Printf("<< SEQUENCES"); + + /* Init_Partial_Lk_Tips_Double(tree); */ + /* Init_Partial_Lk_Loc(tree); */ + + disk = tree->young_disk->prev; + while(disk->prev) disk = disk->prev; + + PhyML_Printf("\n. Parameter boundaries: lambda:[%G,%G]; mu=[%G,%G]; rad=[%G,%G]", + mmod->min_lbda,mmod->max_lbda, + mmod->min_mu,mmod->max_mu, + mmod->min_rad,mmod->max_rad); + PhyML_Printf("\n. Useful parameters: lambda=%G; mu=%G; rad=%G; clockr=%G; sigsq=%G", + mmod->lbda, + mmod->mu, + mmod->rad, + tree->rates->clock_r, + mmod->sigsq); + + PhyML_Printf("\n. Useful statistics: t.root=%f n.int=%d n.coal=%d n.hit=%d root.x=%f root.y=%f nt.div=%f\n", + disk->time, + PHYREX_Total_Number_Of_Intervals(tree), + PHYREX_Total_Number_Of_Coal_Disks(tree), + PHYREX_Total_Number_Of_Hit_Disks(tree), + disk->ldsk->coord->lonlat[0], + disk->ldsk->coord->lonlat[1], + Nucleotide_Diversity(tree->data)); + + Exit("\n"); + + /* PhyML_Printf("\n. Tree: "); */ + /* PhyML_Printf("\n. %s \n",Write_Tree(tree)); */ + + /* PhyML_Printf("\n. Spatial coordinates: "); */ + /* for(i=0;in_otu;i++) */ + /* { */ + /* PhyML_Printf("\n%15s %12f %12f", */ + /* tree->young_disk->ldsk_a[i]->nd->name, */ + /* tree->young_disk->ldsk_a[i]->coord->lonlat[0], */ + /* tree->young_disk->ldsk_a[i]->coord->lonlat[1]); */ + /* } */ + /* PhyML_Printf("\n"); */ + + /* for(int i=0;in_otu;i++) */ + /* { */ + /* PhyML_Printf("\n",i+1); */ + /* PhyML_Printf("\n\t",tree->a_nodes[i]->name); */ + /* PhyML_Printf("\n"); */ + /* PhyML_Printf("\n",i+1); */ + /* PhyML_Printf("\n\t0.0"); */ + /* PhyML_Printf("\n\t0.0"); */ + /* PhyML_Printf("\n\t",i+1); */ + /* PhyML_Printf("\n"); */ + /* } */ + + return(tree); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// Simulate Etheridge-Barton model backwards in time, following n_otu lineages +// on a rectangle. +phydbl PHYREX_Simulate_Backward_Core(t_dsk *init_disk, int avoid_multiple_mergers, t_tree *tree) +{ + t_dsk *disk,*new_disk,*oldest_disk; + int i,j,reached_oldest_disk,err; + phydbl prob_hit,u,new_time,lnL; + t_phyrex_mod *mmod; + t_node *n; + + mmod = tree->mmod; + + Get_Node_Ranks_From_Tip_Times(tree); + + // Get to the youngest node + n = tree->a_nodes[0]; + while(n->rk_next) n = n->rk_next; + + disk = init_disk; + // Make sure at least one of the youngest nodes is on init_disk + for(i=0;in_ldsk_a;++i) if(init_disk->ldsk_a[i]->nd == n) break; + assert(i != init_disk->n_ldsk_a); + + // Get to the oldest sampled disk + disk = init_disk; + while(disk->prev) disk = disk->prev; + oldest_disk = disk; + reached_oldest_disk = NO; + if(init_disk->prev == NULL) reached_oldest_disk = YES; // Only one sampled disk + + + + lnL = 0.0; + disk = init_disk; + do + { + /* MRCA reached */ + if(PHYREX_Number_Of_Outgoing_Ldsks(disk) == 1 && reached_oldest_disk == YES) break; + + /* Proposed new time */ + new_time = disk->time - Rexp(mmod->lbda); + + lnL += log(mmod->lbda) - mmod->lbda * fabs(disk->time - new_time); + + /* New time is older than previous sampled disk (disk->prev) */ + if(disk->prev && new_time < disk->prev->time) + { + new_disk = disk->prev; + new_time = disk->prev->time; + + // Reached oldest disk -> set it to NULL + // so as to indicate that it is ok to stop + // the simulation, continue otherwise + if(new_disk == oldest_disk) reached_oldest_disk = YES; + + /* Connect disk and new_disk */ + disk->prev = new_disk; + new_disk->next = disk; + + /* Time of next event */ + new_disk->time = new_time; + + /* Populate new_disk->ldsk_a array */ + PHYREX_Update_Lindisk_List_Core(new_disk,tree); + } + else + { + /* Create new disk */ + new_disk = PHYREX_Make_Disk_Event(mmod->n_dim,tree->n_otu); + PHYREX_Init_Disk_Event(new_disk,mmod->n_dim,NULL); + + /* new_disk->prev now points to previous sampled disk */ + new_disk->prev = disk->prev; + if(disk->prev) disk->prev->next = new_disk; + + /* Connect disk and new_disk */ + disk->prev = new_disk; + new_disk->next = disk; + + /* Time of next event */ + new_disk->time = new_time; + + /* Coordinates of new event */ + for(j=0;jn_dim;++j) new_disk->centr->lonlat[j] = Uni()*(mmod->lim_up->lonlat[j]-mmod->lim_do->lonlat[j])+mmod->lim_do->lonlat[j]; + + for(j=0;jn_dim;++j) lnL += log(1./(mmod->lim_up->lonlat[j]-mmod->lim_do->lonlat[j])); + + + /* Populate new_disk->ldsk_a array */ + PHYREX_Update_Lindisk_List_Core(new_disk,tree); + + new_disk->ldsk = NULL; + /* Which lineages in new_disk->ldsk_a are hit? */ + for(i=0;in_ldsk_a;++i) + { + prob_hit = -1.; + switch(mmod->name) + { + case PHYREX_UNIFORM: + { + prob_hit = mmod->mu; + break; + } + case PHYREX_NORMAL: + { + prob_hit = log(mmod->mu); + for(j=0;jn_dim;++j) + { + prob_hit += + -pow(new_disk->ldsk_a[i]->coord->lonlat[j] - + new_disk->centr->lonlat[j],2)/(2.*pow(mmod->rad,2)); + } + prob_hit = exp(prob_hit); + break; + } + } + + u = Uni(); + if(!(u > prob_hit)) // disk->ldsk_a[i] is hit + { + lnL += log(prob_hit); + // new_disk->ldsk_a[i] is hit -> coalesce (or just jump) to parent (i.e., new_disk->ldsk) + if(new_disk->ldsk == NULL) + { + new_disk->ldsk = PHYREX_Make_Lindisk_Node(mmod->n_dim); + PHYREX_Init_Lindisk_Node(new_disk->ldsk,new_disk,mmod->n_dim); + + // Generate coordinates for newly created ldsk + switch(tree->mmod->name) + { + case PHYREX_UNIFORM: + { + PHYREX_Runif_Rectangle_Overlap(new_disk->ldsk,new_disk,tree->mmod); + break; + } + case PHYREX_NORMAL: + { + PHYREX_Rnorm_Trunc(new_disk->ldsk,new_disk,tree->mmod); + for(j=0;jmmod->n_dim;++j) + lnL += Log_Dnorm_Trunc(new_disk->ldsk->coord->lonlat[j], + new_disk->centr->lonlat[j], + tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + break; + } + } + } + new_disk->ldsk_a[i]->prev = new_disk->ldsk; + PHYREX_Make_Lindisk_Next(new_disk->ldsk); + new_disk->ldsk->next[new_disk->ldsk->n_next-1] = new_disk->ldsk_a[i]; + } + else + { + lnL += log(1. - prob_hit); + } + } + } + + disk = new_disk; + } + while(1); + disk->prev = NULL; + + /* /\* !!!!!!!!!!! *\/ */ + /* PHYREX_Sum_Coal_Rate(init_disk->ldsk_a[0],init_disk->ldsk_a[1],100,tree); */ + + return(lnL); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// Simulate Etheridge-Barton model forwards in time, following n_otu lineages +// on a rectangle of dimension width x h +t_sarea *PHYREX_Simulate_Forward_Core(int n_sites, t_tree *tree) +{ + t_dsk *disk,*new_disk; + t_ldsk *ldsk,**ldsk_a_pop,**ldsk_a_samp,**ldsk_a_tmp,**ldsk_a_tips,*new_ldsk; + t_ll *ldsk_list,*dum_ll; + int i,j,n_disk,n_dim,n_otu,init_pop_size,curr_pop_size,parent_id,n_lineages,sample_size,n_poly,*permut,n_sampled_demes; + phydbl sum,*parent_prob,prob_death,tree_height,max_x,max_y,trans_x,trans_y,t_sim, one_gen; + short int dies,n_remain; + t_phyrex_mod *mmod; + t_poly **poly; + t_sarea *area; + short int *is_sampled; + phydbl w,h; + phydbl cx,cy; + phydbl lx,ly; + int n_survive,n_offspring, n_gen; + + mmod = tree->mmod; + n_dim = 2; + n_otu = tree->n_otu; + w = (mmod->lim_up->lonlat[0]-mmod->lim_do->lonlat[0]); + h = (mmod->lim_up->lonlat[1]-mmod->lim_do->lonlat[1]); + init_pop_size = mmod->rho*w*h; + n_gen = 10; // number of generations to simulate + one_gen = mmod->gen_cal_time; // time duration of one generation (calendar unit) + t_sim = n_gen * one_gen; // total simulation duration (calendar unit) + + + /* Allocate and initialise first disk event */ + disk = PHYREX_Make_Disk_Event(n_dim,init_pop_size); + PHYREX_Init_Disk_Event(disk,n_dim,NULL); + disk->time = 0.0; + disk->prev = NULL; + disk->n_ldsk_a = init_pop_size; + + /* Allocate coordinates for all individuals in the starting population */ + ldsk_list = NULL; + i = 0; + do + { + ldsk = PHYREX_Make_Lindisk_Node(n_dim); + PHYREX_Init_Lindisk_Node(ldsk,disk,n_dim); + Push_Bottom_Linked_List(ldsk,&ldsk_list,NO); + i++; + } + while(i != init_pop_size); + + + /* Fill in array of lineages on the first disk */ + dum_ll = ldsk_list->head; + i = 0; + do + { + disk->ldsk_a[i] = (t_ldsk *)dum_ll->v; + dum_ll = dum_ll->next; + i++; + } + while(dum_ll != NULL); + + + + /* Generate coordinates for all individuals in starting population */ + for(i=0;ildsk_a[i]->coord->lonlat[0] = Uni()*w; // longitude + disk->ldsk_a[i]->coord->lonlat[1] = Uni()*h; // latitude + } + + + n_disk = 0; + do + { + /* Create new disk */ + new_disk = PHYREX_Make_Disk_Event(n_dim,1); + Free(new_disk->ldsk_a); + new_disk->ldsk_a = NULL; + PHYREX_Init_Disk_Event(new_disk,n_dim,NULL); + new_disk->prev = disk; + disk->next = new_disk; + n_disk++; + + + /* Coordinates of event */ + new_disk->centr->lonlat[0] = Uni()*(mmod->lim_up->lonlat[0]-mmod->lim_do->lonlat[0])+mmod->lim_do->lonlat[0]; + new_disk->centr->lonlat[1] = Uni()*(mmod->lim_up->lonlat[1]-mmod->lim_do->lonlat[1])+mmod->lim_do->lonlat[1]; + + cx = new_disk->centr->lonlat[0]; + cy = new_disk->centr->lonlat[1]; + + + /* Time of new disk */ + new_disk->time = disk->time + Rexp(mmod->lbda); + + /* PhyML_Printf("\n. new_disk->time: %f t_sim: %f",new_disk->time,t_sim); */ + + /* Size of current population */ + curr_pop_size = disk->n_ldsk_a; + + if(curr_pop_size == 0) + { + PhyML_Fprintf(stderr,"\n== Population went extinct after %d events",n_disk); + Exit("\n"); + } + + + if(new_disk->time < t_sim) + { + /* Select one parent */ + parent_prob = (phydbl *)mCalloc(curr_pop_size,sizeof(phydbl)); + for(i=0;ildsk_a[i]->coord->lonlat[0]; + ly = disk->ldsk_a[i]->coord->lonlat[1]; + + switch(mmod->name) + { + case PHYREX_UNIFORM: + { + if(PHYREX_Is_In_Disk(disk->ldsk_a[i]->coord,new_disk,mmod) == YES) + parent_prob[i] = 1.0; + else + parent_prob[i] = 0.0; + break; + } + case PHYREX_NORMAL: + { + parent_prob[i] = 0.0; + parent_prob[i] += -pow(lx - cx,2)/(2.*pow(mmod->rad,2)); + parent_prob[i] += -pow(ly - cy,2)/(2.*pow(mmod->rad,2)); + parent_prob[i] = exp(parent_prob[i]); + break; + } + } + } + + sum = 0.0; + for(i=0;ildsk = disk->ldsk_a[parent_id]; + + Free(parent_prob); + + + /* Which lineages survive that event? */ + n_survive = 0; + for(i=0;ildsk_a[i]->coord->lonlat[0]; + ly = disk->ldsk_a[i]->coord->lonlat[1]; + + prob_death = 0.0; + switch(mmod->name) + { + case PHYREX_UNIFORM: + { + if(PHYREX_Is_In_Disk(disk->ldsk_a[i]->coord,new_disk,mmod) == YES) + prob_death = mmod->mu; + break; + } + case PHYREX_NORMAL: + { + prob_death = log(mmod->mu); + prob_death += -pow(lx - cx,2)/(2.*pow(mmod->rad,2)); + prob_death += -pow(ly - cy,2)/(2.*pow(mmod->rad,2)); + prob_death = exp(prob_death); + break; + } + } + + dies = NO; + if(Uni() < prob_death) dies = YES; + + if(dies == NO) + { + if(n_survive == 0) new_disk->ldsk_a = (t_ldsk **)mCalloc(1,sizeof(t_ldsk *)); + else new_disk->ldsk_a = (t_ldsk **)mRealloc(new_disk->ldsk_a,n_survive+1,sizeof(t_ldsk *)); + new_disk->ldsk_a[n_survive] = disk->ldsk_a[i]; + n_survive++; + } + } + + /* PhyML_Printf("\n. n_survive: %d",n_survive); */ + + /* Offspring */ + /* How many? */ + phydbl r = mmod->rad; + phydbl u = mmod->mu; + phydbl rho = mmod->rho; + phydbl mean = + 0.5*PI*rho*u*r*r* + (erf(0.5*sqrt(2.)/r*(cy-0.0))*erf(0.5*sqrt(2.)/r*(cx-0.0)) + + erf(0.5*sqrt(2.)/r*(cy-h))*erf(0.5*sqrt(2.)/r*(cx-w)) - + erf(0.5*sqrt(2.)/r*(cy-0.0))*erf(0.5*sqrt(2.)/r*(cx-w)) - + erf(0.5*sqrt(2.)/r*(cy-h))*erf(0.5*sqrt(2.)/r*(cx-0.0))); + + n_offspring = Rpois(mean); + + new_disk->n_ldsk_a = n_survive + n_offspring; + + /* PhyML_Printf("\n. n_offspring: %d",n_offspring); */ + + /* Where */ + for(i=0;ildsk_a == NULL) new_disk->ldsk_a = (t_ldsk **)mCalloc(n_survive+1,sizeof(t_ldsk *)); + else new_disk->ldsk_a = (t_ldsk **)mRealloc(new_disk->ldsk_a,n_survive+i+1,sizeof(t_ldsk *)); + + new_disk->ldsk_a[n_survive+i] = new_ldsk; + + + /* Generate new location */ + switch(mmod->name) + { + case PHYREX_UNIFORM: { PHYREX_Runif_Rectangle_Overlap(new_ldsk,new_disk,mmod); break; } + case PHYREX_NORMAL: { PHYREX_Rnorm_Trunc(new_ldsk,new_disk,mmod); break; } + } + + /* Connect to parent */ + new_ldsk->prev = disk->ldsk_a[parent_id]; + } + } + else + { + new_disk->time = t_sim; + new_disk->n_ldsk_a = disk->n_ldsk_a; + new_disk->ldsk_a = (t_ldsk **)mCalloc(curr_pop_size,sizeof(t_ldsk *)); + for(i=0;ildsk_a[i] = disk->ldsk_a[i]; + } + + + disk = new_disk; + + /* printf("\n. pop size: %6d # of events: %6d",disk->n_ldsk_a,n_disk); */ + } + while(disk->time < t_sim); + + + /* Dispersal stuff */ + /* { */ + /* phydbl T = disk->time; // total simulation time (in calendar unit) */ + /* t_ldsk *dum_ldsk = disk->ldsk_a[Rand_Int(0,disk->n_ldsk_a-1)]; // random selection of a lineage among all the lineages available at present time */ + /* t_dsk *dum_dsk = disk; */ + /* phydbl s = w*h; // area */ + /* printf("\n. s: %f",s); fflush(NULL); */ + /* phydbl gentime = 1./(2.*PI*mmod->rad*mmod->rad*mmod->mu*mmod->lbda/s); */ + /* phydbl ssq = 0.0; // sum of squared difference between current and previous position of lineage, when previous pos != current pos. */ + /* phydbl curr_pos,prev_pos; */ + /* int curr_gen,prev_gen,nhits=0; */ + /* prev_pos = dum_ldsk->coord->lonlat[0]; */ + /* curr_pos = prev_pos; */ + /* curr_gen = prev_gen = 1; */ + /* // Compute sum of squared difference of positions */ + /* do */ + /* { */ + /* curr_gen = 1 + (int)(dum_dsk->time-T)/gentime; // increment the number of generations (generation time measured in calendar time units) */ + /* curr_pos = dum_ldsk->coord->lonlat[0]; // current position of lineage */ + + /* if(dum_ldsk->disk == dum_dsk) // lineage was born at that time */ + /* { */ + /* dum_ldsk = dum_ldsk->prev; // jump to parent */ + /* nhits++; */ + /* } */ + + /* if(curr_gen != prev_gen) */ + /* { */ + /* ssq += pow(curr_pos-prev_pos,2); */ + /* prev_pos = curr_pos; */ + /* prev_gen = curr_gen; */ + /* } */ + + /* dum_dsk = dum_dsk->prev; */ + /* } */ + /* while(dum_dsk); */ + + /* PhyML_Printf("\n # var T nhits T/nhits gentime sigsq theta u lambda"); */ + /* PhyML_Printf("\n a@z %G %f %d %f %f %f %f %f %f", */ + /* (1./(T/gentime))*ssq, */ + /* T, */ + /* nhits, */ + /* T/nhits, */ + /* gentime, */ + /* 4*pow(mmod->rad,4)*mmod->lbda/s*PI*mmod->mu*gentime, */ + /* mmod->rad, */ + /* mmod->mu, */ + /* mmod->lbda); */ + + /* Exit("\n"); */ + /* } */ + + + /* /\* Coalescence stuff *\/ */ + /* { */ + /* t_ldsk *lin1, *lin2; */ + /* int n_evts,have_coal,coal_evt; */ + /* phydbl T,t; */ + + /* /\* Selection of two lineages at random *\/ */ + /* while(disk->next) disk = disk->next; */ + /* permut = Permutate(disk->n_ldsk_a); */ + /* lin1 = disk->ldsk_a[permut[0]]; */ + /* lin2 = disk->ldsk_a[permut[1]]; */ + /* Free(permut); */ + + /* printf("\n. disk->time-lin1->prev->time: %f",disk->time-lin1->prev->disk->time); */ + /* printf("\n. disk->time-lin2->prev->time: %f",disk->time-lin2->prev->disk->time); */ + + /* /\* Go back in time *\/ */ + /* curr_t = 0.0; */ + /* n_evts = 0; */ + /* coal_evt = 0; */ + /* have_coal = 0; */ + /* T = disk->time; */ + /* do */ + /* { */ + /* if(disk->ldsk) n_evts++; */ + + /* if(disk->ldsk && disk->ldsk == lin1->prev) lin1 = lin1->prev; */ + /* if(disk->ldsk && disk->ldsk == lin2->prev) lin2 = lin2->prev; */ + + /* if(lin1 == lin2) */ + /* { */ + /* have_coal = 1; */ + /* coal_evt = n_evts; */ + /* break; */ + /* } */ + + /* disk = disk->prev; */ + /* t=disk?disk->time:0.0; */ + /* curr_t = (T-t); */ + + /* /\* printf("\n>>> coal %d n_evts: %d curr_t: %f disk->time: %f T: %f one_gen: %f", *\/ */ + /* /\* have_coal, *\/ */ + /* /\* n_evts, *\/ */ + /* /\* curr_t, *\/ */ + /* /\* t, *\/ */ + /* /\* T, *\/ */ + /* /\* one_gen); *\/ */ + /* } */ + /* /\* while(disk && n_evts < 2); *\/ */ + /* while(disk && curr_t < one_gen); */ + + /* PhyML_Printf("\n. @ coal : %d %d %f",have_coal,coal_evt,curr_t); */ + /* /\* Exit("\n"); *\/ */ + /* } */ + + + + + /* Allocate coordinates for all the tips first (will grow afterwards) */ + ldsk_a_samp = (t_ldsk **)mCalloc(n_otu,sizeof(t_ldsk *)); + ldsk_a_tips = (t_ldsk **)mCalloc(n_otu,sizeof(t_ldsk *)); + ldsk_a_tmp = (t_ldsk **)mCalloc(n_otu,sizeof(t_ldsk *)); + + while(disk->next) disk = disk->next; + ldsk_a_pop = disk->ldsk_a; + + + /* /\* Sample n_otu individuals uniformly at random... *\/ */ + /* while(disk->next) disk = disk->next; */ + /* permut = Permutate(disk->n_ldsk_a); */ + /* for(i=0;in_poly_vert;++j) + { + poly[i]->poly_vert[j]->lonlat[0] *= (mmod->lim_up->lonlat[0]-mmod->lim_do->lonlat[0])*0.5; + poly[i]->poly_vert[j]->lonlat[1] *= (mmod->lim_up->lonlat[1]-mmod->lim_do->lonlat[1])*0.5; + } + + max_x = 0.0; + max_y = 0.0; + for(j=0;jn_poly_vert;++j) + { + if(poly[i]->poly_vert[j]->lonlat[0] > max_x) max_x = poly[i]->poly_vert[j]->lonlat[0]; + if(poly[i]->poly_vert[j]->lonlat[1] > max_y) max_y = poly[i]->poly_vert[j]->lonlat[1]; + } + + trans_x = Uni()*(mmod->lim_up->lonlat[0] - max_x); + trans_y = Uni()*(mmod->lim_up->lonlat[1] - max_y); + + for(j=0;jn_poly_vert;++j) + { + poly[i]->poly_vert[j]->lonlat[0] += trans_x; + poly[i]->poly_vert[j]->lonlat[1] += trans_y; + } + } + + for(i=0;icoord,poly[permut[j]]) == YES) + { + char *s; + int k; + + s = (char *)mCalloc((int)strlen(ldsk_a_pop[i]->coord->id)+1+50,sizeof(char)); + For(k,(int)strlen(ldsk_a_pop[i]->coord->id)+1+20) s[k]='\0'; + sprintf(s,"%d_",i); + strcat(s,ldsk_a_pop[i]->coord->id); + Free(ldsk_a_pop[i]->coord->id); + strcat(s,"_deme"); + sprintf(s+strlen(s),"%d",permut[j]); + ldsk_a_pop[i]->coord->id = s; + + + ldsk_a_samp[sample_size] = ldsk_a_pop[i]; + sample_size++; + PhyML_Printf("\n@ Coord: %f %f %s %p", + ldsk_a_samp[sample_size-1]->coord->lonlat[0], + ldsk_a_samp[sample_size-1]->coord->lonlat[1], + ldsk_a_pop[i]->coord->id,ldsk_a_pop[i]); + + is_sampled[permut[j]] = YES; + break; + } + } + if(sample_size == n_otu) break; + } + + Free(permut); + + if(i == curr_pop_size) + { + for(j=0;jn_poly = n_sampled_demes; + n_sampled_demes = 0; + for(i=0;ia_poly[n_sampled_demes++] = poly[i]; + + + for(i=0;in_poly;++i) + { + /* PhyML_Printf("\n@ Poly %3d area = %f",i,Area_Of_Poly_Monte_Carlo(area->a_poly[i],mmod->lim)); */ + + for(j=0;ja_poly[i]->n_poly_vert;++j) + { + PhyML_Printf("\n@ Poly %3d point %d (x,y) = (%f,%f)", + i, + j, + area->a_poly[i]->poly_vert[j]->lonlat[0], + area->a_poly[i]->poly_vert[j]->lonlat[1]); + } + } + + tree->young_disk = disk; + disk->ldsk_a = ldsk_a_tips; + disk->mmod = tree->mmod; + disk->centr->lonlat[0] = .5*(tree->mmod->lim_up->lonlat[0]-tree->mmod->lim_do->lonlat[0]); + disk->centr->lonlat[1] = .5*(tree->mmod->lim_up->lonlat[1]-tree->mmod->lim_do->lonlat[1]); + disk->n_ldsk_a = n_otu; + + int n_discs = 0; + + n_lineages = n_otu; + do + { + n_remain = 0; + for(i=0;iprev->ldsk != NULL) && (disk->prev->ldsk == ldsk_a_samp[i]->prev)) /* Coalescent event is sampled */ + { + PHYREX_Make_Lindisk_Next(disk->prev->ldsk); + disk->prev->ldsk->next[disk->prev->ldsk->n_next-1] = ldsk_a_samp[i]; + } + else + { + ldsk_a_tmp[n_remain] = ldsk_a_samp[i]; + n_remain++; + } + } + + for(i=0;iprev->ldsk != NULL) && (disk->prev->ldsk->n_next > 0)) ldsk_a_samp[i] = disk->prev->ldsk; + + if((disk->prev->ldsk != NULL) && (disk->prev->ldsk->n_next > 0)) + { + n_lineages -= (disk->prev->ldsk->n_next); + n_lineages += 1; + } + + if(n_lineages != n_remain+(disk->prev->ldsk && disk->prev->ldsk->n_next>0)?1:0) + { + PhyML_Fprintf(stderr,"\n. n_lineages: %d n_remain: %d n_next: %d", + n_lineages, + n_remain, + disk->prev->ldsk->n_next); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + /* None of the sampled lineages was hit */ + if((disk->prev->ldsk != NULL) && (disk->prev->ldsk->n_next == 0)) + { + /* printf("\n. free %s @ %f",disk->ldsk->coord->id,disk->time); */ + Free_Ldisk(disk->prev->ldsk); + disk->prev->ldsk = NULL; + } + + disk = disk->prev; + + if(disk->prev == NULL) + { + PhyML_Fprintf(stderr,"\n. # lineages left: %d",n_remain); + PhyML_Fprintf(stderr,"\n. Sample has not coalesced completely."); + fflush(NULL); + Exit("\n"); + } + } + while(n_lineages > 1); + + + /* for(i=0;i %s",tree->young_disk->ldsk_a[i]->coord->id); */ + + disk->prev = NULL; + + disk = tree->young_disk; + tree_height = disk->time; + n_discs = 0; + while(disk) + { + disk->time -= tree_height; + disk = disk->prev; + n_discs++; + } + + Free(ldsk_a_tmp); + Free(ldsk_a_samp); + Free(ldsk_a_pop); + Free(is_sampled); + + /* PHYREX_Print_Struct('#',tree); */ + /* Exit("\n"); */ + + return(area); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +/* Test whether coord is in disk. Will actually only works in disk */ +/* is a rectangle... */ + +int PHYREX_Is_In_Disk(t_geo_coord *coord, t_dsk *disk, t_phyrex_mod *mmod) +{ + int i; + + assert(disk->centr->dim); + + if(mmod->name == PHYREX_UNIFORM) + { + for(i=0;icentr->dim;i++) + { + if(fabs(coord->lonlat[i] - disk->centr->lonlat[i]) > disk->mmod->rad + 1.E-20) + { + return(NO); + } + } + return(YES); + } + else if(mmod->name == PHYREX_NORMAL) + { + return(YES); + } + + return(-1); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl PHYREX_Lk(t_tree *tree) +{ + t_dsk *disk; + int n_evt; + + + assert(!tree->young_disk->next); + assert(tree->young_disk->prev); + + tree->mmod->c_lnL = 0.0; + + if(PHYREX_Total_Number_Of_Intervals(tree) > tree->mmod->max_num_of_intervals) + { + tree->mmod->c_lnL = UNLIKELY; + return UNLIKELY; + } + + if(isinf(tree->mmod->c_lnL) || isnan(tree->mmod->c_lnL)) + { + tree->mmod->c_lnL = UNLIKELY; + return tree->mmod->c_lnL; + } + + tree->mmod->c_lnL += PHYREX_LnPrior_Radius(tree); + + PHYREX_Update_Lindisk_List(tree); + tree->mmod->c_lnL += PHYREX_Lk_Core(tree->young_disk,tree); + + n_evt = 0; + disk = tree->young_disk->prev; + do + { + if(disk->age_fixed == NO) n_evt++; + + assert(disk); + if(disk->time > disk->next->time) + { + PhyML_Printf("\n. Anomaly in ordering of disk times (disk->time: %f disk->next->time: %f)",disk->time,disk->next->time); + PhyML_Printf("\n. Currently doing following move: %s",tree->mcmc->move_name[tree->mcmc->move_idx]); + tree->mmod->c_lnL = UNLIKELY; + return tree->mmod->c_lnL; + } + + tree->mmod->c_lnL += PHYREX_Lk_Core(disk,tree); + if(disk->prev == NULL) break; + disk = disk->prev; + } + while(1); + + tree->mmod->c_lnL += PHYREX_Lk_Time_Component(tree); + + /* tree->mmod->c_lnL += n_evt * log(tree->mmod->lbda) - tree->mmod->lbda * fabs(tree->young_disk->time - disk->time); */ + + if(isinf(tree->mmod->c_lnL) || isnan(tree->mmod->c_lnL)) tree->mmod->c_lnL = UNLIKELY; + + return(tree->mmod->c_lnL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl PHYREX_Lk_Core(t_dsk *disk, t_tree *tree) +{ + phydbl lnL,log_prob_hit,log_mu; + int was_hit,i,j,err; + phydbl two_theta_two; + + two_theta_two = 2.*pow(tree->mmod->rad,2); + lnL = 0.0; + log_mu = log(tree->mmod->mu); + was_hit = (disk->ldsk != NULL); + + if(disk == tree->young_disk) return 0.0; + if(disk->age_fixed == YES) return 0.0; + + for(i=0;in_ldsk_a;++i) + if(disk->ldsk_a[i]->prev->disk->time > disk->time) + return UNLIKELY; + + if(disk->ldsk != NULL) + { + for(i=0;in_ldsk_a;++i) if(disk->ldsk_a[i]->prev == disk->ldsk) break; + if(i == disk->n_ldsk_a) return UNLIKELY; + /* assert(i != disk->n_ldsk_a); */ + } + + for(i=0;in_ldsk_a;++i) + { + if(PHYREX_Is_In_Ldscape(disk->ldsk_a[i],tree->mmod) == NO) + { + for(j=0;jmmod->n_dim;j++) PhyML_Fprintf(stdout,"\n. Found a lineage outside habitat (%20f)",disk->ldsk_a[i]->coord->lonlat[j]); + return(UNLIKELY); + } + + log_prob_hit = log_mu; + for(j=0;jmmod->n_dim;j++) + log_prob_hit += -pow(disk->ldsk_a[i]->coord->lonlat[j] - disk->centr->lonlat[j],2)/two_theta_two; + + + if(disk->ldsk_a[i]->prev == disk->ldsk) // disk->ldsk_a[i] was hit + { + lnL += log_prob_hit; + } + else // disk->ldsk_a[i] was not hit + { + lnL += log(1. - exp(log_prob_hit)); + } + } + + /* a hit occurred */ + if(was_hit == TRUE) + { + err = NO; + for(j=0;jmmod->n_dim;j++) lnL += Log_Dnorm_Trunc(disk->ldsk->coord->lonlat[j], + disk->centr->lonlat[j], + tree->mmod->rad, + tree->mmod->lim_do->lonlat[j], + tree->mmod->lim_up->lonlat[j],&err); + } + + /* Likelihood for the disk center */ + for(j=0;jmmod->n_dim;j++) lnL += log(1./(tree->mmod->lim_up->lonlat[j]-tree->mmod->lim_do->lonlat[j])); + + return(lnL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Warning: the calculation below does not incoporate time information +// since things get messy when considering serial samples +phydbl PHYREX_Lk_Range(t_dsk *young, t_dsk *old, t_tree *tree) +{ + t_dsk *disk; + phydbl lnL,dt; + int n_evt; + + /* return(PHYREX_Lk(tree)); */ + + if(PHYREX_Total_Number_Of_Intervals(tree) > tree->mmod->max_num_of_intervals) return UNLIKELY; + + assert(young); + + lnL = 0.0; + + PHYREX_Update_Lindisk_List_Core(young,tree); + lnL += PHYREX_Lk_Core(young,tree); + + dt = 0.0; + n_evt = 0; + disk = young->prev; + do + { + if(disk->age_fixed == NO) + { + dt += fabs(disk->next->time - disk->time); + n_evt++; + } + + assert(disk); + if(disk->time > disk->next->time) return UNLIKELY; + PHYREX_Update_Lindisk_List_Core(disk,tree); + lnL += PHYREX_Lk_Core(disk,tree); + if(disk == old) break; + disk = disk->prev; + } + while(disk); + + lnL += n_evt * log(tree->mmod->lbda) - tree->mmod->lbda * dt; + + return(lnL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl PHYREX_Lk_Core_Range(t_dsk *young, t_dsk *old, t_tree *tree) +{ + t_dsk *disk; + phydbl lnL; + + assert(young); + + lnL = 0.0; + + PHYREX_Update_Lindisk_List_Core(young,tree); + lnL += PHYREX_Lk_Core(young,tree); + + disk = young->prev; + do + { + assert(disk); + PHYREX_Update_Lindisk_List_Core(disk,tree); + lnL += PHYREX_Lk_Core(disk,tree); + if(disk == old) break; + disk = disk->prev; + } + while(1); + + + return(lnL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#if (defined PHYREX) +phydbl *PHYREX_MCMC(t_tree *tree) +{ + t_mcmc *mcmc; + int move,i,n_vars; + phydbl u; + FILE *fp_tree,*fp_stats; + phydbl *res; + t_dsk *disk; + + fp_tree = tree->io->fp_out_tree; + fp_stats = tree->io->fp_out_stats; + + if(tree->io->mcmc == NULL) + { + mcmc = MCMC_Make_MCMC_Struct(); + tree->mcmc = mcmc; + } + else + { + tree->mcmc = tree->io->mcmc; + mcmc = tree->mcmc; + } + + + mcmc->io = NULL; + mcmc->is = NO; + mcmc->run = 0; + mcmc->randomize = YES; + mcmc->norm_freq = 1E+3; + mcmc->max_tune = 1.E+20; + mcmc->is_burnin = YES; + mcmc->nd_t_digits = 1; + mcmc->max_lag = 1000; + mcmc->sample_size = mcmc->chain_len/mcmc->sample_interval; + mcmc->sample_num = 0; + disk = NULL; + + PhyML_Fprintf(fp_tree,"#NEXUS"); + PhyML_Fprintf(fp_tree,"\n\nBegin taxa;"); + PhyML_Fprintf(fp_tree,"\n\tDimensions ntax=%d;",tree->n_otu); + PhyML_Fprintf(fp_tree,"\n\tTaxlabels"); + for(int i=0;in_otu;++i) + { + PhyML_Fprintf(fp_tree,"\n\t\t'%s'",tree->a_nodes[i]->name); + } + PhyML_Fprintf(fp_tree,"\n\t;"); + PhyML_Fprintf(fp_tree,"\n\tend;"); + PhyML_Fprintf(fp_tree,"\n\n"); + PhyML_Fprintf(fp_tree,"\nBegin trees;"); + PhyML_Fprintf(fp_tree,"\n\tTranslate"); + for(int i=0;in_otu;++i) + { + PhyML_Fprintf(fp_tree,"\n\t%d '%s'",i+1,tree->a_nodes[i]->name); + if(in_otu-1) PhyML_Fprintf(fp_tree,","); + } + PhyML_Fprintf(fp_tree,"\n;"); + + + + + + MCMC_Complete_MCMC(mcmc,tree); + + n_vars = 12; + + res = (phydbl *)mCalloc(tree->mcmc->chain_len / tree->mcmc->sample_interval * n_vars,sizeof(phydbl)); + + + /* Starting parameter values */ + + /* tree->mmod->lbda = Uni()*(tree->mmod->max_lbda - tree->mmod->min_lbda) + tree->mmod->min_lbda; */ + /* tree->mmod->lbda = (phydbl)(tree->n_otu) / (1.0+fabs(PHYREX_Tree_Height(tree))); */ + /* tree->mmod->mu = Uni()*(tree->mmod->max_mu - tree->mmod->min_mu) + tree->mmod->min_mu; */ + /* tree->mmod->rad = Uni()*(tree->mmod->max_rad - tree->mmod->max_rad/2.) + tree->mmod->max_rad/2.; */ + /* tree->mmod->lbda = 1.0; */ + /* tree->mmod->mu = 0.9; */ + /* tree->mmod->rad = tree->mmod->max_rad/2.; */ + /* tree->mmod->rad = 4.0; */ + + + PHYREX_Update_Sigsq(tree); + + MIXT_Set_Bl_From_Rt(YES,tree); + + if(XML_Search_Node_Attribute_Value("add","true",NO,tree->xml_root) == NULL) + { + PhyML_Fprintf(fp_stats,"\n# before rand glnL: %f alnL: %f",tree->mmod->c_lnL,tree->c_lnL); + PhyML_Fprintf(fp_stats,"\n# ninter: %d",PHYREX_Total_Number_Of_Intervals(tree)); + PhyML_Fprintf(fp_stats,"\n# ncoal: %d",PHYREX_Total_Number_Of_Coal_Disks(tree)); + PhyML_Fprintf(fp_stats,"\n# nhits: %d",PHYREX_Total_Number_Of_Hit_Disks(tree)); + PhyML_Fprintf(fp_stats,"\n# true lbda: %f",tree->mmod->lbda); + PhyML_Fprintf(fp_stats,"\n# true mu: %f",tree->mmod->mu); + PhyML_Fprintf(fp_stats,"\n# true rad: %f",PHYREX_Update_Radius(tree)); + PhyML_Fprintf(fp_stats,"\n# true sigsq: %f",tree->mmod->sigsq); + PhyML_Fprintf(fp_stats,"\n# true neigh. size: %f",PHYREX_Neighborhood_Size(tree)); + PhyML_Fprintf(fp_stats,"\n# fst-based estimate of neighborhood size: %f",PHYREX_Neighborhood_Size_Regression(tree)); + PhyML_Fprintf(fp_stats,"\n# nucleotide diversity: %f",Nucleotide_Diversity(tree->data)); + PhyML_Fprintf(fp_stats,"\n# length of a generation: %G time units",PHYREX_Generation_Length(tree)); + PhyML_Fprintf(fp_stats,"\n# clock rate: %G subst. per time unit",tree->rates->clock_r); + PhyML_Fprintf(fp_stats,"\n# after rand glnL: %f alnL: %f",tree->mmod->c_lnL,tree->c_lnL); + PhyML_Fprintf(fp_stats,"\n# ninter: %d",PHYREX_Total_Number_Of_Intervals(tree)); + PhyML_Fprintf(fp_stats,"\n# ncoal: %d",PHYREX_Total_Number_Of_Coal_Disks(tree)); + PhyML_Fprintf(fp_stats,"\n# nhits: %d",PHYREX_Total_Number_Of_Hit_Disks(tree)); + PhyML_Fprintf(fp_stats,"\n# start lbda: %f",tree->mmod->lbda); + PhyML_Fprintf(fp_stats,"\n# start mu: %f",tree->mmod->mu); + PhyML_Fprintf(fp_stats,"\n# start rad: %f",tree->mmod->rad); + PhyML_Fprintf(fp_stats,"\n# dist. in tree: "); + for(int i=0;in_otu-1;++i) for(int j=i+1;jn_otu;++j) PhyML_Fprintf(fp_stats,"%G ",PHYREX_Dist_Between_Two_Ldsk(tree->a_nodes[i]->ldsk,tree->a_nodes[j]->ldsk,tree)); + PhyML_Fprintf(fp_stats,"\n# dist. in space: "); + for(int i=0;in_otu-1;++i) for(int j=i+1;jn_otu;++j) PhyML_Fprintf(fp_stats,"%G ",Euclidean_Dist(tree->a_nodes[i]->ldsk->coord,tree->a_nodes[j]->ldsk->coord)); + PhyML_Printf("\n"); + + + + fflush(NULL); + + + PhyML_Fprintf(fp_stats,"\n"); + PhyML_Fprintf(fp_stats,"%s\t","sample"); + PhyML_Fprintf(fp_stats,"%s\t","lnP"); + PhyML_Fprintf(fp_stats,"%s\t","alnL"); + PhyML_Fprintf(fp_stats,"%s\t","glnL"); + PhyML_Fprintf(fp_stats,"%s\t","clock"); + PhyML_Fprintf(fp_stats,"%s\t","evolrate"); + PhyML_Fprintf(fp_stats,"%s\t","lbda"); + PhyML_Fprintf(fp_stats,"%s\t","mu"); + PhyML_Fprintf(fp_stats,"%s\t","rad"); + PhyML_Fprintf(fp_stats,"%s\t","neigh"); + PhyML_Fprintf(fp_stats,"%s\t","rhoe"); + PhyML_Fprintf(fp_stats,"%s\t","sigSq"); + PhyML_Fprintf(fp_stats,"%s\t","realsigsqroot"); + PhyML_Fprintf(fp_stats,"%s\t","realsigsqtips"); + PhyML_Fprintf(fp_stats,"%s\t","realsigsqtipsbis"); + PhyML_Fprintf(fp_stats,"%s\t","realsigsqtipster"); + PhyML_Fprintf(fp_stats,"%s\t","dispdist"); + PhyML_Fprintf(fp_stats,"%s\t","nInt"); + PhyML_Fprintf(fp_stats,"%s\t","nCoal"); + PhyML_Fprintf(fp_stats,"%s\t","nHit"); + PhyML_Fprintf(fp_stats,"%s\t","rootTime"); + PhyML_Fprintf(fp_stats,"%s\t","rootLon"); + PhyML_Fprintf(fp_stats,"%s\t","rootLat"); + for(int i=0;imod->kappa);++i) PhyML_Fprintf(fp_stats,"tstv%d\t",i); + if(tree->mod->ras->free_mixt_rates == NO) PhyML_Fprintf(fp_stats,"alpha\t"); + else + { + for(int i=0;imod->ras->n_catg;++i) PhyML_Fprintf(fp_stats,"p(%d)\t",i+1); + for(int i=0;imod->ras->n_catg;++i) PhyML_Fprintf(fp_stats,"rr(%d)\t",i+1); + } + + PhyML_Fprintf(fp_stats,"%s\t","MeanBr"); + PhyML_Fprintf(fp_stats,"%s\t","TreeLen"); + PhyML_Fprintf(fp_stats,"%s\t","accLbda"); + PhyML_Fprintf(fp_stats,"%s\t","accMu"); + PhyML_Fprintf(fp_stats,"%s\t","accRad"); + PhyML_Fprintf(fp_stats,"%s\t","accInDelDisk"); + PhyML_Fprintf(fp_stats,"%s\t","accInDelHit"); + PhyML_Fprintf(fp_stats,"%s\t","accScaleTime"); + PhyML_Fprintf(fp_stats,"%s\t","accSPR"); + PhyML_Fprintf(fp_stats,"%s\t","accSPRlocal"); + PhyML_Fprintf(fp_stats,"%s\t","accPath"); + PhyML_Fprintf(fp_stats,"%s\t","accIndelDiskSerial"); + PhyML_Fprintf(fp_stats,"%s\t","accIndelHitSerial"); + PhyML_Fprintf(fp_stats,"%s\t","accLdskGivenDisk"); + PhyML_Fprintf(fp_stats,"%s\t","accDiskGivenLdsk"); + PhyML_Fprintf(fp_stats,"%s\t","accDiskAndLdsk"); + PhyML_Fprintf(fp_stats,"%s\t","accLdskMulti"); + PhyML_Fprintf(fp_stats,"%s\t","accDiskMulti"); + PhyML_Fprintf(fp_stats,"%s\t","accMoveDiskUD"); + PhyML_Fprintf(fp_stats,"%s\t","accAddRemoveJump"); + PhyML_Fprintf(fp_stats,"%s\t","accLdskTipToRoot"); + PhyML_Fprintf(fp_stats,"%s\t","tuneLbda"); + PhyML_Fprintf(fp_stats,"%s\t","tuneRad"); + PhyML_Fprintf(fp_stats,"%s\t","tuneMu"); + PhyML_Fprintf(fp_stats,"%s\t","tuneIndelDisk"); + PhyML_Fprintf(fp_stats,"%s\t","tuneIndelHit"); + PhyML_Fprintf(fp_stats,"%s\t","tuneLdskGivenDisk"); + PhyML_Fprintf(fp_stats,"%s\t","tuneIndelDiskSerial"); + PhyML_Fprintf(fp_stats,"%s\t","tuneIndelHitSerial"); + } + + + for(i=0;in_moves;i++) tree->mcmc->start_ess[i] = YES; + + PHYREX_Lk(tree); + Set_Update_Eigen(YES,tree->mod); + Lk(NULL,tree); + Set_Update_Eigen(NO,tree->mod); + RATES_Lk_Rates(tree); + + if(isnan(tree->c_lnL) || isinf(tree->c_lnL)) + { + PhyML_Fprintf(stderr,"\n. Cannot compute sequence log-likelihood. Aborting."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + if(isnan(tree->mmod->c_lnL) || isinf(tree->mmod->c_lnL)) + { + PhyML_Fprintf(stderr,"\n. Cannot compute location log-likelihood. Aborting."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + + Set_Both_Sides(NO,tree); + mcmc->always_yes = NO; + move = -1; + do + { + MIXT_Propagate_Tree_Update(tree); + assert(PHYREX_Check_Struct(tree)); + + + if(mcmc->run > mcmc->chain_len_burnin) + for(i=0;in_moves;i++) tree->mcmc->adjust_tuning[i] = NO; + else + { + for(i=0;in_moves;i++) tree->mcmc->adjust_tuning[i] = YES; + tree->mcmc->is_burnin = NO; + } + + u = Uni(); + + for(move=0;movemcmc->n_moves;move++) if(tree->mcmc->move_weight[move] > u-1.E-10) break; + + tree->mcmc->move_idx = move; + + assert(!(move == tree->mcmc->n_moves)); + + if(!(tree->mcmc->run%tree->mcmc->print_every)) + { + PhyML_Fprintf(stdout,"\n. %10d %30s %20f %20f %20f", + tree->mcmc->run, + tree->mcmc->move_name[move], + tree->mmod->c_lnL, + tree->c_lnL, + tree->mmod->c_lnL+tree->c_lnL+tree->rates->c_lnL_rates); + if(tree->numerical_warning == YES) PhyML_Fprintf(stdout," -- WARNING: numerical precision issue detected..."); + } + + + /* tree->mmod->lbda = 2.0; */ + /* tree->mmod->mu = 0.5; */ + /* tree->mmod->rad = 1.; */ + /* tree->rates->clock_r = 1.0E-3; */ + + /* if(tree->mcmc->run == 0) */ + /* { */ + /* PHYREX_Strip_And_Reconnect_Tree(tree); */ + /* PHYREX_Simulate_Backward_Core(tree->young_disk,NO,tree); */ + /* PHYREX_Ldsk_To_Tree(tree); */ + /* } */ + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_lbda")) + MCMC_PHYREX_Lbda(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_mu")) + MCMC_PHYREX_Mu(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_rad")) + MCMC_PHYREX_Radius(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_indel_disk")) + MCMC_PHYREX_Indel_Disk(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_indel_hit")) + MCMC_PHYREX_Indel_Hit(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_move_disk_ud")) + MCMC_PHYREX_Move_Disk_Updown(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_swap_disk")) + MCMC_PHYREX_Swap_Disk(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_scale_times")) + MCMC_PHYREX_Scale_Times(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_spr")) + MCMC_PHYREX_Prune_Regraft(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_spr_local")) + MCMC_PHYREX_Prune_Regraft_Local(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_traj")) + MCMC_PHYREX_Lineage_Traj(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_disk_multi")) + MCMC_PHYREX_Disk_Multi(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_ldsk_multi")) + MCMC_PHYREX_Ldsk_Multi(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_ldsk_and_disk")) + MCMC_PHYREX_Ldsk_And_Disk(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_ldsk_tip_to_root")) + MCMC_PHYREX_Ldsk_Tip_To_Root(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_ldsk_given_disk")) + MCMC_PHYREX_Ldsk_Given_Disk(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_disk_given_ldsk")) + MCMC_PHYREX_Disk_Given_Ldsk(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_indel_disk_serial")) + MCMC_PHYREX_Indel_Disk_Serial(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_indel_hit_serial")) + MCMC_PHYREX_Indel_Hit_Serial(tree); + + if(!strcmp(tree->mcmc->move_name[move],"phyrex_add_remove_jump")) + MCMC_PHYREX_Add_Remove_Jump(tree); + + if(!strcmp(tree->mcmc->move_name[move],"kappa")) + MCMC_Kappa(tree); + + if(!strcmp(tree->mcmc->move_name[move],"rr")) + MCMC_RR(tree); + + if(!strcmp(tree->mcmc->move_name[move],"ras")) + MCMC_Rate_Across_Sites(tree); + + if(!strcmp(tree->mcmc->move_name[move],"br_rate")) + MCMC_Rates_All(tree); + + if(!strcmp(tree->mcmc->move_name[move],"tree_rates")) + MCMC_Tree_Rates(tree); + + if(!strcmp(tree->mcmc->move_name[move],"clock")) + MCMC_Clock_R(tree); + + + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + /* PHYREX_Lk(tree); */ + /* Lk(NULL,tree); */ + + /* PhyML_Printf("\n. Move: %s tree->mmod->c_lnL: %f kappa: %f", */ + /* tree->mcmc->move_name[move], */ + /* tree->mmod->c_lnL, */ + /* tree->mod->kappa->v); */ + + if(tree->mmod->c_lnL < UNLIKELY || tree->c_lnL < UNLIKELY) + { + PhyML_Printf("\n. Move: %s tree->mmod->c_lnL: %f tree->c_lnL: %f", + tree->mcmc->move_name[move], + tree->mmod->c_lnL,tree->c_lnL); + assert(FALSE); + } + + if(tree->mmod->safe_phyrex == YES) + { + /* phydbl c_lnL = tree->c_lnL; */ + /* Lk(NULL,tree); */ + /* if(Are_Equal(c_lnL,tree->c_lnL,1.E-5) == NO) */ + /* { */ + /* PhyML_Fprintf(stderr,"\n. Problem detected with move %s",tree->mcmc->move_name[move]); */ + /* PhyML_Fprintf(stderr,"\n. c_lnL: %f -> %f",c_lnL,tree->c_lnL); */ + /* Generic_Exit(__FILE__,__LINE__,__FUNCTION__); */ + /* } */ + + phydbl g_lnL = tree->mmod->c_lnL; + PHYREX_Lk(tree); + if(Are_Equal(g_lnL,tree->mmod->c_lnL,1.E-5) == NO) + { + PhyML_Fprintf(stderr,"\n. Problem detected with move %s. Iteration %d",tree->mcmc->move_name[move],tree->mcmc->run); + PhyML_Fprintf(stderr,"\n. g_lnL: %f -> %f [%g]",g_lnL,tree->mmod->c_lnL,g_lnL-tree->mmod->c_lnL); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + /* phydbl r_lnL = tree->rates->c_lnL_rates; */ + /* RATES_Lk_Rates(tree); */ + /* if(Are_Equal(r_lnL,tree->rates->c_lnL_rates,1.E-5) == NO) */ + /* { */ + /* PhyML_Fprintf(stderr,"\n. Problem detected with move %s",tree->mcmc->move_name[move]); */ + /* PhyML_Fprintf(stderr,"\n. r_lnL: %f -> %f [%g]",r_lnL,tree->rates->c_lnL_rates,r_lnL-tree->rates->c_lnL_rates); */ + /* Generic_Exit(__FILE__,__LINE__,__FUNCTION__); */ + /* } */ + } + + tree->mcmc->run++; + MCMC_Get_Acc_Rates(tree->mcmc); + + + if(!(tree->mcmc->run%tree->mcmc->sample_interval)) + { + + disk = tree->young_disk; + while(disk->prev) disk = disk->prev; + + PhyML_Fprintf(fp_stats,"\n"); + PhyML_Fprintf(fp_stats,"%6d\t",tree->mcmc->run); + PhyML_Fprintf(fp_stats,"%g\t",tree->c_lnL+tree->mmod->c_lnL+tree->rates->c_lnL_rates); + PhyML_Fprintf(fp_stats,"%g\t",tree->c_lnL); + PhyML_Fprintf(fp_stats,"%g\t",tree->mmod->c_lnL); + PhyML_Fprintf(fp_stats,"%g\t",tree->rates->clock_r); + PhyML_Fprintf(fp_stats,"%g\t",RATES_Realized_Substitution_Rate(tree)); + PhyML_Fprintf(fp_stats,"%g\t",tree->mmod->lbda); + PhyML_Fprintf(fp_stats,"%g\t",tree->mmod->mu); + PhyML_Fprintf(fp_stats,"%g\t",tree->mmod->rad); + PhyML_Fprintf(fp_stats,"%g\t",PHYREX_Neighborhood_Size(tree)); + PhyML_Fprintf(fp_stats,"%g\t",PHYREX_Effective_Density(tree)); + PhyML_Fprintf(fp_stats,"%g\t",PHYREX_Update_Sigsq(tree)); + PhyML_Fprintf(fp_stats,"%g\t",PHYREX_Root_To_Tip_Realized_Sigsq(tree)); + PhyML_Fprintf(fp_stats,"%g\t",PHYREX_Tip_To_Root_Realized_Sigsq(tree)); + PhyML_Fprintf(fp_stats,"%g\t",PHYREX_Tip_To_Root_Realized_Bis_Sigsq(tree)); + PhyML_Fprintf(fp_stats,"%g\t",PHYREX_Tip_To_Root_Realized_Ter_Sigsq(tree)); + PhyML_Fprintf(fp_stats,"%g\t",PHYREX_Realized_Dispersal_Dist(tree)); + PhyML_Fprintf(fp_stats,"%d\t",PHYREX_Total_Number_Of_Intervals(tree)); + PhyML_Fprintf(fp_stats,"%d\t",PHYREX_Total_Number_Of_Coal_Disks(tree)); + PhyML_Fprintf(fp_stats,"%d\t",PHYREX_Total_Number_Of_Hit_Disks(tree)); + PhyML_Fprintf(fp_stats,"%g\t",disk->time); + PhyML_Fprintf(fp_stats,"%g\t",disk->ldsk->coord->lonlat[0]); + PhyML_Fprintf(fp_stats,"%g\t",disk->ldsk->coord->lonlat[1]); + Output_Scalar_Dbl(tree->mod->kappa,"\t",fp_stats); + if(tree->mod->ras->free_mixt_rates == NO) PhyML_Fprintf(fp_stats,"%g\t",tree->mod->ras->alpha->v); + else + { + for(int i=0;imod->ras->n_catg;++i) PhyML_Fprintf(fp_stats,"%g\t",tree->mod->ras->gamma_r_proba->v[i]); + for(int i=0;imod->ras->n_catg;++i) PhyML_Fprintf(fp_stats,"%g\t",tree->mod->ras->gamma_rr->v[i]); + } + PhyML_Fprintf(fp_stats,"%g\t",RATES_Get_Mean_Rate_In_Subtree(tree->n_root,tree)); + PhyML_Fprintf(fp_stats,"%g\t",Tree_Length(tree)); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_lbda]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_mu]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_rad]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_indel_disk]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_indel_hit]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_scale_times]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_spr]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_spr_local]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_traj]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_indel_disk_serial]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_indel_hit_serial]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_ldsk_given_disk]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_disk_given_ldsk]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_ldsk_and_disk]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_ldsk_multi]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_disk_multi]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_move_disk_ud]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_add_remove_jump]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->acc_rate[tree->mcmc->num_move_phyrex_ldsk_tip_to_root]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_lbda]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_rad]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_mu]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_indel_disk]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_indel_hit]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_ldsk_given_disk]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_indel_disk_serial]); + PhyML_Fprintf(fp_stats,"%g\t",tree->mcmc->tune_move[tree->mcmc->num_move_phyrex_indel_hit_serial]); + + + + /* res[0 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = tree->mmod->lbda; */ + /* res[1 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = tree->mmod->mu; */ + /* res[2 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = PHYREX_Update_Sigsq(tree); */ + /* res[3 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = PHYREX_Neighborhood_Size(tree); */ + /* res[4 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = tree->mmod->rad; */ + /* res[5 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = PHYREX_Total_Number_Of_Intervals(tree); */ + /* res[6 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = PHYREX_Total_Number_Of_Coal_Disks(tree); */ + /* res[7 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = PHYREX_Total_Number_Of_Hit_Disks(tree); */ + /* res[8 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = PHYREX_Effective_Density(tree); */ + /* res[9 * tree->mcmc->chain_len / tree->mcmc->sample_interval + tree->mcmc->run / tree->mcmc->sample_interval] = PHYREX_Coalescence_Rate(tree); */ + + /* MCMC_Copy_To_New_Param_Val(tree->mcmc,tree); */ + + /* for(i=0;imcmc->n_moves;i++) if(tree->mcmc->start_ess[i] == YES) MCMC_Update_Effective_Sample_Size(i,tree->mcmc,tree); */ + /* for(i=0;imcmc->n_moves;i++) MCMC_Update_Mode(i,tree->mcmc,tree); */ + + + PHYREX_Ldsk_To_Tree(tree); + TIMES_Time_To_Bl(tree); + tree->bl_ndigits = 3; + tree->write_tax_names = NO; + PHYREX_Label_Nodes_With_Locations(tree); + PHYREX_Label_Edges(tree); + char *s = Write_Tree(tree); + PhyML_Fprintf(fp_tree,"\ntree %d [&lnP=%f,precision={1.e-1,1e-02,1e-01}] = [&R] %s",tree->mcmc->sample_num,tree->c_lnL,s); + PhyML_Fprintf(fp_tree,"\nend;"); + fseek(fp_tree,-5,SEEK_END); + tree->write_tax_names = YES; + Free(s); + + fflush(NULL); + + tree->mcmc->sample_num++; + } + + (void)signal(SIGINT,MCMC_Terminate); + } + while(tree->mcmc->run < tree->mcmc->chain_len); + + PhyML_Fprintf(stdout,"\n. The analysis completed !"); + + fclose(fp_tree); + fclose(fp_stats); + /* fclose(fp_summary); */ + + return(res); +} +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl PHYREX_Wrap_Lk(t_edge *b, t_tree *tree, supert_tree *stree) +{ + return PHYREX_Lk(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void PHYREX_New_Traj(t_dsk *start, t_dsk *end, t_tree *tree) +{ + t_dsk *disk; + int i,j; + int n_hit_up,n_hit_tot; + /* phydbl min_up, min_do; */ + /* phydbl max_up, max_do; */ + + + + for(i=0;in_ldsk_a;i++) + { + /* printf("\n<><><>"); */ + + disk = end; + while(disk != start) + { + /* disk->ldsk_a[i]->min_coord = GEO_Make_Geo_Coord(disk->mmod->n_dim); */ + /* disk->ldsk_a[i]->max_coord = GEO_Make_Geo_Coord(disk->mmod->n_dim); */ + disk = disk->prev; + } + + disk = end; + n_hit_tot = 0; + while(disk != start) + { + if(disk->ldsk_a[i]->is_hit == YES) n_hit_tot++; + disk = disk->prev; + } + + + /* printf("\n. n_hit_tot: %d",n_hit_tot); */ + /* fflush(NULL); */ + + /* printf("\n. Start disk name: %s lindisk %s at %.2f [%.2f %.2f] end disk: %s lindisk %s at %.2f [%.2f %.2f]", */ + /* start->id, */ + /* start->ldsk_a[i]->coord->id, */ + /* start->time, */ + /* start->ldsk_a[i]->coord->lonlat[0], */ + /* start->ldsk_a[i]->coord->lonlat[1], */ + /* end->id, */ + /* end->ldsk_a[i]->coord->id, */ + /* end->time, */ + /* end->ldsk_a[i]->coord->lonlat[0], */ + /* end->ldsk_a[i]->coord->lonlat[1] */ + /* ); */ + /* disk = end; */ + /* while(disk != start) */ + /* { */ + /* printf("\n. %d %s %.2f %.2f", */ + /* i, */ + /* disk->ldsk_a[i]->coord->id, */ + /* disk->ldsk_a[i]->coord->lonlat[0], */ + /* disk->ldsk_a[i]->coord->lonlat[1]); */ + /* disk = disk->prev; */ + /* } */ + + n_hit_up = 0; + disk = end; + while(disk->prev != start) + { + if(disk->ldsk_a[i]->is_hit == YES) + { + n_hit_up++; + + for(j=0;jmmod->n_dim;j++) + { + /* min_up = end->ldsk_a[i]->coord->lonlat[j] - n_hit_up * 2. * disk->mmod->rad; */ + /* min_do = start->ldsk_a[i]->coord->lonlat[j] - (n_hit_tot - n_hit_up) * 2. * disk->mmod->rad; */ + /* disk->ldsk_a[i]->prev->min_coord->lonlat[j] = */ + /* MAX(MAX(MAX(min_up,min_do),0.0),disk->prev->centr->lonlat[j] - disk->mmod->rad); */ + + /* max_up = end->ldsk_a[i]->coord->lonlat[j] + n_hit_up * 2. * disk->mmod->rad; */ + /* max_do = start->ldsk_a[i]->coord->lonlat[j] + (n_hit_tot - n_hit_up) * 2. * disk->mmod->rad; */ + /* disk->ldsk_a[i]->prev->max_coord->lonlat[j] = */ + /* MIN(MIN(MIN(max_up,max_do),disk->mmod->lim->lonlat[j]),disk->prev->centr->lonlat[j] + disk->mmod->rad); */ + + /* printf("\n. curr: %s min_up: %.2f min_do: %.2f max_up: %.2f max_do: %.2f %d %d start: %.2f [%.2f %.2f]", */ + /* disk->ldsk_a[i]->prev->coord->id, */ + /* min_up,min_do,max_up,max_do, */ + /* n_hit_tot,n_hit_up, */ + /* start->ldsk_a[i]->coord->lonlat[j], */ + /* disk->ldsk_a[i]->prev->min_coord->lonlat[j], */ + /* disk->ldsk_a[i]->prev->max_coord->lonlat[j]); */ + } + } + disk = disk->prev; + } + + disk = end; + while(disk->prev != start) + { + if(disk->ldsk_a[i]->is_hit == YES) + { + /* for(j=0;jmmod->n_dim;j++) */ + /* disk->ldsk_a[i]->prev->coord->lonlat[j] = */ + /* Uni()* */ + /* (disk->ldsk_a[i]->prev->max_coord->lonlat[j] - */ + /* disk->ldsk_a[i]->prev->min_coord->lonlat[j]) + */ + /* disk->ldsk_a[i]->prev->min_coord->lonlat[j]; */ + } + else + { + for(j=0;jmmod->n_dim;j++) + disk->ldsk_a[i]->prev->coord->lonlat[j] = + disk->ldsk_a[i]->coord->lonlat[j]; + } + + disk = disk->prev; + } + + disk = end; + while(disk != start) + { + /* Free_Geo_Coord(disk->ldsk_a[i]->min_coord); */ + /* Free_Geo_Coord(disk->ldsk_a[i]->max_coord); */ + disk = disk->prev; + } + } + + /* gtk_widget_queue_draw(tree->draw_area); */ + + /* for(i=0;in_ldsk_a;i++) */ + /* { */ + /* printf("\n<><><>"); */ + /* disk = end; */ + /* while(disk != start) */ + /* { */ + /* printf("\nx %s %.2f %.2f centr: %.2f %.2f", */ + /* disk->ldsk_a[i]->coord->id, */ + /* disk->ldsk_a[i]->coord->lonlat[0], */ + /* disk->ldsk_a[i]->coord->lonlat[1], */ + /* disk->centr->lonlat[0], */ + /* disk->centr->lonlat[1]); */ + /* disk = disk->prev; */ + /* } */ + /* fflush(NULL); */ + /* } */ + + /* PHYREX_Lk(tree); */ + /* printf("\n. >> Lk: %f rad: %f",tree->mmod->c_lnL,tree->mmod->rad); */ + /* sleep(5); */ +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Remove_Disk(t_dsk *disk) +{ + t_dsk *prev; + t_dsk *next; + + prev = disk->prev; + next = disk->next; + + assert(next != NULL); + + if(prev != NULL) prev->next = next; + next->prev = prev; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Insert disk event based on its time. Insertion above the root is permitted +*/ +void PHYREX_Insert_Disk(t_dsk *ins, t_tree *tree) +{ + t_dsk *disk; + + assert(ins != NULL); + + disk = tree->young_disk; + while(disk->prev != NULL && disk->prev->time > ins->time) disk = disk->prev; + + ins->prev = disk->prev; + ins->next = disk; + disk->prev = ins; + if(ins->prev != NULL) ins->prev->next = ins; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +t_ldsk *PHYREX_Prev_Coal_Lindisk(t_ldsk *t) +{ + if(t == NULL) return NULL; + + if(t->n_next > 1) + { + return t; + } + else + { + return PHYREX_Prev_Coal_Lindisk(t->prev); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_ldsk *PHYREX_Next_Coal_Lindisk(t_ldsk *t) +{ + assert(!(t == NULL)); + + if(t->n_next > 1 || t->next == NULL) return t; + else + { + if(t->n_next > 1) // Should have t->is_coal = YES + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit(""); + } + return PHYREX_Next_Coal_Lindisk(t->next[0]); + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Generate a new trajectory, including disk event centers, between + 'y_ldsk' a ``young'' lindisk event and 'o_ldsk' an old one. 'y_ldsk + and 'o_ldsk' remain unaffected. No disk events should be present + between y_ldsk and o_ldsk: we need to generate some first. n_cur_disk + is the current number of disks between y_ldsk and o_ldsk. +*/ +int PHYREX_One_New_Traj(t_ldsk *y_ldsk, t_ldsk *o_ldsk, int dir_o_y, t_dsk *xtra_dsk, int n_cur_disk, t_tree *tree) +{ + t_phyrex_mod *mmod; + t_dsk *disk,**disk_new; + int i,n,K; + int min_n_disk,n_new_disk,n_disk; + + mmod = tree->mmod; + disk = NULL; + disk_new = NULL; + K = 2; + + /* printf("\n# New traj from %s to %s",y_ldsk->coord->id,o_ldsk->coord->id); */ + /* fflush(NULL); */ + + /* Minimum number of disks between y_ldsk and o_ldsk */ + min_n_disk = 0; + for(i=0;in_dim;i++) + { + /* PhyML_Printf("\n# y_ldsk %s : %f o_ldsk->disk->centr: %f rad: %f", */ + /* y_ldsk->coord->id, */ + /* y_ldsk->coord->lonlat[i], */ + /* o_ldsk->disk->centr->lonlat[i], */ + /* mmod->rad); */ + if(y_ldsk->coord->lonlat[i] < o_ldsk->disk->centr->lonlat[i]) + { + n_disk = 0; + while(y_ldsk->coord->lonlat[i] + (2*n_disk-1)*mmod->rad < o_ldsk->disk->centr->lonlat[i] - mmod->rad) n_disk++; + if(n_disk > min_n_disk) min_n_disk = n_disk; + } + else + { + n_disk = 0; + while(y_ldsk->coord->lonlat[i] - (2*n_disk-1)*mmod->rad > o_ldsk->disk->centr->lonlat[i] + mmod->rad) n_disk++; + if(n_disk > min_n_disk) min_n_disk = n_disk; + } + /* printf(" -- min_n_disk: %d",min_n_disk); */ + } + + /* printf("\n# min_n_disk: %d cur_n_disk: %d",min_n_disk,n_cur_disk); */ + /* fflush(NULL); */ + + /* How many disks along the new path between y_ldsk and o_ldsk */ + n_new_disk = Rand_Int(n_cur_disk-K,n_cur_disk+K); + if(n_new_disk < min_n_disk) n_new_disk = min_n_disk; + + if(xtra_dsk != NULL) n_new_disk++; + + /* printf("\n# Add n_new_disk: %d",n_new_disk); fflush(NULL); */ + + if(n_new_disk > 0) + { + /* Make new disks to create a new path between ldsk_left and ldsk_up */ + disk_new = (t_dsk **)mCalloc(n_new_disk,sizeof(t_dsk *)); + for(i=0;in_dim,tree->n_otu); + if(xtra_dsk != NULL) disk_new[n_new_disk-1] = xtra_dsk; + else disk_new[n_new_disk-1] = PHYREX_Make_Disk_Event(mmod->n_dim,tree->n_otu); + + for(i=0;in_dim,mmod); + + /* Times of these new disks. If xtra_dsk != NULL, then make sure you do not */ + /* reset the time of that disk */ + n = (xtra_dsk != NULL) ? (n_new_disk-1) : (n_new_disk); + for(i=0;itime = + Uni()*(y_ldsk->disk->time - o_ldsk->disk->time) + o_ldsk->disk->time; + + /* Insert these events */ + for(i=0;iyoung_disk->next); + disk = tree->young_disk; + while(disk->time > disk_new[i]->time) disk = disk->prev; + PHYREX_Insert_Disk(disk_new[i],tree); + } + + /* for(i=0;i disk_new: %f [%s]",disk_new[i]->time,disk_new[i]->id); fflush(NULL); */ + /* } */ + + /* Add new lindisks to the new disk events */ + for(i=0;ildsk = PHYREX_Make_Lindisk_Node(tree->mmod->n_dim); + PHYREX_Init_Lindisk_Node(disk_new[i]->ldsk,disk_new[i],tree->mmod->n_dim); + PHYREX_Make_Lindisk_Next(disk_new[i]->ldsk); + /* printf("\n# Add ldsk %s to %s",disk_new[i]->ldsk->coord->id,disk_new[i]->id); fflush(NULL); */ + } + + /* Connect them */ + PHYREX_Connect_Ldsk_Given_Disk(disk_new,n_new_disk,y_ldsk,o_ldsk,dir_o_y); + + Free(disk_new); + } + else + { + o_ldsk->next[dir_o_y] = y_ldsk; + y_ldsk->prev = o_ldsk; + } + + /* Generate a trajectory */ + PHYREX_One_New_Traj_Given_Disk(y_ldsk,o_ldsk,tree); + + return(n_new_disk); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Generate a new trajectory, including disk event centers, between + 'y_ldsk' a ``young'' lindisk event and 'o_ldsk' an old one. 'y_ldsk + and 'o_ldsk' remain unaffected. Disk events between these two ldsk + should already be set. +*/ +void PHYREX_One_New_Traj_Given_Disk(t_ldsk *y_ldsk, t_ldsk *o_ldsk, t_tree *tree) +{ + int n_disk_btw; + t_ldsk *ldsk; + phydbl min, max; + phydbl *min_disk_coord, *max_disk_coord; + int i,k; + phydbl rad; + + + /* Number of disks between y_ldsk and o_ldsk */ + ldsk = y_ldsk; + n_disk_btw = 0; + while(ldsk->prev != o_ldsk) + { + n_disk_btw++; + ldsk = ldsk->prev; + } + + if(n_disk_btw == 0) return; + + ldsk = y_ldsk; + rad = ldsk->disk->mmod->rad; + k = 0; + while(ldsk != o_ldsk) + { + if(!ldsk->disk->next) /* Don't change location at tip node */ + { + ldsk = ldsk->prev; + continue; + } + + PHYREX_Store_Geo_Coord(ldsk->coord); + PHYREX_Store_Geo_Coord(ldsk->disk->centr); + + for(i=0;immod->n_dim;i++) + { + min = + MAX(ldsk->disk->mmod->lim_do->lonlat[i], + MAX(ldsk->coord->lonlat[i] - 2.*rad, + o_ldsk->disk->centr->lonlat[i] - rad*(2.*(n_disk_btw-k)-1.))); + + max = + MIN(ldsk->disk->mmod->lim_up->lonlat[i], + MIN(ldsk->coord->lonlat[i] + 2.*rad, + o_ldsk->disk->centr->lonlat[i] + rad*(2.*(n_disk_btw-k)-1.))); + + assert(!(max < min)); + + /* New coordinates for the lindisk */ + ldsk->coord->lonlat[i] = Uni()*(max - min) + min; + } + + /* New coordinate for the centre of the corresponding disk event */ + PHYREX_Get_Min_Max_Disk_Given_Ldsk(ldsk->disk,&min_disk_coord,&max_disk_coord,tree); + for(i=0;immod->n_dim;i++) ldsk->disk->centr->lonlat[i] = Uni()*(max_disk_coord[i] - min_disk_coord[i]) + min_disk_coord[i]; + Free(min_disk_coord); + Free(max_disk_coord); + + ldsk = ldsk->prev; + k++; + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Uniform_Path_Density(t_ldsk *y_ldsk, t_ldsk *o_ldsk, t_tree *tree) +{ + int n_disk_btw; + t_ldsk *ldsk; + phydbl min, max; + int i,k; + phydbl rad; + phydbl log_dens; + phydbl *min_disk_coord, *max_disk_coord; + + if(y_ldsk == o_ldsk) return .0; + + /* Number of disks between y_ldsk and o_ldsk */ + ldsk = y_ldsk; + n_disk_btw = 0; + while(ldsk->prev != o_ldsk) + { + n_disk_btw++; + ldsk = ldsk->prev; + } + + if(n_disk_btw == 0) return .0; + + log_dens = 0.0; + ldsk = y_ldsk; + rad = ldsk->disk->mmod->rad; + k = 0; + while(ldsk != o_ldsk) + { + if(!ldsk->disk->next) + { + ldsk = ldsk->prev; + continue; + } + + for(i=0;idisk->mmod->n_dim;i++) + { + min = + MAX(ldsk->disk->mmod->lim_do->lonlat[i], + MAX(ldsk->coord->lonlat[i] - 2.*rad, + o_ldsk->disk->centr->lonlat[i] - rad*(2.*(n_disk_btw-k)-1.))); + + max = + MIN(ldsk->disk->mmod->lim_up->lonlat[i], + MIN(ldsk->coord->lonlat[i] + 2.*rad, + o_ldsk->disk->centr->lonlat[i] + rad*(2.*(n_disk_btw-k)-1.))); + + assert(!(max < min)); + + log_dens -= log(max - min); + } + + PHYREX_Get_Min_Max_Disk_Given_Ldsk(ldsk->disk,&min_disk_coord,&max_disk_coord,tree); + for(i=0;immod->n_dim;i++) log_dens -= log(max_disk_coord[i] - min_disk_coord[i]); + Free(min_disk_coord); + Free(max_disk_coord); + + ldsk = ldsk->prev; + k++; + } + + return(log_dens); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Return the index of the 'next' element of 'old' that should be + used in order to reach 'young'. +*/ +int PHYREX_Get_Next_Direction(t_ldsk *young, t_ldsk *old) +{ + if(young->disk->time < old->disk->time) + { + PhyML_Printf("\n. young (%s) @ time %f; old (%s) @ time %f", + young->coord->id,young->disk->time, + old->coord->id,old->disk->time); + assert(FALSE); + } + + assert(!(young == NULL)); + + if(young->prev == old) + { + int i; + for(i=0;in_next;i++) if(old->next[i] == young) return i; + } + else + { + return PHYREX_Get_Next_Direction(young->prev,old); + } + return(-1); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Update_Lindisk_List_Range(t_dsk *young, t_dsk *old, t_tree *tree) +{ + t_dsk *disk; + + disk = young; + do + { + assert(disk); + PHYREX_Update_Lindisk_List_Core(disk,tree); + if(disk == old) break; + disk = disk->prev; + } + while(1); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Update_Lindisk_List(t_tree *tree) +{ + PHYREX_Update_Lindisk_List_Pre(tree->young_disk->prev,tree); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Update_Lindisk_List_Pre(t_dsk *disk, t_tree *tree) +{ + if(!disk) return; + else + { + PHYREX_Update_Lindisk_List_Core(disk,tree); + PHYREX_Update_Lindisk_List_Pre(disk->prev,tree); + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Update_Lindisk_List_Core(t_dsk *disk, t_tree *tree) +{ + int i; + + if(!disk) return; + if(!disk->next) return; + + assert(disk->ldsk_a); + + // Set ldsk_a[i] to NULL if it does not point to a tip node + for(i=0;in_otu;++i) + if(disk->ldsk_a[i] && + !(disk->ldsk_a[i]->nd != NULL && + disk->ldsk_a[i]->nd->tax == YES && + disk->age_fixed == YES && + disk->ldsk_a[i]->disk == disk)) + disk->ldsk_a[i] = NULL; + + disk->n_ldsk_a = 0; + for(i=0;in_otu;++i) + if(disk->ldsk_a[i] != NULL) + disk->n_ldsk_a++; + + // Make sure the tip nodes are all at the top of ldsk_a + for(i=0;in_ldsk_a;++i) assert(disk->ldsk_a[i] != NULL); + for(i=disk->n_ldsk_a;in_otu;++i) assert(disk->ldsk_a[i] == NULL); + + for(i=0;inext->n_ldsk_a;++i) + { + // disk->next->ldsk_a[i] does not coalesce or jump on disk->next + // --> add it disk->ldsk_a array + if((disk->next->ldsk_a[i]->prev != NULL && + disk->next->ldsk_a[i]->prev != disk->next->ldsk) || + (disk->next->ldsk_a[i]->prev == NULL)) + { + disk->ldsk_a[disk->n_ldsk_a] = disk->next->ldsk_a[i]; + disk->n_ldsk_a++; + } + } + + // A jump or coalescence has occurred on disk->next + // --> add the lineage to disk->ldsk_a array + if(disk->next->ldsk != NULL) + { + disk->ldsk_a[disk->n_ldsk_a] = disk->next->ldsk; + disk->n_ldsk_a++; + } + + /* PhyML_Printf("\n"); */ + /* for(i=0;in_ldsk_a;++i) PhyML_Printf("\n. Disk %s [%12f] ldsk_a: %s (%3d)",disk->id,disk->time,disk->ldsk_a[i]->coord->id,disk->ldsk_a[i]->nd ? disk->ldsk_a[i]->nd->tax : -1); */ + /* if(disk->ldsk != NULL) PhyML_Printf("\n* Has %s on it (next: %s @ %12f %s)", */ + /* disk->ldsk->coord->id, */ + /* disk->ldsk->next[0]->coord->id, */ + /* disk->ldsk->next[0]->disk->time, */ + /* disk->ldsk->next[0]->prev->coord->id); */ + /* PhyML_Printf("\n. n_ldsk_a: %d",disk->n_ldsk_a); */ + + if(disk->n_ldsk_a == 0 || disk->n_ldsk_a > tree->n_otu) + { + PhyML_Fprintf(stderr,"\n. disk: %s (%p,%d) time: %f next: %s (%f,%d,%c,%d) prev: %s (%f,%d) disk->n_ldsk_a: %d coord: %s n_otu: %d", + disk->id, + disk, + disk->age_fixed, + disk->time, + disk->next ? disk->next->id : "??", + disk->next ? disk->next->time : 0.0, + disk->next ? disk->next->n_ldsk_a : -1, + disk->next->ldsk ? 'y' : 'n', + disk->next->ldsk ? disk->next->ldsk->n_next : -1, + disk->prev ? disk->prev->id : "??", + disk->prev ? disk->prev->time : 0.0, + disk->prev ? disk->prev->n_ldsk_a : -1, + disk->n_ldsk_a, + disk->ldsk?disk->ldsk->coord->id:"??", + tree->n_otu); + assert(FALSE); + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Connect all the ldsk between y_ldsk (young ldsk) and o_ldsk (old ldsk). + The disk between y_ldsk and o_ldsk should have all been set already + Note: the disks in **disk are sorted in ascending order of their + times +*/ + +void PHYREX_Connect_Ldsk_Given_Disk(t_dsk **disk, int n_disk, t_ldsk *y_ldsk, t_ldsk *o_ldsk, int dir_o_y) +{ + int i,j; + t_dsk *disk_tmp; + + /* Sort these events by ascending order of their times */ + for(i=0;itime > disk[i]->time) + { + disk_tmp = disk[i]; + disk[i] = disk[j]; + disk[j] = disk_tmp; + } + } + } + + + for(i=0;ildsk->next[0] = y_ldsk; + y_ldsk->prev = disk[i]->ldsk; + /* printf("\n. connect %s to %s",disk[i]->ldsk->coord->id,y_ldsk->coord->id); fflush(NULL); */ + } + else + { + disk[i]->ldsk->next[0] = disk[i-1]->ldsk; + disk[i-1]->ldsk->prev = disk[i]->ldsk; + /* printf("\n. connect %s to %s",disk[i]->ldsk->coord->id,disk[i-1]->ldsk->coord->id); fflush(NULL); */ + } + } + + /* printf("\n. connect %s next dir: %d [%d] to %s",o_ldsk->coord->id,dir_o_y,o_ldsk->n_next,disk[n_disk-1]->ldsk->coord->id); fflush(NULL); */ + o_ldsk->next[dir_o_y] = disk[n_disk-1]->ldsk; + disk[n_disk-1]->ldsk->prev = o_ldsk; + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Print_Struct(char sign, t_tree *tree) +{ + t_dsk *disk; + int i; + t_ldsk *ldisk; + + PHYREX_Update_Lindisk_List(tree); + + disk = tree->young_disk; + /* while(disk->prev) disk = disk->prev; */ + do + { + PhyML_Printf("\n%c Disk: %s @ %7.3f has %3s on it is_coal? %2d rad: %f age fixed? %d #out: %d", + sign, + disk->id, + disk->time,disk->ldsk?disk->ldsk->coord->id:NULL, + disk->ldsk?disk->ldsk->n_next:-1, + tree->mmod->rad, + disk->age_fixed, + PHYREX_Number_Of_Outgoing_Ldsks(disk)); + /* for(j=0;jmmod->n_dim;j++) PhyML_Printf(" %f",disk->centr->lonlat[j]); */ + /* fflush(NULL); */ + + + for(i=0;in_ldsk_a;i++) + { + ldisk = disk->ldsk_a[i]; + + PhyML_Printf("\n%c ldisk: %s%c prev: %s", + sign, + ldisk->coord->id, + (ldisk->nd && ldisk->nd->tax == YES && ldisk->disk == disk) ? '*' : ' ', + ldisk->prev ? ldisk->prev->coord->id : NULL); + fflush(NULL); + + /* for(j=0;jmmod->n_dim;j++) */ + /* { */ + /* PhyML_Printf(" %f",ldisk->coord->lonlat[j]); */ + /* fflush(NULL); */ + + /* if(FABS(ldisk->coord->lonlat[j] - ldisk->disk->centr->lonlat[j]) > 2.*tree->mmod->rad && */ + /* ldisk->disk->ldsk == ldisk) PhyML_Printf(" ! "); */ + + /* if(ldisk->prev) */ + /* { */ + /* if(ldisk->coord->lonlat[j] < ldisk->prev->disk->centr->lonlat[j] - tree->mmod->rad) PhyML_Printf(" #a "); */ + /* if(ldisk->coord->lonlat[j] > ldisk->prev->disk->centr->lonlat[j] + tree->mmod->rad) PhyML_Printf(" #b "); */ + /* } */ + + /* if(ldisk->next) */ + /* { */ + /* if(ldisk->coord->lonlat[j] < ldisk->disk->centr->lonlat[j] - tree->mmod->rad) PhyML_Printf(" $a "); */ + /* if(ldisk->coord->lonlat[j] > ldisk->disk->centr->lonlat[j] + tree->mmod->rad) PhyML_Printf(" $b "); */ + /* } */ + } + + + disk = disk->prev; + } + while(disk); + PhyML_Printf("\n. End of struct"); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int PHYREX_Check_Struct(t_tree *tree) +{ + int i; + t_ldsk *ldisk; + /* t_dsk *disk; */ + + // Check times + for(i=0;in_otu;++i) + { + ldisk = tree->a_nodes[i]->ldsk; + assert(ldisk); + do + { + if(ldisk->prev->disk->time > ldisk->disk->time) + { + PhyML_Printf("\n. ldisk->id: %s ldisk->prev->id: %s ldsk->disk->time: %f ldsk->prev->disk->time: %f diff: %g ldisk->prev->disk: %s ldisk->disk: %s", + ldisk->coord->id, + ldisk->prev->coord->id, + ldisk->disk->time, + ldisk->prev->disk->time, + ldisk->prev->disk->time-ldisk->disk->time, + ldisk->prev->disk->id, + ldisk->disk->id); + assert(FALSE); + return 0; + } + ldisk = ldisk->prev; + } + while(ldisk->prev); + } + + + /* disk = tree->young_disk; */ + /* do */ + /* { */ + /* for(int i=0;immod->n_dim;++i) */ + /* if(disk->centr->lonlat[i] > tree->mmod->lim_up->lonlat[i] || */ + /* disk->centr->lonlat[i] < tree->mmod->lim_do->lonlat[i]) */ + /* { */ + /* PhyML_Printf("\n. center: %f lim.inf: %f lim.up: %f", */ + /* disk->centr->lonlat[i], */ + /* tree->mmod->lim_do->lonlat[i], */ + /* tree->mmod->lim_up->lonlat[i]); */ + /* return(0); */ + /* } */ + /* disk = disk->prev; */ + /* } */ + /* while(disk); */ + + + return 1; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Store_Geo_Coord(t_geo_coord *t) +{ + int i; + + for(i=0;idim;i++) t->cpy->lonlat[i] = t->lonlat[i]; + t->cpy->dim = t->dim; + strcpy(t->cpy->id,t->id); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + + +void PHYREX_Restore_Geo_Coord(t_geo_coord *t) +{ + int i; + + for(i=0;idim;i++) t->lonlat[i] = t->cpy->lonlat[i]; + t->dim = t->cpy->dim; + strcpy(t->id,t->cpy->id); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int PHYREX_Total_Number_Of_Intervals(t_tree *tree) +{ + t_dsk *disk; + int n_intervals; + + assert(!(tree->young_disk->next)); + + disk = tree->young_disk; + n_intervals = 0; + while(disk->prev) + { + n_intervals++; + disk = disk->prev; + } + return(n_intervals); + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int PHYREX_Number_Of_Intervals_Range(t_dsk *young, t_dsk *old, t_tree *tree) +{ + t_dsk *disk; + int n_intervals; + + disk = young; + n_intervals = 0; + do + { + n_intervals++; + disk = disk->prev; + assert(disk); + } + while(disk != old); + + return(n_intervals); +} + + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int PHYREX_Total_Number_Of_Hit_Disks(t_tree *tree) +{ + t_dsk *disk; + int n_hit_disks; + + assert(!(tree->young_disk->next)); + + disk = tree->young_disk; + n_hit_disks = 0; + while(disk) + { + if(disk->ldsk) n_hit_disks++; + disk = disk->prev; + } + return(n_hit_disks); + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int PHYREX_Total_Number_Of_Coal_Disks(t_tree *tree) +{ + t_dsk *disk; + int n_coal_disks; + + assert(!(tree->young_disk->next)); + + disk = tree->young_disk; + n_coal_disks = 0; + while(disk) + { + if(disk->ldsk && disk->ldsk->n_next > 1) n_coal_disks++; + disk = disk->prev; + } + + return(n_coal_disks); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Log_Dunif_Rectangle_Overlap(t_ldsk *ldsk, t_dsk *disk, t_phyrex_mod *mmod) +{ + phydbl up, down, left, rght; + phydbl log_dens; + /* phydbl main_mass,l; */ + + log_dens = 0.0; + /* main_mass = 1. - mmod->soft_bound_area; */ + + up = MIN(disk->centr->lonlat[0] + mmod->rad, mmod->lim_up->lonlat[0]); + down = MAX(disk->centr->lonlat[0] - mmod->rad, mmod->lim_do->lonlat[0]); + rght = MIN(disk->centr->lonlat[1] + mmod->rad, mmod->lim_up->lonlat[1]); + left = MAX(disk->centr->lonlat[1] - mmod->rad, mmod->lim_do->lonlat[1]); + + + /* l = main_mass / (.5*(1.-main_mass)*(up - down)); */ + /* if(ldsk->coord->lonlat[0] < down) log_dens += log(.5*(1.-main_mass)) + log(l) - l*(down - ldsk->coord->lonlat[0]); */ + /* else if(ldsk->coord->lonlat[0] > up) log_dens += log(.5*(1.-main_mass)) + log(l) - l*(ldsk->coord->lonlat[0] - up); */ + /* else log_dens += log(main_mass) - log(up - down); */ + + /* l = main_mass / (.5*(1.-main_mass)*(rght - left)); */ + /* if(ldsk->coord->lonlat[1] < left) log_dens += log(.5*(1.-main_mass)) + log(l) - l*(left - ldsk->coord->lonlat[1]); */ + /* else if(ldsk->coord->lonlat[1] > rght) log_dens += log(.5*(1.-main_mass)) + log(l) - l*(ldsk->coord->lonlat[1] - rght); */ + /* else log_dens += log(main_mass) - log(rght - left); */ + + + if(ldsk->coord->lonlat[0] < down) return UNLIKELY; + if(ldsk->coord->lonlat[0] > up) return UNLIKELY; + if(ldsk->coord->lonlat[1] < left) return UNLIKELY; + if(ldsk->coord->lonlat[1] > rght) return UNLIKELY; + + log_dens = -log(up-down)-log(rght-left); + + return(log_dens); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Samples uniformly within a rectangle (with truncation for border) */ +/* and returns the corresponding log density */ +phydbl PHYREX_Runif_Rectangle_Overlap(t_ldsk *ldsk, t_dsk *disk, t_phyrex_mod *mmod) +{ + phydbl up, down, left, rght; + + up = MIN(disk->centr->lonlat[0] + mmod->rad, mmod->lim_up->lonlat[0]); + down = MAX(disk->centr->lonlat[0] - mmod->rad, mmod->lim_do->lonlat[0]); + rght = MIN(disk->centr->lonlat[1] + mmod->rad, mmod->lim_up->lonlat[1]); + left = MAX(disk->centr->lonlat[1] - mmod->rad, mmod->lim_do->lonlat[1]); + + ldsk->coord->lonlat[0] = Uni()*(up - down) + down; + ldsk->coord->lonlat[1] = Uni()*(rght - left) + left; + + /* printf("\n. disk %s (%f %f) rad: %f up: %f down: %f rght: %f left: %f", */ + /* disk->id, */ + /* disk->centr->lonlat[0], */ + /* disk->centr->lonlat[1], */ + /* mmod->rad, */ + /* up,down,rght,left); */ + return(log(up-down)+log(rght-left)); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Rnorm_Trunc(t_ldsk *ldsk, t_dsk *disk, t_phyrex_mod *mmod) +{ + int i,err; + + err = NO; + for(i=0;in_dim;++i) + { + ldsk->coord->lonlat[i] = Rnorm_Trunc(disk->centr->lonlat[i],mmod->rad,mmod->lim_do->lonlat[i],mmod->lim_up->lonlat[i],&err); + assert(err != YES); + } + + + return(0.0); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Wrap_Prior_Radius(t_edge *e, t_tree *tree, supert_tree *st) +{ + return PHYREX_LnPrior_Radius(tree); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_LnPrior_Lbda(t_tree *tree) +{ + if(tree->mmod->lbda < tree->mmod->min_lbda) return UNLIKELY; + if(tree->mmod->lbda > tree->mmod->max_lbda) return UNLIKELY; + + /* tree->mmod->c_ln_prior_lbda = */ + /* log(tree->mmod->prior_param_lbda) - */ + /* tree->mmod->prior_param_lbda*tree->mmod->lbda; */ + + /* tree->mmod->c_ln_prior_lbda -= log(exp(-tree->mmod->prior_param_lbda*tree->mmod->min_lbda)- */ + /* exp(-tree->mmod->prior_param_lbda*tree->mmod->max_lbda)); */ + + tree->mmod->c_ln_prior_lbda = -log(tree->mmod->max_lbda - tree->mmod->min_lbda);; + + return(tree->mmod->c_ln_prior_lbda); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_LnPrior_Mu(t_tree *tree) +{ + if(tree->mmod->mu < tree->mmod->min_mu) return UNLIKELY; + if(tree->mmod->mu > tree->mmod->max_mu) return UNLIKELY; + + tree->mmod->c_ln_prior_mu = -log(tree->mmod->max_mu - tree->mmod->min_mu); + + /* tree->mmod->c_ln_prior_mu = -2.*log(tree->mmod->mu); */ + + return(tree->mmod->c_ln_prior_mu); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_LnPrior_Radius(t_tree *tree) +{ + if(tree->mmod->rad < tree->mmod->min_rad) return UNLIKELY; + if(tree->mmod->rad > tree->mmod->max_rad) return UNLIKELY; + + tree->mmod->c_ln_prior_rad = + log(tree->mmod->prior_param_rad) - + tree->mmod->prior_param_rad*tree->mmod->rad; + + tree->mmod->c_ln_prior_rad -= log(exp(-tree->mmod->prior_param_rad*tree->mmod->min_rad)- + exp(-tree->mmod->prior_param_rad*tree->mmod->max_rad)); + + return(tree->mmod->c_ln_prior_rad); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_LnPrior_Sigsq(t_tree *tree) +{ + tree->mmod->c_ln_prior_sigsq = + log(tree->mmod->prior_param_sigsq) - + tree->mmod->prior_param_sigsq*tree->mmod->sigsq; + return(tree->mmod->c_ln_prior_sigsq); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Initial_Ldsk_Pos(t_tree *tree) +{ + t_dsk *disk; + int i,j; + phydbl mean; + + disk = tree->young_disk->prev; + + do + { + if(disk->ldsk) + { + for(i=0;immod->n_dim;i++) + { + mean = 0.0; + for(j=0;jldsk->n_next;j++) mean += disk->ldsk->next[j]->coord->lonlat[i]; + disk->ldsk->coord->lonlat[i] = mean / (phydbl)disk->ldsk->n_next; + } + } + disk = disk->prev; + } + while(disk); + + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Min_Radius(t_tree *tree) +{ + phydbl ori_rad, min_rad; + + ori_rad = tree->mmod->rad; + tree->mmod->rad = tree->mmod->max_rad; + do + { + PHYREX_Lk(tree); + tree->mmod->rad -= 1.0; + } + while(tree->mmod->c_lnL > UNLIKELY + 0.1); + + min_rad = tree->mmod->rad + 2.0; + tree->mmod->rad = ori_rad; + PHYREX_Lk(tree); + return(min_rad); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Get the minimum and maximum values a ldsk can take, given the position of the disk centre */ +void PHYREX_Get_Min_Max_Ldsk_Given_Disk(t_ldsk *ldsk, phydbl **min, phydbl **max, t_tree *tree) +{ + phydbl *loc_min,*loc_max; + int i; + + if(!ldsk->disk->next) return; + + loc_min = (phydbl *)mCalloc(tree->mmod->n_dim, sizeof(phydbl)); + loc_max = (phydbl *)mCalloc(tree->mmod->n_dim, sizeof(phydbl)); + + for(i=0;immod->n_dim;i++) + { + loc_min[i] = ldsk->disk->centr->lonlat[i] - tree->mmod->rad; + loc_max[i] = ldsk->disk->centr->lonlat[i] + tree->mmod->rad; + + if(ldsk->prev) + { + loc_min[i] = MAX(loc_min[i],ldsk->prev->disk->centr->lonlat[i] - tree->mmod->rad); + loc_max[i] = MIN(loc_max[i],ldsk->prev->disk->centr->lonlat[i] + tree->mmod->rad); + } + + loc_min[i] = MAX(tree->mmod->lim_do->lonlat[i],loc_min[i]); + loc_max[i] = MIN(tree->mmod->lim_up->lonlat[i],loc_max[i]); + } + + (*min) = loc_min; + (*max) = loc_max; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Get the minimum and maximum values a disk centre can take, given the position of the ldsk */ +void PHYREX_Get_Min_Max_Disk_Given_Ldsk(t_dsk *disk, phydbl **min, phydbl **max, t_tree *tree) +{ + phydbl *loc_min,*loc_max; + int i,j; + phydbl tmp_min, tmp_max; + + if(!disk->next) return; + + loc_min = (phydbl *)mCalloc(tree->mmod->n_dim,sizeof(phydbl)); + loc_max = (phydbl *)mCalloc(tree->mmod->n_dim,sizeof(phydbl)); + + if(!disk->ldsk || tree->mmod->name == PHYREX_NORMAL) + { + for(i=0;immod->n_dim;i++) + { + loc_min[i] = tree->mmod->lim_do->lonlat[i]; + loc_max[i] = tree->mmod->lim_up->lonlat[i]; + } + } + else + { + for(i=0;immod->n_dim;i++) + { + tmp_min = +INFINITY; + tmp_max = -INFINITY; + for(j=0;jldsk->n_next;j++) + { + if(disk->ldsk->next[j]->coord->lonlat[i] < tmp_min) tmp_min = disk->ldsk->next[j]->coord->lonlat[i]; + if(disk->ldsk->next[j]->coord->lonlat[i] > tmp_max) tmp_max = disk->ldsk->next[j]->coord->lonlat[i]; + } + + if(disk->ldsk->coord->lonlat[i] < tmp_min) tmp_min = disk->ldsk->coord->lonlat[i]; + if(disk->ldsk->coord->lonlat[i] > tmp_max) tmp_max = disk->ldsk->coord->lonlat[i]; + + loc_min[i] = MAX(tree->mmod->lim_do->lonlat[i], + tmp_max - tree->mmod->rad); + + loc_max[i] = MIN(tree->mmod->lim_up->lonlat[i], + tmp_min + tree->mmod->rad); + + assert(!(loc_max[i] < loc_min[i])); + } + } + + (*min) = loc_min; + (*max) = loc_max; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Update_Disk_Ldsk_Subtree(t_ldsk *root_ldsk, t_tree *tree) +{ + int i; + for(i=0;in_next;i++) PHYREX_Update_Disk_Ldsk_Subtree_Pre(root_ldsk,root_ldsk->next[i],root_ldsk,tree); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Update_Disk_Ldsk_Subtree_Pre(t_ldsk *old_ldsk, t_ldsk *young_ldsk, t_ldsk *root_ldsk, t_tree *tree) +{ + if(!young_ldsk->disk->next) + { + PHYREX_One_New_Traj_Given_Disk(young_ldsk,root_ldsk,tree); + return; + } + else + { + int i; + PHYREX_Update_Disk_Ldsk_Subtree_Pre(young_ldsk,young_ldsk->next[0],root_ldsk,tree); + if(young_ldsk->n_next > 1) + { + for(i=1;in_next;i++) PHYREX_Update_Disk_Ldsk_Subtree_Pre(young_ldsk,young_ldsk->next[i],young_ldsk,tree); + } + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Restore_Disk_Ldsk_Subtree(t_ldsk *root_ldsk, t_tree *tree) +{ + int i; + for(i=0;in_next;i++) PHYREX_Restore_Disk_Ldsk_Subtree_Pre(root_ldsk,root_ldsk->next[i],tree); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Restore_Disk_Ldsk_Subtree_Pre(t_ldsk *old_ldsk, t_ldsk *young_ldsk, t_tree *tree) +{ + + if(!young_ldsk->disk->next) return; + else + { + int i; + + PHYREX_Restore_Geo_Coord(young_ldsk->coord); + PHYREX_Restore_Geo_Coord(young_ldsk->disk->centr); + + for(i=0;in_next;i++) + { + PHYREX_Restore_Disk_Ldsk_Subtree_Pre(young_ldsk,young_ldsk->next[i],tree); + } + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Proposal_Disk_Ldsk_Subtree(t_ldsk *root_ldsk, phydbl *logdens, t_tree *tree) +{ + int i; + (*logdens) = 0.0; + for(i=0;in_next;i++) PHYREX_Proposal_Disk_Ldsk_Subtree_Pre(root_ldsk,root_ldsk->next[i],root_ldsk,logdens,tree); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Proposal_Disk_Ldsk_Subtree_Pre(t_ldsk *old_ldsk, t_ldsk *young_ldsk, t_ldsk *root_ldsk, phydbl *logdens, t_tree *tree) +{ + + if(!young_ldsk->disk->next) + { + (*logdens) += PHYREX_Uniform_Path_Density(young_ldsk,root_ldsk,tree); + return; + } + else + { + int i; + for(i=0;in_next;i++) + { + PHYREX_Proposal_Disk_Ldsk_Subtree_Pre(young_ldsk,young_ldsk->next[i],root_ldsk,logdens,tree); + } + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Update the tree structure given the whole set of ldsk events */ +/* Coalescent events involving multiple lineages are resolved using */ +/* very short internal edges. Tip nodes in the tree are always connected */ +/* to the corresponding ldsks. */ +void PHYREX_Ldsk_To_Tree(t_tree *tree) +{ + int i,j; + t_dsk *disk; + t_ldsk *root_ldsk; + + /* Reset */ + for(i=0;i<2*tree->n_otu-1;++i) + { + for(j=0;j<3;++j) + { + tree->a_nodes[i]->v[j] = NULL; + tree->a_nodes[i]->b[j] = NULL; + } + } + + // Erase all connections to internal nodes + disk = tree->young_disk; + do + { + if(disk->ldsk) + { + disk->ldsk->nd = NULL; + assert(disk->age_fixed == NO); + } + disk = disk->prev; + } + while(disk->prev); + + + // Make sure oldest disk has a ldsk on it + assert(disk->ldsk); + root_ldsk = disk->ldsk; + + if(tree->n_root == NULL) tree->n_root = tree->a_nodes[2*tree->n_otu-2]; + assert(tree->n_root); + + i = 2*tree->n_otu-3; + tree->num_curr_branch_available = 0; + PHYREX_Ldsk_To_Tree_Post(tree->n_root,root_ldsk,&i,tree); + + + for(i=0;in_otu;++i) assert(tree->a_nodes[i]->v[0]); + + for(i=0;i<3;++i) + if(tree->n_root->v[2]->v[i] == tree->n_root) + { + tree->n_root->v[2]->v[i] = tree->n_root->v[1]; + break; + } + + for(i=0;i<3;++i) + if(tree->n_root->v[1]->v[i] == tree->n_root) + { + tree->n_root->v[1]->v[i] = tree->n_root->v[2]; + break; + } + + Connect_Edges_To_Nodes_Serial(tree); + + + tree->e_root = NULL; + for(i=0;i<2*tree->n_otu-3;++i) + { + if((tree->a_edges[i]->left == tree->n_root->v[1] && tree->a_edges[i]->rght == tree->n_root->v[2]) || + (tree->a_edges[i]->left == tree->n_root->v[2] && tree->a_edges[i]->rght == tree->n_root->v[1])) + { + tree->e_root = tree->a_edges[i]; + break; + } + } + assert(!(tree->e_root == NULL)); + + tree->n_root->b[1] = tree->a_edges[2*tree->n_otu-3]; + tree->n_root->b[2] = tree->a_edges[2*tree->n_otu-2]; + + tree->n_root->b[1]->left = tree->n_root; + tree->n_root->b[1]->rght = tree->n_root->v[1]; + + tree->n_root->b[2]->left = tree->n_root; + tree->n_root->b[2]->rght = tree->n_root->v[2]; + + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + + MIXT_Propagate_Tree_Update(tree); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Ldsk_To_Tree_Post(t_node *a, t_ldsk *ldsk, int *available, t_tree *tree) +{ + assert(ldsk); + assert(a); + + ldsk->nd = a; + tree->rates->nd_t[a->num] = ldsk->disk->time; + + if(!ldsk->next) return; // Tip node + else + { + t_node *parent,*son; + int idx_next; + t_ldsk *t; + + parent = a; + parent->v[1] = NULL; + parent->v[2] = NULL; + idx_next = 0; + do + { + t = ldsk->next[idx_next]; + + // Descend along that lineage as long as + // one has not reached a tip (t->next == NULL) + // or a coalescent event (t->n_next > 1) + while(t->next && t->n_next <= 1) t = t->next[0]; + + + if(t->nd == NULL) // t->disk is not a sampled disk + { + assert(t->disk->age_fixed == NO); + son = tree->a_nodes[*available]; + (*available) = (*available)-1; + } + else + { + assert(t->disk->age_fixed == YES); + son = t->nd; + } + + PHYREX_Ldsk_To_Tree_Post(son,t,available,tree); + + // Resolve multifurcation + if(parent->v[2] != NULL && idx_next >= 2) + { + t_node *new_parent; + + new_parent = tree->a_nodes[*available]; + (*available) = (*available)-1; + + new_parent->v[0] = parent; + new_parent->v[1] = parent->v[2]; + new_parent->v[2] = son; + + parent->v[2] = new_parent; + son->v[0] = new_parent; + new_parent->v[1]->v[0] = new_parent; + + /* PhyML_Printf("\n[] connect %d to %d",parent->num,new_parent->num); */ + /* PhyML_Printf("\n[] connect %d to %d",new_parent->num,new_parent->v[1]->num); */ + /* PhyML_Printf("\n[] connect %d to %d",new_parent->num,new_parent->v[2]->num); */ + + tree->rates->nd_t[new_parent->num] = ldsk->disk->time; + + parent = new_parent; + } + else + { + son->v[0] = parent; + if(!parent->v[1]) parent->v[1] = son; + else parent->v[2] = son; + + /* printf("\n[] connect %d to %d",parent->num,son->num); */ + } + + idx_next++; + } + while(idx_next != ldsk->n_next); + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// Make sure PHYREX_Make_And_Connect_Tip_Disks was called beforehand +void PHYREX_Tree_To_Ldsk(t_tree *tree) +{ + t_dsk *a_disk,*disk; + t_node *n; + + assert(tree->n_root); + assert(tree->young_disk); + + // Initialise root disk + a_disk = PHYREX_Make_Disk_Event(tree->mmod->n_dim,tree->n_otu); + PHYREX_Init_Disk_Event(a_disk,tree->mmod->n_dim,NULL); + + a_disk->prev = NULL; // last (i.e., oldest) disk + + a_disk->ldsk = PHYREX_Make_Lindisk_Node(tree->mmod->n_dim); + PHYREX_Init_Lindisk_Node(a_disk->ldsk,a_disk,tree->mmod->n_dim); + + tree->n_root->ldsk = a_disk->ldsk; + a_disk->ldsk->nd = tree->n_root; + + // Initialize centre of event on the root disk + a_disk->centr->lonlat[0] = Uni()*(tree->mmod->lim_up->lonlat[0]-tree->mmod->lim_do->lonlat[0])+tree->mmod->lim_do->lonlat[0]; + a_disk->centr->lonlat[1] = Uni()*(tree->mmod->lim_up->lonlat[1]-tree->mmod->lim_do->lonlat[1])+tree->mmod->lim_do->lonlat[1]; + + /* Its location */ + switch(tree->mmod->name) + { + case PHYREX_UNIFORM: + { + PHYREX_Runif_Rectangle_Overlap(a_disk->ldsk,a_disk,tree->mmod); + break; + } + case PHYREX_NORMAL: + { + PHYREX_Rnorm_Trunc(a_disk->ldsk,a_disk,tree->mmod); + break; + } + } + + a_disk->ldsk->nd = tree->n_root; + a_disk->time = tree->rates->nd_t[tree->n_root->num]; + + + /* Inflate_Times_To_Get_Reasonnable_Edge_Lengths(1.E-3,tree); */ + Get_Node_Ranks_From_Times(tree); + + PHYREX_Tree_To_Ldsk_Post(tree->n_root,tree->n_root->v[1],a_disk,tree); + PHYREX_Tree_To_Ldsk_Post(tree->n_root,tree->n_root->v[2],a_disk,tree); + + // Create a doubly-chained list of disks + disk = a_disk; + disk->time = tree->rates->nd_t[tree->n_root->num]; + n = tree->n_root; + while(n->rk_next) + { + // Only jump to next disk if n and n->rk_next are on distinct disks + // If n->ldsk == n->rk_next->ldsk then n->ldsk->disk and n->rk_next->ldsk->disk + // are the same disk (multiple merger) + if((n->ldsk->disk != n->rk_next->ldsk->disk) && (n->ldsk != n->rk_next->ldsk)) + { + disk->next = n->rk_next->ldsk->disk; + disk->next->prev = disk; + disk->next->time = tree->rates->nd_t[n->rk_next->num]; + disk = disk->next; + } + + n = n->rk_next; + } + + + // Fill in ldsk_a arrays throughout the tree + PHYREX_Update_Lindisk_List(tree); + + assert(tree->young_disk->prev); + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Tree_To_Ldsk_Post(t_node *a, t_node *d, t_dsk *a_disk, t_tree *tree) +{ + int i; + + assert(a); + assert(d); + assert(a_disk); + + + if(d->tax) + { + assert(d->ldsk); + PHYREX_Make_Lindisk_Next(a_disk->ldsk); + d->ldsk->prev = a_disk->ldsk; + a_disk->ldsk->next[a_disk->ldsk->n_next-1] = d->ldsk; + a_disk->ldsk->next[a_disk->ldsk->n_next-1]->nd = d; + return; + } + else + { + if(tree->rates->nd_t[d->num] > tree->rates->nd_t[a->num]) + { + t_dsk *d_disk; + + PHYREX_Make_Lindisk_Next(a_disk->ldsk); + + // Make and initialize descendent disk + d_disk = PHYREX_Make_Disk_Event(tree->mmod->n_dim,tree->n_otu); + assert(d_disk); + PHYREX_Init_Disk_Event(d_disk,tree->mmod->n_dim,NULL); + + d_disk->time = tree->rates->nd_t[d->num]; + + d_disk->ldsk = PHYREX_Make_Lindisk_Node(tree->mmod->n_dim); + PHYREX_Init_Lindisk_Node(d_disk->ldsk,d_disk,tree->mmod->n_dim); + + // Initialize centre of event on the root disk + d_disk->centr->lonlat[0] = Uni()*(tree->mmod->lim_up->lonlat[0]-tree->mmod->lim_do->lonlat[0])+tree->mmod->lim_do->lonlat[0]; + d_disk->centr->lonlat[1] = Uni()*(tree->mmod->lim_up->lonlat[1]-tree->mmod->lim_do->lonlat[1])+tree->mmod->lim_do->lonlat[1]; + + /* Its location */ + switch(tree->mmod->name) + { + case PHYREX_UNIFORM: + { + PHYREX_Runif_Rectangle_Overlap(d_disk->ldsk,d_disk,tree->mmod); + break; + } + case PHYREX_NORMAL: + { + PHYREX_Rnorm_Trunc(d_disk->ldsk,d_disk,tree->mmod); + break; + } + } + + d_disk->ldsk->nd = d; + d->ldsk = d_disk->ldsk; + + a_disk->ldsk->next[a_disk->ldsk->n_next-1] = d_disk->ldsk; + d_disk->ldsk->prev = a_disk->ldsk; + + for(i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + PHYREX_Tree_To_Ldsk_Post(d,d->v[i],d_disk,tree); + } + } + + } + else // time[d] == time[a] -> add lineage to a_disk instead of creating d_disk + { + d->ldsk = a_disk->ldsk; + + for(i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + PHYREX_Tree_To_Ldsk_Post(d,d->v[i],a_disk,tree); + } + } + } + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Simulate_Disk_And_Node_Times(t_tree *tree) +{ + t_dsk *disk; + + disk = tree->young_disk; + assert(disk->age_fixed == YES); // age of youngest disk should be fixed + + do + { + // disk->prev is not a sample --> simulate its age by sampling in exp distribution + if(disk->prev->age_fixed == NO) + { + disk->prev->time = disk->time - Rexp(tree->mmod->lbda); + + // set time of internal node sitting on disk->prev + if(disk->prev->ldsk != NULL) + tree->rates->nd_t[disk->prev->ldsk->nd->num] = + disk->prev->time; + } + PhyML_Printf("\n. Simulate times disk %s time: %f",disk->id,disk->time); + disk = disk->prev; + } + while(disk->prev); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// Connections between tip nodes and corresponding ldsks (plus the +// associated disks) should be made early on and never modified +// after that. +void PHYREX_Make_And_Connect_Tip_Disks(t_tree *tree) +{ + t_dsk *disk,*new_disk; + t_node *n; + + Get_Node_Ranks_From_Tip_Times(tree); + + // Find most recent tip + n = tree->a_nodes[0]; + while(n->rk_next) n = n->rk_next; + + // Create most recent disk + disk = PHYREX_Make_Disk_Event(tree->mmod->n_dim,tree->n_otu); + PHYREX_Init_Disk_Event(disk,tree->mmod->n_dim,NULL); + disk->age_fixed = YES; // Sample disks have their ages fixed + disk->time = tree->rates->nd_t[n->num]; // Set time of youngest disk + PhyML_Fprintf(stdout,"\n. Youngest sampled disk time set to %f (disk id: %s)",disk->time,disk->id); + + // ldsk_a[0] is connected to youngest tip + disk->ldsk_a[0] = PHYREX_Make_Lindisk_Node(tree->mmod->n_dim); + PHYREX_Init_Lindisk_Node(disk->ldsk_a[0],disk,tree->mmod->n_dim); + disk->n_ldsk_a = 1; + disk->ldsk_a[0]->nd = n; + n->ldsk = disk->ldsk_a[0]; + n->ldsk->disk = disk; + + + // Set pointer to young_disk here and not elsewhere! + tree->young_disk = disk; + new_disk = NULL; + do + { + assert(n->rk_prev); + + // n and n->rk_prev have distinct time stamps -> they should be on two distinct disks + if(Are_Equal(tree->rates->nd_t[n->num],tree->rates->nd_t[n->rk_prev->num],SMALL) == NO) + { + new_disk = PHYREX_Make_Disk_Event(tree->mmod->n_dim,tree->n_otu); + PHYREX_Init_Disk_Event(new_disk,tree->mmod->n_dim,NULL); + new_disk->age_fixed = YES; + + new_disk->ldsk_a[0] = PHYREX_Make_Lindisk_Node(tree->mmod->n_dim); + PHYREX_Init_Lindisk_Node(new_disk->ldsk_a[0],new_disk,tree->mmod->n_dim); + new_disk->ldsk_a[0]->nd = n->rk_prev; + new_disk->ldsk_a[0]->disk = new_disk; + new_disk->n_ldsk_a = 1; + + new_disk->next = disk; + disk->prev = new_disk; + + disk = new_disk; + } + // n and n->rk_prev have the same time stamp -> they sit on the same disk + else + { + disk->ldsk_a[disk->n_ldsk_a] = PHYREX_Make_Lindisk_Node(tree->mmod->n_dim); + PHYREX_Init_Lindisk_Node(disk->ldsk_a[disk->n_ldsk_a],disk,tree->mmod->n_dim); + disk->ldsk_a[disk->n_ldsk_a]->nd = n->rk_prev; + disk->ldsk_a[disk->n_ldsk_a]->disk = disk; + disk->n_ldsk_a++; + } + + // Set sampled disk time + disk->time = tree->rates->nd_t[n->rk_prev->num]; + PhyML_Fprintf(stdout,"\n. Set sampled disk (id: %s) time to %15f",disk->id,disk->time); + + n->rk_prev->ldsk = disk->ldsk_a[disk->n_ldsk_a-1]; + n = n->rk_prev; + } + while(n->rk_prev); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Remove_Lindisk_Next(t_ldsk *ldsk, t_ldsk *rm) +{ + t_ldsk **new_next; + int i,pos; + + new_next = (t_ldsk **)mCalloc(ldsk->n_next-1+NEXT_BLOCK_SIZE,sizeof(t_ldsk *)); + + pos = 0; + for(i=0;in_next;i++) + { + if(ldsk->next[i] != rm) + { + new_next[pos] = ldsk->next[i]; + pos++; + } + } + + ldsk->n_next--; + Free(ldsk->next); + ldsk->next = new_next; + /* printf("\n. remove next for ldsk %s n_next set to %d",ldsk->coord->id,ldsk->n_next); */ + /* fflush(NULL); */ +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Returns the vector of average pairwise distances between ldsk on each disk */ +phydbl *PHYREX_Mean_Pairwise_Distance_Between_Lineage_Locations(t_tree *tree) +{ + phydbl *dist; + int block,n_disks,i,j, k; + t_dsk *disk; + + PHYREX_Update_Lindisk_List(tree); + + dist = NULL; + block = 100; + disk = tree->young_disk; + n_disks = 0; + do + { + if(!n_disks) dist = (phydbl *)mCalloc(block,sizeof(phydbl)); + else if(!(n_disks%block)) dist = (phydbl *)mRealloc(dist,n_disks+block,sizeof(phydbl)); + + dist[n_disks] = 0.0; + for(i=0;in_ldsk_a-1;i++) + { + for(j=i+1;jn_ldsk_a;j++) + { + for(k=0;kmmod->n_dim;k++) + { + dist[n_disks] += FABS(disk->ldsk_a[i]->coord->lonlat[k] - disk->ldsk_a[j]->coord->lonlat[k]); + printf("\n * %d %f %f %f", + k, + disk->ldsk_a[i]->coord->lonlat[k], + disk->ldsk_a[j]->coord->lonlat[k], + tree->mmod->lim_up->lonlat[k]); + } + } + } + dist[n_disks] /= (phydbl)(disk->n_ldsk_a * (disk->n_ldsk_a-1) / 2.); + + printf("\n %d %f %f",disk->n_ldsk_a,disk->time,dist[n_disks]); + + n_disks++; + disk = disk->prev; + } + while(disk->prev); + + return(dist); + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Random_Select_Time_Between_Jumps(t_tree *tree) +{ + t_dsk *disk,**valid_disks; + int n_valid_disks,block,select; + phydbl time; + + valid_disks = NULL; + disk = NULL; + block = 100; + + assert(!(tree->young_disk->next)); + + disk = tree->young_disk->prev; + n_valid_disks = 0; + do + { + if(disk->ldsk != NULL && disk->prev != NULL) + { + if(!n_valid_disks) valid_disks = (t_dsk **)mCalloc(block,sizeof(t_dsk *)); + else if(!(n_valid_disks%block)) valid_disks = (t_dsk **)mRealloc(valid_disks,n_valid_disks+block,sizeof(t_dsk *)); + valid_disks[n_valid_disks] = disk; + n_valid_disks++; + } + disk = disk->prev; + } + while(disk->prev); + + if(!n_valid_disks) return -1.0; + + select = Rand_Int(0,n_valid_disks-1); + + time = valid_disks[select]->time - valid_disks[select]->ldsk->prev->disk->time; + + Free(valid_disks); + + return(time); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int PHYREX_Is_In_Ldscape(t_ldsk *ldsk, t_phyrex_mod *mmod) +{ + int j; + for(j=0;jn_dim;j++) + if(ldsk->coord->lonlat[j] > mmod->lim_up->lonlat[j] || + ldsk->coord->lonlat[j] < mmod->lim_do->lonlat[j]) return NO; + return YES; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Mean_Time_Between_Events(t_tree *tree) +{ + int n_inter; + phydbl T; + + n_inter = PHYREX_Total_Number_Of_Intervals(tree); + T = -tree->rates->nd_t[tree->n_root->num]; + return((phydbl)(T/n_inter)); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Uses the regression technique described in Barton et al. TPB (2013) + to estimate the size of the neighborhood when the population evolve + according to a spatial Lambda-Fleming-Viot process. +*/ +phydbl PHYREX_Neighborhood_Size_Regression(t_tree *tree) +{ + int i,j,pair; + t_node *anc; + phydbl *dist,min_dist; + phydbl QA,Qr,*fst,fst0,fst_min_dist; + phydbl cov_fst_dist,var_dist,slope; + phydbl eps; + + eps = 1.E-10; + + QA = Mean_Identity(tree->data); + + fst = (phydbl *)mCalloc(tree->n_otu*(tree->n_otu-1)/2,sizeof(phydbl)); + dist = (phydbl *)mCalloc(tree->n_otu*(tree->n_otu-1)/2,sizeof(phydbl)); + + pair = 0; + fst0 = 0.0; + for(i=0;in_otu-1;i++) + { + fst_min_dist = 0.0; + min_dist = MDBL_MAX; + for(j=i+1;jn_otu;j++) + { + anc = Find_Lca_Pair_Of_Nodes(tree->a_nodes[i],tree->a_nodes[j],tree); + if(anc == NULL) + { + PhyML_Fprintf(stderr,"\n. %s",Write_Tree(tree)); + PhyML_Fprintf(stderr,"\n. %s %s",tree->a_nodes[i]->name,tree->a_nodes[j]->name); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + dist[pair] = Euclidean_Dist(tree->a_nodes[i]->ldsk->coord,tree->a_nodes[j]->ldsk->coord); + dist[pair] = log(dist[pair]); + + Qr = Pairwise_Identity(i,j,tree->data); + fst[pair] = (Qr-QA)/(1.-QA); + + if(dist[pair] < min_dist) + { + min_dist = dist[pair]; + fst_min_dist = fst[pair]; + } + + pair++; + } + fst0 += fst_min_dist; + } + + fst0 /= (phydbl)(tree->n_otu); + + cov_fst_dist = Covariance(dist,fst,pair); + var_dist = Variance(dist,pair); + + slope = cov_fst_dist / var_dist; + + Free(dist); + Free(fst); + + return((fst0-1.+eps)/(slope+eps)); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Rand_Pairs_Coal_Times_Dist(t_tree *tree) +{ + t_node *anc; + phydbl dist; + int i, j; + + i = Rand_Int(0,tree->n_otu-1); + j = Rand_Int(0,tree->n_otu-1); + + if(i == j) PhyML_Printf("\nxxWxx 0.0 0.0"); + else + { + + anc = Find_Lca_Pair_Of_Nodes(tree->a_nodes[i],tree->a_nodes[j],tree); + if(anc == NULL) + { + PhyML_Fprintf(stderr,"\n. %s",Write_Tree(tree)); + PhyML_Fprintf(stderr,"\n. %s %s",tree->a_nodes[i]->name,tree->a_nodes[j]->name); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + PhyML_Printf("\nxxWxx %12f",tree->rates->nd_t[anc->num]); + dist = Euclidean_Dist(tree->a_nodes[i]->ldsk->coord,tree->a_nodes[j]->ldsk->coord); + PhyML_Printf(" %f",dist); + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Generation_Length(t_tree *tree) +{ + return(1./(2.*tree->mmod->mu*POW(tree->mmod->rad,2)*PI*PHYREX_Rate_Per_Unit_Area(tree))); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Neighborhood_Size(t_tree *tree) +{ + switch(tree->mmod->name) + { + case PHYREX_UNIFORM: { return(1./tree->mmod->mu); break; } + case PHYREX_NORMAL: { return(2./tree->mmod->mu); break; } + } + return(-1.); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Update_Sigsq(t_tree *tree) +{ + switch(tree->mmod->name) + { + case PHYREX_UNIFORM: { return(-1.0); break;} + case PHYREX_NORMAL: + { + return(4.*PI* + PHYREX_Rate_Per_Unit_Area(tree) * + pow(tree->mmod->rad,4)* + tree->mmod->mu); + break; + } + } + return(-1.); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Update_Radius(t_tree *tree) +{ + switch(tree->mmod->name) + { + case PHYREX_UNIFORM: { return(-1.0); break;} + case PHYREX_NORMAL: + { + return(POW(tree->mmod->sigsq/(PHYREX_Rate_Per_Unit_Area(tree)*4.*PI*tree->mmod->mu),0.25)); + break; + } + } + return(-1.); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Sample_Rad_From_Prior(t_tree *tree) +{ + phydbl u,h,w,lbda,mu,b,a; + + h = (tree->mmod->lim_up->lonlat[0]-tree->mmod->lim_do->lonlat[0]); + w = (tree->mmod->lim_up->lonlat[1]-tree->mmod->lim_do->lonlat[1]); + lbda = tree->mmod->lbda; + mu = tree->mmod->mu; + a = tree->mmod->min_sigsq; + b = tree->mmod->max_sigsq; + + u = Uni(); + + return(POW(((b-a)*u+a)*h*w/(4.*PI*lbda*mu),0.25)); + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Read_Tip_Coordinates(t_tree *tree) +{ + char *s; + FILE *fp; + int i,*done,found_sw,found_ne; + phydbl sw_lon, sw_lat, ne_lon, ne_lat; + t_node *n; + + assert(tree->young_disk); + + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + fp = tree->io->fp_in_coord; + done = (int *)mCalloc(tree->n_otu,sizeof(int)); + + found_sw = NO; + found_ne = NO; + + for(i=0;in_otu;i++) done[i] = NO; + + do + { + if(fscanf(fp,"%s",s) == EOF) break; + for(i=0;in_otu;i++) if(strstr(tree->a_nodes[i]->name,s)) break; + + if(i != tree->n_otu) /* Found a match */ + { + assert(tree->a_nodes[i]->ldsk); + // First column: latitude, second one: longitude + if(fscanf(fp,"%lf",&(tree->a_nodes[i]->ldsk->coord->lonlat[1])) == EOF) break; + if(fscanf(fp,"%lf",&(tree->a_nodes[i]->ldsk->coord->lonlat[0])) == EOF) break; + done[i] = YES; + } + else + { + if(!strcmp(s,"|SouthWest|") || !strcmp(s,"|southwest|") || !strcmp(s,"|Southwest|")) + { + found_sw = YES; + if(fscanf(fp,"%lf",&(sw_lat)) == EOF) break; + if(fscanf(fp,"%lf",&(sw_lon)) == EOF) break; + } + else if(!strcmp(s,"|NorthEast|") || !strcmp(s,"|northeast|") || !strcmp(s,"|Northeast|")) + { + found_ne = YES; + if(fscanf(fp,"%lf",&(ne_lat)) == EOF) break; + if(fscanf(fp,"%lf",&(ne_lon)) == EOF) break; + } + else /* Haven't found any match but still need to skip long and lat for unsampled location */ + { + phydbl dum; + if(fscanf(fp,"%lf",&dum) == EOF) break; + if(fscanf(fp,"%lf",&dum) == EOF) break; + } + } + } + while(1); + + if(found_ne == NO) + { + PhyML_Fprintf(stderr,"\n. Could not find coordinates for northernmost point."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + if(found_sw == NO) + { + PhyML_Fprintf(stderr,"\n. Could not find coordinates for southernmost point."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + for(i=0;in_otu;i++) + if(done[i] == NO) + { + PhyML_Fprintf(stderr,"\n. Could not find coordinates for '%s'.",tree->a_nodes[i]->name); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + n = NULL; + for(i=0;in_otu;i++) + { + n = tree->a_nodes[i]; + + PhyML_Printf("\n. Coordinates of '%-50s': %12f\t %12f", + tree->a_nodes[i]->name, + n->ldsk->coord->lonlat[0], + n->ldsk->coord->lonlat[1]); + } + + tree->mmod->lim_up->lonlat[0] = ne_lon; + tree->mmod->lim_up->lonlat[1] = ne_lat; + + tree->mmod->lim_do->lonlat[0] = sw_lon; + tree->mmod->lim_do->lonlat[1] = sw_lat; + + + Free(s); + Free(done); + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Rate_Per_Unit_Area(t_tree *tree) +{ + int i; + phydbl denom; + + denom = (tree->mmod->lim_up->lonlat[0]-tree->mmod->lim_do->lonlat[0]); + for(i=1;immod->n_dim;i++) denom *= (tree->mmod->lim_up->lonlat[i]-tree->mmod->lim_do->lonlat[i]); + + return(tree->mmod->lbda / denom); + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Tree_Height(t_tree *tree) +{ + t_dsk *disk; + + disk = tree->young_disk; + while(disk && disk->prev) disk = disk->prev; + + return(disk->time); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int PHYREX_Random_Insert_Ldsk_In_Next_List(t_ldsk *ins, t_ldsk *where) +{ + int size, pos, i, *rk; + t_ldsk **next_cpy; + + size = where->n_next; + + rk = (int *)mCalloc(size,sizeof(int)); + next_cpy = (t_ldsk **)mCalloc(size,sizeof(t_ldsk *)); + + for(i=0;inext[i]; + + pos = Rand_Int(0,size); + + for(i=0;inext[rk[i]] = next_cpy[i]; + + where->next[pos]= ins; + + + Free(rk); + Free(next_cpy); + + return pos; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Insert_Ldsk_In_Next_List(t_ldsk *ins, int pos, t_ldsk *where) +{ + int size, i, *rk; + t_ldsk **next_cpy; + + size = where->n_next; + + rk = (int *)mCalloc(size,sizeof(int)); + next_cpy = (t_ldsk **)mCalloc(size,sizeof(t_ldsk *)); + + for(i=0;inext[i]; + + for(i=0;inext[rk[i]] = next_cpy[i]; + + where->next[pos]= ins; + + Free(rk); + Free(next_cpy); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* end is older ldsk. beg is younger ldsk. Remove path between */ +/* beg ldsk and end ldsk. If beg->prev == end, then beg->prev set */ +/* to NULL and old->next[dir_to_beg] set to NULL as well. */ + +t_ldsk *PHYREX_Remove_Path(t_ldsk *young, t_ldsk *old, int *pos_old, t_tree *tree) +{ + t_ldsk *path,*ldsk; + int dir_old_young,jumps; + + path = NULL; + + dir_old_young = PHYREX_Get_Next_Direction(young,old); + assert(dir_old_young >= 0); + *pos_old = dir_old_young; + PHYREX_Remove_Lindisk_Next(old,old->next[dir_old_young]); + + + jumps = 1; + ldsk = young->prev; + while(ldsk != old) + { + if(jumps == 1) path = ldsk; + PHYREX_Remove_Disk(ldsk->disk); + ldsk = ldsk->prev; + jumps++; + } + + if(jumps == 1) + path = NULL; + else + { + /* Set end of path to NULL */ + ldsk = path; + while(ldsk->prev != old) { ldsk = ldsk->prev; assert(ldsk); } + ldsk->prev = NULL; + } + + + /* path == NULL if young->prev = old, otherwise path points to the first ldsk */ + /* after jump away from young towards the past (i.e., towards old) */ + return(path); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Insert_Path(t_ldsk *young, t_ldsk *old, t_ldsk *path, int pos, t_tree *tree) +{ + t_ldsk *ldsk; + + assert(path != young); + + if(path == NULL) + { + young->prev = old; + PHYREX_Insert_Ldsk_In_Next_List(young,pos,old); + } + else + { + /* Attach path to the young ldsk */ + path->next[0] = young; + young->prev = path; + + ldsk = path; + do + { + PHYREX_Insert_Disk(ldsk->disk,tree); + ldsk = ldsk->prev; + } + while(ldsk); + + /* Get to the end of path */ + ldsk = path; + while(ldsk->prev != NULL) { ldsk = ldsk->prev; assert(ldsk); } + + /* Attach it to old ldsk (both ways)*/ + PHYREX_Insert_Ldsk_In_Next_List(ldsk,pos,old); + ldsk->prev = old; + } + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Effective_Density(t_tree *tree) +{ + return(PHYREX_Neighborhood_Size(tree)/(4.*PI*PHYREX_Update_Sigsq(tree))); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +t_ldsk *PHYREX_Generate_Path(t_ldsk *young, t_ldsk *old, phydbl n_evt, phydbl sd, t_tree *tree) +{ + int i,j,swap,err; + phydbl *time,dum,mode; + t_ldsk *path,**ldsk_a; + t_dsk *disk; + phydbl X,Y,Xp,Yp; + phydbl slope,inter; + + path = NULL; + + if(n_evt == 0) return(NULL); // path is set to NULL + + time = (phydbl *)mCalloc(n_evt,sizeof(phydbl)); + ldsk_a = (t_ldsk **)mCalloc(n_evt,sizeof(t_ldsk *)); + + + for(i=0;idisk->time - old->disk->time) + old->disk->time; + + /* Bubble sort time in decreasing order */ + do + { + swap = NO; + for(i=0;i time[i]) + { + swap = YES; + dum = time[i+1]; + time[i+1] = time[i]; + time[i] = dum; + } + } + } + while(swap == YES); + + for(i=0;immod->n_dim); + disk = PHYREX_Make_Disk_Event(tree->mmod->n_dim,tree->n_otu); + PHYREX_Init_Lindisk_Node(ldsk_a[i],disk,tree->mmod->n_dim); + PHYREX_Make_Lindisk_Next(ldsk_a[i]); + PHYREX_Init_Disk_Event(disk,tree->mmod->n_dim,tree->mmod); + disk->ldsk = ldsk_a[i]; + disk->time = time[i]; + } + + for(i=0;iprev = ldsk_a[i+1]; + ldsk_a[i]->prev = NULL; + + for(i=1;inext[0] = ldsk_a[i-1]; + ldsk_a[0]->next[0] = NULL; + + path = ldsk_a[0]; + + /* Instantiate path */ + for(i=0;immod->n_dim;i++) + { + X = old->coord->lonlat[i]; + Y = old->disk->time; + + for(j=0;jcoord->lonlat[i]; + Yp = young->disk->time; + } + else + { + assert(ldsk_a[j]->n_next == 1); + Xp = ldsk_a[j]->next[0]->coord->lonlat[i]; + Yp = ldsk_a[j]->next[0]->disk->time; + } + + slope = (Yp-Y)/(Xp-X); + inter = Y - slope*X; + + if(j == 0) + { + mode = (young->disk->time - inter)/slope; + } + else + { + mode = (ldsk_a[j]->next[0]->disk->time - inter)/slope; + } + + ldsk_a[j]->coord->lonlat[i] = Rnorm_Trunc(mode, + sd, + tree->mmod->lim_do->lonlat[i], + tree->mmod->lim_up->lonlat[i],&err); + + + /* ldsk_a[j]->disk->centr->lonlat[i] = Rnorm_Trunc(mode, */ + /* sd, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[i],&err); */ + + + ldsk_a[j]->disk->centr->lonlat[i] = Rnorm_Trunc(ldsk_a[j]->coord->lonlat[i], + sd, + tree->mmod->lim_do->lonlat[i], + tree->mmod->lim_up->lonlat[i],&err); + } + } + + Free(ldsk_a); + Free(time); + + return(path); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Path_Logdensity(t_ldsk *young, t_ldsk *old, phydbl sd, t_tree *tree) +{ + int i,j,err; + t_ldsk *ldsk; + phydbl lnDens,mode; + phydbl X,Y,Xp,Yp; + phydbl slope,inter; + int dir_to_young; + + lnDens = 0.0; + mode = 0.0; + + for(i=0;immod->n_dim;i++) + { + + j = 0; + ldsk = young->prev; + + X = old->coord->lonlat[i]; + Y = old->disk->time; + + // Density up to the last jump (to old ldsk) which should + // not be accounted for (it is not part of the simulation + // when randomly generating a path using PHYREX_Generate_Path + while(ldsk != old) + { + + if(ldsk->n_next > 1) + dir_to_young = PHYREX_Get_Next_Direction(young,ldsk); + else + dir_to_young = 0; + + Xp = ldsk->next[dir_to_young]->coord->lonlat[i]; + Yp = ldsk->next[dir_to_young]->disk->time; + + slope = (Yp-Y)/(Xp-X); + inter = Y - slope*X; + + assert(ldsk != NULL); + + /* mode = (old->coord->lonlat[i] - young->coord->lonlat[i])/(n_evt+1.-j) + young->coord->lonlat[i]; */ + + mode = (ldsk->disk->time - inter)/slope; + + lnDens += Log_Dnorm_Trunc(ldsk->coord->lonlat[i], + mode, + sd, + tree->mmod->lim_do->lonlat[i], + tree->mmod->lim_up->lonlat[i],&err); + + /* lnDens += Log_Dnorm_Trunc(ldsk->disk->centr->lonlat[i], */ + /* mode, */ + /* sd, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[i],&err); */ + + lnDens += Log_Dnorm_Trunc(ldsk->disk->centr->lonlat[i], + ldsk->coord->lonlat[i], + sd, + tree->mmod->lim_do->lonlat[i], + tree->mmod->lim_up->lonlat[i],&err); + /* lnDens += log(1./tree->mmod->lim->lonlat[i]); */ + + ldsk = ldsk->prev; + j++; + } + } + + return(lnDens); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Sample_Path(t_ldsk *young, t_ldsk *old, phydbl sd, phydbl *global_hr, t_tree *tree) +{ + phydbl new_ldsk_pos,cur_ldsk_pos; + phydbl new_centr_pos,cur_centr_pos; + phydbl new_glnL,cur_glnL; + phydbl u,alpha,ratio,hr; + int n_mcmc_iter; + int i,err; + t_ldsk *ldsk; + int accept,reject; + int path_len; + + + path_len = PHYREX_Path_Len(young,old)-2; + if(path_len == 0) return; + + assert(young != old); + new_glnL = cur_glnL = tree->mmod->c_lnL; + + n_mcmc_iter = 0; + accept = reject = 0; + do + { + + ldsk = young->prev; + do + { + assert(ldsk->prev); + + PHYREX_Store_Geo_Coord(ldsk->coord); + PHYREX_Store_Geo_Coord(ldsk->disk->centr); + + hr = 0.0; + ratio = 0.0; + + /* cur_glnL = PHYREX_Lk_Range(young->disk,old->disk,tree); */ + cur_glnL = PHYREX_Lk_Range(ldsk->disk,ldsk->prev->disk,tree); + new_glnL = cur_glnL; + + for(i=0;immod->n_dim;i++) + { + cur_ldsk_pos = ldsk->coord->lonlat[i]; + cur_centr_pos = ldsk->disk->centr->lonlat[i]; + + /* new_centr_pos = Rnorm_Trunc(cur_centr_pos, */ + /* 0.5*sd, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[i],&err); */ + + new_centr_pos = Uni() * (tree->mmod->lim_up->lonlat[i]-tree->mmod->lim_do->lonlat[i])+tree->mmod->lim_do->lonlat[i]; + + new_ldsk_pos = Rnorm_Trunc(new_centr_pos, + sd, + tree->mmod->lim_do->lonlat[i], + tree->mmod->lim_up->lonlat[i],&err); + + + /* PhyML_Printf("\n. cur_centr: %12f new_centr: %12f",cur_centr_pos,new_centr_pos); */ + /* PhyML_Printf(" d(new|cur)=%12f d(cur|new): %12f", */ + /* Log_Dnorm_Trunc(new_centr_pos, */ + /* cur_centr_pos, */ + /* 0.5*sd, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[i],&err), */ + /* Log_Dnorm_Trunc(cur_centr_pos, */ + /* new_centr_pos, */ + /* 0.5*sd, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[i],&err)); */ + + + /* PhyML_Printf(" cur_ldsk: %12f new_ldsk: %12f",cur_ldsk_pos,new_ldsk_pos); */ + /* PhyML_Printf(" d(new|cur)=%12f d(cur|new): %12f", */ + /* Log_Dnorm_Trunc(new_ldsk_pos, */ + /* new_centr_pos, */ + /* 0.5*sd, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[i],&err), */ + /* Log_Dnorm_Trunc(cur_ldsk_pos, */ + /* cur_centr_pos, */ + /* 0.5*sd, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[i],&err)); */ + + + hr -= Log_Dnorm_Trunc(new_ldsk_pos, + new_centr_pos, + sd, + tree->mmod->lim_do->lonlat[i], + tree->mmod->lim_up->lonlat[i],&err); + + /* hr -= Log_Dnorm_Trunc(new_centr_pos, */ + /* cur_centr_pos, */ + /* 0.5*sd, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[i],&err); */ + + + hr += Log_Dnorm_Trunc(cur_ldsk_pos, + cur_centr_pos, + sd, + tree->mmod->lim_do->lonlat[i], + tree->mmod->lim_up->lonlat[i],&err); + + /* hr += Log_Dnorm_Trunc(cur_centr_pos, */ + /* new_centr_pos, */ + /* 0.5*sd, */ + /* 0.0, */ + /* tree->mmod->lim->lonlat[i],&err); */ + + + ldsk->coord->lonlat[i] = new_ldsk_pos; + ldsk->disk->centr->lonlat[i] = new_centr_pos; + } + + /* new_glnL = PHYREX_Lk_Range(young->disk,old->disk,tree); */ + /* new_glnL = PHYREX_Lk_Core_Range(young->disk,old->disk,tree); */ + new_glnL = PHYREX_Lk_Range(ldsk->disk,ldsk->prev->disk,tree); + /* new_glnL = PHYREX_Lk(tree); */ + + + /* PhyML_Printf("\n. k: %4d lnL: %f",k,cur_glnL); */ + + ratio += (new_glnL - cur_glnL); + ratio += hr; + + /* (*global_hr) -= ratio; */ + + ratio = exp(ratio); + alpha = MIN(1.,ratio); + + u = Uni(); + + if(u > alpha) /* Reject */ + { + PHYREX_Restore_Geo_Coord(ldsk->coord); + PHYREX_Restore_Geo_Coord(ldsk->disk->centr); + reject++; + } + else + { + cur_glnL = new_glnL; + accept++; + } + + ldsk = ldsk->prev; + } + while(ldsk != old); + + n_mcmc_iter++; + } + while(n_mcmc_iter < 100 * path_len); + /* while(n_mcmc_iter < 1); */ + /* PhyML_Printf("\n. ratio: %f %d %d",(phydbl)(accept)/(phydbl)(accept+reject),accept,reject); */ +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Time_Tree_Length(t_tree *tree) +{ + phydbl len; + int i; + t_dsk *disk; + + disk = tree->young_disk; + while(disk->prev) disk = disk->prev; + + len = 0.0; + for(i=0;ildsk->n_next;i++) PHYREX_Time_Tree_Length_Pre(disk->ldsk,disk->ldsk->next[i],&len,tree); + + assert(!(isnan(len) || isinf(len))); + + return(len); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Time_Tree_Length_Pre(t_ldsk *a, t_ldsk *d, phydbl *len, t_tree *tree) +{ + int i; + + (*len) += FABS(a->disk->time - d->disk->time); + + if(d->disk->next == NULL) return; + else + for(i=0;in_next;i++) PHYREX_Time_Tree_Length_Pre(d,d->next[i],len,tree); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int PHYREX_Is_On_Path(t_ldsk *target, t_ldsk *young, t_ldsk *old) +{ + t_ldsk *ldsk; + + if(target == young || target == old) return NO; + + assert(!(young->disk->time < old->disk->time)); + + ldsk = young->prev; + while(ldsk != old) + { + if(ldsk == target) return YES; + ldsk = ldsk->prev; + assert(!(ldsk == NULL)); + } + return NO; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int PHYREX_Path_Len(t_ldsk *young, t_ldsk *old) +{ + t_ldsk *ldsk; + int len; + + len = 0; + ldsk = young; + while(ldsk != old) + { + len++; + ldsk = ldsk->prev; + } + len++; + return len; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Print_Disk_Lk(t_tree *tree) +{ + t_dsk *disk; + + PHYREX_Update_Lindisk_List(tree); + + disk = tree->young_disk->prev; + + do + { + PhyML_Printf("\n. Disk: %s time: %12f lk: %12f cumlk: %12f", + disk->id, + disk->time, + PHYREX_Lk_Core(disk,tree), + -1.); + + disk = disk->prev; + } + while(disk->prev); + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +t_ldsk *PHYREX_Find_Lca_Pair_Of_Ldsk(t_ldsk *n1, t_ldsk *n2, t_tree *tree) +{ + t_ldsk **list1, **list2, *lca; + int len1, len2; + + assert(n1); + assert(n2); + + if(n1 == n2) return(n1); + + PHYREX_Get_List_Of_Ancestors(n1,&list1,&len1,tree); + PHYREX_Get_List_Of_Ancestors(n2,&list2,&len2,tree); + + len1 = len1-1; + len2 = len2-1; + + /* printf("\n. len1: %d len2: %d",len1,len2); fflush(NULL); */ + /* printf("\n. %f %f %d %d [%f %f]", */ + /* list1[1]->disk->time, */ + /* list2[1]->disk->time, */ + /* len1,len2, */ + /* n1->disk->time, */ + /* n2->disk->time); */ + + assert(list1[len1] == list2[len2]); + + + do + { + if((len1 < 0 || len2 < 0) || (list1[len1] != list2[len2])) break; + len1--; + len2--; + } + while(len1 && len2); + + + lca = list1[len1+1]; + + Free(list1); + Free(list2); + + assert(lca); + + return(lca); + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Get_List_Of_Ancestors(t_ldsk *start, t_ldsk ***list, int *len, t_tree *tree) +{ + int block,i; + t_ldsk *ldsk; + + assert(start); + block = 100; + + *list = (t_ldsk **)mCalloc(block,sizeof(t_ldsk *)); + + ldsk = start; + i = 0; + do + { + (*list)[i] = ldsk; + if(!(i%block)) *list = (t_ldsk **)mRealloc(*list,i+block,sizeof(t_ldsk *)); + i++; + ldsk = ldsk->prev; + } + while(ldsk); + + (*len) = i; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Dist_To_Lca(t_ldsk *d, t_ldsk *lca) +{ + return(fabs(d->disk->time - lca->disk->time)); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Dist_Between_Two_Ldsk(t_ldsk *n1, t_ldsk *n2, t_tree *tree) +{ + t_ldsk *lca; + + lca = PHYREX_Find_Lca_Pair_Of_Ldsk(n1,n2,tree); + + return(PHYREX_Dist_To_Lca(n1,lca)+PHYREX_Dist_To_Lca(n2,lca)); +} + + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Print_MultiTypeTree_Config_File(int n_sites, char *filename, t_tree *tree) +{ + int i, j, n_demes; + char *s,**deme_names; + FILE *fp; + + + fp = Openfile(filename,WRITE); + assert(fp); + + deme_names = (char **)mCalloc(n_sites,sizeof(char *)); + + n_demes = 0; + for(i=0;in_otu;i++) + { + s = strrchr(tree->a_nodes[i]->ldsk->coord->id,'_'); + for(j=0;j"); + PhyML_Fprintf(fp,"\n"); + + PhyML_Fprintf(fp,"\n"); + + + for(i=0;in_otu;i++) + { + PhyML_Fprintf(fp,"\n", + tree->a_nodes[i]->ldsk->coord->id, + /* tree->a_nodes[i]->coord->id, */ + tree->a_nodes[i]->name, + tree->a_nodes[i]->c_seq->state); + } + + PhyML_Fprintf(fp,"\n"); + + PhyML_Fprintf(fp,"\nbeast.math.distributions.Uniform"); + PhyML_Fprintf(fp,"\nbeast.math.distributions.Exponential"); + PhyML_Fprintf(fp,"\nbeast.math.distributions.LogNormalDistributionModel"); + PhyML_Fprintf(fp,"\nbeast.math.distributions.Normal"); + PhyML_Fprintf(fp,"\nbeast.math.distributions.Beta"); + PhyML_Fprintf(fp,"\nbeast.math.distributions.Gamma"); + PhyML_Fprintf(fp,"\nbeast.math.distributions.LaplaceDistribution"); + PhyML_Fprintf(fp,"\nbeast.math.distributions.Prior"); + PhyML_Fprintf(fp,"\nbeast.math.distributions.InverseGamma"); + PhyML_Fprintf(fp,"\nbeast.math.distributions.OneOnX"); + + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + + + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + For(i,n_demes*(n_demes-1)) strcat(s,"1.0 "); + PhyML_Fprintf(fp,"\n%s",n_demes*(n_demes-1),s); + Free(s); + + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + for(i=0;i%s",n_demes,s); + Free(s); + + PhyML_Fprintf(fp,"\n"); + + PhyML_Fprintf(fp,"\nn_otu;i++) + { + s = strrchr(tree->a_nodes[i]->ldsk->coord->id,'_'); + PhyML_Fprintf(fp,"%s=%s", + tree->a_nodes[i]->ldsk->coord->id, + s+1); + + if(i < tree->n_otu-1) PhyML_Fprintf(fp,","); + else PhyML_Fprintf(fp,"\">"); + } + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n2.0"); + + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + for(i=0;i%s",n_demes,s); + Free(s); + + s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + For(i,n_demes*(n_demes-1)) strcat(s,"1.0 "); + PhyML_Fprintf(fp,"\n%s",n_demes*(n_demes-1),s); + Free(s); + + + PhyML_Fprintf(fp,"\n0.25"); + PhyML_Fprintf(fp,"\n"); + + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n1.0"); + PhyML_Fprintf(fp,"\n1.25"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n1.0"); + PhyML_Fprintf(fp,"\n1.25"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n1.0"); + PhyML_Fprintf(fp,"\n1.25"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n1.0"); + PhyML_Fprintf(fp,"\n1.0"); + PhyML_Fprintf(fp,"\n0.0"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n%G",1.0); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + /* PhyML_Fprintf(fp,"\n"); */ + /* PhyML_Fprintf(fp,"\n"); */ + /* PhyML_Fprintf(fp,"\n"); */ + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + PhyML_Fprintf(fp,"\n"); + + for(i=0;in_otu,sizeof(char *)); + + disk = tree->young_disk; + + n_demes = 0; + for(i=0;in_otu;i++) + { + for(j=0;jldsk_a[i]->coord->id,"_deme"),deme_list[j])) + { + break; + } + } + + if(j == n_demes) + { + deme_list[j] = strstr(disk->ldsk_a[i]->coord->id,"_deme"); + /* printf("\n. deme_list[%d]: %s",j,deme_list[j]); */ + n_demes++; + } + } + + Free(deme_list); + + + return(n_demes); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// Coalescence rate with time expressed in calendar unit +phydbl PHYREX_Coalescence_Rate(t_tree *tree) +{ + phydbl mu,theta,lbda,w,h; + + mu = tree->mmod->mu; + theta = tree->mmod->rad; + lbda = tree->mmod->lbda; + w = (tree->mmod->lim_up->lonlat[0]-tree->mmod->lim_do->lonlat[0]); + h = (tree->mmod->lim_up->lonlat[1]-tree->mmod->lim_do->lonlat[1]); + + return(4.*POW(PI,2)*POW(theta,4)*POW(mu,2)*lbda / (POW(w,2)*POW(h,2))); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl Prob_Two_Random_Lineages_Coal_One_Event(phydbl w, phydbl h, phydbl mu, phydbl rad) +{ + phydbl cx,cy; + phydbl l1x,l1y; + phydbl l2x,l2y; + phydbl prob_hit; + int n_hit,n_trials,trial; + + n_trials = 10000000; + trial = 0; + n_hit = 0; + do + { + cx = Uni()*w; + cy = Uni()*h; + + l1x = Uni()*w; + l1y = Uni()*h; + + l2x = Uni()*w; + l2y = Uni()*h; + + prob_hit = log(mu); + prob_hit += -POW(l1x - cx,2)/(2.*pow(rad,2)); + prob_hit += -POW(l1y - cy,2)/(2.*pow(rad,2)); + + prob_hit += log(mu); + prob_hit += -POW(l2x - cx,2)/(2.*pow(rad,2)); + prob_hit += -POW(l2y - cy,2)/(2.*pow(rad,2)); + + prob_hit = exp(prob_hit); + + if(!(Uni() > prob_hit)) n_hit++; + + trial++; + } + while(trial != n_trials); + + return((phydbl)n_hit/n_trials); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Prob_Two_Lineages_Coal(t_ldsk *l0, t_ldsk *l1, t_tree *tree) +{ + phydbl eucl,prob,area,W,H; + + assert(tree->mmod->n_dim == 2); + + W = (tree->mmod->lim_up->lonlat[0]-tree->mmod->lim_do->lonlat[0]); + H = (tree->mmod->lim_up->lonlat[1]-tree->mmod->lim_do->lonlat[1]); + + area = W*H; + + eucl = Euclidean_Dist(l0->coord,l1->coord); + + prob = 0.0; + prob += 2.*log(tree->mmod->mu); + prob += 2.*log(tree->mmod->rad); + prob += log(PI); + prob -= log(4.*area); + prob -= 0.25*eucl*eucl/(tree->mmod->rad*tree->mmod->rad); + + + prob += + log(erf((l0->coord->lonlat[0] + l1->coord->lonlat[0])/(2.*tree->mmod->rad)) + + erf((2.*W - l0->coord->lonlat[0] - l1->coord->lonlat[0])/(2.*tree->mmod->rad))); + + prob += + log(erf((l0->coord->lonlat[1] + l1->coord->lonlat[1])/(2.*tree->mmod->rad)) + + erf((2.*H - l0->coord->lonlat[1] - l1->coord->lonlat[1])/(2.*tree->mmod->rad))); + + prob = exp(prob); + + return(prob); +} + + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Returns the number of ldsks going from disk towards the past */ +int PHYREX_Number_Of_Outgoing_Ldsks(t_dsk *disk) +{ + int i; + + if(disk->ldsk == NULL) return disk->n_ldsk_a; + else + { + int n_out; + + n_out = 0; + for(i=0;in_ldsk_a;++i) + { + if(disk->ldsk_a[i] && disk->ldsk_a[i]->prev != disk->ldsk) + { + n_out++; + } + } + return(n_out+1); /* +1 so as to count disk->ldsk in */ + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Select uniformly at random a lineage going "out of" disk (towards the past) */ +t_ldsk *PHYREX_Random_Select_Outgoing_Ldsk(t_dsk *disk) +{ + int i,*permut,n_ldsk_a_out; + t_ldsk **ldsk_a_out,*target_ldsk; + + ldsk_a_out = (t_ldsk **)mCalloc(disk->n_ldsk_a,sizeof(t_ldsk *)); + + n_ldsk_a_out = 0; + if(disk->ldsk != NULL) + { + ldsk_a_out[0] = disk->ldsk; + n_ldsk_a_out = 1; + } + + for(i=0;in_ldsk_a;++i) + { + if(disk->ldsk_a[i] && disk->ldsk_a[i]->prev != disk->ldsk) + { + ldsk_a_out[n_ldsk_a_out] = disk->ldsk_a[i]; + n_ldsk_a_out++; + } + } + + permut = Permutate(n_ldsk_a_out); + target_ldsk = ldsk_a_out[permut[0]]; + + Free(permut); + Free(ldsk_a_out); + + return(target_ldsk); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Remove and free all disks and ldsks except for sampled disks. + Connect the sampled disks together */ + +void PHYREX_Strip_And_Reconnect_Tree(t_tree *tree) +{ + t_dsk *disk,*prev; + int i,orig_size; + + disk = tree->young_disk; + do + { + if(disk->age_fixed == YES) + { + orig_size = disk->n_ldsk_a; + for(i=0;ildsk_a[i] && + disk->ldsk_a[i]->disk != disk) + { + disk->ldsk_a[i] = NULL; + disk->n_ldsk_a--; + } + } + for(i=0;in_ldsk_a;++i) disk->ldsk_a[i]->prev = NULL; + } + disk = disk->prev; + } + while(disk); + + disk = tree->young_disk; + do + { + prev = disk->prev; + if(disk->age_fixed == NO) + { + PHYREX_Remove_Disk(disk); + Free_Ldisk(disk->ldsk); + Free_Disk(disk); + } + disk = prev; + } + while(disk); + + + /* disk = tree->young_disk; */ + /* do */ + /* { */ + /* PhyML_Printf("\n. %s %d",disk->id,disk->age_fixed); */ + /* if(disk->age_fixed == YES) */ + /* { */ + /* for(i=0;in_ldsk_a;++i) */ + /* { */ + /* PhyML_Printf("\n. %s %f %s",disk->id,disk->time,disk->ldsk_a[i] ? disk->ldsk_a[i]->coord->id : "?"); */ + /* } */ + /* } */ + /* disk = disk->prev; */ + /* } */ + /* while(disk); */ + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int PHYREX_Scale_All(phydbl scale, t_dsk *start_disk, t_tree *tree) +{ + t_dsk *disk; + t_dsk **sorted_disk; + int n_disk,n_disk_scaled,sorted,i; + + n_disk = 0; + n_disk_scaled = 0; + + disk = start_disk->prev; + assert(disk); + + do + { + if(disk->age_fixed == NO) + { + disk->time = disk->time * scale + start_disk->time * (1.-scale); + n_disk_scaled++; + } + + n_disk++; + disk = disk->prev; + } + while(disk); + + sorted_disk = (t_dsk **)mCalloc(n_disk,sizeof(t_dsk *)); + disk = start_disk->prev; + n_disk = 0; + do + { + sorted_disk[n_disk] = disk; + n_disk++; + disk = disk->prev; + } + while(disk); + + + do + { + sorted = YES; + for(i=0;itime < sorted_disk[i+1]->time) + { + sorted = NO; + disk = sorted_disk[i]; + sorted_disk[i] = sorted_disk[i+1]; + sorted_disk[i+1] = disk; + } + } + } + while(sorted == NO); + + + for(i=0;iyoung_disk; + do + { + if(disk->age_fixed == YES) tree->old_samp_disk = disk; + disk = disk->prev; + } + while(disk); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Time_Of_Descendants(t_ldsk *ldsk, t_tree *tree) +{ + if(ldsk->disk->age_fixed == YES || ldsk->disk == tree->young_disk) return ldsk->disk->time; + else + { + int i; + phydbl t,min; + + min = tree->young_disk->time; + + for(i=0;in_next;++i) + { + t = PHYREX_Time_Of_Descendants(ldsk->next[i],tree); + if(t < min) min = t; + } + return(min); + } + return(1.); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Time_Of_Prev_Sampled_Disk(t_dsk *disk, t_tree *tree) +{ + + if(disk->prev == NULL) return -INFINITY; + else + { + disk = disk->prev; + while(disk && disk->age_fixed == NO) disk = disk->prev; + if(!disk) return -INFINITY; + else return(disk->time); + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Time_Of_Next_Sampled_Disk(t_dsk *disk, t_tree *tree) +{ + + if(disk->next == NULL) return tree->young_disk->time; + else + { + disk = disk->next; + while(disk && disk->age_fixed == NO) disk = disk->next; + if(!disk) return tree->young_disk->time; + else return(disk->time); + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Lk_Time_Component(t_tree *tree) +{ + phydbl lnL; + t_dsk *disk; + phydbl dt; + int n_evt; + + n_evt = 0; + dt = 0.0; + lnL = 0.0; + disk = tree->young_disk->prev; + do + { + + if(disk->age_fixed == NO) + { + dt += fabs(disk->next->time - disk->time); + n_evt++; + } + + disk = disk->prev; + + } + while(disk); + + lnL += n_evt * log(tree->mmod->lbda) - tree->mmod->lbda * dt; + + return(lnL); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +t_ldsk *PHYREX_Find_Ldsk_From_Id(char *id, t_ldsk *root) +{ + t_ldsk *ldsk; + + ldsk = NULL; + + if(!strcmp(root->coord->id,id)) return(root); + + if(root->n_next == 0) return(NULL); + + for(int i=0;in_next;++i) + { + ldsk = PHYREX_Find_Ldsk_From_Id(id,root->next[i]); + if(ldsk != NULL) break; + } + + return(ldsk); +} + + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +t_geo_coord *PHYREX_Mean_Next_Loc(t_ldsk *ldsk, t_tree *tree) +{ + t_geo_coord *mean; + int i,j; + + mean = GEO_Make_Geo_Coord(tree->mmod->n_dim); + + assert(ldsk->n_next > 0); + + for(i=0;in_next;++i) + { + for(j=0;jmmod->n_dim;++j) + { + mean->lonlat[j] += ldsk->next[i]->coord->lonlat[j]; + } + } + + for(j=0;jmmod->n_dim;++j) + { + mean->lonlat[j] /= (phydbl)ldsk->n_next; + } + + return(mean); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// realized sigsq = (1/d) E(\sum_x D_x^2), where $D_x$ is the +// square euclidean distance along the x-axis between the +// location of a lineage at time $t$ and time $t+1$. +phydbl PHYREX_Root_To_Tip_Realized_Sigsq(t_tree *tree) +{ + t_dsk *disk,*root_disk; + int i; + phydbl res,*sigsq; + phydbl t_root, t_tip; + + sigsq = (phydbl *)mCalloc(tree->young_disk->n_ldsk_a,sizeof(phydbl)); + + disk = tree->young_disk; + while(disk->prev) disk = disk->prev; + root_disk = disk; + + t_root = root_disk->time; + t_tip = tree->young_disk->time; + assert(t_tip - t_root > 0.0); + + disk = tree->young_disk; + for(i=0;in_ldsk_a;++i) + sigsq[i] = pow(Euclidean_Dist(root_disk->ldsk->coord,disk->ldsk_a[i]->coord) / (t_tip - t_root),2); + + res = Quantile(sigsq,disk->n_ldsk_a,0.5); + + Free(sigsq); + + return(res/tree->mmod->n_dim); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// Mean Haversine distance (in km) per year (measured on path between root and tips on the most recent disk) +phydbl PHYREX_Realized_Dispersal_Dist(t_tree *tree) +{ + t_dsk *disk,*root_disk; + phydbl dist,t_tip,t_root; + int i; + + disk = tree->young_disk; + while(disk->prev) disk = disk->prev; + root_disk = disk; + + t_root = root_disk->time; + t_tip = tree->young_disk->time; + assert(t_tip - t_root > 0.0); + \ + disk = tree->young_disk; + dist = 0.0; + for(i=0;in_ldsk_a;++i) + { + dist += Haversine_Distance(root_disk->ldsk->coord->lonlat[0], + root_disk->ldsk->coord->lonlat[1], + disk->ldsk_a[i]->coord->lonlat[0], + disk->ldsk_a[i]->coord->lonlat[1])/(t_tip - t_root); + + } + + return(dist/disk->n_ldsk_a); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Tip_To_Root_Realized_Sigsq(t_tree *tree) +{ + t_dsk *disk; + phydbl *sigsq,res; + int i; + + + sigsq = (phydbl *)mCalloc(tree->young_disk->n_ldsk_a,sizeof(phydbl)); + + disk = tree->young_disk; + for(i=0;in_ldsk_a;++i) + { + sigsq[i] = + pow(Euclidean_Dist(disk->ldsk_a[i]->coord, + disk->ldsk_a[i]->prev->coord)/fabs(disk->time - disk->ldsk_a[i]->prev->disk->time),2); + + } + + res = Quantile(sigsq,disk->n_ldsk_a,0.5); + + Free(sigsq); + + return(res/tree->mmod->n_dim); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Tip_To_Root_Realized_Bis_Sigsq(t_tree *tree) +{ + t_dsk *disk; + phydbl sumdist,sumt; + int i; + + /* sumdist = 0.0; */ + /* sumt = 0.0; */ + /* disk = tree->young_disk; */ + /* for(i=0;in_ldsk_a;++i) */ + /* { */ + /* sumdist += Euclidean_Dist(disk->ldsk_a[i]->coord, */ + /* disk->ldsk_a[i]->prev->coord); */ + /* sumt += fabs(disk->time - disk->ldsk_a[i]->prev->disk->time); */ + /* } */ + + /* return(pow(sumdist/sumt,2)/tree->mmod->n_dim); */ + + sumdist = 0.0; + sumt = 0.0; + disk = tree->young_disk; + for(i=0;in_ldsk_a;++i) + { + sumdist += pow(Euclidean_Dist(disk->ldsk_a[i]->coord, + disk->ldsk_a[i]->prev->coord),2); + sumt += tree->mmod->n_dim * fabs(disk->time - disk->ldsk_a[i]->prev->disk->time); + } + + return(sumdist/sumt); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl PHYREX_Tip_To_Root_Realized_Ter_Sigsq(t_tree *tree) +{ + t_ldsk *ldsk; + phydbl mean,dist; + int i; + + mean = 0.0; + for(i=0;iyoung_disk->n_ldsk_a;++i) + { + ldsk = tree->young_disk->ldsk_a[i]; + while(ldsk && ldsk->prev && fabs(ldsk->prev->disk->time-tree->young_disk->ldsk_a[i]->disk->time) < 1.0) + { + ldsk = ldsk->prev; + if(ldsk == NULL) return(-1.); + } + dist = Euclidean_Dist(ldsk->coord,tree->young_disk->ldsk_a[i]->coord); + mean += pow(dist,2); + + /* PhyML_Printf("\n. %3d (%12f %12f) (%12f %12f) dist: %12f mean: %12f", */ + /* i, */ + /* tree->young_disk->ldsk_a[i]->coord->lonlat[0], */ + /* tree->young_disk->ldsk_a[i]->coord->lonlat[1], */ + /* ldsk->coord->lonlat[0], */ + /* ldsk->coord->lonlat[1], */ + /* Euclidean_Dist(ldsk->coord,tree->young_disk->ldsk_a[i]->coord), */ + /* mean); */ + + } + + return(mean/(tree->young_disk->n_ldsk_a*tree->mmod->n_dim)); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Label_Nodes_With_Locations(t_tree *tree) +{ + t_dsk *disk; + t_node *n; + phydbl lon,lat; + + + lon = lat = -1.; + + for(int i=0;in_otu;++i) + { + if(tree->a_nodes[i]->label == NULL) + { + tree->a_nodes[i]->label = Make_Label(); + tree->a_nodes[i]->label->next = Make_Label(); + } + + lat = tree->a_nodes[i]->ldsk->coord->lonlat[1]; + lon = tree->a_nodes[i]->ldsk->coord->lonlat[0]; + + sprintf(tree->a_nodes[i]->label->key,"&location"); + sprintf(tree->a_nodes[i]->label->val,"{%f,%f}",lat,lon); + sprintf(tree->a_nodes[i]->label->next->key,"location"); + sprintf(tree->a_nodes[i]->label->next->val,"{%f,%f}",lat,lon); + } + + disk = tree->young_disk->prev; + + do + { + if(disk->ldsk && disk->ldsk->nd != NULL) + { + n = disk->ldsk->nd; + if(n->label == NULL) + { + n->label = Make_Label(); + n->label->next = Make_Label(); + } + + lat = disk->ldsk->coord->lonlat[1]; + lon = disk->ldsk->coord->lonlat[0]; + + sprintf(n->label->key,"&location"); + sprintf(n->label->val,"{%f,%f}",lat,lon); + sprintf(n->label->next->key,"location"); + sprintf(n->label->next->val,"{%f,%f}",lat,lon); + + /* Print same label on all internal nodes with exactly the */ + /* same coalescence time. */ + for(int i=tree->n_otu;i<2*tree->n_otu-1;++i) + { + if(tree->a_nodes[i] != n && + Are_Equal(tree->rates->nd_t[i], + tree->rates->nd_t[n->num], + 1.E-10) == YES) + { + n = tree->a_nodes[i]; + if(n->label == NULL) + { + n->label = Make_Label(); + n->label->next = Make_Label(); + } + + lat = disk->ldsk->coord->lonlat[1]; + lon = disk->ldsk->coord->lonlat[0]; + + sprintf(n->label->key,"&location"); + sprintf(n->label->val,"{%f,%f}",lat,lon); + sprintf(n->label->next->key,"location"); + sprintf(n->label->next->val,"{%f,%f}",lat,lon); + } + } + } + + disk = disk->prev; + } + while(disk); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Label_Edges(t_tree *tree) +{ + for(int i=0;i<2*tree->n_otu-1;++i) + { + if(tree->a_edges[i]->label == NULL) + { + tree->a_edges[i]->label = Make_Label(); + tree->a_edges[i]->label->next = Make_Label(); + } + + sprintf(tree->a_edges[i]->label->key,"&rate"); + sprintf(tree->a_edges[i]->label->val,"0.0"); + + sprintf(tree->a_edges[i]->label->next->key,"location.rate"); + sprintf(tree->a_edges[i]->label->next->val,"0.0"); + } + + +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void PHYREX_Integrated_Coal_Rate(t_ldsk *l0, t_ldsk *l1, phydbl T, t_tree *tree) +{ + t_ldsk *baseline; + phydbl integrated_coal_rate,njumps,coaltime; + int coal; + + PhyML_Printf("\n# "); + + + coal = -1; + baseline = l0; + integrated_coal_rate = 0.0; + njumps = 0.0; + coaltime = 0.0; + do + { + if(l0->prev->disk->time > l1->prev->disk->time) + { + assert(coal == -1); + integrated_coal_rate += + tree->mmod->lbda * PHYREX_Prob_Two_Lineages_Coal(l0,l1,tree) * + fabs(baseline->disk->time - MAX(l0->prev->disk->time,l1->prev->disk->time)); + + njumps+=1.0; + baseline = l0->prev; + + l0 = l0->prev; + } + else if(l0->prev->disk->time < l1->prev->disk->time) + { + assert(coal == -1); + integrated_coal_rate += + tree->mmod->lbda * PHYREX_Prob_Two_Lineages_Coal(l0,l1,tree) * + fabs(baseline->disk->time - MAX(l0->prev->disk->time,l1->prev->disk->time)); + + njumps+=1.0; + baseline = l1->prev; + + l1 = l1->prev; + } + else + { + assert(l0->prev); + assert(l1->prev); + assert(l0->prev == l1->prev); + coaltime = l0->prev->disk->time; + if(coaltime > T) + { + coal = 1; + } + else + { + coal = 0; + integrated_coal_rate += + tree->mmod->lbda * PHYREX_Prob_Two_Lineages_Coal(l0,l1,tree) * + fabs(baseline->disk->time - T); + } + + l0->prev = NULL; + l1->prev = NULL; + } + } + while(l0->prev && l1->prev); + + PhyML_Printf("%d %f %g %f", + coal, + integrated_coal_rate, + njumps, + coaltime); + PhyML_Printf("\n"); + Exit("\n"); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// Calculation of Pr(T>n) where T is the proba of coalescence +void PHYREX_Sum_Coal_Rate(t_ldsk *l0, t_ldsk *l1, int n, t_tree *tree) +{ + t_dsk *disk; + phydbl prod_one_min_coal_prob; + int coal,n_evts; + + + PhyML_Printf("\n# "); + + prod_one_min_coal_prob = 0.0; + n_evts = 1; + coal = 0; + disk = tree->young_disk->prev; + do + { + + if(n_evts <= n) prod_one_min_coal_prob += log(1. - PHYREX_Prob_Two_Lineages_Coal(l0,l1,tree)); + + if(l0->prev == disk->ldsk) l0 = disk->ldsk; + if(l1->prev == disk->ldsk) l1 = disk->ldsk; + if(l0 == l1 && n_evts <= n) coal = 1; + disk = disk->prev; + n_evts++; + } + while(disk); + + prod_one_min_coal_prob = exp(prod_one_min_coal_prob); + + PhyML_Printf("%d %d %f",coal,n_evts,prod_one_min_coal_prob); + PhyML_Printf("\n"); + Exit("\n"); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ diff --git a/phyml/phyrex.h b/phyml/phyrex.h new file mode 100644 index 0000000..60947f0 --- /dev/null +++ b/phyml/phyrex.h @@ -0,0 +1,144 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef PHYREX_H +#define PHYREX_H + +#include "utilities.h" + +void PHYREX_XML(char *xml_filename); +int PHYREX_Main(int argc, char **argv); +int PHYREX_Main_Simulate(int argc, char **argv); +t_tree *PHYREX_Simulate(int n_otu, int n_sites, phydbl w, phydbl h, phydbl lbda, phydbl rad, phydbl mu, int r_seed); +phydbl PHYREX_Lk(t_tree *tree); +phydbl PHYREX_Wrap_Lk(t_edge *b, t_tree *tree, supert_tree *stree); +phydbl *PHYREX_MCMC(t_tree *tree); +int PHYREX_Is_In_Disk(t_geo_coord *coord, t_dsk *disk, t_phyrex_mod *mmod); +void PHYREX_New_Traj(t_dsk *start, t_dsk *end, t_tree *tree); +void PHYREX_Remove_Disk(t_dsk *disk); +void PHYREX_Insert_Disk(t_dsk *ins, t_tree *tree); +t_ldsk *PHYREX_Prev_Coal_Lindisk(t_ldsk *t); +t_ldsk *PHYREX_Next_Coal_Lindisk(t_ldsk *t); +int PHYREX_Get_Next_Direction(t_ldsk *young, t_ldsk *old); +void PHYREX_Update_Lindisk_List(t_tree *tree); +void PHYREX_Update_Lindisk_List_Pre(t_dsk *disk, t_tree *tree); +/* void PHYREX_Update_Lindisk_List(phydbl time, t_ldsk **list, int *pos, t_dsk *disk); */ +/* void PHYREX_Update_Lindisk_List_Pre(t_ldsk *ldsk, phydbl time, t_ldsk **list, int *pos); */ +void PHYREX_Connect_Ldsk_Given_Disk(t_dsk **disk, int n_disk, t_ldsk *y_ldsk, t_ldsk *o_ldsk, int dir_o_y); +void PHYREX_Print_Struct(char sign, t_tree *tree); +phydbl PHYREX_Uniform_Path_Density(t_ldsk *y_ldsk, t_ldsk *o_ldsk, t_tree *tree); +int PHYREX_Check_Struct(t_tree *tree); +void PHYREX_Store_Geo_Coord(t_geo_coord *t); +void PHYREX_Restore_Geo_Coord(t_geo_coord *t); +int PHYREX_Total_Number_Of_Intervals(t_tree *tree); +int PHYREX_Total_Number_Of_Coal_Disks(t_tree *tree); +int PHYREX_Total_Number_Of_Hit_Disks(t_tree *tree); +phydbl PHYREX_Log_Dunif_Rectangle_Overlap(t_ldsk *ldsk, t_dsk *disk, t_phyrex_mod *mmod); +phydbl PHYREX_Runif_Rectangle_Overlap(t_ldsk *ldsk, t_dsk *disk, t_phyrex_mod *mod); +int PHYREX_One_New_Traj(t_ldsk *y_ldsk, t_ldsk *o_ldsk, int dir_o_y, t_dsk *xtra_dsk, int n_cur_disk, t_tree *tree); +phydbl PHYREX_Wrap_Prior_Radius(t_edge *e, t_tree *tree, supert_tree *st); +phydbl PHYREX_LnPrior_Radius(t_tree *tree); +void PHYREX_Initial_Ldsk_Pos(t_tree *tree); +phydbl PHYREX_Min_Radius(t_tree *tree); +void PHYREX_Get_Min_Max_Disk_Given_Ldsk(t_dsk *disk, phydbl **min, phydbl **max, t_tree *tree); +void PHYREX_Get_Min_Max_Ldsk_Given_Disk(t_ldsk *ldsk, phydbl **min, phydbl **max, t_tree *tree); +void PHYREX_One_New_Traj_Given_Disk(t_ldsk *y_ldsk, t_ldsk *o_ldsk, t_tree *tree); +void PHYREX_Update_Disk_Ldsk_Subtree(t_ldsk *root_ldsk, t_tree *tree); +void PHYREX_Update_Disk_Ldsk_Subtree_Pre(t_ldsk *old_ldsk, t_ldsk *young_ldsk, t_ldsk *root_ldsk, t_tree *tree); +void PHYREX_Restore_Disk_Ldsk_Subtree(t_ldsk *root_ldsk, t_tree *tree); +void PHYREX_Restore_Disk_Ldsk_Subtree_Pre(t_ldsk *old_ldsk, t_ldsk *young_ldsk, t_tree *tree); +void PHYREX_Proposal_Disk_Ldsk_Subtree(t_ldsk *root_ldsk, phydbl *logdens, t_tree *tree); +void PHYREX_Proposal_Disk_Ldsk_Subtree_Pre(t_ldsk *old_ldsk, t_ldsk *young_ldsk, t_ldsk *root_ldsk, phydbl *logdens, t_tree *tree); +phydbl PHYREX_LnPrior_Lbda(t_tree *tree); +phydbl PHYREX_LnPrior_Mu(t_tree *tree); +void PHYREX_Ldsk_To_Tree(t_tree *tree); +void PHYREX_Ldsk_To_Tree_Post(t_node *a, t_ldsk *ldsk, int *available, t_tree *tree); +phydbl PHYREX_Rnorm_Trunc(t_ldsk *ldsk, t_dsk *disk, t_phyrex_mod *mod); +void PHYREX_Remove_Lindisk_Next(t_ldsk *ldsk, t_ldsk *rm); +phydbl PHYREX_Simulate_Backward_Core(t_dsk *init_disk, int avoid_multiple_mergers, t_tree *tree); +phydbl *PHYREX_Mean_Pairwise_Distance_Between_Lineage_Locations(t_tree *tree); +phydbl PHYREX_Random_Select_Time_Between_Jumps(t_tree *tree); +t_sarea *PHYREX_Simulate_Forward_Core(int n_sites, t_tree *tree); +int PHYREX_Is_In_Ldscape(t_ldsk *ldsk, t_phyrex_mod *mmod); +void PHYREX_Update_Lindisk_List_Core(t_dsk *disk, t_tree *tree); +phydbl PHYREX_Mean_Time_Between_Events(t_tree *tree); +void PHYREX_All_Pairs_Coal_Times_Dist(t_tree *tree); +void PHYREX_Rand_Pairs_Coal_Times_Dist(t_tree *tree); +phydbl PHYREX_Neighborhood_Size_Regression(t_tree *tree); +phydbl PHYREX_Neighborhood_Size(t_tree *tree); +phydbl PHYREX_Update_Radius(t_tree *tree); +phydbl PHYREX_Update_Sigsq(t_tree *tree); +void PHYREX_Read_Tip_Coordinates(t_tree *tree); +phydbl PHYREX_Sample_Rad_From_Prior(t_tree *tree); +void MCMC_PHYREX_Sigsq(t_tree *tree); +phydbl PHYREX_LnPrior_Sigsq(t_tree *tree); +phydbl PHYREX_Rate_Per_Unit_Area(t_tree *tree); +phydbl PHYREX_Tree_Height(t_tree *tree); +int PHYREX_Random_Insert_Ldsk_In_Next_List(t_ldsk *ins, t_ldsk *where); +void PHYREX_Insert_Ldsk_In_Next_List(t_ldsk *ins, int pos, t_ldsk *where); +t_ldsk *PHYREX_Remove_Path(t_ldsk *beg, t_ldsk *end, int *pos_end, t_tree *tree); +void PHYREX_Insert_Path(t_ldsk *beg, t_ldsk *end, t_ldsk *path, int pos, t_tree *tree); +t_ldsk *PHYREX_Generate_Path(t_ldsk *beg, t_ldsk *end, phydbl n_evt, phydbl sd, t_tree *tree); +phydbl PHYREX_Path_Logdensity(t_ldsk *beg, t_ldsk *end, phydbl sd, t_tree *tree); +phydbl PHYREX_Time_Tree_Length(t_tree *tree); +void PHYREX_Time_Tree_Length_Pre(t_ldsk *a, t_ldsk *d, phydbl *len, t_tree *tree); +int PHYREX_Is_On_Path(t_ldsk *target, t_ldsk *beg, t_ldsk *end); +int PHYREX_Path_Len(t_ldsk *beg, t_ldsk *end); +phydbl PHYREX_Lk_Core(t_dsk *disk, t_tree *tree); +void PHYREX_Print_Disk_Lk(t_tree *tree); +phydbl PHYREX_Lk_Core_Bis(t_dsk *disk, t_tree *tree); +t_ldsk *PHYREX_Find_Lca_Pair_Of_Ldsk(t_ldsk *n1, t_ldsk *n2, t_tree *tree); +void PHYREX_Get_List_Of_Ancestors(t_ldsk *start, t_ldsk ***list, int *len, t_tree *tree); +phydbl PHYREX_Dist_To_Lca(t_ldsk *d, t_ldsk *lca); +phydbl PHYREX_Dist_Between_Two_Ldsk(t_ldsk *n1, t_ldsk *n2, t_tree *tree); +phydbl PHYREX_Lk_Range(t_dsk *young, t_dsk *old, t_tree *tree); +void PHYREX_Print_MultiTypeTree_Config_File(int n_sites, char *filename, t_tree *tree); +phydbl PHYREX_Effective_Density(t_tree *tree); +phydbl PHYREX_Generation_Length(t_tree *tree); +int PHYREX_Number_Of_Sampled_Demes(t_tree *tree); +phydbl PHYREX_Coalescence_Rate(t_tree *tree); +t_tree *PHYREX_Simulate_Independent_Loci(int n_otu, int n_loci, phydbl w, phydbl h, int r_seed); +phydbl Prob_Two_Random_Lineages_Coal_One_Event(phydbl w, phydbl h, phydbl mu, phydbl rad); +void PHYREX_Tree_To_Ldsk(t_tree *tree); +void PHYREX_Tree_To_Ldsk_Post(t_node *a, t_node *d, t_dsk *a_disk, t_tree *tree); +void PHYREX_Make_And_Connect_Tip_Disks(t_tree *tree); +void PHYREX_Simulate_Disk_And_Node_Times(t_tree *tree); +int PHYREX_Number_Of_Outgoing_Ldsks(t_dsk *disk); +t_ldsk *PHYREX_Random_Select_Outgoing_Ldsk(t_dsk *disk); +void PHYREX_Strip_And_Reconnect_Tree(t_tree *tree); +int PHYREX_Scale_All(phydbl scale, t_dsk *start_disk, t_tree *tree); +void PHYREX_Sample_Path(t_ldsk *young, t_ldsk *old, phydbl sd, phydbl *global_hr, t_tree *tree); +void PHYREX_Update_Lindisk_List_Range(t_dsk *young, t_dsk *old, t_tree *tree); +phydbl PHYREX_Lk_Core_Range(t_dsk *young, t_dsk *old, t_tree *tree); +int PHYREX_Number_Of_Intervals_Range(t_dsk *young, t_dsk *old, t_tree *tree); +void PHYREX_Oldest_Sampled_Disk(t_tree *tree); +phydbl PHYREX_Time_Of_Descendants(t_ldsk *ldsk, t_tree *tree); +phydbl PHYREX_Time_Of_Prev_Sampled_Disk(t_dsk *disk, t_tree *tree); +phydbl PHYREX_Time_Of_Next_Sampled_Disk(t_dsk *disk, t_tree *tree); +phydbl PHYREX_Lk_Time_Component(t_tree *tree); +phydbl PHYREX_Lk_Space_Component(t_tree *tree); +t_ldsk *PHYREX_Find_Ldsk_From_Id(char *id, t_ldsk *root); +t_geo_coord *PHYREX_Mean_Next_Loc(t_ldsk *ldsk, t_tree *tree); +phydbl PHYREX_Root_To_Tip_Realized_Sigsq(t_tree *tree); +phydbl PHYREX_Tip_To_Root_Realized_Sigsq(t_tree *tree); +phydbl PHYREX_Realized_Dispersal_Dist(t_tree *tree); +phydbl PHYREX_Tip_To_Root_Realized_Bis_Sigsq(t_tree *tree); +void PHYREX_Label_Nodes_With_Locations(t_tree *tree); +void PHYREX_Label_Edges(t_tree *tree); +phydbl PHYREX_Tip_To_Root_Realized_Ter_Sigsq(t_tree *tree); +void PHYREX_Integrated_Coal_Rate(t_ldsk *l0, t_ldsk *l1, phydbl T, t_tree *tree); +phydbl PHYREX_Prob_Two_Lineages_Coal(t_ldsk *l0, t_ldsk *l1, t_tree *tree); +void PHYREX_Sum_Coal_Rate(t_ldsk *l0, t_ldsk *l1, int n, t_tree *tree); + +#endif diff --git a/phyml/rates.c b/phyml/rates.c index 4b40b82..3f1b6b2 100644 --- a/phyml/rates.c +++ b/phyml/rates.c @@ -10,122 +10,708 @@ the GNU public licence. See http://www.opensource.org for details. */ - /* Routines for molecular clock trees and molecular dating */ -#include "spr.h" -#include "utilities.h" -#include "lk.h" -#include "optimiz.h" -#include "bionj.h" -#include "models.h" -#include "free.h" -#include "options.h" -#include "simu.h" -#include "eigen.h" -#include "pars.h" -#include "alrt.h" -#include "mc.h" -#include "m4.h" -#include "draw.h" + #include "rates.h" +#ifdef RWRAPPER +#include +#endif + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl RATES_Lk_Rates(t_tree *tree) +{ + + if(tree->eval_rlnL == NO) return UNLIKELY; + + tree->rates->c_lnL_rates = .0; + + RATES_Lk_Rates_Pre(tree->n_root,tree->n_root->v[2],NULL,tree); + RATES_Lk_Rates_Pre(tree->n_root,tree->n_root->v[1],NULL,tree); + + if(isnan(tree->rates->c_lnL_rates)) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + return tree->rates->c_lnL_rates; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Lk_Rates_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree) +{ + int i; + phydbl log_dens,mu_a,mu_d,r_a,r_d,dt_a,dt_d; + int n_a,n_d; + + log_dens = -1.; + + if(d->anc != a) + { + PhyML_Fprintf(stderr,"\n. d=%d d->anc=%d a=%d root=%d",d->num,d->anc->num,a->num,tree->n_root->num); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + assert(FALSE); + } + + dt_a = -1.; + if(a != tree->n_root) dt_a = tree->rates->nd_t[a->num] - tree->rates->nd_t[a->anc->num]; + + mu_a = tree->rates->br_r[a->num]; + r_a = tree->rates->nd_r[a->num]; + n_a = tree->rates->n_jps[a->num]; + + dt_d = FABS(tree->rates->nd_t[d->num] - tree->rates->nd_t[a->num]); + mu_d = tree->rates->br_r[d->num]; + r_d = tree->rates->nd_r[d->num]; + n_d = tree->rates->n_jps[d->num]; + + log_dens = RATES_Lk_Rates_Core(mu_a,mu_d,r_a,r_d,n_a,n_d,dt_a,dt_d,tree); + tree->rates->c_lnL_rates += log_dens; + + if(isnan(tree->rates->c_lnL_rates)) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + MCMC_Print_Param(tree->mcmc,tree); + Exit("\n"); + } + + tree->rates->triplet[a->num] += log_dens; + + + if(d->tax) return; + else + { + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + RATES_Lk_Rates_Pre(d,d->v[i],d->b[i],tree); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl RATES_Lk_Rates_Core(phydbl br_r_a, phydbl br_r_d, phydbl nd_r_a, phydbl nd_r_d, int n_a, int n_d, phydbl dt_a, phydbl dt_d, t_tree *tree) +{ + phydbl log_dens; + phydbl mean,sd; + phydbl min_r, max_r; + phydbl cr; + + cr = tree->rates->clock_r; + log_dens = UNLIKELY; + mean = sd = -1.; + min_r = tree->rates->min_rate; + max_r = tree->rates->max_rate; + + dt_d = MAX(0.5,dt_d); // We give only one decimal when printing out node heights. It is therefore a fair approximation + + switch(tree->rates->model) + { + case THORNE : + { + PhyML_Fprintf(stderr,"\n. Not implemented yet."); + assert(FALSE); + break; + } + case GUINDON : + { + int err; + + min_r = tree->rates->min_rate; + max_r = tree->rates->max_rate; + + nd_r_d = log(nd_r_d*cr); + nd_r_a = log(nd_r_a*cr); + min_r = log(min_r*cr); + max_r = log(max_r*cr); + + sd = sqrt(tree->rates->nu*dt_d); + mean = nd_r_a - .5*sd*sd; + + // log(density(log(Rate))) + log_dens = Log_Dnorm_Trunc(nd_r_d,mean,sd,min_r,max_r,&err); + // log(density(Rate)) + log_dens -= log(exp(nd_r_d)/cr); + + if(err) + { + PhyML_Fprintf(stderr,"\n. Run: %d",tree->mcmc->run); + PhyML_Fprintf(stderr,"\n. br_r_d=%f mean=%f sd=%f min_r=%f max_r=%f dt_d=%f",br_r_d,mean,sd,min_r,max_r,dt_d); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + break; + } + case LOGNORMAL : + { + int err; + phydbl log_br_r_d = log(br_r_d); + log_dens = Log_Dnorm_Trunc(log_br_r_d,0.0,tree->rates->nu,tree->rates->min_rate,tree->rates->max_rate,&err); + log_dens -= log_br_r_d; + break; + } + case STRICTCLOCK : + { + log_dens = 0.0; + break; + } + + default : + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + } + if(isnan(log_dens)) + { + PhyML_Fprintf(stderr,"\n. Run=%4d br_r_d=%f br_r_a=%f dt_d=%f dt_a=%f nu=%f log_dens=%G sd=%f mean=%f\n", + tree->mcmc->run, + br_r_d,br_r_a,dt_d,dt_a,tree->rates->nu,log_dens, + sd,mean); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + return log_dens; +} -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void RATES_Monte_Carlo_Mean_Rates(arbre *tree) +phydbl RATES_Lk_Change_One_Rate(t_node *d, phydbl new_rate, t_tree *tree) { - RATES_Monte_Carlo_Mean_Rates_Pre(tree->n_root,tree->n_root->v[0],NULL,1.0,tree); - RATES_Monte_Carlo_Mean_Rates_Pre(tree->n_root,tree->n_root->v[1],NULL,1.0,tree); + tree->rates->br_r[d->num] = new_rate; + RATES_Update_Triplet(d,tree); + RATES_Update_Triplet(d->anc,tree); + return(tree->rates->c_lnL_rates); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl RATES_Lk_Change_One_Time(t_node *n, phydbl new_t, t_tree *tree) +{ + if(n == tree->n_root) + { + PhyML_Fprintf(stderr,"\n. Moving the time of the root t_node is not permitted."); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + else + { + int i; + + tree->rates->nd_t[n->num] = new_t; + + RATES_Update_Triplet(n,tree); + + for(i=0;i<3;i++) + { + if(n->b[i] != tree->e_root) RATES_Update_Triplet(n->v[i],tree); + else RATES_Update_Triplet(tree->n_root,tree); + } + } + return(tree->rates->c_lnL_rates); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void RATES_Monte_Carlo_Mean_Rates_Pre(node *a, node *d, edge *b, phydbl curr_rate, arbre *tree) +void RATES_Update_Triplet(t_node *n, t_tree *tree) { - if(b) + phydbl curr_triplet,new_triplet; + phydbl dt0,dt1,dt2; + phydbl mu1_mu0,mu2_mu0; + phydbl mu0,mu1,mu2; + phydbl r0,r1,r2; + int n0,n1,n2; + int i; + t_node *v1,*v2; + + if(n->tax) return; + + curr_triplet = tree->rates->triplet[n->num]; + + dt0 = dt1 = dt2 = -100.0; + r0 = r1 = r2 = 0.0; + + if(n == tree->n_root) { - phydbl curr_t, next_t, mean_rate; - phydbl shape,exp; + phydbl log_dens; - /**/ - shape = 1.0; - /**/ + log_dens = 0.0; - mean_rate = curr_rate; - curr_t = a->t - Rexp(tree->rates->lexp[b->num]);; + dt0 = tree->rates->nd_t[tree->n_root->v[2]->num] - tree->rates->nd_t[tree->n_root->num]; + dt1 = tree->rates->nd_t[tree->n_root->v[1]->num] - tree->rates->nd_t[tree->n_root->num]; + mu0 = tree->rates->br_r[tree->n_root->v[2]->num]; + mu1 = tree->rates->br_r[tree->n_root->v[1]->num]; - while(curr_t > d->t) + r0 = tree->rates->nd_r[tree->n_root->v[2]->num]; + r1 = tree->rates->nd_r[tree->n_root->v[1]->num]; + + n0 = tree->rates->n_jps[tree->n_root->v[2]->num]; + n1 = tree->rates->n_jps[tree->n_root->v[1]->num]; + + switch(tree->rates->model) { - curr_rate = Rgamma(shape,tree->rates->br_r[b->num] / shape); - exp = Rexp(tree->rates->lexp[b->num]); - -/* printf("\n. curr_rate=%f mean_r=%f exp=%f curr_t=%f lim=%f", */ -/* curr_rate,mean_rate,exp,curr_t,d->t); */ + case COMPOUND_COR : case COMPOUND_NOCOR : + { + log_dens = RATES_Dmu(mu0,n0,dt0,tree->rates->nu,1./tree->rates->nu,tree->rates->lexp,0,1); + log_dens *= RATES_Dmu(mu1,n1,dt1,tree->rates->nu,1./tree->rates->nu,tree->rates->lexp,0,1); + log_dens = log(log_dens); + break; + } + case EXPONENTIAL : + { + log_dens = Dexp(mu0,tree->rates->lexp) * Dexp(mu1,tree->rates->lexp); + log_dens = log(log_dens); + break; + } + case LOGNORMAL : + { + log_dens = Dgamma(mu0,tree->rates->nu,1./tree->rates->nu) * Dgamma(mu1,tree->rates->nu,1./tree->rates->nu); + log_dens = log(log_dens); + break; + } + case THORNE : + { + int err; + phydbl mean0,sd0; + phydbl mean1,sd1; - next_t = curr_t - exp; - - if(next_t > d->t) - { - mean_rate = (1./(a->t - next_t)) * (mean_rate * (a->t - curr_t) + curr_rate * (curr_t - next_t)); - } - else - { - mean_rate = (1./(a->t - d->t)) * (mean_rate * (a->t - curr_t) + curr_rate * (curr_t - d->t)); - } + + sd0 = SQRT(tree->rates->nu*dt0); + mean0 = 1.0; + + sd1 = SQRT(tree->rates->nu*dt1); + mean1 = 1.0; - curr_t = next_t; + log_dens = + Log_Dnorm_Trunc(mu0,mean0,sd0,tree->rates->min_rate,tree->rates->max_rate,&err) + + Log_Dnorm_Trunc(mu1,mean1,sd1,tree->rates->min_rate,tree->rates->max_rate,&err); + + break; + } + case GUINDON : + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n. Not implemented yet.\n"); + break; + } + default : + { + Exit("\n. Model not implemented yet.\n"); + break; + } } + new_triplet = log_dens; - tree->rates->mc_mr[d->num][tree->rates->curr_mc_run] = mean_rate; -/* printf("\n. %3d %f %f",d->num,mean_rate,tree->rates->br_r[b->num]); */ + if(isnan(log_dens) || isinf(FABS(log_dens))) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + MCMC_Print_Param(tree->mcmc,tree); + Exit("\n"); + } } - - if(d->tax) return; else { - int i; - For(i,3) + mu0 = mu1 = mu2 = -1.; + n0 = n1 = n2 = -1; + + mu0 = tree->rates->br_r[n->num]; + dt0 = FABS(tree->rates->nd_t[n->num] - tree->rates->nd_t[n->anc->num]); + n0 = tree->rates->n_jps[n->num]; + r0 = tree->rates->nd_r[n->num]; + + v1 = v2 = NULL; + for(i=0;i<3;i++) { - if((d->v[i] != a) && (d->b[i] != tree->e_root)) + if((n->v[i] != n->anc) && (n->b[i] != tree->e_root)) { - RATES_Monte_Carlo_Mean_Rates_Pre(d,d->v[i],d->b[i],curr_rate,tree); + if(!v1) + { + v1 = n->v[i]; + mu1 = tree->rates->br_r[v1->num]; + dt1 = FABS(tree->rates->nd_t[v1->num] - tree->rates->nd_t[n->num]); + n1 = tree->rates->n_jps[v1->num]; + r1 = tree->rates->nd_r[v1->num]; + } + else + { + v2 = n->v[i]; + mu2 = tree->rates->br_r[v2->num]; + dt2 = FABS(tree->rates->nd_t[v2->num] - tree->rates->nd_t[n->num]); + n2 = tree->rates->n_jps[v2->num]; + r2 = tree->rates->nd_r[v2->num]; + } } } - } - return; + + mu1_mu0 = RATES_Lk_Rates_Core(mu0,mu1,r0,r1,n0,n1,dt0,dt1,tree); + mu2_mu0 = RATES_Lk_Rates_Core(mu0,mu2,r0,r1,n0,n2,dt0,dt2,tree); + + new_triplet = mu1_mu0 + mu2_mu0; + } + + tree->rates->c_lnL_rates = tree->rates->c_lnL_rates + new_triplet - curr_triplet; + tree->rates->triplet[n->num] = new_triplet; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + + +phydbl RATES_Compound_Core(phydbl mu1, phydbl mu2, int n1, int n2, phydbl dt1, phydbl dt2, phydbl alpha, phydbl beta, phydbl lexp, phydbl eps, int approx) +{ + if((n1 > -1) && (n2 > -1)) + { + return RATES_Compound_Core_Joint(mu1,mu2,n1,n2,dt1,dt2,alpha,beta,lexp,eps,approx); + } + else + { + return RATES_Compound_Core_Marginal(mu1,mu2,dt1,dt2,alpha,beta,lexp,eps,approx); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl RATES_Compound_Core_Marginal(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, phydbl alpha, phydbl beta, phydbl lexp, phydbl eps, int approx) +{ + phydbl p0,p1,v0,v1,v2; + phydbl dmu1; + int equ; + phydbl dens; + + v0 = v1 = v2 = 0.0; + + /* Probability of 0 and 1 jumps */ + p0 = Dpois(0,lexp*(dt2+dt1),NO); + p1 = Dpois(1,lexp*(dt2+dt1),NO); + + dmu1 = RATES_Dmu(mu1,-1,dt1,alpha,beta,lexp,0,0); + + /* Are the two rates equal ? */ + equ = 0; + if(FABS(mu1-mu2) < eps) equ = 1; + + /* No jump */ + if(equ) + { + v0 = 1.0*Dgamma(mu1,alpha,beta)/dmu1; + /* Rprintf("\n. mu1=%f mu2=%f",mu1,mu2); */ + } + else + { + v0 = 1.E-100; + } + + /* One jump */ + v1 = RATES_Dmu1_And_Mu2_One_Jump_Two_Intervals(mu1,mu2,dt1,dt2,alpha,beta); + v1 /= dmu1; + + /* Two jumps and more (approximation) */ + if(approx == 1) + { + v2 = + RATES_Dmu(mu1,-1,dt1,alpha,beta,lexp,0,0)*RATES_Dmu(mu2,-1,dt2,alpha,beta,lexp,0,0) - + Dpois(0,lexp*dt1,NO) * Dpois(0,lexp*dt2,NO) * + Dgamma(mu1,alpha,beta) * Dgamma(mu2,alpha,beta); + } + else + { + v2 = + RATES_Dmu_One(mu1,dt1,alpha,beta,lexp) * + RATES_Dmu_One(mu2,dt2,alpha,beta,lexp); + + v2 += Dpois(0,lexp*dt1,NO)*Dgamma(mu1,alpha,beta)*RATES_Dmu(mu2,-1,dt2,alpha,beta,lexp,1,0); + v2 += Dpois(0,lexp*dt2,NO)*Dgamma(mu2,alpha,beta)*RATES_Dmu(mu1,-1,dt1,alpha,beta,lexp,1,0); + + } +/* PhyML_Printf("\n. %f %f %f %f %f ",mu1,mu2,dt1,dt2,v2); */ + v2 /= dmu1; + + dens = p0*v0 + p1*v1 + v2; +/* dens = p1*v1 + v2; */ + /* dens = p1*v1 + v2; */ + /* dens = v0; */ +/* dens *= dmu1; */ + + if(dens < SMALL) + { + PhyML_Printf("\n. dens=%12G mu1=%12G mu2=%12G dt1=%12G dt2=%12G lexp=%12G alpha=%f v0=%f v1=%f v2=%f p0=%f p1=%f p2=%f", + dens, + mu1,mu2,dt1,dt2, + lexp, + alpha, + v0,v1,v2, + p0,p1,1.-p0-p1); + } + + return dens; + } -/*********************************************************/ +/**********************************************************/ -void RATES_Print_Rates(arbre *tree) +phydbl RATES_Compound_Core_Joint(phydbl mu1, phydbl mu2, int n1, int n2, phydbl dt1, phydbl dt2, + phydbl alpha, phydbl beta, phydbl lexp, phydbl eps, int approx) { - RATES_Print_Rates_Pre(tree->n_root,tree->n_root->v[0],NULL,tree); + phydbl density; + phydbl dmu1; + + + if(n1 < 0 || n2 < 0) + { + PhyML_Fprintf(stderr,"\n. n1=%d n2=%d",n1,n2); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + dmu1 = RATES_Dmu(mu1,n1,dt1,alpha,beta,lexp,0,0); + + if((n1 < 0) || (n2 < 0)) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if((n1 == 0) && (n2 == 0)) + { + if(FABS(mu1-mu2) < eps) { density = Dgamma(mu1,alpha,beta); } + else { density = 1.E-70; } + } + else if((n1 == 0) && (n2 == 1)) + { + density = + Dgamma(mu1,alpha,beta) * + RATES_Dmu1_Given_V_And_N(mu2,mu1,1,dt2,alpha,beta); + } + else if((n1 == 1) && (n2 == 0)) + { + density = + Dgamma(mu2,alpha,beta) * + RATES_Dmu1_Given_V_And_N(mu1,mu2,1,dt1,alpha,beta); + } + else /* independent */ + { + density = + RATES_Dmu(mu1,n1,dt1,alpha,beta,lexp,0,0) * + RATES_Dmu(mu2,n2,dt2,alpha,beta,lexp,0,0); + } + + density /= dmu1; + + density *= Dpois(n2,dt2*lexp,NO); + + if(density < 1.E-70) density = 1.E-70; + +/* PhyML_Printf("\n. density = %15G mu1=%3.4f mu2=%3.4f dt1=%3.4f dt2=%3.4f n1=%2d n2=%2d",density,mu1,mu2,dt1,dt2,n1,n2); */ + return density; +} + +/**********************************************************/ + +void RATES_Print_Triplets(t_tree *tree) +{ + int i; + For(i,2*tree->n_otu-1) PhyML_Printf("\n. Node %3d t=%f",i,tree->rates->triplet[i]); +} + + +/**********************************************************/ + +void RATES_Print_Rates(t_tree *tree) +{ + RATES_Print_Rates_Pre(tree->n_root,tree->n_root->v[2],NULL,tree); RATES_Print_Rates_Pre(tree->n_root,tree->n_root->v[1],NULL,tree); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void RATES_Print_Rates_Pre(node *a, node *d, edge *b, arbre *tree) +void RATES_Copy_Rate_Struct(t_rate *from, t_rate *to, int n_otu) { + int i; - if(b) + to->lexp = from->lexp; + to->alpha = from->alpha; + to->less_likely = from->less_likely; + + to->birth_rate = from->birth_rate; + to->birth_rate_min = from->birth_rate_min; + to->birth_rate_max = from->birth_rate_max; + to->birth_rate_pivot = from->birth_rate_pivot; + + to->death_rate = from->death_rate; + to->death_rate_min = from->death_rate_min; + to->death_rate_max = from->death_rate_max; + to->death_rate_pivot = from->death_rate_pivot; + + to->nu = from->nu; + to->min_nu = from->min_nu; + to->max_nu = from->max_nu; + + to->min_rate = from->min_rate; + to->max_rate = from->max_rate; + + to->c_lnL1 = from->c_lnL1; + to->c_lnL2 = from->c_lnL2; + + to->c_lnL_rates = from->c_lnL_rates; + to->c_lnL_times = from->c_lnL_times; + to->c_lnL_jps = from->c_lnL_jps; + + to->clock_r = from->clock_r; + to->min_clock = from->min_clock; + to->max_clock = from->max_clock; + + to->lbda_nu = from->lbda_nu; + to->min_dt = from->min_dt; + to->step_rate = from->step_rate; + to->true_tree_size = from->true_tree_size; + to->p_max = from->p_max; + to->norm_fact = from->norm_fact; + + to->adjust_rates = from->adjust_rates; + to->use_rates = from->use_rates; + to->bl_from_rt = from->bl_from_rt; + to->approx = from->approx; + to->model = from->model; + to->is_allocated = from->is_allocated; + to->met_within_gibbs = from->met_within_gibbs; + + to->update_mean_l = from->update_mean_l; + to->update_cov_l = from->update_cov_l; + + to->nd_t_recorded = from->nd_t_recorded; + to->br_r_recorded = from->br_r_recorded; + + to->log_K_cur = from->log_K_cur; + to->cur_comb_numb = from->cur_comb_numb; + to->update_time_norm_const = from->update_time_norm_const; + + for(i=0;i<2*n_otu-1;++i) to->nd_r[i] = from->nd_r[i]; + for(i=0;i<2*n_otu-1;++i) to->br_r[i] = from->br_r[i]; + for(i=0;i<2*n_otu-1;++i) to->buff_br_r[i] = from->buff_br_r[i]; + for(i=0;i<2*n_otu-1;++i) to->buff_nd_r[i] = from->buff_nd_r[i]; + for(i=0;i<2*n_otu-1;++i) to->true_r[i] = from->true_r[i]; + for(i=0;i<2*n_otu-1;++i) to->nd_t[i] = from->nd_t[i]; + for(i=0;i<2*n_otu-1;++i) to->buff_t[i] = from->buff_t[i]; + for(i=0;i<2*n_otu-1;++i) to->true_t[i] = from->true_t[i]; + for(i=0;i<2*n_otu-1;++i) to->t_mean[i] = from->t_mean[i]; + for(i=0;i<2*n_otu-1;++i) to->t_prior[i] = from->t_prior[i]; + for(i=0;i<2*n_otu-1;++i) to->t_prior_min[i] = from->t_prior_min[i]; + for(i=0;i<2*n_otu-1;++i) to->t_prior_max[i] = from->t_prior_max[i]; + for(i=0;i<2*n_otu-1;++i) to->t_floor[i] = from->t_floor[i]; + for(i=0;i<2*n_otu-1;++i) to->t_rank[i] = from->t_rank[i]; + for(i=0;i<2*n_otu-1;++i) to->t_has_prior[i] = from->t_has_prior[i]; + for(i=0;i<2*n_otu-2;++i) to->dens[i] = from->dens[i]; + for(i=0;i<2*n_otu-1;++i) to->triplet[i] = from->triplet[i]; + for(i=0;i<2*n_otu-1;++i) to->n_jps[i] = from->n_jps[i]; + for(i=0;i<2*n_otu-2;++i) to->t_jps[i] = from->t_jps[i]; + For(i,(2*n_otu-2)*(2*n_otu-2)) to->cov_l[i] = from->cov_l[i]; + For(i,(2*n_otu-2)*(2*n_otu-2)) to->invcov[i] = from->invcov[i]; + for(i=0;i<2*n_otu-2;++i) to->mean_l[i] = from->mean_l[i]; + for(i=0;i<2*n_otu-2;++i) to->ml_l[i] = from->ml_l[i]; + for(i=0;i<2*n_otu-2;++i) to->cur_l[i] = from->cur_l[i]; + For(i,2*n_otu-3) to->u_ml_l[i] = from->u_ml_l[i]; + For(i,2*n_otu-3) to->u_cur_l[i] = from->u_cur_l[i]; + For(i,(2*n_otu-2)*(2*n_otu-2)) to->cov_r[i] = from->cov_r[i]; + for(i=0;i<2*n_otu-2;++i) to->cond_var[i] = from->cond_var[i]; + for(i=0;i<2*n_otu-2;++i) to->mean_r[i] = from->mean_r[i]; + for(i=0;i<2*n_otu-1;++i) to->mean_t[i] = from->mean_t[i]; + For(i,(2*n_otu-1)*(2*n_otu-1)) to->lca[i] = from->lca[i]; + For(i,(2*n_otu-2)*(2*n_otu-2)) to->reg_coeff[i] = from->reg_coeff[i]; + For(i,(2*n_otu-2)*(6*n_otu-9)) to->trip_reg_coeff[i] = from->trip_reg_coeff[i]; + For(i,(2*n_otu-2)*9) to->trip_cond_cov[i] = from->trip_cond_cov[i]; + For(i,2*n_otu) to->_2n_vect1[i] = from->_2n_vect1[i]; + For(i,2*n_otu) to->_2n_vect2[i] = from->_2n_vect2[i]; + For(i,2*n_otu) to->_2n_vect3[i] = from->_2n_vect3[i]; + For(i,2*n_otu) to->_2n_vect4[i] = from->_2n_vect4[i]; + For(i,2*n_otu) to->_2n_vect5[i] = from->_2n_vect5[i]; + For(i,4*n_otu*n_otu) to->_2n2n_vect1[i] = from->_2n2n_vect1[i]; + For(i,4*n_otu*n_otu) to->_2n2n_vect2[i] = from->_2n2n_vect2[i]; + for(i=0;i<2*n_otu-1;++i) to->br_do_updt[i] = from->br_do_updt[i]; + for(i=0;i<2*n_otu-1;++i) to->cur_gamma_prior_mean[i] = from->cur_gamma_prior_mean[i]; + for(i=0;i<2*n_otu-1;++i) to->cur_gamma_prior_var[i] = from->cur_gamma_prior_var[i]; + for(i=0;i<2*n_otu-1;++i) to->n_tips_below[i] = from->n_tips_below[i]; + for(i=0;i<2*n_otu-1;++i) to->time_slice_lims[i] = from->time_slice_lims[i]; + for(i=0;i<2*n_otu-1;++i) to->n_time_slice_spans[i] = from->n_time_slice_spans[i]; + for(i=0;i<2*n_otu-1;++i) to->curr_slice[i] = from->curr_slice[i]; + for(i=0;i<2*n_otu-1;++i) to->has_survived[i] = from->has_survived[i]; + for(i=0;i<2*n_otu-1;++i) to->survival_rank[i] = from->survival_rank[i]; + for(i=0;i<2*n_otu-1;++i) to->survival_dur[i] = from->survival_dur[i]; + for(i=0;i<2*n_otu-1;++i) to->calib_prob[i] = from->calib_prob[i]; + for(i=0;i<2*n_otu-1;++i) to->t_prior_min_ori[i] = from->t_prior_max_ori[i]; + For(i,n_otu*n_otu) to->times_partial_proba[i] = from->times_partial_proba[i]; + For(i,n_otu*n_otu) to->numb_calib_chosen[i] = from->numb_calib_chosen[i]; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Duplicate_Calib_Struct(t_tree *from, t_tree *to) +{ + int i,j; + + to->rates->n_cal = from->rates->n_cal; + for(i=0;irates->n_cal;i++) { - printf("\n. Edge %3d m_rate = %10f r_rate = %10f t_a = %15f t_d = %15f", - b->num, - tree->rates->mean_r, - tree->rates->br_r[b->num], - a->t,d->t); + to->rates->a_cal[i] = Duplicate_Calib(from->rates->a_cal[i]); + for(j=0;jrates->a_cal[i]->clade_list_size;j++) + Init_Target_Tip(to->rates->a_cal[i]->clade_list[j],to); } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Print_Rates_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree) +{ + if((d == tree->n_root->v[2] && d->tax) || (d == tree->n_root->v[1] && d->tax)) + PhyML_Printf("\n. a=%3d ++d=%3d rate=%12f t_left=%12f t_rght=%12f ml=%12f l=%12f %12f", + a->num,d->num, + tree->rates->br_r[d->num], + tree->rates->nd_t[a->num],tree->rates->nd_t[d->num], + tree->rates->ml_l[d->num], + tree->rates->cur_l[d->num], + (tree->rates->nd_t[d->num]-tree->rates->nd_t[a->num])*tree->rates->clock_r*tree->rates->br_r[d->num]); + + else if((d == tree->n_root->v[2]) || (d == tree->n_root->v[1])) + PhyML_Printf("\n. a=%3d __d=%3d rate=%12f t_left=%12f t_rght=%12f ml=%12f l=%12f %12f", + a->num,d->num, + tree->rates->br_r[d->num], + tree->rates->nd_t[a->num],tree->rates->nd_t[d->num], + tree->rates->ml_l[d->num], + tree->rates->cur_l[d->num], + (tree->rates->nd_t[d->num]-tree->rates->nd_t[a->num])*tree->rates->clock_r*tree->rates->br_r[d->num]); + else + PhyML_Printf("\n. a=%3d d=%3d rate=%12f t_left=%12f t_rght=%12f ml=%12f l=%12f %12f", + a->num,d->num, + tree->rates->br_r[d->num], + tree->rates->nd_t[a->num],tree->rates->nd_t[d->num], + tree->rates->ml_l[d->num], + tree->rates->cur_l[d->num], + (tree->rates->nd_t[d->num]-tree->rates->nd_t[a->num])*tree->rates->clock_r*tree->rates->br_r[d->num]); + if(d->tax) return; else { int i; - For(i,3) + for(i=0;i<3;i++) { if((d->v[i] != a) && (d->b[i] != tree->e_root)) { @@ -135,42 +721,3076 @@ void RATES_Print_Rates_Pre(node *a, node *d, edge *b, arbre *tree) } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -trate *RATES_Make_Rate_Struct(arbre *tree) + +phydbl RATES_Average_Rate(t_tree *tree) { - trate *rates; + int i; + phydbl sum; + sum = 0.0; + for(i=0;i<2*tree->n_otu-2;++i) sum += tree->rates->br_r[i]; + return sum/(2*tree->n_otu-2); +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - rates = (trate *)mCalloc(1,sizeof(trate)); - rates->br_r = (phydbl *)mCalloc(2*tree->n_otu-3,sizeof(phydbl)); - rates->lexp = (phydbl *)mCalloc(2*tree->n_otu-3,sizeof(phydbl)); - rates->mc_mr = (phydbl **)mCalloc(2*tree->n_otu-1,sizeof(phydbl *)); +phydbl RATES_Average_Substitution_Rate(t_tree *tree) +{ + phydbl l,dt; + int i; - return rates; + l = 0.0; + dt = 0.0; + for(i=0;i<2*tree->n_otu-1;++i) + { + if(tree->a_nodes[i] != tree->n_root) + { + dt += FABS(tree->rates->nd_t[tree->a_nodes[i]->num] - tree->rates->nd_t[tree->a_nodes[i]->anc->num]); + l += tree->rates->cur_l[tree->a_nodes[i]->num]; + } + } + + return(l/dt); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void RATES_Init_Rate_Struct(trate *rates, arbre *tree) +phydbl RATES_Check_Mean_Rates_True(t_tree *tree) { + phydbl sum; int i; + + sum = 0.0; + for(i=0;i<2*tree->n_otu-2;++i) sum += tree->rates->true_r[i]; + return(sum/(phydbl)(2*tree->n_otu-2)); +} - rates->n_mc_runs = 500; - rates->mean_r = 0.00001; - rates->curr_mc_run = 0; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,2*tree->n_otu-3) +int RATES_Check_Node_Times(t_tree *tree) +{ + int err; + err = NO; + RATES_Check_Node_Times_Pre(tree->n_root,tree->n_root->v[2],&err,tree); + RATES_Check_Node_Times_Pre(tree->n_root,tree->n_root->v[1],&err,tree); + return err; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Check_Node_Times_Pre(t_node *a, t_node *d, int *err, t_tree *tree) +{ + if((tree->rates->nd_t[d->num] < tree->rates->nd_t[a->num]) || (FABS(tree->rates->nd_t[d->num] - tree->rates->nd_t[a->num]) < 1.E-20)) + { + PhyML_Printf("\n. a->t=%f d->t=%f",tree->rates->nd_t[a->num],tree->rates->nd_t[d->num]); + PhyML_Printf("\n. a->t_prior_min=%f a->t_prior_max=%f",tree->rates->t_prior_min[a->num],tree->rates->t_prior_max[a->num]); + PhyML_Printf("\n. d->t_prior_min=%f d->t_prior_max=%f",tree->rates->t_prior_min[d->num],tree->rates->t_prior_max[d->num]); + *err = YES; + } + if(d->tax) return; + else + { + int i; + + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + RATES_Check_Node_Times_Pre(d,d->v[i],err,tree); + } +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Bracket_N_Jumps(int *up, int *down, phydbl param) +{ + phydbl cdf,eps,a,b,c; + int step; + + step = 10; + eps = 1.E-10; + cdf = 0.0; + c = 1; + + while(cdf < 1.-eps) + { + c = (int)FLOOR(c * step); + cdf = Ppois(c,param); + } + + a = 0.0; + b = (c-a)/2.; + step = 0; + do + { + step++; + cdf = Ppois(b,param); + if(cdf < eps) a = b; + else + { + break; + } + b = (c-a)/2.; + } + while(step < 1000); + + if(step == 1000) + { + PhyML_Fprintf(stderr,"\n. a=%f b=%f c=%f param=%f",a,b,c,param); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + *up = c; + *down = a; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* + mu : average rate of the time period dt + dt : time period to be considered + a : rate at a given time point is gamma distributed. a is the shape parameter + b : rate at a given time point is gamma distributed. b is the scale parameter + lexp : the number of rate switches is Poisson distributed with parameter lexp * dt +*/ +/* compute f(mu;dt,a,b,lexp), the probability density of mu. We need to integrate over the + possible number of jumps (n) during the time interval dt */ +phydbl RATES_Dmu(phydbl mu, int n_jumps, phydbl dt, phydbl a, phydbl b, phydbl lexp, int min_n, int jps_dens) +{ + if(n_jumps < 0) /* Marginal, i.e., the number of jumps is not fixed */ + { + phydbl var,cumpoissprob,dens,mean,poissprob,ab2,gammadens,lexpdt; + int n,up,down; + + var = 0.0; + cumpoissprob = 0.0; + dens = 0.0; + n = 0; + mean = a*b; + ab2 = a*b*b; + lexpdt = lexp*dt; + + RATES_Bracket_N_Jumps(&up,&down,lexpdt); + For(n,MAX(down,min_n)-1) cumpoissprob += Dpois(n,lexpdt,NO); + + for(n=MAX(down,min_n);n 1.-1.E-04) break; + } + + if(dens < 1.E-70) dens = 1.E-70; + + return(dens); + } + else /* Joint, i.e., return P(mu | dt, n_jumps) */ + { + phydbl mean, var, density; + + + mean = 1.0; + var = (2./(n_jumps+2.))*a*b*b; + + if(jps_dens) + density = Dgamma_Moments(mu,mean,var) * Dpois(n_jumps,dt*lexp,NO); + else + density = Dgamma_Moments(mu,mean,var); + + if(density < 1.E-70) density = 1.E-70; + + return density; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl RATES_Dmu_One(phydbl mu, phydbl dt, phydbl a, phydbl b, phydbl lexp) +{ + phydbl var,cumpoissprob,dens,mean,poissprob,ab2,gammadens,lexpdt; + int n,up,down; + + var = 0.0; + cumpoissprob = 0.0; + dens = 0.0; + n = 0; + mean = a*b; + ab2 = a*b*b; + lexpdt = lexp*dt; + + if(dt < 0.0) + { + PhyML_Fprintf(stderr,"\n. dt=%f",dt); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if(lexpdt < SMALL) + { + PhyML_Fprintf(stderr,"\n. lexpdt=%G lexp=%G dt=%G",lexpdt,lexp,dt); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if(mu < 1.E-10) + { + PhyML_Fprintf(stderr,"\n. mu=%G",mu); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + RATES_Bracket_N_Jumps(&up,&down,lexpdt); + + For(n,MAX(1,down)-1) cumpoissprob += Dpois(n,lexpdt,NO); + + for(n=MAX(1,down);nbr_r[i] = 1.0; - rates->lexp[i] = 0.001; + poissprob = Dpois(n,lexpdt,NO); /* probability of having n jumps */ + var = (n/((n+1)*(n+1)*(n+2)))*(POW(1-a*b,2) + 2/(n+1)*ab2) + 2*n*n*ab2/POW(n+1,3); + gammadens = Dgamma_Moments(mu,mean,var); + dens += poissprob * gammadens; + cumpoissprob += poissprob; + if(cumpoissprob > 1.-1.E-06) break; } - For(i,2*tree->n_otu-1) - rates->mc_mr[i] = (phydbl *)mCalloc(rates->n_mc_runs,sizeof(phydbl)); + return(dens); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Given the times of nodes a (ta) and d (td), the shape of the gamma distribution of instantaneous + rates, the parameter of the exponential distribution of waiting times between rate jumps and the + instantaneous rate at t_node a, this function works out an expected number of (amino-acids or + nucleotide) substitutions per site. +*/ +void RATES_Expect_Number_Subst(phydbl t_beg, phydbl t_end, phydbl r_beg, int *n_jumps, phydbl *mean_r, phydbl *r_end, t_rate *rates, t_tree *tree) +{ + phydbl curr_r, curr_t, next_t; + + switch(rates->model) + { + case COMPOUND_COR:case COMPOUND_NOCOR: + { + /* Compound Poisson */ + if(rates->model == COMPOUND_COR) + { + curr_r = r_beg; + *mean_r = r_beg; + } + else + { + curr_r = Rgamma(rates->nu,1./rates->nu);; + *mean_r = curr_r; + } + + curr_t = t_beg + Rexp(rates->lexp); /* Exponentially distributed waiting times */ + next_t = curr_t; + + *n_jumps = 0; + while(curr_t < t_end) + { + curr_r = Rgamma(rates->nu,1./rates->nu); /* Gamma distributed random instantaneous rate */ + + (*n_jumps)++; + + next_t = curr_t + Rexp(rates->lexp); + + if(next_t < t_end) + { + *mean_r = (1./(next_t - t_beg)) * (*mean_r * (curr_t - t_beg) + curr_r * (next_t - curr_t)); + } + else + { + *mean_r = (1./(t_end - t_beg)) * (*mean_r * (curr_t - t_beg) + curr_r * (t_end - curr_t)); + } + curr_t = next_t; + } + + /* PhyML_Printf("\n. [%3d %f %f]",*n_jumps,*mean_r,r_beg); */ + + if(*mean_r < rates->min_rate) *mean_r = rates->min_rate; + if(*mean_r > rates->max_rate) *mean_r = rates->max_rate; + + *r_end = curr_r; + break; + } + case EXPONENTIAL: + { + *mean_r = Rexp(rates->nu); + + if(*mean_r < rates->min_rate) *mean_r = rates->min_rate; + if(*mean_r > rates->max_rate) *mean_r = rates->max_rate; + + *r_end = *mean_r; + break; + } + case LOGNORMAL: + { + *mean_r = Rgamma(rates->nu,1./rates->nu); + if(*mean_r < rates->min_rate) *mean_r = rates->min_rate; + if(*mean_r > rates->max_rate) *mean_r = rates->max_rate; + + *r_end = *mean_r; + break; + } + case THORNE: + { + phydbl sd,mean; + int err; + + sd = SQRT(rates->nu*FABS(t_beg-t_end)); + mean = r_beg; + + *mean_r = Rnorm_Trunc(mean,sd,rates->min_rate,rates->max_rate,&err); + + if(err) PhyML_Printf("\n. %s %d %d",__FILE__,__LINE__,tree->mcmc->run); + *r_end = *mean_r; + break; + } + default: + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n. Model not implemented yet.\n"); + break; + } + } } + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Get_Mean_Rates_Pre(t_node *a, t_node *d, t_edge *b, phydbl r_a, t_tree *tree) +{ + phydbl a_t,d_t; + phydbl mean_r; + int n_jumps; + phydbl r_d; + + a_t = tree->rates->nd_t[a->num]; + d_t = tree->rates->nd_t[d->num]; + + mean_r = -1.; + n_jumps = -1; + r_d = -1.; + RATES_Expect_Number_Subst(a_t,d_t,r_a,&n_jumps,&mean_r,&r_d,tree->rates,tree); + + tree->rates->br_r[d->num] = mean_r; + tree->rates->true_r[d->num] = mean_r; + tree->rates->t_jps[d->num] = n_jumps; + + + /* Move to the next branches */ + if(d->tax) return; + else + { + int i; + + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + RATES_Get_Mean_Rates_Pre(d,d->v[i],d->b[i],r_d,tree); + } + } + } + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Random_Branch_Lengths(t_tree *tree) +{ + phydbl r0; + + r0 = 1.0; + + tree->rates->br_r[tree->n_root->num] = r0; + + RATES_Get_Mean_Rates_Pre(tree->n_root,tree->n_root->v[2],NULL,r0,tree); + RATES_Get_Mean_Rates_Pre(tree->n_root,tree->n_root->v[1],NULL,r0,tree); + +/* RATES_Normalise_Rates(tree); */ + + RATES_Update_Cur_Bl(tree); + RATES_Initialize_True_Rates(tree); + + tree->n_root_pos = + tree->rates->cur_l[tree->n_root->v[2]->num] / + (tree->rates->cur_l[tree->n_root->v[2]->num] + tree->rates->cur_l[tree->n_root->v[1]->num]); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Set_Node_Times(t_tree *tree) +{ + RATES_Set_Node_Times_Pre(tree->n_root,tree->n_root->v[2],tree); + RATES_Set_Node_Times_Pre(tree->n_root,tree->n_root->v[1],tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Init_Triplets(t_tree *tree) +{ + int i; + For(i,2*tree->n_otu-1) tree->rates->triplet[i] = 0.0; +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Set_Node_Times_Pre(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax) return; + else + { + t_node *v1, *v2; /* the two sons of d */ + phydbl t_sup, t_inf; + int i; + + v1 = v2 = NULL; + for(i=0;i<3;i++) if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(!v1) v1 = d->v[i]; + else v2 = d->v[i]; + } + + t_inf = MIN(tree->rates->nd_t[v1->num],tree->rates->nd_t[v2->num]); + t_sup = tree->rates->nd_t[a->num]; + + if(t_sup > t_inf) + { + PhyML_Fprintf(stderr,"\n. t_sup = %f t_inf = %f",t_sup,t_inf); + PhyML_Fprintf(stderr,"\n. Run = %d",tree->mcmc->run); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if(tree->rates->nd_t[d->num] > t_inf) + { + tree->rates->nd_t[d->num] = t_inf; + PhyML_Printf("\n. Time for t_node %d is larger than should be. Set it to %f",d->num,tree->rates->nd_t[d->num]); + } + else if(tree->rates->nd_t[d->num] < t_sup) + { + tree->rates->nd_t[d->num] = t_sup; + PhyML_Printf("\n. Time for t_node %d is lower than should be. Set it to %f",d->num,tree->rates->nd_t[d->num]); + } + + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + RATES_Set_Node_Times_Pre(d,d->v[i],tree); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + + +phydbl RATES_Dmu1_And_Mu2_One_Jump_Two_Intervals(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, phydbl alpha, phydbl beta) +{ + phydbl dens; + + if(mu2 < 1.E-10) + { + PhyML_Fprintf(stderr,"\n. mu2=%G",mu2); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if(mu1 < 1.E-10) + { + PhyML_Fprintf(stderr,"\n. mu2=%G",mu1); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + dens = + ((dt1/(dt1+dt2)) * RATES_Dmu1_Given_V_And_N(mu1,mu2,1,dt1,alpha,beta) * Dgamma(mu2,alpha,beta)) + + ((dt2/(dt1+dt2)) * RATES_Dmu1_Given_V_And_N(mu2,mu1,1,dt2,alpha,beta) * Dgamma(mu1,alpha,beta)); + + return dens; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl RATES_Dmu1_Given_V_And_N(phydbl mu1, phydbl v, int n, phydbl dt1, phydbl a, phydbl b) +{ + phydbl lbda,dens,h,u; + phydbl mean,var; + int n_points,i; + phydbl ndb; + phydbl end, beg; + + n_points = 20; + + end = MIN(mu1/v-0.01,0.99); + beg = 0.01; + + dens = 0.0; + + if(end > beg) + { + mean = a*b; + var = a*b*b*2./(n+1.); + ndb = (phydbl)n/dt1; + + h = (end - beg) / (phydbl)n_points; + + lbda = beg; + for(i=0;i 1.-1.E-6) break; + } + + if(density < 0.0) + { + PhyML_Fprintf(stderr,"\n. density=%f cmpoiss = %f i=%d n_min=%d mu1=%f mu2=%f dt1=%f dt2=%f", + density,cumpoiss,i,n_min,mu1,mu2,dt1,dt2); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + return(density); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Joint density of mu1 and mu2 given the number of jumps (n) in the interval dt1+dt2, which are considered + as independant. Hence, for n jumps occuring in dt1+dt2, the number of jumps occuring in dt1 and dt2 are + n and 0, or n-1 and 1, or n-2 and 2 ... or 0 and n. This function sums over all these scenarios, with + weights corresponding to the probability of each partitition. + */ + +phydbl RATES_Dmu2_And_Mu1_Given_N(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, int n, phydbl a, phydbl b, phydbl lexp) + { + phydbl density,cumpoiss,poiss,abb,ab,lognf,logdt1,logdt2,nlogdt; + int i; + + density = 0.0; + abb = a*b*b; + ab = a*b; + cumpoiss = 0.0; + poiss = 0.0; + lognf = LnFact(n); + logdt1 = log(dt1); + logdt2 = log(dt2); + nlogdt = n*log(dt1+dt2); + + For(i,n+1) + { + poiss = lognf - LnFact(i) - LnFact(n-i) + i*logdt1 + (n-i)*logdt2 - nlogdt; + poiss = exp(poiss); + cumpoiss = cumpoiss + poiss; + + if(mu2 < 1.E-10) + { + PhyML_Fprintf(stderr,"\n. mu2=%f",mu2); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if(mu1 < 1.E-10) + { + PhyML_Fprintf(stderr,"\n. mu1=%f",mu1); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + + density = density + poiss * Dgamma_Moments(mu2,ab,2./((n-i)+2.)*abb) * Dgamma_Moments(mu1,ab,2./(i+2.)*abb); + if(cumpoiss > 1.-1.E-6) break; + } + + return(density); + } + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Initialize_True_Rates(t_tree *tree) +{ + int i; + For(i,2*tree->n_otu-2) tree->rates->true_r[i] = tree->rates->br_r[i]; +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Get_Rates_From_Bl(t_tree *tree) +{ + phydbl dt,cr; + t_node *left, *rght; + int i; + + dt = -1.0; + cr = tree->rates->clock_r; + + if(tree->n_root) + { + dt = FABS(tree->rates->nd_t[tree->n_root->num] - tree->rates->nd_t[tree->n_root->v[2]->num]); + tree->rates->br_r[tree->n_root->v[2]->num] = 0.5 * tree->e_root->l->v / (dt*cr); + dt = FABS(tree->rates->nd_t[tree->n_root->num] - tree->rates->nd_t[tree->n_root->v[1]->num]); + tree->rates->br_r[tree->n_root->v[1]->num] = 0.5 * tree->e_root->l->v / (dt*cr); + } + + + For(i,2*tree->n_otu-3) + { + if(tree->a_edges[i] != tree->e_root) + { + left = tree->a_edges[i]->left; + rght = tree->a_edges[i]->rght; + dt = FABS(tree->rates->nd_t[left->num] - tree->rates->nd_t[rght->num]); + + if(left->anc == rght) tree->rates->br_r[left->num] = tree->a_edges[i]->l->v / (dt*cr); + else tree->rates->br_r[rght->num] = tree->a_edges[i]->l->v / (dt*cr); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl RATES_Lk_Jumps(t_tree *tree) +{ + int i,n_jps; + phydbl dens,dt,lexp; + t_node *n; + + n = NULL; + lexp = tree->rates->lexp; + n_jps = 0; + dt = 0.0; + dens = 0.0; + + For(i,2*tree->n_otu-2) + { + n = tree->a_nodes[i]; + dt = FABS(tree->rates->nd_t[n->num]-tree->rates->nd_t[n->anc->num]); + n_jps = tree->rates->n_jps[n->num]; + dens += Dpois(n_jps,lexp*dt,YES); + } + + tree->rates->c_lnL_jps = dens; + + return dens; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Posterior_Rates(t_tree *tree) +{ + int node_num; + node_num = Rand_Int(0,2*tree->n_otu-3); + RATES_Posterior_One_Rate(tree->a_nodes[node_num]->anc,tree->a_nodes[node_num],NO,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Posterior_Times(t_tree *tree) +{ + int node_num; + node_num = Rand_Int(tree->n_otu,2*tree->n_otu-3); + RATES_Posterior_One_Time(tree->a_nodes[node_num]->anc,tree->a_nodes[node_num],NO,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Posterior_One_Rate(t_node *a, t_node *d, int traversal, t_tree *tree) +{ + phydbl like_mean, like_var; + phydbl prior_mean, prior_var; + phydbl post_mean, post_var, post_sd; + phydbl dt,rd,cr,cel,cvl; + int dim; + phydbl l_opp; /* length of the branch connected to the root, opposite to the one connected to d */ + t_edge *b; + int i; + t_node *v2,*v3; + phydbl T0,T1,T2,T3; + phydbl U0,U1,U2,U3; + phydbl V1,V2,V3; + phydbl r_min,r_max; + int err; + phydbl ratio,u; + phydbl cvr, cer; + phydbl nf; + phydbl new_lnL_data, cur_lnL_data, new_lnL_rate, cur_lnL_rate; + phydbl sd1,sd2,sd3; + phydbl inflate_var; + + if(d == tree->n_root) return; + + dim = 2*tree->n_otu-3; + err = NO; + + inflate_var = tree->rates->inflate_var; + + b = NULL; + if(a == tree->n_root) b = tree->e_root; + else for(i=0;i<3;i++) if(d->v[i] == a) { b = d->b[i]; break; } + + v2 = v3 = NULL; + if(!d->tax) + { + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(!v2) { v2 = d->v[i]; } + else { v3 = d->v[i]; } + } + } + + T3 = T2 = 0.0; + T0 = tree->rates->nd_t[a->num]; + T1 = tree->rates->nd_t[d->num]; + U0 = tree->rates->br_r[a->num]; + U1 = tree->rates->br_r[d->num]; + U3 = U2 = -1.0; + + if(!d->tax) + { + T2 = tree->rates->nd_t[v2->num]; + T3 = tree->rates->nd_t[v3->num]; + U2 = tree->rates->br_r[v2->num]; + U3 = tree->rates->br_r[v3->num]; + } + + + V1 = tree->rates->nu * FABS(T1 - T0); + V2 = tree->rates->nu * FABS(T2 - T1); + V3 = tree->rates->nu * FABS(T3 - T1); + + dt = T1 - T0; + rd = U1; + cr = tree->rates->clock_r; + r_min = tree->rates->min_rate; + r_max = tree->rates->max_rate; + nf = tree->rates->norm_fact; + sd1 = SQRT(V1); + sd2 = SQRT(V2); + sd3 = SQRT(V3); + + + /* Likelihood */ + cel=0.0; + for(i=0;inum) + cel += tree->rates->reg_coeff[b->num*dim+i] * (tree->rates->u_cur_l[i] - tree->rates->mean_l[i]); + cel += tree->rates->mean_l[b->num]; + cvl = tree->rates->cond_var[b->num]; + + l_opp = 0.0; + if(a == tree->n_root) + { + if(d == a->v[0]) l_opp = tree->rates->cur_l[a->v[1]->num]; + else l_opp = tree->rates->cur_l[a->v[0]->num]; + cel -= l_opp; + } + + + if(isnan(cvl) || isnan(cel) || cvl < .0) + { + for(i=0;inum) printf("\n. reg: %f %f %f nu=%f clock=%f", + tree->rates->reg_coeff[b->num*dim+i], + tree->rates->u_cur_l[i], + tree->rates->mean_l[i], + tree->rates->nu,tree->rates->clock_r); + PhyML_Fprintf(stderr,"\n. cel=%f cvl=%f\n",cel,cvl); + PhyML_Fprintf(stderr,"\n. Warning: invalid expected and/or std. dev. values. Skipping this step.\n"); + Exit("\n"); + } + + /* Model rates */ + /* if(tree->mod->log_l == YES) cel = exp(cel); */ + /* like_mean = cel / (dt*cr*nf); */ + /* like_var = cvl / POW(dt*cr*nf,2); */ + + like_mean = cel / (dt*cr*nf); + like_var = cvl / POW(dt*cr*nf,2); + + /* Prior */ + if(!d->tax) + { + cvr = 1./(1./V1 + 1./V2 + 1./V3); + cer = cvr*(U0/V1 + U2/V2 + U3/V3); + } + else + { + cvr = V1; + cer = U0; + } + + if(cvr < 0.0) + { + PhyML_Fprintf(stderr,"\n. cvr=%f d->tax=%d V1=%f v2=%f V3=%f",cvr,d->tax,V1,V2,V3); + PhyML_Fprintf(stderr,"\n. T0=%f T1=%f T2=%f T3=%f",T0,T1,T2,T3); + Exit("\n"); + } + + prior_mean = cer; + prior_var = cvr; + + /* Posterior */ + post_mean = (prior_mean/prior_var + like_mean/like_var)/(1./prior_var + 1./like_var); + post_var = 1./(1./prior_var + 1./like_var); + + + /* Sample according to priors */ + if(tree->eval_alnL == NO) + { + post_mean = prior_mean; + post_var = prior_var; + } + + post_sd = SQRT(post_var); + + rd = Rnorm_Trunc(post_mean,inflate_var*post_sd,r_min,r_max,&err); + + if(err || isnan(rd)) + { + PhyML_Fprintf(stderr,"\n"); + PhyML_Fprintf(stderr,"\n. run: %d err=%d d->tax=%d",tree->mcmc->run,err,d->tax); + PhyML_Fprintf(stderr,"\n. rd=%f cvr=%G dt=%G cr=%G",rd,cvr,dt,cr); + PhyML_Fprintf(stderr,"\n. prior_mean = %G prior_var = %G",prior_mean,prior_var); + PhyML_Fprintf(stderr,"\n. like_mean = %G like_var = %G",like_mean,like_var); + PhyML_Fprintf(stderr,"\n. post_mean = %G post_var = %G",post_mean,post_var); + PhyML_Fprintf(stderr,"\n. clock_r = %f",tree->rates->clock_r); + PhyML_Fprintf(stderr,"\n. T0=%f T1=%f T2=%f T3=%f",T0,T1,T2,T3); + PhyML_Fprintf(stderr,"\n. U0=%f U1=%f U2=%f U3=%f",U0,U1,U2,U3); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + /* !!!!!!!!!!!!!! */ +/* u = Uni(); */ +/* rd = U1 * exp(1.*(u-0.5)); */ + + if(rd > r_min && rd < r_max) + { + + cur_lnL_data = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_data = tree->c_lnL; + new_lnL_rate = tree->rates->c_lnL_rates; + + tree->rates->br_r[d->num] = rd; + RATES_Update_Norm_Fact(tree); + RATES_Update_Cur_Bl(tree); + + if(tree->eval_alnL) new_lnL_data = Lk(b,tree); + /* new_lnL_rate = RATES_Lk_Rates(tree); */ + new_lnL_rate = + cur_lnL_rate - + (Log_Dnorm_Trunc(U1,U0,sd1,r_min,r_max,&err)) + + (Log_Dnorm_Trunc(rd,U0,sd1,r_min,r_max,&err)); + + if(!d->tax) + { + new_lnL_rate -= (Log_Dnorm_Trunc(U2,U1,sd2,r_min,r_max,&err) + Log_Dnorm_Trunc(U3,U1,sd3,r_min,r_max,&err)); + new_lnL_rate += (Log_Dnorm_Trunc(U2,rd,sd2,r_min,r_max,&err) + Log_Dnorm_Trunc(U3,rd,sd3,r_min,r_max,&err)); + } + + tree->rates->c_lnL_rates = new_lnL_rate; + + /* printf("\n. %f %f sd1=%f U1=%f rd=%f ra=%f a=%d d=%d [%f] [%f %f]", */ + /* new_lnL_rate,RATES_Lk_Rates(tree),sd1,U1,rd,ra,a->num,d->num,tree->rates->br_r[tree->n_root->num], */ + /* Log_Dnorm_Trunc(U1,ra,sd1,r_min,r_max,&err), */ + /* Log_Dnorm_Trunc(rd,ra,sd1,r_min,r_max,&err)); */ + + ratio = 0.0; + /* Proposal ratio */ + ratio += (Log_Dnorm_Trunc(U1,post_mean,inflate_var*post_sd,r_min,r_max,&err) - Log_Dnorm_Trunc(rd,post_mean,inflate_var*post_sd,r_min,r_max,&err)); + /* ratio += log(rd/U1); */ + /* Prior ratio */ + ratio += (new_lnL_rate - cur_lnL_rate); + /* Likelihood ratio */ + ratio += (new_lnL_data - cur_lnL_data); + + + ratio = exp(ratio); + + /* printf("\n. R a=%3d T0=%6.1f T1=%6.1f T2=%6.1f T3=%6.1f ratio=%8f pm=%7f U1=%7.2f rd=%7.2f %f %f lr=%f %f ld=%f %f [%f]",a->num,T0,T1,T2,T3,ratio,post_mean,U1,rd, */ + /* Log_Dnorm_Trunc(U1,post_mean,post_sd,r_min,r_max,&err), */ + /* Log_Dnorm_Trunc(rd,post_mean,post_sd,r_min,r_max,&err), */ + /* new_lnL_rate,cur_lnL_rate, */ + /* new_lnL_data,cur_lnL_data, */ + /* ((Pnorm(r_max,U1,sd2)-Pnorm(r_min,U1,sd2)) * */ + /* (Pnorm(r_max,U1,sd3)-Pnorm(r_min,U1,sd3)))/ */ + /* ((Pnorm(r_max,rd,sd2)-Pnorm(r_min,rd,sd2)) * */ + /* (Pnorm(r_max,rd,sd3)-Pnorm(r_min,rd,sd3)))); */ + + + u = Uni(); + + if(u > MIN(1.,ratio)) + { + tree->rates->br_r[d->num] = U1; /* reject */ + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->c_lnL = cur_lnL_data; + RATES_Update_Cur_Bl(tree); + Update_PMat_At_Given_Edge(b,tree); + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_br_r+d->num]++; + } + + RATES_Update_Norm_Fact(tree); + tree->mcmc->acc_rate[tree->mcmc->num_move_br_r+d->num] = + (tree->mcmc->acc_move[tree->mcmc->num_move_br_r+d->num]+1.E-6)/ + (tree->mcmc->run_move[tree->mcmc->num_move_br_r+d->num]+1.E-6); + } + + tree->mcmc->run_move[tree->mcmc->num_move_br_r+d->num]++; + + + if(traversal == YES) + { + if(d->tax == YES) return; + else + { + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(tree->io->lk_approx == EXACT) Update_Partial_Lk(tree,d->b[i],d); + /* if(tree->io->lk_approx == EXACT) { tree->both_sides = YES; Lk(tree); } */ + RATES_Posterior_One_Rate(d,d->v[i],YES,tree); + } + } + + if(tree->io->lk_approx == EXACT) Update_Partial_Lk(tree,b,d); + /* if(tree->io->lk_approx == EXACT) { tree->both_sides = YES; Lk(tree); } */ + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Posterior_One_Time(t_node *a, t_node *d, int traversal, t_tree *tree) +{ + /* + T0 (a) + | + | l1,U1,b1 + | + T1 (d) + / \ + l2,u2,b2 / \ L3,u3,b3 + / \ + t2 t3 + (v2) (v3) + + */ + + phydbl l1,l2,l3; + phydbl new_l1; + phydbl El1,El2,El3; + phydbl u0,r1,r2,r3; + phydbl t0,t1,t2,t3; + phydbl t_min, t_max; +/* phydbl t_max_12,t_max_13; */ + phydbl bl_min, bl_max; + phydbl t1_new; + phydbl EX,EY; + phydbl VX,VY; + phydbl cr; + int i,j; + phydbl *mu, *cov; + phydbl *cond_mu, *cond_cov; + short int *is_1; + phydbl sig11, sig1X, sig1Y, sigXX, sigXY, sigYY; + phydbl cov11,cov12,cov13,cov22,cov23,cov33; + int dim; + t_edge *b1, *b2, *b3; + t_node *v2,*v3; + phydbl *l2XY; + phydbl l_opp; + t_edge *buff_b; + t_node *buff_n; + int err; + int num_1, num_2, num_3; + phydbl nf; + phydbl u, ratio; + phydbl new_lnL_data, cur_lnL_data, new_lnL_rate, cur_lnL_rate; + int num_move; + phydbl inflate_var; + + dim = 2*tree->n_otu-3; + num_move = tree->mcmc->num_move_times; + inflate_var = tree->rates->inflate_var; + + if(d->tax) return; + + if(FABS(tree->rates->t_prior_min[d->num] - tree->rates->t_prior_max[d->num]) < 1.E-10) return; + + l2XY = tree->rates->_2n_vect2; + mu = tree->rates->_2n_vect3; + cov = tree->rates->_2n2n_vect1; + cond_mu = tree->rates->_2n_vect1; + cond_cov = tree->rates->_2n2n_vect2; + is_1 = tree->rates->_2n_vect5; + err = NO; + + b1 = NULL; + if(a == tree->n_root) b1 = tree->e_root; + else for(i=0;i<3;i++) if(d->v[i] == a) { b1 = d->b[i]; break; } + + b2 = b3 = NULL; + v2 = v3 = NULL; + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(!v2) { v2 = d->v[i]; b2 = d->b[i]; } + else { v3 = d->v[i]; b3 = d->b[i]; } + } + + t2 = tree->rates->nd_t[v2->num]; + t3 = tree->rates->nd_t[v3->num]; + + buff_n = NULL; + buff_b = NULL; + if(t3 > t2) + { + buff_n = v2; + v2 = v3; + v3 = buff_n; + + buff_b = b2; + b2 = b3; + b3 = buff_b; + } + + t0 = tree->rates->nd_t[a->num]; + t1 = tree->rates->nd_t[d->num]; + t2 = tree->rates->nd_t[v2->num]; + t3 = tree->rates->nd_t[v3->num]; + u0 = tree->rates->br_r[a->num]; + r1 = tree->rates->br_r[d->num]; + r2 = tree->rates->br_r[v2->num]; + r3 = tree->rates->br_r[v3->num]; + l1 = tree->rates->cur_l[d->num]; + l2 = tree->rates->cur_l[v2->num]; + l3 = tree->rates->cur_l[v3->num]; + cr = tree->rates->clock_r; + nf = tree->rates->norm_fact; + + for(i=0;inum] = 1; + is_1[b2->num] = 1; + is_1[b3->num] = 1; + +/* for(i=0;irates->mean_l,tree->rates->cov_l,tree->rates->u_cur_l,dim,is_1,3,cond_mu,cond_cov); */ + +/* El1 = cond_mu[b1->num]; */ +/* El2 = cond_mu[b2->num]; */ +/* El3 = cond_mu[b3->num]; */ + +/* cov11 = cond_cov[b1->num*dim+b1->num]; */ +/* cov12 = cond_cov[b1->num*dim+b2->num]; */ +/* cov13 = cond_cov[b1->num*dim+b3->num]; */ +/* cov23 = cond_cov[b2->num*dim+b3->num]; */ +/* cov22 = cond_cov[b2->num*dim+b2->num]; */ +/* cov33 = cond_cov[b3->num*dim+b3->num]; */ + + +/* El1 = tree->rates->u_ml_l[b1->num]; */ +/* El2 = tree->rates->u_ml_l[b2->num]; */ +/* El3 = tree->rates->u_ml_l[b3->num]; */ + +/* cov11 = tree->rates->cov[b1->num*dim+b1->num]; */ +/* cov12 = tree->rates->cov[b1->num*dim+b2->num]; */ +/* cov13 = tree->rates->cov[b1->num*dim+b3->num]; */ +/* cov23 = tree->rates->cov[b2->num*dim+b3->num]; */ +/* cov22 = tree->rates->cov[b2->num*dim+b2->num]; */ +/* cov33 = tree->rates->cov[b3->num*dim+b3->num]; */ + +/* PhyML_Fprintf(stderr,"\n- El1=%10f El2=%10f El3=%10f",El1,El2,El3); */ +/* PhyML_Fprintf(stderr,"\n- cov11=%10f cov12=%10f cov13=%10f cov23=%10f cov22=%10f cov33=%10f", cov11,cov12,cov13,cov23,cov22,cov33); */ + + num_1 = num_2 = num_3 = -1; + if(b1->num < b2->num && b2->num < b3->num) { num_1 = 0; num_2 = 1; num_3 = 2; } + if(b1->num < b3->num && b3->num < b2->num) { num_1 = 0; num_2 = 2; num_3 = 1; } + if(b2->num < b1->num && b1->num < b3->num) { num_1 = 1; num_2 = 0; num_3 = 2; } + if(b2->num < b3->num && b3->num < b1->num) { num_1 = 2; num_2 = 0; num_3 = 1; } + if(b3->num < b2->num && b2->num < b1->num) { num_1 = 2; num_2 = 1; num_3 = 0; } + if(b3->num < b1->num && b1->num < b2->num) { num_1 = 1; num_2 = 2; num_3 = 0; } + + cov11 = tree->rates->trip_cond_cov[d->num * 9 + num_1 * 3 + num_1]; + cov12 = tree->rates->trip_cond_cov[d->num * 9 + num_1 * 3 + num_2]; + cov13 = tree->rates->trip_cond_cov[d->num * 9 + num_1 * 3 + num_3]; + cov23 = tree->rates->trip_cond_cov[d->num * 9 + num_2 * 3 + num_3]; + cov22 = tree->rates->trip_cond_cov[d->num * 9 + num_2 * 3 + num_2]; + cov33 = tree->rates->trip_cond_cov[d->num * 9 + num_3 * 3 + num_3]; + + El1=0.0; + for(i=0;inum && i != b2->num && i != b3->num) + El1 += tree->rates->trip_reg_coeff[d->num * (6*tree->n_otu-9) + num_1 * dim +i] * (tree->rates->u_cur_l[i] - tree->rates->mean_l[i]); + El1 += tree->rates->mean_l[b1->num]; + + El2=0.0; + for(i=0;inum && i != b2->num && i != b3->num) + El2 += tree->rates->trip_reg_coeff[d->num * (6*tree->n_otu-9) + num_2 * dim +i] * (tree->rates->u_cur_l[i] - tree->rates->mean_l[i]); + El2 += tree->rates->mean_l[b2->num]; + + El3=0.0; + for(i=0;inum && i != b2->num && i != b3->num) + El3 += tree->rates->trip_reg_coeff[d->num * (6*tree->n_otu-9) + num_3 * dim +i] * (tree->rates->u_cur_l[i] - tree->rates->mean_l[i]); + El3 += tree->rates->mean_l[b3->num]; + + +/* PhyML_Fprintf(stderr,"\n+ El1=%10f El2=%10f El3=%10f",El1,El2,El3); */ +/* PhyML_Fprintf(stderr,"\n+ cov11=%10f cov12=%10f cov13=%10f cov23=%10f cov22=%10f cov33=%10f", cov11,cov12,cov13,cov23,cov22,cov33); */ + + + t1_new = +1; + + t_min = MAX(t0,tree->rates->t_prior_min[d->num]); + t_max = MIN(MIN(t2,t3),tree->rates->t_prior_max[d->num]); + + t_min += tree->rates->min_dt; + t_max -= tree->rates->min_dt; + + if(t_min > t_max) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + bl_min = bl_max = -1.0; + + l_opp = 0.0; + if(a == tree->n_root) + { + l_opp = (d == a->v[0])?(tree->rates->cur_l[a->v[1]->num]):(tree->rates->cur_l[a->v[0]->num]); + El1 -= l_opp; + } + + EX = El1/r1 + El2/r2; + EY = El1/r1 + El3/r3; + + VX = cov11/(r1*r1) + cov22/(r2*r2) + 2.*cov12/(r1*r2); + VY = cov11/(r1*r1) + cov33/(r3*r3) + 2.*cov13/(r1*r3); + + mu[0] = El1; + mu[1] = EX; + mu[2] = EY; + + sig11 = cov11; + sig1X = cov11/r1 + cov12/r2; + sig1Y = cov11/r1 + cov13/r3; + sigXX = VX; + sigYY = VY; + sigXY = cov11/(r1*r1) + cov13/(r1*r3) + cov12/(r1*r2) + cov23/(r2*r3); + + cov[0*3+0] = sig11; cov[0*3+1] = sig1X; cov[0*3+2] = sig1Y; + cov[1*3+0] = sig1X; cov[1*3+1] = sigXX; cov[1*3+2] = sigXY; + cov[2*3+0] = sig1Y; cov[2*3+1] = sigXY; cov[2*3+2] = sigYY; + + l2XY[0] = 0.0; /* does not matter */ + l2XY[1] = (t2-t0)*cr*nf; /* constraint 1 */ + l2XY[2] = (t3-t0)*cr*nf; /* constraint 2 */ + + is_1[0] = is_1[1] = is_1[2] = 0; + is_1[0] = 1; + + Normal_Conditional(mu,cov,l2XY,3,is_1,1,cond_mu,cond_cov); + + + if(cond_cov[0*3+0] < 0.0) + { + PhyML_Printf("\n. a: %d d: %d",a->num,d->num); + PhyML_Printf("\n. Conditional mean=%G var=%G",cond_mu[0],cond_cov[0*3+0]); + PhyML_Printf("\n. t0=%G t1=%f t2=%f t3=%f l1=%G l2=%G l3=%G",t0,t1,t2,t3,l1,l2,l3); + PhyML_Printf("\n. El1=%G El2=%G El3=%G Nu=%G r1=%G r2=%G r3=%G cr=%G",El1,El2,El3,tree->rates->nu,r1,r2,r3,cr); + PhyML_Printf("\n. COV11=%f COV12=%f COV13=%f COV22=%f COV23=%f COV33=%f",cov11,cov12,cov13,cov22,cov23,cov33); + PhyML_Printf("\n. constraint1: %f constraints2: %f",l2XY[1],l2XY[2]); + PhyML_Printf("\n"); + for(i=0;i<3;i++) + { + PhyML_Printf(". mu%d=%12lf\t",i,mu[i]); + for(j=0;j<3;j++) + { + PhyML_Printf("%12lf ",cov[i*3+j]); + } + PhyML_Printf("\n"); + } + cond_cov[0*3+0] = 1.E-10; + } + + + bl_min = (t_min - t0) * r1 * cr * nf; + bl_max = (t_max - t0) * r1 * cr * nf; + + new_l1 = Rnorm_Trunc(cond_mu[0],inflate_var*SQRT(cond_cov[0*3+0]),bl_min,bl_max,&err); +/* new_l1 = Rnorm(cond_mu[0],SQRT(cond_cov[0*3+0])); */ + + + if(new_l1 < bl_min) new_l1 = l1; + if(new_l1 > bl_max) new_l1 = l1; + + t1_new = new_l1/(r1*cr*nf) + t0; + + + if(err) + { + PhyML_Printf("\n"); + PhyML_Printf("\n. Root ? %s",(tree->n_root==a)?("yes"):("no")); + PhyML_Printf("\n. %s %d %d",__FILE__,__LINE__,tree->mcmc->run); + PhyML_Printf("\n. t0=%f t1=%f t2=%f t3=%f",t0,t1,t2,t3); + PhyML_Printf("\n. t_min=%f t_max=%f",t_min,t_max); + PhyML_Printf("\n. bl_min=%f bl_max=%f",bl_min,bl_max); + PhyML_Printf("\n. cond_mu[0]=%f cond_cov[0]=%f",cond_mu[0],SQRT(cond_cov[0*3+0])); + PhyML_Printf("\n. El1=%f El2=%f El3=%f",El1,El2,El3); + PhyML_Printf("\n. l1=%f l2=%f l3=%f",l1,l2,l3); + PhyML_Printf("\n. u0=%f r1=%f r2=%f r3=%f",u0,r1,r2,r3); + PhyML_Printf("\n. COV11=%f COV22=%f",cov11,cov22); + PhyML_Printf("\n. Clock rate = %f",tree->rates->clock_r); + PhyML_Printf("\n. Setting t1_new to %f",t1); + t1_new = t1; + /* Exit("\n"); */ + } + /* } */ + /* else */ + /* { */ + /* bl_min = (t2 - t_max) * r2; */ + /* bl_max = (t2 - t_min) * r2; */ + + /* l2 = Rnorm_Trunc(cond_mu[0],SQRT(cond_cov[0*3+0]),bl_min,bl_max,&err); */ + /* t1_new = -l2/r2 + t2; */ + + /* if(err) */ + /* { */ + /* PhyML_Printf("\n"); */ + /* PhyML_Printf("\n. %s %d %d",__FILE__,__LINE__,tree->mcmc->run); */ + /* PhyML_Printf("\n. t0=%f t1=%f t2=%f t3=%f",t0,t1,t2,t3); */ + /* PhyML_Printf("\n. t_min=%f t_max=%f",t_min,t_max); */ + /* PhyML_Printf("\n. bl_min=%f bl_max=%f",bl_min,bl_max); */ + /* PhyML_Printf("\n. cond_mu[0]=%f cond_cov[0]=%f",cond_mu[0],SQRT(cond_cov[0*3+0])); */ + /* PhyML_Printf("\n. El1=%f El2=%f El3=%f",El1,El2,El3); */ + /* PhyML_Printf("\n. l1=%f l2=%f l3=%f",l1,l2,l3); */ + /* PhyML_Printf("\n. u0=%f r1=%f r2=%f r3=%f",u0,r1,r2,r3); */ + /* PhyML_Printf("\n. COV11=%f COV22=%f",cov11,cov22); */ + /* PhyML_Printf("\n. Clock rate = %f",tree->rates->clock_r); */ + /* PhyML_Printf("\n. Setting t1_new to %f",t1); */ + /* t1_new = t1; */ + /* /\* Exit("\n"); *\/ */ + /* } */ + /* } */ + + if(t1_new < t0) + { + t1_new = t0+1.E-4; + PhyML_Printf("\n"); + PhyML_Printf("\n. a is root -> %s",(a == tree->n_root)?("YES"):("NO")); + PhyML_Printf("\n. t0 = %f t1_new = %f t1 = %f",t0,t1_new,t1); + PhyML_Printf("\n. t_min=%f t_max=%f",t_min,t_max); + PhyML_Printf("\n. l1 = %f",l1); + PhyML_Printf("\n. bl_min = %f bl_max = %f",bl_min,bl_max); + PhyML_Printf("\n. (t1-t0)=%f (t2-t1)=%f",t1-t0,t2-t1); + PhyML_Printf("\n. l1 = %f l2 = %f cov11=%f cov22=%f cov33=%f",l1,l2,cov11,cov22,cov33); + PhyML_Printf("\n. clock=%G",tree->rates->clock_r); + PhyML_Printf("\n. u0=%f r1=%f r2=%f r3=%f",u0,r1,r2,r3); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + /* Exit("\n"); */ + } + if(t1_new > MIN(t2,t3)) + { + PhyML_Printf("\n"); + PhyML_Printf("\n. a is root -> %s",(a == tree->n_root)?("YES"):("NO")); + PhyML_Printf("\n. t0 = %f t1_new = %f t1 = %f t2 = %f t3 = %f MIN(t2,t3)=%f",t0,t1_new,t1,t2,t3,MIN(t2,t3)); + PhyML_Printf("\n. t_min=%f t_max=%f",t_min,t_max); + PhyML_Printf("\n. l2 = %f",l2); + PhyML_Printf("\n. bl_min = %f bl_max = %f",bl_min,bl_max); + PhyML_Printf("\n. (t1-t0)=%f (t2-t1)=%f",t1-t0,t2-t1); + PhyML_Printf("\n. l1 = %f l2 = %f cov11=%f cov22=%f cov33=%f",l1,l2,cov11,cov22,cov33); + PhyML_Printf("\n. clock=%G",tree->rates->clock_r); + PhyML_Printf("\n. u0=%f r1=%f r2=%f r3=%f",u0,r1,r2,r3); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + /* Exit("\n"); */ + } + + if(isnan(t1_new)) + { + PhyML_Printf("\n. run=%d",tree->mcmc->run); + PhyML_Printf("\n. mean=%G var=%G",cond_mu[0],cond_cov[0*3+0]); + PhyML_Printf("\n. t1=%f l1=%G r1=%G t0=%G",t1,l1,r1,t0); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + /* Exit("\n"); */ + } + + if(tree->eval_alnL == YES) + tree->rates->nd_t[d->num] = t1_new; + else + { + u = Uni(); + tree->rates->nd_t[d->num] = u*(t_max-t_min) + t_min; + } + + RATES_Update_Norm_Fact(tree); + RATES_Update_Cur_Bl(tree); + + cur_lnL_data = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_data = tree->c_lnL; + new_lnL_rate = tree->rates->c_lnL_rates; + + /* !!!!!!!!!!!!!!!!! */ + /* tree->both_sides = NO; */ + /* new_lnL_data = Lk(tree); */ + + if(tree->io->lk_approx == EXACT) + { + Update_PMat_At_Given_Edge(b1,tree); + Update_PMat_At_Given_Edge(b2,tree); + Update_PMat_At_Given_Edge(b3,tree); + Update_Partial_Lk(tree,b1,d); + } + new_lnL_data = Lk(b1,tree); + + new_lnL_rate = RATES_Lk_Rates(tree); + + ratio = 0.0; + + /* Proposal ratio */ + if(tree->eval_alnL) + ratio += (Log_Dnorm_Trunc(l1, cond_mu[0],inflate_var*SQRT(cond_cov[0*3+0]),bl_min,bl_max,&err) - + Log_Dnorm_Trunc(new_l1,cond_mu[0],inflate_var*SQRT(cond_cov[0*3+0]),bl_min,bl_max,&err)); + + /* Prior ratio */ + ratio += (new_lnL_rate - cur_lnL_rate); + + /* Likelihood ratio */ + ratio += (new_lnL_data - cur_lnL_data); + + /* printf("\n* d:%d Ratio=%f l1=%f new_l1=%f mean=%f ml=%f sd=%f [%f %f]", */ + /* d->num, */ + /* exp(ratio), */ + /* l1,new_l1, */ + /* cond_mu[0], */ + /* tree->rates->mean_l[b1->num], */ + /* SQRT(cond_cov[0*3+0]), */ + /* Log_Dnorm(l1,cond_mu[0],SQRT(cond_cov[0*3+0]),&err),Log_Dnorm(new_l1,cond_mu[0],SQRT(cond_cov[0*3+0]),&err)); */ + + ratio = exp(ratio); + + + u = Uni(); + if(u > MIN(1.,ratio)) + { + tree->rates->nd_t[d->num] = t1; /* reject */ + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->c_lnL = cur_lnL_data; + RATES_Update_Cur_Bl(tree); + if(tree->io->lk_approx == EXACT) + { + Update_PMat_At_Given_Edge(b1,tree); + Update_PMat_At_Given_Edge(b2,tree); + Update_PMat_At_Given_Edge(b3,tree); + Update_Partial_Lk(tree,b1,d); + } + } + else + { + tree->mcmc->acc_move[num_move]++; + } + + RATES_Update_Norm_Fact(tree); + + tree->mcmc->run_move[num_move]++; + + if(traversal == YES) + { + if(d->tax == YES) return; + else + { + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(tree->io->lk_approx == EXACT) Update_Partial_Lk(tree,d->b[i],d); + RATES_Posterior_One_Time(d,d->v[i],YES,tree); + } + } + if(tree->io->lk_approx == EXACT) Update_Partial_Lk(tree,b1,d); + } + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Posterior_Time_Root(t_tree *tree) +{ + /* + Root, T0 + / \ + l1 / \ l2 + / \ + v1,t1 v2,t2 + + */ + + phydbl t1,t2; + phydbl u0,u1,u2; + phydbl cel,cvl; + int i,dim; + t_edge *b; + t_node *root; + phydbl t0,t0_min, t0_max; + phydbl new_t0; +/* phydbl t_max_01, t_max_02; */ + int err; + phydbl cr; + phydbl bl_min, bl_max; + phydbl new_l; + phydbl new_lnL_data, cur_lnL_data, cur_lnL_rate; + phydbl u,ratio; + + dim = 2*tree->n_otu-3; + b = tree->e_root; + root = tree->n_root; + t0 = tree->rates->nd_t[root->num]; + t1 = tree->rates->nd_t[root->v[2]->num]; + t2 = tree->rates->nd_t[root->v[1]->num]; + u1 = tree->rates->br_r[root->v[2]->num]; + u2 = tree->rates->br_r[root->v[1]->num]; + u0 = 1.0; + cr = tree->rates->clock_r; + t0_min = -BIG; + t0_max = MIN(t1,t2); + + /* t0_max = MIN(t1 - (1./tree->rates->nu)*POW((u0-u1)/tree->rates->z_max,2), */ + /* t2 - (1./tree->rates->nu)*POW((u0-u2)/tree->rates->z_max,2)); */ + + /* if(u1 > u0) t_max_01 = t1 - (1./tree->rates->nu)*POW((u1-u0)/(PointNormal(tree->rates->p_max*Pnorm(.0,.0,1.))),2); */ + /* else t_max_01 = t1 - (1./tree->rates->nu)*POW((u1-u0)/(PointNormal(tree->rates->p_max*(1.-Pnorm(.0,.0,1.)))),2); */ + + /* if(u2 > u0) t_max_02 = t2 - (1./tree->rates->nu)*POW((u2-u0)/(PointNormal(tree->rates->p_max*Pnorm(.0,.0,1.))),2); */ + /* else t_max_02 = t2 - (1./tree->rates->nu)*POW((u2-u0)/(PointNormal(tree->rates->p_max*(1.-Pnorm(.0,.0,1.)))),2); */ + + + /* t_max_01 = RATES_Find_Max_Dt_Bisec(u1,u0,tree->rates->t_prior_min[root->num],t1,tree->rates->nu,tree->rates->p_max,(u1 < u0)?YES:NO); */ + /* t_max_02 = RATES_Find_Max_Dt_Bisec(u2,u0,tree->rates->t_prior_min[root->num],t2,tree->rates->nu,tree->rates->p_max,(u2 < u0)?YES:NO); */ + /* t0_max = MIN(t_max_01,t_max_02); */ + + /* RATES_Min_Max_Interval(u0,u1,u2,r3,t0,t2,t3,&t_min,&t_max,tree->rates->nu,tree->rates->p_max,tree); */ + + t0_min = MAX(t0_min,tree->rates->t_prior_min[root->num]); + t0_max = MIN(t0_max,tree->rates->t_prior_max[root->num]); + + t0_max -= tree->rates->min_dt; + + if(t0_min > t0_max) return; + + tree->rates->t_prior[root->num] = Uni()*(t0_max - t0_min) + t0_min; + + u0 *= cr; + u1 *= cr; + u2 *= cr; + + if(FABS(tree->rates->t_prior_min[root->num] - tree->rates->t_prior_max[root->num]) < 1.E-10) return; + + cel=0.0; + for(i=0;inum) cel += tree->rates->reg_coeff[b->num*dim+i] * (tree->rates->u_cur_l[i] - tree->rates->mean_l[i]); + cel += tree->rates->mean_l[b->num]; + + cvl = tree->rates->cond_var[b->num]; + + bl_min = u1 * (t1 - t0_max) + u2 * (t2 - t0_max); + bl_max = u1 * (t1 - t0_min) + u2 * (t2 - t0_min); + + if(bl_min > bl_max) return; + + new_l = Rnorm_Trunc(cel,SQRT(cvl),bl_min,bl_max,&err); + + new_t0 = (u1*t1 + u2*t2 - new_l)/(u1+u2); + + if(t0 > t1 || t0 > t2) + { + PhyML_Printf("\n"); + PhyML_Printf("\n. Run = %d",tree->mcmc->run); + PhyML_Printf("\n. t0=%f t1=%f t2=%f",t0,t1,t2); + PhyML_Printf("\n. t0_min=%f t0_max=%f",t0_min,t0_max); + PhyML_Printf("\n. new_l=%f cel=%f",new_l,cel); + PhyML_Printf("\n. u0=%f u1=%f u2=%f",u0/cr,u1/cr,u2/cr); + PhyML_Printf("\n. Nu = %f Clock = %f",tree->rates->nu,tree->rates->clock_r); + PhyML_Printf("\n. Setting t0 to %f",tree->rates->nd_t[root->num]); + return; + } + + if(t0 < t0_min || t0 > t0_max) + { + PhyML_Printf("\n"); + PhyML_Printf("\n. Run = %d",tree->mcmc->run); + PhyML_Printf("\n. t0=%f t1=%f t2=%f",t0,t1,t2); + PhyML_Printf("\n. t0_min=%f t0_max=%f",t0_min,t0_max); + PhyML_Printf("\n. u0=%f u1=%f u2=%f",u0/cr,u1/cr,u2/cr); + PhyML_Printf("\n. Nu = %f Clock = %f",tree->rates->nu,tree->rates->clock_r); + PhyML_Printf("\n. Setting t0 to %f",tree->rates->nd_t[root->num]); + t0 = tree->rates->nd_t[root->num]; + } + + /* Sample according to prior */ +/* tree->rates->nd_t[root->num] = tree->rates->t_prior[root->num]; */ + + /* Sample according to posterior */ + tree->rates->nd_t[root->num] = new_t0; + + RATES_Update_Norm_Fact(tree); + RATES_Update_Cur_Bl(tree); + + cur_lnL_data = tree->c_lnL; + cur_lnL_rate = tree->rates->c_lnL_rates; + new_lnL_data = tree->c_lnL; + + new_lnL_data = Lk(NULL,tree); + + ratio = 0.0; + /* Prior ratio */ + ratio += .0; + /* Likelihood ratio */ + ratio += new_lnL_data - cur_lnL_data; + + ratio = exp(ratio); + u = Uni(); + if(u > MIN(1.,ratio)) + { + tree->rates->nd_t[root->num] = t0; /* reject */ + tree->rates->c_lnL_rates = cur_lnL_rate; + tree->c_lnL = cur_lnL_data; + } + else + { + tree->mcmc->acc_move[tree->mcmc->num_move_times]++; + } + + RATES_Update_Norm_Fact(tree); + RATES_Update_Cur_Bl(tree); + + tree->mcmc->run_move[tree->mcmc->num_move_times]++; + tree->mcmc->acc_rate[tree->mcmc->num_move_times] = + (tree->mcmc->acc_move[tree->mcmc->num_move_times]+1.E-6)/ + (tree->mcmc->run_move[tree->mcmc->num_move_times]+1.E-6); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Update_Cur_Bl(t_tree *tree) +{ + + RATES_Update_Cur_Bl_Pre(tree->n_root,tree->n_root->v[1],tree->n_root->b[1],tree); + RATES_Update_Cur_Bl_Pre(tree->n_root,tree->n_root->v[2],tree->n_root->b[2],tree); + + if(tree->mod && tree->mod->log_l == YES) + { + tree->e_root->l->v = + exp(tree->n_root->b[1]->l->v) + + exp(tree->n_root->b[2]->l->v) ; + tree->e_root->l->v = log(tree->e_root->l->v); + } + else + { + tree->e_root->l->v = tree->n_root->b[1]->l->v + tree->n_root->b[2]->l->v; + } + + tree->rates->u_cur_l[tree->e_root->num] = tree->e_root->l->v; + tree->n_root_pos = tree->n_root->b[2]->l->v / tree->e_root->l->v; + + if(tree->rates->model == GUINDON) + { + phydbl t0,t1,t2; + t_node *n0, *n1; + + n0 = tree->n_root->v[2]; + n1 = tree->n_root->v[1]; + t1 = tree->rates->nd_t[tree->n_root->v[2]->num]; + t2 = tree->rates->nd_t[tree->n_root->v[1]->num]; + t0 = tree->rates->nd_t[tree->n_root->num]; + + tree->e_root->l->v = + (t1-t0)/(t1+t2-2.*t0)*tree->rates->cur_gamma_prior_mean[n0->num] + + (t2-t0)/(t1+t2-2.*t0)*tree->rates->cur_gamma_prior_mean[n1->num]; + + tree->e_root->l_var->v = + pow((t1-t0)/(t1+t2-2.*t0),2)*tree->rates->cur_gamma_prior_var[n0->num] + + pow((t2-t0)/(t1+t2-2.*t0),2)*tree->rates->cur_gamma_prior_var[n1->num]; + } + + if(tree->is_mixt_tree == YES) MIXT_RATES_Update_Cur_Bl(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Update_Cur_Bl_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree) +{ + phydbl dt,rr,cr,ra,rd,ta,td,nu; + + assert(a); + assert(d); + + ra = rd = -1.; + tree->rates->br_do_updt[d->num] = YES; + + if(tree->rates->br_do_updt[d->num] == YES) + { + tree->rates->br_do_updt[d->num] = NO; + + if(tree->rates->model == LOGNORMAL || + tree->rates->model == THORNE || + tree->rates->model == STRICTCLOCK) + { + rd = tree->rates->br_r[d->num]; + ra = tree->rates->br_r[a->num]; + } + else if(tree->rates->model == GUINDON) + { + rd = tree->rates->nd_r[d->num]; + ra = tree->rates->nd_r[a->num]; + } + else assert(FALSE); + + dt = fabs(tree->rates->nd_t[d->num] - tree->rates->nd_t[a->num]); + cr = tree->rates->clock_r; + td = tree->rates->nd_t[d->num]; + ta = tree->rates->nd_t[a->num]; + nu = tree->rates->nu; + rr = -1.0; + + + if(tree->rates->model == LOGNORMAL) + { + rr = rd; + tree->rates->cur_l[d->num] = dt*rr*cr; + /* PhyML_Printf("\n. a: %d d: %d rr: %f dt: %f cr: %f tree: %p",a->num,d->num,rr,dt,cr,tree); */ + } + + if(tree->rates->model == THORNE) + { + rr = (ra+rd)/2.; + tree->rates->cur_l[d->num] = dt*rr*cr; + } + + if(tree->rates->model == GUINDON) + { + phydbl m,v; + + Integrated_Geometric_Brownian_Bridge_Moments(dt,ra,rd,nu,&m,&v); + + if(isnan(m) || isnan(v) || m < 0.0 || v < 0.0) + { + PhyML_Fprintf(stderr,"\n. dt: %G ra: %G rd: %G nu: %G m: %G v: %G a is root ? %d d is root ? %d", + dt,ra,rd,nu,m,v, + a==tree->n_root, + d==tree->n_root); + } + + m *= cr*dt; // the actual rate average is m * cr. We multiply by dt in order to derive the value for the branch length + v *= (cr*cr)*(dt*dt); + + tree->rates->cur_gamma_prior_mean[d->num] = m; + tree->rates->cur_gamma_prior_var[d->num] = v; + + tree->rates->cur_l[d->num] = tree->rates->cur_gamma_prior_mean[d->num]; // Required for having proper branch lengths in Write_Tree function + } + + if(tree->rates->model == STRICTCLOCK) + { + tree->rates->cur_l[d->num] = dt*cr; + } + + /* printf("\n. td: %12f ta: %12f dt: %12f cr: %12f ra: %12f rd: %12f l: %12f", */ + /* tree->rates->nd_t[d->num], */ + /* tree->rates->nd_t[a->num], */ + /* dt,cr,ra,rd,tree->rates->cur_l[d->num]); */ + + + if(tree->mod && tree->mod->log_l == YES) tree->rates->cur_l[d->num] = log(tree->rates->cur_l[d->num]); + + if(b) + { + b->l->v = tree->rates->cur_l[d->num]; + tree->rates->u_cur_l[b->num] = tree->rates->cur_l[d->num]; + b->l_var->v = tree->rates->cur_gamma_prior_var[d->num]; + } + + if(b && (isnan(b->l->v) || isnan(b->l_var->v))) + { + PhyML_Fprintf(stderr,"\n. dt=%G rr=%G cr=%G ra=%G rd=%G nu=%G %f %f ",dt,rr,cr,ra,rd,nu,b->l_var->v,b->l->v); + PhyML_Fprintf(stderr,"\n. ta=%G td=%G ra*cr=%G rd*cr=%G sd=%G",ta,td,ra*cr,rd*cr,SQRT(dt*nu)*cr); + /* assert(FALSE); */ + } + } + + if(d->tax) return; + else + { + int i; + for(i=0;i<3;++i) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + RATES_Update_Cur_Bl_Pre(d,d->v[i],d->b[i],tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Bl_To_Bl(t_tree *tree) +{ + RATES_Bl_To_Bl_Pre(tree->n_root,tree->n_root->v[2],NULL,tree); + RATES_Bl_To_Bl_Pre(tree->n_root,tree->n_root->v[1],NULL,tree); + /* tree->rates->cur_l[tree->n_root->v[2]->num] = tree->a_edges[tree->e_root->num]->l->v * tree->n_root_pos; */ + /* tree->rates->cur_l[tree->n_root->v[1]->num] = tree->a_edges[tree->e_root->num]->l->v * (1. - tree->n_root_pos); */ + tree->rates->cur_l[tree->n_root->v[2]->num] = tree->a_edges[tree->e_root->num]->l->v * 0.5; + tree->rates->cur_l[tree->n_root->v[1]->num] = tree->a_edges[tree->e_root->num]->l->v * (1. - 0.5); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Bl_To_Bl_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree) +{ + + if(b) + { + tree->rates->cur_l[d->num] = b->l->v; + } + + if(d->tax) return; + else + { + int i; + + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + RATES_Bl_To_Bl_Pre(d,d->v[i],d->b[i],tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Bl_To_Ml(t_tree *tree) +{ + RATES_Bl_To_Ml_Pre(tree->n_root,tree->n_root->v[2],NULL,tree); + RATES_Bl_To_Ml_Pre(tree->n_root,tree->n_root->v[1],NULL,tree); + tree->rates->u_ml_l[tree->e_root->num] = tree->a_edges[tree->e_root->num]->l->v; + tree->rates->ml_l[tree->n_root->v[2]->num] = tree->rates->u_ml_l[tree->e_root->num] * tree->n_root_pos; + tree->rates->ml_l[tree->n_root->v[1]->num] = tree->rates->u_ml_l[tree->e_root->num] * (1. - tree->n_root_pos); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Bl_To_Ml_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree) +{ + + if(b) + { + tree->rates->u_ml_l[b->num] = b->l->v; + tree->rates->ml_l[d->num] = b->l->v; + } + + if(d->tax) return; + else + { + int i; + + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + RATES_Bl_To_Ml_Pre(d,d->v[i],d->b[i],tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Get_Cov_Matrix_Rooted(phydbl *unroot_cov, t_tree *tree) +{ + int i,dim; + + dim = 2*tree->n_otu-3; + + RATES_Get_Cov_Matrix_Rooted_Pre(tree->n_root,tree->n_root->v[2],NULL,unroot_cov,tree); + RATES_Get_Cov_Matrix_Rooted_Pre(tree->n_root,tree->n_root->v[1],NULL,unroot_cov,tree); + + for(i=0;irates->cov_l[i*(dim+1)+tree->n_root->v[2]->num] /= 2.; + for(i=0;irates->cov_l[i*(dim+1)+tree->n_root->v[1]->num] /= 2.; + for(i=0;irates->cov_l[tree->n_root->v[2]->num*(dim+1)+i] /= 2.; + for(i=0;irates->cov_l[tree->n_root->v[1]->num*(dim+1)+i] /= 2.; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Get_Cov_Matrix_Rooted_Pre(t_node *a, t_node *d, t_edge *b, phydbl *cov, t_tree *tree) +{ + int i, dim; + t_node *n; + + dim = 2*tree->n_otu-3; + n = NULL; + + for(i=0;ia_edges[i] != tree->e_root) + { + n = + (tree->a_edges[i]->left->anc == tree->a_edges[i]->rght)? + (tree->a_edges[i]->left): + (tree->a_edges[i]->rght); + + if(b) + { + tree->rates->cov_l[d->num*(dim+1) + n->num] = cov[b->num*dim + i]; + } + else + { + tree->rates->cov_l[d->num*(dim+1) + n->num] = cov[tree->e_root->num*dim + i]; + } + } + else + { + n = tree->e_root->left; + if(b) + tree->rates->cov_l[d->num*(dim+1) + n->num] = cov[b->num*dim + i]; + else + tree->rates->cov_l[d->num*(dim+1) + n->num] = cov[tree->e_root->num*dim + i]; + + n = tree->e_root->rght; + if(b) + tree->rates->cov_l[d->num*(dim+1) + n->num] = cov[b->num*dim + i]; + else + tree->rates->cov_l[d->num*(dim+1) + n->num] = cov[tree->e_root->num*dim + i]; + } + } + + + if(d->tax) return; + else + { + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + RATES_Get_Cov_Matrix_Rooted_Pre(d,d->v[i],d->b[i],cov,tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Covariance_Mu(t_tree *tree) +{ + int i,j; + phydbl dt,var; + int dim; + int lca_num; + + dim = 2*tree->n_otu-2; + + For(i,dim*dim) tree->rates->cov_r[i] = 0.0; + + dt = tree->rates->nd_t[tree->n_root->v[2]->num] - tree->rates->nd_t[tree->n_root->num]; + var = dt * tree->rates->nu; + tree->rates->cov_r[tree->n_root->v[2]->num*dim+tree->n_root->v[2]->num] = var; + + + dt = tree->rates->nd_t[tree->n_root->v[1]->num] - tree->rates->nd_t[tree->n_root->num]; + var = dt * tree->rates->nu; + tree->rates->cov_r[tree->n_root->v[1]->num*dim+tree->n_root->v[1]->num] = var; + + RATES_Variance_Mu_Pre(tree->n_root,tree->n_root->v[2],tree); + RATES_Variance_Mu_Pre(tree->n_root,tree->n_root->v[1],tree); + + for(i=0;irates->lca[i*(dim+1)+j]->num; + if(lca_num < dim) + { + tree->rates->cov_r[i*dim+j] = tree->rates->cov_r[lca_num*dim+lca_num]; + tree->rates->cov_r[j*dim+i] = tree->rates->cov_r[i*dim+j]; + } + else if(lca_num == dim) + { + tree->rates->cov_r[i*dim+j] = 0.0; + tree->rates->cov_r[j*dim+i] = 0.0; + } + else + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Variance_Mu_Pre(t_node *a, t_node *d, t_tree *tree) +{ + int dim; + phydbl var0; + phydbl dt1,var1; + phydbl dt2,var2; + int i; + int dir1, dir2; + + dim = 2*tree->n_otu-2; + + if(d->tax) return; + + dir1 = dir2 = -1; + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(dir1 < 0) dir1 = i; + else dir2 = i; + } + } + + + var0 = tree->rates->cov_r[d->num*dim+d->num]; + + dt1 = tree->rates->nd_t[d->v[dir1]->num] - tree->rates->nd_t[d->num]; + var1 = tree->rates->nu*dt1; + + dt2 = tree->rates->nd_t[d->v[dir2]->num] - tree->rates->nd_t[d->num]; + var2 = tree->rates->nu*dt2; + + tree->rates->cov_r[d->v[dir1]->num*dim+d->v[dir1]->num] = var0+var1; + tree->rates->cov_r[d->v[dir2]->num*dim+d->v[dir2]->num] = var0+var2; + + + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + RATES_Variance_Mu_Pre(d,d->v[i],tree); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Fill_Lca_Table(t_tree *tree) +{ + int i,j; + int dim; + + dim = 2*tree->n_otu-1; + + for(i=0;irates->lca[i*dim+j] = Find_Lca_Pair_Of_Nodes(tree->a_nodes[i],tree->a_nodes[j],tree); + tree->rates->lca[j*dim+i] = tree->rates->lca[i*dim+j]; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Get V(L_{i} | L_{-i}) for all i */ +void RATES_Get_Conditional_Variances(t_tree *tree) +{ + int i,j; + short int *is_1; + phydbl *a; + int dim; + t_edge *b; + phydbl *cond_mu, *cond_cov; + + dim = 2*tree->n_otu-3; + a = tree->rates->_2n_vect1; + is_1 = tree->rates->_2n_vect5; + b = NULL; + cond_mu = tree->rates->_2n_vect2; + cond_cov = tree->rates->_2n2n_vect1; + + for(i=0;irates->mean_l[i] * (Uni() * 0.2 + 0.9); + + for(i=0;ia_edges[i]; + + for(j=0;jnum] = 1; + + For(j,dim*dim) cond_cov[j] = 0.0; + for(j=0;jrates->mean_l,tree->rates->cov_l,a,dim,is_1,1,cond_mu,cond_cov); + + tree->rates->cond_var[b->num] = cond_cov[b->num*dim+b->num]; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Get_All_Reg_Coeff(t_tree *tree) +{ + int i,j; + short int *is_1; + phydbl *a; + int dim; + t_edge *b; + + dim = 2*tree->n_otu-3; + a = tree->rates->_2n_vect1; + is_1 = tree->rates->_2n_vect5; + b = NULL; + + for(i=0;irates->mean_l[i] * (Uni() * 0.2 + 0.9); + + for(i=0;ia_edges[i]; + + for(j=0;jnum] = 1; + + Get_Reg_Coeff(tree->rates->mean_l,tree->rates->cov_l,a,dim,is_1,1,tree->rates->reg_coeff+b->num*dim); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/* Get V(L_{i} | L_{-i}) for all i */ +void RATES_Get_Trip_Conditional_Variances(t_tree *tree) +{ + int i,j; + short int *is_1; + phydbl *a; + phydbl *cond_mu, *cond_cov; + t_node *n; + int n_otu; + + a = tree->rates->_2n_vect1; + is_1 = tree->rates->_2n_vect5; + cond_mu = tree->rates->_2n_vect2; + cond_cov = tree->rates->_2n2n_vect1; + n = NULL; + n_otu = tree->n_otu; + + For(i,2*n_otu-3) a[i] = tree->rates->mean_l[i] * (Uni() * 0.2 + 0.9); + + for(i=0;i<2*n_otu-2;++i) + { + n = tree->a_nodes[i]; + if(!n->tax) + { + For(j,2*n_otu-3) is_1[j] = 0; + is_1[n->b[0]->num] = 1; + is_1[n->b[1]->num] = 1; + is_1[n->b[2]->num] = 1; + + Normal_Conditional_Unsorted(tree->rates->mean_l,tree->rates->cov_l,a,2*n_otu-3,is_1,3,cond_mu,cond_cov); + + for(j=0;j<9;j++) tree->rates->trip_cond_cov[n->num*9+j] = cond_cov[j]; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Get_All_Trip_Reg_Coeff(t_tree *tree) +{ + int i,j; + short int *is_1; + phydbl *a; + t_node *n; + int n_otu; + + a = tree->rates->_2n_vect1; + is_1 = tree->rates->_2n_vect5; + n = NULL; + n_otu = tree->n_otu; + + For(i,2*n_otu-3) a[i] = tree->rates->mean_l[i] * (Uni() * 0.2 + 0.9); + + for(i=0;i<2*n_otu-2;++i) + { + n = tree->a_nodes[i]; + if(!n->tax) + { + For(j,2*n_otu-3) is_1[j] = 0; + is_1[n->b[0]->num] = 1; + is_1[n->b[1]->num] = 1; + is_1[n->b[2]->num] = 1; + + Get_Reg_Coeff(tree->rates->mean_l,tree->rates->cov_l,a,2*n_otu-3,is_1,3,tree->rates->trip_reg_coeff+n->num*(6*n_otu-9)); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Check_Lk_Rates(t_tree *tree, int *err) +{ + int i; + phydbl u,u_anc; + phydbl t,t_anc; + + *err = 0; + + For(i,2*tree->n_otu-2) + { + u = tree->rates->br_r[i]; + u_anc = tree->rates->br_r[tree->a_nodes[i]->anc->num]; + t = tree->rates->nd_t[i]; + t_anc = tree->rates->nd_t[tree->a_nodes[i]->anc->num]; + + if(t_anc > t) + { + PhyML_Printf("\n. %d %d u=%f u_anc=%f t=%f t_anc=%f",i,tree->a_nodes[i]->anc->num,u,u_anc,t,t_anc); + PhyML_Printf("\n. %d %d %d",tree->n_root->num,tree->n_root->v[2]->num,tree->n_root->v[1]->num); + *err = 1; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl RATES_Realized_Substitution_Rate(t_tree *tree) +{ + return(Tree_Length(tree)/TIMES_Tree_Length(tree)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl RATES_Expected_Tree_Length(t_tree *tree) +{ + int n; + phydbl mean; + + n = 0; + mean = 0.0; + RATES_Expected_Tree_Length_Pre(tree->n_root,tree->n_root->v[2],1.0,&mean,&n,tree); + RATES_Expected_Tree_Length_Pre(tree->n_root,tree->n_root->v[1],1.0,&mean,&n,tree); + + if(n != 2*tree->n_otu-2) + { + PhyML_Fprintf(stderr,"\n. n=%d 2n-2=%d",n,2*tree->n_otu-2); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + return mean; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Expected_Tree_Length_Pre(t_node *a, t_node *d, phydbl eranc, phydbl *mean, int *n, t_tree *tree) +{ + phydbl erdes; + int i; + phydbl loc_mean; + int loc_n; + + +/* erdes = u_anc - */ +/* sd*(Dnorm((tree->rates->min_rate-u_anc)/sd,.0,1.) - Dnorm((tree->rates->max_rate-u_anc)/sd,.0,1.))/ */ +/* (Pnorm((tree->rates->max_rate-u_anc)/sd,.0,1.) - Pnorm((tree->rates->min_rate-u_anc)/sd,.0,1.)); */ + + /* erdes = Norm_Trunc_Mean(eranc,sd,tree->rates->min_rate,tree->rates->max_rate); */ + erdes = 1.0; + + loc_mean = *mean; + loc_n = *n; + + loc_mean *= loc_n; + loc_mean += erdes; + loc_mean /= (loc_n + 1); + + *mean = loc_mean; + *n = loc_n + 1; + + + if(d->tax) return; + else + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + RATES_Expected_Tree_Length_Pre(d,d->v[i],erdes,mean,n,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Update_Norm_Fact(t_tree *tree) +{ + /* int i; */ + /* phydbl r,t,t_anc; */ + /* phydbl num,denom; */ + + /* num = denom = 0.0; */ + + /* For(i,2*tree->n_otu-2) */ + /* { */ + /* r = tree->rates->br_r[i]; */ + /* t = tree->rates->nd_t[i]; */ + /* t_anc = tree->rates->nd_t[tree->a_nodes[i]->anc->num]; */ + + /* num += (t-t_anc); */ + /* denom += (t-t_anc) * r; */ + /* } */ + /* tree->rates->norm_fact = num/denom; */ + + tree->rates->norm_fact = 1.0; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Normalise_Rates(t_tree *tree) +{ + phydbl expr,curr; + int i; + + curr = RATES_Average_Substitution_Rate(tree); + curr /= tree->rates->clock_r; + + /* Set expected mean rate to one such that clock_r is + easy to interpret regarding the mean values of br_r */ + expr = 1.0; + + For(i,2*tree->n_otu-2) + { + tree->rates->br_r[i] *= expr/curr; + + if(tree->rates->br_r[i] > tree->rates->max_rate) + tree->rates->br_r[i] = tree->rates->max_rate; + + if(tree->rates->br_r[i] < tree->rates->min_rate) + tree->rates->br_r[i] = tree->rates->min_rate; + } + + tree->rates->clock_r *= curr/expr; + /* Branch lengths therefore do not change */ + +/* if(tree->rates->clock_r < tree->rates->min_clock) */ +/* { */ +/* PhyML_Printf("\n. Curr mean rates: %G",curr); */ +/* PhyML_Printf("\n. Set clock rate to: %G",tree->rates->clock_r); */ +/* tree->rates->clock_r = tree->rates->min_clock; */ +/* } */ +/* if(tree->rates->clock_r > tree->rates->max_clock) */ +/* { */ +/* PhyML_Printf("\n. Curr mean rates: %G",curr); */ +/* PhyML_Printf("\n. Set clock rate to: %G",tree->rates->clock_r); */ +/* tree->rates->clock_r = tree->rates->max_clock; */ +/* } */ + + RATES_Update_Norm_Fact(tree); + RATES_Update_Cur_Bl(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl RATES_Find_Max_Dt_Bisec(phydbl r, phydbl r_mean, phydbl ta, phydbl tc, phydbl nu, phydbl threshp, int inf) +{ + phydbl cdfr,cdf0; + phydbl sd; + phydbl trunc_cdf; + phydbl ori_tc, ori_ta; + phydbl tb; + + ori_tc = tc; + ori_ta = ta; + +/* PhyML_Printf("\n Max %s r=%f r_mean%f",inf?"inf":"sup",r,r_mean); */ + do + { + tb = ta + (tc - ta)/2.; + + + sd = SQRT(nu*(ori_tc - tb)); + cdfr = Pnorm(r ,r_mean,sd); + cdf0 = Pnorm(.0,r_mean,sd); + + if(inf) + trunc_cdf = (cdfr - cdf0)/(1. - cdf0); + else + trunc_cdf = (1. - cdfr)/(1. - cdf0); + +/* PhyML_Printf("\n. ta=%15f tb=%15f tc=%15f cdf = %15f",ta,tb,tc,trunc_cdf); */ + + if(trunc_cdf > threshp) + { + ta = tb; + } + else + { + tc = tb; + } + + }while((tc - ta)/(ori_tc - ori_ta) > 0.001); + + if(tb < ori_ta) + { + PhyML_Fprintf(stderr,"\n. tb < ta r=%f r_mean=%f",r,r_mean); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + if(tb > ori_tc) + { + PhyML_Fprintf(stderr,"\n. tb > tc r=%f r_mean=%f ori_ta=%f ori_tc=%f tb=%f",r,r_mean,ori_ta,ori_tc,tb); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + return tb; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl RATES_Find_Min_Dt_Bisec(phydbl r, phydbl r_mean, phydbl ta, phydbl tc, phydbl nu, phydbl threshp, int inf) +{ + phydbl cdfr,cdf0; + phydbl sd; + phydbl trunc_cdf; + phydbl ori_tc, ori_ta; + phydbl tb; + + ori_tc = tc; + ori_ta = ta; + +/* PhyML_Printf("\n Min %s r=%f r_mean=%f",inf?"inf":"sup",r,r_mean); */ + do + { + + tb = ta + (tc - ta)/2.; + + + sd = SQRT(nu*(tb - ori_ta)); + cdfr = Pnorm(r ,r_mean,sd); + cdf0 = Pnorm(.0,r_mean,sd); + + if(inf) + trunc_cdf = (cdfr - cdf0)/(1. - cdf0); + else + trunc_cdf = (1. - cdfr)/(1. - cdf0); + +/* PhyML_Printf("\n. ta=%15f tb=%15f tc=%15f cdf = %15f",ta,tb,tc,trunc_cdf); */ + + if(trunc_cdf > threshp) + { + tc = tb; + } + else + { + ta = tb; + } + + }while((tc - ta)/(ori_tc - ori_ta) > 0.001); + + if(tb < ori_ta) + { + PhyML_Fprintf(stderr,"\n. tb < ta r=%f r_mean=%f",r,r_mean); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + if(tb > ori_tc) + { + PhyML_Fprintf(stderr,"\n. tb > tc r=%f r_mean=%f ori_ta=%f ori_tc=%f tb=%f",r,r_mean,ori_ta,ori_tc,tb); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + return tb; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Min_Max_Interval(phydbl u0, phydbl u1, phydbl u2, phydbl u3, phydbl t0, phydbl t2, phydbl t3, + phydbl *t_min, phydbl *t_max, phydbl nu, phydbl p_thresh, t_tree *tree) +{ + int n_eval; + int i; + phydbl sum_cdf; + phydbl *cdf; + phydbl t1; + phydbl mint2t3; + + mint2t3 = MIN(t2,t3); + n_eval = 5; + + cdf = (phydbl *)mCalloc(n_eval,sizeof(phydbl)); + + sum_cdf = .0; + for(i=0;irates->min_rate,tree->rates->max_rate) * + Dnorm_Trunc(u2,u1,SQRT(nu*(t2-t1)),tree->rates->min_rate,tree->rates->max_rate) * + Dnorm_Trunc(u3,u1,SQRT(nu*(t3-t1)),tree->rates->min_rate,tree->rates->max_rate) * + (mint2t3 - t0) / (n_eval + 1); + if(i) cdf[i] += cdf[i-1]; + } + sum_cdf = cdf[i-1]; + + for(i=0;i p_thresh) + { + *t_min = t0 + (i + 1)*(mint2t3 - t0)/(n_eval + 1); + break; + } + + for(i=0;i (1. - p_thresh)) + { + *t_max = t0 + (i + 1)*(mint2t3 - t0)/(n_eval + 1); + break; + } + + Free(cdf); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl RATES_Get_Correction_Factor(phydbl mode, phydbl sd, int *err, t_tree *tree) +{ + + phydbl K,X0,X1,X2,Y0,Y1,Y2; + phydbl eps=0.01; + phydbl A,B; + phydbl slope,inter; + phydbl denom; + + *err = NO; + + + /* DO NOTHING */ + return 0.0; + + + + A = tree->rates->min_rate / sd; + B = tree->rates->max_rate / sd; + K = mode / sd; + + X0 = 0.; +/* Y0 = Dnorm(X0-K,.0,1.)/(1. - Pnorm(X0-K,.0,1.)) - X0; */ + Y0 = (Dnorm(A-K+X0,.0,1.)-Dnorm(B-K+X0,.0,1.))/(Pnorm(B-K+X0,.0,1.)-Pnorm(A-K+X0,.0,1.)) - X0; + + X1 = .1; +/* Y1 = Dnorm(X1-K,.0,1.)/(1. - Pnorm(X1-K,.0,1.)) - X1; */ + Y1 = (Dnorm(A-K+X1,.0,1.)-Dnorm(B-K+X1,.0,1.))/(Pnorm(B-K+X1,.0,1.)-Pnorm(A-K+X1,.0,1.)) - X1; + +/* printf("\n. ^^ mean=%f sd=%f",mode,sd); */ + +/* printf("\n. X0=%f Y0=%f X1=%f Y1=%f",X0,Y0,X1,Y1); */ + + do + { + + slope = (Y1-Y0)/(X1-X0); + inter = Y0 - X0*(Y1-Y0)/(X1-X0); + + X2 = -inter/slope; + + denom = (Pnorm(B-K+X2,.0,1.)-Pnorm(A-K+X2,.0,1.)); + + if(denom < 1.E-10) + { +/* printf("\n. X2 = %f Y2=%f num=%f denom=%f Y1=%f Y0=%f X1=%f X0=%f mode=%f sd=%f",X2,Y2,num,denom,Y1,Y0,X1,X0,mode,sd); */ + *err = YES; + break; + } + +/* Y2 = Dnorm(X2-K,.0,1.)/(1. - Pnorm(X2-K,.0,1.)) - X2; */ + Y2 = (Dnorm(A-K+X2,.0,1.)-Dnorm(B-K+X2,.0,1.))/(Pnorm(B-K+X2,.0,1.)-Pnorm(A-K+X2,.0,1.)) - X2; + + /* printf("\n. X2 = %f Y2=%f num=%f denom=%f Y1=%f Y0=%f X1=%f X0=%f",X2,Y2,num,denom,Y1,Y0,X1,X0); */ + + if(X2 > X1) + { + X0 = X1; + X1 = X2; + Y0 = Y1; + Y1 = Y2; + } + else + { + X1 = X0; + X0 = X2; + Y1 = Y0; + Y0 = Y2; + } + }while(fabs(Y2) > eps); + +/* printf("\n. shift = %f X2=%f Y2 = %f",X2*sd,X2,Y2); */ + + return X2 * sd; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Sample_Average_Rate(t_node *a, t_node *d, t_tree *tree) +{ + return(-1.); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Update_Mean_Br_Len(int iter, t_tree *tree) +{ + int i,dim; + phydbl *mean; + + if(tree->rates->update_mean_l == NO) return; + + dim = 2*tree->n_otu-3; + mean = tree->rates->mean_l; + + for(i=0;ia_edges[i]->l->v; + mean[i] /= (phydbl)(iter+1); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Update_Cov_Br_Len(int iter, t_tree *tree) +{ + int i,j,dim; + phydbl *mean,*cov; + + if(tree->rates->update_cov_l == NO) return; + + dim = 2*tree->n_otu-3; + mean = tree->rates->mean_l; + cov = tree->rates->cov_l; + + for(i=0;imcmc->run; + cov[i*dim+j] += tree->a_edges[i]->l->v * tree->a_edges[j]->l->v; + cov[i*dim+j] /= (phydbl)(tree->mcmc->run+1); + cov[i*dim+j] -= mean[i]*mean[j]; + + if(i == j && cov[i*dim+j] < MIN_VAR_BL) cov[i*dim+j] = MIN_VAR_BL; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Set_Mean_L(t_tree *tree) +{ + int i; + For(i,2*tree->n_otu-3) + { + tree->rates->mean_l[i] = tree->a_edges[i]->l->v; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Record_Times(t_tree *mixt_tree) +{ + int i; + t_tree *tree; + + tree = mixt_tree; + do + { + if(tree->rates->nd_t_recorded == YES) + { + PhyML_Fprintf(stderr,"\n. Overwriting recorded times is forbidden.\n"); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + For(i,2*tree->n_otu-1) tree->rates->buff_t[i] = tree->rates->nd_t[i]; + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Reset_Times(t_tree *mixt_tree) +{ + int i; + t_tree *tree; + + tree = mixt_tree; + do + { + tree->rates->nd_t_recorded = NO; + for(i=0;i<2*tree->n_otu-1;++i) tree->rates->nd_t[i] = tree->rates->buff_t[i]; + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Record_Rates(t_tree *tree) +{ + int i; + + if(tree->rates->br_r_recorded == YES) + { + PhyML_Fprintf(stderr,"\n. Overwriting recorded rates is forbidden.\n"); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + for(i=0;i<2*tree->n_otu-2;++i) tree->rates->buff_br_r[i] = tree->rates->br_r[i]; + for(i=0;i<2*tree->n_otu-1;++i) tree->rates->buff_nd_r[i] = tree->rates->nd_r[i]; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Reset_Rates(t_tree *tree) +{ + int i; + tree->rates->br_r_recorded = NO; + for(i=0;i<2*tree->n_otu-2;++i) tree->rates->br_r[i] = tree->rates->buff_br_r[i]; + for(i=0;i<2*tree->n_otu-1;++i) tree->rates->nd_r[i] = tree->rates->buff_nd_r[i]; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Set_Clock_And_Nu_Max(t_tree *tree) +{ + phydbl dt,nu; + phydbl min_t; + int i; + phydbl step; + phydbl l_max; + phydbl max_clock; + phydbl r_max; + phydbl tune; + phydbl pa,pb; + + if(tree->rates->model == THORNE || + tree->rates->model == GUINDON) + { + tune = 1.05; + r_max = tree->rates->max_rate; + l_max = tree->mod->l_max; + + min_t = .0; + for(i=0;i<2*tree->n_otu-1;++i) if(tree->rates->t_prior_min[i] < min_t) min_t = tree->rates->t_prior_min[i]; + + dt = FABS(min_t); + max_clock = l_max / dt; + + nu = 1.E-10; + step = 1.E-1; + do + { + do + { + nu += step; + pa = Dnorm(0.0, 0.0,SQRT(nu*dt)); + pb = Dnorm(r_max,0.0,SQRT(nu*dt)); + }while(pa/pb > tune); + nu -= step; + step /= 10.; + }while(step > 1.E-10); + + tree->rates->max_nu = nu; + /* tree->rates->max_nu = 1.0; */ + tree->rates->max_clock = max_clock; + + PhyML_Printf("\n. Clock rate parameter upper bound set to %f expected subst./site/time unit",tree->rates->max_clock); + PhyML_Printf("\n. Autocorrelation parameter upper bound set to %f",tree->rates->max_nu); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void RATES_Set_Birth_Rate_Boundaries(t_tree *tree) +{ + phydbl lbda; + phydbl p_above_min,p_below_max; + phydbl min,max; + int assign = YES; + + min = -0.01*tree->rates->t_prior_max[tree->n_root->num]; + max = -100.*tree->rates->t_prior_min[tree->n_root->num]; + + for(lbda = 0.0001; lbda < 10; lbda+=0.0001) + { + p_above_min = 1. - POW(1.-exp(-lbda*min),tree->n_otu); + p_below_max = POW(1.-exp(-lbda*max),tree->n_otu); + + if(p_above_min < 1.E-10) + { + tree->rates->birth_rate_max = lbda; + break; + } + if(p_below_max > 1.E-10 && assign==YES) + { + assign = NO; + tree->rates->birth_rate_min = lbda; + } + } + + /* tree->rates->birth_rate_min = 1.E-6; */ + /* tree->rates->birth_rate_max = 1.; */ + PhyML_Printf("\n. Birth rate lower bound set to %f.",tree->rates->birth_rate_min); + PhyML_Printf("\n. Birth rate upper bound set to %f.",tree->rates->birth_rate_max); + +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl RATES_Get_Mean_Rate_In_Subtree(t_node *root, t_tree *tree) +{ + phydbl sum; + int n; + + sum = 0.0; + n = 0; + + if(root->tax == NO) + { + if(root == tree->n_root) + { + RATES_Get_Mean_Rate_In_Subtree_Pre(root,root->v[2],&sum,&n,tree); + RATES_Get_Mean_Rate_In_Subtree_Pre(root,root->v[1],&sum,&n,tree); + } + else + { + int i; + for(i=0;i<3;i++) + { + if(root->v[i] != root->anc && root->b[i] != tree->e_root) + { + RATES_Get_Mean_Rate_In_Subtree_Pre(root,root->v[i],&sum,&n,tree); + } + } + } + return sum/(phydbl)n; + } + else + { + return 0.0; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Get_Mean_Rate_In_Subtree_Pre(t_node *a, t_node *d, phydbl *sum, int *n, t_tree *tree) +{ + /* (*sum) += exp(tree->rates->nd_r[d->num]); */ + + if(tree->rates->model == LOGNORMAL || + tree->rates->model == THORNE || + tree->rates->model == STRICTCLOCK) + { + (*sum) += tree->rates->br_r[d->num]; + } + else if(tree->rates->model == GUINDON) + { + (*sum) += tree->rates->nd_r[d->num]; + } + + else assert(FALSE); + + (*n) += 1; + + if(d->tax == YES) return; + else + { + int i; + for(i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + RATES_Get_Mean_Rate_In_Subtree_Pre(d,d->v[i],sum,n,tree); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +char *RATES_Get_Model_Name(int model) +{ + char *s; + + s = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + switch(model) + { + case GUINDON : {strcpy(s,"geometric Brownian"); break;} + case THORNE : {strcpy(s,"gbd"); break;} + case LOGNORMAL : {strcpy(s,"lognormal"); break;} + case STRICTCLOCK : {strcpy(s,"strict clock"); break;} + default : + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + break; + } + } + return s; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void RATES_Get_Survival_Ranks(t_tree *tree) +{ + int i,j; + phydbl rank; + + + For(i,2*tree->n_otu-2) + { + rank = 0.; + For(j,2*tree->n_otu-2) + { + if(tree->rates->br_r[i] > tree->rates->br_r[j]) rank += 1.0; + } + + tree->rates->survival_rank[i] = rank; + } + + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int RATES_Check_Edge_Length_Consistency(t_tree *mixt_tree) +{ + int i; + t_tree *tree; + + tree = mixt_tree; + + do + { + if(tree->is_mixt_tree == YES) tree = tree->next; + + for(i=0;i<2*tree->n_otu-3;++i) + { + if(tree->a_edges[i]->left->anc == tree->a_edges[i]->rght) + { + if(Are_Equal(tree->rates->cur_l[tree->a_edges[i]->left->num], + tree->a_edges[i]->l->v, + 1.E-5) == NO) + { + PhyML_Fprintf(stderr,"\n. cur_l: %G l: %G is_root: %d", + tree->rates->cur_l[tree->a_edges[i]->left->num], + tree->a_edges[i]->l->v, + tree->a_edges[i] == tree->e_root); + return 0; + } + } + + if(tree->a_edges[i]->rght->anc == tree->a_edges[i]->left) + { + if(Are_Equal(tree->rates->cur_l[tree->a_edges[i]->rght->num], + tree->a_edges[i]->l->v, + 1.E-5) == NO) + { + PhyML_Fprintf(stderr,"\n. cur_l: %G l: %G is_root: %d", + tree->rates->cur_l[tree->a_edges[i]->rght->num], + tree->a_edges[i]->l->v, + tree->a_edges[i] == tree->e_root); + return 0; + } + } + } + + tree = tree->next; + } + while(tree); + + return 1; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ diff --git a/phyml/rates.h b/phyml/rates.h index 696e484..461167b 100644 --- a/phyml/rates.h +++ b/phyml/rates.h @@ -10,14 +10,177 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef RATES_H #define RATES_H -void RATES_Monte_Carlo_Mean_Rates(arbre *tree); -void RATES_Monte_Carlo_Mean_Rates_Pre(node *a, node *d, edge *b, phydbl curr_rate, arbre *tree); -void RATES_Print_Rates(arbre *tree); -void RATES_Print_Rates_Pre(node *a, node *d, edge *b, arbre *tree); -trate *RATES_Make_Rate_Struct(arbre *tree); -void RATES_Init_Rate_Struct(trate *rates, arbre *tree); +#include "utilities.h" +#include "spr.h" +#include "lk.h" +#include "optimiz.h" +#include "bionj.h" +#include "models.h" +#include "free.h" +#include "help.h" +#include "simu.h" +#include "eigen.h" +#include "pars.h" +#include "alrt.h" +#include "time.h" +#include "m4.h" +#include "draw.h" +#include "mcmc.h" +#include "stats.h" + +void RATES_Monte_Carlo_Mean_Rates(t_tree *tree); +void RATES_Monte_Carlo_Mean_Rates_Pre(t_node *a, t_node *d, t_edge *b, phydbl curr_rate, t_tree *tree); +void RATES_Print_Rates(t_tree *tree); +void RATES_Print_Rates_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +t_rate *RATES_Make_Rate_Struct(int n_otu); +void RATES_Init_Rate_Struct(t_rate *rates, t_rate *existing_rates, int n_otu); +void RATES_Classify_Branches(t_tree *tree); +void RATES_Adjust_Rates(t_tree *tree); +void RATES_Adjust_Rates_Local_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void RATES_Adjust_Rates_Local(t_node *a, t_node *d, t_edge *b1, t_tree *tree); +void RATES_Record_T(t_tree *tree); +void RATES_Restore_T(t_tree *tree); +void RATES_Monte_Carlo_Mean_Rates_Core(phydbl t_lim_sup, phydbl t_lim_inf, phydbl *curr_rate, phydbl *mean_rate, phydbl lexp, phydbl alpha); +phydbl RATES_Lk_Rates(t_tree *tree); +void RATES_Lk_Rates_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void RATES_Fill_Node_Rates_Pre(t_node *a, t_node *d, t_edge *b, phydbl *node_r, t_tree *tree); +void RATES_Fill_Node_Rates(phydbl *node_r, t_tree *tree); +void RATES_Optimize_Node_Times_Serie_Fixed_Br_Len(t_node *a, t_node *d, t_tree *tree); +void RATES_Optimize_Lexp(t_tree *tree); +void RATES_Round_Optimize(t_tree *tree); +void RATES_Optimize_Lexp(t_tree *tree); +void RATES_Optimize_Alpha(t_tree *tree); +phydbl RATES_Dmu(phydbl mu, int n_jumps, phydbl dt, phydbl a, phydbl b, phydbl lexp, int min_n, int jps_dens); +phydbl RATES_Dr_X_Dx(phydbl r, phydbl mu, phydbl y, phydbl dt, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu_Given_Y_Trpzd(phydbl mu, phydbl y, phydbl dt, phydbl a, phydbl b, phydbl lexp, + int nsteps, phydbl beg, phydbl end, phydbl prevs); +phydbl RATES_Dmu_Given_Y_Std(phydbl mu, phydbl y, phydbl dt, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu_Given_Y_Romb(phydbl mu, phydbl y, phydbl dt, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu_Given_Y(phydbl mu, phydbl y, phydbl dt, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dy_Given_Mu(phydbl mu, phydbl y, phydbl dt, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu2_Given_Y_X_Dy_Given_Mu1(phydbl mu1, phydbl mu2, phydbl y, phydbl dt1, phydbl dt2, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu2_Given_Mu1_Trpz(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, phydbl a, phydbl b, phydbl lexp, + int nsteps, phydbl beg, phydbl end, phydbl prevs); +phydbl RATES_Dmu2_And_Mu1(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu2_Given_Mu1(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu2_Given_Mu1_Romb(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, phydbl a, phydbl b, phydbl lexp); +void RATES_Random_Branch_Lengths(t_tree *tree); +void RATES_Bracket_N_Jumps(int *up, int *down, phydbl param); +void RATES_Set_Node_Times(t_tree *tree); +void RATES_Set_Node_Times_Pre(t_node *a, t_node *d, t_tree *tree); +void RATES_Optimize_Node_Times(t_tree *tree); +phydbl RATES_Exp_Y(phydbl mu1, phydbl mu2, phydbl dt1, phydbl lexp); +phydbl RATES_Dmu2_Given_Mu1_Bis(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, phydbl alpha, phydbl beta, phydbl lexp); +void RATES_Replace_Br_Lengths_By_Rates_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void RATES_Replace_Br_Lengths_By_Rates(t_tree *tree); + +void RATES_Get_Mean_Rates(t_tree *tree); +void RATES_Get_Mean_Rates_Pre(t_node *a, t_node *d, t_edge *b, phydbl r_a, t_tree *tree); +void RATES_Expect_Number_Subst(phydbl t_beg, phydbl t_end, phydbl r_beg, int *n_jumps, phydbl *mean_r, phydbl *r_end, t_rate *rates, t_tree *tree); +void RATES_Optimize_Clock_Rate(t_tree *tree); +phydbl RATES_Dmu1_Given_Lbda_And_Mu2(phydbl lbda, phydbl mu1, phydbl mu2, phydbl alpha, phydbl beta); +phydbl RATES_Dmu1_And_Mu2_One_Jump_Trpz(phydbl mu1, phydbl mu2, phydbl a, phydbl b, + int nsteps, phydbl beg, phydbl end, phydbl prevs); +phydbl RATES_Dmu1_And_Mu2_One_Jump_One_Interval(phydbl mu1, phydbl mu2, phydbl a, phydbl b); +phydbl RATES_Dmu1_And_Mu2_One_Jump_Two_Intervals(phydbl dt1, phydbl dt2, phydbl mu1, phydbl mu2, phydbl a, phydbl b); + +phydbl RATES_Dmu1_And_Mu2_One_Jump_Old(phydbl mu1, phydbl mu2, phydbl a, phydbl b); + +phydbl RATES_Dmu2_And_Min_N_Given_Mu1(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, int n_min, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu2_And_Mu1_Given_N(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, int n, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Lk_Rates_Core(phydbl br_r_a, phydbl br_r_d, phydbl nd_r_a, phydbl nd_r_d, int n_a, int n_d, phydbl dt_a, phydbl dt_d, t_tree *tree); +void RATES_Init_Triplets(t_tree *tree); +phydbl RATES_Lk_Change_One_Time(t_node *n, phydbl new_t, t_tree *tree); +void RATES_Update_Triplet(t_node *n, t_tree *tree); +void RATES_Print_Triplets(t_tree *tree); +phydbl RATES_Lk_Change_One_Rate(t_node *d, phydbl new_rate, t_tree *tree); +phydbl RATES_Dmu2_And_Mu1_Given_Min_N(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, int n_min, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu2_And_Mu1_Given_N_Normal(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, int n, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Coeff_Corr(phydbl alpha, phydbl beta, int n1, int n2); +phydbl RATES_Dmu2_And_Mu1_Given_N_Full(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, int n, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu1_Given_V_And_N(phydbl mu1, phydbl v, int n, phydbl dt1, phydbl a, phydbl b); +phydbl RATES_Yule(t_tree *tree); +phydbl RATES_Check_Mean_Rates(t_tree *tree); +void RATES_Check_Mean_Rates_Pre(t_node *a, t_node *d, t_edge *b, phydbl *sum, t_tree *tree); +void RATES_Discretize_Rates(t_tree *tree); +void RATES_Discretize_Rates_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +phydbl RATES_Dmu_Given_V_And_MinN(phydbl mu, phydbl dt, phydbl v, int minn, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Dmu_One(phydbl mu, phydbl dt, phydbl a, phydbl b, phydbl lexp); +phydbl RATES_Compound_Core(phydbl mu1, phydbl mu2, int n1, int n2, phydbl dt1, phydbl dt2, phydbl alpha, phydbl beta, phydbl lexp, phydbl eps, int approx); +void RATES_Record_Rates(t_tree *tree); +void RATES_Reset_Rates(t_tree *tree); +void RATES_Record_Times(t_tree *tree); +void RATES_Reset_Times(t_tree *tree); +void RATES_Update_T_Rates_Pre(t_node *a, t_node *d, t_tree *tree); +void RATES_Update_T_Rates(t_tree *tree); +void RATES_Get_Rates_From_Bl(t_tree *tree); +phydbl RATES_Compound_Core_Joint(phydbl mu1, phydbl mu2, int n1, int n2, phydbl dt1, phydbl dt2, + phydbl alpha, phydbl beta, phydbl lexp, phydbl eps, int approx); +phydbl RATES_Dmu_Joint(phydbl mu, int n, phydbl dt, phydbl a, phydbl b, phydbl lexp, int min_n); +phydbl RATES_Compound_Core_Marginal(phydbl mu1, phydbl mu2, phydbl dt1, phydbl dt2, phydbl alpha, + phydbl beta, phydbl lexp, phydbl eps, int approx); +phydbl RATES_Lk_Jumps(t_tree *tree); +void RATES_Posterior_Rates(t_tree *tree); +void RATES_Posterior_One_Rate(t_node *a, t_node *d, int traversal, t_tree *tree); +void RATES_Free_Rates(t_rate *rates); +void RATES_Initialize_True_Rates(t_tree *tree); +void RATES_Posterior_Times(t_tree *tree); +void RATES_Posterior_One_Time(t_node *a, t_node *d, int traversal, t_tree *tree); +void RATES_Update_Cur_Bl(t_tree *tree); +void RATES_Update_Cur_Bl_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void RATES_Get_Cov_Matrix_Rooted(phydbl *unroot_cov, t_tree *tree); +void RATES_Get_Cov_Matrix_Rooted_Pre(t_node *a, t_node *d, t_edge *b, phydbl *cov, t_tree *tree); +void RATES_Bl_To_Ml(t_tree *tree); +void RATES_Bl_To_Ml_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +int RATES_Check_Node_Times(t_tree *tree); +void RATES_Check_Node_Times_Pre(t_node *a, t_node *d, int *err, t_tree *tree); +void RATES_Covariance_Mu(t_tree *tree); +void RATES_Variance_Mu_Pre(t_node *a, t_node *d, t_tree *tree); +void RATES_Fill_Lca_Table(t_tree *tree); +void RATES_Posterior_Clock_Rate(t_tree *tree); +void RATES_Get_Conditional_Variances(t_tree *tree); +void RATES_Get_All_Reg_Coeff(t_tree *tree); +void RATES_Posterior_Time_Root(t_tree *tree); +void RATES_Get_Trip_Conditional_Variances(t_tree *tree); +void RATES_Get_All_Trip_Reg_Coeff(t_tree *tree); +void RATES_Check_Lk_Rates(t_tree *tree, int *err); +phydbl RATES_Expected_Tree_Length(t_tree *tree); +void RATES_Expected_Tree_Length_Pre(t_node *a, t_node *d, phydbl eranc, phydbl *mean, int *n, t_tree *tree); +void RATES_Normalise_Rates(t_tree *tree); +phydbl RATES_Check_Mean_Rates_True(t_tree *tree); +phydbl RATES_Find_Min_Dt_Bisec(phydbl r0, phydbl r1, phydbl t0, phydbl t1, phydbl nu, phydbl threshp, int inf); +phydbl RATES_Find_Max_Dt_Bisec(phydbl r0, phydbl r1, phydbl t0, phydbl t1, phydbl nu, phydbl threshp, int inf); +void RATES_Min_Max_Interval(phydbl u0, phydbl u1, phydbl u2, phydbl u3, phydbl t0, phydbl t2, phydbl t3, + phydbl *t_min, phydbl *t_max, phydbl nu, phydbl p_thresh, t_tree *tree); + + +phydbl RATES_Get_Correction_Factor(phydbl mode, phydbl sd, int *err, t_tree *tree); +phydbl RATES_Average_Substitution_Rate(t_tree *tree); +void RATES_Update_Norm_Fact(t_tree *tree); +void RATES_Update_Mean_Br_Len(int iter, t_tree *tree); +void RATES_Update_Cov_Br_Len(int iter, t_tree *tree); +void RATES_Set_Mean_L(t_tree *tree); +void RATES_Fill_All_Param(t_rate *rate, t_tree *tree); +void RATES_Record_Rates(t_tree *tree); +void RATES_Reset_Rates(t_tree *tree); +phydbl RATES_Average_Rate(t_tree *tree); +void RATES_Set_Clock_And_Nu_Max(t_tree *tree); +phydbl RATES_Lk_Linreg(t_tree *tree); +phydbl RATES_Get_Mean_Rate_In_Subtree(t_node *root, t_tree *tree); +void RATES_Get_Mean_Rate_In_Subtree_Pre(t_node *a, t_node *d, phydbl *sum, int *n, t_tree *tree); +char *RATES_Get_Model_Name(int model); +void RATES_Get_Survival_Ranks(t_tree *tree); +void RATES_Bl_To_Bl(t_tree *tree); +void RATES_Bl_To_Bl_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void RATES_Set_Birth_Rate_Boundaries(t_tree *tree); +void RATES_Copy_Rate_Struct(t_rate *from, t_rate *to, int n_otu); +void RATES_Duplicate_Calib_Struct(t_tree *from, t_tree *to); +int RATES_Check_Edge_Length_Consistency(t_tree *tree); +phydbl RATES_Realized_Substitution_Rate(t_tree *tree); #endif diff --git a/phyml/rwrapper.c b/phyml/rwrapper.c new file mode 100644 index 0000000..e53a9a8 --- /dev/null +++ b/phyml/rwrapper.c @@ -0,0 +1,162 @@ +#include "rwrapper.h" +/* #include */ +/* #include */ + +/*********************************************************/ +/*********************************************************/ +/*********************************************************/ +/*********************************************************/ +/*********************************************************/ + +/* void RWRAPPER_Min_Number_Of_Tip_Permut(char **tree_file_name, char **coord_file_name, phydbl *res) */ +/* { */ +/* t_tree *tree; */ +/* option *io; */ +/* FILE *fp_tree_file, *fp_coord_file; */ +/* int i; */ + + +/* srand(time(NULL)); rand(); */ + +/* /\\* Rprintf("%s\n",tree_file_name[0]); *\\/ */ +/* /\\* Rprintf("%s\n",coord_file_name[0]); *\\/ */ + +/* fp_tree_file = (FILE *)fopen(tree_file_name[0],"r"); */ +/* fp_coord_file = (FILE *)fopen(coord_file_name[0],"r"); */ + +/* io = (option *)Make_Input(); */ +/* io->fp_in_tree = fp_tree_file; */ +/* Read_Tree_File(io); */ +/* tree = io->treelist->tree[0]; */ +/* tree->io = io; */ + +/* tree->io->z_scores = (phydbl *)mCalloc(tree->n_otu,sizeof(phydbl)); */ + +/* /\\* for(i=0;in_otu;i++) tree->io->z_scores[i] = TIPO_Read_One_Taxon_Zscore(fp_coord_file,tree->noeud[i]->name,1,tree); *\\/ */ +/* /\\* TIPO_Normalize_Zscores(tree); *\\/ */ +/* /\\* TIPO_Get_Min_Number_Of_Tip_Permut(tree); *\\/ */ +/* /\\* res[0] = (phydbl)tree->tip_order_score; *\\/ */ + + +/* for(i=0;in_otu;i++) tree->io->z_scores[i] = TIPO_Read_One_Taxon_Zscore(fp_coord_file,tree->a_nodes[i]->name,1,tree); */ +/* Free_Bip(tree); */ +/* Alloc_Bip(tree); */ +/* Get_Bip(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); */ +/* TIPO_Get_Tips_Y_Rank_From_Zscores(tree); */ +/* /\\* TIPO_Get_Tips_Y_Rank(tree); *\\/ */ + +/* tree->geo_mig_sd = 1.; */ +/* Generic_Brent_Lk(&(tree->geo_mig_sd), */ +/* 1.E-5,1.E+2,1.E-6, */ +/* 100,NO, */ +/* &Optwrap_Geo_Lk, */ +/* NULL,tree,NULL); */ + +/* res[0] = (phydbl)tree->geo_mig_sd; */ +/* /\\* for(i=0;in_otu;i++) Rprintf("\n.. %f",tree->io->z_scores[i]); *\\/ */ +/* /\\* printf("\n>> sd: %f",tree->geo_mig_sd); *\\/ */ + +/* fclose(fp_tree_file); */ +/* fclose(fp_coord_file); */ + +/* } */ + +/*********************************************************/ + +void RWRAPPER_Log_Dnorm(phydbl *x, phydbl *mean, phydbl *sd, phydbl *res) +{ + int err; + err = NO; + *res = Log_Dnorm(*x,*mean,*sd,&err); +} + +/*********************************************************/ + +void RWRAPPER_Integrated_Geometric_Brownian_Bridge_Mean(phydbl *T, phydbl *A, phydbl *B, phydbl *u, phydbl *mean) +{ + Integrated_Geometric_Brownian_Bridge_Mean(*T,*A,*B,*u,mean); +} + +/*********************************************************/ + +void RWRAPPER_Integrated_Geometric_Brownian_Bridge_Var(phydbl *T, phydbl *A, phydbl *B, phydbl *u, phydbl *var) +{ + Integrated_Geometric_Brownian_Bridge_Var(*T,*A,*B,*u,var); +} + +/* /\*********************************************************\/ */ + +/* void RWRAPPER_Rnorm_Trunc(phydbl *mean, phydbl *sd, phydbl *min, phydbl *max, phydbl *res) */ +/* { */ +/* *res = Rnorm_Trunc(*mean,*sd,*min,*max); */ +/* } */ + +/* void RWRAPPER_Cholesky_Decomp(double *A, int *dim) */ +/* { */ +/* Cholesky_Decomp(A,*dim); */ +/* } */ + +/*********************************************************/ + +/* void RWRAPPER_Bivariate_Normal_Density(phydbl *x, phydbl *y, phydbl *mux, phydbl *muy, phydbl *sdx, phydbl *sdy, phydbl *rho, phydbl *dens) */ +/* { */ +/* *dens = Bivariate_Normal_Density(*x,*y,*mux,*muy,*sdx,*sdy,*rho); */ +/* } */ + +/* /\*********************************************************\/ */ + +/* void RWRAPPER_Dmu2_And_Mu1_Given_Min_N(phydbl *mu1, phydbl *mu2, phydbl *dt1, phydbl *dt2, int *n_min, phydbl *a, phydbl *b, phydbl *lexp, phydbl *dens) */ +/* { */ +/* *dens = RATES_Dmu2_And_Mu1_Given_Min_N(*mu1, *mu2, *dt1, *dt2, *n_min, *a, *b, *lexp); */ +/* } */ +/* /\*********************************************************\/ */ + +/* void RWRAPPER_Dgamma(phydbl *x, phydbl *shape, phydbl *scale, phydbl *dens) */ +/* { */ +/* *dens = Dgamma(*x,*shape,*scale); */ +/* } */ + +/* /\*********************************************************\/ */ + +/* void RWRAPPER_Dnorm(phydbl *x, phydbl *mean, phydbl *var, double *dens) */ +/* { */ +/* *dens = Dnorm_Moments(*x,*mean,*var); */ +/* } */ +/* /\*********************************************************\/ */ + +/* void RWRAPPER_Dmu_One(phydbl *mu, phydbl *dt, phydbl *a, phydbl *b, phydbl *lexp, double *dens) */ +/* { */ +/* *dens = RATES_Dmu_One(*mu,*dt,*a,*b,*lexp); */ +/* } */ +/* /\*********************************************************\/ */ + +/* void RWRAPPER_Dr_X_Dx(double *r, double *mu, double *y, double *dt, double *a, double *b, double *lexp, double *dens) */ +/* { */ +/* *dens = RATES_Dr_X_Dx(*r,*mu,*y,*dt,*a,*b,*lexp); */ +/* } */ + +/* /\*********************************************************\/ */ + +/* void RWRAPPER_Dmu_Given_Y(double *mu, double *y, double *dt, double *a, double *b, double *lexp, double *dens) */ +/* { */ +/* *dens = RATES_Dmu_Given_Y(*mu,*y,*dt,*a,*b,*lexp); */ +/* } */ + +/* /\*********************************************************\/ */ + +/* void RWRAPPER_Dmu2_And_Mu1(double *mu1, double *mu2, double *dt1, double *dt2, double *a, double *b, double *lexp, double *dens) */ +/* { */ +/* *dens = RATES_Dmu2_And_Mu1(*mu1,*mu2,*dt1,*dt2,*a,*b,*lexp); */ +/* } */ + +/* /\*********************************************************\/ */ + +/* void RWRAPPER_Dmu2_Given_Mu1(double *mu1, double *mu2, double *dt1, double *dt2, double *a, double *b, double *lexp, double *dens) */ +/* { */ +/* /\* *dens = RATES_Dmu2_Given_Mu1(*mu1,*mu2,*dt1,*dt2,*a,*b,*lexp); *\/ */ +/* *dens = RATES_Dmu2_Given_Mu1_Bis(*mu1,*mu2,*dt1,*dt2,*a,*b,*lexp); */ +/* } */ + +/* /\*********************************************************\/ */ + + diff --git a/phyml/rwrapper.h b/phyml/rwrapper.h new file mode 100644 index 0000000..6ae40b7 --- /dev/null +++ b/phyml/rwrapper.h @@ -0,0 +1,47 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef RWRAPPER_H +#define RWRAPPER_H + +#include "utilities.h" +#include "rates.h" +#include "eigen.h" +#include "io.h" +#include "stats.h" +#include "tiporder.h" + +/* void RWRAPPER_Dmu2_Given_Mu1_And_Min_N(phydbl *mu1, phydbl *mu2, phydbl *dt1, phydbl *dt2, int *n_min, phydbl *a, phydbl *b, phydbl *lexp, phydbl *dens); */ +/* void RWRAPPER_Dnorm(phydbl *x, phydbl *mean, phydbl *var, double *dens); */ +/* void RWRAPPER_Dmu(phydbl *mu, phydbl *dt, phydbl *a, phydbl *b, phydbl *lexp, double *dens); */ +/* void RWRAPPER_Dr_X_Dx(double *r, double *mu, double *y, double *dt, double *a, double *b, double *lexp, double *dens); */ +/* void RWRAPPER_Dmu_Given_Y(double *mu, double *y, double *dt, double *a, double *b, double *lexp, double *dens); */ +/* void RWRAPPER_Dmu(phydbl *mu, phydbl *dt, phydbl *a, phydbl *b, phydbl *lexp, double *dens); */ +/* void RWRAPPER_Dmu2_Given_Mu1(double *mu1, double *mu2, double *dt1, double *dt2, double *a, double *b, double *lexp, double *dens); */ +/* void RWRAPPER_Dgamma(phydbl *x, phydbl *shape, phydbl *scale, phydbl *dens); */ +/* void RWRAPPER_Bivariate_Normal_Density(phydbl *x, phydbl *y, phydbl *mux, phydbl *muy, phydbl *sdx, phydbl *sdy, phydbl *rho, phydbl *dens); */ +/* void RWRAPPER_Dmu2_And_Mu1_Given_Min_N(phydbl *mu1, phydbl *mu2, phydbl *dt1, phydbl *dt2, int *n_min, phydbl *a, phydbl *b, phydbl *lexp, phydbl *dens); */ +/* void RWRAPPER_RATES_Dmu1_And_Mu2_One_Jump_Two_Intervals(phydbl *dt1, phydbl *dt2, phydbl *mu1, phydbl *mu2, phydbl *alpha, phydbl *beta, phydbl *dens); */ +/* void RWRAPPER_Dmu_One(phydbl *mu, phydbl *dt, phydbl *a, phydbl *b, phydbl *lexp, double *dens); */ +/* void RWRAPPER_Lk_Rates_Core(phydbl *mu1, phydbl *mu2, phydbl *dt1, phydbl *dt2, phydbl *a, phydbl *b, phydbl *lexp, phydbl *eps, int *approx, phydbl *dens); */ +/* void RWRAPPER_Dmu2_And_Mu1(double *mu1, double *mu2, double *dt1, double *dt2, double *a, double *b, double *lexp, double *dens); */ +/* void RWRAPPER_Rnorm_Trunc(phydbl *mean, phydbl *sd, phydbl *min, phydbl *max, phydbl *res); */ +/* void RWRAPPER_Cholesky_Decomp(double *A, int *dim); */ +/* void RWRAPPER_Min_Number_Of_Tip_Permut(char **tree_file_name, char **coord_file_name, phydbl *res); */ +void RWRAPPER_Log_Dnorm(phydbl *x, phydbl *mean, phydbl *sd, phydbl *res); +void RWRAPPER_Integrated_Geometric_Brownian_Bridge_Mean(phydbl *T, phydbl *A, phydbl *B, phydbl *u, phydbl *mean); +void RWRAPPER_Integrated_Geometric_Brownian_Bridge_Var(phydbl *T, phydbl *A, phydbl *B, phydbl *u, phydbl *var); + + +#endif diff --git a/phyml/simu.c b/phyml/simu.c index 197d523..07a6049 100644 --- a/phyml/simu.c +++ b/phyml/simu.c @@ -1,7 +1,7 @@ /* PHYML : a program that computes maximum likelihood phylogenies from -DNA or AA homologous sequences +DNA or AA homologous sequences Copyright (C) Stephane Guindon. Oct 2003 onward @@ -10,174 +10,83 @@ the GNU public licence. See http://www.opensource.org for details. */ -#include "utilities.h" -#include "lk.h" -#include "optimiz.h" -#include "models.h" -#include "free.h" #include "simu.h" -#include "spr.h" -#include "pars.h" -#include "alrt.h" +#ifdef BEAGLE +#include "beagle_utils.h" +#endif -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Simu_Loop(arbre *tree) +void Simu_Loop(t_tree *tree) { - phydbl lk_old; - - do - { - lk_old = tree->c_lnL; - Simu(tree,1000); - Check_NNI_Five_Branches(tree); - } - while(tree->c_lnL > lk_old + tree->mod->s_opt->min_diff_lk_global); + return; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Simu(arbre *tree, int n_step_max) +int Simu(t_tree *tree, int n_step_max, phydbl delta_lnL, phydbl init_T, phydbl delta_T, int min_n_edges_traversed) { - phydbl old_loglk,n_iter,lambda; - int i,n_neg,n_tested,n_without_swap,n_tot_swap,step,it_lim_without_swap; - edge **sorted_b,**tested_b; - int each,each_invar,opt_free_param; - int recurr; - - sorted_b = (edge **)mCalloc(tree->n_otu-3,sizeof(edge *)); - tested_b = (edge **)mCalloc(tree->n_otu-3,sizeof(edge *)); - - old_loglk = UNLIKELY; - tree->c_lnL = UNLIKELY; - n_iter = 1.0; - it_lim_without_swap = (tree->mod->invar)?(8):(5); - n_tested = 0; - n_without_swap = 0; - step = 0; - each = 4; - lambda = .75; - each_invar = 2; - n_tot_swap = 0; - opt_free_param = 0; - recurr = 0; + phydbl old_loglk,delta; + unsigned int n_round; + time_t t_cur; - Update_Dirs(tree); - - if(tree->mod->s_opt->print) printf("\n\n. Starting simultaneous NNI moves...\n"); - - if(tree->lock_topo) - { - printf("\n. The tree topology is locked."); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - + tree->c_lnL = UNLIKELY; + delta = UNLIKELY; + old_loglk = UNLIKELY; + n_round = 0; + tree->annealing_temp = init_T; do { - ++step; - - if(step > n_step_max) break; - - each--; - each_invar--; - - tree->both_sides = 1; - Lk(tree); - - - if(tree->io->print_trace) - { - fprintf(tree->io->fp_out_trace,"[%f]%s\n",tree->c_lnL,Write_Tree(tree)); fflush(tree->io->fp_out_trace); - if(tree->io->print_site_lnl) Print_Site_Lk(tree,tree->io->fp_out_lk); fflush(tree->io->fp_out_lk); - } - - if(tree->mod->s_opt->print) - { - Print_Lk(tree,"[Topology ]"); -/* if(step > 1) (n_tested > 1)?(printf(" (%d NNIs)",n_tested)):(printf(" (%d NNI )",n_tested)); */ - } - - if((fabs(old_loglk-tree->c_lnL) < tree->mod->s_opt->min_diff_lk_global) || - (n_without_swap > it_lim_without_swap)) - { - break; - } - - - if(tree->c_lnL < old_loglk) - { - if(!Mov_Backward_Topo_Bl(tree,old_loglk,tested_b,n_tested)) - Exit("\n. Err: mov_back failed\n"); - if(!tree->n_swap) n_neg = 0; - - For(i,2*tree->n_otu-3) tree->t_edges[i]->l_old = tree->t_edges[i]->l; - Optimiz_All_Free_Param(tree,tree->mod->s_opt->print); - tree->both_sides = 1; - Lk(tree); - } - else - { - - if(!each) - { - opt_free_param = 1; - each = 4; - if(tree->mod->n_catg < tree->mod->n_catg) tree->mod->n_catg++; - Optimiz_All_Free_Param(tree,tree->mod->s_opt->print); - tree->both_sides = 1; - Lk(tree); - } - - old_loglk = tree->c_lnL; - Fill_Dir_Table(tree); - Fix_All(tree); - n_neg = 0; - For(i,2*tree->n_otu-3) - if((!tree->t_edges[i]->left->tax) && - (!tree->t_edges[i]->rght->tax)) - NNI(tree,tree->t_edges[i],0); - - - Select_Edges_To_Swap(tree,sorted_b,&n_neg); - Sort_Edges_NNI_Score(tree,sorted_b,n_neg); - Optimiz_Ext_Br(tree); - Update_Bl(tree,lambda); - - n_tested = 0; - For(i,(int)ceil((phydbl)n_neg*(lambda))) - tested_b[n_tested++] = sorted_b[i]; - - Make_N_Swap(tree,tested_b,0,n_tested); - - n_tot_swap += n_tested; - - if(n_tested > 0) n_without_swap = 0; - else n_without_swap++; - } - n_iter+=1.0; + for(int i=0;i<2*tree->n_otu-3;++i) tree->a_edges[i]->l->v *= Rgamma((phydbl)(0.2*n_round+1),(phydbl)(1./(0.2*n_round+1))); + old_loglk = tree->c_lnL; + Set_Both_Sides(NO,tree); + tree->tip_root = Rand_Int(0,tree->n_otu-1); + Lk(NULL,tree); + tree->n_edges_traversed = 0; + tree->fully_nni_opt = YES; + NNI_Traversal(tree->a_nodes[tree->tip_root], + tree->a_nodes[tree->tip_root]->v[0], + NULL, + tree->a_nodes[tree->tip_root]->b[0], + YES, + tree); + delta = tree->c_lnL - old_loglk; + tree->annealing_temp -= delta_T; + if(tree->annealing_temp < 0.0) tree->annealing_temp = 0.0; + n_round++; + time(&t_cur); + + PhyML_Printf("\n. %5ds lnL: %12G T: %12G %4d/%4d", + (int)(t_cur-tree->t_beg), + tree->c_lnL, + tree->annealing_temp, + tree->n_edges_traversed, + tree->n_otu); + + if((n_round >= n_step_max || tree->fully_nni_opt == YES) && Are_Equal(tree->annealing_temp,0.0,1.E-3) && delta < delta_lnL) break; } while(1); - - Round_Optimize(tree,tree->data); - Free(sorted_b); - Free(tested_b); + return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Simu_Pars(arbre *tree, int n_step_max) + +void Simu_Pars(t_tree *tree, int n_step_max) { phydbl old_pars,n_iter,lambda; int i,n_neg,n_tested,n_without_swap,n_tot_swap,step; - edge **sorted_b,**tested_b; + t_edge **sorted_b,**tested_b; int each; - - sorted_b = (edge **)mCalloc(tree->n_otu-3,sizeof(edge *)); - tested_b = (edge **)mCalloc(tree->n_otu-3,sizeof(edge *)); - + + sorted_b = (t_edge **)mCalloc(tree->n_otu-3,sizeof(t_edge *)); + tested_b = (t_edge **)mCalloc(tree->n_otu-3,sizeof(t_edge *)); + old_pars = 0; tree->c_pars = 0; n_iter = 1.0; @@ -185,13 +94,13 @@ void Simu_Pars(arbre *tree, int n_step_max) n_without_swap = 0; step = 0; each = 4; - lambda = .75; + lambda = 0.5; n_tot_swap = 0; - + Update_Dirs(tree); - - if(tree->mod->s_opt->print) printf("\n. Starting simultaneous NNI moves (parsimony criterion)...\n"); - + + if((tree->verbose > VL0) && (tree->io->quiet == NO)) PhyML_Printf("\n\n. Starting simultaneous NNI moves (parsimony criterion)...\n"); + do { ++step; @@ -200,55 +109,53 @@ void Simu_Pars(arbre *tree, int n_step_max) each--; - tree->both_sides = 1; - Pars(tree); + Set_Both_Sides(YES,tree); + Pars(NULL,tree); - if(tree->mod->s_opt->print) - { - Print_Pars(tree); - if(step > 1) (n_tested > 1)?(printf("[%4d NNIs]",n_tested)):(printf("[%4d NNI ]",n_tested)); - } + if((tree->verbose > VL0) && (tree->io->quiet == NO)) + { + Print_Pars(tree); + if(step > 1) (n_tested > 1)?(printf("[%4d NNIs]",n_tested)):(printf("[%4d NNI ]",n_tested)); + } + + + if(FABS(old_pars - tree->c_pars) < SMALL) break; - - if(old_pars == tree->c_pars) break; - if((tree->c_pars > old_pars) && (step > 1)) - { - if(tree->mod->s_opt->print) - printf("\n\n. Moving backward (topology) \n"); - if(!Mov_Backward_Topo_Pars(tree,old_pars,tested_b,n_tested)) - Exit("\n. Err: mov_back failed\n"); - if(!tree->n_swap) n_neg = 0; - - tree->both_sides = 1; - Pars(tree); - } - else - { - - old_pars = tree->c_pars; - Fill_Dir_Table(tree); - - n_neg = 0; - For(i,2*tree->n_otu-3) - if((!tree->t_edges[i]->left->tax) && - (!tree->t_edges[i]->rght->tax)) - NNI_Pars(tree,tree->t_edges[i],0); - - Select_Edges_To_Swap(tree,sorted_b,&n_neg); - Sort_Edges_NNI_Score(tree,sorted_b,n_neg); - - n_tested = 0; - For(i,(int)ceil((phydbl)n_neg*(lambda))) - tested_b[n_tested++] = sorted_b[i]; - - Make_N_Swap(tree,tested_b,0,n_tested); - - n_tot_swap += n_tested; - - if(n_tested > 0) n_without_swap = 0; - else n_without_swap++; - } + { + if(tree->verbose > VL0 && tree->io->quiet == NO) + PhyML_Printf("\n\n. Moving backward (topology) \n"); + if(!Mov_Backward_Topo_Pars(tree,old_pars,tested_b,n_tested)) + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(!tree->n_swap) n_neg = 0; + + Set_Both_Sides(YES,tree); + Pars(NULL,tree); + } + else + { + old_pars = tree->c_pars; + + n_neg = 0; + For(i,2*tree->n_otu-3) + if((!tree->a_edges[i]->left->tax) && + (!tree->a_edges[i]->rght->tax)) + NNI_Pars(tree,tree->a_edges[i],NO); + + Select_Edges_To_Swap(tree,sorted_b,&n_neg); + Sort_Edges_NNI_Score(tree,sorted_b,n_neg); + + n_tested = 0; + For(i,(int)CEIL((phydbl)n_neg*(lambda))) + tested_b[n_tested++] = sorted_b[i]; + + Make_N_Swap(tree,tested_b,0,n_tested); + + n_tot_swap += n_tested; + + if(n_tested > 0) n_without_swap = 0; + else n_without_swap++; + } n_iter+=1.0; } while(1); @@ -257,359 +164,848 @@ void Simu_Pars(arbre *tree, int n_step_max) Free(tested_b); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Select_Edges_To_Swap(arbre *tree, edge **sorted_b, int *n_neg) +void Select_Edges_To_Swap(t_tree *tree, t_edge **sorted_b, int *n_neg) { int i; - edge *b; - int min; - phydbl best_score; + t_edge *b; + /* phydbl best_score; */ *n_neg = 0; - min = 0; - + For(i,2*tree->n_otu-3) { - b = tree->t_edges[i]; - best_score = b->nni->score; - - if((!b->left->tax) && (!b->rght->tax) && (b->nni->score < .0)) - { - Check_NNI_Scores_Around(b->left,b->rght,b,&best_score); - Check_NNI_Scores_Around(b->rght,b->left,b,&best_score); - if(best_score < b->nni->score) continue; - sorted_b[*n_neg] = b; - (*n_neg)++; - } + b = tree->a_edges[i]; + /* best_score = b->nni->score; */ + + if((!b->left->tax) && (!b->rght->tax) && (b->nni->score < -tree->mod->s_opt->min_diff_lk_move)) + { + /* // Evaluate NNIs on edges at distance 1 */ + /* Check_NNI_Scores_Around(b->left,b->rght,b,&best_score,tree); */ + /* Check_NNI_Scores_Around(b->rght,b->left,b,&best_score,tree); */ + + /* // Evaluate NNIs on edges at distance 2 */ + /* Check_NNI_Scores_Around(b->left,b->left->v[b->l_v1],b,&best_score,tree); */ + /* Check_NNI_Scores_Around(b->left,b->left->v[b->l_v2],b,&best_score,tree); */ + + /* // Evaluate NNIs on edges at distance 2 */ + /* Check_NNI_Scores_Around(b->rght,b->rght->v[b->r_v1],b,&best_score,tree); */ + /* Check_NNI_Scores_Around(b->rght,b->rght->v[b->r_v2],b,&best_score,tree); */ + + /* if(best_score < b->nni->score) continue; */ + + sorted_b[*n_neg] = b; + (*n_neg)++; + } + + + /* if((!b->left->tax) && (!b->rght->tax) && (b->nni->score < -tree->mod->s_opt->min_diff_lk_move)) */ + /* { */ + /* sorted_b[*n_neg] = b; */ + /* (*n_neg)++; */ + /* } */ + } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void Update_Bl(arbre *tree, phydbl fact) +void Update_Bl(t_tree *tree, phydbl fact) { int i; - edge *b; + scalar_dbl *l,*l_old,*l0; For(i,2*tree->n_otu-3) { - b = tree->t_edges[i]; - b->l = b->l_old + (b->nni->l0 - b->l_old)*fact; + l = tree->a_edges[i]->l; + l_old = tree->a_edges[i]->l_old; + l0 = tree->a_edges[i]->nni->l0; + + do + { + l->v = l_old->v + (l0->v - l_old->v)*fact; + l = l->next; + l_old = l_old->next; + l0 = l0->next; + } + while(l); } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Make_N_Swap(arbre *tree,edge **b, int beg, int end) +void Make_N_Swap(t_tree *tree,t_edge **b, int beg, int end) { int i; + /* t_edge *orig; */ + t_node *n1,*n2,*n3,*n4; + + n1 = n2 = n3 = n4 = NULL; -/* printf("\n. Beg Actually performing swaps\n"); */ tree->n_swap = 0; for(i=beg;inni->swap_node_v2->v[tree->t_dir[b[i]->nni->swap_node_v2->num][b[i]->nni->swap_node_v1->num]], - b[i]->nni->swap_node_v2, - b[i]->nni->swap_node_v3, - b[i]->nni->swap_node_v3->v[tree->t_dir[b[i]->nni->swap_node_v3->num][b[i]->nni->swap_node_v4->num]], - tree); - - b[i]->l = b[i]->nni->best_l; - + n1 = n2 = n3 = n4 = NULL; + + n1 = b[i]->nni->swap_node_v1; + n2 = b[i]->nni->swap_node_v2; + n3 = b[i]->nni->swap_node_v3; + n4 = b[i]->nni->swap_node_v4; + + /* if(b[i]->nni->best_conf == 1) */ + /* { */ + /* n1 = b[i]->left->v[b[i]->l_v2]; */ + /* n2 = b[i]->left; */ + /* n3 = b[i]->rght; */ + /* n4 = b[i]->rght->v[b[i]->r_v1]; */ + /* } */ + /* else if(b[i]->nni->best_conf == 2) */ + /* { */ + /* n1 = b[i]->left->v[b[i]->l_v2]; */ + /* n2 = b[i]->left; */ + /* n3 = b[i]->rght; */ + /* n4 = b[i]->rght->v[b[i]->r_v2]; */ + /* } */ + + if(b[i]->nni->best_conf == 1) + { + if(n1 != b[i]->left->v[b[i]->l_v2] || + /* n2 != b[i]->left || */ + /* n3 != b[i]->rght || */ + n4 != b[i]->rght->v[b[i]->r_v1]) continue; + } + else if(b[i]->nni->best_conf == 2) + { + if(n1 != b[i]->left->v[b[i]->l_v2] || + /* n2 != b[i]->left || */ + /* n3 != b[i]->rght || */ + n4 != b[i]->rght->v[b[i]->r_v2]) continue; + } + + Swap(n1,n2,n3,n4,tree); + + if(!Check_Topo_Constraints(tree,tree->io->cstr_tree)) + { + /* Undo this swap as it violates one of the topological constraints + defined in the input constraint tree + */ + Swap(n4,n2,n3,n1,tree); + } + + if(tree->n_root) + { + tree->n_root->v[2] = tree->e_root->left; + tree->n_root->v[1] = tree->e_root->rght; + } + + Copy_Scalar_Dbl(b[i]->nni->best_l,b[i]->l); + Copy_Scalar_Dbl(b[i]->nni->best_v,b[i]->l_var); + + /* orig = b[i]; */ + /* do */ + /* { */ + /* b[i]->l->v = b[i]->nni->best_l; */ + /* b[i] = b[i]->next; */ + /* } */ + /* while(b[i]); */ + /* b[i] = orig; */ + tree->n_swap++; } -/* printf("\n. End Actually performing swaps\n"); */ + + /* PhyML_Printf("\n. End Actually performing swaps\n"); */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Make_Best_Swap(arbre *tree) +int Make_Best_Swap(t_tree *tree) { int i,j,return_value; - edge *b,**sorted_b; - + t_edge *b,**sorted_b; + /* t_edge *orig; */ + t_node *n1,*n2,*n3,*n4; - sorted_b = (edge **)mCalloc(tree->n_otu-3,sizeof(edge *)); + + sorted_b = (t_edge **)mCalloc(tree->n_otu-3,sizeof(t_edge *)); j=0; - For(i,2*tree->n_otu-3) if((!tree->t_edges[i]->left->tax) && - (!tree->t_edges[i]->rght->tax)) - sorted_b[j++] = tree->t_edges[i]; - + For(i,2*tree->n_otu-3) + if((!tree->a_edges[i]->left->tax) && + (!tree->a_edges[i]->rght->tax)) + sorted_b[j++] = tree->a_edges[i]; + Sort_Edges_NNI_Score(tree,sorted_b,tree->n_otu-3); - + if(sorted_b[0]->nni->score < -0.0) { b = sorted_b[0]; return_value = 1; - - Swap(b->nni->swap_node_v2->v[tree->t_dir[b->nni->swap_node_v2->num][b->nni->swap_node_v1->num]], - b->nni->swap_node_v2, - b->nni->swap_node_v3, - b->nni->swap_node_v3->v[tree->t_dir[b->nni->swap_node_v3->num][b->nni->swap_node_v4->num]], - tree); - - - b->l = b->nni->best_l; - -/* (b->nni->best_conf == 1)? */ -/* (Swap(b->left->v[b->l_v2],b->left,b->rght,b->rght->v[b->r_v1],tree)): */ -/* (Swap(b->left->v[b->l_v2],b->left,b->rght,b->rght->v[b->r_v2],tree)); */ -/* b->l = */ -/* (b->nni->best_conf == 1)? */ -/* (b->nni->l1): */ -/* (b->nni->l2); */ - - + n1 = n2 = n3 = n4 = NULL; + + /* n1 = b->nni->swap_node_v1; */ + /* n2 = b->nni->swap_node_v2; */ + /* n3 = b->nni->swap_node_v3; */ + /* n4 = b->nni->swap_node_v4; */ + + if(b->nni->best_conf == 1) + { + n1 = b->left->v[b->l_v2]; + n2 = b->left; + n3 = b->rght; + n4 = b->rght->v[b->r_v1]; + } + else if(b->nni->best_conf == 2) + { + n1 = b->left->v[b->l_v2]; + n2 = b->left; + n3 = b->rght; + n4 = b->rght->v[b->r_v2]; + } + + Swap(n1,n2,n3,n4,tree); + + if(!Check_Topo_Constraints(tree,tree->io->cstr_tree)) + { + /* Undo this swap as it violates one of the topological constraints + defined in the input constraint tree + */ + Swap(n4,n2,n3,n1,tree); + } + + /* b->l->v = b->nni->best_l; */ + + Copy_Scalar_Dbl(b->nni->best_l,b->l); + Copy_Scalar_Dbl(b->nni->best_v,b->l_var); + + /* orig = b; */ + /* do */ + /* { */ + /* b->l->v = b->nni->best_l; */ + /* b = b->next; */ + /* } */ + /* while(b); */ + /* b = orig; */ } else return_value = 0; - + Free(sorted_b); return return_value; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Mov_Backward_Topo_Bl(arbre *tree, phydbl lk_old, edge **tested_b, int n_tested) +int Mov_Backward_Topo_Bl(t_tree *tree, phydbl lk_old, t_edge **tested_b, int n_tested) { - phydbl *l_init; + scalar_dbl **l_init,**v_init; int i,step,beg,end; - edge *b; + t_edge *b,*orig; + l_init = (scalar_dbl **)mCalloc(2*tree->n_otu-3,sizeof(scalar_dbl *)); + v_init = (scalar_dbl **)mCalloc(2*tree->n_otu-3,sizeof(scalar_dbl *)); - l_init = (phydbl *)mCalloc(2*tree->n_otu-3,sizeof(phydbl)); + For(i,2*tree->n_otu-3) + { + l_init[i] = Duplicate_Scalar_Dbl(tree->a_edges[i]->l); + v_init[i] = Duplicate_Scalar_Dbl(tree->a_edges[i]->l_var); + } - For(i,2*tree->n_otu-3) l_init[i] = tree->t_edges[i]->l; - step = 2; - tree->both_sides = 0; do { - For(i,2*tree->n_otu-3) - { - b = tree->t_edges[i]; - b->l = b->l_old + (1./step) * (l_init[i] - b->l_old); - } - - beg = (int)floor((phydbl)n_tested/(step-1)); + For(i,2*tree->n_otu-3) + { + b = tree->a_edges[i]; + + orig = b; + do + { + b->l->v = b->l_old->v + (1./step) * (l_init[i]->v - b->l_old->v); + if(b->next == NULL) break; + b = b->next; + l_init[i] = l_init[i]->next; + } + while(b); + b = orig; + } + + beg = (int)FLOOR((phydbl)n_tested/(step-1)); end = 0; Unswap_N_Branch(tree,tested_b,beg,end); beg = 0; - end = (int)floor((phydbl)n_tested/step); + end = (int)FLOOR((phydbl)n_tested/step); Swap_N_Branch(tree,tested_b,beg,end); if(!end) tree->n_swap = 0; - tree->both_sides = 0; - Lk(tree); - - step++; + Set_Both_Sides(NO,tree); + Lk(NULL,tree); + step++; + }while((tree->c_lnL < lk_old) && (step < 1000)); - + if(step == 1000) { - if(tree->n_swap) Exit("\n. Err. in Mov_Backward_Topo_Bl (n_swap > 0)\n"); - - For(i,2*tree->n_otu-3) - { - b = tree->t_edges[i]; - b->l = b->l_old; - } + if(tree->n_swap) Exit("\n== Err. in Mov_Backward_Topo_Bl (n_swap > 0)\n"); + + Restore_Br_Len(tree); - tree->both_sides = 0; - Lk(tree); + Set_Both_Sides(NO,tree); + Lk(NULL,tree); } + For(i,2*tree->n_otu-3) + { + while(l_init[i]->prev) l_init[i] = l_init[i]->prev; + Free_Scalar_Dbl(l_init[i]); + } Free(l_init); - tree->n_swap = 0; For(i,2*tree->n_otu-3) { - if(tree->t_edges[i]->nni->score < 0.0) tree->n_swap++; - tree->t_edges[i]->nni->score = +1.0; + while(v_init[i]->prev) v_init[i] = v_init[i]->prev; + Free_Scalar_Dbl(v_init[i]); } + Free(v_init); + + tree->n_swap = 0; + For(i,2*tree->n_otu-3) + { + if(tree->a_edges[i]->nni->score < 0.0) tree->n_swap++; + tree->a_edges[i]->nni->score = +1.0; + } + - if(tree->c_lnL > lk_old) return 1; - else if((tree->c_lnL > lk_old-tree->mod->s_opt->min_diff_lk_local) && - (tree->c_lnL < lk_old+tree->mod->s_opt->min_diff_lk_local)) return -1; + else if((tree->c_lnL > lk_old-tree->mod->s_opt->min_diff_lk_local) && + (tree->c_lnL < lk_old+tree->mod->s_opt->min_diff_lk_local)) return -1; else return 0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Mov_Backward_Topo_Pars(arbre *tree, int pars_old, edge **tested_b, int n_tested) +int Mov_Backward_Topo_Pars(t_tree *tree, int pars_old, t_edge **tested_b, int n_tested) { int i,step,beg,end; - + step = 2; - tree->both_sides = 0; do { - beg = (int)floor((phydbl)n_tested/(step-1)); + beg = (int)FLOOR((phydbl)n_tested/(step-1)); end = 0; Unswap_N_Branch(tree,tested_b,beg,end); beg = 0; - end = (int)floor((phydbl)n_tested/step); + end = (int)FLOOR((phydbl)n_tested/step); Swap_N_Branch(tree,tested_b,beg,end); - + if(!end) tree->n_swap = 0; - - tree->both_sides = 0; - Pars(tree); - + + Set_Both_Sides(NO,tree); + Pars(NULL,tree); + step++; - }while((tree->c_pars > pars_old) && (step < 1000)); + } + while((tree->c_pars > pars_old) && (step < 1000)); + - if(step == 1000) { if(tree->n_swap) Exit("\n. Err. in Mov_Backward_Topo_Bl (n_swap > 0)\n"); - tree->both_sides = 0; - Pars(tree); + Set_Both_Sides(NO,tree); + Pars(NULL,tree); } tree->n_swap = 0; - For(i,2*tree->n_otu-3) + For(i,2*tree->n_otu-3) { - if(tree->t_edges[i]->nni->score < 0.0) tree->n_swap++; - tree->t_edges[i]->nni->score = +1.0; + if(tree->a_edges[i]->nni->score < 0.0) tree->n_swap++; + tree->a_edges[i]->nni->score = +1.0; } - + if(tree->c_pars < pars_old) return 1; else if(tree->c_pars == pars_old) return -1; else return 0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Unswap_N_Branch(arbre *tree, edge **b, int beg, int end) + +void Unswap_N_Branch(t_tree *tree, t_edge **b, int beg, int end) { int i; + /* t_edge *orig; */ + t_node *n1,*n2,*n3,*n4; + n1 = n2 = n3 = n4 = NULL; + if(end>beg) { for(i=beg;inum, */ -/* b[i]->nni->swap_node_v2->v[tree->t_dir[b[i]->nni->swap_node_v2->num][b[i]->nni->swap_node_v1->num]]->num, */ -/* b[i]->nni->swap_node_v4->num, */ -/* b[i]->nni->swap_node_v2->num, */ -/* b[i]->nni->swap_node_v3->num, */ -/* b[i]->nni->swap_node_v3->v[tree->t_dir[b[i]->nni->swap_node_v3->num][b[i]->nni->swap_node_v4->num]]->num, */ -/* b[i]->nni->swap_node_v1->num */ -/* ); */ - - Swap(b[i]->nni->swap_node_v2->v[tree->t_dir[b[i]->nni->swap_node_v2->num][b[i]->nni->swap_node_v1->num]], - b[i]->nni->swap_node_v2, - b[i]->nni->swap_node_v3, - b[i]->nni->swap_node_v3->v[tree->t_dir[b[i]->nni->swap_node_v3->num][b[i]->nni->swap_node_v4->num]], - tree); - - -/* (b[i]->nni->best_conf == 1)? */ -/* (Swap(b[i]->left->v[b[i]->l_v2],b[i]->left,b[i]->rght,b[i]->rght->v[b[i]->r_v1],tree)): */ -/* (Swap(b[i]->left->v[b[i]->l_v2],b[i]->left,b[i]->rght,b[i]->rght->v[b[i]->r_v2],tree)); */ - - b[i]->l = b[i]->l_old; - } + { + n1 = n2 = n3 = n4 = NULL; + + n1 = b[i]->nni->swap_node_v4; + n2 = b[i]->nni->swap_node_v2; + n3 = b[i]->nni->swap_node_v3; + n4 = b[i]->nni->swap_node_v1; + + /* if(b[i]->nni->best_conf == 1) */ + /* { */ + /* n1 = b[i]->left->v[b[i]->l_v2]; */ + /* n2 = b[i]->left; */ + /* n3 = b[i]->rght; */ + /* n4 = b[i]->rght->v[b[i]->r_v1]; */ + /* } */ + /* else if(b[i]->nni->best_conf == 2) */ + /* { */ + /* n1 = b[i]->left->v[b[i]->l_v2]; */ + /* n2 = b[i]->left; */ + /* n3 = b[i]->rght; */ + /* n4 = b[i]->rght->v[b[i]->r_v2]; */ + /* } */ + + Swap(n1,n2,n3,n4,tree); + + if(!Check_Topo_Constraints(tree,tree->io->cstr_tree)) + { + /* Undo this swap as it violates one of the topological constraints + defined in the input constraint tree + */ + Swap(n4,n2,n3,n1,tree); + } + + + /* (b[i]->nni->best_conf == 1)? */ + /* (Swap(b[i]->left->v[b[i]->l_v2],b[i]->left,b[i]->rght,b[i]->rght->v[b[i]->r_v1],tree)): */ + /* (Swap(b[i]->left->v[b[i]->l_v2],b[i]->left,b[i]->rght,b[i]->rght->v[b[i]->r_v2],tree)); */ + + /* b[i]->l->v = b[i]->l_old->v; */ + + Copy_Scalar_Dbl(b[i]->l_old,b[i]->l); + Copy_Scalar_Dbl(b[i]->l_var_old,b[i]->l_var); + + /* orig = b[i]; */ + /* do */ + /* { */ + /* b[i]->l->v = b[i]->l_old->v; */ + /* b[i] = b[i]->next; */ + /* } */ + /* while(b[i]); */ + /* b[i] = orig; */ + + } } else { for(i=beg-1;i>=end;i--) - { - Swap(b[i]->nni->swap_node_v2->v[tree->t_dir[b[i]->nni->swap_node_v2->num][b[i]->nni->swap_node_v1->num]], - b[i]->nni->swap_node_v2, - b[i]->nni->swap_node_v3, - b[i]->nni->swap_node_v3->v[tree->t_dir[b[i]->nni->swap_node_v3->num][b[i]->nni->swap_node_v4->num]], - tree); - - b[i]->l = b[i]->l_old; - } + { + n1 = n2 = n3 = n4 = NULL; + + n1 = b[i]->nni->swap_node_v4; + n2 = b[i]->nni->swap_node_v2; + n3 = b[i]->nni->swap_node_v3; + n4 = b[i]->nni->swap_node_v1; + + /* if(b[i]->nni->best_conf == 1) */ + /* { */ + /* n1 = b[i]->left->v[b[i]->l_v2]; */ + /* n2 = b[i]->left; */ + /* n3 = b[i]->rght; */ + /* n4 = b[i]->rght->v[b[i]->r_v1]; */ + /* } */ + /* else if(b[i]->nni->best_conf == 2) */ + /* { */ + /* n1 = b[i]->left->v[b[i]->l_v2]; */ + /* n2 = b[i]->left; */ + /* n3 = b[i]->rght; */ + /* n4 = b[i]->rght->v[b[i]->r_v2]; */ + /* } */ + + Swap(n1,n2,n3,n4,tree); + + if(!Check_Topo_Constraints(tree,tree->io->cstr_tree)) + { + /* Undo this swap as it violates one of the topological constraints + defined in the input constraint tree + */ + Swap(n4,n2,n3,n1,tree); + } + + + /* b[i]->l->v = b[i]->l_old->v; */ + Copy_Scalar_Dbl(b[i]->l_old,b[i]->l); + Copy_Scalar_Dbl(b[i]->l_var_old,b[i]->l_var); + + + /* orig = b[i]; */ + /* do */ + /* { */ + /* b[i]->l->v = b[i]->l_old->v; */ + /* b[i] = b[i]->next; */ + /* } */ + /* while(b[i]); */ + /* b[i] = orig; */ + + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Swap_N_Branch(arbre *tree,edge **b, int beg, int end) +void Swap_N_Branch(t_tree *tree,t_edge **b, int beg, int end) { int i; - + /* t_edge *orig; */ + t_node *n1,*n2,*n3,*n4; + + n1 = n2 = n3 = n4 = NULL; + if(end>beg) { for(i=beg;inni->swap_node_v2->v[tree->t_dir[b[i]->nni->swap_node_v2->num][b[i]->nni->swap_node_v1->num]], - b[i]->nni->swap_node_v2, - b[i]->nni->swap_node_v3, - b[i]->nni->swap_node_v3->v[tree->t_dir[b[i]->nni->swap_node_v3->num][b[i]->nni->swap_node_v4->num]], - tree); - - - b[i]->l = b[i]->nni->best_l; - - } + { + n1 = n2 = n3 = n4 = NULL; + + n1 = b[i]->nni->swap_node_v1; + n2 = b[i]->nni->swap_node_v2; + n3 = b[i]->nni->swap_node_v3; + n4 = b[i]->nni->swap_node_v4; + + + /* if(b[i]->nni->best_conf == 1) */ + /* { */ + /* n1 = b[i]->left->v[b[i]->l_v2]; */ + /* n2 = b[i]->left; */ + /* n3 = b[i]->rght; */ + /* n4 = b[i]->rght->v[b[i]->r_v1]; */ + /* } */ + /* else if(b[i]->nni->best_conf == 2) */ + /* { */ + /* n1 = b[i]->left->v[b[i]->l_v2]; */ + /* n2 = b[i]->left; */ + /* n3 = b[i]->rght; */ + /* n4 = b[i]->rght->v[b[i]->r_v2]; */ + /* } */ + + Swap(n1,n2,n3,n4,tree); + + if(!Check_Topo_Constraints(tree,tree->io->cstr_tree)) + { + /* Undo this swap as it violates one of the topological constraints + defined in the input constraint tree + */ + Swap(n4,n2,n3,n1,tree); + } + + /* b[i]->l->v = b[i]->nni->best_l; */ + + Copy_Scalar_Dbl(b[i]->nni->best_l,b[i]->l); + Copy_Scalar_Dbl(b[i]->nni->best_v,b[i]->l_var); + + /* orig = b[i]; */ + /* do */ + /* { */ + /* b[i]->l->v = b[i]->nni->best_l; */ + /* b[i] = b[i]->next; */ + /* } */ + /* while(b[i]); */ + /* b[i] = orig; */ + } } else { for(i=beg-1;i>=end;i--) - { - Swap(b[i]->nni->swap_node_v2->v[tree->t_dir[b[i]->nni->swap_node_v2->num][b[i]->nni->swap_node_v1->num]], - b[i]->nni->swap_node_v2, - b[i]->nni->swap_node_v3, - b[i]->nni->swap_node_v3->v[tree->t_dir[b[i]->nni->swap_node_v3->num][b[i]->nni->swap_node_v4->num]], - tree); - - b[i]->l = b[i]->nni->best_l; - } + { + + n1 = n2 = n3 = n4 = NULL; + + n1 = b[i]->nni->swap_node_v1; + n2 = b[i]->nni->swap_node_v2; + n3 = b[i]->nni->swap_node_v3; + n4 = b[i]->nni->swap_node_v4; + + + /* if(b[i]->nni->best_conf == 1) */ + /* { */ + /* n1 = b[i]->left->v[b[i]->l_v2]; */ + /* n2 = b[i]->left; */ + /* n3 = b[i]->rght; */ + /* n4 = b[i]->rght->v[b[i]->r_v1]; */ + /* } */ + /* else if(b[i]->nni->best_conf == 2) */ + /* { */ + /* n1 = b[i]->left->v[b[i]->l_v2]; */ + /* n2 = b[i]->left; */ + /* n3 = b[i]->rght; */ + /* n4 = b[i]->rght->v[b[i]->r_v2]; */ + /* } */ + + Swap(n1,n2,n3,n4,tree); + + if(!Check_Topo_Constraints(tree,tree->io->cstr_tree)) + { + /* Undo this swap as it violates one of the topological constraints + defined in the input constraint tree + */ + Swap(n4,n2,n3,n1,tree); + } + + /* b[i]->l->v = b[i]->nni->best_l; */ + + Copy_Scalar_Dbl(b[i]->nni->best_l,b[i]->l); + Copy_Scalar_Dbl(b[i]->nni->best_v,b[i]->l_var); + + /* orig = b[i]; */ + /* do */ + /* { */ + /* b[i]->l->v = b[i]->nni->best_l; */ + /* b[i] = b[i]->next; */ + /* } */ + /* while(b[i]); */ + /* b[i] = orig; */ + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Check_NNI_Scores_Around(node *a, node *d, edge *b, phydbl *best_score) +void Check_NNI_Scores_Around(t_node *a, t_node *d, t_edge *b, phydbl *best_score, t_tree *tree) { - int i; - For(i,3) + + if(d->tax) return; + + for(i=0;i<3;i++) { if((d->v[i] != a) && (!d->v[i]->tax)) - { - if((d->b[i]->nni->score > *best_score-1.E-10) && - (d->b[i]->nni->score < *best_score+1.E-10)) /* ties */ - { - d->b[i]->nni->score = *best_score+1.; - } - - if(d->b[i]->nni->score < *best_score) - { - *best_score = d->b[i]->nni->score; - } - } + { + if((d->b[i]->nni->score > *best_score-1.E-10) && + (d->b[i]->nni->score < *best_score+1.E-10)) /* ties */ + { + d->b[i]->nni->score = *best_score+1.; + } + + if(d->b[i]->nni->score < *best_score) + { + *best_score = d->b[i]->nni->score; + } + } } } -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +/* + v + | + | + a + / \ + d u + / \ + v1 v2 +*/ +void NNI_Traversal(t_node *a, t_node *d, t_node *v, t_edge *b, int opt_edges, t_tree *tree) +{ + int i,dir1, dir2; + + /* printf("\n. a: %d d: %d b->is_alive ? %d -- [%d - %d]", a->num,d->num,b->is_alive,a->tax,d->tax); */ + + if(d->tax == YES) + { + if(opt_edges == YES) Br_Len_Opt(&(b->l->v),b,tree); + return; + } + else if(a->tax == YES) + { + if(opt_edges == YES && a->tax == YES) Br_Len_Opt(&(b->l->v),b,tree); + for(i=0;i<3;++i) + if(d->v[i] != a) + { + Update_Partial_Lk(tree,d->b[i],d); + NNI_Traversal(d,d->v[i],a,d->b[i],opt_edges,tree); + } + Update_Partial_Lk(tree,b,d); + } + else + { + tree->n_edges_traversed++; + NNI_Core(a,d,v,b,opt_edges,tree); + + dir1 = dir2 = -1; + for(i=0;i<3;++i) + if(d->v[i] != a) + { + if(dir1 < 0) dir1 = i; + else dir2 = i; + } + + Update_Partial_Lk(tree,d->b[dir1],d); + NNI_Traversal(d,d->v[dir1],a,d->b[dir1],opt_edges,tree); + Update_Partial_Lk(tree,d->b[dir2],d); + NNI_Traversal(d,d->v[dir2],a,d->b[dir2],opt_edges,tree); + + Update_Partial_Lk(tree,b,d); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void NNI_Core(t_node *a, t_node *d, t_node *v, t_edge *b, int opt_edges, t_tree *tree) +{ + phydbl lk0,lk1,lk2; + phydbl rnd; + t_node *v1,*v2,*u,*dum; + scalar_dbl *l0,*l1,*l2; + phydbl p_accept; + int i; + + + l0 = l1 = l2 = NULL; + + lk0 = UNLIKELY; + lk1 = UNLIKELY; + lk2 = UNLIKELY; + + v1 = v2 = NULL; + for(i=0;i<3;++i) + if(d->v[i] != a) + { + if(v1 == NULL) v1 = d->v[i]; + else v2 = d->v[i]; + } + assert(v1 != NULL); + assert(v2 != NULL); + + dum = NULL; + rnd = Uni(); + if(rnd < .5) + { + dum = v1; + v1 = v2; + v2 = dum; + } + + u = NULL; + for(i=0;i<3;++i) if(a->v[i] != d && a->v[i] != v) { u = a->v[i]; break; } + + if(opt_edges == YES) Br_Len_Opt(&(b->l->v),b,tree); + lk0 = Lk(b,tree); + l0 = Duplicate_Scalar_Dbl(b->l); + + /* Swap_Partial_Lk_Extra(b,a,0,tree); */ + /* Swap_Partial_Lk_Extra(b,d,1,tree); */ + + // First NNI + Swap(v1,d,a,u,tree); + // Update partial likelihood looking up + Update_Partial_Lk(tree,b,a); + // Update partial likelihood looking down + Update_Partial_Lk(tree,b,d); + // Evaluate likelihood + if(opt_edges == YES) Br_Len_Opt(&(b->l->v),b,tree); + lk1 = Lk(b,tree); + /* if(lk1 > lk0 + tree->mod->s_opt->min_diff_lk_move) */ + /* { */ + /* tree->fully_nni_opt = NO; */ + /* return; */ + /* } */ + l1 = Duplicate_Scalar_Dbl(b->l); + // Unswap + Swap(u,d,a,v1,tree); + + + + // Second NNI + Swap(v2,d,a,u,tree); + // Update partial likelihood looking up + Update_Partial_Lk(tree,b,a); + // Update partial likelihood looking down + Update_Partial_Lk(tree,b,d); + // Evaluate likelihood + if(opt_edges == YES) Br_Len_Opt(&(b->l->v),b,tree); + lk2 = Lk(b,tree); + /* if(lk2 > lk0 + tree->mod->s_opt->min_diff_lk_move) */ + /* { */ + /* tree->fully_nni_opt = NO; */ + /* Free_Scalar_Dbl(l1); */ + /* return; */ + /* } */ + l2 = Duplicate_Scalar_Dbl(b->l); + // Unswap + Swap(u,d,a,v2,tree); + + /* Swap_Partial_Lk_Extra(b,a,0,tree); */ + /* Swap_Partial_Lk_Extra(b,d,1,tree); */ + + /* if((u->tax == YES && !strcmp(u->name,"tax57")) || */ + /* (v1->tax == YES && !strcmp(v1->name,"tax57")) || */ + /* (v2->tax == YES && !strcmp(v2->name,"tax57"))) */ + /* printf("\n. lk0: %G lk1: %G lk2: %G l0: %G l1: %G l2: %G",lk0,lk1,lk2,l0->v,l1->v,l2->v); */ + + /* printf("\n. a: %d d: %d -- lk0: %f lk1: %f lk2: %f p: %G %G %G %G",a->num,d->num,lk0,lk1,lk2,p_accept,l0->v,l1->v,l2->v); */ + + p_accept = exp((lk1-lk0)/(tree->annealing_temp+1.E-6)); + if(Are_Equal(lk1,lk0,tree->mod->s_opt->min_diff_lk_local) && Are_Equal(tree->annealing_temp,0.0,1.E-3)) p_accept = .0; + rnd = Uni(); + + + if(rnd < p_accept && lk2 < lk1) + { + Swap(v1,d,a,u,tree); + Copy_Scalar_Dbl(l1,b->l); + tree->c_lnL = lk1; + Update_Partial_Lk(tree,b,a); + Update_Partial_Lk(tree,b,d); + tree->fully_nni_opt = NO; + } + else + { + p_accept = exp((lk2-lk0)/(tree->annealing_temp+1.E-6)); + if(Are_Equal(lk2,lk0,tree->mod->s_opt->min_diff_lk_local) && Are_Equal(tree->annealing_temp,0.0,1.E-3)) p_accept = .0; + rnd = Uni(); + if(rnd < p_accept) + { + Swap(v2,d,a,u,tree); + Copy_Scalar_Dbl(l2,b->l); + tree->c_lnL = lk2; + Update_Partial_Lk(tree,b,a); + Update_Partial_Lk(tree,b,d); + tree->fully_nni_opt = NO; + } + else + { + Update_Partial_Lk(tree,b,a); + Update_Partial_Lk(tree,b,d); + Copy_Scalar_Dbl(l0,b->l); + tree->c_lnL = lk0; + } + } + + Update_PMat_At_Given_Edge(b,tree); + + if(l0) Free_Scalar_Dbl(l0); + if(l1) Free_Scalar_Dbl(l1); + if(l2) Free_Scalar_Dbl(l2); +} diff --git a/phyml/simu.h b/phyml/simu.h index 04ec375..9e36ae4 100644 --- a/phyml/simu.h +++ b/phyml/simu.h @@ -10,20 +10,26 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef CURR_H #define CURR_H -void Simu_Loop(arbre *tree); -void Simu(arbre *tree,int n_step_max); -void Select_Edges_To_Swap(arbre *tree,edge **sorted_b,int *n_neg); -void Update_Bl(arbre *tree,phydbl fact); -void Make_N_Swap(arbre *tree,edge **b,int beg,int end); -int Make_Best_Swap(arbre *tree); -int Mov_Backward_Topo_Bl(arbre *tree,phydbl lk_old,edge **tested_b,int n_tested); -void Unswap_N_Branch(arbre *tree,edge **b,int beg,int end); -void Swap_N_Branch(arbre *tree,edge **b,int beg,int end); -void Check_NNI_Scores_Around(node *a, node *d, edge *b, phydbl *best_score); -int Mov_Backward_Topo_Pars(arbre *tree, int pars_old, edge **tested_b, int n_tested); -void Simu_Pars(arbre *tree, int n_step_max); +#include "utilities.h" + +int Simu(t_tree *tree, int n_step_max, phydbl delta_lnL, phydbl init_T, phydbl delta_T, int min_n_edges_traversed); +void Simu_Loop(t_tree *tree); +void Select_Edges_To_Swap(t_tree *tree,t_edge **sorted_b,int *n_neg); +void Update_Bl(t_tree *tree,phydbl fact); +void Make_N_Swap(t_tree *tree,t_edge **b,int beg,int end); +int Make_Best_Swap(t_tree *tree); +int Mov_Backward_Topo_Bl(t_tree *tree,phydbl lk_old,t_edge **tested_b,int n_tested); +void Unswap_N_Branch(t_tree *tree,t_edge **b,int beg,int end); +void Swap_N_Branch(t_tree *tree,t_edge **b,int beg,int end); +void Check_NNI_Scores_Around(t_node *a, t_node *d, t_edge *b, phydbl *best_score, t_tree *tree); +int Mov_Backward_Topo_Pars(t_tree *tree, int pars_old, t_edge **tested_b, int n_tested); +void Simu_Pars(t_tree *tree, int n_step_max); +void NNI_Traversal(t_node *a, t_node *d, t_node *v, t_edge *b, int opt_edges, t_tree *tree); +void NNI_Core(t_node *a, t_node *d, t_node *v, t_edge *b, int opt_edges, t_tree *tree); #endif diff --git a/phyml/spr.c b/phyml/spr.c index 4c2b766..9bfa6a0 100644 --- a/phyml/spr.c +++ b/phyml/spr.c @@ -1,3112 +1,2354 @@ /* -** spr.c: Routines for performing SPR moves on the tree. -** -** Wim Hordijk Last modified: 28 August 2006 -*/ - -#include "utilities.h" -#include "models.h" -#include "lk.h" -#include "free.h" -#include "optimiz.h" -#include "spr.h" -#include "alrt.h" +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. -/* -** BIG: Some big number. -*/ +Copyright (C) Stephane Guindon. Oct 2003 onward. -#define BIG 1e05 +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. -/* -** Global vars. -** -** - cur_lk: The current likelihood of the tree. -** - subtree_dist: The average subtree distances matrix. -** - seq_dist: The sequence distance matrix. -** - optim_cand: Array for holding candidate moves for local and global branch -** length optimization. -** - rgrft_cand: Array for holding candidate regraft positions. -** - v_tmp: The central node of the temporary regraft structure for -** estimating changes in likelihood. -** - path: The path through the tree during the recursive tree length -** calculation. -** - sum_scale_tmp Array for temporarily storing scaling factors. -** - p_lk_tmp: Temporary partial likelihood storage. -** - e_brent: A temporary edge to use for estimating distances using Brent. - -** - tree->mod->s_opt->wim_n_rgrft: Number of promising regraft positions to consider when - performing all improving SPR moves. -** - tree->mod->s_opt->wim_n_optim: Number of candidate moves on which to perform local branch - length optimization. -** - tree->mod->s_opt->wim_max_dist: Maximum regraft distance to consider. -** - tree->mod->s_opt->wim_n_globl: Number of candidates moves on which to perform global branch - length optimization. -** - tree->mod->s_opt->wim_n_best: Number of promising regraft positions to consider when - performing only the best SPR move. - -** - nr_d_l: Total number of change in tree length calculations done. -** - nr_d_lk: Total number of change in likelihood calculations done. -** - nr_loc: Total number of local branch length optimizations done. -** - nr_glb: Total number of global branch length optimizations done. */ -phydbl cur_lk, **subtree_dist, *sum_scale_tmp, ***p_lk_tmp; -matrix *seq_dist; -_move_ **optim_cand, **rgrft_cand; -node *v_tmp=NULL, **path; -edge *e_brent=NULL; -int nr_d_L, nr_d_lk, nr_loc, nr_glb; - /* -** Init_SPR: Initialize the SPR algorithm: allocate memory and set variables. +** spr.c: Routines for performing SPR moves on the tree. ** -** Parameters: -** - tree: The current tree to use for initialization. +** Wim Hordijk Last modified: 28 August 2006 +** Stephane Guindon 2007 */ -void Init_SPR (arbre *tree) -{ - int i, j, nr_nodes, nr_edges; - node *u_0, *u_1, *u_2; - - /* - ** Get the SPR parameter values. - */ - nr_edges = 2*tree->n_otu-3; - - if(tree->mod->s_opt->wim_n_rgrft < 0) tree->mod->s_opt->wim_n_rgrft = 1 + nr_edges / 5; - if(tree->mod->s_opt->wim_n_globl < 0) tree->mod->s_opt->wim_n_globl = 1 + nr_edges / 10; - if(tree->mod->s_opt->wim_max_dist < 0) tree->mod->s_opt->wim_max_dist = 1 + nr_edges / 10; - if(tree->mod->s_opt->wim_n_optim < 0) tree->mod->s_opt->wim_n_optim = 100; - if(tree->mod->s_opt->wim_n_best < 0) tree->mod->s_opt->wim_n_best = tree->mod->s_opt->wim_n_rgrft; /* can't - * be - * anything else - */ - - - /* - ** If it doesn't exist yet, create the temporary regraft structure: - ** a central node with three edges and tip nodes adjacent to it. - */ - if (v_tmp == NULL) - { - int i,j; - - v_tmp=Make_Node_Light(0); - v_tmp->tax = 0; - u_0=Make_Node_Light(1); - u_0->tax = 1; - u_1=Make_Node_Light(2); - u_1->tax = 1; - u_2=Make_Node_Light(3); - u_2->tax = 1; - - v_tmp->v[0] = u_0; - v_tmp->v[1] = u_1; - v_tmp->v[2] = u_2; - u_0->v[0] = v_tmp; - u_1->v[0] = v_tmp; - u_2->v[0] = v_tmp; - - edge *edge_0 = Make_Edge_Light (v_tmp, u_0, 0); - Make_Edge_Lk (edge_0, tree); - edge *edge_1 = Make_Edge_Light (v_tmp, u_1,1); - Make_Edge_Lk (edge_1, tree); - edge *edge_2 = Make_Edge_Light (v_tmp, u_2,2); - Make_Edge_Lk (edge_2, tree); - - - For(i,tree->data->crunch_len) - { - For(j,tree->mod->n_catg) - { - Free(edge_0->p_lk_rght[i][j]); - } - Free(edge_0->p_lk_rght[i]); - } - Free(edge_0->p_lk_rght); - - if(!edge_0->rght->tax) Free(edge_0->sum_scale_f_rght); - - - For(i,tree->data->crunch_len) - { - For(j,tree->mod->n_catg) - { - Free(edge_1->p_lk_rght[i][j]); - } - Free(edge_1->p_lk_rght[i]); - } - Free(edge_1->p_lk_rght); - - if(!edge_1->rght->tax) Free(edge_1->sum_scale_f_rght); - - - For(i,tree->data->crunch_len) - { - For(j,tree->mod->n_catg) - { - Free(edge_2->p_lk_rght[i][j]); - } - Free(edge_2->p_lk_rght[i]); - } - Free(edge_2->p_lk_rght); - - if(!edge_2->rght->tax) Free(edge_2->sum_scale_f_rght); - } - - /* - ** If it doesn't exist yet, create the temporary edge. - */ - if (e_brent == NULL) - { - int i,j; - - u_1=Make_Node_Light(4); - u_1->tax = 1; - u_2=Make_Node_Light(5); - u_2->tax = 1; - u_1->v[0] = u_2; - u_2->v[0] = u_1; - edge *edge_4 = Make_Edge_Light (u_1, u_2, 3); - Make_Edge_Lk (edge_4, tree); - e_brent = u_1->b[0]; - - - For(i,tree->data->crunch_len) - { - For(j,tree->mod->n_catg) - { - Free(edge_4->p_lk_rght[i][j]); - } - Free(edge_4->p_lk_rght[i]); - } - Free(edge_4->p_lk_rght); - - if(!edge_4->rght->tax) Free(edge_4->sum_scale_f_rght); - - - For(i,tree->data->crunch_len) - { - For(j,tree->mod->n_catg) - { - Free(edge_4->p_lk_left[i][j]); - } - Free(edge_4->p_lk_left[i]); - } - Free(edge_4->p_lk_left); +#include "spr.h" - if(!edge_4->left->tax) Free(edge_4->sum_scale_f_left); - } +#ifdef BEAGLE +#include "beagle_utils.h" +#endif - /* - ** Allocate memory for temporarily storing partial likelihoods and - ** scaling factors. - */ - p_lk_tmp = (phydbl ***)mCalloc (tree->n_pattern, sizeof (phydbl **)); - for (i = 0; i < tree->n_pattern; i++) - { - p_lk_tmp[i] = (phydbl **)mCalloc (tree->mod->n_catg, sizeof (phydbl *)); - for (j = 0; j < tree->mod->n_catg; j++) - { - p_lk_tmp[i][j] = (phydbl *)mCalloc (tree->mod->ns, sizeof (phydbl)); - } - } - sum_scale_tmp = (phydbl *)mCalloc (tree->n_pattern, sizeof (phydbl)); +/*********************************************************/ +/* Sort list of SPR move by putting the shallowest moves first */ +void Sort_Spr_List_Depth(t_tree *tree) +{ + int i,j; + t_spr *buff; - /* - ** Allocate memory for storing the average subtree distances. - */ - nr_nodes = 2*tree->n_otu-2; - subtree_dist = (phydbl **)malloc (nr_nodes * sizeof (phydbl *)); - for (i = 0; i < nr_nodes; i++) + for(i=0;in_moves-1;i++) { - subtree_dist[i] = (phydbl *)malloc (nr_nodes * sizeof (phydbl)); + for(j=i+1;jn_moves;j++) + { + if(tree->spr_list_one_edge[j]->depth_path < tree->spr_list_one_edge[i]->depth_path) + { + buff = tree->spr_list_one_edge[i]; + tree->spr_list_one_edge[i] = tree->spr_list_one_edge[j]; + tree->spr_list_one_edge[j] = buff; + } + } } +} - /* - ** Allocate memory for storing the candidate regraft positions and - ** edge length optimization moves. - */ - rgrft_cand = (_move_ **)malloc (MAX(tree->mod->s_opt->wim_n_rgrft,tree->mod->s_opt->wim_n_best) * sizeof (_move_ *)); - for (i = 0; i < MAX(tree->mod->s_opt->wim_n_rgrft,tree->mod->s_opt->wim_n_best); i++) - { - rgrft_cand[i] = (_move_ *)malloc (sizeof (_move_)); - rgrft_cand[i]->path = (node **)malloc ((tree->mod->s_opt->wim_max_dist+2) * sizeof (node *)); - } - optim_cand = (_move_ **)malloc (tree->mod->s_opt->wim_n_optim * sizeof (_move_ *)); - for (i = 0; i < tree->mod->s_opt->wim_n_optim; i++) - { - optim_cand[i] = (_move_ *)malloc (sizeof (_move_)); - optim_cand[i]->path = (node **)malloc ((tree->mod->s_opt->wim_max_dist+2) * sizeof (node *)); - } - path = (node **)malloc ((tree->mod->s_opt->wim_max_dist+2) * sizeof (node *)); +/*********************************************************/ +/*********************************************************/ +/* Sort list of SPR move by putting the more likely moves first */ +void Sort_Spr_List_LnL(t_spr **list, int list_size, t_tree *tree) +{ + int i,j; + t_spr *buff; - if(!tree->mat) + for(i=0;idata, tree->mod); - tree->mat = seq_dist; + for(j=i+1;jlnL > list[i]->lnL) + { + buff = list[i]; + list[i] = list[j]; + list[j] = buff; + } + } } - else - seq_dist = tree->mat; - - /* - ** Set variables. - */ - nr_d_L = 0; - nr_d_lk = 0; - nr_loc = 0; - nr_glb = 0; } -/* -** Clean_SPR: Free up the used memory. -** -** Parameters: -** - tree: The current tree. -*/ - -void Clean_SPR (arbre *tree) +/*********************************************************/ +/*********************************************************/ +/* Sort list of SPR move by putting the more parsimonious moves first */ +void Sort_Spr_List_Pars(t_tree *tree) { - int i, j; + int i,j; + t_spr *buff; - /* - ** Clean up the temporary regraft structure. - */ - Free_Node (v_tmp->v[0]); - Free_Node (v_tmp->v[1]); - Free_Node (v_tmp->v[2]); - v_tmp->b[0]->p_lk_rght = NULL; - Free_Edge_Lk (tree, v_tmp->b[0]); - Free_Edge (v_tmp->b[0]); - v_tmp->b[1]->p_lk_rght = NULL; - Free_Edge_Lk(tree, v_tmp->b[1]); - Free_Edge(v_tmp->b[1]); - v_tmp->b[2]->p_lk_rght = NULL; - Free_Edge_Lk (tree, v_tmp->b[2]); - Free_Edge (v_tmp->b[2]); - Free_Node (v_tmp); - v_tmp = NULL; - - /* - ** Clean up the temporary edge. - */ - Free_Node (e_brent->left); - Free_Node (e_brent->rght); - e_brent->p_lk_left = NULL; - e_brent->p_lk_rght = NULL; - Free_Edge_Lk (tree, e_brent); - Free_Edge (e_brent); - e_brent = NULL; - - /* - ** Free the temporary partial likelihood and scaling memory. - */ - for (i = 0; i < tree->n_pattern; i++) - { - for (j = 0; j < tree->mod->n_catg; j++) + for(i=0;isize_spr_list_one_edge-1;i++) { - free (p_lk_tmp[i][j]); + for(j=i+1;jsize_spr_list_one_edge;j++) + { + if(tree->spr_list_one_edge[j]->pars < tree->spr_list_one_edge[i]->pars) + { + buff = tree->spr_list_one_edge[i]; + tree->spr_list_one_edge[i] = tree->spr_list_one_edge[j]; + tree->spr_list_one_edge[j] = buff; + } + } } - free (p_lk_tmp[i]); - } - free (p_lk_tmp); - free (sum_scale_tmp); +} - /* - ** Free the subtree distance matrix. - */ - for (i = 0; i < 2*tree->n_otu - 2; i++) - { - free (subtree_dist[i]); - } - free (subtree_dist); - /* - ** Free the arrays for storing the candidate regrafting positions and - ** edge length optimization moves. - */ - for (i = 0; i < MAX(tree->mod->s_opt->wim_n_rgrft,tree->mod->s_opt->wim_n_best); i++) - { - free (rgrft_cand[i]->path); - free (rgrft_cand[i]); - } - free (rgrft_cand); - for (i = 0; i < tree->mod->s_opt->wim_n_optim; i++) - { - free (optim_cand[i]->path); - free (optim_cand[i]); - } - free (optim_cand); - free (path); +/*********************************************************/ +/*********************************************************/ +/*********************************************************/ +void Randomize_Spr_List(t_tree *tree) +{ + int i,j; + t_spr *buff; - /* - ** Print some statistics (for "research" purposes only). - */ -/* printf ("nr_d_L: %d\n", nr_d_L); */ -/* printf ("nr_d_lk: %d\n", nr_d_lk); */ -/* printf ("nr_loc: %d\n", nr_loc); */ -/* printf ("nr_glb: %d\n", nr_glb); */ + for(i=0;in_moves;i++) + { + j = Rand_Int(0,tree->n_moves-1); + buff = tree->spr_list_one_edge[i]; + tree->spr_list_one_edge[i] = tree->spr_list_one_edge[j]; + tree->spr_list_one_edge[j] = buff; + } } +/*********************************************************/ -/* -** Optim_SPR: Optimize the tree using SPR moves. -** -** Parameters: -** - tree: The tree to optimize. -** - max_size: The maximum size (= number of taxa) of the subtrees to be -** pruned. If m=0 or m>ntax, all possible prunings will be -** considered. -** - method: The optimization method to use ("ALL" or "BEST"). -*/ - -void Optim_SPR (arbre *tree, int max_size, int method) +int Spr(phydbl init_lnL, phydbl prop_spr, t_tree *tree) { - int nr_moves, improvement; - node *root; + int i,br; + int *br_idx; + t_edge *b; + + tree->mod->s_opt->n_improvements = 0; + tree->mod->s_opt->max_spr_depth = 0; + tree->mod->s_opt->max_rank_triple_move = 0; + tree->mod->s_opt->max_delta_lnL_spr_current = 0.0; - if(tree->mod->s_opt->print) printf("\n\n. Starting SPR moves...\n"); + Reset_Spr_List(tree->spr_list_all_edge,tree->size_spr_list_all_edge); - /* - ** Calculate the current likelihood value. - */ - tree->both_sides = 1; - cur_lk = Return_Lk (tree); - time(&(tree->t_current)); - if(tree->mod->s_opt->print) Print_Lk(tree,"topology"); + br_idx = Permutate(2*tree->n_otu-3); - /* - ** Optimize all edge lengths and calculate the new likelihood value. - */ -/* printf("\n. Optimizing edge lengths."); */ - root = tree->noeud[0]; - Optimize_Br_Len_Serie (root, root->v[0], root->b[0], tree, tree->data); - tree->both_sides = 1; - cur_lk = Return_Lk (tree); - time(&(tree->t_current)); - if(tree->mod->s_opt->print) Print_Lk(tree,"topology"); - - /* - ** While improvements were found, perform another round of SPR moves. - */ - nr_moves = 0; - improvement = 1; - while (improvement) + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + tree->best_lnL = tree->c_lnL; + + /* PhyML_Printf("\n. init: %f",tree->c_lnL); */ + + for(i=0;in_otu-3)*prop_spr));++i) { - /* - ** Perform one round of SPR moves. - */ - if (method == ALL) - { - improvement = Perform_SPR_Moves (tree, max_size); - } - else if (method == BEST) - { - improvement = Perform_Best_SPR (tree, max_size); - } - else if (method == ONE) - { - improvement = Perform_One_SPR (tree, max_size); - } - else - { - printf ("\n. Unknown SPR optimization method, bailing out...\n"); - exit (1); - } - - /* If an improvement was found, update statistics. */ - if(improvement) - { - nr_moves++; - if((nr_moves == 1) || (nr_moves % 4 == 1)) - { - /* - ** Optimize model parameters. - */ - Optimiz_All_Free_Param (tree, tree->mod->s_opt->print); - tree->both_sides = 1; - Lk(tree); - } - } + br = br_idx[i]; - /* Beg SG 28 May 2007 */ - if(method == BEST || method == ONE) break; - /* Beg SG 28 May 2007 */ - } + if(!(br%10)) if(tree->io->print_json_trace == YES) JSON_Tree_Io(tree,tree->io->fp_out_json_trace); - if(tree->mod->s_opt->print) printf ("\n\n. Number of SPR moves: %d\n", nr_moves); + b = tree->a_edges[br]; + + if(b->l->v > tree->mod->s_opt->l_min_spr) + { + Spr_Subtree(b,b->left,tree); + Spr_Subtree(b,b->rght,tree); + } + } - /* - ** Perform a last round of optimization steps (for edge lengths). - */ - Round_Optimize(tree,tree->data); - Check_NNI_Five_Branches(tree); -} + + Free(br_idx); + + if(tree->mod->s_opt->n_improvements == 0 && tree->mod->s_opt->spr_lnL == YES) + { + Optimize_Br_Len_Serie(2,tree); + tree->best_lnL = tree->c_lnL; + Sort_Spr_List_LnL(tree->spr_list_all_edge,tree->size_spr_list_all_edge,tree); + for(i=0;in_otu-3);++i) + { + Try_One_Spr_Move_Full(tree->spr_list_all_edge[i],NO,tree); + if(tree->spr_list_all_edge[i]->lnL > tree->best_lnL + tree->mod->s_opt->min_diff_lk_move) break; + } + Sort_Spr_List_LnL(tree->spr_list_all_edge,tree->size_spr_list_all_edge,tree); + if(tree->spr_list_all_edge[0]->lnL > tree->best_lnL + tree->mod->s_opt->min_diff_lk_move) + Try_One_Spr_Move_Full(tree->spr_list_all_edge[0],YES,tree); + } + + return tree->mod->s_opt->n_improvements; +} -/* -** Perform_SPR_Moves: Perform a round of SPR moves on the tree. Prune each subtree in -** turn and calculate the change in tree length for each candidate -** regraft position. Estimate change in likelihood for the most -** promising moves, and perform all moves that result in an -** improvement. If no improvements were found at all, try local edge -** length optimization. If still no improvement, try global edge -** length optimization. -** -** Parameters: -** - tree: The tree to perform the SPR moves on. -** - max_size: The maximum size (= number of taxa) of the subtrees to be -** pruned. If m=0 or m>ntax, all possible prunings will be -** considered. -** -** Returns: -** If the current tree could be improved: 1. -** Otherwise: 0. -*/ +/*********************************************************/ -int Perform_SPR_Moves (arbre *tree, int max_size) +void Spr_Pre_Order(t_node *a, t_node *d, t_edge *b, t_tree *tree) { - int nr_edges, i, j, candidate, improvement; - node *root, *v_prune; - edge *e_prune; + if(d->tax) return; + else + { + unsigned int i; + - /* - ** Calculate the average subtree distances. - */ - root = tree->noeud[0]; - PostOrder_v (tree, root->v[0], root->b[0]); + /* printf("\n. a: %d d: %d score: %d d1: %d d2: %d ",a->num,d->num,tree->c_pars); */ - /* - ** Initialize the array of optimization candidates. - */ - for (i = 0; i < tree->mod->s_opt->wim_n_optim; i++) - { - optim_cand[i]->delta_lk = -1.0*BIG; - optim_cand[i]->d_L = -1.0*BIG; - } + /* for(i=0;i<3;++i) */ + /* { */ + /* if(d->v[i] != a) */ + /* { */ + /* Spr_Subtree(d->b[i],d->v[i],tree); */ + /* } */ + /* } */ - /* - ** Try all possible SPR moves and perform the ones that give an improvement. - */ - nr_edges = 2*tree->n_otu - 3; - cur_lk = tree->c_lnL; - improvement = 0; + Spr_Subtree(b,a,tree); + + for(i=0;i<3;++i) + { + if(d->v[i] != a) + { + Spr_Pre_Order(d,d->v[i],d->b[i],tree); + } + } + } +} -/* printf("\n >>>>>>>>>>>>>>>>>>"); */ -/* printf("\n. cur_lk = %f %f",cur_lk,Return_Lk(tree)); */ +/*********************************************************/ -/* printf ("\n. Trying SPR moves"); */ -/* printf ("\n. - calculating tree distances and estimating likelihoods"); */ +void Spr_Subtree(t_edge *b, t_node *link, t_tree *tree) +{ + int i; + int n_moves_pars, n_moves, min_pars, best_move_idx; + t_spr *best_pars_move; + t_edge *init_target, *dummy, *residual; + + if(link->v[0] == NULL || link->v[1] == NULL || link->v[2] == NULL) return; - for(i = 0; i < nr_edges; i++) - { - /* - ** Get the next prune edge. - */ - e_prune = tree->t_edges[i]; - /* - ** Try right subtree if appropriate. - */ - if (!e_prune->left->tax) - { - /* - ** Clear the regraft candidate list. - */ - for (j = 0; j < tree->mod->s_opt->wim_n_rgrft; j++) - { - rgrft_cand[j]->d_L = -1.0*BIG; - } - v_prune = e_prune->left; - if ((max_size == 0) || (e_prune->num_tax_rght <= max_size)) - { - /* - ** Calculate changes in tree length, and estimate changes in likelihood for - ** the most promising candidates. Perform moves that give an improvement. - */ - Calc_Tree_Length (e_prune, v_prune, tree); - if ((candidate = Est_Lk_Change (e_prune, v_prune, tree)) >= 0) - { - improvement = 1; - Make_Move (rgrft_cand[candidate],0,tree); -/* printf("\n. Make simple move"); */ -/* printf("\n. lk after simple move = %f",Return_Lk(tree)); */ - } - } - } - /* - ** Try left subtree if appropriate. - */ - if (!e_prune->rght->tax) - { - /* - ** Clear the regraft candidate list. - */ - for (j = 0; j < tree->mod->s_opt->wim_n_rgrft; j++) - { - rgrft_cand[j]->d_L = -1.0*BIG; - } - v_prune = e_prune->rght; - if ((max_size == 0) || (e_prune->num_tax_left <= max_size)) - { - /* - ** Calculate changes in tree length, and estimate changes in likelihood for - ** the most promising candidates. Perform moves that give an improvement. - */ - Calc_Tree_Length (e_prune, v_prune, tree); - if ((candidate = Est_Lk_Change (e_prune, v_prune, tree)) >= 0) - { - improvement = 1; - Make_Move (rgrft_cand[candidate],0,tree); -/* printf("\n. Make simple move"); */ -/* printf("\n. lk after simple move = %f",Return_Lk(tree)); */ - } - } - } - } - - /* - ** If there was no improvement at all, try local edge length optimization at the - ** regraft position. - */ + Reset_Spr_List(tree->spr_list_one_edge,tree->size_spr_list_one_edge); + + best_move_idx = -1; + tree->n_moves = 0; -/* printf("\n. before local = %f %f",tree->c_lnL,Return_Lk(tree)); */ + MIXT_Set_Pars_Thresh(tree); - if (!improvement) + if((link != b->left) && (link != b->rght)) { - /* printf ("\n. - performing local edge length optimizations"); */ - if ((candidate = Find_Optim_Local (tree)) >= 0) - { -/* printf("\n. make local move"); */ - improvement = 1; - Make_Move (optim_cand[candidate],1,tree); -/* printf("\n. lk after local move = %f",Return_Lk(tree)); */ - } + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); } - - - /* - ** If there was still no improvement, try global edge length optimization. - */ -/* printf("\n. before global = %f %f",tree->c_lnL,Return_Lk(tree)); */ - - if (!improvement) + else { -/* printf ("\n. - performing global edge length optimization"); */ - if ((candidate = Find_Optim_Globl (tree)) >= 0) - { -/* printf("\n. make global move"); */ - improvement = 1; - Make_Move (optim_cand[candidate],2,tree); -/* printf("\n. lk after global move = %f",Return_Lk(tree)); */ - } + tree->mod->s_opt->worst_lnL_spr = BIG; + + if(!link->tax) Test_All_Spr_Targets(b,link,tree); + + if(tree->n_moves) + { + n_moves_pars = MIN(tree->mod->s_opt->min_n_triple_moves,tree->n_moves); + n_moves = MIN(tree->mod->s_opt->min_n_triple_moves,tree->n_moves); + + if(tree->mod->s_opt->spr_lnL == NO) n_moves = n_moves_pars; + n_moves = MAX(1,n_moves); + + if(tree->mod->s_opt->spr_pars == YES) + { + min_pars = 1E+8; + best_pars_move = NULL; + + for(i=0;ispr_list_one_edge[i]->pars < min_pars) + { + best_pars_move = tree->spr_list_one_edge[i]; + min_pars = tree->spr_list_one_edge[i]->pars; + } + } + + assert(best_pars_move); + + if(best_pars_move->pars < tree->best_pars) + { + Prune_Subtree(best_pars_move->n_link,best_pars_move->n_opp_to_link,&init_target,&residual,tree); + Graft_Subtree(best_pars_move->b_target,best_pars_move->n_link,NULL,residual,NULL,tree); + if(!Check_Topo_Constraints(tree,tree->io->cstr_tree)) + { + Prune_Subtree(best_pars_move->n_link,best_pars_move->n_opp_to_link,&dummy,&residual,tree); + Graft_Subtree(init_target,best_pars_move->n_link,NULL,residual,NULL,tree); + Set_Both_Sides(YES,tree); + Pars(NULL,tree); + } + else + { + if(best_pars_move->depth_path > tree->mod->s_opt->max_spr_depth) tree->mod->s_opt->max_spr_depth = best_pars_move->depth_path; + Set_Both_Sides(YES,tree); + Pars(NULL,tree); + tree->best_pars = tree->c_pars; + if(tree->best_pars != best_pars_move->pars) + { + PhyML_Fprintf(stderr,"\n== best_pars = %d move_pars = %d",tree->best_pars,best_pars_move->pars); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } + tree->mod->s_opt->n_improvements++; + } + Reset_Spr_List(tree->spr_list_one_edge,tree->size_spr_list_one_edge); + } + else + { + Set_Both_Sides(YES,tree); + Pars(NULL,tree); + } + } + else + { + int apply_move = NO; + phydbl accept_prob,u; + + if(tree->mod->s_opt->spr_lnL == YES) + { + Sort_Spr_List_LnL(tree->spr_list_one_edge,tree->size_spr_list_one_edge,tree); + + if(tree->spr_list_one_edge[0]->lnL > tree->best_lnL) + { + best_move_idx = 0; + } + else if(tree->mod->s_opt->eval_list_regraft == YES) + { + best_move_idx = Evaluate_List_Of_Regraft_Pos_Triple(tree->spr_list_one_edge,n_moves,tree); + } + else + { + best_move_idx = -1; + } + } + else + { + best_move_idx = Evaluate_List_Of_Regraft_Pos_Triple(tree->spr_list_one_edge,n_moves,tree); + } + + if(best_move_idx > -1) + { + if(Are_Equal(tree->annealing_temp,0.0,1.E-3) == NO) + { + accept_prob = exp((tree->spr_list_one_edge[best_move_idx]->lnL - tree->best_lnL)/tree->annealing_temp); + u = Uni(); + if(!(u > accept_prob)) apply_move = YES; + } + else + { + if(tree->spr_list_one_edge[best_move_idx]->lnL > tree->best_lnL + tree->mod->s_opt->min_diff_lk_move) + apply_move = YES; + } + } + + if((best_move_idx > -1) && (apply_move == YES)) + { + Try_One_Spr_Move_Triple(tree->spr_list_one_edge[best_move_idx],tree); + } + else + { + Pars(NULL,tree); + } + } + } + Reset_Spr_List(tree->spr_list_one_edge,tree->size_spr_list_one_edge); } - -/* printf("\n. after all = %f %f",tree->c_lnL,Return_Lk(tree)); */ - - /* - ** Optimize all edge lengths again to make sure we got an updated - ** likelihood value. - */ - tree->both_sides = 1; - cur_lk = Return_Lk (tree); - root = tree->noeud[0]; - Optimize_Br_Len_Serie (root, root->v[0], root->b[0], tree, tree->data); - tree->both_sides = 1; - cur_lk = Return_Lk (tree); - time(&(tree->t_current)); - if(tree->mod->s_opt->print) Print_Lk(tree,"topology"); - - /* - ** Return the result. - */ - return (improvement); } +/*********************************************************/ -/* -** Perform_Best_SPR: Perform the best SPR move on the tree. Prune each subtree in -** turn and calculate the change in tree length for each candidate -** regraft position. Estimate change in likelihood for the most -** promising regraft positions, and store the best one. Then choose -** the best candidate over all moves. If no improving move can be -** found, try local edge length optimization, and if necessary -** global edge length optimization. -** -** Parameters: -** - tree: The tree to perform the SPR moves on. -** - max_size: The maximum size (= number of taxa) of the subtrees to be -** pruned. If m=0 or m>ntax, all possible prunings will be -** considered. -** -** Returns: -** If an improving move could be performed: 1. -** Otherwise: 0. -*/ - -int Perform_Best_SPR (arbre *tree, int max_size) +int Test_All_Spr_Targets(t_edge *b_pulled, t_node *n_link, t_tree *tree) { - int nr_edges, i, j, candidate, improvement; - node *root, *v_prune; - edge *e_prune; - - /* - ** Calculate the average subtree distances. - */ - root = tree->noeud[0]; - PostOrder_v (tree, root->v[0], root->b[0]); - - /* - ** Initialize the array of optimization candidates. - */ - for (i = 0; i < tree->mod->s_opt->wim_n_optim; i++) - { - optim_cand[i]->delta_lk = -1.0*BIG; - optim_cand[i]->d_L = -1.0*BIG; - } + t_node *n_opp_to_link,*n_v1,*n_v2; + t_edge *b_target,*b_residual; + int i,dir1,dir2; + scalar_dbl *init_l_v1, *init_l_v2, *init_l_pulled; + scalar_dbl *init_v_v1, *init_v_v2, *init_v_pulled; + int best_found; + phydbl init_lnL; - /* - ** Try all possible SPR moves and perform the best one. - */ - nr_edges = 2*tree->n_otu - 3; - cur_lk = tree->c_lnL; - improvement = 0; -/* printf ("\n. Trying SPR moves"); */ -/* printf ("\n. -calculating tree distances and estimating likelihoods"); */ - for (i = 0; i < nr_edges; i++) - { - /* - ** Get the next prune edge. - */ - e_prune = tree->t_edges[i]; - /* - ** Try right subtree if appropriate. - */ - if (!e_prune->left->tax) + if(tree->mixt_tree != NULL) { - /* - ** Clear the regraft candidate list. - */ - for (j = 0; j < tree->mod->s_opt->wim_n_best; j++) - { - rgrft_cand[j]->d_L = -1.0*BIG; - } - v_prune = e_prune->left; - if ((max_size == 0) || (e_prune->num_tax_rght <= max_size)) - { - /* - ** Calculate changes in tree length, and estimate changes in likelihood for - ** the most promising candidates. Store the best one in the optimization list. - */ - Calc_Tree_Length (e_prune, v_prune, tree); - candidate = Best_Lk_Change (e_prune, v_prune, tree); - } + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); } - /* - ** Try left subtree if appropriate. - */ - if (!e_prune->rght->tax) - { - /* - ** Clear the regraft candidate list. - */ - for (j = 0; j < tree->mod->s_opt->wim_n_rgrft; j++) - { - rgrft_cand[j]->d_L = -1.0*BIG; - } - v_prune = e_prune->rght; - if ((max_size == 0) || (e_prune->num_tax_left <= max_size)) + + init_lnL = tree->c_lnL; + b_target = b_residual = NULL; + n_opp_to_link = (n_link == b_pulled->rght)?(b_pulled->left):(b_pulled->rght); + + init_l_pulled = Duplicate_Scalar_Dbl(b_pulled->l); + init_v_pulled = Duplicate_Scalar_Dbl(b_pulled->l_var); + + dir1 = dir2 = -1; + for(i=0;i<3;i++) + if(n_link->v[i] != n_opp_to_link) { - /* - ** Calculate changes in tree length, and estimate changes in likelihood for - ** the most promising candidates. Perform moves that give an improvement. - */ - Calc_Tree_Length (e_prune, v_prune, tree); - candidate = Best_Lk_Change (e_prune, v_prune, tree); + if(dir1<0) dir1 = i; + else dir2 = i; } - } - } - /* If the best candidate has a positive estimated change in - ** likelihood, perform that move. - */ - if (optim_cand[0]->delta_lk > 1.0/BIG) - { - improvement = 1; - Make_Move (optim_cand[0],0,tree); - } + assert(dir1 > -1); + assert(dir2 > -1); - /* - ** If there was no improvement at all, try local edge length optimization at the - ** regraft position. - */ - if (!improvement) - { -/* printf ("\n. - performing local edge length optimizations"); */ - if ((candidate = Find_Optim_Local (tree)) >= 0) + if(n_link->v[dir1]->num < n_link->v[dir2]->num) { - improvement = 1; - Make_Move (optim_cand[candidate],1,tree); + n_v1 = n_link->v[dir1]; + n_v2 = n_link->v[dir2]; + init_l_v1 = Duplicate_Scalar_Dbl(n_link->b[dir1]->l); + init_l_v2 = Duplicate_Scalar_Dbl(n_link->b[dir2]->l); + init_v_v1 = Duplicate_Scalar_Dbl(n_link->b[dir1]->l_var); + init_v_v2 = Duplicate_Scalar_Dbl(n_link->b[dir2]->l_var); } - } - - /* - ** If there was still no improvement, try global edge length optimization. - */ - if (!improvement) - { -/* printf ("\n. - performing global edge length optimization"); */ - if ((candidate = Find_Optim_Globl (tree)) >= 0) + else { - improvement = 1; - Make_Move (optim_cand[candidate],2,tree); + n_v1 = n_link->v[dir2]; + n_v2 = n_link->v[dir1]; + init_l_v1 = Duplicate_Scalar_Dbl(n_link->b[dir2]->l); + init_l_v2 = Duplicate_Scalar_Dbl(n_link->b[dir1]->l); + init_v_v1 = Duplicate_Scalar_Dbl(n_link->b[dir2]->l_var); + init_v_v2 = Duplicate_Scalar_Dbl(n_link->b[dir1]->l_var); } - } - /* - ** Optimize all edge lengths again to make sure we got an updated - ** likelihood value. - */ - tree->both_sides = 1; - cur_lk = Return_Lk (tree); - root = tree->noeud[0]; - Optimize_Br_Len_Serie (root, root->v[0], root->b[0], tree, tree->data); - tree->both_sides = 1; - cur_lk = Return_Lk (tree); - time(&(tree->t_current)); - if(tree->mod->s_opt->print) Print_Lk(tree,"topology"); - - /* - ** Return the result. - */ - return (improvement); -} + if(!(n_v1->tax && n_v2->tax)) /*! Pruning is meaningless otherwise */ + { + Prune_Subtree(n_link,n_opp_to_link,&b_target,&b_residual,tree); + if(tree->mod->s_opt->spr_lnL == YES) Update_PMat_At_Given_Edge(b_target,tree); + + for(i=0;isize_spr_list_one_edge;++i) tree->spr_list_one_edge[i]->path_prev = NULL; + + tree->edge_list = NULL; + tree->node_list = NULL; + best_found = NO; + tree->depth_curr_path = 0; + tree->curr_path[0] = b_target->left; + Test_One_Spr_Target_Recur(b_target->rght, + b_target->left, + b_pulled,n_link,b_residual,b_target,&best_found,NULL,tree); + + if(best_found == NO || tree->perform_spr_right_away == NO) + { + tree->depth_curr_path = 0; + tree->curr_path[0] = b_target->rght; + Test_One_Spr_Target_Recur(b_target->left, + b_target->rght, + b_pulled,n_link,b_residual,b_target,&best_found,NULL,tree); + } + + Graft_Subtree(b_target,n_link,NULL,b_residual,NULL,tree); + + if((n_link->v[dir1] != n_v1) || (n_link->v[dir2] != n_v2)) PhyML_Printf("\n== Warning: -- SWITCH NEEDED -- ! \n"); + + Copy_Scalar_Dbl(init_l_v1,n_link->b[dir1]->l); + Copy_Scalar_Dbl(init_v_v1,n_link->b[dir1]->l_var); + + Copy_Scalar_Dbl(init_l_v2,n_link->b[dir2]->l); + Copy_Scalar_Dbl(init_v_v2,n_link->b[dir2]->l_var); + + Copy_Scalar_Dbl(init_l_pulled,b_pulled->l); + Copy_Scalar_Dbl(init_v_pulled,b_pulled->l_var); + + if(tree->mod->s_opt->spr_pars == NO) + { + Update_PMat_At_Given_Edge(n_link->b[dir1],tree); + Update_PMat_At_Given_Edge(n_link->b[dir2],tree); + Update_PMat_At_Given_Edge(b_pulled,tree); + } + + if(tree->mod->s_opt->spr_pars == NO) + { + Update_Partial_Lk(tree,b_pulled, n_link); + Update_Partial_Lk(tree,b_target, n_link); + Update_Partial_Lk(tree,b_residual,n_link); + } + else + { + Update_Partial_Pars(tree,b_pulled, n_link); + Update_Partial_Pars(tree,b_target, n_link); + Update_Partial_Pars(tree,b_residual,n_link); + } + + t_ll *e_ll = tree->edge_list->head; + t_ll *n_ll = tree->node_list->head; + t_edge *e; + t_node *n; + do + { + assert(e_ll); + assert(n_ll); + + e = (t_edge *)e_ll->v; + n = (t_node *)n_ll->v; + + /* printf("\n. update on edge %d node %d",e->num,n->num); fflush(NULL); */ + if(tree->mod->s_opt->spr_lnL) + Update_Partial_Lk(tree,e,n); + else + Update_Partial_Pars(tree,e,n); + + e_ll = e_ll->next; + n_ll = n_ll->next; + } + while(e_ll != NULL); -/* -** Perform_One_Moves: Perform a round of SPR moves on the tree. Prune each subtree in -** turn and calculate the change in tree length for each candidate -** regraft position. Estimate change in likelihood for the most -** promising moves, and perform the first move that results in an -** improvement. If no improvements were found at all, try local edge -** length optimization. If still no improvement, try global edge -** length optimization. -** -** Parameters: -** - tree: The tree to perform the SPR moves on. -** - max_size: The maximum size (= number of taxa) of the subtrees to be -** pruned. If m=0 or m>ntax, all possible prunings will be -** considered. -** -** Returns: -** If the current tree could be improved: 1. -** Otherwise: 0. -*/ -int Perform_One_SPR(arbre *tree, int max_size) -{ - int nr_edges, i, j, candidate, improvement; - node *root, *v_prune; - edge *e_prune; + + Free_Linked_List(tree->edge_list); + Free_Linked_List(tree->node_list); + } - /* - ** Calculate the average subtree distances. - */ - - root = tree->noeud[0]; - PostOrder_v (tree, root->v[0], root->b[0]); + tree->c_lnL = init_lnL; - /* - ** Initialize the array of optimization candidates. - */ - for (i = 0; i < tree->mod->s_opt->wim_n_optim; i++) - { - optim_cand[i]->delta_lk = -1.0*BIG; - optim_cand[i]->d_L = -1.0*BIG; - } + Free_Scalar_Dbl(init_l_v1); + Free_Scalar_Dbl(init_l_v2); + Free_Scalar_Dbl(init_l_pulled); - /* - ** Try all possible SPR moves and perform the ones that give an improvement. - */ - nr_edges = 2*tree->n_otu - 3; - cur_lk = tree->c_lnL; - improvement = 0; - -/* printf("\n >>>>>>>>>>>>>>>>>>"); */ -/* printf("\n. cur_lk = %f %f",cur_lk,Return_Lk(tree)); */ + Free_Scalar_Dbl(init_v_v1); + Free_Scalar_Dbl(init_v_v2); + Free_Scalar_Dbl(init_v_pulled); -/* printf ("\n. Trying SPR moves"); */ -/* printf ("\n. - calculating tree distances and estimating likelihoods"); */ + return 0; +} - for(i = 0; i < nr_edges; i++) - { - /* - ** Get the next prune edge. - */ - e_prune = tree->t_edges[i]; - /* - ** Try right subtree if appropriate. - */ - if (!e_prune->left->tax) - { - /* - ** Clear the regraft candidate list. - */ - for (j = 0; j < tree->mod->s_opt->wim_n_rgrft; j++) - { - rgrft_cand[j]->d_L = -1.0*BIG; - } - v_prune = e_prune->left; - if ((max_size == 0) || (e_prune->num_tax_rght <= max_size)) - { - /* - ** Calculate changes in tree length, and estimate changes in likelihood for - ** the most promising candidates. Perform moves that give an improvement. - */ - Calc_Tree_Length (e_prune, v_prune, tree); - if ((candidate = Est_Lk_Change (e_prune, v_prune, tree)) >= 0) - { - improvement = 1; - Make_Move (rgrft_cand[candidate],0,tree); - } - } - } - /* - ** Try left subtree if appropriate. - */ - if (!e_prune->rght->tax && !improvement) - { - /* - ** Clear the regraft candidate list. - */ - for (j = 0; j < tree->mod->s_opt->wim_n_rgrft; j++) - { - rgrft_cand[j]->d_L = -1.0*BIG; - } - v_prune = e_prune->rght; - if ((max_size == 0) || (e_prune->num_tax_left <= max_size)) - { - /* - ** Calculate changes in tree length, and estimate changes in likelihood for - ** the most promising candidates. Perform moves that give an improvement. - */ - Calc_Tree_Length (e_prune, v_prune, tree); - if ((candidate = Est_Lk_Change (e_prune, v_prune, tree)) >= 0) - { - improvement = 1; - Make_Move (rgrft_cand[candidate],0,tree); -/* printf("\n. Make simple move"); */ -/* printf("\n. lk after simple move = %f",Return_Lk(tree)); */ - } - } - } - if(improvement) break; - } +/*********************************************************/ + +void Test_One_Spr_Target_Recur(t_node *a, t_node *d, t_edge *pulled, t_node *link, t_edge *residual, t_edge *init_target, int *best_found, t_spr *prev_move, t_tree *tree) +{ + unsigned int i; + t_spr *move,*next_move; - /* - ** If there was no improvement at all, try local edge length optimization at the - ** regraft position. - */ + move = next_move = NULL; + + if(*best_found == YES && tree->perform_spr_right_away == YES) return; + + if(d->tax) return; + else + { + for(i=0;i<3;++i) + { + if(d->v[i] != a) + { + + if(tree->mod->s_opt->spr_pars == NO) + Update_Partial_Lk(tree,d->b[i],d); + else + Update_Partial_Pars(tree,d->b[i],d); + + /* printf("\n push edge %d node %d",d->b[i]->num,d->num); fflush(NULL); */ + Push_Bottom_Linked_List(d->b[i],&tree->edge_list,NO); + Push_Bottom_Linked_List(d,&tree->node_list,NO); + + tree->depth_curr_path++; + + tree->curr_path[tree->depth_curr_path] = d->v[i]; + + if((tree->depth_curr_path <= tree->mod->s_opt->max_depth_path) && + (tree->depth_curr_path >= tree->mod->s_opt->min_depth_path)) + { + + move = Test_One_Spr_Target(d->b[i],pulled,link,residual,init_target,d,tree); + + move->path_prev = prev_move; + + if((tree->mod->s_opt->spr_pars == NO && move->lnL > tree->best_lnL + tree->mod->s_opt->min_diff_lk_move) || + (tree->mod->s_opt->spr_pars == YES && move->pars < tree->best_pars)) + { + *best_found = YES; + } + } + + bool go_to_next = + (tree->depth_curr_path < tree->mod->s_opt->max_depth_path && + ((tree->mod->s_opt->spr_pars == NO && move && move->lnL > tree->best_lnL - tree->mod->s_opt->max_delta_lnL_spr) || + tree->mod->s_opt->spr_pars == YES)); + + /* bool go_to_next = tree->depth_curr_path < tree->mod->s_opt->max_depth_path; */ + + if(go_to_next == YES) Test_One_Spr_Target_Recur(d,d->v[i],pulled,link,residual,init_target,best_found,move,tree); + + tree->depth_curr_path--; + } + } + } +} -/* printf("\n. before local = %f %f",tree->c_lnL,Return_Lk(tree)); */ +/*********************************************************/ - if (!improvement) +t_spr *Test_One_Spr_Target(t_edge *b_target, t_edge *b_arrow, t_node *n_link, t_edge *b_residual, t_edge *init_target, t_node *polarity, t_tree *tree) +{ + scalar_dbl *init_target_l, *init_arrow_l, *init_residual_l; + scalar_dbl *init_target_v, *init_arrow_v, *init_residual_v; + int i,dir_v0,dir_v1,dir_v2; + scalar_dbl *l0,*l1,*l2; + scalar_dbl *v0,*v1,*v2; + t_node *n1,*n2; + phydbl init_lnL; + int init_pars; + t_spr *move; + unsigned int rk; + + if(tree->mixt_tree != NULL) { - /* printf ("\n. - performing local edge length optimizations"); */ - if ((candidate = Find_Optim_Local (tree)) >= 0) - { -/* printf("\n. make local move"); */ - improvement = 1; - Make_Move (optim_cand[candidate],1,tree); -/* printf("\n. lk after local move = %f",Return_Lk(tree)); */ - } + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); } - - /* - ** If there was still no improvement, try global edge length optimization. - */ -/* printf("\n. before global = %f %f",tree->c_lnL,Return_Lk(tree)); */ + tree->n_moves++; + + init_lnL = tree->c_lnL; + init_pars = tree->c_pars; + + move = tree->spr_list_one_edge[tree->size_spr_list_one_edge]; - if (!improvement) + if(move->init_target_l == NULL) { -/* printf ("\n. - performing global edge length optimization"); */ - if ((candidate = Find_Optim_Globl (tree)) >= 0) - { -/* printf("\n. make global move"); */ - improvement = 1; - Make_Move (optim_cand[candidate],2,tree); -/* printf("\n. lk after global move = %f",Return_Lk(tree)); */ - } + move->init_target_l = Duplicate_Scalar_Dbl(init_target->l); + move->init_target_v = Duplicate_Scalar_Dbl(init_target->l_var); + } + else + { + Copy_Scalar_Dbl(init_target->l, move->init_target_l); + Copy_Scalar_Dbl(init_target->l_var,move->init_target_v); } - -/* printf("\n. after all = %f %f",tree->c_lnL,Return_Lk(tree)); */ - /* - ** Optimize all edge lengths again to make sure we got an updated - ** likelihood value. - */ - tree->both_sides = 1; - cur_lk = Return_Lk (tree); - root = tree->noeud[0]; - Optimize_Br_Len_Serie (root, root->v[0], root->b[0], tree, tree->data); - tree->both_sides = 1; - cur_lk = Return_Lk (tree); - time(&(tree->t_current)); - if(tree->mod->s_opt->print) Print_Lk(tree,"topology"); - - /* - ** Return the result. - */ - return (improvement); -} + // Save edge lengths so that they can be recovered in the end + init_target_l = Duplicate_Scalar_Dbl(b_target->l); + init_target_v = Duplicate_Scalar_Dbl(b_target->l_var); -/* -** Calc_Tree_Length: Calculate the change in tree length, given a pruned subtree, -** for each possible regraft position. -** -** Parameters: -** - e_prune: The edge at which the subtree is pruned. -** - v_prune: The root of the pruned subtree. -*/ + init_arrow_l = Duplicate_Scalar_Dbl(b_arrow->l); + init_arrow_v = Duplicate_Scalar_Dbl(b_arrow->l_var); -void Calc_Tree_Length (edge *e_prune, node *v_prune, arbre *tree) -{ - int i, d0, d1, d2; - phydbl d_uu; - node *u_prune, *u1, *u2; + init_residual_l = Duplicate_Scalar_Dbl(b_residual->l); + init_residual_v = Duplicate_Scalar_Dbl(b_residual->l_var); - /* - ** Get the directions from node v_prune. - */ - d0 = -1; - u_prune = NULL; - for (i = 0; i < 3; i++) - { - if (v_prune->b[i] == e_prune) - { - d0 = i; - u_prune = v_prune->v[i]; - break; - } - } - d1 = (d0 + 1) % 3; - d2 = 3 - d0 - d1; + Graft_Subtree(b_target,n_link,NULL,b_residual,NULL,tree); - /* - ** Get the relevant average subtree distance within the pruned subtree. - */ - if (!u_prune->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) + if(tree->mod->s_opt->spr_lnL == YES) { - if (u_prune->b[i] != e_prune) - { - if (u1 == NULL) - { - u1 = u_prune->v[i]; - } - else - { - u2 = u_prune->v[i]; - } - } + Update_PMat_At_Given_Edge(b_target,tree); + Update_PMat_At_Given_Edge(b_residual,tree); + Update_Partial_Lk(tree,b_arrow,n_link); + Lk(b_arrow,tree); } - d_uu = subtree_dist[u1->num][u2->num]; - } else - { - d_uu = 0.0; - } - - /* - ** Recursively calculate the change in tree length for each - ** possible regraft position. - ** - ** First recurse into direction d1. - */ - if (!v_prune->v[d1]->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) { - if (v_prune->v[d1]->b[i] != v_prune->b[d1]) - { - if (u1 == NULL) - { - u1 = v_prune->v[d1]->v[i]; - } - else - { - u2 = v_prune->v[d1]->v[i]; - } - } + Update_Partial_Pars(tree,b_arrow,n_link); + Pars(b_arrow,tree); } - Tree_Length(v_prune, u_prune, v_prune->v[d1], v_prune->v[d2], u1, v_prune->v[d2], - u2, subtree_dist[u_prune->num][v_prune->v[d2]->num], d_uu, 0.0, 1, tree); - Tree_Length(v_prune, u_prune, v_prune->v[d1], v_prune->v[d2], u2, v_prune->v[d2], - u1, subtree_dist[u_prune->num][v_prune->v[d2]->num], d_uu, 0.0, 1, tree); - } - /* - ** Next recurse into direction d2. - */ - if (!v_prune->v[d2]->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) + + n1 = (b_residual->left == n_link)?(b_residual->rght):(b_residual->left); + n2 = (b_target->left == n_link)?(b_target->rght):(b_target->left); + dir_v1 = dir_v2 = dir_v0 = -1; + for(i=0;i<3;++i) { - if (v_prune->v[d2]->b[i] != v_prune->b[d2]) - { - if (u1 == NULL) - { - u1 = v_prune->v[d2]->v[i]; - } - else - { - u2 = v_prune->v[d2]->v[i]; - } - } + if(n_link->v[i] == n1) dir_v1 = i; + else if(n_link->v[i] == n2) dir_v2 = i; + else dir_v0 = i; } - Tree_Length(v_prune, u_prune, v_prune->v[d2], v_prune->v[d1], u1, v_prune->v[d1], - u2, subtree_dist[u_prune->num][v_prune->v[d1]->num], d_uu, 0.0, 1, tree); - Tree_Length(v_prune, u_prune, v_prune->v[d2], v_prune->v[d1], u2, v_prune->v[d1], - u1, subtree_dist[u_prune->num][v_prune->v[d1]->num], d_uu, 0.0, 1, tree); - } -} + l0 = Duplicate_Scalar_Dbl(n_link->b[dir_v0]->l); + v0 = Duplicate_Scalar_Dbl(n_link->b[dir_v0]->l_var); -/* -** Tree_Length: Recursively calculate the change in tree length for a given pruned -** subtree and regraft position. -** -** Parameters: -** - v_prune: The root of the pruned subtree. -** - u_prune: The node adjacent to v_p along the pruned edge. -** - v_n: The node adjacent to the regraft edge in the "backward" direction. -** - v_n_1: The previous v_n. -** - v_nx1: The node adjacent to the regrafting edge in the "forward" direction. -** - v_0: The other node originally adjacent to v_p; -** - u_n: The other node adjecent to v_n (besides v_n_1 and v_nx1); -** - d_uv_1: The distance between u_p and v_n_1; -** - d_uu: The subtree distance between descendants of u_prune. -** - d_L_1: The previous change in tree length. -** - n: The current distance from the prune position. -*/ - -void Tree_Length (node *v_prune, node *u_prune, node *v_n, node *v_n_1, node *v_nx1, - node *v_0, node *u_n, phydbl d_up_v_1, phydbl d_L_1, phydbl d_uu, - int n, arbre *tree) -{ - int i, j; - phydbl d_un_v, d_up_v, d_L; - node *u1, *u2; - edge *e_prune, *e_regraft; - _move_ *tmp_cand; - - /* - ** Update the path and number of calculations. - */ - path[n] = v_n; - nr_d_L++; - e_prune = NULL; - e_regraft = NULL; - - /* - ** Calculate the change in tree length for the current pruned subtree and regraft - ** position. - */ - if (n == 1) - { - d_un_v = subtree_dist[u_n->num][v_0->num]; - } - else - { - d_un_v = subtree_dist[u_n->num][v_n_1->num] - - (pow (0.5, n) * subtree_dist[u_n->num][u_prune->num]) + - (pow (0.5, n) * subtree_dist[u_n->num][v_0->num]); - } - d_up_v = 0.5 * (d_up_v_1 + subtree_dist[u_prune->num][u_n->num]); - /* - ** Alternative method for calculating d_up_v. Just kept it around for reference... - ** - d_up_v = subtree_dist[u_prune->num][u_n->num] - (0.5 * d_uu); - if (!u_n->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) + if(n_link->v[dir_v1]->num > n_link->v[dir_v2]->num) { - if (u_n->v[i] != v_n) - { - if (u1 == NULL) - { - u1 = u_n->v[i]; - } - else - { - u2 = u_n->v[i]; - } - } + l1 = Duplicate_Scalar_Dbl(n_link->b[dir_v2]->l); + v1 = Duplicate_Scalar_Dbl(n_link->b[dir_v2]->l_var); + l2 = Duplicate_Scalar_Dbl(n_link->b[dir_v1]->l); + v2 = Duplicate_Scalar_Dbl(n_link->b[dir_v1]->l_var); } - d_up_v -= 0.5 * subtree_dist[u1->num][u2->num]; - } - for (i = 0; i < 3; i++) - { - if (u_n->v[i] == v_n) + else { - d_up_v -= u_n->b[i]->l; - break; + l1 = Duplicate_Scalar_Dbl(n_link->b[dir_v1]->l); + v1 = Duplicate_Scalar_Dbl(n_link->b[dir_v1]->l_var); + l2 = Duplicate_Scalar_Dbl(n_link->b[dir_v2]->l); + v2 = Duplicate_Scalar_Dbl(n_link->b[dir_v2]->l_var); } - } - */ - d_L = d_L_1 + 0.25*((d_up_v_1 + subtree_dist[u_n->num][v_nx1->num]) - - (d_un_v + subtree_dist[u_prune->num][v_nx1->num])); - /* - ** If the change is within the tree->mod->s_opt->wim_n_rgrft best ones so far, save it. - */ - if (d_L > rgrft_cand[tree->mod->s_opt->wim_n_rgrft-1]->d_L) - { - for (i = 0; i < 3; i++) + for(i=0;idepth_curr_path+1;++i) move->path[i] = tree->curr_path[i]; + + if(move->l0 != NULL) { - if (v_prune->v[i] == u_prune) - { - e_prune = v_prune->b[i]; - } - if (v_n->v[i] == v_nx1) - { - e_regraft = v_n->b[i]; - } + Free_Scalar_Dbl(move->l0); + Free_Scalar_Dbl(move->v0); } - i = tree->mod->s_opt->wim_n_rgrft-1; - rgrft_cand[i]->v_prune = v_prune; - rgrft_cand[i]->u_prune = u_prune; - rgrft_cand[i]->v_n = v_n; - rgrft_cand[i]->v_nx1 = v_nx1; - rgrft_cand[i]->u_n = u_n; - rgrft_cand[i]->e_prune = e_prune; - rgrft_cand[i]->e_regraft = e_regraft; - rgrft_cand[i]->d_L = d_L; - rgrft_cand[i]->d_up_v = d_up_v; - rgrft_cand[i]->d_un_v = d_un_v; - rgrft_cand[i]->dist = n; - for (j = 1; j <= n; j++) - { - rgrft_cand[i]->path[j] = path[j]; - } - - rgrft_cand[i]->path[n+1] = v_nx1; - /* - ** Move the candidate to the appropriate position in the list, so the list - ** remains sorted in decreasing d_L value. - */ - while ((i > 0) && (rgrft_cand[i]->d_L > rgrft_cand[i-1]->d_L)) + + if(move->l1 != NULL) { - tmp_cand = rgrft_cand[i]; - rgrft_cand[i] = rgrft_cand[i-1]; - rgrft_cand[i-1] = tmp_cand; - i--; + Free_Scalar_Dbl(move->l1); + Free_Scalar_Dbl(move->v1); } - } - /* - ** Recurse. - */ - if (n < tree->mod->s_opt->wim_max_dist) - { - if (!v_nx1->tax) + if(move->l2 != NULL) { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (v_nx1->v[i] != v_n) - { - if (u1 == NULL) - { - u1 = v_nx1->v[i]; - } - else - { - u2 = v_nx1->v[i]; - } - } - } - Tree_Length (v_prune, u_prune, v_nx1, v_n, u1, v_0, u2, d_up_v, d_uu, d_L, n+1, tree); - Tree_Length (v_prune, u_prune, v_nx1, v_n, u2, v_0, u1, d_up_v, d_uu, d_L, n+1, tree); + Free_Scalar_Dbl(move->l2); + Free_Scalar_Dbl(move->v2); } - } -} + move->l0 = l0; + move->v0 = v0; -/* -** Est_Lk_Change: Estimate the changes in likelihood for the most promising candidate -** regraft positions given a pruned subtree. -** -** Parameters: -** - e_prune: The edge at which the subtree was pruned. -** - v_prune: The root of the pruned subtree. -** - tree: The tree on which to do the calculations. -** -** Returns: -** If an improvement as found: The candidate which gives the improvement (which -** will be the first one found). -** Otherwise: -1. -*/ + move->l1 = l1; + move->v1 = v1; -int Est_Lk_Change (edge *e_prune, node *v_prune, arbre *tree) -{ - int i, j, cand, best_cand, d0, d1, d2, n, pat, cat, ste; - phydbl d_uu, best_d_lk, l_connect, l_01, l_02, l_12, l_est[3], new_lk, - ***p_lk1_tmp, ***p_lk2_tmp, *p_sum, ***p_lk, l_simple[3], l_dist[3]; - node *u_prune, *v_n, *v_nx1, *u_n, *u1, *u2; - edge *e_regraft, *e_tmp; - _move_ *tmp_cand; - - /* - ** Get the directions from node v_prune. - */ - d0 = -1; - u_prune = NULL; - for (i = 0; i < 3; i++) - { - if (v_prune->b[i] == e_prune) - { - d0 = i; - u_prune = v_prune->v[i]; - break; - } - } - d1 = (d0 + 1) % 3; - d2 = 3 - d0 - d1; + move->l2 = l2; + move->v2 = v2; - /* - ** Copy the relevant partial likelihoods to the temporary regraft structure. - ** We can point to the original matrices, cos they won't be changed anyway. - */ - if (v_prune == e_prune->left) - { - v_tmp->b[0]->p_lk_rght = e_prune->p_lk_rght; - v_tmp->b[0]->sum_scale_f_rght = e_prune->sum_scale_f_rght; - } - else - { - v_tmp->b[0]->p_lk_rght = e_prune->p_lk_left; - v_tmp->b[0]->sum_scale_f_rght = e_prune->sum_scale_f_left; - } - v_tmp->num = v_prune->num; - v_tmp->v[0]->num = u_prune->num; - v_tmp->b[0]->num = e_prune->num; - - /* - ** Estimate the length of the edge that will connect the two "detached" nodes - ** after pruning. (The average of the sum of the lengths of the original two - ** edges and the average subtree distance based estimate.) - */ - l_connect = subtree_dist[v_prune->v[d1]->num][v_prune->v[d2]->num]; - if (!v_prune->v[d1]->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (v_prune->v[d1]->b[i] != v_prune->b[d1]) - { - if (u1 == NULL) - { - u1 = v_prune->v[d1]->v[i]; - } - else - { - u2 = v_prune->v[d1]->v[i]; - } - } - } - l_connect -= 0.5 * subtree_dist[u1->num][u2->num]; - } - if (!v_prune->v[d2]->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (v_prune->v[d2]->b[i] != v_prune->b[d2]) - { - if (u1 == NULL) - { - u1 = v_prune->v[d2]->v[i]; - } - else - { - u2 = v_prune->v[d2]->v[i]; - } - } - } - l_connect -= 0.5 * subtree_dist[u1->num][u2->num]; - } - l_connect += (v_prune->b[d1]->l + v_prune->b[d2]->l); - l_connect /= 2.0; - if (l_connect < BL_MIN) - { - l_connect = BL_MIN; - } + move->depth_path = tree->depth_curr_path; + move->pars = tree->c_pars; + move->lnL = tree->c_lnL; + move->b_target = b_target; + move->n_link = n_link; + move->b_opp_to_link = b_arrow; + move->b_init_target = init_target; + move->dist = b_target->topo_dist_btw_edges; + move->n_opp_to_link = (n_link==b_arrow->left)?(b_arrow->rght):(b_arrow->left); + + rk = Include_One_Spr_To_List_Of_Spr(tree->spr_list_one_edge,tree->size_spr_list_one_edge,move,tree); + Include_One_Spr_To_List_Of_Spr(tree->spr_list_all_edge,tree->size_spr_list_all_edge,move,tree); + + Prune_Subtree(n_link, + (n_link==b_arrow->left)?(b_arrow->rght):(b_arrow->left), + &b_target, + &b_residual, + tree); - /* - ** Temporarily swap the relevant partial likelihoods at the prune site. - ** - ** Direction d1. - */ - if (v_prune == v_prune->b[d1]->left) - { - p_lk1_tmp = v_prune->b[d1]->p_lk_left; - if (v_prune == v_prune->b[d2]->left) - { - v_prune->b[d1]->p_lk_left = v_prune->b[d2]->p_lk_rght; - } - else - { - v_prune->b[d1]->p_lk_left = v_prune->b[d2]->p_lk_left; - } - } - else - { - p_lk1_tmp = v_prune->b[d1]->p_lk_rght; - if (v_prune == v_prune->b[d2]->left) - { - v_prune->b[d1]->p_lk_rght = v_prune->b[d2]->p_lk_rght; - } - else - { - v_prune->b[d1]->p_lk_rght = v_prune->b[d2]->p_lk_left; - } - } - /* - ** Direction d2. - */ - if (v_prune == v_prune->b[d2]->left) - { - p_lk2_tmp = v_prune->b[d2]->p_lk_left; - if (v_prune == v_prune->b[d1]->left) - { - v_prune->b[d2]->p_lk_left = v_prune->b[d1]->p_lk_rght; - } - else - { - v_prune->b[d2]->p_lk_left = v_prune->b[d1]->p_lk_left; - } - } - else - { - p_lk2_tmp = v_prune->b[d2]->p_lk_rght; - if (v_prune == v_prune->b[d1]->left) - { - v_prune->b[d2]->p_lk_rght = v_prune->b[d1]->p_lk_rght; - } - else - { - v_prune->b[d2]->p_lk_rght = v_prune->b[d1]->p_lk_left; - } - } + + Copy_Scalar_Dbl(init_target_l,b_target->l); + Copy_Scalar_Dbl(init_target_v,b_target->l_var); - /* - ** Temporarily set the edge lengths and update transition prob's at the - ** prune site. - */ - v_prune->b[d1]->l_old = v_prune->b[d1]->l; - v_prune->b[d2]->l_old = v_prune->b[d2]->l; - v_prune->b[d1]->l = l_connect; - v_prune->b[d2]->l = l_connect; - Update_PMat_At_Given_Edge (v_prune->b[d1], tree); - Update_PMat_At_Given_Edge (v_prune->b[d2], tree); - - /* - ** Get the relevant average subtree distance within the pruned subtree. - */ - if (!u_prune->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (u_prune->b[i] != e_prune) - { - if (u1 == NULL) - { - u1 = u_prune->v[i]; - } - else - { - u2 = u_prune->v[i]; - } - } - } - d_uu = subtree_dist[u1->num][u2->num]; - } - else - { - d_uu = 0.0; - } + Copy_Scalar_Dbl(init_arrow_l,b_arrow->l); + Copy_Scalar_Dbl(init_arrow_v,b_arrow->l_var); - /* - ** Try each candidate SPR and estimate the change in likelihood. - */ - best_d_lk = 1.0/BIG; - best_cand = -1; - for (cand = 0; cand < tree->mod->s_opt->wim_n_rgrft; cand++) - { - /* - ** If there are no more candidates, bail out... - */ - if (rgrft_cand[cand]->d_L == -1.0*BIG) - { - break; - } - else - { - nr_d_lk++; - } + Copy_Scalar_Dbl(init_residual_l,b_residual->l); + Copy_Scalar_Dbl(init_residual_v,b_residual->l_var); - /* - ** Get the relevant nodes and edges. - */ - v_n = rgrft_cand[cand]->v_n; - v_nx1 = rgrft_cand[cand]->v_nx1; - u_n = rgrft_cand[cand]->u_n; - e_regraft = rgrft_cand[cand]->e_regraft; - - /* - ** Update the relevant partial likelihoods along the path between the prune - ** and regraft positions (temporarily save the first one). - */ - n = rgrft_cand[cand]->dist; - e_tmp = NULL; - p_lk = NULL; - p_sum = NULL; - for (i = 1; i <= n; i++) - { - /* - ** Get the next edge along the path. - */ - for (j = 0; j < 3; j++) - { - if (rgrft_cand[cand]->path[i]->v[j] == rgrft_cand[cand]->path[i+1]) - { - e_tmp = rgrft_cand[cand]->path[i]->b[j]; - break; - } - } - if (i == 1) - { - /* - ** Save the first partial likelihood along the path. - */ - if (rgrft_cand[cand]->path[i] == e_tmp->left) - { - p_lk = e_tmp->p_lk_left; - p_sum = e_tmp->sum_scale_f_left; - } - else - { - p_lk = e_tmp->p_lk_rght; - p_sum = e_tmp->sum_scale_f_rght; - } - - for (pat = 0; pat < tree->n_pattern; pat++) - { - sum_scale_tmp[pat] = p_sum[pat]; - for (cat = 0; cat < tree->mod->n_catg; cat++) - { - for (ste = 0; ste < tree->mod->ns; ste++) - { - p_lk_tmp[pat][cat][ste] = p_lk[pat][cat][ste]; - } - } - } - } - Update_P_Lk (tree, e_tmp, rgrft_cand[cand]->path[i]); - } - if (v_n == e_regraft->left) - { - v_tmp->b[1]->p_lk_rght = e_regraft->p_lk_left; - v_tmp->b[2]->p_lk_rght = e_regraft->p_lk_rght; - v_tmp->b[1]->sum_scale_f_rght = e_regraft->sum_scale_f_left; - v_tmp->b[2]->sum_scale_f_rght = e_regraft->sum_scale_f_rght; - } - else - { - v_tmp->b[1]->p_lk_rght = e_regraft->p_lk_rght; - v_tmp->b[2]->p_lk_rght = e_regraft->p_lk_left; - v_tmp->b[1]->sum_scale_f_rght = e_regraft->sum_scale_f_rght; - v_tmp->b[2]->sum_scale_f_rght = e_regraft->sum_scale_f_left; - } + if(tree->mod->s_opt->spr_lnL == YES) Update_PMat_At_Given_Edge(b_target,tree); + + tree->c_lnL = init_lnL; + tree->c_pars = init_pars; - /* - ** Estimate edge lengths of the three relevant regraft edges based on - ** average subtree distances. - ** - ** l_01 - */ - /* - ** Alternative method of estimating l_01. Kept it around for reference... - ** - l_01 = subtree_dist[u_prune->num][u_n->num] - (0.5 * d_uu); - if (!u_n->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (u_n->v[i] != v_n) - { - if (u1 == NULL) - { - u1 = u_n->v[i]; - } - else - { - u2 = u_n->v[i]; - } - } - } - l_01 -= 0.5 * subtree_dist[u1->num][u2->num]; - } - for (i = 0; i < 3; i++) - { - if (u_n->v[i] == v_n) - { - l_01 -= u_n->b[i]->l; - break; - } - } - */ - l_01 = rgrft_cand[cand]->d_up_v - (0.5 * rgrft_cand[cand]->d_un_v) - - (0.5 * d_uu); - /* - ** l_02 - */ - l_02 = subtree_dist[u_prune->num][v_nx1->num] - (0.5 * d_uu); - if (!v_nx1->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (v_nx1->v[i] != v_n) - { - if (u1 == NULL) - { - u1 = v_nx1->v[i]; - } - else - { - u2 = v_nx1->v[i]; - } - } - } - l_02 -= (0.5 * subtree_dist[u1->num][u2->num]); - } - /* - ** l_12 - */ - l_12 = e_regraft->l; - /* - ** Simple estimates. - */ - l_simple[0] = l_02 - (0.5*e_regraft->l); - l_simple[1] = 0.5 * e_regraft->l; - l_simple[2] = 0.5 * e_regraft->l; - for (i = 0; i < 3; i++) - { - if (l_simple[i] < BL_MIN) - { - l_simple[i] = BL_MIN; - } - } - /* - ** Average subtree distance based estimates. - */ - l_dist[0] = 0.5 * ( l_01 + l_02 - l_12); - l_dist[1] = 0.5 * ( l_01 - l_02 + l_12); - l_dist[2] = 0.5 * (-l_01 + l_02 + l_12); - for (i = 0; i < 3; i++) + Free_Scalar_Dbl(init_target_l); + Free_Scalar_Dbl(init_arrow_l); + Free_Scalar_Dbl(init_residual_l); + Free_Scalar_Dbl(init_target_v); + Free_Scalar_Dbl(init_arrow_v); + Free_Scalar_Dbl(init_residual_v); + + return tree->spr_list_one_edge[rk]; +} + +/*********************************************************/ + +void Global_Spr_Search(t_tree *tree) +{ + unsigned int i,iter; + phydbl best_lnL; + t_tree *best_tree; + time_t t_cur; + phydbl mean_delta_lnL_spr,max_delta_lnL_spr,tune_l_mult; + + unsigned int no_improv = 0; + unsigned int last_best_found = 0; + unsigned int hit_zero_improv = 0; + unsigned int freq = 1; + const unsigned int round_freq = 10; + + best_lnL = UNLIKELY; + tree->verbose = (tree->verbose == VL0) ? VL0 : VL1; + best_tree = Duplicate_Tree(tree); + + if(tree->io->print_json_trace == YES) JSON_Tree_Io(tree,tree->io->fp_out_json_trace); + + if(tree->verbose > VL0 && tree->io->quiet == NO) PhyML_Printf("\n\n. Score of initial tree: %.2f",tree->c_lnL); + + + tree->mod->s_opt->min_diff_lk_move = 1.E-1; + tree->mod->s_opt->min_diff_lk_local = 1.E-1; + Round_Optimize(tree,1000); + best_lnL = tree->c_lnL; + Copy_Tree(tree,best_tree); + + + if(tree->verbose > VL0 && tree->io->quiet == NO) PhyML_Printf("\n\n. Starting first round of SPRs...\n"); + + tree->mod->s_opt->max_depth_path = MAX(40,1+(int)(tree->n_otu/4)); + tree->mod->s_opt->max_delta_lnL_spr = 1000; + tree->mod->s_opt->l_min_spr = 0.0; + tree->mod->s_opt->spr_lnL = YES; + tree->mod->s_opt->spr_pars = NO; + tree->mod->s_opt->min_diff_lk_move = 1.E-0; + tree->mod->s_opt->min_diff_lk_local = 1.E-0; + tree->perform_spr_right_away = YES; + tree->mod->s_opt->eval_list_regraft = NO; + tree->mod->s_opt->max_delta_lnL_spr_current = 0.0; + tree->mod->s_opt->min_n_triple_moves = 1; + mean_delta_lnL_spr = 0.0; + max_delta_lnL_spr = 0.0; + hit_zero_improv = 0; + tune_l_mult = 0.01; + best_lnL = tree->c_lnL; + + iter = 0; + do { - if (l_dist[i] < BL_MIN) - { - l_dist[i] = BL_MIN; - } + + if(!(iter%freq)) + { + for(int i=0;i<2*tree->n_otu-3;++i) MIXT_Multiply_Scalar_Dbl(tree->a_edges[i]->l,Rgamma((phydbl)(tune_l_mult*iter+1),(phydbl)(1./(tune_l_mult*iter+1)))); + for(int i=0;i<2*tree->n_otu-3;++i) Set_Scalar_Dbl_Min_Thresh(tree->mod->l_min,tree->a_edges[i]->l); + for(int i=0;i<2*tree->n_otu-3;++i) Set_Scalar_Dbl_Max_Thresh(tree->mod->l_max,tree->a_edges[i]->l); + freq--; + if(freq < 1) freq=1; + } + + if(iter> 10) tree->mod->s_opt->l_min_spr = 1.E-3; + + Spr(tree->c_lnL,1.0,tree); + Optimize_Br_Len_Serie(2,tree); + + if(!(iter%round_freq) && iter > 0) Round_Optimize(tree,1000); + + if(tree->verbose > VL0 && tree->io->quiet == NO) + { + time(&t_cur); + PhyML_Printf("\n\t%8ds | %3d | lnL=%12.1f | depth=%5d/%5d | improvements=%4d | delta_lnL=%7.1f/%7.1f %c", + (int)(t_cur-tree->t_beg), + iter+1, + tree->c_lnL, + tree->mod->s_opt->max_spr_depth, + tree->mod->s_opt->max_depth_path, + tree->mod->s_opt->n_improvements, + tree->mod->s_opt->max_delta_lnL_spr_current, + tree->mod->s_opt->max_delta_lnL_spr, + (tree->numerical_warning == YES) ? '!' : ' '); + } + + if(tree->mod->s_opt->n_improvements > (int)(tree->n_otu/5)) + { + tune_l_mult *= 1.2; + } + + tree->mod->s_opt->max_depth_path = MAX(5,MAX(tree->mod->s_opt->max_spr_depth+6,(int)(0.6*tree->mod->s_opt->max_depth_path))); + + if((iter%4) > 0 || iter == 0) + { + mean_delta_lnL_spr += tree->mod->s_opt->max_delta_lnL_spr_current; + if(tree->mod->s_opt->max_delta_lnL_spr_current > max_delta_lnL_spr) max_delta_lnL_spr = tree->mod->s_opt->max_delta_lnL_spr_current; + } + else if(iter > 0) + { + mean_delta_lnL_spr /= 4.0; + /* tree->mod->s_opt->max_delta_lnL_spr = MAX(50.,MIN(2.0*mean_delta_lnL_spr,0.5*tree->mod->s_opt->max_delta_lnL_spr)); */ + tree->mod->s_opt->max_delta_lnL_spr = MAX(50.,2.*max_delta_lnL_spr); + mean_delta_lnL_spr = tree->mod->s_opt->max_delta_lnL_spr_current; + max_delta_lnL_spr = 0.0; + } + + + if(tree->c_lnL > best_lnL) + { + no_improv = 0; + best_lnL = tree->c_lnL; + Copy_Tree(tree,best_tree); + if(tree->verbose > VL0 && tree->io->quiet == NO) PhyML_Printf(" +"); + if(tree->io->print_json_trace == YES) JSON_Tree_Io(tree,tree->io->fp_out_json_trace); + } + + if(tree->mod->s_opt->n_improvements == 0) + { + hit_zero_improv++; + } + + no_improv++; + iter++; } - /* - ** Take the average of the two estimates. - */ - l_est[0] = (l_simple[0] + l_dist[0]) / 2.0; - l_est[1] = (l_simple[1] + l_dist[1]) / 2.0; - l_est[2] = (l_simple[2] + l_dist[2]) / 2.0; - - /* - ** Set the edge lengths and update the relevant transition prob's and - ** partial likelihoods in the temporary regraft structure. - */ + while(tree->mod->s_opt->n_improvements > 15 && no_improv < 10); - for (i = 0; i < 3; i++) + + if(tree->verbose > VL0 && tree->io->quiet == NO) PhyML_Printf("\n\n. Second round of optimization...\n"); + + + tree->mod->s_opt->max_depth_path = MAX(10,(int)(1.5*tree->mod->s_opt->max_depth_path)); + tree->mod->s_opt->l_min_spr = 1.E-3; + tree->mod->s_opt->spr_lnL = YES; + tree->mod->s_opt->spr_pars = NO; + tree->mod->s_opt->min_diff_lk_move = 1.E-2; + tree->mod->s_opt->min_diff_lk_local = 1.E-2; + tree->mod->s_opt->apply_spr_right_away = YES; + tree->mod->s_opt->apply_spr = YES; + tree->mod->s_opt->eval_list_regraft = NO; + tree->mod->s_opt->max_delta_lnL_spr_current = 0.0; + tree->mod->s_opt->min_n_triple_moves = 1; + tree->mod->s_opt->deepest_path = 0; + mean_delta_lnL_spr = 0.0; + max_delta_lnL_spr = 0.0; + hit_zero_improv = 0; + no_improv = 0; + + do + { + if(!(iter%freq)) + { + for(int i=0;i<2*tree->n_otu-3;++i) MIXT_Multiply_Scalar_Dbl(tree->a_edges[i]->l,Rgamma((phydbl)(tune_l_mult*iter+1),(phydbl)(1./(tune_l_mult*iter+1)))); + for(int i=0;i<2*tree->n_otu-3;++i) Set_Scalar_Dbl_Min_Thresh(tree->mod->l_min,tree->a_edges[i]->l); + for(int i=0;i<2*tree->n_otu-3;++i) Set_Scalar_Dbl_Max_Thresh(tree->mod->l_max,tree->a_edges[i]->l); + freq--; + if(freq < 1) freq=1; + } + + Spr(tree->c_lnL,1.0,tree); + Optimize_Br_Len_Serie(2,tree); + + if(!(iter%round_freq) && iter > 0) Round_Optimize(tree,1000); + + if(tree->verbose > VL0 && tree->io->quiet == NO) + { + time(&t_cur); + PhyML_Printf("\n\t%8ds | %3d | lnL=%12.1f | depth=%5d/%5d | improvements=%4d | delta_lnL=%7.1f/%7.1f %c", + (int)(t_cur-tree->t_beg), + iter+1, + tree->c_lnL, + tree->mod->s_opt->max_spr_depth, + tree->mod->s_opt->max_depth_path, + tree->mod->s_opt->n_improvements, + tree->mod->s_opt->max_delta_lnL_spr_current, + tree->mod->s_opt->max_delta_lnL_spr, + (tree->numerical_warning == YES) ? '!' : ' '); + } + + tree->mod->s_opt->max_depth_path = MAX(5,MAX(tree->mod->s_opt->max_spr_depth+4,(int)(0.8*tree->mod->s_opt->max_depth_path))); + tree->mod->s_opt->max_depth_path = MIN(20,tree->mod->s_opt->max_depth_path); + + if((iter%4) > 0 || iter == 0) + { + mean_delta_lnL_spr += tree->mod->s_opt->max_delta_lnL_spr_current; + if(tree->mod->s_opt->max_delta_lnL_spr_current > max_delta_lnL_spr) max_delta_lnL_spr = tree->mod->s_opt->max_delta_lnL_spr_current; + } + else if(iter > 0) + { + mean_delta_lnL_spr /= 4.0; + tree->mod->s_opt->max_delta_lnL_spr = MAX(20.,2.*max_delta_lnL_spr); + mean_delta_lnL_spr = tree->mod->s_opt->max_delta_lnL_spr_current; + max_delta_lnL_spr = 0.0; + } + + + if(tree->c_lnL > best_lnL) + { + no_improv = 0; + best_lnL = tree->c_lnL; + Copy_Tree(tree,best_tree); + if(tree->verbose > VL0 && tree->io->quiet == NO) PhyML_Printf(" +"); + if(tree->io->print_json_trace == YES) JSON_Tree_Io(tree,tree->io->fp_out_json_trace); + } + + if(tree->mod->s_opt->n_improvements == 0) + { + hit_zero_improv++; + } + + no_improv++; + iter++; + } + while(tree->mod->s_opt->n_improvements > 5 && no_improv < 10); + + if(tree->verbose > VL0 && tree->io->quiet == NO) PhyML_Printf("\n\n. Third round of optimization...\n"); + last_best_found = 0; + + tree->mod->s_opt->max_depth_path = MAX(10,tree->mod->s_opt->max_depth_path); + tree->mod->s_opt->max_delta_lnL_spr = MAX(100.,tree->mod->s_opt->max_delta_lnL_spr); + tree->mod->s_opt->spr_lnL = YES; + tree->mod->s_opt->spr_pars = NO; + tree->mod->s_opt->l_min_spr = 1.E-4; + tree->mod->s_opt->min_diff_lk_move = 1.E-2; + tree->mod->s_opt->min_diff_lk_local = 1.E-2; + tree->mod->s_opt->apply_spr_right_away = YES; + tree->mod->s_opt->apply_spr = YES; + tree->mod->s_opt->eval_list_regraft = YES; + tree->mod->s_opt->max_delta_lnL_spr_current = 0.0; + tree->mod->s_opt->min_n_triple_moves = 5; + tree->mod->s_opt->max_rank_triple_move = 0; + tree->mod->s_opt->max_no_better_tree_found = 10; + + do { - v_tmp->b[i]->l = l_est[i]; /* TO DO */ - if (v_tmp->b[i]->l < BL_MIN) - { - v_tmp->b[i]->l = BL_MIN; - } - Update_PMat_At_Given_Edge (v_tmp->b[i], tree); + Spr(tree->c_lnL,1.0,tree); + Optimize_Br_Len_Serie(2,tree); + + if(!(iter%round_freq)) Round_Optimize(tree,1000); + + if(tree->verbose > VL0 && tree->io->quiet == NO) + { + time(&t_cur); + PhyML_Printf("\n\t%8ds | %3d | lnL=%12.1f | depth=%5d/%5d | improvements=%4d | delta_lnL=%7.1f/%7.1f | triple moves=%4d %c", + (int)(t_cur-tree->t_beg), + iter+1, + tree->c_lnL, + tree->mod->s_opt->max_spr_depth, + tree->mod->s_opt->max_depth_path, + tree->mod->s_opt->n_improvements, + tree->mod->s_opt->max_delta_lnL_spr_current, + tree->mod->s_opt->max_delta_lnL_spr, + tree->mod->s_opt->min_n_triple_moves, + (tree->numerical_warning == YES) ? '!' : ' '); + } + + tree->mod->s_opt->max_depth_path = MIN(30,MAX(5,MAX(2*tree->mod->s_opt->max_spr_depth,(int)(0.8*tree->mod->s_opt->max_depth_path)))); + tree->mod->s_opt->max_delta_lnL_spr = MAX(100.,0.8*tree->mod->s_opt->max_delta_lnL_spr_current); + tree->mod->s_opt->min_n_triple_moves = MAX(5,2*tree->mod->s_opt->max_rank_triple_move); + + if(tree->c_lnL > best_lnL) + { + last_best_found = 0;; + best_lnL = tree->c_lnL; + Copy_Tree(tree,best_tree); + if(tree->verbose > VL0 && tree->io->quiet == NO) PhyML_Printf(" +"); + if(tree->io->print_json_trace == YES) JSON_Tree_Io(tree,tree->io->fp_out_json_trace); + } + + last_best_found++; + iter++; } + while(tree->mod->s_opt->n_improvements > 0 && last_best_found <= tree->mod->s_opt->max_no_better_tree_found); - /* Beg SG 18 May 2007 */ - if(tree->mod->s_opt->wim_inside_opt) - { - Triple_Dist(v_tmp,tree); - For(i,3) l_est[i] = v_tmp->b[i]->l; - } - /* End SG 18 May 2007 */ + Copy_Tree(best_tree,tree); + + if(tree->verbose > VL0 && tree->io->quiet == NO) PhyML_Printf("\n\n. Final optimisation steps...\n"); + + i = tree->verbose; + tree->verbose = VL0; + tree->mod->s_opt->min_diff_lk_move = 1.E-03; + tree->mod->s_opt->min_diff_lk_local = 1.E-03; + do + { + tree->mod->s_opt->fast_nni = NO; + Round_Optimize(tree,10); + if(!Check_NNI_Five_Branches(tree)) break; + } + while(1); + tree->verbose = i; + + Free_Tree(best_tree); + return; +} - /* - ** Calculate the change in likelihood locally. Save it and the estimated edge - ** lengths in the current candidate in the list. - */ - Update_P_Lk (tree, v_tmp->b[0], v_tmp); - new_lk = Lk_At_Given_Edge (v_tmp->b[0],tree); -/* printf("\n. new_lk = %f",new_lk); */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +void Speed_Spr(t_tree *tree, phydbl prop_spr, int max_cycles, phydbl delta_lnL) +{ + int step,old_pars; + phydbl old_lnL; + + if(tree->lock_topo == YES) + { + PhyML_Fprintf(stderr,"\n== The tree topology is locked."); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } + + + Set_Both_Sides(NO,tree); + Pars(NULL,tree); + if(tree->mod->s_opt->spr_pars == NO) Lk(NULL,tree); + Record_Br_Len(tree); + + tree->mod->s_opt->deepest_path = 0; + tree->best_pars = tree->c_pars; + tree->best_lnL = tree->c_lnL; + old_lnL = tree->c_lnL; + old_pars = tree->c_pars; + step = 0; + do + { + ++step; + + old_lnL = tree->c_lnL; + old_pars = tree->c_pars; + + Set_Both_Sides(YES,tree); + Pars(NULL,tree); + if(tree->mod->s_opt->spr_pars == NO) Lk(NULL,tree); + Spr(UNLIKELY,prop_spr,tree); + + // Set maximum depth for future spr rounds to deepest spr found so far + tree->mod->s_opt->max_depth_path = tree->mod->s_opt->max_spr_depth; + + if(tree->mod->s_opt->spr_pars == NO) + { + if(tree->mod->s_opt->n_improvements > 0) + { + /* Optimise branch lengths */ + Optimize_Br_Len_Serie(2,tree); + /* Print log-likelihood and parsimony scores */ + if(tree->verbose > VL2 && tree->io->quiet == NO) Print_Lk(tree,"[Branch lengths ]"); + } + } + else + { + if(tree->verbose > VL2 && tree->io->quiet == NO) Print_Pars(tree); + } + Pars(NULL,tree); + + if(tree->io->print_trace) + { + char *s = Write_Tree(tree); + PhyML_Fprintf(tree->io->fp_out_trace,"[%f]%s\n",tree->c_lnL,s); fflush(tree->io->fp_out_trace); + if((tree->io->print_site_lnl) && (!tree->mod->s_opt->spr_pars)) + { + Print_Site_Lk(tree,tree->io->fp_out_lk); + fflush(tree->io->fp_out_lk); + } + Free(s); + } + + if(tree->io->print_json_trace == YES) JSON_Tree_Io(tree,tree->io->fp_out_json_trace); + + /* Record the current best log-likelihood and parsimony */ + if(tree->c_lnL > tree->best_lnL) tree->best_lnL = tree->c_lnL; + if(tree->c_pars < tree->best_pars) tree->best_pars = tree->c_pars; + + if(tree->mod->s_opt->spr_pars == NO) + { + if(tree->c_lnL < old_lnL-tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Fprintf(stderr,"\n== old_lnL = %f c_lnL = %f",old_lnL,tree->c_lnL); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit(""); + } + } + else + { + if(tree->c_pars > old_pars) + { + PhyML_Fprintf(stderr,"\n== old_pars = %d c_pars = %d",old_pars,tree->c_pars); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit(""); + } + } + + /* Record the current best branch lengths */ + Record_Br_Len(tree); + /* Exit if no improvements after complete optimization */ + if(step+1 > max_cycles) break; + if((tree->mod->s_opt->spr_pars == NO) && (fabs(old_lnL-tree->c_lnL) < delta_lnL)) break; + if((tree->mod->s_opt->spr_pars == YES) && (fabs((phydbl)(old_pars-tree->c_pars)) < 1)) break; + if(!tree->mod->s_opt->n_improvements) break; + } + while(1); +} +/*********************************************************/ - rgrft_cand[cand]->delta_lk = new_lk - cur_lk; - rgrft_cand[cand]->rgrft_rank = cand; - rgrft_cand[cand]->optim_rank = -1; - rgrft_cand[cand]->globl_rank = -1; - rgrft_cand[cand]->l_connect = l_connect; - for (i = 0; i < 3; i++) - { - rgrft_cand[cand]->l_est[i] = v_tmp->b[i]->l; - } - if (rgrft_cand[cand]->delta_lk > best_d_lk) - { - best_d_lk = rgrft_cand[cand]->delta_lk; - best_cand = cand; - } +int Evaluate_List_Of_Regraft_Pos_Triple(t_spr **spr_list, int list_size, t_tree *tree) +{ + t_spr *move; + t_edge *init_target, *b_residual; + int i,j,best_move,better_found; + int dir_v0, dir_v1, dir_v2; + scalar_dbl *recorded_l,*recorded_v; + phydbl best_lnL,init_lnL; + int recorded; - /* - ** If the change is within the tree->mod->s_opt->wim_n_optim best ones, save it in the list of - ** optimization candidates. - */ - if (rgrft_cand[cand]->delta_lk > optim_cand[tree->mod->s_opt->wim_n_optim-1]->delta_lk) + if(tree->mixt_tree != NULL) { - i = tree->mod->s_opt->wim_n_optim-1; - optim_cand[i]->v_prune = rgrft_cand[cand]->v_prune; - optim_cand[i]->u_prune = rgrft_cand[cand]->u_prune; - optim_cand[i]->v_n = rgrft_cand[cand]->v_n; - optim_cand[i]->v_nx1 = rgrft_cand[cand]->v_nx1; - optim_cand[i]->u_n = rgrft_cand[cand]->u_n; - optim_cand[i]->e_prune = rgrft_cand[cand]->e_prune; - optim_cand[i]->e_regraft = rgrft_cand[cand]->e_regraft; - optim_cand[i]->d_L = rgrft_cand[cand]->d_L; - optim_cand[i]->dist = rgrft_cand[cand]->dist; - optim_cand[i]->rgrft_rank = rgrft_cand[cand]->rgrft_rank; - optim_cand[i]->optim_rank = rgrft_cand[cand]->optim_rank; - optim_cand[i]->globl_rank = rgrft_cand[cand]->globl_rank; - optim_cand[i]->l_connect = rgrft_cand[cand]->l_connect; - for (j = 0; j < 3; j++) - { - optim_cand[i]->l_est[j] = rgrft_cand[cand]->l_est[j]; - } - optim_cand[i]->delta_lk = rgrft_cand[cand]->delta_lk; - /* - ** Move the candidate to the appropriate position in the list, so the list - ** remains sorted in decreasing delta_Lk value. - */ - while ((i > 0) && (optim_cand[i]->delta_lk > optim_cand[i-1]->delta_lk)) - { - tmp_cand = optim_cand[i]; - optim_cand[i] = optim_cand[i-1]; - optim_cand[i-1] = tmp_cand; - i--; - } + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); } - /* - ** Reset the partial likelihoods along the path. - */ - for (pat = 0; pat < tree->n_pattern; pat++) - { - p_sum[pat] = sum_scale_tmp[pat]; - for (cat = 0; cat < tree->mod->n_catg; cat++) - { - for (ste = 0; ste < tree->mod->ns; ste++) - { - p_lk[pat][cat][ste] = p_lk_tmp[pat][cat][ste]; - } - } - } - n = rgrft_cand[cand]->dist; - for (i = 2; i <= n; i++) + best_lnL = UNLIKELY; + init_target = b_residual = NULL; + best_move = -1; + init_lnL = tree->c_lnL; + recorded_v = recorded_l = NULL; + better_found = NO; + + if(list_size == 0) { - for (j = 0; j < 3; j++) - { - if (rgrft_cand[cand]->path[i]->v[j] == rgrft_cand[cand]->path[i+1]) - { - e_tmp = rgrft_cand[cand]->path[i]->b[j]; - break; - } - } - Update_P_Lk (tree, e_tmp, rgrft_cand[cand]->path[i]); + PhyML_Fprintf(stderr,"\n== List size is 0 !"); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); } - /* - ** If an improvement was found, forget the other candidates... - */ - if (best_cand >= 0) + + recorded = NO; + for(i=0;ib[d1]->left) - { - v_prune->b[d1]->p_lk_left = p_lk1_tmp; - } - else - { - v_prune->b[d1]->p_lk_rght = p_lk1_tmp; - } - if (v_prune == v_prune->b[d2]->left) - { - v_prune->b[d2]->p_lk_left = p_lk2_tmp; - } - else - { - v_prune->b[d2]->p_lk_rght = p_lk2_tmp; - } + if(!move) + { + PhyML_Fprintf(stderr,"\n== move is NULL\n"); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } + + if(move->b_target) + { + /* Record t_edge lengths */ + Record_Br_Len(tree); + + /* Prune subtree */ + Prune_Subtree(move->n_link, + move->n_opp_to_link, + &init_target, + &b_residual, + tree); + + if(recorded == NO) + { + /*! Rough optimisation of the branch length at prune site + * We only need to perform this optimisation for the first + * element of spr_list because the pruned subtree is the + * same across all the elements of spr_list. It would not + * be true in the general case + */ + recorded = YES; + + Br_Len_Opt(&(init_target->l->v),init_target,tree); + + /*! Record branch length at prune site */ + if(recorded_l == NULL) + { + recorded_l = Duplicate_Scalar_Dbl(init_target->l); + recorded_v = Duplicate_Scalar_Dbl(init_target->l_var); + } + else + { + Copy_Scalar_Dbl(init_target->l,recorded_l); + Copy_Scalar_Dbl(init_target->l_var,recorded_v); + } + + Copy_Scalar_Dbl(recorded_l,move->init_target_l); + Copy_Scalar_Dbl(recorded_v,move->init_target_v); + } + else + { + Copy_Scalar_Dbl(recorded_l,move->b_init_target->l); + Copy_Scalar_Dbl(recorded_v,move->b_init_target->l_var); + + Copy_Scalar_Dbl(recorded_l,move->init_target_l); + Copy_Scalar_Dbl(recorded_v,move->init_target_v); + } + + /* Update the change proba matrix at prune position */ + Update_PMat_At_Given_Edge(init_target,tree); + + /* Update conditional likelihoods along the path from the prune to + the regraft position */ + MIXT_Set_Alias_Subpatt(YES,tree); + Update_Partial_Lk_Along_A_Path(move->path,move->depth_path+1,tree); + MIXT_Set_Alias_Subpatt(NO,tree); + + + /* Regraft subtree */ + Graft_Subtree(move->b_target,move->n_link,NULL,b_residual,NULL,tree); + + MIXT_Set_Alias_Subpatt(YES,tree); + move->lnL = Triple_Dist(move->n_link,tree); + MIXT_Set_Alias_Subpatt(NO,tree); + + /* printf("\n. %d/%d init_lnL: %12G move->lnL= %12G best_lnL=%12G absolute_best=%12G", */ + /* i, */ + /* list_size, */ + /* init_lnL, */ + /* move->lnL, */ + /* best_lnL, */ + /* tree->best_lnL); */ + + /* Record updated branch lengths for this move */ + dir_v1 = dir_v2 = dir_v0 = -1; + for(j=0;j<3;j++) + { + if(move->n_link->v[j] == move->n_opp_to_link) dir_v0 = j; + else if(dir_v1 < 0) dir_v1 = j; + else dir_v2 = j; + } + + Copy_Scalar_Dbl(move->n_link->b[dir_v0]->l, move->l0); + Copy_Scalar_Dbl(move->n_link->b[dir_v0]->l_var,move->v0); + + if(move->n_link->v[dir_v1]->num > move->n_link->v[dir_v2]->num) + { + Copy_Scalar_Dbl(move->n_link->b[dir_v2]->l, move->l1); + Copy_Scalar_Dbl(move->n_link->b[dir_v2]->l_var,move->v1); + + Copy_Scalar_Dbl(move->n_link->b[dir_v1]->l, move->l2); + Copy_Scalar_Dbl(move->n_link->b[dir_v1]->l_var,move->v2); + } + else + { + Copy_Scalar_Dbl(move->n_link->b[dir_v1]->l, move->l1); + Copy_Scalar_Dbl(move->n_link->b[dir_v1]->l_var,move->v1); + + Copy_Scalar_Dbl(move->n_link->b[dir_v2]->l, move->l2); + Copy_Scalar_Dbl(move->n_link->b[dir_v2]->l_var,move->v2); + } + + if(move->lnL > best_lnL) + { + best_lnL = move->lnL; + best_move = i; + } + + /* Regraft the subtree at its original position */ + Prune_Subtree(move->n_link, + move->n_opp_to_link, + &move->b_target, + &b_residual, + tree); + + Graft_Subtree(init_target, + move->n_link, + NULL, + b_residual, + NULL, + tree); + + /* Restore branch lengths */ + Restore_Br_Len(tree); + + /* Update relevant change proba matrices */ + Update_PMat_At_Given_Edge(move->b_target,tree); + + tree->c_lnL = init_lnL; + } + + /* PhyML_Printf("\n. [ %4d/%4d ] %f %f %s", */ + /* i,list_size,tree->best_lnL,move->lnL, */ + /* (move->lnL > tree->best_lnL + tree->mod->s_opt->min_diff_lk_move) ? "**" : ""); */ - /* - ** Reset the relevant edge lengths and transition prob's at the prune site. - */ - v_prune->b[d1]->l = v_prune->b[d1]->l_old; - v_prune->b[d2]->l = v_prune->b[d2]->l_old; - Update_PMat_At_Given_Edge (v_prune->b[d1], tree); - Update_PMat_At_Given_Edge (v_prune->b[d2], tree); - /* - ** Return the best candidate. - */ - return (best_cand); + /* Bail out as soon as you've found a true improvement */ + if(move->lnL > tree->best_lnL + tree->mod->s_opt->min_diff_lk_move) + { + better_found = YES; + if(i > tree->mod->s_opt->max_rank_triple_move) tree->mod->s_opt->max_rank_triple_move = i; + break; + } + } + + /* PhyML_Printf("\n. max_improv = %f",max_improv); */ + + + if(better_found == NO) + { + MIXT_Set_Alias_Subpatt(YES,tree); + for(i=0;ib_target) + { + for(j=0;j<3;++j) Update_PMat_At_Given_Edge(move->n_link->b[j],tree); + for(j=0;j<3;++j) Update_Partial_Lk(tree,move->n_link->b[j],move->n_link); + + /* TO DO : we don't need to update all these partial likelihoods here. + Would need to record only those that were along the paths examined + above */ + + for(j=0;j<3;++j) + if(move->n_link->v[j] != move->n_opp_to_link) + Pre_Order_Lk(move->n_link,move->n_link->v[j],tree); + + break; + } + } + MIXT_Set_Alias_Subpatt(NO,tree); + } + +#ifdef DEBUG + if(best_move < 0 && list_size > 0) + { + PhyML_Printf("\n\n== Best_move < 0 !"); + PhyML_Printf("\n== List size = %d",list_size); + PhyML_Printf("\n== Best lnL = %f",best_lnL); + for(i=0;ib_target,move->lnL); + } + + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } +#endif + + Free_Scalar_Dbl(recorded_l); + Free_Scalar_Dbl(recorded_v); + + return best_move; } +/*********************************************************/ -/* -** Best_Lk_Change: Estimate the changes in likelihood for the most promising candidate -** regraft positions given a pruned subtree and save the best one. -** -** Parameters: -** - e_prune: The edge at which the subtree was pruned. -** - v_prune: The root of the pruned subtree. -** - tree: The tree on which to do the calculations. -** -** Returns: -** The candidate which gives the best (possibly negative) improvement. -*/ - -int Best_Lk_Change (edge *e_prune, node *v_prune, arbre *tree) +int Try_One_Spr_Move_Triple(t_spr *move, t_tree *tree) { - int i, j, cand, best_cand, d0, d1, d2, n, pat, cat, ste; - phydbl d_uu, best_d_lk, l_connect, l_01, l_02, l_12, l_est[3], new_lk, - ***p_lk1_tmp, ***p_lk2_tmp, *p_sum, ***p_lk, l_simple[3], l_dist[3]; - node *u_prune, *v_n, *v_nx1, *u_n, *u1, *u2; - edge *e_regraft, *e_tmp; - _move_ *tmp_cand; - - /* - ** Get the directions from node v_prune. - */ - d0 = -1; - u_prune = NULL; - for (i = 0; i < 3; i++) - { - if (v_prune->b[i] == e_prune) + t_edge *init_target, *b_residual; + int j; + int dir_v0, dir_v1, dir_v2; + int accept; + + assert(move); + if(move->n_link == NULL) return -1; + + if(tree->mixt_tree != NULL) { - d0 = i; - u_prune = v_prune->v[i]; - break; + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); } - } - d1 = (d0 + 1) % 3; - d2 = 3 - d0 - d1; - /* - ** Copy the relevant partial likelihoods to the temporary regraft structure. - ** We can point to the original matrices, cos they won't be changed anyway. - */ - if (v_prune == e_prune->left) - { - v_tmp->b[0]->p_lk_rght = e_prune->p_lk_rght; - v_tmp->b[0]->sum_scale_f_rght = e_prune->sum_scale_f_rght; - } - else - { - v_tmp->b[0]->p_lk_rght = e_prune->p_lk_left; - v_tmp->b[0]->sum_scale_f_rght = e_prune->sum_scale_f_left; - } - v_tmp->num = v_prune->num; - v_tmp->v[0]->num = u_prune->num; - v_tmp->b[0]->num = e_prune->num; - - /* - ** Estimate the length of the edge that will connect the two "detached" nodes - ** after pruning. (The average of the sum of the lengths of the original two - ** edges and the average subtree distance based estimate.) - */ - l_connect = subtree_dist[v_prune->v[d1]->num][v_prune->v[d2]->num]; - if (!v_prune->v[d1]->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (v_prune->v[d1]->b[i] != v_prune->b[d1]) - { - if (u1 == NULL) - { - u1 = v_prune->v[d1]->v[i]; - } - else - { - u2 = v_prune->v[d1]->v[i]; - } - } - } - l_connect -= 0.5 * subtree_dist[u1->num][u2->num]; - } - if (!v_prune->v[d2]->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (v_prune->v[d2]->b[i] != v_prune->b[d2]) - { - if (u1 == NULL) - { - u1 = v_prune->v[d2]->v[i]; - } - else - { - u2 = v_prune->v[d2]->v[i]; - } - } - } - l_connect -= 0.5 * subtree_dist[u1->num][u2->num]; - } - l_connect += (v_prune->b[d1]->l + v_prune->b[d2]->l); - l_connect /= 2.0; - if (l_connect < BL_MIN) - { - l_connect = BL_MIN; - } + Record_Br_Len(tree); - /* - ** Temporarily swap the relevant partial likelihoods at the prune site. - ** - ** Direction d1. - */ - if (v_prune == v_prune->b[d1]->left) - { - p_lk1_tmp = v_prune->b[d1]->p_lk_left; - if (v_prune == v_prune->b[d2]->left) - { - v_prune->b[d1]->p_lk_left = v_prune->b[d2]->p_lk_rght; - } - else - { - v_prune->b[d1]->p_lk_left = v_prune->b[d2]->p_lk_left; - } - } - else - { - p_lk1_tmp = v_prune->b[d1]->p_lk_rght; - if (v_prune == v_prune->b[d2]->left) - { - v_prune->b[d1]->p_lk_rght = v_prune->b[d2]->p_lk_rght; - } - else - { - v_prune->b[d1]->p_lk_rght = v_prune->b[d2]->p_lk_left; - } - } - /* - ** Direction d2. - */ - if (v_prune == v_prune->b[d2]->left) - { - p_lk2_tmp = v_prune->b[d2]->p_lk_left; - if (v_prune == v_prune->b[d1]->left) - { - v_prune->b[d2]->p_lk_left = v_prune->b[d1]->p_lk_rght; - } - else - { - v_prune->b[d2]->p_lk_left = v_prune->b[d1]->p_lk_left; - } - } - else - { - p_lk2_tmp = v_prune->b[d2]->p_lk_rght; - if (v_prune == v_prune->b[d1]->left) - { - v_prune->b[d2]->p_lk_rght = v_prune->b[d1]->p_lk_rght; - } - else - { - v_prune->b[d2]->p_lk_rght = v_prune->b[d1]->p_lk_left; - } - } + Prune_Subtree(move->n_link, + move->n_opp_to_link, + &init_target, + &b_residual, + tree); + + Copy_Scalar_Dbl(move->init_target_l,init_target->l); + Copy_Scalar_Dbl(move->init_target_v,init_target->l_var); - /* - ** Temporarily set the edge lengths and update transition prob's at the - ** prune site. - */ - v_prune->b[d1]->l_old = v_prune->b[d1]->l; - v_prune->b[d2]->l_old = v_prune->b[d2]->l; - v_prune->b[d1]->l = l_connect; - v_prune->b[d2]->l = l_connect; - Update_PMat_At_Given_Edge (v_prune->b[d1], tree); - Update_PMat_At_Given_Edge (v_prune->b[d2], tree); - - /* - ** Get the relevant average subtree distance within the pruned subtree. - */ - if (!u_prune->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (u_prune->b[i] != e_prune) - { - if (u1 == NULL) - { - u1 = u_prune->v[i]; - } - else - { - u2 = u_prune->v[i]; - } - } - } - d_uu = subtree_dist[u1->num][u2->num]; - } - else - { - d_uu = 0.0; - } + Graft_Subtree(move->b_target,move->n_link,NULL,b_residual,NULL,tree); - /* - ** Try the best candidate SPRs and estimate the change in likelihood. - */ - best_d_lk = -1.0*BIG; - best_cand = 0; - for (cand = 0; cand < tree->mod->s_opt->wim_n_best; cand++) - { - /* - ** If there are no more candidates, bail out... - */ - if (rgrft_cand[cand]->d_L == -1.0*BIG) - { - break; - } - else + dir_v1 = dir_v2 = dir_v0 = -1; + for(j=0;j<3;j++) { - nr_d_lk++; + if(move->n_link->v[j] == move->n_opp_to_link) dir_v0 = j; + else if(dir_v1 < 0) dir_v1 = j; + else dir_v2 = j; } - /* - ** Get the relevant nodes and edges. - */ - v_n = rgrft_cand[cand]->v_n; - v_nx1 = rgrft_cand[cand]->v_nx1; - u_n = rgrft_cand[cand]->u_n; - e_regraft = rgrft_cand[cand]->e_regraft; - - /* - ** Update the relevant partial likelihoods along the path between the prune - ** and regraft positions (temporarily save the first one). - */ - n = rgrft_cand[cand]->dist; - e_tmp = NULL; - p_lk = NULL; - p_sum = NULL; - for (i = 1; i <= n; i++) - { - /* - ** Get the next edge along the path. - */ - for (j = 0; j < 3; j++) - { - if (rgrft_cand[cand]->path[i]->v[j] == rgrft_cand[cand]->path[i+1]) - { - e_tmp = rgrft_cand[cand]->path[i]->b[j]; - break; - } - } - if (i == 1) - { - /* - ** Save the first partial likelihood along the path. - */ - if (rgrft_cand[cand]->path[i] == e_tmp->left) - { - p_lk = e_tmp->p_lk_left; - p_sum = e_tmp->sum_scale_f_left; - } - else - { - p_lk = e_tmp->p_lk_rght; - p_sum = e_tmp->sum_scale_f_rght; - } - for (pat = 0; pat < tree->n_pattern; pat++) - { - sum_scale_tmp[pat] = p_sum[pat]; - for (cat = 0; cat < tree->mod->n_catg; cat++) - { - for (ste = 0; ste < tree->mod->ns; ste++) - { - p_lk_tmp[pat][cat][ste] = p_lk[pat][cat][ste]; - } - } - } - } - Update_P_Lk (tree, e_tmp, rgrft_cand[cand]->path[i]); - } - if (v_n == e_regraft->left) - { - v_tmp->b[1]->p_lk_rght = e_regraft->p_lk_left; - v_tmp->b[2]->p_lk_rght = e_regraft->p_lk_rght; - v_tmp->b[1]->sum_scale_f_rght = e_regraft->sum_scale_f_left; - v_tmp->b[2]->sum_scale_f_rght = e_regraft->sum_scale_f_rght; - } - else - { - v_tmp->b[1]->p_lk_rght = e_regraft->p_lk_rght; - v_tmp->b[2]->p_lk_rght = e_regraft->p_lk_left; - v_tmp->b[1]->sum_scale_f_rght = e_regraft->sum_scale_f_rght; - v_tmp->b[2]->sum_scale_f_rght = e_regraft->sum_scale_f_left; - } + Copy_Scalar_Dbl(move->l0,move->n_link->b[dir_v0]->l); + Copy_Scalar_Dbl(move->v0,move->n_link->b[dir_v0]->l_var); - /* - ** Estimate edge lengths of the three relevant regraft edges based on - ** average subtree distances. - ** - ** l_01 - */ - /* - ** Alternative method of estimating l_01. Kept it around for reference... - ** - l_01 = subtree_dist[u_prune->num][u_n->num] - (0.5 * d_uu); - if (!u_n->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (u_n->v[i] != v_n) - { - if (u1 == NULL) - { - u1 = u_n->v[i]; - } - else - { - u2 = u_n->v[i]; - } - } - } - l_01 -= 0.5 * subtree_dist[u1->num][u2->num]; - } - for (i = 0; i < 3; i++) - { - if (u_n->v[i] == v_n) - { - l_01 -= u_n->b[i]->l; - break; - } - } - */ - l_01 = rgrft_cand[cand]->d_up_v - (0.5 * rgrft_cand[cand]->d_un_v) - - (0.5 * d_uu); - /* - ** l_02 - */ - l_02 = subtree_dist[u_prune->num][v_nx1->num] - (0.5 * d_uu); - if (!v_nx1->tax) - { - u1 = u2 = NULL; - for (i = 0; i < 3; i++) - { - if (v_nx1->v[i] != v_n) - { - if (u1 == NULL) - { - u1 = v_nx1->v[i]; - } - else - { - u2 = v_nx1->v[i]; - } - } - } - l_02 -= (0.5 * subtree_dist[u1->num][u2->num]); - } - /* - ** l_12 - */ - l_12 = e_regraft->l; - /* - ** Simple estimates. - */ - l_simple[0] = l_02 - (0.5*e_regraft->l); - l_simple[1] = 0.5 * e_regraft->l; - l_simple[2] = 0.5 * e_regraft->l; - for (i = 0; i < 3; i++) - { - if (l_simple[i] < BL_MIN) - { - l_simple[i] = BL_MIN; - } - } - /* - ** Average subtree distance based estimates. - */ - l_dist[0] = 0.5 * ( l_01 + l_02 - l_12); - l_dist[1] = 0.5 * ( l_01 - l_02 + l_12); - l_dist[2] = 0.5 * (-l_01 + l_02 + l_12); - for (i = 0; i < 3; i++) - { - if (l_dist[i] < BL_MIN) - { - l_dist[i] = BL_MIN; - } - } - /* - ** Take the average of the two estimates. - */ - l_est[0] = (l_simple[0] + l_dist[0]) / 2.0; - l_est[1] = (l_simple[1] + l_dist[1]) / 2.0; - l_est[2] = (l_simple[2] + l_dist[2]) / 2.0; - - /* - ** Set the edge lengths and update the relevant transition prob's and - ** partial likelihoods in the temporary regraft structure. - */ - for (i = 0; i < 3; i++) - { - v_tmp->b[i]->l = l_est[i]; - if (v_tmp->b[i]->l < BL_MIN) - { - v_tmp->b[i]->l = BL_MIN; - } - Update_PMat_At_Given_Edge (v_tmp->b[i], tree); - } - Update_P_Lk (tree, v_tmp->b[0], v_tmp); - - /* - ** Calculate the change in likelihood locally. Save it and the estimated edge - ** lengths in the current candidate in the list. - */ - new_lk = Lk_At_Given_Edge (v_tmp->b[0],tree); - rgrft_cand[cand]->delta_lk = new_lk - cur_lk; - rgrft_cand[cand]->rgrft_rank = cand; - rgrft_cand[cand]->optim_rank = -1; - rgrft_cand[cand]->globl_rank = -1; - rgrft_cand[cand]->l_connect = l_connect; - for (i = 0; i < 3; i++) + if(move->n_link->v[dir_v1]->num > move->n_link->v[dir_v2]->num) { - rgrft_cand[cand]->l_est[i] = v_tmp->b[i]->l; - } - if (rgrft_cand[cand]->delta_lk > best_d_lk) - { - best_d_lk = rgrft_cand[cand]->delta_lk; - best_cand = cand; - } + Copy_Scalar_Dbl(move->l1,move->n_link->b[dir_v2]->l); + Copy_Scalar_Dbl(move->v1,move->n_link->b[dir_v2]->l_var); - /* - ** Reset the partial likelihoods along the path. - */ - for (pat = 0; pat < tree->n_pattern; pat++) - { - p_sum[pat] = sum_scale_tmp[pat]; - for (cat = 0; cat < tree->mod->n_catg; cat++) - { - for (ste = 0; ste < tree->mod->ns; ste++) - { - p_lk[pat][cat][ste] = p_lk_tmp[pat][cat][ste]; - } - } + Copy_Scalar_Dbl(move->l2,move->n_link->b[dir_v1]->l); + Copy_Scalar_Dbl(move->v2,move->n_link->b[dir_v1]->l_var); } - n = rgrft_cand[cand]->dist; - for (i = 2; i <= n; i++) + else { - for (j = 0; j < 3; j++) - { - if (rgrft_cand[cand]->path[i]->v[j] == rgrft_cand[cand]->path[i+1]) - { - e_tmp = rgrft_cand[cand]->path[i]->b[j]; - break; - } - } - Update_P_Lk (tree, e_tmp, rgrft_cand[cand]->path[i]); - } - } + Copy_Scalar_Dbl(move->l1,move->n_link->b[dir_v1]->l); + Copy_Scalar_Dbl(move->v1,move->n_link->b[dir_v1]->l_var); - /* - ** If the best candidate is within the tree->mod->s_opt->wim_n_optim best ones, save it in the list of - ** optimization candidates. - */ - if (rgrft_cand[best_cand]->delta_lk > optim_cand[tree->mod->s_opt->wim_n_optim-1]->delta_lk) - { - i = tree->mod->s_opt->wim_n_optim-1; - optim_cand[i]->v_prune = rgrft_cand[best_cand]->v_prune; - optim_cand[i]->u_prune = rgrft_cand[best_cand]->u_prune; - optim_cand[i]->v_n = rgrft_cand[best_cand]->v_n; - optim_cand[i]->v_nx1 = rgrft_cand[best_cand]->v_nx1; - optim_cand[i]->u_n = rgrft_cand[best_cand]->u_n; - optim_cand[i]->e_prune = rgrft_cand[best_cand]->e_prune; - optim_cand[i]->e_regraft = rgrft_cand[best_cand]->e_regraft; - optim_cand[i]->d_L = rgrft_cand[best_cand]->d_L; - optim_cand[i]->dist = rgrft_cand[best_cand]->dist; - optim_cand[i]->rgrft_rank = rgrft_cand[best_cand]->rgrft_rank; - optim_cand[i]->optim_rank = rgrft_cand[best_cand]->optim_rank; - optim_cand[i]->globl_rank = rgrft_cand[best_cand]->globl_rank; - optim_cand[i]->l_connect = rgrft_cand[best_cand]->l_connect; - - for (j = 0; j < 3; j++) - { - optim_cand[i]->l_est[j] = rgrft_cand[best_cand]->l_est[j]; - } - optim_cand[i]->delta_lk = rgrft_cand[best_cand]->delta_lk; - /* - ** Move the candidate to the appropriate position in the list, so the list - ** remains sorted in decreasing delta_Lk value. - */ - while ((i > 0) && (optim_cand[i]->delta_lk > optim_cand[i-1]->delta_lk)) - { - tmp_cand = optim_cand[i]; - optim_cand[i] = optim_cand[i-1]; - optim_cand[i-1] = tmp_cand; - i--; - } + Copy_Scalar_Dbl(move->l2,move->n_link->b[dir_v2]->l); + Copy_Scalar_Dbl(move->v2,move->n_link->b[dir_v2]->l_var); } + + accept = YES; + if(!Check_Topo_Constraints(tree,tree->io->cstr_tree)) accept = NO; + - /* - ** Swap back the relevant partial likelihoods at the prune site. - */ - if (v_prune == v_prune->b[d1]->left) - { - v_prune->b[d1]->p_lk_left = p_lk1_tmp; - } - else - { - v_prune->b[d1]->p_lk_rght = p_lk1_tmp; - } - if (v_prune == v_prune->b[d2]->left) - { - v_prune->b[d2]->p_lk_left = p_lk2_tmp; + if(accept == YES) /* Apply the move */ + { + time(&(tree->t_current)); + Pars(NULL,tree); + + Update_PMat_At_Given_Edge(init_target,tree); + for(int i=0;i<3;++i) Update_PMat_At_Given_Edge(move->n_link->b[i],tree); + Post_Order_Lk(move->n_opp_to_link,move->n_link,tree); + Pre_Order_Lk(move->n_opp_to_link,move->n_link,tree); + Pre_Order_Lk(move->n_link,move->n_opp_to_link,tree); + Lk(move->b_opp_to_link,tree); + + if(fabs(tree->c_lnL - move->lnL) > tree->mod->s_opt->min_diff_lk_move) + { + PhyML_Fprintf(stderr,"\n== c_lnL = %f move_lnL = %f", tree->c_lnL,move->lnL); + PhyML_Fprintf(stderr,"\n== %d l0=%G l1=%G l2=%G v0=%G v1=%G v2=%G",move->n_link->num,move->l0->v,move->l1->v,move->l2->v,move->v0->v,move->v1->v,move->v2->v); + PhyML_Fprintf(stderr,"\n== Gamma MGF? %d",tree->io->mod->gamma_mgf_bl); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d.\n",__FILE__,__LINE__); + Check_Lk_At_Given_Edge(YES,tree); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + if(tree->verbose > VL2 && tree->io->quiet == NO) + { + Print_Lk_And_Pars(tree); + PhyML_Printf(" [depth=%5d]",move->depth_path); fflush(NULL); + } + + + tree->mod->s_opt->n_improvements++; + + t_spr *dum_move = move; + phydbl delta = 0.0; + while(dum_move) + { + delta = move->lnL - dum_move->lnL; + if(delta > tree->mod->s_opt->max_delta_lnL_spr_current) + tree->mod->s_opt->max_delta_lnL_spr_current = delta; + dum_move = dum_move->path_prev; + } + + + + if(tree->c_lnL > tree->best_lnL) tree->best_lnL = tree->c_lnL; + Record_Br_Len(tree); + + if(move->depth_path > tree->mod->s_opt->deepest_path) + tree->mod->s_opt->deepest_path = move->depth_path; + + if(move->depth_path > tree->mod->s_opt->max_spr_depth) tree->mod->s_opt->max_spr_depth = move->depth_path; + + return 1; } - else + else // Go back to original topology { - v_prune->b[d2]->p_lk_rght = p_lk2_tmp; - } + Prune_Subtree(move->n_link, + move->n_opp_to_link, + &move->b_target, + &b_residual, + tree); + + Graft_Subtree(init_target, + move->n_link, + NULL, + b_residual, + NULL, + tree); - /* - ** Reset the relevant edge lengths and transition prob's at the prune site. - */ - v_prune->b[d1]->l = v_prune->b[d1]->l_old; - v_prune->b[d2]->l = v_prune->b[d2]->l_old; - Update_PMat_At_Given_Edge (v_prune->b[d1], tree); - Update_PMat_At_Given_Edge (v_prune->b[d2], tree); + Restore_Br_Len(tree); - /* - ** Return the best candidate. - */ - return (best_cand); + return 0; + } } +/*********************************************************/ -/* -** Make_Move: Perform an actual SPR move and calculate the new likelihood. -** -** Parameters: -** - candidate: The candidate move to perform. -** - tree: The tree on which to perform the move. -** -*/ - -void Make_Move (_move_ *move, int type, arbre *tree) +int Try_One_Spr_Move_Full(t_spr *move, short int apply_move, t_tree *tree) { - int i; - node *v_prune, *u_prune, *v_n, *root; - edge *e_prune, *e_regraft, *e_connect, *e_avail; - phydbl new_lk; + t_edge *init_target, *b_residual; + phydbl init_lnL; + + assert(move); + if(move->n_link == NULL) return -1; + init_lnL = tree->c_lnL; + + Record_Br_Len(tree); - /* - ** Get the relevant nodes and edges. - */ - v_prune = move->v_prune; - u_prune = move->u_prune; - v_n = move->v_n; - e_prune = move->e_prune; - e_regraft = move->e_regraft; - /* printf (" making move: %d -> %d (%f)\n", e_prune->num, e_regraft->num, move->delta_lk); */ - /* - ** Perform the move and set edge lengths. - */ - Prune (e_prune, v_prune, &(e_connect), &(e_avail), tree); - Regraft (e_regraft, v_prune, e_avail, tree); - e_connect->l = move->l_connect; + Prune_Subtree(move->n_link, + move->n_opp_to_link, + &init_target, + &b_residual, + tree); + Graft_Subtree(move->b_target,move->n_link,NULL,b_residual,NULL,tree); - for (i = 0; i < 3; i++) + Optimize_Br_Len_Serie(2,tree); + + move->lnL = tree->c_lnL; + + if(tree->c_lnL > tree->best_lnL + tree->mod->s_opt->min_diff_lk_move && apply_move == YES) { - if (v_prune->v[i] == u_prune) - { - v_prune->b[i]->l = move->l_est[0]; - } - else if (v_prune->v[i] == v_n) - { - v_prune->b[i]->l = move->l_est[1]; - } - else - { - v_prune->b[i]->l = move->l_est[2]; - } + tree->best_lnL = tree->c_lnL; + tree->mod->s_opt->n_improvements++; + return 1; } + else + { + Prune_Subtree(move->n_link, + move->n_opp_to_link, + &move->b_target, + &b_residual, + tree); + Graft_Subtree(init_target, + move->n_link, + NULL, + b_residual, + NULL, + tree); - if(type > 0) /* local or global move */ - { Restore_Br_Len(tree); + tree->c_lnL = init_lnL; + return 0; } - - /* - ** Calculate the new likelihood. - */ - tree->both_sides = 1; - new_lk = Return_Lk (tree); - if(tree->c_lnL < cur_lk) + return -1; +} + +/*********************************************************/ + +unsigned int Include_One_Spr_To_List_Of_Spr(t_spr **list, int list_size, t_spr *move, t_tree *tree) +{ + unsigned int i, rk; + t_spr *buff_spr,*orig_move, *orig_move_list, *move_list; + t_tree *orig_tree; + + if(tree->mixt_tree != NULL) { - printf("\n. tree->c_lnL = %f cur_lk = %f",tree->c_lnL,cur_lk); - printf("\n. Err in file %s at line %d",__FILE__,__LINE__); - Warn_And_Exit(""); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); } - cur_lk = new_lk; - /* - ** Recalculate the average distances between all (non-overlapping) subtrees. - */ - root = tree->noeud[0]; - PostOrder_v (tree, root->v[0], root->b[0]); -} + rk = 0; + + if(((tree->mod->s_opt->spr_lnL == YES) && (move->lnL > list[list_size-1]->lnL)) || + ((tree->mod->s_opt->spr_lnL == NO) && (move->pars <= list[list_size-1]->pars))) + { + move_list = list[list_size-1]; + /* printf("\n. Include move with lnL: %G to list %p",move->lnL,(void *)list); */ + + move_list->depth_path = move->depth_path; + move_list->pars = move->pars; + move_list->lnL = move->lnL; + move_list->dist = move->dist; + + if(move_list->l0 == NULL) + { + move_list->l0 = Duplicate_Scalar_Dbl(move->l0); + move_list->v0 = Duplicate_Scalar_Dbl(move->v0); + } + else + { + Copy_Scalar_Dbl(move->l0,move_list->l0); + Copy_Scalar_Dbl(move->v0,move_list->v0); + } + + if(move_list->l1 == NULL) + { + move_list->l1 = Duplicate_Scalar_Dbl(move->l1); + move_list->v1 = Duplicate_Scalar_Dbl(move->v1); + } + else + { + Copy_Scalar_Dbl(move->l1,move_list->l1); + Copy_Scalar_Dbl(move->v1,move_list->v1); + } + + if(move_list->l2 == NULL) + { + move_list->l2 = Duplicate_Scalar_Dbl(move->l2); + move_list->v2 = Duplicate_Scalar_Dbl(move->v2); + } + else + { + Copy_Scalar_Dbl(move->l2,move_list->l2); + Copy_Scalar_Dbl(move->v2,move_list->v2); + } -/* -** Find_Optim_Local: Perform local edge length optimization on the candidates in the -** optimization list, and return the first one that gives an -** improvement in likelihood. -** -** Parameters: -** - tree: The tree on which to check the moves. -** -** Returns: -** If an improvement was found: The candidate that gives the improvement. -** Otherwise: -1. -*/ -int Find_Optim_Local (arbre *tree) -{ - int best_cand, cand, i; - node *v_prune, *u_prune, *v_n; - edge *e_prune, *e_regraft, *e_connect, *e_avail; - phydbl max_change, new_lk; - _move_ *move, *tmp_cand; - - /* - ** Try all candidate moves starting from the first one. - */ - best_cand = -1; - max_change = 1.0/BIG; - for(cand = 0; cand < tree->mod->s_opt->wim_n_optim; cand++) - { - move = optim_cand[cand]; - if(move->delta_lk > -1.0*BIG) - { - /* - ** Get the relevant nodes and edges. - */ - v_prune = move->v_prune; - u_prune = move->u_prune; - v_n = move->v_n; - e_prune = move->e_prune; - e_regraft = move->e_regraft; - - /* - ** Perform the move and set edge lengths. - */ - Prune (e_prune, v_prune, &(e_connect), &(e_avail), tree); - Regraft (e_regraft, v_prune, e_avail, tree); - e_connect->l_old = e_connect->l; - e_connect->l = move->l_connect; - - for (i = 0; i < 3; i++) - { - v_prune->b[i]->l_old = v_prune->b[i]->l; - - if (v_prune->v[i] == u_prune) - { - v_prune->b[i]->l = move->l_est[0]; - } - else if (v_prune->v[i] == v_n) - { - v_prune->b[i]->l = move->l_est[1]; - } - else - { - v_prune->b[i]->l = move->l_est[2]; - } - } - - tree->both_sides = 1; - Lk(tree); // Not sure anymore whether this is required... - - /* - ** Use Brent optimization on the relevant edges at the regraft position - ** and calculate the new likelihood value. - */ - Br_Len_Brent (10.*(v_prune->b[0]->l), v_prune->b[0]->l, BL_MIN, 1.e-10, - v_prune->b[0], tree, 250); - Br_Len_Brent (10.*(v_prune->b[1]->l), v_prune->b[1]->l, BL_MIN, 1.e-10, - v_prune->b[1], tree, 250); - Br_Len_Brent (10.*(v_prune->b[2]->l), v_prune->b[2]->l, BL_MIN, 1.e-10, - v_prune->b[2], tree, 250); - -/* Update_PMat_At_Given_Edge (v_prune->b[0], tree); */ -/* Update_PMat_At_Given_Edge (v_prune->b[1], tree); */ -/* Update_PMat_At_Given_Edge (v_prune->b[2], tree); */ - - Update_P_Lk (tree, v_prune->b[0], v_prune); - new_lk = Lk_At_Given_Edge (v_prune->b[0],tree); - -/* printf("\n. local new_lk = %f",new_lk); */ - - /* - ** Save the change in likelihood and move the current candidate to the - ** appropriate place in the list. - */ - move->delta_lk = new_lk - cur_lk; - move->optim_rank = cand; - i = cand; - while ((i > 0) && (optim_cand[i]->delta_lk > optim_cand[i-1]->delta_lk)) - { - tmp_cand = optim_cand[i]; - optim_cand[i] = optim_cand[i-1]; - optim_cand[i-1] = tmp_cand; - i--; - } - if (move->delta_lk > max_change) - { - best_cand = i; - max_change = move->delta_lk; - Record_Br_Len(tree); - } - - - /* - ** Undo the move again. - */ - Prune (e_prune, v_prune, &(e_regraft), &(e_avail), tree); - Regraft (e_connect, v_prune, e_avail, tree); - e_regraft->l = e_regraft->l_old; - for (i = 0; i < 3; i++) - { - v_prune->b[i]->l = v_prune->b[i]->l_old; - } - tree->both_sides = 1; - Lk(tree); - nr_loc++; -/* printf("\n. local back to = %f",tree->c_lnL); */ - } + if(move_list->init_target_l == NULL) + { + move_list->init_target_l = Duplicate_Scalar_Dbl(move->init_target_l); + move_list->init_target_v = Duplicate_Scalar_Dbl(move->init_target_v); + } else - { - break; - } + { + Copy_Scalar_Dbl(move->init_target_l,move_list->init_target_l); + Copy_Scalar_Dbl(move->init_target_v,move_list->init_target_v); + } + + orig_move = move; + orig_move_list = move_list; + orig_tree = tree; + do + { + move_list->b_target = move->b_target; + move_list->n_link = move->n_link; + move_list->n_opp_to_link = move->n_opp_to_link; + move_list->b_opp_to_link = move->b_opp_to_link; + move_list->b_init_target = move->b_init_target; + + move = move->next; + move_list = move_list->next; + tree = tree->next; + } + while(tree); + + move = orig_move; + move_list = orig_move_list; + tree = orig_tree; - /* - ** If an improvement was found, forget the other candidates... - */ - if (best_cand >= 0) - { - break; - } - } - - /* - ** Return the best candidate. - */ - return (best_cand); + for(i=0;idepth_path+1;++i) move_list->path[i] = move->path[i]; + + for(i=list_size-1;i>0;i--) + { + if(((tree->mod->s_opt->spr_lnL == YES) && (list[i]->lnL > list[i-1]->lnL)) || + ((tree->mod->s_opt->spr_lnL == NO) && (list[i]->pars <= list[i-1]->pars))) + { + + orig_tree = tree; + do + { + buff_spr = list[i-1]; + list[i-1] = list[i]; + list[i] = buff_spr; + + if(tree->next) tree = tree->next; + else tree = tree->next; + } + while(tree); + tree = orig_tree; + + } + else + { + rk = i; + break; + } + } + } + return rk; } +/*********************************************************/ -/* -** Find_Optim_Globl: Perform global edge length optimization on the candidates in the -** optimization list, and return the first one that gives an -** improvement in likelihood. -** -** Parameters: -** - tree: The tree on which to check the moves. -** -** Returns: -** If an improvement is found: The candidate that gives the improvement. -** Otherwise: -1. -*/ - -int Find_Optim_Globl (arbre *tree) +void Random_Spr(int n_moves, t_tree *tree) { - int best_cand, cand, i; - node *v_prune, *u_prune, *v_n, *root; - edge *e_prune, *e_regraft, *e_connect, *e_avail; - phydbl max_change, new_lk; - _move_ *move; - - /* - ** Try all moves. - */ - best_cand = -1; - max_change = 1.0/BIG; - for (cand = 0; cand < tree->mod->s_opt->wim_n_globl; cand++) - { - move = optim_cand[cand]; - if (move->delta_lk > -1.0*BIG) + int i; + int br_pulled, br_target; + t_spr *spr_struct; + t_edge *target, *residual; + + spr_struct = Make_One_Spr(tree); + Init_One_Spr(spr_struct); + target = residual = NULL; + + for(i=0;in_otu-3-1)); */ + br_pulled = Rand_Int(0,2*tree->n_otu-3-1); - /* - ** Get the relevant nodes and edges. - */ - v_prune = move->v_prune; - u_prune = move->u_prune; - v_n = move->v_n; - e_prune = move->e_prune; - e_regraft = move->e_regraft; - - /* - ** Perform the move and optimize all edge lengths. - */ - Prune (e_prune, v_prune, &(e_connect), &(e_avail), tree); - Regraft (e_regraft, v_prune, e_avail, tree); - e_connect->l_old = e_connect->l; - e_connect->l = move->l_connect; - - for (i = 0; i < 3; i++) - { - v_prune->b[i]->l_old = v_prune->b[i]->l; - if (v_prune->v[i] == u_prune) - { - v_prune->b[i]->l = move->l_est[0]; - } - else if (v_prune->v[i] == v_n) - { - v_prune->b[i]->l = move->l_est[1]; - } - else - { - v_prune->b[i]->l = move->l_est[2]; - } - } + do + { + /* br_target = (int)((phydbl)rand()/RAND_MAX * (2*tree->n_otu-3-1)); */ + br_target = Rand_Int(0,2*tree->n_otu-3-1); + } + while(br_target == br_pulled); + + spr_struct->n_link = tree->a_edges[br_pulled]->left; + spr_struct->n_opp_to_link = tree->a_edges[br_pulled]->rght; + spr_struct->b_opp_to_link = tree->a_edges[br_pulled]; + spr_struct->b_target = tree->a_edges[br_target]; + spr_struct->b_init_target = NULL; - tree->both_sides = 1; - Lk(tree); - root = tree->noeud[0]; - Optimize_Br_Len_Serie (root, root->v[0], root->b[0], tree, tree->data); - tree->both_sides = 1; - new_lk = Return_Lk (tree); - -/* printf("\n. global new_lk = %f\n",tree->c_lnL); */ - - /* - ** Save the change in likelihood and undo the move. - */ - - move->delta_lk = new_lk - cur_lk; - move->globl_rank = cand; - if (move->delta_lk > max_change) - { - best_cand = cand; - max_change = move->delta_lk; - Record_Br_Len(tree); - } - - Prune (e_prune, v_prune, &(e_regraft), &(e_avail), tree); - Regraft (e_connect, v_prune, e_avail, tree); - e_regraft->l = e_regraft->l_old; - for (i = 0; i < 3; i++) - { - v_prune->b[i]->l = v_prune->b[i]->l_old; - } - tree->both_sides = 1; - Restore_Br_Len(tree); - Lk(tree); - nr_glb++; -/* printf("\n. global back to = %f",tree->c_lnL); */ + if(!Check_Spr_Move_Validity(spr_struct,tree)) + { + spr_struct->n_link = tree->a_edges[br_pulled]->rght; + spr_struct->n_opp_to_link = tree->a_edges[br_pulled]->left; + } + +#ifdef DEBUG + if(!Check_Spr_Move_Validity(spr_struct,tree)) + { + Warn_And_Exit("\n== Could not find a valid move...\n"); + } +#endif + + if(spr_struct->n_link == spr_struct->b_target->left || + spr_struct->n_link == spr_struct->b_target->rght) + { + n_moves++; + continue; + } + + Prune_Subtree(spr_struct->n_link, + spr_struct->n_opp_to_link, + &target, + &residual, + tree); + + Graft_Subtree(spr_struct->b_target, + spr_struct->n_link, + NULL, + residual,NULL,tree); + } + Free(spr_struct); +} - } - else break; +/*********************************************************/ - /* - ** If an improvement was found, forget the other candidates... - */ - if (best_cand >= 0) break; +void Reset_Spr_List(t_spr **list, int size) +{ + int i; + + for(i=0;idepth_path = 0; + list[i]->pars = MAX_PARS; + list[i]->lnL = UNLIKELY; + list[i]->n_link = NULL; + list[i]->n_opp_to_link = NULL; + list[i]->b_target = NULL; } +} - /* - ** Return the best candidate. - */ - return (best_cand); +/*********************************************************/ + +int Check_Spr_Move_Validity(t_spr *this_spr_move, t_tree *tree) +{ + int match; + + match = 0; + Found_In_Subtree(this_spr_move->n_link, + this_spr_move->n_opp_to_link, + this_spr_move->b_target->left, + &match, + tree); + + if(match) return 0; + else return 1; } +/*********************************************************/ -/* -** Prune: Prune the subtree at a certain edge and node. Note that edge -** lengths are not set and partial likelihoods are not updated. -** -** Parameters: -** - e: The edge at which to prune the subtree. -** - v: The node adjacent to edge e which forms the root of the subtree. -** - e_connect: An edge pointer which will point to the edge that was left -** after pruning. -** - e_avail: The edge that is "left over" and should be used in the -** regrafting step. -** - tree: The tree on which the pruning is done. -** -** -** -** \ / -** o -** | -** | e --> subtree to be pruned -** | -** o v -** / \ -** e1/ \e2 -** / \ -** o o -** u1 u2 --> such that u1->num < u2->num -*/ +void Spr_Pars(int threshold, int n_round_max, t_tree *tree) +{ + int curr_pars,round; -void Prune (edge *e, node *v, edge **e_connect, edge **e_avail, arbre *tree) -{ - int dir0, dir1, dir2, v0, v1, v2, tmp_dir, i, j, k; - node *u1, *u2, *tmp_node; - edge *e1, *e2; - phydbl *sum_scale_f, ***p_lk; - - /* - ** Get the relevant directions, nodes and edges. - ** Make sure that node u1 is the node with the smaller number. - */ - dir0 = -1; - for (i = 0; i < 3; i++) - { - if (v->b[i] == e) + if(tree->verbose > VL2 && tree->io->quiet == NO) PhyML_Printf("\n. Minimizing parsimony...\n"); + + tree->best_pars = 1E+8; + tree->best_lnL = UNLIKELY; + tree->mod->s_opt->spr_lnL = NO; + tree->mod->s_opt->spr_pars = YES; + curr_pars = tree->c_pars; + tree->mod->s_opt->max_depth_path = tree->n_otu; + round = 0; + do { - dir0 = i; - break; + curr_pars = tree->c_pars; + Speed_Spr(tree,1.0,1,0.0); } - } - dir1 = (dir0 + 1) % 3; - dir2 = 3 - dir0 - dir1; - u1 = v->v[dir1]; - u2 = v->v[dir2]; - if (u1->num > u2->num) - { - tmp_node = u1; - u1 = u2; - u2 = tmp_node; - tmp_dir = dir1; - dir1 = dir2; - dir2 = tmp_dir; - } - e1 = v->b[dir1]; - e2 = v->b[dir2]; + while(tree->mod->s_opt->n_improvements && fabs((phydbl)(tree->c_pars - curr_pars)) > threshold && round++ < n_round_max); +} - /* - ** Detach node v from the tree. - */ - v->v[dir1] = NULL; - v->v[dir2] = NULL; - v->b[dir1] = NULL; - v->b[dir2] = NULL; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Spr_Shuffle(t_tree *mixt_tree) +{ + phydbl lk_old; + int *orig_catg,n,n_iter; + t_tree *tree,**tree_list; - /* - ** Connect nodes u1 and u2 via edge e1 and copy relevant partial likelihoods. + if(mixt_tree->verbose > VL0) PhyML_Printf("\n\n. Refining the tree...\n"); + + /*! Get the number of classes in each mixture */ + orig_catg = MIXT_Get_Number_Of_Classes_In_All_Mixtures(mixt_tree); + + + /*! Set the number of rate classes to (at most) 2. + ! Propagate this to every mixture tree in the analysis */ - if (u2 == e2->left) - { - v0 = e2->l_r; - v1 = e2->l_v1; - v2 = e2->l_v2; - sum_scale_f = e2->sum_scale_f_left; - p_lk = e2->p_lk_left; - } - else - { - v0 = e2->r_l; - v1 = e2->r_v1; - v2 = e2->r_v2; - sum_scale_f = e2->sum_scale_f_rght; - p_lk = e2->p_lk_rght; - } - if (u1 == e1->left) - { - e1->rght = u2; - e1->r_l = v0; - e1->r_v1 = v1; - e1->r_v2 = v2; - for (i = 0; i < tree->n_pattern; i++) - { - e1->sum_scale_f_rght[i] = sum_scale_f[i]; - for (j = 0; j < tree->mod->n_catg; j++) - { - for (k = 0; k < tree->mod->ns; k++) - { - e1->p_lk_rght[i][j][k] = p_lk[i][j][k]; - } - } - } - } - else - { - e1->left = u2; - e1->l_r = v0; - e1->l_v1 = v1; - e1->l_v2 = v2; - for (i = 0; i < tree->n_pattern; i++) + tree = mixt_tree; + n = 0; + do { - e1->sum_scale_f_left[i] = sum_scale_f[i]; - for (j = 0; j < tree->mod->n_catg; j++) +#ifdef BEAGLE + tree->b_inst = create_beagle_instance(tree, tree->io->quiet, tree->io); + //Instead of capping the rate categories at 2, just + //give the other categories 0 weight + if(orig_catg[n] > 2) //should we even bother? { - for (k = 0; k < tree->mod->ns; k++) - { - e1->p_lk_left[i][j][k] = p_lk[i][j][k]; - } + double cat_wghts[orig_catg[n]]; + //Give the first two categories equal weights + cat_wghts[0] = 0.5; + cat_wghts[1] = 0.5; + int i; + for(i=2;ib_inst,0,cat_wghts); + if(ret<0) {fprintf(stderr, "beagleSetCategoryWeights() on instance %i failed:%i\n\n",tree->b_inst,ret);Exit(""); } + tree->mod->optimizing_topology = true; } +#endif + tree->mod->ras->n_catg = MIN(2,orig_catg[n]); + if(tree->mod->ras->invar == YES) tree->mod->ras->n_catg--; + tree = tree->next_mixt; + n++; } - } - for (i = 0; i < 3; i++) - { - if (u1->v[i] == v) - { - u1->v[i] = u2; - } - if (u2->v[i] == v) - { - u2->v[i] = u1; - u2->b[i] = e1; - u2->l[i] = e1->l; - } - } + while(tree); - /* - ** Make sure that a possible tip node is still on the right side. - */ - if (e1->left->tax) - { - /* - ** Swap left and right. - */ - tmp_node = e1->left; - e1->left = e1->rght; - e1->rght = tmp_node; - tmp_dir = e1->l_r; - e1->l_r = e1->r_l; - e1->r_l = tmp_dir; - tmp_dir = e1->l_v1; - e1->l_v1 = e1->r_v1; - e1->r_v1 = tmp_dir; - tmp_dir = e1->l_v2; - e1->l_v2 = e1->r_v2; - e1->r_v2 = tmp_dir; - p_lk = e1->p_lk_left; - e1->p_lk_left = e1->p_lk_rght; - e1->p_lk_rght = p_lk; - sum_scale_f = e1->sum_scale_f_left; - e1->sum_scale_f_left = e1->sum_scale_f_rght; - e1->sum_scale_f_rght = sum_scale_f; - } - /* - ** Set the connecting and available edges. - */ - *(e_connect) = e1; - *(e_avail) = e2; -} + /*! Make sure the number of trees in each mixture is at most 2 + */ + tree_list = MIXT_Record_All_Mixtures(mixt_tree); + MIXT_Break_All_Mixtures(orig_catg,mixt_tree); + Set_Both_Sides(YES,mixt_tree); + Lk(NULL,mixt_tree); -/* -** Regraft: Regraft a subtree at a certain edge. Note that edge lengths -** are not set and partial likelihoods are not updated. -** -** Parameters: -** - e: The edge to regraft the subtree on. -** - v: The root of the subtree to regraft. -** - avail: A previously deleted edge now available for insertion again. -** - tree: The tree on which the regrafting is done. -** -** -** \ / -** o -** | -** | --> subtree to regraft -** | -** o v -** -** o--------o -** u1 e u2 --> such that u1->num < u2->num -*/ -void Regraft (edge *e, node *v, edge *avail, arbre *tree) -{ - int dir0, dir1, dir2, i, j, k; - phydbl *sum_scale_f, ***p_lk; - node *u1, *u2; + mixt_tree->best_pars = 1E+8; + mixt_tree->mod->s_opt->spr_lnL = NO; + mixt_tree->mod->s_opt->spr_pars = NO; + mixt_tree->mod->s_opt->quickdirty = NO; + mixt_tree->best_lnL = mixt_tree->c_lnL; + mixt_tree->mod->s_opt->max_depth_path = mixt_tree->n_otu; + mixt_tree->mod->s_opt->min_diff_lk_move = 0.1; + mixt_tree->annealing_temp = 0.0; - /* - ** Get the relevant directions and nodes. - */ - dir0 = -1; - for (i = 0; i < 3; i++) - { - if (v->b[i] != NULL) + n_iter = 0; + do { - dir0 = i; - break; + Set_Both_Sides(YES,mixt_tree); + Lk(NULL,mixt_tree); + Pars(NULL,mixt_tree); + Record_Br_Len(mixt_tree); + + mixt_tree->best_pars = mixt_tree->c_pars; + mixt_tree->best_lnL = mixt_tree->c_lnL; + + lk_old = mixt_tree->c_lnL; + Spr(UNLIKELY,1.0,mixt_tree); + + mixt_tree->annealing_temp -= 2.; + + if(mixt_tree->annealing_temp < 0.0) mixt_tree->annealing_temp = 0.0; + + if(mixt_tree->mod->s_opt->n_improvements < 5 || + mixt_tree->mod->s_opt->max_spr_depth < 2 || + FABS(lk_old-mixt_tree->c_lnL) < 5. || + ++n_iter > 10) break; + } - } - dir1 = (dir0 + 1) % 3; - dir2 = 3 - dir0 - dir1; - if (e->left->num < e->rght->num) - { - u1 = e->left; - u2 = e->rght; - sum_scale_f = e->sum_scale_f_rght; - p_lk = e->p_lk_rght; - } - else - { - u1 = e->rght; - u2 = e->left; - sum_scale_f = e->sum_scale_f_left; - p_lk = e->p_lk_left; - } + while(1); - /* - ** Connect nodes v and u2 via the available edge 'avail' and copy the - ** relevant partial likelihood. - ** (We want to do this first, cos we need some of the values of edge - ** e before changing them below). - */ - avail->left = v; - avail->rght = u2; - avail->l_r = dir2; - avail->l_v1 = dir0; - avail->l_v2 = dir1; - v->v[dir2] = u2; - v->b[dir2] = avail; - for (i = 0; i < 3; i++) - { - if (e == u2->b[i]) + mixt_tree->annealing_temp = 0.0; + + if(mixt_tree->verbose > VL0 && mixt_tree->io->quiet == NO) { - u2->v[i] = v; - u2->b[i] = avail; - avail->r_l = i; - avail->r_v1 = (i + 1) % 3; - avail->r_v2 = 3 - i - avail->r_v1; - break; + PhyML_Printf("\n\n. End of refining stage...\n"); } - } - for (i = 0; i < tree->n_pattern; i++) - { - avail->sum_scale_f_rght[i] = sum_scale_f[i]; - for (j = 0; j < tree->mod->n_catg; j++) + + /*! Go back to the original data structure, with potentially more + ! than 2 trees per mixture + */ + MIXT_Reconnect_All_Mixtures(tree_list,mixt_tree); + Free(tree_list); + + /*! Set the number of rate classes to their original values + */ + tree = mixt_tree; + n = 0; + do { - for (k = 0; k < tree->mod->ns; k++) - { - avail->p_lk_rght[i][j][k] = p_lk[i][j][k]; + tree->mod->ras->n_catg = orig_catg[n]; +#ifdef BEAGLE + tree->mod->optimizing_topology = false; + //Reset the rate categories to their original weights + if(orig_catg[n] > 2){ + update_beagle_ras(tree->mod); } +#endif + if(tree->mod->ras->invar == YES) tree->mod->ras->n_catg--; + tree = tree->next_mixt; + n++; } - } + while(tree); - /* - ** Connect nodes v and u1 via edge e. - */ - if (u1 == e->left) - { - e->rght = v; - e->r_l = dir1; - e->r_v1 = dir0; - e->r_v2 = dir2; - } - else - { - e->left = v; - e->l_r = dir1; - e->l_v1 = dir0; - e->l_v2 = dir2; - } - v->v[dir1] = u1; - v->b[dir1] = e; - for (i = 0; i < 3; i++) - { - if (u1->v[i] == u2) + Free(orig_catg); + + /*! Only the first two trees for each mixture have been modified so + ! far -> need to update the other trees by copying the modified trees + ! onto them. + */ + tree = mixt_tree; + do { - u1->v[i] = v; - break; + if(tree != mixt_tree) Copy_Tree(mixt_tree,tree); + tree = tree->next; } - } -} + while(tree); +} -/* -** PostOrder_v: Recursively visit all nodes v in postorder to calculate -** the average distance between subtrees. -** -** Parameters: -** - tree: The tree for which to calculate the average distances. -** - v: The current node. -** - e: The edge we came from. -*/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void PostOrder_v (arbre *tree, node *v, edge *e) +void Spr_Random_Explore(t_tree *tree, phydbl anneal_temp, phydbl prop_spr, int do_rnd, int max_cycles) { - int i; - node *w; + int step,i,n_targets,n_rand,no_improvement; + t_tree *best_tree; + scalar_dbl **best_bl; + t_node *rnd_node; + t_edge *b_target,*b_residual,**target_list,*rnd_edge; + phydbl true_best_lnL; + + if(tree->lock_topo == YES) + { + PhyML_Fprintf(stderr,"\n== The tree topology is locked."); + PhyML_Fprintf(stderr,"\n== Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } + + Set_Both_Sides(NO,tree); + Pars(NULL,tree); + Lk(NULL,tree); + + tree->mod->s_opt->max_depth_path = (int)(tree->n_otu/3); + tree->mod->s_opt->min_diff_lk_move = 0.1; + tree->mod->s_opt->spr_lnL = NO; + tree->mod->s_opt->spr_pars = NO; + tree->mod->s_opt->deepest_path = 0; + tree->best_pars = tree->c_pars; + step = 0; + true_best_lnL = tree->c_lnL; + best_tree = Make_Tree_From_Scratch(tree->n_otu,tree->data); + best_bl = Copy_Br_Len(tree); + target_list = (t_edge **)mCalloc(2*tree->n_otu-3,sizeof(t_edge *)); + n_targets = 0; + no_improvement = 0; + tree->annealing_temp = anneal_temp; + Copy_Tree(tree,best_tree); + + do + { + + if(do_rnd == YES) + { + n_rand = 0; + do + { + rnd_node = tree->a_nodes[Rand_Int(tree->n_otu,2*tree->n_otu-3)]; + assert(rnd_node != tree->n_root && rnd_node->tax == NO); + + rnd_edge = rnd_node->b[Rand_Int(0,2)]; + + Prune_Subtree(rnd_node, + rnd_node == rnd_edge->left ? rnd_edge->rght : rnd_edge->left, + &b_target, + &b_residual, + tree); + + n_targets = 0; + for(i=0;i<3;i++) + if(b_target->left->v[i] != b_target->rght) + Get_List_Of_Adjacent_Targets(b_target->left,b_target->left->v[i],NULL,&target_list,&n_targets,0,5); + + for(i=0;i<3;i++) + if(b_target->rght->v[i] != b_target->left) + Get_List_Of_Adjacent_Targets(b_target->rght,b_target->rght->v[i],NULL,&target_list,&n_targets,0,5); + + if(n_targets > 0) b_target = target_list[Rand_Int(0,n_targets-1)]; + + assert(b_target != NULL); + + Graft_Subtree(b_target,rnd_node,NULL,b_residual,NULL,tree); + + n_rand++; + } + while(n_rand != 1); + } + + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + Pars(NULL,tree); + + Print_Lk_And_Pars(tree); + + if(tree->annealing_temp < 0.0) tree->annealing_temp = 0.0; + if(prop_spr > 1.0) prop_spr = 1.0; + + tree->best_lnL = tree->c_lnL; + tree->best_pars = tree->c_pars; + Spr(UNLIKELY,prop_spr,tree); + + tree->annealing_temp -= 0.5; + prop_spr+=0.2; + + Optimiz_All_Free_Param(tree,(tree->io->quiet == YES)?(0):(tree->verbose > VL0)); + Optimize_Br_Len_Serie(2,tree); + + if(tree->io->print_trace) + { + char *s = Write_Tree(tree); + PhyML_Fprintf(tree->io->fp_out_trace,"[%f]%s\n",tree->c_lnL,s); fflush(tree->io->fp_out_trace); + if((tree->io->print_site_lnl) && (!tree->mod->s_opt->spr_pars)) + { + Print_Site_Lk(tree,tree->io->fp_out_lk); + fflush(tree->io->fp_out_lk); + } + Free(s); + } + + if(tree->io->print_json_trace == YES) JSON_Tree_Io(tree,tree->io->fp_out_json_trace); + + /* Record the current best log-likelihood and parsimony */ + if(tree->c_lnL > true_best_lnL) + { + no_improvement = 0; + true_best_lnL = tree->c_lnL; + For(i,2*tree->n_otu-1) Free_Scalar_Dbl(best_bl[i]); + Free(best_bl); + best_bl = Copy_Br_Len(tree); + Copy_Tree(tree,best_tree); /* Record tree topology, branch lengths and model parameters */ + } + else + { + no_improvement++; + } + + Transfer_Br_Len_To_Tree(best_bl,tree); + Copy_Tree(best_tree,tree); - /* - ** If v is not a taxon, recurse. - */ - if (!v->tax) - { - for (i = 0; i < 3; i++) - { - if (v->b[i] != e) - { - PostOrder_v (tree, v->v[i], v->b[i]); - } } - } + while(++step <= max_cycles && tree->mod->s_opt->n_improvements > 0 && tree->mod->s_opt->max_spr_depth > 1); - /* - ** Recurse over all nodes w not in the current subtree and calculate - ** the average distance between the current subtree and all others. - */ - if (v == e->left) - { - w = e->rght; - } - else - { - w = e->left; - } - PostOrder_w (tree, v, e, w, e); + Free(target_list); } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/* -** PostOrder_w: Recursively visit all nodes w not in the subtree of v in -** postorder and calculate the average distance between the -** subtree of v and all others. -** -** Parameters: -** - tree: The tree for which to calculate the average distances. -** - v: The root node of the first subtree. -** - v_e: The edge adjacent to the first subtree. -** - w: The current node. -** - e: The edge we came from. -*/ -void PostOrder_w (arbre *tree, node *v, edge *v_e, node *w, edge *e) +void Prune_Regraft_Time_Tree(t_tree *tree) { - int i; - node *w1, *w2, *v1, *v2; - - /* - ** If w is not a taxon, recurse. - */ - if (!w->tax) - { - for (i = 0; i < 3; i++) - { - if (w->b[i] != e) - { - PostOrder_w (tree, v, v_e, w->v[i], w->b[i]); - } - } - } - - /* - ** Calculate the average distance between the subtrees defined by - ** nodes v and w. - */ - if (v->tax && w->tax) - { - subtree_dist[v->num][w->num] = seq_dist->dist[v->num][w->num]; - } - else if (!v->tax) - { - v1 = v2 = NULL; - for (i = 0; i < 3; i++) - { - if (v->b[i] != v_e) - { - if (v1 == NULL) - { - v1 = v->v[i]; - } - else - { - v2 = v->v[i]; - } - } - } - subtree_dist[v->num][w->num] = 0.5*(subtree_dist[v1->num][w->num] + - subtree_dist[v2->num][w->num]); - } - else - { - w1 = w2 = NULL; - for (i = 0; i < 3; i++) - { - if (w->b[i] != e) - { - if (w1 == NULL) - { - w1 = w->v[i]; - } - else - { - w2 = w->v[i]; - } - } - } - subtree_dist[v->num][w->num] = 0.5*(subtree_dist[v->num][w1->num] + - subtree_dist[v->num][w2->num]); - } - subtree_dist[w->num][v->num] = subtree_dist[v->num][w->num]; + phydbl u,ratio; + phydbl t_min,t_max; + phydbl cur_lnL_seq,new_lnL_seq; + phydbl cur_lnL_time,new_lnL_time; + phydbl new_t; + int i,j,k,prune_idx,n_regraft_nd,regraft_idx,dir_prune; + phydbl *times; + int rnd_dir,dir_v1,dir_v2,keepon; + t_node *prune,*prune_daughter,*new_regraft_nd,*cur_regraft_nd; + t_ll *regraft_nd_list; + t_edge *target, *ori_target, *residual,*regraft_edge; + phydbl regraft_t_min,regraft_t_max; + + times = tree->rates->nd_t; + + do + { + keepon = NO; + for(i=tree->n_otu;i<2*tree->n_otu-2;++i) // for each internal node + { + + TIMES_Update_Node_Ordering(tree); + + RATES_Record_Times(tree); + + cur_lnL_seq = tree->c_lnL; + new_lnL_seq = UNLIKELY; + cur_lnL_time = tree->rates->c_lnL_times; + new_lnL_time = UNLIKELY; + + regraft_edge = NULL; + new_regraft_nd = NULL; + cur_regraft_nd = NULL; + new_t = 0.0; + + // Prune node + prune_idx = i; + prune = tree->a_nodes[prune_idx]; + assert(prune && prune->tax == NO); + + + // Select a daughter of prune node + dir_v1 = dir_v2 = -1; + for(j=0;j<3;++j) + if(prune->v[j] != prune->anc && prune->b[j] != tree->e_root) + { + if(dir_v1 < 0) dir_v1 = j; + else dir_v2 = j; + } + + u = Uni(); + if(u < 0.5) rnd_dir = dir_v1; + else rnd_dir = dir_v2; + + prune_daughter = prune->v[rnd_dir]; + cur_regraft_nd = prune->v[rnd_dir == dir_v1 ? dir_v2 : dir_v1]; + + if(prune == tree->n_root) + { + if(prune_daughter == prune->v[dir_v1] && prune->v[dir_v2]->tax == YES) + { + prune_daughter = prune->v[dir_v2]; + cur_regraft_nd = prune->v[dir_v1]; + } + + if(prune_daughter == prune->v[dir_v2] && prune->v[dir_v1]->tax == YES) + { + prune_daughter = prune->v[dir_v1]; + cur_regraft_nd = prune->v[dir_v2]; + } + } + + assert(prune_daughter->anc == prune); + + dir_prune = -1; + for(j=0;j<3;j++) + { + if(prune_daughter->v[j] == prune || prune_daughter->b[j] == tree->e_root) + { + dir_prune = j; + break; + } + } + assert(dir_prune > -1); + + + // Get the list of potential regraft nodes (oldest node on regraft edge) + regraft_nd_list = DATE_List_Of_Regraft_Nodes(prune_daughter->v[dir_prune],prune_daughter,®raft_t_min,®raft_t_max,NO,tree); + assert(regraft_nd_list); + if(prune == tree->n_root) Push_Bottom_Linked_List(prune,®raft_nd_list,YES); + + + // Number of regraft nodes + n_regraft_nd = Linked_List_Len(regraft_nd_list); + + + for(j=0;jnum],times[new_regraft_nd->num]); + if(new_regraft_nd == tree->n_root) t_min = 10.0*t_max; + else t_min = times[new_regraft_nd->anc->num]; + t_min = MAX(t_min,regraft_t_min); + + new_t = Uni()*(t_max-t_min) + t_min; + + + // New age + if(prune == tree->n_root || new_regraft_nd == tree->n_root) + { + if(prune == tree->n_root) + { + if(prune_daughter == tree->n_root->v[1]) times[tree->n_root->num] = times[tree->n_root->v[2]->num]; + else times[tree->n_root->num] = times[tree->n_root->v[1]->num]; + times[prune_daughter->v[dir_prune]->num] = new_t; + } + if(new_regraft_nd == tree->n_root) + { + times[prune_daughter->v[dir_prune]->num] = times[tree->n_root->num]; + times[tree->n_root->num] = new_t; + } + } + else + { + times[prune->num] = new_t; + } + + + // Prune + target = residual = NULL; + Prune_Subtree(prune_daughter->v[dir_prune], + prune_daughter, + &target,&residual,tree); + ori_target = target; + + + // Regraft edge is the one sitting above regraft_nd + if(new_regraft_nd == tree->n_root->v[1] || + new_regraft_nd == tree->n_root->v[2] || + new_regraft_nd == tree->n_root) regraft_edge = tree->e_root; + else + { + for(k=0;k<3;k++) if(new_regraft_nd->v[k] == new_regraft_nd->anc) break; + assert(k!=3); + regraft_edge = new_regraft_nd->b[k]; + } + + assert(regraft_edge); + + + // Regraft + Graft_Subtree(regraft_edge, + prune_daughter->v[dir_prune], + prune_daughter, + residual, + new_regraft_nd,tree); + + + if(!TIMES_Check_Node_Height_Ordering(tree)) + { + PhyML_Fprintf(stderr,"\n== prune[%d]->t:%.3f daughter[%d]->t:%.3f prune_anc[%d]->t:%.3f regraft[%d]->t:%.3f regraft_anc[%d]->t:%.3f [effective:%d] t_prior_min/max: [prune:[%.3f %.3f] regraft:[%.3f %.3f]] ", + prune->num, + times[prune->num], + prune_daughter->num, + times[prune_daughter->num], + prune->anc ? prune->anc->num : -1, + prune->anc ? times[prune->anc->num] : -1., + new_regraft_nd->num, + times[new_regraft_nd->num], + new_regraft_nd->anc ? new_regraft_nd->anc->num : -1, + new_regraft_nd->anc ? times[new_regraft_nd->anc->num] : +1., + prune->num, + tree->rates->t_prior_min[prune->num], + tree->rates->t_prior_max[prune->num], + tree->rates->t_prior_min[new_regraft_nd->num], + tree->rates->t_prior_max[new_regraft_nd->num]); + PhyML_Fprintf(stderr,"\n== root: %d %d %d",tree->n_root->num,tree->n_root->v[1]->num,tree->n_root->v[2]->num); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + DATE_Assign_Primary_Calibration(tree); + new_lnL_time = TIMES_Lk_Times(NO,tree); + + if(new_lnL_time > UNLIKELY) + { + Set_Both_Sides(NO,tree); + new_lnL_seq = Lk(NULL,tree); + } + + ratio = (new_lnL_seq - cur_lnL_seq); + + + if(ratio < .0) + { + // Reject + Prune_Subtree(prune_daughter->v[dir_prune], + prune_daughter, + &target,&residual,tree); + Graft_Subtree(ori_target, + prune_daughter->v[dir_prune], + prune_daughter,residual,prune == tree->n_root ? tree->n_root : cur_regraft_nd,tree); + + RATES_Reset_Times(tree); + RATES_Update_Cur_Bl(tree); + DATE_Assign_Primary_Calibration(tree); + TIMES_Lk_Times(NO,tree); + + + if(!(tree->rates->c_lnL_times > UNLIKELY)) + { + printf("\n== time prune: %f",times[prune->num]); + printf("\n== time prune_daughter: %f",times[prune_daughter->num]); + printf("\n== prune: %d prune_daughter: %d prune_daughter->v[dir_prune]: %d cur_regraft_nd: %d new_regraft_nd: %d", + prune->num, + prune_daughter->num, + prune_daughter->v[dir_prune]->num, + cur_regraft_nd->num, + new_regraft_nd->num); + TIMES_Lk_Times(YES,tree); + fflush(NULL); + } + assert(tree->rates->c_lnL_times > UNLIKELY); + + tree->c_lnL = cur_lnL_seq; + tree->rates->c_lnL_times = cur_lnL_time; + } + else + { + PhyML_Printf("\n. Hill-climbing step :: subtree [%4d/%4d] target [%4d/%4d] lnl: %f delta: %f", + i,2*tree->n_otu-2, + j,n_regraft_nd, + tree->c_lnL, + ratio); + if(ratio > 10.) keepon = YES; + break; + } + } + Free_Linked_List(regraft_nd_list); + } + }while(keepon == YES); } - - -/* -** EOF: spr.c -*/ + + + ////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// ** EOF: spr.c diff --git a/phyml/spr.h b/phyml/spr.h index dd38449..44bd9c0 100644 --- a/phyml/spr.h +++ b/phyml/spr.h @@ -4,6 +4,8 @@ ** Wim Hordijk Last modified: 28 August 2006 */ +#include + #ifndef _SPR_H_ #define _SPR_H_ @@ -19,35 +21,63 @@ typedef struct { - node *v_prune, *u_prune, *v_n, *v_nx1, *u_n, **path; - edge *e_prune, *e_regraft; + t_node *v_prune, *u_prune, *v_n, *v_nx1, *u_n, **path; + t_edge *e_prune, *e_regraft; phydbl l_connect, l_est[3], delta_lk, d_L, d_up_v, d_un_v; int dist, rgrft_rank, optim_rank, globl_rank; } _move_; -void Init_SPR (arbre *tree); -void Clean_SPR (arbre *tree); -void Optim_SPR (arbre *tree, int max_size, int method); -int Perform_SPR_Moves (arbre *tree, int max_size); -int Perform_Best_SPR (arbre *tree, int max_size); -int Perform_One_SPR (arbre *tree, int max_size); - -void Calc_Tree_Length (edge *e_prune, node *v_prune, arbre *tree); -void Tree_Length (node *v_prune, node *u_prune, node *v_n, node *v_n_1, - node *v_nx1, node *v_0, node *u_n, phydbl d_up_v_1, - phydbl d_uu, phydbl d_L_1, int n, arbre *tree); -int Est_Lk_Change (edge *e_prune, node *v_prune, arbre *tree); -int Best_Lk_Change (edge *e_prune, node *v_prune, arbre *tree); -void Make_Move (_move_ *move, int type, arbre *tree); -int Find_Optim_Local (arbre *tree); -int Find_Optim_Globl (arbre *tree); -void Prune (edge *e, node *v, edge **e_connect, edge **e_avail, - arbre *tree); -void Regraft (edge *e, node *v, edge *avail, arbre *tree); -void PostOrder_v (arbre *tree, node *v, edge *e); -void PostOrder_w (arbre *tree, node *v, edge *v_e, node *w, edge *e); +void Init_SPR (t_tree *tree); +void Clean_SPR (t_tree *tree); +void Optim_SPR (t_tree *tree, int max_size, int method); +int Perform_SPR_Moves (t_tree *tree, int max_size); +int Perform_Best_SPR (t_tree *tree, int max_size); +int Perform_One_SPR (t_tree *tree, int max_size); + +void Prune (t_edge *e, t_node *v, t_edge **e_connect, t_edge **e_avail, + t_tree *tree); +void Regraft (t_edge *e, t_node *v, t_edge *avail, t_tree *tree); +void PostOrder_v (t_tree *tree, t_node *v, t_edge *e); +void PostOrder_w (t_tree *tree, t_node *v, t_edge *v_e, t_node *w, t_edge *e); + + + + + +void Speed_Spr(t_tree *tree, phydbl prop_spr, int max_cycles, phydbl delta_lnL); +void Global_Spr_Search(t_tree *tree); +void Make_Spr_List(t_tree *tree); +void Init_One_Spr(t_spr *a_spr); +t_spr *Make_One_Spr(t_tree *tree); +int Spr(phydbl init_lnL, phydbl prop_spr, t_tree *tree); +int Spr_Recur(t_node *a, t_node *d, t_tree *tree); +int Test_All_Spr_Targets(t_edge *pulled, t_node *link, t_tree *tree); +void Randomize_Spr_List(t_tree *tree); +void Test_One_Spr_Target_Recur(t_node *a, t_node *d, t_edge *pulled, t_node *link, t_edge *residual, t_edge *init_target, int *best_found, t_spr *prev_move, t_tree *tree); +t_spr *Test_One_Spr_Target(t_edge *b_target, t_edge *b_arrow, t_node *n_link, t_edge *b_residual, t_edge *init_target, t_node *polarity, t_tree *tree); +void Apply_Spr_Moves_One_By_One(t_tree *tree); +int Try_One_Spr_Move_Triple(t_spr *move, t_tree *tree); +int Try_One_Spr_Move_Full(t_spr *move, short int apply_move, t_tree *tree); +void Make_Best_Spr(t_tree *tree); +void Random_Spr(int n_moves, t_tree *tree); +unsigned int Include_One_Spr_To_List_Of_Spr(t_spr **list, int list_size, t_spr *move, t_tree *tree); +void Reset_Spr_List(t_spr **list, int size); +int Evaluate_List_Of_Regraft_Pos_Triple(t_spr **spr_list, int list_size, t_tree *tree); +void Best_Spr(t_tree *tree); +int Check_Spr_Move_Validity(t_spr *this_spr_move, t_tree *tree); +void Spr_Subtree(t_edge *b, t_node *link, t_tree *tree); +void Spr_Pars(int threshold, int n_round_max, t_tree *tree); +void Spr_Shuffle(t_tree *tree); +void Sort_Spr_List_Depth(t_tree *tree); +void Sort_Spr_List_LnL(t_spr **list, int list_size, t_tree *tree); +void Spr_Random_Explore(t_tree *tree, phydbl anneal_temp, phydbl prop_spr, int do_rnd, int max_cycles); +void Sort_Spr_List_Pars(t_tree *tree); +void Spr_List_Of_Trees(t_tree *tree); +void Prune_Regraft_Time_Tree(t_tree *tree); +void Spr_Pre_Order(t_node *a, t_node *d, t_edge *b, t_tree *tree); + #endif /* _SPR_H_ */ diff --git a/phyml/sse.c b/phyml/sse.c new file mode 100644 index 0000000..a9b5ac1 --- /dev/null +++ b/phyml/sse.c @@ -0,0 +1,583 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "assert.h" +#include "sse.h" + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +#if defined(__SSE3__) + +void SSE_Update_Eigen_Lr(t_edge *b, t_tree *tree) +{ + unsigned int site,catg; + unsigned int i,j; + + unsigned const int npattern = tree->n_pattern; + unsigned const int ncatg = tree->mod->ras->n_catg; + unsigned const int ns = tree->mod->ns; + unsigned const int sz = (int)BYTE_ALIGN / 8; + unsigned const int nblocks = ns / sz; + unsigned const int ncatgns = ncatg*ns; + + const phydbl *p_lk_left,*p_lk_rght,*pi; + phydbl *dot_prod,*p_lk_left_pi; + phydbl *l_ev,*r_ev; + + __m128d *_l_ev,*_r_ev,*_prod_left,*_prod_rght; + +#ifndef WIN32 + if(posix_memalign((void **)&p_lk_left_pi,BYTE_ALIGN,(size_t) ns * sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&l_ev,BYTE_ALIGN,(size_t) ns * ns * sizeof(phydbl))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_l_ev,BYTE_ALIGN,(size_t) ns * ns / sz * sizeof(__m128d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_r_ev,BYTE_ALIGN,(size_t) ns * ns / sz * sizeof(__m128d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_prod_left,BYTE_ALIGN,(size_t) ns / sz * sizeof(__m128d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_prod_rght,BYTE_ALIGN,(size_t) ns / sz * sizeof(__m128d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + p_lk_left_pi = _aligned_malloc(ns * sizeof(phydbl),BYTE_ALIGN); + l_ev = _aligned_malloc(ns * ns * sizeof(phydbl),BYTE_ALIGN); + _l_ev = _aligned_malloc(ns * ns / sz * sizeof(__m128d),BYTE_ALIGN); + _r_ev = _aligned_malloc(ns * ns / sz * sizeof(__m128d),BYTE_ALIGN); + _prod_left = _aligned_malloc(ns / sz * sizeof(__m128d),BYTE_ALIGN); + _prod_rght = _aligned_malloc(ns / sz * sizeof(__m128d),BYTE_ALIGN); +#endif + + + assert(sz == 2); + assert(tree->update_eigen_lr == YES); + + r_ev = tree->mod->eigen->r_e_vect; + + /* Copy transpose of matrix of left eigen vectors */ + for(i=0;imod->eigen->l_e_vect[j*ns+i]; + + /* Load into AVX registers */ + for(i=0;ileft->tax ? b->p_lk_tip_l : b->p_lk_left; + p_lk_rght = b->rght->tax ? b->p_lk_tip_r : b->p_lk_rght; + pi = tree->mod->e_frq->pi->v; + dot_prod = tree->dot_prod; + + for(site=0;sitedata->wght[site] > SMALL) + { + for(catg=0;catgleft->tax == NO) p_lk_left += ns; + if(b->rght->tax == NO) p_lk_rght += ns; + } + + if(b->left->tax == YES) p_lk_left += ns; + if(b->rght->tax == YES) p_lk_rght += ns; + } + else + { + if(b->left->tax == YES) p_lk_left += ns; + else p_lk_left += ncatgns; + + if(b->rght->tax == YES) p_lk_rght += ns; + else p_lk_rght += ncatgns; + + dot_prod += ncatgns; + } + } + + Free(l_ev); + Free(_l_ev); + Free(_r_ev); + Free(_prod_left); + Free(_prod_rght); + Free(p_lk_left_pi); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl SSE_Lk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, int ns) +{ + phydbl lk; + unsigned int l; + const unsigned sz = (int)BYTE_ALIGN / 8; + const unsigned int nblocks = ns/sz; + __m128d _prod[nblocks],_x; + + for(l=0;ln_pattern; + const unsigned int ns = tree->mod->ns; + const unsigned int ncatg = tree->mod->ras->n_catg; + + const unsigned int ncatgns = ncatg * ns; + const unsigned int nsns = ns * ns; + + const unsigned int sz = (int)BYTE_ALIGN / 8; + const unsigned nblocks = ns/sz; + + __m128d *_tPij1,*_tPij2,*_pmat1plk1,*_pmat2plk2,*_plk0,*_init_tPij1,*_init_tPij2; + +#ifndef WIN32 + if(posix_memalign((void **)&_tPij1,BYTE_ALIGN,(size_t)(ncatg * nsns / sz) * sizeof(__m128d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_tPij2,BYTE_ALIGN,(size_t)(ncatg * nsns / sz) * sizeof(__m128d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_pmat1plk1,BYTE_ALIGN,(size_t)ns / sz * sizeof(__m128d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_pmat2plk2,BYTE_ALIGN,(size_t)ns / sz * sizeof(__m128d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(posix_memalign((void **)&_plk0,BYTE_ALIGN,(size_t)(ns / sz) * sizeof(__m128d))) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); +#else + _tPij1 = _aligned_malloc(ncatg * nsns / sz * sizeof(__m128d),BYTE_ALIGN); + _tPij2 = _aligned_malloc(ncatg * nsns / sz * sizeof(__m128d),BYTE_ALIGN); + tPij1 = _aligned_malloc(ncatg * nsns / sz * sizeof(__m128d),BYTE_ALIGN); + tPij2 = _aligned_malloc(ncatg * nsns / sz * sizeof(__m128d),BYTE_ALIGN); + _pmat1plk1 = _aligned_malloc(ns / sz * sizeof(__m128d),BYTE_ALIGN); + _pmat2plk2 = _aligned_malloc(ns / sz * sizeof(__m128d),BYTE_ALIGN); + _plk0 = _aligned_malloc(ns / sz * sizeof(__m128d),BYTE_ALIGN); +#endif + + _init_tPij1 = _tPij1; + _init_tPij2 = _tPij2; + + sum_scale_v1_val = 0; + sum_scale_v2_val = 0; + n_v1 = n_v2 = NULL; + plk0 = plk1 = plk2 = NULL; + Pij1 = Pij2 = NULL; + tPij1 = tPij2 = NULL; + sum_scale_v1 = sum_scale_v2 = NULL; + p_lk_loc = NULL; + state_v1 = state_v2 = -1; + + + Set_All_Partial_Lk(&n_v1,&n_v2, + &plk0,&sum_scale,&p_lk_loc, + &Pij1,&tPij1,&plk1,&sum_scale_v1, + &Pij2,&tPij2,&plk2,&sum_scale_v2, + d,b,tree); + + // Copy transpose of transition matrices into AVX registers + for(i=0;imod->augmented == YES) + { + PhyML_Printf("\n== AVX version of the Update_Partial_Lk function does not"); + PhyML_Printf("\n== allow augmented data."); + assert(FALSE); + } + + /* For every site in the alignment */ + for(site=0;sitedata->wght[site] > SMALL) + { + state_v1 = state_v2 = -1; + ambiguity_check_v1 = ambiguity_check_v2 = YES; + + if(n_v1 && n_v1->tax) + { + ambiguity_check_v1 = n_v1->c_seq->is_ambigu[site]; + if(ambiguity_check_v1 == NO) state_v1 = n_v1->c_seq->d_state[site]; + } + + if(n_v2 && n_v2->tax) + { + ambiguity_check_v2 = n_v2->c_seq->is_ambigu[site]; + if(ambiguity_check_v2 == NO) state_v2 = n_v2->c_seq->d_state[site]; + } + + _tPij1 = _init_tPij1; + _tPij2 = _init_tPij2; + + for(catg=0;catgtax) ? 0 : ns; + plk2 += (n_v2->tax) ? 0 : ns; + } + + plk1 += (n_v1->tax) ? ns : 0; + plk2 += (n_v2->tax) ? ns : 0; + + if(tree->scaling_method == SCALE_FAST) + { + sum_scale_v1_val = (sum_scale_v1)?(sum_scale_v1[site]):(0); + sum_scale_v2_val = (sum_scale_v2)?(sum_scale_v2[site]):(0); + sum_scale[site] = sum_scale_v1_val + sum_scale_v2_val; + + if(sum_scale[site] >= 1024) + { + /* plk0 -= ncatgns; */ + /* plk1 -= (n_v1->tax) ? ns : ncatgns; */ + /* plk2 -= (n_v2->tax) ? ns : ncatgns; */ + /* PhyML_Fprintf(stderr,"\n. PARTIAL site: %d plk0: %p [%g %g %g %g] plk1: %p [%g %g %g %g] plk2: %p [%g %g %g %g]", */ + /* site, */ + /* plk0, */ + /* plk0[0], */ + /* plk0[1], */ + /* plk0[2], */ + /* plk0[3], */ + /* plk1, */ + /* plk1[0], */ + /* plk1[1], */ + /* plk1[2], */ + /* plk1[3], */ + /* plk2, */ + /* plk2[0], */ + /* plk2[1], */ + /* plk2[2], */ + /* plk2[3] */ + /* ); */ + /* PhyML_Fprintf(stderr,"\n. PARTIAL site: %d d: %d n_v1: %d n_v2: %d",site,d->num,n_v1->num,n_v2->num); */ + /* PhyML_Fprintf(stderr,"\n. PARTIAL site: %d sum n: %d sum n_v1: %d sum n_v2: %d",site,sum_scale[site],sum_scale_v1_val,sum_scale_v2_val); */ + + /* plk0 += ncatgns; */ + /* plk1 += (n_v1->tax) ? ns : ncatgns; */ + /* plk2 += (n_v2->tax) ? ns : ncatgns; */ + /* Exit("\n"); */ + } + + plk0 -= ncatgns; + + largest_p_lk = -BIG; + for(i=0;i largest_p_lk) + largest_p_lk = plk0[i]; + + if(largest_p_lk < INV_TWO_TO_THE_LARGE && + tree->mod->augmented == NO && + tree->apply_lk_scaling == YES) + { + for(i=0;itax) ? ns : ncatgns; + plk2 += (n_v2->tax) ? ns : ncatgns; + } + } + + Free(_init_tPij1); + Free(_init_tPij2); + Free(_pmat1plk1); + Free(_pmat2plk2); + Free(_plk0); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void SSE_Partial_Lk_Exex(const __m128d *_tPij1, const int state1, const __m128d *_tPij2, const int state2, const int ns, __m128d *plk0) +{ + unsigned const int sz = (int)BYTE_ALIGN / 8; + unsigned const int nblocks = ns / sz; + unsigned int i; + + _tPij1 = _tPij1 + state1 * nblocks; + _tPij2 = _tPij2 + state2 * nblocks; + for(i=0;i 1.0 || plk1[i] < 1.0 || plk2[i] > 1.0 || plk2[i] < 1.0) break; + + if(i != ns) + { + SSE_Matrix_Vect_Prod(_tPij1,plk1,ns,_pmat1plk1); + SSE_Matrix_Vect_Prod(_tPij2,plk2,ns,_pmat2plk2); + + for(i=0;i + +#ifndef SSE_H +#define SSE_H + +#include "utilities.h" +#include "optimiz.h" +#include "models.h" +#include "free.h" +#include "times.h" +#include "mixt.h" + +#if defined(__SSE3__) + +void SSE_Update_Partial_Lk(t_tree *tree,t_edge *b_fcus,t_node *n); +void SSE_Update_Eigen_Lr(t_edge *b, t_tree *tree); +phydbl SSE_Lk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, int ns); +phydbl SSE_Lk_Core_One_Class_No_Eigen_Lr(phydbl *p_lk_left, phydbl *p_lk_rght, phydbl *Pij, phydbl *tPij, phydbl *pi, int ns, int ambiguity_check, int state); +phydbl SSE_Lk_Core(int state, int ambiguity_check, t_edge *b, t_tree *tree); +phydbl SSE_Lk_Core_Nucl(int state, int ambiguity_check, t_edge *b, t_tree *tree); +phydbl SSE_Lk_Core_AA(int state, int ambiguity_check, t_edge *b, t_tree *tree); +void SSE_Lk_dLk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, unsigned int ns, phydbl *lk, phydbl *dlk); + +void SSE_Partial_Lk_Exex(const __m128d *_tPij1, const int state1, const __m128d *_tPij2, const int state2, const int ns, __m128d *plk0); +void SSE_Partial_Lk_Exin(const __m128d *_tPij1, const int state1, const __m128d *_tPij2, const phydbl *_plk2, __m128d *_pmat2plk2, const int ns, __m128d *_plk0); +void SSE_Partial_Lk_Inin(const __m128d *_tPij1, const phydbl *plk1, __m128d *_pmat1plk1, const __m128d *_tPij2, const phydbl *plk2, __m128d *_pmat2plk2, const int ns, __m128d *_plk0); +void SSE_Matrix_Vect_Prod(const __m128d *_m_transpose, const phydbl *_v, const int ns, __m128d *_u); + +#endif +#endif diff --git a/phyml/stats.c b/phyml/stats.c new file mode 100644 index 0000000..d7037a4 --- /dev/null +++ b/phyml/stats.c @@ -0,0 +1,5210 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "stats.h" + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* RANDOM VARIATES GENERATORS */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/*********************************************************************/ +/* A C-function for TT800 : July 8th 1996 Version */ +/* by M. Matsumoto, email: matumoto@math.keio.ac.jp */ +/* tt800() generate one pseudorandom number with double precision */ +/* which is uniformly distributed on [0,1]-interval */ +/* for each call. One may choose any initial 25 seeds */ +/* except all zeros. */ + +/* See: ACM Transactions on Modelling and Computer Simulation, */ +/* Vol. 4, No. 3, 1994, pages 254-266. */ + +phydbl tt800() +{ + int M=7; + unsigned long y; + static int k = 0; + static unsigned long x[25]={ /* initial 25 seeds, change as you wish */ + 0x95f24dab, 0x0b685215, 0xe76ccae7, 0xaf3ec239, 0x715fad23, + 0x24a590ad, 0x69e4b5ef, 0xbf456141, 0x96bc1b7b, 0xa7bdf825, + 0xc1de75b7, 0x8858a9c9, 0x2da87693, 0xb657f9dd, 0xffdc8a9f, + 0x8121da71, 0x8b823ecb, 0x885d05f5, 0x4e20cd47, 0x5a9ad5d9, + 0x512c0c03, 0xea857ccd, 0x4cc1d30f, 0x8891a8a1, 0xa6b7aadb + }; + static unsigned long mag01[2]={ + 0x0, 0x8ebfd028 /* this is magic vector `a', don't change */ + }; + if (k==25) { /* generate 25 words at one time */ + int kk; + for (kk=0;kk<25-M;kk++) { + x[kk] = x[kk+M] ^ (x[kk] >> 1) ^ mag01[x[kk] % 2]; + } + for (; kk<25;kk++) { + x[kk] = x[kk+(M-25)] ^ (x[kk] >> 1) ^ mag01[x[kk] % 2]; + } + k=0; + } + y = x[k]; + y ^= (y << 7) & 0x2b5b2500; /* s and b, magic vectors */ + y ^= (y << 15) & 0xdb8b0000; /* t and c, magic vectors */ + y &= 0xffffffff; /* you may delete this line if word size = 32 */ + /* + the following line was added by Makoto Matsumoto in the 1996 version + to improve lower bit's corellation. + Delete this line to o use the code published in 1994. + */ + y ^= (y >> 16); /* added to the 1994 version */ + k++; + return((phydbl)y / (unsigned long) 0xffffffff); +} + +/*********************************************************************/ + +phydbl Uni() +{ + phydbl r,mx; + mx = (phydbl)RAND_MAX; + r = (phydbl)rand(); + r /= mx; + /* r = tt800(); */ + return r; +} + +/*********************************************************************/ +// Return a uniform draw u s.t., min <= u <= max +int Rand_Int(int min, int max) +{ +/* phydbl u; */ +/* u = (phydbl)rand(); */ +/* u /= (RAND_MAX); */ +/* u *= (max - min + 1); */ +/* u += min; */ +/* return (int)FLOOR(u); */ + + int u; + /* if(max < min) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); */ + u = rand(); + return (u%(max+1-min)+min); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + + +/********************* random Gamma generator ************************ +* Properties: +* (1) X = Gamma(alpha,lambda) = Gamma(alpha,1)/lambda +* (2) X1 = Gamma(alpha1,1), X2 = Gamma(alpha2,1) independent +* then X = X1+X2 = Gamma(alpha1+alpha2,1) +* (3) alpha = k = integer then +* X = Gamma(k,1) = Erlang(k,1) = -sum(log(Ui)) = -log(prod(Ui)) +* where U1,...Uk iid uniform(0,1) +* +* Decompose alpha = k+delta with k = [alpha], and 00.) + { + phydbl y = 0.; + phydbl b = (alpha+exp(1.))/exp(1.); + phydbl p = 1./alpha; + int go = 0; + while (go==0) + { + phydbl u = Uni(); + phydbl w = Uni(); + phydbl v = b*u; + if (v<=1.) + { + x = POW(v,p); + y = exp(-x); + } + else + { + x = -log(p*(b-v)); + y = POW(x,alpha-1.); + } + go = (w= 1. Algorithm GD in: + + Ahrens, J.H. and Dieter, U. (1982). + Generating gamma variates by a modified + rejection technique. + Comm. ACM, 25, 47-54. + + + [2] Shape parameter 0 < a < 1. Algorithm GS in: + + Ahrens, J.H. and Dieter, U. (1974). + Computer methods for sampling from gamma, beta, + poisson and binomial distributions. + Computing, 12, 223-246. + */ + + + double a = (double)shape; + /* Constants : */ + const static double sqrt32 = 5.656854; + const static double exp_m1 = 0.36787944117144232159;/* exp(-1) = 1/e */ + + /* Coefficients q[k] - for q0 = sum(q[k]*a^(-k)) + * Coefficients a[k] - for q = q0+(t*t/2)*sum(a[k]*v^k) + * Coefficients e[k] - for exp(q)-1 = sum(e[k]*q^k) + */ + const static double q1 = 0.04166669; + const static double q2 = 0.02083148; + const static double q3 = 0.00801191; + const static double q4 = 0.00144121; + const static double q5 = -7.388e-5; + const static double q6 = 2.4511e-4; + const static double q7 = 2.424e-4; + + const static double a1 = 0.3333333; + const static double a2 = -0.250003; + const static double a3 = 0.2000062; + const static double a4 = -0.1662921; + const static double a5 = 0.1423657; + const static double a6 = -0.1367177; + const static double a7 = 0.1233795; + + /* State variables [FIXME for threading!] :*/ + static double aa = 0.; + static double aaa = 0.; + static double s, s2, d; /* no. 1 (step 1) */ + static double q0, b, si, c;/* no. 2 (step 4) */ + + double e, p, q, r, t, u, v, w, x, ret_val; + + if(a < 0.0 || scale <= 0.0) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + if (a < 1.) + { /* GS algorithm for parameters a < 1 */ + if(a == 0) return 0.; + e = 1.0 + exp_m1 * a; + for(;;) + { + p = e * Uni(); + if (p >= 1.0) + { + x = -log((e - p) / a); + if (Rexp(1.) >= (1.0 - a) * log(x)) + break; + } + else + { + x = exp(log(p) / a); + if (Rexp(1.) >= x) + break; + } + } + return scale * x; + } + + /* --- a >= 1 : GD algorithm --- */ + + /* Step 1: Recalculations of s2, s, d if a has changed */ + if (a != aa) + { + aa = a; + s2 = a - 0.5; + s = SQRT(s2); + d = sqrt32 - s * 12.0; + } + /* Step 2: t = standard normal deviate, + x = (s,1/2) -normal deviate. */ + + /* immediate acceptance (i) */ + t = Rnorm(0.0,1.0); + x = s + 0.5 * t; + ret_val = x * x; + if (t >= 0.0) return scale * ret_val; + + /* Step 3: u = 0,1 - uniform sample. squeeze acceptance (s) */ + u = Uni(); + if (d * u <= t * t * t) return scale * ret_val; + + /* Step 4: recalculations of q0, b, si, c if necessary */ + + if (a != aaa) + { + aaa = a; + r = 1.0 / a; + q0 = ((((((q7 * r + q6) * r + q5) * r + q4) * r + q3) * r + + q2) * r + q1) * r; + + /* Approximation depending on size of parameter a */ + /* The constants in the expressions for b, si and c */ + /* were established by numerical experiments */ + + if (a <= 3.686) + { + b = 0.463 + s + 0.178 * s2; + si = 1.235; + c = 0.195 / s - 0.079 + 0.16 * s; + } + else if (a <= 13.022) + { + b = 1.654 + 0.0076 * s2; + si = 1.68 / s + 0.275; + c = 0.062 / s + 0.024; + } + else + { + b = 1.77; + si = 0.75; + c = 0.1515 / s; + } + } + + /* Step 5: no quotient test if x not positive */ + if (x > 0.0) + { + /* Step 6: calculation of v and quotient q */ + v = t / (s + s); + if (fabs(v) <= 0.25) + q = q0 + 0.5 * t * t * ((((((a7 * v + a6) * v + a5) * v + a4) * v + + a3) * v + a2) * v + a1) * v; + else + q = q0 - s * t + 0.25 * t * t + (s2 + s2) * log(1.0 + v); + + + /* Step 7: quotient acceptance (q) */ + if (log(1.0 - u) <= q) + return scale * ret_val; + } + + for(;;) + { + /* Step 8: e = standard exponential deviate + * u = 0,1 -uniform deviate + * t = (b,si)-double exponential (laplace) sample */ + e = Rexp(1.0); + u = Uni(); + u = u + u - 1.0; + if (u < 0.0) + t = b - si * e; + else + t = b + si * e; + /* Step 9: rejection if t < tau(1) = -0.71874483771719 */ + if (t >= -0.71874483771719) { + /* Step 10: calculation of v and quotient q */ + v = t / (s + s); + if (fabs(v) <= 0.25) + q = q0 + 0.5 * t * t * + ((((((a7 * v + a6) * v + a5) * v + a4) * v + a3) * v + + a2) * v + a1) * v; + else + q = q0 - s * t + 0.25 * t * t + (s2 + s2) * log(1.0 + v); + /* Step 11: hat acceptance (h) */ + /* (if q not positive go to step 8) */ + if (q > 0.0) { + w = exp(q)-1.0; + /* if t is rejected sample again at step 8 */ + if (c * fabs(u) <= w * exp(e - 0.5 * t * t)) + break; + } + } + } /* repeat .. until `t' is accepted */ + x = s + 0.5 * t; + return scale * x * x; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Rexp(phydbl lambda) +{ + return -log(Uni()+SMALL)/lambda; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Returns a random deviates from an exponential distribution */ +/* left-truncated at 'left' and right-truncated at 'rght' */ +phydbl Rexp_Trunc(phydbl lambda, phydbl left, phydbl rght) +{ + phydbl u; + u = Uni(); + return (left-log(1. - u*(1.-exp(-lambda*(rght-left))))/lambda); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl Rnorm(phydbl mean, phydbl sd) +{ + /* Box-Muller transformation */ + phydbl u1, u2, res; + + /* u1=Uni(); */ + /* u2=Uni(); */ + /* u1 = SQRT(-2.*log(u1))*COS(6.28318530717959f*u2); */ + + /* Polar */ + phydbl d,x,y; + + do + { + u1=Uni(); + u2=Uni(); + x = 2.*u1-1.; + y = 2.*u2-1.; + d = x*x + y*y; + if(d>.0 && d<1.) break; + } + while(1); + u1 = x*SQRT((-2.*log(d))/d); + + res = u1*sd+mean; + + if(isnan(res) || isinf(res)) + { + printf("\n. res=%f sd=%f mean=%f u1=%f u2=%f",res,sd,mean,u1,u2); + } + return res; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl *Rnorm_Multid(phydbl *mu, phydbl *cov, int dim) +{ + phydbl *L,*x,*y; + int i,j; + + x = (phydbl *)mCalloc(dim,sizeof(phydbl)); + y = (phydbl *)mCalloc(dim,sizeof(phydbl)); + + L = (phydbl *)Cholesky_Decomp(cov,dim); + + for(i=0;i z_max+eps)) + { + *error = 1; + PhyML_Printf("\n. Numerical precision issue detected in Rnorm_Trunc."); + PhyML_Printf("\n. z = %f",z); + PhyML_Printf("\n. mean=%f sd=%f z_min=%f z_max=%f min=%f max=%f",mean,sd,z_min,z_max,min,max); + ret_val = (max - min)/2.; + Exit("\n"); + } + + ret_val = z*sd+mean; + + return ret_val; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +/* Borrowed from https://github.com/olafmersmann/truncnorm/blob/afc91b696db8a3feda25d39435fd979bacd962c6/src/rtruncnorm.c */ + +phydbl Rnorm_Trunc_Algo1(phydbl alpha, phydbl beta) +{ + phydbl z = -DBL_MAX; + while(z < alpha || z > beta) + { + z = Rnorm(0.0,1.0); + } + return(z); +} + +phydbl Rnorm_Trunc_Algo2(phydbl alpha, phydbl beta) +{ + phydbl z = 0.0; + phydbl d_alpha = Dnorm(alpha,0.0,1.0); + const double ub = alpha < 0.0 && beta > 0.0 ? M_1_SQRT_2PI : d_alpha; + do + { + z = Uni()*(beta-alpha) + alpha; + } + while(Uni() * ub > Dnorm(z,0.0,1.0)); + return(z); +} + +phydbl Rnorm_Trunc_Algo3(phydbl alpha, phydbl beta) +{ + + phydbl z = alpha - 1.0; + while(z < alpha || z > beta) + { + z = Rnorm(0,1); + z = fabs(z); + } + return(z); +} + +phydbl Rnorm_Trunc_Algo4(phydbl alpha, phydbl beta) +{ + phydbl z = 0.0; + const phydbl ainv = 1.0/alpha; + phydbl rho; + do + { + z = Rexp(ainv) + alpha; + rho = exp(-0.5 * pow((z-alpha),2)); + } + while(Uni() > rho || z > beta); + return(z); +} + + +phydbl Rnorm_Trunc(phydbl mean, phydbl sd, phydbl min, phydbl max, int *error) +{ + phydbl alpha,beta; + phydbl d_alpha,d_beta; + phydbl z,ret_val; + + alpha = (min - mean)/sd; + beta = (max - mean)/sd; + + d_alpha = Dnorm(alpha,0.0,1.0); + d_beta = Dnorm(beta,0.0,1.0); + + /* PhyML_Printf("\n. alpha: %f beta: %f d_alpha: %f d_beta: %f",alpha,beta,d_alpha,d_beta); */ + + + if(beta < alpha) return NAN; + else + { + if(!(alpha > 0.0) && !(beta < 0.0)) + { + if(!(d_alpha > 0.15) || !(d_beta > 0.15)) + { + z = Rnorm_Trunc_Algo1(alpha,beta); + return(mean + sd * z); + } + else + { + z = Rnorm_Trunc_Algo2(alpha,beta); + return(mean + sd * z); + } + } + else if(alpha > 0.0) + { + if(!(d_alpha / d_beta > 2.18)) + { + z = Rnorm_Trunc_Algo2(alpha,beta); + return(mean + sd * z); + } + else + { + if(!(alpha > 0.725)) + { + z = Rnorm_Trunc_Algo3(alpha,beta); + return(mean + sd * z); + } + else + { + z = Rnorm_Trunc_Algo4(alpha,beta); + return(mean + sd * z); + } + } + } + else + { + if(!(d_beta / d_alpha > 2.18)) + { + z = Rnorm_Trunc_Algo2(alpha,beta); + return(mean - sd * z); + } + else if(beta > -0.725) + { + z = Rnorm_Trunc_Algo3(alpha,beta); + return(mean - sd * z); + } + else + { + z = Rnorm_Trunc_Algo4(alpha,beta); + return(mean - sd * z); + } + } + } + + ret_val = mean + sd*z; + return ret_val; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl *Rnorm_Multid_Trunc(phydbl *mean, phydbl *cov, phydbl *min, phydbl *max, int dim) +{ + int i,j; + phydbl *L,*x, *u; + phydbl up, low, rec; + int err; + + u = (phydbl *)mCalloc(dim,sizeof(phydbl)); + x = (phydbl *)mCalloc(dim,sizeof(phydbl)); + + L = Cholesky_Decomp(cov,dim); + + low = (min[0]-mean[0])/L[0*dim+0]; + up = (max[0]-mean[0])/L[0*dim+0]; + u[0] = Rnorm_Trunc(0.0,1.0,low,up,&err); + + for(i=1;i>>\n"); */ +/* for(i=0;i 1.-SMALL) + { + if(logit == YES) return(-INFINITY); + else return(0.0); + } + + if(logit == YES) + prob = (k - 1.)*log(1. - p) + log(p); + else + prob = POW(1.-p,k-1.)*p; + + return(prob); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Pgeom(phydbl k, phydbl p) +{ + + if(k < 1.) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(p > 1.-SMALL) return(0.0); + + return(1. - POW((1. - p),k)); + +} + + +/* + * Random variates from the Poisson distribution. Completely stolen from R code. + * + * REFERENCE + * + * Ahrens, J.H. and Dieter, U. (1982). + * Computer generation of Poisson deviates + * from modified normal distributions. + * ACM Trans. Math. Software 8, 163-179. + */ +phydbl Rpois(phydbl mmu) +{ + double mu = (double)mmu; + + double a0 = -0.5; + double a1 = 0.3333333; + double a2 = -0.2500068; + double a3 = 0.2000118; + double a4 = -0.1661269; + double a5 = 0.1421878; + double a6 = -0.1384794; + double a7 = 0.1250060; + double one_7 = 0.1428571428571428571; + double one_12 = 0.0833333333333333333; + double one_24 = 0.0416666666666666667; + + /* Factorial Table (0:9)! */ + const static double fact[10] = + { + 1., 1., 2., 6., 24., 120., 720., 5040., 40320., 362880. + }; + /* These are static --- persistent between calls for same mu : */ + static int l, m; + static double b1, b2, c, c0, c1, c2, c3; + static double pp[36], p0, p, q, s, d, omega; + static double big_l;/* integer "w/o overflow" */ + static double muprev = 0., muprev2 = 0.;/*, muold = 0.*/ + /* Local Vars [initialize some for -Wall]: */ + double del, difmuk= 0., E= 0., fk= 0., fx, fy, g, px, py, t, u= 0., v, x; + double pois = -1.; + int k, kflag, big_mu, new_big_mu = FALSE; + + if (isnan(mu) || mu < 0.0) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if (mu <= 0.) return 0.; + + big_mu = mu >= 10.; + if(big_mu) new_big_mu = FALSE; + if (!(big_mu && mu == muprev)) {/* maybe compute new persistent par.s */ + if (big_mu) + { + new_big_mu = TRUE; + /* Case A. (recalculation of s,d,l because mu has changed): + * The poisson probabilities pk exceed the discrete normal + * probabilities fk whenever k >= m(mu). + */ + muprev = mu; + s = sqrt(mu); + d = 6. * mu * mu; + big_l = floor(mu - 1.1484); + /* = an upper bound to m(mu) for all mu >= 10.*/ + } + else + { + /* Small mu ( < 10) -- not using normal approx. */ + /* Case B. (start new table and calculate p0 if necessary) */ + /*muprev = 0.;-* such that next time, mu != muprev ..*/ + if (mu != muprev) + { + muprev = mu; + m = MAX(1, (int) mu); + l = 0; /* pp[] is already ok up to pp[l] */ + q = p0 = p = exp(-mu); + } + for(;;) + { + /* Step U. uniform sample for inversion method */ + u = Uni(); + if (u <= p0) return 0.; + /* Step T. table comparison until the end pp[l] of the + pp-table of cumulative poisson probabilities + (0.458 > ~= pp[9](= 0.45792971447) for mu=10 ) */ + if (l != 0) + { + for (k = (u <= 0.458) ? 1 : MIN(l, m); k <= l; k++) if (u <= pp[k]) return((phydbl)k); + if (l == 35) /* u > pp[35] */ + continue; + } + /* Step C. creation of new poisson + probabilities p[l..] and their cumulatives q =: pp[k] */ + l++; + for (k = l; k <= 35; k++) + { + p *= mu / k; + q += p; + pp[k] = q; + if (u <= q) + { + l = k; + return((phydbl)k); + } + } + l = 35; + } /* end(repeat) */ + }/* mu < 10 */ + } /* end {initialize persistent vars} */ + /* Only if mu >= 10 : ----------------------- */ + /* Step N. normal sample */ + g = mu + s * Rnorm(0.0,1.0);/* norm_rand() ~ N(0,1), standard normal */ + if (g >= 0.) + { + pois = floor(g); + /* Step I. immediate acceptance if pois is large enough */ + if (pois >= big_l) + return((phydbl)pois); + /* Step S. squeeze acceptance */ + fk = pois; + difmuk = mu - fk; + u = Uni(); /* ~ U(0,1) - sample */ + if (d * u >= difmuk * difmuk * difmuk) + return((phydbl)pois); + } + /* Step P. preparations for steps Q and H. + (recalculations of parameters if necessary) */ + if (new_big_mu || mu != muprev2) { + /* Careful! muprev2 is not always == muprev + because one might have exited in step I or S + */ + muprev2 = mu; + omega = M_1_SQRT_2PI / s; + /* The quantities b1, b2, c3, c2, c1, c0 are for the Hermite + * approximations to the discrete normal probabilities fk. */ + b1 = one_24 / mu; + b2 = 0.3 * b1 * b1; + c3 = one_7 * b1 * b2; + c2 = b2 - 15. * c3; + c1 = b1 - 6. * b2 + 45. * c3; + c0 = 1. - b1 + 3. * b2 - 15. * c3; + c = 0.1069 / mu; /* guarantees majorization by the 'hat'-function. */ + } + if (g >= 0.) { + /* 'Subroutine' F is called (kflag=0 for correct return) */ + kflag = 0; + goto Step_F; + } + for(;;) + { + /* Step E. Exponential Sample */ + E = Rexp(1.0); /* ~ Exp(1) (standard exponential) */ + /* sample t from the laplace 'hat' + (if t <= -0.6744 then pk < fk for all mu >= 10.) */ + u = 2. * Uni() - 1.; + /* t = 1.8 + fsign(E, u); */ + t = 1.8 + ((u >= 0.0) ? fabs(E) : -fabs(E)); + if (t > -0.6744) + { + pois = floor(mu + s * t); + fk = pois; + difmuk = mu - fk; + /* 'subroutine' F is called (kflag=1 for correct return) */ + kflag = 1; + Step_F: /* 'subroutine' F : calculation of px,py,fx,fy. */ + if (pois < 10) { /* use factorials from table fact[] */ + px = -mu; + py = pow(mu, pois) / fact[(int)pois]; + } + else { + /* Case pois >= 10 uses polynomial approximation + a0-a7 for accuracy when advisable */ + del = one_12 / fk; + del = del * (1. - 4.8 * del * del); + v = difmuk / fk; + if (fabs(v) <= 0.25) + px = fk * v * v * (((((((a7 * v + a6) * v + a5) * v + a4) * + v + a3) * v + a2) * v + a1) * v + a0) + - del; + else /* |v| > 1/4 */ + px = fk * log(1. + v) - difmuk - del; + py = M_1_SQRT_2PI / sqrt(fk); + } + x = (0.5 - difmuk) / s; + x *= x;/* x^2 */ + fx = -0.5 * x; + fy = omega * (((c3 * x + c2) * x + c1) * x + c0); + if (kflag > 0) { + /* Step H. Hat acceptance (E is repeated on rejection) */ + if (c * fabs(u) <= py * exp(px + E) - fy * exp(fx + E)) + break; + } else + /* Step Q. Quotient acceptance (rare case) */ + if (fy - u * fy <= py * exp(px - fx)) + break; + }/* t > -.67.. */ + } + return((phydbl)pois); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* DENSITIES / PROBA */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Dnorm_Moments(phydbl x, phydbl mean, phydbl var) +{ + phydbl dens,sd,pi; + + pi = 3.141593; + sd = SQRT(var); + + dens = 1./(SQRT(2*pi)*sd)*exp(-((x-mean)*(x-mean)/(2.*sd*sd))); + + return dens; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Dnorm(phydbl x, phydbl mean, phydbl sd) +{ + phydbl dens; + + /* dens = -(.5*LOG2PI+log(sd)) - .5*POW(x-mean,2)/POW(sd,2); */ + /* return exp(dens); */ + + x = (x-mean)/sd; + + dens = M_1_SQRT_2_PI * exp(-0.5*x*x); + + return dens / sd; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Log_Dnorm(phydbl x, phydbl mean, phydbl sd, int *err) +{ + phydbl dens; + + *err = NO; + + x = (x-mean)/sd; + + dens = -(phydbl)log(SQRT(2.*PI)) - x*x*0.5 - log(sd); + + if(dens < -BIG) + { + PhyML_Printf("\n. dens=%f -- x=%f mean=%f sd=%f\n",dens,x,mean,sd); + *err = 1; + } + + return dens; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl Log_Dnorm_Trunc(phydbl x, phydbl mean, phydbl sd, phydbl lo, phydbl up, int *err) +{ + phydbl log_dens; + phydbl cdf_up, cdf_lo; + + if(x < lo || x > up) return -230.; + + *err = NO; + cdf_lo = cdf_up = 0.0; + + log_dens = Log_Dnorm(x,mean,sd,err); + + if(*err == YES) + { + PhyML_Printf("\n== mean=%f sd=%f lo=%f up=%f cdf_lo=%G CDF_up=%G log_dens=%G",mean,sd,lo,up,cdf_lo,cdf_up,log_dens); + PhyML_Printf("\n== Warning in file %s at line %d\n",__FILE__,__LINE__); + *err = YES; + } + + cdf_up = Pnorm(up,mean,sd); + cdf_lo = Pnorm(lo,mean,sd); + + if(cdf_up - cdf_lo < 1.E-20) + { + log_dens = -230.; /* ~log(1.E-100) */ + } + else + { + log_dens -= log(cdf_up - cdf_lo); + } + + if(isnan(log_dens) || isinf(fabs(log_dens))) + { + PhyML_Printf("\n. x=%f mean=%f sd=%f lo=%f up=%f cdf_lo=%G CDF_up=%G log_dens=%G",x,mean,sd,lo,up,cdf_lo,cdf_up,log_dens); + PhyML_Printf("\n. Warning in file %s at line %d\n",__FILE__,__LINE__); + *err = YES; + } + + return log_dens; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Dnorm_Trunc(phydbl x, phydbl mean, phydbl sd, phydbl lo, phydbl up) +{ + phydbl dens; + phydbl cdf_up, cdf_lo; + + dens = Dnorm(x,mean,sd); + cdf_up = Pnorm(up,mean,sd); + cdf_lo = Pnorm(lo,mean,sd); + + dens /= (cdf_up - cdf_lo); + + if(isnan(dens) || isinf(fabs(dens))) + { + PhyML_Printf("\n== mean=%f sd=%f lo=%f up=%f cdf_lo=%G CDF_up=%G",mean,sd,lo,up,cdf_lo,cdf_up); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + return dens; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Dnorm_Multi(phydbl *x, phydbl *mu, phydbl *cov, int size, int _log) +{ + phydbl *xmmu,*invcov; + phydbl *buff1,*buff2; + int i; + phydbl det,density; + + xmmu = (phydbl *)mCalloc(size,sizeof(phydbl)); + invcov = (phydbl *)mCalloc(size*size,sizeof(phydbl)); + + for(i=0;i INFINITY) + { + PhyML_Printf("\n. WARNING: huge value of x -> x = %G",x); + x = 1.E+10; + } + + if(x < 1.E-200) + { + if(x < 0.0) return 0.0; + else + { + PhyML_Printf("\n. WARNING: Dgamma -> small value of x = %G (shape: %G scale: %G : %G)",x,shape,scale,shape*scale); + x = 1.E-200; + } + } + + + if(scale < 0.0 || shape < 0.0) + { + PhyML_Printf("\n. scale=%f shape=%f",scale,shape); + Exit("\n"); + } + + + v = (shape-1.) * log(x) - shape * log(scale) - x / scale - LnGamma(shape); + + + if(v < 500.) + { + v = exp(v); + } + else + { + PhyML_Printf("\n. WARNING v=%f x=%f shape=%f scale=%f",v,x,shape,scale); + PhyML_Printf("\n. log(x) = %G LnGamma(shape)=%G",log(x),LnGamma(shape)); + v = exp(v); + /* PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); */ + /* Exit("\n"); */ + } + + + return v; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl Dexp(phydbl x, phydbl param) +{ + return param * exp(-param * x); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Returns the density of an exponential distribution left-truncated */ +/* at 'left' and right-truncated at 'rght' */ + +phydbl Dexp_Trunc(phydbl x, phydbl lambda, phydbl left, phydbl rght) +{ + return (lambda * exp(-lambda * x))/(exp(-lambda * left) - exp(-lambda * rght)); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Poisson probability */ +phydbl Dpois(phydbl x, phydbl param, int logit) +{ + phydbl v; + + if(param < SMALL) + { + if(x < SMALL) + { + if(logit) return 0.0; + else return 1.0; + } + else + { + if(logit) return -INFINITY; + else return 0.0; + } + } + + if(x < .0) + { + if(logit == YES) return(-INFINITY); + else return 0.0; + } + + v = x * log(param) - param - Factln(x); + if(logit == YES) return v; + else + { + if(v < 500.) + { + v = exp(v); + } + else + { + PhyML_Printf("\n. WARNING v=%f x=%f param=%f",v,x,param); + v = exp(500); + } + return v; + } + return(-1.0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* CDFs */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Error function +phydbl Erf(phydbl x) +{ + return(2.*Pnorm(x*sqrt(2.),0.0,1.0)-1.); +} + +phydbl Pnorm(phydbl x, phydbl mean, phydbl sd) +{ +/* const phydbl b1 = 0.319381530; */ +/* const phydbl b2 = -0.356563782; */ +/* const phydbl b3 = 1.781477937; */ +/* const phydbl b4 = -1.821255978; */ +/* const phydbl b5 = 1.330274429; */ +/* const phydbl p = 0.2316419; */ +/* const phydbl c = 0.39894228; */ + + x = (x-mean)/sd; + +/* if(x >= 0.0) */ +/* { */ +/* phydbl t = 1.0 / ( 1.0 + p * x ); */ +/* return (1.0 - c * exp( -x * x / 2.0 ) * t * */ +/* ( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )); */ +/* } */ +/* else */ +/* { */ +/* phydbl t = 1.0 / ( 1.0 - p * x ); */ +/* return ( c * exp( -x * x / 2.0 ) * t * */ +/* ( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )); */ +/* } */ + +/* i_tail in {0,1,2} means: "lower", "upper", or "both" : + if(lower) return *cum := P[X <= x] + if(upper) return *ccum := P[X > x] = 1 - P[X <= x] +*/ + +/* return Pnorm_Marsaglia(x); */ + return Pnorm_Ihaka_Derived_From_Cody(x); +} + + +/* G. Marsaglia. "Evaluating the Normal distribution". Journal of Statistical Software. 2004. Vol. 11. Issue 4. */ +phydbl Pnorm_Marsaglia(phydbl x) +{ + long double s=x,t=0,b=x,q=x*x,i=1; + while(s!=t) s=(t=s)+(b*=q/(i+=2)); + return .5+s*exp(-.5*q-.91893853320467274178L); + +} + + + +/* Stolen from R source code */ +#define SIXTEN 16 + +phydbl Pnorm_Ihaka_Derived_From_Cody(phydbl x) +{ + + const static double a[5] = { + 2.2352520354606839287, + 161.02823106855587881, + 1067.6894854603709582, + 18154.981253343561249, + 0.065682337918207449113 + }; + const static double b[4] = { + 47.20258190468824187, + 976.09855173777669322, + 10260.932208618978205, + 45507.789335026729956 + }; + const static double c[9] = { + 0.39894151208813466764, + 8.8831497943883759412, + 93.506656132177855979, + 597.27027639480026226, + 2494.5375852903726711, + 6848.1904505362823326, + 11602.651437647350124, + 9842.7148383839780218, + 1.0765576773720192317e-8 + }; + const static double d[8] = { + 22.266688044328115691, + 235.38790178262499861, + 1519.377599407554805, + 6485.558298266760755, + 18615.571640885098091, + 34900.952721145977266, + 38912.003286093271411, + 19685.429676859990727 + }; + const static double p[6] = { + 0.21589853405795699, + 0.1274011611602473639, + 0.022235277870649807, + 0.001421619193227893466, + 2.9112874951168792e-5, + 0.02307344176494017303 + }; + const static double q[5] = { + 1.28426009614491121, + 0.468238212480865118, + 0.0659881378689285515, + 0.00378239633202758244, + 7.29751555083966205e-5 + }; + + double xden, xnum, temp, del, eps, xsq, y; + int i, lower, upper; + double cum,ccum; + int i_tail; + + i_tail = 0; + cum = ccum = 0.0; + + if(isnan(x)) { cum = ccum = x; return (phydbl)cum; } + + /* Consider changing these : */ + eps = DBL_EPSILON * 0.5; + + /* i_tail in {0,1,2} =^= {lower, upper, both} */ + lower = i_tail != 1; + upper = i_tail != 0; + + y = fabs(x); + if (y <= 0.67448975) { /* qnorm(3/4) = .6744.... -- earlier had 0.66291 */ + if (y > eps) { + xsq = x * x; + xnum = a[4] * xsq; + xden = xsq; + for (i = 0; i < 3; ++i) { + xnum = (xnum + a[i]) * xsq; + xden = (xden + b[i]) * xsq; + } + } else xnum = xden = 0.0; + + temp = x * (xnum + a[3]) / (xden + b[3]); + if(lower) cum = 0.5 + temp; + if(upper) ccum = 0.5 - temp; + } + else if (y <= M_SQRT_32) { + + /* Evaluate pnorm for 0.674.. = qnorm(3/4) < |x| <= SQRT(32) ~= 5.657 */ + + xnum = c[8] * y; + xden = y; + for (i = 0; i < 7; ++i) { + xnum = (xnum + c[i]) * y; + xden = (xden + d[i]) * y; + } + temp = (xnum + c[7]) / (xden + d[7]); + +#define do_del(X) \ + xsq = floor(X * SIXTEN) / SIXTEN; \ + del = (X - xsq) * (X + xsq); \ + cum = exp(-xsq * xsq * 0.5) * exp(-del * 0.5) * temp; \ + ccum = 1.0 - cum; \ + +#define swap_tail \ + if (x > 0.) {/* swap ccum <--> cum */ \ + temp = cum; if(lower) cum = ccum; ccum = temp; \ + } + + do_del(y); + swap_tail; + } + +/* else |x| > SQRT(32) = 5.657 : + * the next two case differentiations were really for lower=T, log=F + * Particularly *not* for log_p ! + + * Cody had (-37.5193 < x && x < 8.2924) ; R originally had y < 50 + * + * Note that we do want symmetry(0), lower/upper -> hence use y + */ + else if((lower && -37.5193 < x && x < 8.2924) || (upper && -8.2924 < x && x < 37.5193)) + { + /* Evaluate pnorm for x in (-37.5, -5.657) union (5.657, 37.5) */ + xsq = 1.0 / (x * x); + xnum = p[5] * xsq; + xden = xsq; + for (i = 0; i < 4; ++i) { + xnum = (xnum + p[i]) * xsq; + xden = (xden + q[i]) * xsq; + } + temp = xsq * (xnum + p[4]) / (xden + q[4]); + temp = (M_1_SQRT_2_PI - temp) / y; + + do_del(x); + swap_tail; + } + else + { /* no log_p , large x such that probs are 0 or 1 */ + if(x > 0) { cum = 1.; ccum = 0.; } + else { cum = 0.; ccum = 1.; } + } + + return (phydbl)cum; + + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Pgamma(phydbl x, phydbl shape, phydbl scale) +{ + return IncompleteGamma(x/scale,shape,LnGamma(shape)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Ppois(phydbl x, phydbl param) +{ + /* Press et al. (1990) approximation of the CDF for the Poisson distribution */ + if(param < SMALL || x < 0.0) + { + PhyML_Printf("\n== param = %G x=%G",param,x); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + return IncompleteGamma(x,param,LnGamma(param)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Inverse CDFs */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl PointChi2 (phydbl prob, phydbl v) +{ +/* returns z so that Prob{x.999998 || v<=0) return ((phydbl)-1); + + g = (double)LnGamma(v/2); + xx=v/2; c=xx-1; + if (v >= -1.24*log(p)) goto l1; + + ch=pow((p*xx*exp(g+xx*aa)), 1/xx); + if (ch-e<0) return (ch); + goto l4; +l1: + if (v>.32) goto l3; + ch=0.4; a=log(1-p); +l2: + q=ch; p1=1+ch*(4.67+ch); p2=ch*(6.73+ch*(6.66+ch)); + t=-0.5+(4.67+2*ch)/p1 - (6.73+ch*(13.32+3*ch))/p2; + ch-=(1-exp(a+g+.5*ch+c*aa)*p2/p1)/t; + if (fabs(q/ch-1)-.01 <= 0) goto l4; + else goto l2; + +l3: + x=(double)PointNormal (p); + p1=0.222222/v; ch=v*pow((x*sqrt(p1)+1-p1), 3.0); + if (ch>2.2*v+6) ch=-2*(log(1-p)-c*log(.5*ch)+g); +l4: + q=ch; p1=.5*ch; + if ((t=(double)IncompleteGamma (p1, xx, g))<0) { + PhyML_Printf ("\nerr IncompleteGamma"); + return ((phydbl)-1.); + } + p2=p-t; + t=p2*exp(xx*aa+g+p1-c*log(ch)); + b=t/ch; a=0.5*t-b*c; + + s1=(210+a*(140+a*(105+a*(84+a*(70+60*a))))) / 420; + s2=(420+a*(735+a*(966+a*(1141+1278*a))))/2520; + s3=(210+a*(462+a*(707+932*a)))/2520; + s4=(252+a*(672+1182*a)+c*(294+a*(889+1740*a)))/5040; + s5=(84+264*a+c*(175+606*a))/2520; + s6=(120+c*(346+127*c))/5040; + ch+=t*(1+0.5*t*s1-b*c*(s1-b*(s2-b*(s3-b*(s4-b*(s5-b*s6)))))); + if (fabs(q/ch-1) > e) goto l4; + + return (phydbl)(ch); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + + +/* + The following function was extracted from the source code of R. + It implements the methods referenced below. + * REFERENCE + * + * Beasley, J. D. and S. G. Springer (1977). + * Algorithm AS 111: The percentage points of the normal distribution, + * Applied Statistics, 26, 118-121. + * + * Wichura, M.J. (1988). + * Algorithm AS 241: The Percentage Points of the Normal Distribution. + * Applied Statistics, 37, 477-484. + */ + + +phydbl PointNormal (phydbl prob) +{ +/* returns z so that Prob{x 0) */ +/* r = 1-p;/\* 1-p *\/ */ +/* else */ +/* r = p_;/\* = R_DT_Iv(p) ^= p *\/ */ + +/* r = sqrt(-log(r)); */ +/* /\* r = sqrt(-log(r)) <==> min(p, 1-p) = exp( - r^2 ) *\/ */ + +/* if (r <= 5.) { /\* <==> min(p,1-p) >= exp(-25) ~= 1.3888e-11 *\/ */ +/* r += -1.6; */ +/* val = (((((((r * 7.7454501427834140764e-4 + */ +/* .0227238449892691845833) * r + .24178072517745061177) * */ +/* r + 1.27045825245236838258) * r + */ +/* 3.64784832476320460504) * r + 5.7694972214606914055) * */ +/* r + 4.6303378461565452959) * r + */ +/* 1.42343711074968357734) */ +/* / (((((((r * */ +/* 1.05075007164441684324e-9 + 5.475938084995344946e-4) * */ +/* r + .0151986665636164571966) * r + */ +/* .14810397642748007459) * r + .68976733498510000455) * */ +/* r + 1.6763848301838038494) * r + */ +/* 2.05319162663775882187) * r + 1.); */ +/* } */ +/* else */ +/* { /\* very close to 0 or 1 *\/ */ +/* r += -5.; */ +/* val = (((((((r * 2.01033439929228813265e-7 + */ +/* 2.71155556874348757815e-5) * r + */ +/* .0012426609473880784386) * r + .026532189526576123093) * */ +/* r + .29656057182850489123) * r + */ +/* 1.7848265399172913358) * r + 5.4637849111641143699) * */ +/* r + 6.6579046435011037772) */ +/* / (((((((r * */ +/* 2.04426310338993978564e-15 + 1.4215117583164458887e-7)* */ +/* r + 1.8463183175100546818e-5) * r + */ +/* 7.868691311456132591e-4) * r + .0148753612908506148525) */ +/* * r + .13692988092273580531) * r + */ +/* .59983220655588793769) * r + 1.); */ +/* } */ + +/* if(q < 0.0) */ +/* val = -val; */ +/* /\* return (q >= 0.)? r : -r ;*\/ */ +/* } */ +/* return (phydbl)val; */ +/* } */ + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* MISCs */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Bico(int n, int k) +{ + return FLOOR(0.5+exp(Factln(n)-Factln(k)-Factln(n-k))); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Factln(int n) +{ + /* static phydbl a[101]; */ + + /* if (n < 0) { Warn_And_Exit("\n== Err: negative factorial in routine FACTLN"); } */ + /* if (n <= 1) return 0.0; */ + /* if (n <= 100) return (a[n]>SMALL) ? a[n] : (a[n]=Gammln(n+1.0)); */ + /* else return Gammln(n+1.0); */ + return Gammln(n+1.0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Gammln(phydbl xx) +{ + double x,tmp,ser; + static double cof[6]={76.18009173,-86.50532033,24.01409822, + -1.231739516,0.120858003e-2,-0.536382e-5}; + int j; + + x=xx-1.0; + tmp=x+5.5; + tmp -= (x+0.5)*log(tmp); + ser=1.0; + for (j=0;j<=5;j++) + { + x += 1.0; + ser += cof[j]/x; + } + return (phydbl)(-tmp+log(2.50662827465*ser)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/* void Plim_Binom(phydbl pH0, int N, phydbl *pinf, phydbl *psup) */ +/* { */ +/* *pinf = pH0 - 1.64*SQRT(pH0*(1-pH0)/(phydbl)N); */ +/* if(*pinf < 0) *pinf = .0; */ +/* *psup = pH0 + 1.64*SQRT(pH0*(1-pH0)/(phydbl)N); */ +/* } */ + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl LnGamma (phydbl alpha) +{ +/* returns ln(gamma(alpha)) for alpha>0, accurate to 10 decimal places. + Stirling's formula is used for the central polynomial part of the procedure. + Pike MC & Hill ID (1966) Algorithm 291: Logarithm of the gamma function. + Communications of the Association for Computing Machinery, 9:684 +*/ + double x=alpha, f=0, z; + if (x<7) { + f=1; z=x-1; + while (++z<7) f*=z; + x=z; f=-log(f); + } + z = 1/(x*x); + return (phydbl)(f + (x-0.5)*log(x) - x + .918938533204673 + + (((-.000595238095238*z+.000793650793651)*z-.002777777777778)*z + +.083333333333333)/x); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl IncompleteGamma(phydbl x, phydbl alpha, phydbl ln_gamma_alpha) +{ +/* returns the incomplete gamma ratio I(x,alpha) where x is the upper + limit of the integration and alpha is the shape parameter. + returns (-1) if in error + ln_gamma_alpha = ln(Gamma(alpha)), is almost redundant. + (1) series expansion if (alpha>x || x<=1) + (2) continued fraction otherwise + RATNEST FORTRAN by + Bhattacharjee GP (1970) The incomplete gamma integral. Applied Statistics, + 19: 285-287 (AS32) +*/ + int i; + double p=alpha, g=ln_gamma_alpha; + double accurate=1e-8, overflow=1e30; + double factor, gin=0, rn=0, a=0,b=0,an=0,dif=0, term=0, pn[6]; + + if (fabs(x) < SMALL) return ((phydbl).0); + if (x<0 || p<=0) return ((phydbl)-1); + + factor=exp(p*log(x)-x-g); + if (x>1 && x>=p) goto l30; + /* (1) series expansion */ + gin=1; term=1; rn=p; + l20: + rn++; + term*=x/rn; gin+=term; + + if (term > accurate) goto l20; + gin*=factor/p; + goto l50; + l30: + /* (2) continued fraction */ + a=1-p; b=a+x+1; term=0; + pn[0]=1; pn[1]=x; pn[2]=x+1; pn[3]=x*b; + gin=pn[2]/pn[3]; + l32: + a++; b+=2; term++; an=a*term; + for (i=0; i<2; i++) pn[i+4]=b*pn[i+2]-an*pn[i]; + if (fabs(pn[5]) < .0) goto l35; + rn=pn[4]/pn[5]; dif=fabs(gin-rn); + if (dif>accurate) goto l34; + if (dif<=accurate*rn) goto l42; + l34: + gin=rn; + l35: + for (i=0; i<4; i++) pn[i]=pn[i+2]; + if (fabs(pn[4]) < overflow) goto l32; + for (i=0; i<4; i++) pn[i]/=overflow; + goto l32; + l42: + gin=1-factor*gin; + + l50: + return (phydbl)(gin); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int DiscreteGamma (phydbl freqK[], phydbl rK[], + phydbl alfa, phydbl beta, int K, int median) +{ + /* discretization of gamma distribution with equal proportions in each + category + */ + + int i; + phydbl gap05=1.0/(2.0*K), t, factor=alfa/beta*K, lnga1; + + if(K==1) + { + freqK[0] = 1.0; + rK[0] = 1.0; + return 0; + } + + if (median) + { + for (i=0; i n) return(0); + if (k > n/2) k = n-k; + if(!k) return(1); + + accum = 1.; + for(i=1;in_otu-3; + + cov = (phydbl *)mCalloc(dim*dim,sizeof(phydbl)); + mean = (phydbl *)mCalloc( dim,sizeof(phydbl)); + ori_wght = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); + site_num = (int *)mCalloc(tree->data->init_len,sizeof(int)); + + for(i=0;idata->crunch_len;i++) ori_wght[i] = tree->data->wght[i]; + + n_site = 0; + for(i=0;idata->crunch_len;i++) For(j,tree->data->wght[i]) + { + site_num[n_site] = i; + n_site++; + } + + + tree->verbose = VL0; + for(replicate=0;replicaten_otu-3) tree->a_edges[i]->l->v = .1; + + for(i=0;idata->crunch_len;i++) tree->data->wght[i] = 0; + + for(i=0;idata->init_len;i++) + { + position = Rand_Int(0,(int)(tree->data->init_len-1.0)); + tree->data->wght[site_num[position]] += 1; + } + + Round_Optimize(tree,ROUND_MAX); + + For(i,2*tree->n_otu-3) For(j,2*tree->n_otu-3) cov[i*dim+j] += log(tree->a_edges[i]->l->v) * log(tree->a_edges[j]->l->v); + For(i,2*tree->n_otu-3) mean[i] += log(tree->a_edges[i]->l->v); + + PhyML_Printf("[%3d/%3d]",replicate,sample_size); fflush(NULL); +/* PhyML_Printf("\n. %3d %12f %12f %12f ", */ +/* replicate, */ +/* cov[1*dim+1]/(replicate+1)-mean[1]*mean[1]/POW(replicate+1,2), */ +/* tree->a_edges[1]->l->v, */ +/* mean[1]/(replicate+1)); */ + } + + For(i,2*tree->n_otu-3) mean[i] /= (phydbl)sample_size; + For(i,2*tree->n_otu-3) For(j,2*tree->n_otu-3) cov[i*dim+j] /= (phydbl)sample_size; + For(i,2*tree->n_otu-3) For(j,2*tree->n_otu-3) cov[i*dim+j] -= mean[i]*mean[j]; +/* For(i,2*tree->n_otu-3) if(cov[i*dim+i] < var_min) cov[i*dim+i] = var_min; */ + + +/* PhyML_Printf("\n"); */ +/* For(i,2*tree->n_otu-3) PhyML_Printf("%f %f\n",mean[i],tree->a_edges[i]->l->v); */ +/* PhyML_Printf("\n"); */ +/* PhyML_Printf("\n"); */ +/* For(i,2*tree->n_otu-3) */ +/* { */ +/* For(j,2*tree->n_otu-3) */ +/* { */ +/* PhyML_Printf("%G\n",cov[i*dim+j]); */ +/* } */ +/* PhyML_Printf("\n"); */ +/* } */ + + for(i=0;idata->crunch_len;i++) tree->data->wght[i] = ori_wght[i]; + + Free(mean); + Free(ori_wght); + Free(site_num); + + return cov; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Work out the Hessian for the likelihood function. Only branch lengths are considered as variable. + This function is very much inspired from Jeff Thorne's 'hessian' function in his program 'estbranches'. */ +phydbl *Hessian(t_tree *tree) +{ + phydbl *hessian; + phydbl *plus_plus, *minus_minus, *plus_zero, *minus_zero, *plus_minus, zero_zero; + phydbl *ori_bl,*inc,*buff; + int *ok_edges,*is_ok; + int dim; + int n_ok_edges; + int i,j; + phydbl eps; + phydbl lk; + phydbl lnL,lnL1,lnL2,ori_lnL; + phydbl l_inf; + + dim = 2*tree->n_otu-3; + eps = (tree->mod->log_l == YES)?(0.2):(1E-4); + + hessian = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + ori_bl = (phydbl *)mCalloc((int)dim,sizeof(phydbl)); + plus_plus = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + minus_minus = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + plus_minus = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + plus_zero = (phydbl *)mCalloc((int)dim ,sizeof(phydbl)); + minus_zero = (phydbl *)mCalloc((int)dim ,sizeof(phydbl)); + inc = (phydbl *)mCalloc((int)dim ,sizeof(phydbl)); + buff = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + ok_edges = (int *)mCalloc((int)dim,sizeof(int)); + is_ok = (int *)mCalloc((int)dim,sizeof(int)); + + lnL = lnL1 = lnL2 = UNLIKELY; + + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + ori_lnL = tree->c_lnL; + + + for(i=0;ia_edges[i]->l->v; + + if(tree->mod->log_l == NO) + l_inf = MAX(tree->mod->l_min,1./(phydbl)tree->data->init_len); + else + l_inf = MAX(tree->mod->l_min,-log((phydbl)tree->data->init_len)); + + + n_ok_edges = 0; + for(i=0;ia_edges[i]->l->v*(1.-eps) > l_inf) + { + inc[i] = eps * tree->a_edges[i]->l->v; + ok_edges[n_ok_edges] = i; + n_ok_edges++; + is_ok[i] = 1; + } + else + { + inc[i] = -1.0; + is_ok[i] = 0; + } + } + + + /* Fine tune the increments */ + for(i=0;ia_edges[i]->l->v += inc[i]; + lnL1 = Lk(tree->a_edges[i],tree); + tree->a_edges[i]->l->v = ori_bl[i]; + inc[i] *= 1.1; + }while((fabs(lnL1 - ori_lnL) < 1.E-1) && + (tree->a_edges[i]->l->v+inc[i] < tree->mod->l_max)); + inc[i] /= 1.1; + } + + + + /* zero zero */ + zero_zero = tree->c_lnL; + + /* plus zero */ + for(i=0;ia_edges[i]->l->v += inc[i]; + lk = Lk(tree->a_edges[i],tree); + plus_zero[i] = lk; + tree->a_edges[i]->l->v = ori_bl[i]; + } + } + + + /* minus zero */ + for(i=0;ia_edges[i]->l->v -= inc[i]; + lk = Lk(tree->a_edges[i],tree); + minus_zero[i] = lk; + tree->a_edges[i]->l->v = ori_bl[i]; + } + } + + + for(i=0;ia_edges[i],tree); + + /* plus plus */ + for(i=0;ia_edges[i]->l->v += inc[i]; + Update_PMat_At_Given_Edge(tree->a_edges[i],tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->left->tax) && (tree->a_edges[i]->left->v[j] != tree->a_edges[i]->rght)) + Recurr_Hessian(tree->a_edges[i]->left,tree->a_edges[i]->left->v[j],1,inc,plus_plus+i*dim,is_ok,tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->rght->tax) && (tree->a_edges[i]->rght->v[j] != tree->a_edges[i]->left)) + Recurr_Hessian(tree->a_edges[i]->rght,tree->a_edges[i]->rght->v[j],1,inc,plus_plus+i*dim,is_ok,tree); + + tree->a_edges[i]->l->v = ori_bl[i]; + Lk(NULL,tree); + } + } + + + /* plus minus */ + for(i=0;ia_edges[i]->l->v += inc[i]; + Update_PMat_At_Given_Edge(tree->a_edges[i],tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->left->tax) && (tree->a_edges[i]->left->v[j] != tree->a_edges[i]->rght)) + Recurr_Hessian(tree->a_edges[i]->left,tree->a_edges[i]->left->v[j],-1,inc,plus_minus+i*dim,is_ok,tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->rght->tax) && (tree->a_edges[i]->rght->v[j] != tree->a_edges[i]->left)) + Recurr_Hessian(tree->a_edges[i]->rght,tree->a_edges[i]->rght->v[j],-1,inc,plus_minus+i*dim,is_ok,tree); + + tree->a_edges[i]->l->v = ori_bl[i]; + Lk(NULL,tree); + } + } + + + /* minus minus */ + for(i=0;ia_edges[i]->l->v -= inc[i]; + + Update_PMat_At_Given_Edge(tree->a_edges[i],tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->left->tax) && (tree->a_edges[i]->left->v[j] != tree->a_edges[i]->rght)) + Recurr_Hessian(tree->a_edges[i]->left,tree->a_edges[i]->left->v[j],-1,inc,minus_minus+i*dim,is_ok,tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->rght->tax) && (tree->a_edges[i]->rght->v[j] != tree->a_edges[i]->left)) + Recurr_Hessian(tree->a_edges[i]->rght,tree->a_edges[i]->rght->v[j],-1,inc,minus_minus+i*dim,is_ok,tree); + + tree->a_edges[i]->l->v = ori_bl[i]; + Lk(NULL,tree); + } + } + + + + for(i=0;idata->init_len; */ + /* Approximate variance for very short branches */ + for(i=0;ia_edges[i]->l->v; + do + { + lnL = Lk(tree->a_edges[i],tree); + tree->a_edges[i]->l->v += eps; + lnL1 = Lk(tree->a_edges[i],tree); + tree->a_edges[i]->l->v += eps; + lnL2 = Lk(tree->a_edges[i],tree); + tree->a_edges[i]->l->v -= 2.*eps; + + hessian[i*dim+i] = (lnL2 - 2.*lnL1 + lnL) / POW(eps,2); + +/* printf("\n* l=%G eps=%f lnL=%f lnL1=%f lnL2=%f var=%f",tree->a_edges[i]->l->v,eps,lnL,lnL1,lnL2,hessian[i*dim+i]); */ + eps *= 5.; + }while(fabs(lnL2 - lnL) < 1.E-3); + + hessian[i*dim+i] = -1.0 / hessian[i*dim+i]; + + } + + + /* Fit a straight line to the log-likelihood (i.e., an exponential to the likelihood) */ + /* It is only a straight line when considering branch length (rather than log(branch lengths)) */ + for(i=0;ia_edges[i]->l->v / tree->mod->l_min < 1.1) && + (tree->a_edges[i]->l->v / tree->mod->l_min > 0.9)) + { + phydbl *x,*y,l; + phydbl cov,var; + + x=plus_plus; + y=minus_minus; + l=(tree->mod->log_l == YES)?(exp(tree->a_edges[i]->l->v)):(tree->a_edges[i]->l->v); /* Get actual branch length */ + + for(j=0;ja_edges[i]->l->v = (tree->mod->log_l)?(log(x[j])):(x[j]); /* Transform to log if necessary */ + y[j] = Lk(tree->a_edges[i],tree); + tree->a_edges[i]->l->v = (tree->mod->log_l)?(log(l)):(l); /* Go back to initial edge length */ + } + + cov = Covariance(x,y,dim); + var = Covariance(x,x,dim); + + /* cov/var is minus the parameter of the exponential distribution. + The variance is therefore : */ + hessian[i*dim+i] = 1.0 / pow(cov/var,2); + + /* printf("\n. Hessian = %G cov=%G var=%G",hessian[i*dim+i],cov,var); */ + } + /* } */ + + + for(i=0;ia_edges[i]->l->v,hessian[i*dim+i]); +/* PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); */ +/* Exit("\n"); */ + hessian[i*dim+i] = MIN_VAR_BL; + } + + for(i=0;ia_edges[i]->l->v,hessian[i*dim+i]); + hessian[i*dim+i] = MIN_VAR_BL; + } + if(hessian[i*dim+i] > MAX_VAR_BL) + { + PhyML_Printf("\n. l=%10G var(l)=%12G. WARNING: numerical precision issues may affect this analysis.", + tree->a_edges[i]->l->v,hessian[i*dim+i]); + hessian[i*dim+i] = MAX_VAR_BL; + } + } + + Iter_Matinv(hessian,dim,dim,NO); + + For(i,dim*dim) hessian[i] = -1.0*hessian[i]; + + for(i=0;i 1.E-3) + { + PhyML_Printf("\n. Hessian not symmetrical."); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + hessian[i*dim+j] = (hessian[i*dim+j] + hessian[j*dim+i]) / 2.; + hessian[j*dim+i] = hessian[i*dim+j]; + } + } + +/* printf("\n"); */ +/* printf("HESSIAN\n"); */ +/* for(i=0;ia_edges[i]->l->v); */ +/* for(j=0;ja_edges[i]->l->v); */ + /* for(j=0;jn_otu-3; + eps = (tree->mod->log_l == YES)?(0.2):(1.E-6); + + gradient = (phydbl *)mCalloc((int)dim,sizeof(phydbl)); + ori_bl = (phydbl *)mCalloc((int)dim,sizeof(phydbl)); + plus = (phydbl *)mCalloc((int)dim,sizeof(phydbl)); + minus = (phydbl *)mCalloc((int)dim,sizeof(phydbl)); + inc = (phydbl *)mCalloc((int)dim ,sizeof(phydbl)); + is_ok = (int *)mCalloc((int)dim,sizeof(int)); + + lnL = lnL1 = lnL2 = UNLIKELY; + + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + + for(i=0;ia_edges[i]->l->v; + + if(tree->mod->log_l == NO) + l_inf = MAX(tree->mod->l_min,1./(phydbl)tree->data->init_len); + else + l_inf = MAX(tree->mod->l_min,-log((phydbl)tree->data->init_len)); + + for(i=0;ia_edges[i]->l->v*(1.-eps) > l_inf) + { + inc[i] = eps * tree->a_edges[i]->l->v; + is_ok[i] = YES; + } + else + { + inc[i] = -1.0; + is_ok[i] = NO; + } + } + + /* plus */ + for(i=0;ia_edges[i]->l->v += inc[i]; + lk = Lk(tree->a_edges[i],tree); + plus[i] = lk; + tree->a_edges[i]->l->v = ori_bl[i]; + } + } + + + /* minus */ + for(i=0;ia_edges[i]->l->v -= inc[i]; + lk = Lk(tree->a_edges[i],tree); + minus[i] = lk; + tree->a_edges[i]->l->v = ori_bl[i]; + } + } + + + for(i=0;ia_edges[i]->l->v); + lnL = Lk(tree->a_edges[i],tree); + tree->a_edges[i]->l->v += eps; + lnL1 = Lk(tree->a_edges[i],tree); + tree->a_edges[i]->l->v += eps; + lnL2 = Lk(tree->a_edges[i],tree); + tree->a_edges[i]->l->v -= eps; + tree->a_edges[i]->l->v -= eps; + gradient[i] = (4.*lnL1 - lnL2 - 3.*lnL) / (2.*eps); + } + } + + /* Make sure to update likelihood before bailing out */ + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + + Free(ori_bl); + Free(plus); + Free(minus); + Free(inc); + Free(is_ok); + + +/* printf("\n"); */ +/* printf("GRADIENT\n"); */ +/* for(i=0;ia_edges[i]->l->v); */ +/* for(j=0;ja_edges[i]->l->v,gradient[i]); */ +/* } */ + +/* Exit("\n"); */ + + return gradient; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/* Work out the Hessian for the likelihood function using the method described by Seo et al., 2004, MBE. + Corresponds to the outer product of the scores approach described in Porter, 2002. (matrix J1) +*/ +phydbl *Hessian_Seo(t_tree *tree) +{ + phydbl *hessian,*site_hessian; + phydbl *gradient; + phydbl *plus, *minus, *plusplus, *zero; + phydbl *ori_bl,*inc_plus,*inc_minus,*inc; + int *is_ok; + int dim; + int i,j,k; + phydbl eps; + phydbl ori_lnL,lnL1,lnL2; + phydbl l_inf; + int l,n; + phydbl small_var; + + dim = 2*tree->n_otu-3; + eps = (tree->mod->log_l == YES)?(0.2):(1.E-4); + + hessian = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + site_hessian = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + gradient = (phydbl *)mCalloc((int)dim,sizeof(phydbl)); + ori_bl = (phydbl *)mCalloc((int)dim,sizeof(phydbl)); + plus = (phydbl *)mCalloc((int)dim*tree->n_pattern,sizeof(phydbl)); + plusplus = (phydbl *)mCalloc((int)dim*tree->n_pattern,sizeof(phydbl)); + minus = (phydbl *)mCalloc((int)dim*tree->n_pattern,sizeof(phydbl)); + zero = (phydbl *)mCalloc((int)dim*tree->n_pattern,sizeof(phydbl)); + inc_plus = (phydbl *)mCalloc((int)dim,sizeof(phydbl)); + inc_minus = (phydbl *)mCalloc((int)dim,sizeof(phydbl)); + inc = (phydbl *)mCalloc((int)dim,sizeof(phydbl)); + is_ok = (int *)mCalloc((int)dim,sizeof(int)); + + lnL1 = lnL2 = UNLIKELY; + + for(i=0;ia_edges[i]->l->v; + + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + ori_lnL = tree->c_lnL; + + + if(tree->mod->log_l == NO) + l_inf = MAX(tree->mod->l_min,1./(phydbl)tree->data->init_len); + else + l_inf = MAX(tree->mod->l_min,-log((phydbl)tree->data->init_len)); + + for(i=0;ia_edges[i]->l->v*(1.-eps) > l_inf) + { + inc_plus[i] = fabs(eps * MAX(tree->mod->l_min,tree->a_edges[i]->l->v)); + inc_minus[i] = fabs(eps * MAX(tree->mod->l_min,tree->a_edges[i]->l->v)); + is_ok[i] = YES; + } + else + { + inc_plus[i] = fabs(0.2 * MAX(tree->mod->l_min,tree->a_edges[i]->l->v)); + inc_minus[i] = fabs(0.2 * MAX(tree->mod->l_min,tree->a_edges[i]->l->v)); + is_ok[i] = NO; + } + + + } + + /* Fine tune the increments */ + for(i=0;ia_edges[i]->l->v += inc_plus[i]; + lnL1 = Lk(tree->a_edges[i],tree); + tree->a_edges[i]->l->v = ori_bl[i]; + inc_plus[i] *= 1.1; + }while((fabs(lnL1 - ori_lnL) < 1.E-1) && (tree->a_edges[i]->l->v+inc_plus[i] < tree->mod->l_max)); + inc_plus[i] /= 1.1; + } + + for(i=0;ia_edges[i]->l->v -= inc_minus[i]; + lnL1 = Lk(tree->a_edges[i],tree); + tree->a_edges[i]->l->v = ori_bl[i]; + inc_minus[i] *= 1.1; + }while((fabs(lnL1 - ori_lnL) < 1.E-1) && + (tree->a_edges[i]->l->v -inc_minus[i] > tree->mod->l_min)); + inc_minus[i] /= 1.1; + } + + for(i=0;ia_edges[i]->l->v += inc[i]; + Lk(tree->a_edges[i],tree); + for(j=0;jn_pattern;j++) plus[i*tree->n_pattern+j] = log(tree->cur_site_lk[j]); + tree->a_edges[i]->l->v = ori_bl[i]; + } + } + + + /* minus */ + for(i=0;ia_edges[i]->l->v -= inc[i]; + Lk(tree->a_edges[i],tree); + for(j=0;jn_pattern;j++) minus[i*tree->n_pattern+j] = log(tree->cur_site_lk[j]); + tree->a_edges[i]->l->v = ori_bl[i]; + } + } + + + for(i=0;ia_edges[i],tree); + for(j=0;jn_pattern;j++) zero[i*tree->n_pattern+j] = log(tree->cur_site_lk[j]); + + tree->a_edges[i]->l->v += inc[i]; + lnL1 = Lk(tree->a_edges[i],tree); + for(j=0;jn_pattern;j++) plus[i*tree->n_pattern+j] = log(tree->cur_site_lk[j]); + + tree->a_edges[i]->l->v += inc[i]; + lnL2 = Lk(tree->a_edges[i],tree); + for(j=0;jn_pattern;j++) plusplus[i*tree->n_pattern+j] = log(tree->cur_site_lk[j]); + + tree->a_edges[i]->l->v = ori_bl[i]; + + } + } + + For(i,dim*dim) hessian[i] = 0.0; + + for(k=0;kn_pattern;k++) + { + for(i=0;in_pattern+k] - minus[i*tree->n_pattern+k])/(inc[i] + inc[i]); + else + gradient[i] = (4.*plus[i*tree->n_pattern+k] - plusplus[i*tree->n_pattern+k] - 3.*zero[i*tree->n_pattern+k])/(inc[i] + inc[i]); + + /* if(is_ok[i] == NO) */ + /* printf("\n. i=%d site=%d l=%G plus=%G plusplus=%G zero=%G num=%f grad=%G", */ + /* i,k,tree->a_edges[i]->l->v, */ + /* plus[i*tree->n_pattern+k],plusplus[i*tree->n_pattern+k],zero[i*tree->n_pattern+k], */ + /* (4.*plus[i*tree->n_pattern+k] - plusplus[i*tree->n_pattern+k] - 3.*zero[i*tree->n_pattern+k]), */ + /* gradient[i]); */ + + } + for(i=0;idata->wght[k]; + } + + + /* Make sure to update likelihood before bailing out */ + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + + l = tree->data->init_len; + n = tree->mod->ns; + /* Delta method for variance. Assumes Jukes and Cantor with p=1/n */ + small_var = (1./(l*l))*(1.-1./l)*(n-1.)*(n-1.)/(n-1.-n/l); + for(i=0;imod->log_l == YES) + { + hessian[i*dim+i] = small_var * POW(exp(tree->a_edges[i]->l->v),-2); + hessian[i*dim+i] = -1./hessian[i*dim+i]; + } + } + + for(i=0;imod->log_l == YES) + { + hessian[i*dim+i] = small_var * POW(exp(tree->a_edges[i]->l->v),-2); + hessian[i*dim+i] = -1./hessian[i*dim+i]; + } + } + + + for(i=0;i 1.E-3) + { + PhyML_Printf("\n== Hessian not symmetrical."); + PhyML_Printf("\n== Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + hessian[i*dim+j] = (hessian[i*dim+j] + hessian[j*dim+i]) / 2.; + hessian[j*dim+i] = hessian[i*dim+j]; + } + } + + /* printf("\n"); */ + /* printf("HESSIAN SEO\n"); */ + /* for(i=0;ia_edges[i]->l->v); */ + /* for(j=0;jv[i] == d) + { + Update_Partial_Lk(tree,a->b[i],a); + + ori_l = a->b[i]->l->v; + if(is_ok[a->b[i]->num]) + { + if(plus_minus > 0) a->b[i]->l->v += inc[a->b[i]->num]; + else a->b[i]->l->v -= inc[a->b[i]->num]; + res[a->b[i]->num] = Lk(a->b[i],tree); + a->b[i]->l->v = ori_l; + Update_PMat_At_Given_Edge(a->b[i],tree); + } + break; + } + + if(d->tax) return; + else + for(i=0;i<3;i++) + if(d->v[i] != a) + Recurr_Hessian(d,d->v[i],plus_minus,inc,res,is_ok,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/* Work out the Hessian for the likelihood function. Only logARITHM of branch lengths are considered as variable. + This function is very much inspired from Jeff Thorne's 'hessian' function in his program 'estbranches'. */ +phydbl *Hessian_Log(t_tree *tree) +{ + phydbl *hessian; + phydbl *plus_plus, *minus_minus, *plus_zero, *minus_zero, *plus_minus, *zero_zero; + phydbl *ori_bl,*inc,*buff; + int *ok_edges,*is_ok; + int dim; + int n_ok_edges; + int i,j; + phydbl eps; + phydbl lk; + + dim = 2*tree->n_otu-3; + eps = 1.E-4; + + hessian = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + ori_bl = (phydbl *)mCalloc((int)dim, sizeof(phydbl)); + plus_plus = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + minus_minus = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + plus_minus = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + plus_zero = (phydbl *)mCalloc((int)dim ,sizeof(phydbl)); + minus_zero = (phydbl *)mCalloc((int)dim ,sizeof(phydbl)); + zero_zero = (phydbl *)mCalloc((int)dim ,sizeof(phydbl)); + inc = (phydbl *)mCalloc((int)dim ,sizeof(phydbl)); + buff = (phydbl *)mCalloc((int)dim*dim,sizeof(phydbl)); + ok_edges = (int *)mCalloc((int)dim, sizeof(int)); + is_ok = (int *)mCalloc((int)dim, sizeof(int)); + + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + + for(i=0;ia_edges[i]->l->v; + + n_ok_edges = 0; + for(i=0;ia_edges[i]->l->v > 3.0/(phydbl)tree->data->init_len) + { + inc[i] = fabs(eps * tree->a_edges[i]->l->v); + ok_edges[n_ok_edges] = i; + n_ok_edges++; + is_ok[i] = 1; + } + else is_ok[i] = 0; + } + + /* zero zero */ + lk = Log_Det(is_ok,tree); + for(i=0;ic_lnL+lk; + + /* plus zero */ + for(i=0;ia_edges[i]->l->v += inc[i]; + lk = Lk(tree->a_edges[i],tree); + plus_zero[i] = lk+Log_Det(is_ok,tree); + tree->a_edges[i]->l->v = ori_bl[i]; + } + } + + + /* minus zero */ + for(i=0;ia_edges[i]->l->v -= inc[i]; + lk = Lk(tree->a_edges[i],tree); + minus_zero[i] = lk+Log_Det(is_ok,tree); + tree->a_edges[i]->l->v = ori_bl[i]; + } + } + + for(i=0;ia_edges[i],tree); + + /* plus plus */ + for(i=0;ia_edges[i]->l->v += inc[i]; + Update_PMat_At_Given_Edge(tree->a_edges[i],tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->left->tax) && (tree->a_edges[i]->left->v[j] != tree->a_edges[i]->rght)) + Recurr_Hessian_Log(tree->a_edges[i]->left,tree->a_edges[i]->left->v[j],1,inc,plus_plus+i*dim,is_ok,tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->rght->tax) && (tree->a_edges[i]->rght->v[j] != tree->a_edges[i]->left)) + Recurr_Hessian_Log(tree->a_edges[i]->rght,tree->a_edges[i]->rght->v[j],1,inc,plus_plus+i*dim,is_ok,tree); + +/* for(j=0;j 0.0) */ +/* { */ +/* tree->a_edges[j]->l->v += inc[j]; */ +/* Lk(tree); */ +/* plus_plus[i*dim+j]=tree->c_lnL; */ +/* tree->a_edges[j]->l->v = ori_bl[j]; */ +/* } */ +/* } */ + + tree->a_edges[i]->l->v = ori_bl[i]; + Lk(NULL,tree); + } + } + + /* plus minus */ + for(i=0;ia_edges[i]->l->v += inc[i]; + Update_PMat_At_Given_Edge(tree->a_edges[i],tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->left->tax) && (tree->a_edges[i]->left->v[j] != tree->a_edges[i]->rght)) + Recurr_Hessian_Log(tree->a_edges[i]->left,tree->a_edges[i]->left->v[j],-1,inc,plus_minus+i*dim,is_ok,tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->rght->tax) && (tree->a_edges[i]->rght->v[j] != tree->a_edges[i]->left)) + Recurr_Hessian_Log(tree->a_edges[i]->rght,tree->a_edges[i]->rght->v[j],-1,inc,plus_minus+i*dim,is_ok,tree); + +/* for(j=0;j 0.0) */ +/* { */ +/* tree->a_edges[j]->l->v -= inc[j]; */ +/* Lk(tree); */ +/* plus_minus[i*dim+j] = tree->c_lnL; */ +/* tree->a_edges[j]->l->v = ori_bl[j]; */ +/* } */ +/* } */ + + tree->a_edges[i]->l->v = ori_bl[i]; + Lk(NULL,tree); + } + } + + + /* minus minus */ + for(i=0;ia_edges[i]->l->v -= inc[i]; + + Update_PMat_At_Given_Edge(tree->a_edges[i],tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->left->tax) && (tree->a_edges[i]->left->v[j] != tree->a_edges[i]->rght)) + Recurr_Hessian_Log(tree->a_edges[i]->left,tree->a_edges[i]->left->v[j],-1,inc,minus_minus+i*dim,is_ok,tree); + + for(j=0;j<3;j++) + if((!tree->a_edges[i]->rght->tax) && (tree->a_edges[i]->rght->v[j] != tree->a_edges[i]->left)) + Recurr_Hessian_Log(tree->a_edges[i]->rght,tree->a_edges[i]->rght->v[j],-1,inc,minus_minus+i*dim,is_ok,tree); + +/* for(j=0;j 0.0) */ +/* { */ +/* tree->a_edges[j]->l->v -= inc[j]; */ +/* Lk(tree); */ +/* minus_minus[i*dim+j] = tree->c_lnL; */ +/* tree->a_edges[j]->l->v = ori_bl[j]; */ +/* } */ +/* } */ + + tree->a_edges[i]->l->v = ori_bl[i]; + Lk(NULL,tree); + } + } + +/* for(i=0;ia_edges[i]->l->v+inc[i],2)-POW(tree->a_edges[i]->l->v,2); */ + for(i=0;ia_edges[i]->l->v+inc[i])-log(tree->a_edges[i]->l->v); +/* for(i=0;ia_edges[i]->l->v+inc[i])-SQRT(tree->a_edges[i]->l->v); */ + + for(i=0;idata->init_len,2); + } + + if(!Matinv(hessian,dim,dim,NO)) + { + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + For(i,dim*dim) hessian[i] = -1.0*hessian[i]; + +/* for(i=0;ia_edges[i]->l->v); */ +/* For(j,i+1) */ +/* { */ +/* PhyML_Printf("%12lf ",hessian[i*dim+j]); */ +/* } */ +/* PhyML_Printf("\n"); */ +/* } */ + +/* Matinv(hessian,dim,dim); */ + +/* PhyML_Printf("\n"); */ + + for(i=0;ia_edges[i]->l->v); + For(j,i+1) + { + PhyML_Printf("%12lf ",hessian[i*dim+j]); + } + PhyML_Printf("\n"); + } +/* Exit("\n"); */ + + + Free(ori_bl); + Free(plus_plus); + Free(minus_minus); + Free(plus_zero); + Free(minus_zero); + Free(plus_minus); + Free(zero_zero); + Free(inc); + Free(buff); + Free(ok_edges); + Free(is_ok); + + return hessian; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Recurr_Hessian_Log(t_node *a, t_node *d, int plus_minus, phydbl *inc, phydbl *res, int *is_ok, t_tree *tree) +{ + int i; + phydbl ori_l; + + for(i=0;i<3;i++) + if(a->v[i] == d) + { + Update_Partial_Lk(tree,a->b[i],a); + + ori_l = a->b[i]->l->v; + if(is_ok[a->b[i]->num]) + { + if(plus_minus > 0) a->b[i]->l->v += inc[a->b[i]->num]; + else a->b[i]->l->v -= inc[a->b[i]->num]; + res[a->b[i]->num] = Lk(a->b[i],tree); + res[a->b[i]->num] += Log_Det(is_ok,tree); + a->b[i]->l->v = ori_l; + Update_PMat_At_Given_Edge(a->b[i],tree); + } + break; + } + + if(d->tax) return; + else + for(i=0;i<3;i++) + if(d->v[i] != a) + Recurr_Hessian_Log(d,d->v[i],plus_minus,inc,res,is_ok,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Log_Det(int *is_ok, t_tree *tree) +{ + int i; + phydbl ldet; + + ldet = 0.0; +/* For(i,2*tree->n_otu-3) if(is_ok[i]) ldet += log(2.*SQRT(tree->a_edges[i]->l->v)); */ + For(i,2*tree->n_otu-3) if(is_ok[i]) ldet += log(tree->a_edges[i]->l->v); +/* For(i,2*tree->n_otu-3) if(is_ok[i]) ldet -= log(2*tree->a_edges[i]->l->v); */ + + return ldet; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Normal_Trunc_Mean(phydbl mu, phydbl sd, phydbl min, phydbl max) +{ + phydbl mean; + + mean = mu + sd * + (Dnorm((min-mu)/sd,0.,1.)-Dnorm((max-mu)/sd,0.,1.))/ + (Pnorm((max-mu)/sd,0.,1.)-Pnorm((min-mu)/sd,0.,1.)); + return mean; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Constraint_Normal_Trunc_Mean(phydbl wanted_mu, phydbl sd, phydbl min, phydbl max) +{ + int j; + phydbl dx,f,fmid,xmid,rtb; + phydbl x1, x2; + + x1 = min; + x2 = max; + + f = Normal_Trunc_Mean(x1,sd,min,max) - wanted_mu; + fmid = Normal_Trunc_Mean(x2,sd,min,max) - wanted_mu; + + if(f*fmid >= 0.0) + { + PhyML_Printf("\n. Root must be bracketed for bisection!"); + PhyML_Printf("\n. f=%f fmid=%f",f,fmid); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + rtb = f < 0.0 ? (dx=x2-x1,x1) : (dx=x1-x2,x2); + + for(j=0;j<100;j++) + { + xmid=rtb+(dx *= 0.5); + fmid=Normal_Trunc_Mean(xmid,sd,min,max)-wanted_mu; + if(fmid <= 0.0) rtb=xmid; + if(fmid > -1.E-10 && fmid < 1.E-10) return rtb; + } + + Exit("Too many bisections in RTBIS"); + return(-1.); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Matinv(phydbl *x, const int n, const int m, const int verbose) +{ + +/* x[n*m] ... m>=n +*/ + + int i,j,k; + int *irow; + phydbl ee, t,t1,xmax; + phydbl det; + + ee = 1.0E-10; + det = 1.0; + + irow = (int *)mCalloc(n,sizeof(int)); + + for(i=0;i=0; i--) + { + if (irow[i] == i) continue; + for(j=0;j 100) + { + PhyML_Printf("\n== Err in file %s at line %d.",__FILE__,__LINE__); + return 0; + } + } + if(pb) PhyML_Printf("\n== Managed to fix the problem by rescaling the matrix."); + For(i,n*m) x[i] = buff[i]*scaler; + Free(buff); + return 1; +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl *Matrix_Mult(phydbl *A, phydbl *B, int nra, int nca, int nrb, int ncb) +{ + int i,j,k; + phydbl *C; + + C = (phydbl *)mCalloc(nra*ncb,sizeof(phydbl)); + + if(nca != nrb) + { + PhyML_Printf("\n. Matrices dimensions don't match."); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + for(i=0;i 1.E-3) */ +/* { */ +/* PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); */ +/* Warn_And_Exit(""); */ +/* } */ +/* } */ + + + for(i=0;i 1.E-3) + { + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + } + + Free(mu1); + Free(mu2); + Free(sig11); + Free(sig12); + Free(sig21); + Free(sig22); + Free(ctrd_a); + Free(cond_cov_norder); + Free(cond_mu_norder); + Free(sig12_invsig22); + Free(buff_mat); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/* http://en.wikipedia.org/wiki/Multivariate_normal_distribution (Conditional distributions) */ +void Normal_Conditional_Unsorted(phydbl *mu, phydbl *cov, phydbl *a, int n, short int *is_1, int n1, phydbl *cond_mu, phydbl *cond_cov) +{ + phydbl *mu1,*mu2; + phydbl *sig11,*sig12,*sig21,*sig22,*sig12_invsig22,*buff; + phydbl *ctrd_a; + int n2; + int i,j,nr,nc; + + n2 = n-n1; + + mu1 = (phydbl *)mCalloc(n1, sizeof(phydbl)); + mu2 = (phydbl *)mCalloc(n2, sizeof(phydbl)); + sig11 = (phydbl *)mCalloc(n1*n1,sizeof(phydbl)); + sig12 = (phydbl *)mCalloc(n1*n2,sizeof(phydbl)); + sig21 = (phydbl *)mCalloc(n2*n1,sizeof(phydbl)); + sig22 = (phydbl *)mCalloc(n2*n2,sizeof(phydbl)); + ctrd_a = (phydbl *)mCalloc(n2, sizeof(phydbl)); + + nr=0; + for(i=0;irates->cov_l; + mean = tree->rates->mean_l; + dim = 2*tree->n_otu-3; + + fp = fopen("covariance","w"); + fprintf(fp,"\n"); + fprintf(fp,"Run\t"); + fprintf(fp,"lnL\t"); + for(i=0;irates->u_ml_l[i]); + + + for(i=0;in_otu-3) tree->a_edges[i]->l->v *= Rgamma(5.,1./5.); */ + + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + + iter = 0; + do + { + /* tree->both_sides = YES; */ + /* Lk(tree); */ + MCMC_Br_Lens(tree); + /* MCMC_Scale_Br_Lens(tree); */ + + + max_diff_mean = 0.0; + for(i=0;ia_edges[i]->l->v; + mean[i] /= (phydbl)(iter+1); + + new_mean = mean[i]; + diff_mean = MAX(cur_mean,new_mean)/MIN(cur_mean,new_mean); + if(diff_mean > max_diff_mean) max_diff_mean = diff_mean; + /* printf("\n. %d diff_mean = %f %f %f %f",i,diff_mean,cur_mean,new_mean,tree->a_edges[i]->l->v); */ + } + + max_diff_cov = 0.0; + for(i=0;ia_edges[i]->l->v * tree->a_edges[j]->l->v; + cov[i*dim+j] /= (phydbl)(iter+1); + + new_cov = cov[i*dim+j]; + diff_cov = MAX(cur_cov,new_cov)/MIN(cur_cov,new_cov); + if(diff_cov > max_diff_cov) max_diff_cov = diff_cov; + } + } + iter++; + + /* if(!(iter%10)) */ + /* printf("\n. iter=%d max_diff_mean=%f max_diff_cov=%f",iter,max_diff_mean,max_diff_cov); */ + + /* if(iter && max_diff_mean < 1.01 && max_diff_cov < 1.01) break; */ + + if(!(iter%20)) + { + fprintf(fp,"\n"); + fprintf(fp,"%d\t",iter); + fprintf(fp,"%f\t",tree->c_lnL); + for(i=0;ia_edges[i]->l->v); + fflush(NULL); + } + + }while(iter < 5000); + + + for(i=0;i max || min > max) + { + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + cons = LnGamma(n+1) - LnGamma(r) - LnGamma(n-r+1); + cons = exp(cons); + cons = ROUND(cons); + + Fx = (x-min)/(max-min); + + dens = cons * pow(Fx,r-1) * pow(1.-Fx,n-r) * (1./(max-min)); + + /* printf("\n. x=%f r=%d n=%d min=%f max=%f dens=%f",x,r,n,min,max,dens); */ + /* Exit("\n"); */ + + return(dens); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Covariance(phydbl *x, phydbl *y, int n) +{ + int i; + phydbl mean_x,mean_y,mean_xy; + + mean_x = .0; + for(i=0;i alpha - lambda[cond]*min[i]) + { + PhyML_Printf("\n. Cannot satisfy the constraint.\n"); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + err = NO; + zi = Rnorm_Trunc(cond_mean,SQRT(cond_var), + MAX(lambda[i]*min[i],alpha-lambda[cond]*max[cond]), + MIN(lambda[i]*max[i],alpha-lambda[cond]*min[cond]),&err); + if(err == YES) + { + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + sum += zi; + x[i] = zi / lambda[i]; + } + } + + x[cond] = (k - sum)/lambda[cond]; + + }while(iter++ < 10); + + return(loc_res); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Integrated_Brownian_Bridge_Moments(phydbl x_beg, phydbl x_end, + phydbl y_beg, phydbl y_end, + phydbl brownian_var, phydbl *mean, phydbl *var) +{ + /* phydbl *y; */ + /* phydbl *y_mean; */ + /* int n_rep; */ + int n_breaks; + int i; + /* int j; */ + /* phydbl traj_mean, traj_sd; */ + /* phydbl x_prev, x_curr; */ + phydbl x; + phydbl x_step; + phydbl sum; + /* phydbl sumsum; */ + phydbl scaled_var; + + scaled_var = brownian_var/fabs(x_end - x_beg); + + n_breaks = 100; + + + /* n_rep = 500; */ + + /* x_step = (x_end - x_beg)/(n_breaks+1); */ + + /* y = (phydbl *)mCalloc(n_breaks+2,sizeof(phydbl)); */ + /* y_mean = (phydbl *)mCalloc(n_rep,sizeof(phydbl)); */ + + /* y[0] = y_beg; */ + /* y[n_breaks+1] = y_end; */ + + /* for(i=0;i 2.0 && pnormarg2 > 2.0) || + (pnormarg1 < -2.0 && pnormarg2 < -2.0)) + { + // Proposition 5.1 in Privaut & Guindon, 2015, Journal of mathematical biology 71 (6-7), 1387-1409 + *mean = T*(B-A)/log(B/A)+u*u*T*T*((A+B)/(2.*pow(log(B/A),2)) - (B-A)/pow(log(B/A),3)); + } + else + { + // Proposition 3.3 in Privaut & Guindon, 2015, Journal of mathematical biology 71 (6-7), 1387-1409 + *mean = + (A/(u*u))*sqrt(2.*PI*u*u*T)*exp(pow(u*u*T/2.+log(B/A),2)/(2.*u*u*T))* + (Pnorm(pnormarg1,0.,1.) - + Pnorm(pnormarg2,0.,1.)); + } + + *mean = *mean/T; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Integrated_Geometric_Brownian_Bridge_Var(phydbl T, phydbl A, phydbl B, phydbl u, phydbl *var) +{ + + double U = T*u*u; + double logz = log(B/A); + double z = B/A; + double m; + + phydbl pnormarg1 = log(B/A)/sqrt(u*u*T) + .5*sqrt(u*u*T); + phydbl pnormarg2 = pnormarg1 - sqrt(u*u*T); + + if((pnormarg1 > 2.0 && pnormarg2 > 2.0) || + (pnormarg1 < -2.0 && pnormarg2 < -2.0)) + { + // Proposition 5.1 in Privaut & Guindon, 2015, Journal of mathematical biology 71 (6-7), 1387-1409 + *var = 0.0; + } + else + { + // Proposition 3.3 in Privaut & Guindon, 2015, Journal of mathematical biology 71 (6-7), 1387-1409 + *var = + 2.*sqrt(2.*PI*U)*exp(pow(U +logz,2)/(2.*U))*(Pnorm(logz/sqrt(U) + sqrt(U),0.0,1.0)-Pnorm(logz/sqrt(U) - sqrt(U),0.0,1.0)) - + (1.+z)*2.*sqrt(2.*PI*U)*exp(pow(U/2.+logz,2)/(2.*U))*(Pnorm(logz/sqrt(U) + .5*sqrt(U),0.0,1.0)-Pnorm(logz/sqrt(U) - .5*sqrt(U),0.0,1.0)); + *var = *var * pow(A,2) / pow(u,4); + Integrated_Geometric_Brownian_Bridge_Mean(T,A,B,u,&m); + *var = *var / pow(T,2); + *var = *var - m*m; + } + if(*var < 0.0) *var = 0.0; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Inverse method to sample from X where P(X=xi)=pi[i] + +int Sample_i_With_Proba_pi(phydbl *pi, int len) +{ + phydbl *cum_pi; + int i; + phydbl u; + + cum_pi = (phydbl *)mCalloc(len,sizeof(phydbl)); + + u = .0; + for(i=0;i 1. + 1.E-10) || (cum_pi[i-1] < 1. - 1.E-10)) + { + PhyML_Printf("\n== Sum of probabilities is different from 1.0 (%f).",cum_pi[i-1]); + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + i = 0; + u = Uni(); + for(i=0;i u) break; + + if(i == len) + { + for(i=0;i=0; --i ) + { + if ( p[i]<1 ) + small[num_small++] = i; + else + large[num_large++] = i; + } + + while ( num_small && num_large ) + { + a = small[--num_small]; + g = large[--num_large]; + prob[a] = p[a]; + alias[a] = g; + p[g] = p[g] + p[a] - 1; + if ( p[g] < 1 ) + small[num_small++] = g; + else + large[num_large++] = g; + } + + while ( num_large ) + prob[ large[--num_large] ] = 1; + + while ( num_small ) + prob[ small[--num_small] ] = 1; + + Free( p ); + Free( small ); + Free( large ); + + for(n=0; n obs_stat) p_val += 1.; + } + + return(p_val / (phydbl)npermut); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Weighted_Mean(phydbl *x, phydbl *w, int l) +{ + int i; + phydbl wm; + wm = .0; + if(w) for(i=0;i 8*(int)sizeof(int)) + { + PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + sum = 0; + for(i=0;i> i) & 1; + } + + return(sum); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Modulo (int a, int b) +{ + if(b < 0) + return Modulo(-a, -b); + int ret = a % b; + if(ret < 0) + ret+=b; + return ret; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Runif_Disk(phydbl *sampled_x, phydbl *sampled_y, phydbl centrx, phydbl centry, phydbl radius) +{ + phydbl r,theta; + + r = Uni(); + theta = Uni()*2.*PI; + + (*sampled_x) = SQRT(r)*COS(theta); + (*sampled_y) = SQRT(r)*SIN(theta); + + (*sampled_x) *= radius; + (*sampled_y) *= radius; + + (*sampled_x) += centrx; + (*sampled_y) += centry; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Random_String(char *s, int len) +{ + int i; + for(i=0;in_poly_vert = n; + + for(i=0;ipoly_vert[i]->lonlat[0] = Uni(); + p->poly_vert[i]->lonlat[1] = Uni(); + } + + return(p); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Area_Of_Poly_Monte_Carlo(t_poly *poly, t_geo_coord *lim) +{ + int n_hit,n_trials,trial; + t_geo_coord *point; + + point = (t_geo_coord *)GEO_Make_Geo_Coord(2); + + n_trials = 1E+7; + trial = 0; + n_hit = 0; + do + { + point->lonlat[0] = Uni()*lim->lonlat[0]; + point->lonlat[1] = Uni()*lim->lonlat[1]; + if(Is_In_Polygon(point,poly) == YES) n_hit++; + trial++; + } + while(trial < n_trials); + + + Free_Geo_Coord(point); + + return((phydbl)(n_hit)/n_trials*lim->lonlat[0]*lim->lonlat[1]); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int Is_In_Polygon(t_geo_coord *point, t_poly *poly) +{ + int i,j; + phydbl x,y,x1,y1,x2,y2; + phydbl x_intersect; + short int is_in; + + assert(point); + assert(poly); + + /* Coordinates of the point to test */ + x = point->lonlat[0]; + y = point->lonlat[1]; + + j = poly->n_poly_vert-1; + is_in = NO; + for(i=0;in_poly_vert;i++) + { + /* Edge of polygon goes from (x1,y1) to (x2,y2) */ + x1 = poly->poly_vert[i]->lonlat[0]; + y1 = poly->poly_vert[i]->lonlat[1]; + x2 = poly->poly_vert[j]->lonlat[0]; + y2 = poly->poly_vert[j]->lonlat[1]; + + j = i; + + /* Shoot an horizontal ray to the right. Find out if + this ray hits the polygon edge */ + if((y1 < y && y2 > y) || (y2 < y && y1 > y)) + { + /* Coordinates along X-axis of the intersection between ray and edge */ + x_intersect = (y-y1)/(y1-y2)*(x1-x2)+x1; + if(x_intersect > x) /* Intersection is on the righthand side */ + is_in = (is_in == YES)?NO:YES; + } + } + + return is_in; +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Modified Bessel function of the first kind. Stolen from Numerical Recipes in C. */ +phydbl Bessi0(phydbl x) +{ + phydbl ax,ans; + phydbl y; + + if ((ax=fabs(x)) < 3.75) + { + y=x/3.75; + y*=y; + ans=1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492+y*(0.2659732+y*(0.360768e-1+y*0.45813e-2))))); + } + else + { + y=3.75/ax; + ans=(exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1+y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2+y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1+y*0.392377e-2)))))))); + } + + return ans; +} + + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +/* Modified Bessel function of the second kind (degree 0). Stolen from Numerical Recipes in C. */ +phydbl Bessk0(phydbl x) +{ + phydbl y,ans; + + if (x <= 2.0) + { + y=x*x/4.0; + ans=(-log(x/2.0)*Bessi0(x))+(-0.57721566+y*(0.42278420+y*(0.23069756+y*(0.3488590e-1+y*(0.262698e-2+y*(0.10750e-3+y*0.74e-5)))))); + } + else + { + y=2.0/x; + ans=(exp(-x)/sqrt(x))*(1.25331414+y*(-0.7832358e-1+y*(0.2189568e-1+y*(-0.1062446e-1+y*(0.587872e-2+y*(-0.251540e-2+y*0.53208e-3)))))); + } + + return ans; +} + + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl Euclidean_Dist(t_geo_coord *x, t_geo_coord *y) +{ + int i; + phydbl dist; + + if(x->dim != y->dim) + { + PhyML_Printf("\n. x->dim: %d y->dim: %d",x->dim,y->dim); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + dist = 0.0; + for(i=0;idim;i++) dist += pow(x->lonlat[i]-y->lonlat[i],2); + + return(sqrt(dist)); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Return a vector rk such that rk[i] gives the index of the i-th largest element in x */ +int *Ranks(phydbl *x, int len) +{ + int *rk,tmp; + int i,swap; + + rk = (int *)mCalloc(len,sizeof(int)); + + for(i=0;i end_time) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + for(i=0;i time[i])) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + state = Brownian_Generate(var,n_steps,beg_time,time); + end_brown = Rnorm(state[n_steps-1],SQRT((time[n_steps-1] - end_time)*var)); + + for(i=0;i up) ref = up - (ref - up); + if(ref < down) ref = down + (down - ref); + }while(!(ref < up && ref > down)); + + return(ref); +} diff --git a/phyml/stats.h b/phyml/stats.h new file mode 100644 index 0000000..63b6a42 --- /dev/null +++ b/phyml/stats.h @@ -0,0 +1,145 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef STATS_H +#define STATS_H + +#include "utilities.h" +#include "free.h" +#include "lk.h" +#include "optimiz.h" +#include "models.h" +#include "eigen.h" + + +phydbl *Covariance_Matrix(t_tree *tree); +phydbl *Hessian(t_tree *tree); +void Recurr_Hessian(t_node *a, t_node *b, int plus_minus, phydbl *inc, phydbl *res, int *is_ok, t_tree *tree); +phydbl stdnormal_inv(phydbl p); +phydbl Uni(); +int Rand_Int(int min, int max); +phydbl Ahrensdietergamma(phydbl alpha); +phydbl Rgamma(phydbl shape, phydbl scale); +phydbl Rexp(phydbl lambda); +phydbl Bico(int n, int k); +phydbl Factln(int n); +phydbl Gammln(phydbl xx); +phydbl Pbinom(int N, int ni, phydbl p); +phydbl LnGamma (phydbl alpha); +phydbl IncompleteGamma(phydbl x, phydbl alpha, phydbl ln_gamma_alpha); +phydbl PointChi2 (phydbl prob, phydbl v); +phydbl Bivariate_Normal_Density(phydbl x, phydbl y, phydbl mux, phydbl muy, phydbl sdx, phydbl sdy, phydbl rho); +phydbl PointNormal (phydbl prob); +int DiscreteGamma (phydbl freqK[], phydbl rK[],phydbl alfa, phydbl beta, int K, int median); +phydbl Pnorm(phydbl x, phydbl mean, phydbl var); +phydbl Dnorm_Moments(phydbl x, phydbl mean, phydbl var); +phydbl Dnorm(phydbl x, phydbl mean, phydbl sd); +phydbl Pgamma(phydbl x, phydbl shape, phydbl scale); +phydbl Dgamma_Moments(phydbl x, phydbl mean, phydbl var); +phydbl Dgamma(phydbl x, phydbl shape, phydbl scale); +phydbl LnFact(int n); +int Choose(int n, int k); +phydbl LnChoose(int n, int k); +phydbl Ppois(phydbl x, phydbl param); +phydbl Dexp(phydbl x, phydbl param); +phydbl Dpois(phydbl x, phydbl param, int logit); +phydbl Rand_Normal_Deviate(phydbl mean, phydbl sd); +phydbl Rnorm(phydbl mean, phydbl sd); +phydbl *Rnorm_Multid(phydbl *mu, phydbl *cov, int dim); +phydbl Rnorm_Trunc(phydbl mean, phydbl sd, phydbl min, phydbl max, int *err); +phydbl *Rnorm_Multid_Trunc(phydbl *mean, phydbl *cov, phydbl *min, phydbl *max, int dim); +phydbl *Hessian_Log(t_tree *tree); +void Recurr_Hessian_Log(t_node *a, t_node *d, int plus_minus, phydbl *inc, phydbl *res, int *is_ok, t_tree *tree); +phydbl Log_Det(int *is_ok, t_tree *tree); +phydbl Dnorm_Trunc(phydbl x, phydbl mean, phydbl sd, phydbl lo, phydbl up); +phydbl Normal_Trunc_Mean(phydbl mu, phydbl sd, phydbl min, phydbl max); +phydbl Constraint_Normal_Trunc_Mean(phydbl wanted_mu, phydbl sd, phydbl min, phydbl max); +phydbl Dnorm_Multi(phydbl *x, phydbl *mu, phydbl *cov, int size, int _log); +phydbl Dnorm_Multi_Given_InvCov_Det(phydbl *x, phydbl *mu, phydbl *invcov, phydbl det, int size, int _log); +phydbl Prop_Log_Dnorm_Multi_Given_InvCov_Det(phydbl *x, phydbl *mu, phydbl *invcov, phydbl det, int size); +phydbl Log_Dnorm(phydbl x, phydbl mean, phydbl sd, int *err); +phydbl tt800(); +phydbl Pnorm_Ihaka_Derived_From_Cody(phydbl x); +int Matinv(phydbl *x, const int n, const int m, const int verbose); +phydbl *Matrix_Mult(phydbl *A, phydbl *B, int nra, int nca, int nrb, int ncb); +phydbl *Matrix_Transpose(phydbl *A, int dim); +void Normal_Conditional(phydbl *mu, phydbl *cov, phydbl *a, int n, short int *is_1, int n1, phydbl *cond_mu, phydbl *cond_var); +void Normal_Conditional_Unsorted(phydbl *mu, phydbl *cov, phydbl *a, int n, short int *is_1, int n1, phydbl *cond_mu, phydbl *cond_cov); +phydbl Matrix_Det(phydbl *A, int size, int _log); +void Get_Reg_Coeff(phydbl *mu, phydbl *cov, phydbl *a, int n, short int *is_1, int n1, phydbl *reg_coeff); +phydbl Rnorm_Trunc_Inverse(phydbl mean, phydbl sd, phydbl min, phydbl max, int *error); +phydbl Norm_Trunc_Sd(phydbl mu, phydbl sd, phydbl a, phydbl b); +phydbl Norm_Trunc_Mean(phydbl mu, phydbl sd, phydbl a, phydbl b); +int Norm_Trunc_Mean_Sd(phydbl mu, phydbl sd, phydbl a, phydbl b, phydbl *trunc_mu, phydbl *trunc_sd); +phydbl Log_Dnorm_Trunc(phydbl x, phydbl mean, phydbl sd, phydbl lo, phydbl up, int *err); +phydbl Pnorm_Marsaglia(phydbl x); +int Iter_Matinv(phydbl *x, int n, int m, int verbose); +phydbl Dorder_Unif(phydbl x, int r, int n, phydbl min, phydbl max); +phydbl Covariance(phydbl *x, phydbl *y, int n); +phydbl *Rnorm_Multid_Trunc_Constraint(phydbl *mu, phydbl *cov, phydbl *min, phydbl *max, phydbl *lambda, phydbl k, phydbl *res, int len); +phydbl *Gradient(t_tree *tree); +phydbl *Hessian_Seo(t_tree *tree); +void Integrated_Brownian_Bridge_Moments(phydbl x_beg, phydbl x_end, + phydbl y_beg, phydbl y_end, + phydbl sd, phydbl *mean, phydbl *var); +void Integrated_Geometric_Brownian_Bridge_Moments(phydbl T, phydbl A, phydbl B, phydbl u, phydbl *mean, phydbl *var); +void Integrated_Geometric_Brownian_Bridge_Mean(phydbl T, phydbl A, phydbl B, phydbl u, phydbl *mean); +void Integrated_Geometric_Brownian_Bridge_Var(phydbl T, phydbl A, phydbl B, phydbl u, phydbl *mean); +int Sample_i_With_Proba_pi(phydbl *pi, int len); +int* Sample_n_i_With_Proba_pi(phydbl *pi, int len,int n_elts); +phydbl Quantile(phydbl *x, int len, phydbl p); +phydbl Prob(phydbl *x, int len, phydbl z); +phydbl Inverse_Truncated_Normal(phydbl y, phydbl mu, phydbl sigma, phydbl lim_inf, phydbl lim_sup); +phydbl Progressive_EXP(phydbl x); +int *Permutate(int len); +phydbl Mantel(phydbl *x, phydbl *y, int nrow, int ncol); +phydbl Weighted_Mean(phydbl *x, phydbl *w, int l); +int Sum_Bits(int value, int range); +int Modulo (int a, int b); +void Runif_Disk(phydbl *sampled_x, phydbl *sampled_y, phydbl centrx, phydbl centry, phydbl radius); +void Random_String(char *s, int len); +int *Random_Permut(int n); +phydbl Dexp_Trunc(phydbl x, phydbl lambda, phydbl left, phydbl rght); +phydbl Rexp_Trunc(phydbl lambda, phydbl left, phydbl rght); +t_poly *Rpoly(int n); +phydbl Area_Of_Poly_Monte_Carlo(t_poly *poly, t_geo_coord *lim); +int Is_In_Polygon(t_geo_coord *point, t_poly *poly); +phydbl Variance(phydbl *x, int l); +phydbl Bessi0(phydbl x); +phydbl Bessk0(phydbl x); +phydbl Euclidean_Dist(t_geo_coord *x, t_geo_coord *y); +int *Ranks(phydbl *x, int len); +phydbl Rpois(phydbl mmu); +phydbl Rgeom(phydbl p); +phydbl Dgeom(phydbl k, phydbl p, int logit); +phydbl Pgeom(phydbl k, phydbl p); +phydbl *Brownian_Bridge_Generate(phydbl start, phydbl end, phydbl var, phydbl beg_time, phydbl end_time, int n_steps, phydbl *time); +phydbl *Brownian_Generate(phydbl var, int n_steps, phydbl beg_time, phydbl *time); +phydbl Brownian_Bridge_Logdensity(phydbl start, phydbl end, phydbl *state, phydbl var, phydbl end_time, int n_steps, phydbl *time); +phydbl Reflected(phydbl x, phydbl down, phydbl up); +phydbl *Random_Walk_Generate(phydbl var, int n_steps); +phydbl *Random_Walk_Bridged_Generate(phydbl start, phydbl end, phydbl var, int n_steps); +phydbl Dnbinom(phydbl x, phydbl n, phydbl p, int logit); +phydbl Rnbinom(phydbl n, phydbl p); +phydbl Erf(phydbl x); +phydbl Rnorm_Trunc_Algo1(phydbl alpha, phydbl beta); +phydbl Rnorm_Trunc_Algo2(phydbl alpha, phydbl beta); +phydbl Rnorm_Trunc_Algo3(phydbl alpha, phydbl beta); +phydbl Rnorm_Trunc_Algo4(phydbl alpha, phydbl beta); + + + + + +#endif diff --git a/phyml/tbe.c b/phyml/tbe.c new file mode 100644 index 0000000..f2dc561 --- /dev/null +++ b/phyml/tbe.c @@ -0,0 +1,195 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include "tbe.h" +#include "utilities.h" + +/* UNION AND INTERSECT CALCULATIONS (FOR THE TRANSFER METHOD) */ +void Update_IC_Ref_Tree(t_tree *ref_tree, t_node * orig, t_node* target, t_edge *my_br, t_tree *boot_tree, + short unsigned** i_matrix, short unsigned** c_matrix, int* cluster_sizes){ + /* this function does the post-order traversal (recursive from the pseudoroot to the leaves, updating knowledge for the subtrees) + of the reference tree, examining only leaves (terminal edges) of the bootstrap tree. + It sends a probe from the orig node to the target node (nodes in ref_tree), calculating I_ij and C_ij + (see Brehelin, Gascuel, Martin 2008). */ + int j, k; + int edge_id; /* its id */ + int next_edge_id; + t_node *tip; + int boot_edge_id; + edge_id = my_br->num; /* all this is in ref_tree */ + assert(target==my_br->rght); /* the descendant should always be the right side of the edge ? */ + + if(target->tax) { + cluster_sizes[edge_id] = 1; + for (j=0; j < 2*boot_tree->n_otu-3; j++) { /* for all the terminal edges of boot_tree */ + boot_edge_id = boot_tree->a_edges[j]->num; + // If not tip, continue + tip = NULL; + if(boot_tree->a_edges[j]->rght->tax) + tip = boot_tree->a_edges[j]->rght; + if(boot_tree->a_edges[j]->left->tax) + tip = boot_tree->a_edges[j]->left; + if(tip == NULL) continue; + /* we only want to scan terminal edges of boot_tree, where the right son is a leaf */ + /* else we update all the I_ij and C_ij with i = edge_id */ + if (strcmp(target->name,tip->name)) { + /* here the taxa are different */ + i_matrix[edge_id][boot_edge_id] = 0; + c_matrix[edge_id][boot_edge_id] = 1; + } else { + /* same taxa here in T_ref and T_boot */ + i_matrix[edge_id][boot_edge_id] = 1; + c_matrix[edge_id][boot_edge_id] = 0; + } + } /* end for on all edges of T_boot, for my_br being terminal */ + } else { + cluster_sizes[edge_id] = 0; + /* now the case where my_br is not a terminal edge */ + /* first initialise (zero) the cells we are going to update */ + for (j=0; j < 2*boot_tree->n_otu-3; j++){ + /* We initialize the i and c matrices for the edge edge_id with : + * 0 for i : because afterwards we do i[edge_id] = i[edge_id] || i[next_edge_id] + * 1 for c : because afterwards we do c[edge_id] = c[edge_id] && c[next_edge_id] + */ + if(boot_tree->a_edges[j]->rght->tax || boot_tree->a_edges[j]->left->tax){ + boot_edge_id = boot_tree->a_edges[j]->num; + i_matrix[edge_id][boot_edge_id] = 0; + c_matrix[edge_id][boot_edge_id] = 1; + } + } + + for (k = 0; k < 3; k++) { + if(target->v[k]!=orig){ + Update_IC_Ref_Tree(ref_tree, target, target->v[k], target->b[k], boot_tree, i_matrix, c_matrix, cluster_sizes); + next_edge_id = target->b[k]->num; + cluster_sizes[edge_id] += cluster_sizes[next_edge_id]; + for (j=0; j < 2*boot_tree->n_otu-3; j++) { /* for all the terminal edges of boot_tree */ + boot_edge_id = boot_tree->a_edges[j]->num; + // If not a tip, continue + if(!(boot_tree->a_edges[j]->rght->tax) && !(boot_tree->a_edges[j]->left->tax)) continue; + i_matrix[edge_id][boot_edge_id] = i_matrix[edge_id][boot_edge_id] || i_matrix[next_edge_id][boot_edge_id]; + /* above is an OR between two integers, result is 0 or 1 */ + c_matrix[edge_id][boot_edge_id] = c_matrix[edge_id][boot_edge_id] && c_matrix[next_edge_id][boot_edge_id]; + /* above is an AND between two integers, result is 0 or 1 */ + } /* end for j */ + } + } /* end for on all edges of T_boot, for my_br being internal */ + } /* ending the case where my_br is an internal edge */ +} /* end update_i_c_post_order_ref_tree */ + + +void Update_All_IC_Ref_Tree(t_tree* ref_tree, t_tree* boot_tree, + short unsigned** i_matrix, short unsigned** c_matrix, int* cluster_sizes) { + /* this function is the first step of the union and intersection calculations */ + int i; + t_node *root; + + if(!ref_tree->n_root){ + i = 0; + while((!ref_tree->a_nodes[ref_tree->n_otu+i]->v[0]) || + (!ref_tree->a_nodes[ref_tree->n_otu+i]->v[1]) || + (!ref_tree->a_nodes[ref_tree->n_otu+i]->v[2])) i++; + root=ref_tree->a_nodes[ref_tree->n_otu+i]; + Update_IC_Ref_Tree(ref_tree, root, root->v[0], root->b[0], boot_tree, i_matrix, c_matrix, cluster_sizes); + Update_IC_Ref_Tree(ref_tree, root, root->v[1], root->b[1], boot_tree, i_matrix, c_matrix, cluster_sizes); + Update_IC_Ref_Tree(ref_tree, root, root->v[2], root->b[2], boot_tree, i_matrix, c_matrix, cluster_sizes); + } else { + root=ref_tree->n_root; + Update_IC_Ref_Tree(ref_tree, root, root->v[0], root->b[0], boot_tree, i_matrix, c_matrix, cluster_sizes); + Update_IC_Ref_Tree(ref_tree, root, root->v[1], root->b[1], boot_tree, i_matrix, c_matrix, cluster_sizes); + } +} /* end update_all_i_c_post_order_ref_tree */ + +void Update_IC_Boot_Tree(t_tree* ref_tree, t_tree* boot_tree, t_node* orig, t_node* target, + t_edge *my_br, short unsigned** i_matrix, short unsigned** c_matrix, + short unsigned** hamming, short unsigned* min_dist, + short unsigned* min_dist_edge, int* cluster_sizes) { + /* here we implement the second part of the Brehelin/Gascuel/Martin algorithm: + post-order traversal of the bootstrap tree, and numerical recurrence. + in this function, orig and target are nodes of boot_tree (aka T_boot). + min_dist is an array whose size is equal to the number of edges in T_ref. + It gives for each edge of T_ref its min distance to a split in T_boot. */ + int i, k; + int boot_edge_id /* its id */, next_boot_edge_id /* id of descending branches. */; + int N = ref_tree->n_otu; + /* we first have to determine which is the direction of the edge (orig -> target and target -> orig) */ + boot_edge_id = my_br->num; /* here this is an edge_id corresponding to T_boot */ + + if(!target->tax){ + + /* because nothing to do in the case where target is a leaf: intersection and union already ok. */ + /* otherwise, keep on posttraversing in all other directions */ + + /* first initialise (zero) the cells we are going to update */ + for (i=0; i < 2*ref_tree->n_otu-3; i++) i_matrix[i][boot_edge_id] = c_matrix[i][boot_edge_id] = 0; + + for(k=0;k<3;k++) { + if(target->v[k] != orig){ + next_boot_edge_id = target->b[k]->num; + Update_IC_Boot_Tree(ref_tree, boot_tree, target, target->v[k], target->b[k], + i_matrix, c_matrix, hamming, min_dist, min_dist_edge, cluster_sizes); + for (i=0; i < 2*ref_tree->n_otu-3; i++) { /* for all the edges of ref_tree */ + i_matrix[i][boot_edge_id] += i_matrix[i][next_boot_edge_id]; + c_matrix[i][boot_edge_id] += c_matrix[i][next_boot_edge_id]; + } /* end for i */ + } + } + } /* end if target is not a leaf: the following loop is performed in all cases */ + + for (i=0; i< 2*ref_tree->n_otu-3; i++) { /* for all the edges of ref_tree */ + /* at this point we can calculate in all cases (internal branch or not) the Hamming distance at [i][boot_edge_id], */ + /* card of union minus card of intersection */ + hamming[i][boot_edge_id] = cluster_sizes[i] /* #taxa in the cluster i of T_ref */ + + c_matrix[i][boot_edge_id] /* #taxa in cluster edge_id of T_boot BUT NOT in cluster i of T_ref */ + - i_matrix[i][boot_edge_id]; /* #taxa in the intersection of the two clusters */ + + /* Let's immediately calculate the right ditance, taking into account the fact that the true disance is min (dist, N-dist) */ + if (hamming[i][boot_edge_id] > N/2 /* floor value */) hamming[i][boot_edge_id] = N - hamming[i][boot_edge_id]; + + /* and update the min of all Hamming (TRANSFER) distances hamming[i][j] over all j */ + if (hamming[i][boot_edge_id] < min_dist[i]){ + min_dist[i] = hamming[i][boot_edge_id]; + min_dist_edge[i] = boot_edge_id; + } + } /* end for on all edges of T_ref */ +} /* end update_i_c_post_order_boot_tree */ + + +void Update_All_IC_Boot_Tree(t_tree* ref_tree, t_tree* boot_tree, short unsigned** i_matrix, + short unsigned** c_matrix, short unsigned** hamming, + short unsigned* min_dist, short unsigned* min_dist_edge, int* cluster_sizes) { + /* this function is the second step of the union and intersection calculations */ + int i; + t_node *root; + if(!boot_tree->n_root){ + i = 0; + while((!boot_tree->a_nodes[boot_tree->n_otu+i]->v[0]) || + (!boot_tree->a_nodes[boot_tree->n_otu+i]->v[1]) || + (!boot_tree->a_nodes[boot_tree->n_otu+i]->v[2])) i++; + root=boot_tree->a_nodes[boot_tree->n_otu+i]; + Update_IC_Boot_Tree(ref_tree, boot_tree, root, root->v[0], root->b[0], i_matrix, c_matrix, hamming, min_dist, min_dist_edge, cluster_sizes); + Update_IC_Boot_Tree(ref_tree, boot_tree, root, root->v[1], root->b[1], i_matrix, c_matrix, hamming, min_dist, min_dist_edge, cluster_sizes); + Update_IC_Boot_Tree(ref_tree, boot_tree, root, root->v[2], root->b[2], i_matrix, c_matrix, hamming, min_dist, min_dist_edge, cluster_sizes); + } else { + root=boot_tree->n_root; + Update_IC_Boot_Tree(ref_tree, boot_tree, root, root->v[0], root->b[0], i_matrix, c_matrix, hamming, min_dist, min_dist_edge, cluster_sizes); + Update_IC_Boot_Tree(ref_tree, boot_tree, root, root->v[1], root->b[2], i_matrix, c_matrix, hamming, min_dist, min_dist_edge, cluster_sizes); + } + + /* and then some checks to make sure everything went ok */ + for(i=0; i<2*ref_tree->n_otu-3; i++) { + assert(min_dist[ref_tree->a_edges[i]->num] >= 0); + if(ref_tree->a_edges[i]->rght->tax || ref_tree->a_edges[i]->left->tax){ + assert(min_dist[ref_tree->a_edges[i]->num] == 0); /* any terminal edge should have an exact match in any bootstrap tree */ + } + } +} /* end update_all_i_c_post_order_boot_tree */ diff --git a/phyml/tbe.h b/phyml/tbe.h new file mode 100644 index 0000000..d9dca3b --- /dev/null +++ b/phyml/tbe.h @@ -0,0 +1,31 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#ifndef TBE_H +#define TBE_H + +#include "utilities.h" + +/* Functions to compute Transfer distances, used in transfert bootstrap */ +void Update_All_IC_Ref_Tree(t_tree* ref_tree, t_tree* boot_tree, + short unsigned** i_matrix, short unsigned** c_matrix, int* cluster_sizes); +void Update_IC_Ref_Tree(t_tree *ref_tree, t_node * orig, t_node* target, t_edge *my_br, t_tree *boot_tree, + short unsigned** i_matrix, short unsigned** c_matrix, int* cluster_sizes); +void Update_IC_Boot_Tree(t_tree* ref_tree, t_tree* boot_tree, t_node* orig, t_node* target, + t_edge *my_br, short unsigned** i_matrix, short unsigned** c_matrix, + short unsigned** hamming, short unsigned* min_dist, + short unsigned* min_dist_edge, int* cluster_sizes); +void Update_All_IC_Boot_Tree(t_tree* ref_tree, t_tree* boot_tree, + short unsigned** i_matrix, short unsigned** c_matrix, + short unsigned** hamming, short unsigned* min_dist, + short unsigned* min_dist_edge, int* cluster_sizes); +#endif diff --git a/phyml/times.c b/phyml/times.c new file mode 100644 index 0000000..78afe49 --- /dev/null +++ b/phyml/times.c @@ -0,0 +1,2279 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + + +/* Routines for molecular clock trees and molecular dating */ + + +#include "times.h" + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Least_Square_Node_Times(t_edge *e_root, t_tree *tree) +{ + + /* Solve A.x = b, where x is the vector of times estimated + under the least square criterion and b is the vector + of edge lengths + + A is a n x n matrix, with n being the number of + nodes in a rooted tree (i.e. 2*n_otu-1). + + */ + + phydbl *A, *b, *x; + int n; + int i,j; + t_node *root; + + n = 2*tree->n_otu-1; + + A = (phydbl *)mCalloc(n*n,sizeof(phydbl)); + b = (phydbl *)mCalloc(n, sizeof(phydbl)); + x = (phydbl *)mCalloc(n, sizeof(phydbl)); + + if(!tree->n_root && e_root) Add_Root(e_root,tree); + else if(!e_root) Add_Root(tree->a_edges[0],tree); + + root = tree->n_root; + + TIMES_Least_Square_Node_Times_Pre(root,root->v[1],A,b,n,tree); + TIMES_Least_Square_Node_Times_Pre(root,root->v[2],A,b,n,tree); + + b[root->num] = tree->e_root->l->v/2.; + + A[root->num * n + root->num] = 1.0; + A[root->num * n + root->v[2]->num] = -.5; + A[root->num * n + root->v[1]->num] = -.5; + + if(!Matinv(A, n, n,YES)) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s').\n",__FILE__,__LINE__,__FUNCTION__); + Exit("\n"); + } + + for(i=0;irates->nd_t[tree->a_nodes[i]->num] = -x[i]; + tree->rates->nd_t[root->num] = -x[n-1]; + tree->n_root->b[2]->l->v = tree->rates->nd_t[root->v[2]->num] - tree->rates->nd_t[root->num]; + tree->n_root->b[1]->l->v = tree->rates->nd_t[root->v[1]->num] - tree->rates->nd_t[root->num]; + + Free(A); + Free(b); + Free(x); + + return; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Least_Square_Node_Times_Pre(t_node *a, t_node *d, phydbl *A, phydbl *b, int n, t_tree *tree) +{ + if(d->tax) + { + A[d->num * n + d->num] = 1.; + + /* Set the time stamp at tip nodes to 0.0 */ +/* PhyML_Printf("\n. Tip t_node date set to 0"); */ + b[d->num] = 0.0; + return; + } + else + { + int i; + + for(i=0;i<3;++i) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + TIMES_Least_Square_Node_Times_Pre(d,d->v[i],A,b,n,tree); + + A[d->num * n + d->num] = 1.; + b[d->num] = .0; + for(i=0;i<3;++i) + { + A[d->num * n + d->v[i]->num] = -1./3.; + if(d->v[i] != a) b[d->num] += d->b[i]->l->v; + else b[d->num] -= d->b[i]->l->v; + } + b[d->num] /= 3.; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/* Adjust t_node times in order to have correct time stamp ranking with + respect to the tree topology */ + +void TIMES_Adjust_Node_Times(t_tree *tree) +{ + TIMES_Adjust_Node_Times_Pre(tree->n_root->v[2],tree->n_root->v[1],tree); + TIMES_Adjust_Node_Times_Pre(tree->n_root->v[1],tree->n_root->v[2],tree); + + if(tree->rates->nd_t[tree->n_root->num] > MIN(tree->rates->nd_t[tree->n_root->v[2]->num], + tree->rates->nd_t[tree->n_root->v[1]->num])) + { + tree->rates->nd_t[tree->n_root->num] = MIN(tree->rates->nd_t[tree->n_root->v[2]->num], + tree->rates->nd_t[tree->n_root->v[1]->num]); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Adjust_Node_Times_Pre(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax) return; + else + { + int i; + phydbl min_height; + + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + TIMES_Adjust_Node_Times_Pre(d,d->v[i],tree); + } + + min_height = 0.0; + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(tree->rates->nd_t[d->v[i]->num] < min_height) + { + min_height = tree->rates->nd_t[d->v[i]->num]; + } + } + } + + if(tree->rates->nd_t[d->num] > min_height) tree->rates->nd_t[d->num] = min_height; + + if(tree->rates->nd_t[d->num] < -100.) tree->rates->nd_t[d->num] = -100.; + + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + + /* Multiply each time stamp at each internal + t_node by 'tree->time_stamp_mult'. + */ + +void TIMES_Mult_Time_Stamps(t_tree *tree) +{ + int i; + For(i,2*tree->n_otu-2) tree->rates->nd_t[tree->a_nodes[i]->num] *= FABS(tree->mod->s_opt->tree_size_mult); + tree->rates->nd_t[tree->n_root->num] *= FABS(tree->mod->s_opt->tree_size_mult); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Print_Node_Times(t_node *a, t_node *d, t_tree *tree) +{ + t_edge *b; + int i; + + b = NULL; + for(i=0;i<3;i++) if((d->v[i]) && (d->v[i] == a)) {b = d->b[i]; break;} + + PhyML_Printf("\n. (%3d %3d) a->t = %12f d->t = %12f (#=%12f) b->l->v = %12f [%12f;%12f]", + a->num,d->num, + tree->rates->nd_t[a->num], + tree->rates->nd_t[d->num], + tree->rates->nd_t[a->num]-tree->rates->nd_t[d->num], + (b)?(b->l->v):(-1.0), + tree->rates->t_prior_min[d->num], + tree->rates->t_prior_max[d->num]); + if(d->tax) return; + else + { + int i; + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + TIMES_Print_Node_Times(d,d->v[i],tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Set_All_Node_Priors(t_tree *tree) +{ + int i; + phydbl min_prior; + + /* Set all t_prior_max values */ + TIMES_Set_All_Node_Priors_Bottom_Up(tree->n_root,tree->n_root->v[2],tree); + TIMES_Set_All_Node_Priors_Bottom_Up(tree->n_root,tree->n_root->v[1],tree); + + tree->rates->t_prior_max[tree->n_root->num] = + MIN(tree->rates->t_prior_max[tree->n_root->num], + MIN(tree->rates->t_prior_max[tree->n_root->v[2]->num], + tree->rates->t_prior_max[tree->n_root->v[1]->num])); + + + /* Set all t_prior_min values */ + if(!tree->rates->t_has_prior[tree->n_root->num]) + { + min_prior = 1.E+10; + for(i=0;i<2*tree->n_otu-2;++i) + { + if(tree->rates->t_has_prior[i]) + { + if(tree->rates->t_prior_min[i] < min_prior) + min_prior = tree->rates->t_prior_min[i]; + } + } + tree->rates->t_prior_min[tree->n_root->num] = 2.0 * min_prior; + /* tree->rates->t_prior_min[tree->n_root->num] = 10. * min_prior; */ + } + + if(tree->rates->t_prior_min[tree->n_root->num] > 0.0) + { + PhyML_Fprintf(stderr,"\n. Failed to set the lower bound for the root node."); + PhyML_Fprintf(stderr,"\n. Make sure at least one of the calibration interval"); + PhyML_Fprintf(stderr,"\n. provides a lower bound."); + Exit("\n"); + } + + + TIMES_Set_All_Node_Priors_Top_Down(tree->n_root,tree->n_root->v[2],tree); + TIMES_Set_All_Node_Priors_Top_Down(tree->n_root,tree->n_root->v[1],tree); + + Get_Node_Ranks(tree); + TIMES_Set_Floor(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Set_All_Node_Priors_Bottom_Up(t_node *a, t_node *d, t_tree *tree) +{ + int i; + phydbl t_sup; + + if(d->tax) return; + else + { + t_node *v1, *v2; /* the two sons of d */ + + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + TIMES_Set_All_Node_Priors_Bottom_Up(d,d->v[i],tree); + } + } + + v1 = v2 = NULL; + for(i=0;i<3;i++) if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(!v1) v1 = d->v[i]; + else v2 = d->v[i]; + } + + if(tree->rates->t_has_prior[d->num] == YES) + { + t_sup = MIN(tree->rates->t_prior_max[d->num], + MIN(tree->rates->t_prior_max[v1->num], + tree->rates->t_prior_max[v2->num])); + + tree->rates->t_prior_max[d->num] = t_sup; + + if(tree->rates->t_prior_max[d->num] < tree->rates->t_prior_min[d->num]) + { + PhyML_Fprintf(stderr,"\n. prior_min=%f prior_max=%f",tree->rates->t_prior_min[d->num],tree->rates->t_prior_max[d->num]); + PhyML_Fprintf(stderr,"\n. Inconsistency in the prior settings detected at node %d",d->num); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function %s)\n\n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit("\n"); + } + } + else + { + tree->rates->t_prior_max[d->num] = + MIN(tree->rates->t_prior_max[v1->num], + tree->rates->t_prior_max[v2->num]); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Set_All_Node_Priors_Top_Down(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax) return; + else + { + int i; + + if(tree->rates->t_has_prior[d->num] == YES) + { + tree->rates->t_prior_min[d->num] = MAX(tree->rates->t_prior_min[d->num],tree->rates->t_prior_min[a->num]); + + if(tree->rates->t_prior_max[d->num] < tree->rates->t_prior_min[d->num]) + { + PhyML_Fprintf(stderr,"\n. prior_min=%f prior_max=%f",tree->rates->t_prior_min[d->num],tree->rates->t_prior_max[d->num]); + PhyML_Fprintf(stderr,"\n. Inconsistency in the prior settings detected at t_node %d",d->num); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function %s)\n\n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit("\n"); + } + } + else + { + tree->rates->t_prior_min[d->num] = tree->rates->t_prior_min[a->num]; + } + + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + TIMES_Set_All_Node_Priors_Top_Down(d,d->v[i],tree); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Set_Floor(t_tree *tree) +{ + TIMES_Set_Floor_Post(tree->n_root,tree->n_root->v[2],tree); + TIMES_Set_Floor_Post(tree->n_root,tree->n_root->v[1],tree); + tree->rates->t_floor[tree->n_root->num] = MIN(tree->rates->t_floor[tree->n_root->v[2]->num], + tree->rates->t_floor[tree->n_root->v[1]->num]); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Set_Floor_Post(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax) + { + tree->rates->t_floor[d->num] = tree->rates->nd_t[d->num]; + d->rank_max = d->rank; + return; + } + else + { + int i; + t_node *v1,*v2; + + v1 = v2 = NULL; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + TIMES_Set_Floor_Post(d,d->v[i],tree); + if(!v1) v1 = d->v[i]; + else v2 = d->v[i]; + } + } + tree->rates->t_floor[d->num] = MIN(tree->rates->t_floor[v1->num], + tree->rates->t_floor[v2->num]); + + if(tree->rates->t_floor[v1->num] < tree->rates->t_floor[v2->num]) + { + d->rank_max = v1->rank_max; + } + else if(tree->rates->t_floor[v2->num] < tree->rates->t_floor[v1->num]) + { + d->rank_max = v2->rank_max; + } + else + { + d->rank_max = MAX(v1->rank_max,v2->rank_max); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Does it work for serial samples? */ +phydbl TIMES_Log_Conditional_Uniform_Density(t_tree *tree) +{ + phydbl min,max; + phydbl dens; + int i; + + min = tree->rates->nd_t[tree->n_root->num]; + + dens = 0.0; + For(i,2*tree->n_otu-1) + { + if((tree->a_nodes[i]->tax == NO) && (tree->a_nodes[i] != tree->n_root)) + { + max = tree->rates->t_floor[i]; + + dens += log(Dorder_Unif(tree->rates->nd_t[i], + tree->a_nodes[i]->rank-1, + tree->a_nodes[i]->rank_max-2, + min,max)); + } + } + return dens; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Returns the marginal density of tree height assuming the +// Yule model of speciation. +phydbl TIMES_Lk_Yule_Root_Marginal(t_tree *tree) +{ + int n; + int j; + t_node *nd; + phydbl *t,*ts; + phydbl lbda; + phydbl T; + + lbda = tree->rates->birth_rate; + t = tree->rates->nd_t; + ts = tree->rates->time_slice_lims; + T = ts[0] - t[tree->n_root->num]; + + n = 0; + nd = NULL; + For(j,2*tree->n_otu-2) + { + nd = tree->a_nodes[j]; + + if((t[nd->num] > ts[0] && t[nd->anc->num] < ts[0]) || // lineage that is crossing ts[0] + (nd->tax == YES && Are_Equal(t[nd->num],ts[0],1.E-6) == YES)) // tip that is lying on ts[0] + n++; + } + + return LnGamma(n+1) + log(lbda) - 2.*lbda*T + (n-2.)*log(1. - exp(-lbda*T)); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Returns the joint density of internal node heights assuming +// the Yule model of speciation. +phydbl TIMES_Lk_Yule_Joint(t_tree *tree) +{ + int i,j; + phydbl loglk; + phydbl *t; + phydbl dt; + int n; // number of lineages at a given time point + phydbl lbda; + t_node *nd; + phydbl *ts; + int *tr; + phydbl top_t; + short int *interrupted; + phydbl sumdt; + + interrupted = (short int *)mCalloc(tree->n_otu,sizeof(short int)); + + t = tree->rates->nd_t; + ts = tree->rates->time_slice_lims; + tr = tree->rates->t_rank; + lbda = tree->rates->birth_rate; + + TIMES_Update_Node_Ordering(tree); + + for(j=0;jn_otu;j++) interrupted[j] = NO; + + loglk = .0; + + sumdt = .0; + n = 1; + For(i,2*tree->n_otu-2) // t[tr[0]] is the time of the oldest node, t[tr[1]], the second oldest and so on... + { + + for(j=0;jn_otu;j++) + if((t[j] < t[tr[i]]) && (interrupted[j] == NO)) + { + interrupted[j] = YES; + n--; // How many lineages have stopped above t[tr[i]]? + } + + top_t = t[tr[i+1]]; + dt = top_t - t[tr[i]]; + sumdt += dt; + + /* printf("\n. %d node up=%d [%f] node do=%d [%f] dt=%f",i,tr[i],t[tr[i]],tr[i+1],t[tr[i+1]],dt); */ + + if(n<1) + { + PhyML_Fprintf(stderr,"\n. i=%d tr[i]=%f",i,t[tr[i]]); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + if(dt > 1.E-10) loglk += log((n+1)*lbda) - (n+1)*lbda*dt; + n++; + } + + /* printf("\n. sumdt = %f th=%f",sumdt,tree->rates->nd_t[tree->n_root->num]); */ + /* printf("\n0 loglk = %f",loglk); */ + + for(i=0;irates->n_time_slices-1;i++) + { + n = 0; + dt = 0.; + For(j,2*tree->n_otu-2) + { + nd = tree->a_nodes[j]; + if(t[nd->num] > ts[i] && t[nd->anc->num] < ts[i]) // How many lineages are crossing this time slice limit? + { + n++; + if(t[nd->num] < dt) dt = t[nd->num]; // take the oldest node younger than the time slice + } + } + dt -= ts[i]; + loglk += log(n*lbda) - n*lbda*dt; + } + + /* printf("\n1 loglk = %f",loglk); */ + + Free(interrupted); + + return loglk; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Returns the conditional density of internal node heights +// given the tree height under the Yule model. Uses the order +// statistics 'simplification' as described in Yang and Rannala, 2005. +phydbl TIMES_Lk_Yule_Order(t_tree *tree) +{ + int j; + phydbl *t,*tf; + t_node *n; + phydbl loglk; + phydbl loglbda; + phydbl lbda; + phydbl *tp_min,*tp_max; + phydbl lower_bound,upper_bound; + /* phydbl root_height; */ + + tp_min = tree->rates->t_prior_min; + tp_max = tree->rates->t_prior_max; + tf = tree->rates->t_floor; + t = tree->rates->nd_t; + n = NULL; + loglbda = log(tree->rates->birth_rate); + lbda = tree->rates->birth_rate; + lower_bound = -1.; + upper_bound = -1.; + /* root_height = FABS(tree->rates->nd_t[tree->n_root->num]); */ + + /*! Adapted from Equation (6) in T. Stadler's Systematic Biology, 2012 paper with + sampling fraction set to 1 and death rate set to 0. Dropped the 1/(n-1) scaling + factor. */ + + /* loglk = 0.0; */ + /* For(j,2*tree->n_otu-2) */ + /* { */ + /* n = tree->a_nodes[j]; */ + /* lower_bound = MAX(FABS(tf[j]),FABS(tp_max[j])); */ + /* upper_bound = MIN(FABS(t[tree->n_root->num]),FABS(tp_min[j])); */ + + /* if(n->tax == NO) */ + /* { */ + /* loglk += (loglbda - lbda * FABS(t[j])); */ + /* /\* loglk -= log(exp(-lbda*lower_bound) - exp(-lbda*upper_bound)); // incorporate calibration boundaries here. *\/ */ + /* } */ + /* } */ + + + /*! Adapted from Equation (7) in T. Stadler's Systematic Biology, 2012 paper with + sampling fraction set to 1 and death rate set to 0. */ + + // Check that each node is within its calibration-derived interval + For(j,2*tree->n_otu-1) if(t[j] < tp_min[j] || t[j] > tp_max[j]) return(-INFINITY); + + loglk = 0.0; + For(j,2*tree->n_otu-2) + { + n = tree->a_nodes[j]; + lower_bound = MAX(FABS(tf[j]),FABS(tp_max[j])); + upper_bound = FABS(tp_min[j]); + + if(n->tax == NO) + { + loglk += (loglbda - lbda * FABS(t[j])); + loglk -= log(exp(-lbda*lower_bound) - exp(-lbda*upper_bound)); // incorporate calibration boundaries here. + } + + if(isinf(loglk) || isnan(loglk)) + { + /* PhyML_Printf("\n. Lower bound: %f",lower_bound); */ + /* PhyML_Printf("\n. Upper bound: %f",upper_bound); */ + /* PhyML_Printf("\n. tf: %f tp_max: %f tp_min: %f ",tf[j],tp_max[j],tp_min[j]); */ + /* PhyML_Printf("\n. exp1: %f",exp(-lbda*lower_bound)); */ + /* PhyML_Printf("\n. exp2: %f",exp(-lbda*upper_bound)); */ + /* PhyML_Printf("\n. diff: %f",exp(-lbda*lower_bound) - exp(-lbda*upper_bound)); */ + /* Exit("\n"); */ + return(-INFINITY); + } + } + + lower_bound = MAX(FABS(tf[tree->n_root->num]),FABS(tp_max[tree->n_root->num])); + upper_bound = FABS(tp_min[tree->n_root->num]); + loglk += log(2) + loglbda - 2.*lbda * FABS(t[tree->n_root->num]); + loglk -= log(exp(-2.*lbda*lower_bound) - exp(-2.*lbda*upper_bound)); + + if(isinf(loglk) || isnan(loglk)) + { + /* PhyML_Printf("\n. * Lower bound: %f",lower_bound); */ + /* PhyML_Printf("\n. * Upper bound: %f",upper_bound); */ + /* PhyML_Printf("\n. * tf: %f tp_max: %f tp_min: %f",tf[tree->n_root->num],tp_max[tree->n_root->num],tp_min[tree->n_root->num]); */ + /* PhyML_Printf("\n. * exp1: %f",exp(-2.*lbda*lower_bound)); */ + /* PhyML_Printf("\n. * exp2: %f",exp(-2.*lbda*upper_bound)); */ + /* PhyML_Printf("\n. * diff: %f",exp(-2.*lbda*lower_bound) - exp(-2.*lbda*upper_bound)); */ + /* Exit("\n"); */ + return(-INFINITY); + } + + + return(loglk); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl TIMES_Lk_Times(int verbose, t_tree *tree) +{ + DATE_Assign_Primary_Calibration(tree); + DATE_Update_T_Prior_MinMax(tree); + tree->rates->c_lnL_times = TIMES_Lk_Birth_Death(verbose,tree); + return(tree->rates->c_lnL_times); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Lk_Times_Trav(t_node *a, t_node *d, phydbl lim_inf, phydbl lim_sup, phydbl *logdens, t_tree *tree) +{ + int i; + + if(!d->tax) + { + /* if(tree->rates->nd_t[d->num] > lim_sup) */ + /* { */ + /* lim_inf = lim_sup; */ + /* lim_sup = 0.0; */ + /* For(i,2*tree->n_otu-2) */ + /* if((tree->rates->t_floor[i] < lim_sup) && (tree->rates->t_floor[i] > tree->rates->nd_t[d->num])) */ + /* lim_sup = tree->rates->t_floor[i]; */ + /* } */ + + /* if(tree->rates->nd_t[d->num] < lim_inf || tree->rates->nd_t[d->num] > lim_sup) */ + /* { */ + /* PhyML_Printf("\n. nd_t = %f lim_inf = %f lim_sup = %f",tree->rates->nd_t[d->num],lim_inf,lim_sup); */ + /* PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); */ + /* Exit("\n"); */ + /* } */ + + lim_inf = tree->rates->nd_t[tree->n_root->num]; + lim_sup = tree->rates->t_floor[d->num]; + + *logdens = *logdens + log(lim_sup - lim_inf); + } + + if(d->tax == YES) return; + else + { + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + TIMES_Lk_Times_Trav(d,d->v[i],lim_inf,lim_sup,logdens,tree); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl TIMES_Log_Number_Of_Ranked_Labelled_Histories(t_node *root, int per_slice, t_tree *tree) +{ + int i; + phydbl logn; + t_node *v1,*v2; + int n1,n2; + + TIMES_Update_Curr_Slice(tree); + + logn = .0; + v1 = v2 = NULL; + if(root == tree->n_root) + { + TIMES_Log_Number_Of_Ranked_Labelled_Histories_Post(root,root->v[2],per_slice,&logn,tree); + TIMES_Log_Number_Of_Ranked_Labelled_Histories_Post(root,root->v[1],per_slice,&logn,tree); + v1 = root->v[2]; + v2 = root->v[1]; + } + else + { + for(i=0;i<3;i++) + { + if(root->v[i] != root->anc && root->b[i] != tree->e_root) + { + TIMES_Log_Number_Of_Ranked_Labelled_Histories_Post(root,root->v[i],per_slice,&logn,tree); + if(!v1) v1 = root->v[i]; + else v2 = root->v[i]; + } + } + } + + + if(per_slice == NO) + { + n1 = tree->rates->n_tips_below[v1->num]; + n2 = tree->rates->n_tips_below[v2->num]; + } + else + { + if(tree->rates->curr_slice[v1->num] == tree->rates->curr_slice[root->num]) + n1 = tree->rates->n_tips_below[v1->num]; + else + n1 = 1; + + if(tree->rates->curr_slice[v2->num] == tree->rates->curr_slice[root->num]) + n2 = tree->rates->n_tips_below[v2->num]; + else + n2 = 1; + } + + tree->rates->n_tips_below[root->num] = n1+n2; + + logn += Factln(n1+n2-2) - Factln(n1-1) - Factln(n2-1); + + return(logn); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Log_Number_Of_Ranked_Labelled_Histories_Post(t_node *a, t_node *d, int per_slice, phydbl *logn, t_tree *tree) +{ + if(d->tax == YES) + { + tree->rates->n_tips_below[d->num] = 1; + return; + } + else + { + int i,n1,n2; + t_node *v1, *v2; + + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + TIMES_Log_Number_Of_Ranked_Labelled_Histories_Post(d,d->v[i],per_slice,logn,tree); + } + } + + v1 = v2 = NULL; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(v1 == NULL) {v1 = d->v[i];} + else {v2 = d->v[i];} + } + } + + + if(per_slice == NO) + { + n1 = tree->rates->n_tips_below[v1->num]; + n2 = tree->rates->n_tips_below[v2->num]; + } + else + { + if(tree->rates->curr_slice[v1->num] == tree->rates->curr_slice[d->num]) + n1 = tree->rates->n_tips_below[v1->num]; + else + n1 = 1; + + if(tree->rates->curr_slice[v2->num] == tree->rates->curr_slice[d->num]) + n2 = tree->rates->n_tips_below[v2->num]; + else + n2 = 1; + } + + tree->rates->n_tips_below[d->num] = n1+n2; + + (*logn) += Factln(n1+n2-2) - Factln(n1-1) - Factln(n2-1); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Update_Curr_Slice(t_tree *tree) +{ + int i,j; + + For(i,2*tree->n_otu-1) + { + for(j=0;jrates->n_time_slices;j++) + { + if(!(tree->rates->nd_t[i] > tree->rates->time_slice_lims[j])) break; + } + tree->rates->curr_slice[i] = j; + + /* PhyML_Printf("\n. Node %3d [%12f] is in slice %3d.",i,tree->rates->nd_t[i],j); */ + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl TIMES_Lk_Uniform_Core(t_tree *tree) +{ + phydbl logn; + + logn = TIMES_Log_Number_Of_Ranked_Labelled_Histories(tree->n_root,YES,tree); + + tree->rates->c_lnL_times = 0.0; + TIMES_Lk_Uniform_Post(tree->n_root,tree->n_root->v[2],tree); + TIMES_Lk_Uniform_Post(tree->n_root,tree->n_root->v[1],tree); + + /* printf("\n. ^ %f %f %f", */ + /* (phydbl)(tree->rates->n_tips_below[tree->n_root->num]-2.), */ + /* log(tree->rates->time_slice_lims[tree->rates->curr_slice[tree->n_root->num]] - */ + /* tree->rates->nd_t[tree->n_root->num]), */ + /* (phydbl)(tree->rates->n_tips_below[tree->n_root->num]-2.) * */ + /* log(tree->rates->time_slice_lims[tree->rates->curr_slice[tree->n_root->num]] - */ + /* tree->rates->nd_t[tree->n_root->num])); */ + + tree->rates->c_lnL_times += + Factln(tree->rates->n_tips_below[tree->n_root->num]-2.) - + (phydbl)(tree->rates->n_tips_below[tree->n_root->num]-2.) * + log(tree->rates->time_slice_lims[tree->rates->curr_slice[tree->n_root->num]] - + tree->rates->nd_t[tree->n_root->num]); + + tree->rates->c_lnL_times -= logn; + + return(tree->rates->c_lnL_times); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Get_Number_Of_Time_Slices(t_tree *tree) +{ + int i; + + tree->rates->n_time_slices=0; + TIMES_Get_Number_Of_Time_Slices_Post(tree->n_root,tree->n_root->v[2],tree); + TIMES_Get_Number_Of_Time_Slices_Post(tree->n_root,tree->n_root->v[1],tree); + Qksort(tree->rates->time_slice_lims,NULL,0,tree->rates->n_time_slices-1); + + if(tree->rates->n_time_slices > 1) + { + PhyML_Printf("\n"); + PhyML_Printf("\n. Sequences were collected at %d different time points.",tree->rates->n_time_slices); + for(i=0;irates->n_time_slices;i++) printf("\n+ [%3d] time point @ %12f ",i+1,tree->rates->time_slice_lims[i]); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Get_Number_Of_Time_Slices_Post(t_node *a, t_node *d, t_tree *tree) +{ + int i; + + if(d->tax == YES) + { + for(i=0;irates->n_time_slices;i++) + if(Are_Equal(tree->rates->t_floor[d->num],tree->rates->time_slice_lims[i],1.E-6)) break; + + if(i == tree->rates->n_time_slices) + { + tree->rates->time_slice_lims[i] = tree->rates->t_floor[d->num]; + tree->rates->n_time_slices++; + } + return; + } + else + { + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + TIMES_Get_Number_Of_Time_Slices_Post(d,d->v[i],tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Get_N_Slice_Spans(t_tree *tree) +{ + int i,j; + + For(i,2*tree->n_otu-2) + { + if(tree->a_nodes[i]->tax == NO) + { + for(j=0;jrates->n_time_slices;j++) + { + if(Are_Equal(tree->rates->t_floor[i],tree->rates->time_slice_lims[j],1.E-6)) + { + tree->rates->n_time_slice_spans[i] = j+1; + /* PhyML_Printf("\n. Node %3d spans %3d slices [%12f].", */ + /* i+1, */ + /* tree->rates->n_slice_spans[i], */ + /* tree->rates->t_floor[i]); */ + break; + } + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Lk_Uniform_Post(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax == YES) return; + else + { + int i; + + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + TIMES_Lk_Uniform_Post(d,d->v[i],tree); + } + } + + if(tree->rates->curr_slice[a->num] != tree->rates->curr_slice[d->num]) + { + tree->rates->c_lnL_times += + Factln(tree->rates->n_tips_below[d->num]-1.) - + (phydbl)(tree->rates->n_tips_below[d->num]-1.) * + log(tree->rates->time_slice_lims[tree->rates->curr_slice[d->num]] - + tree->rates->nd_t[d->num]); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Set the root position so that most of the taxa in the outgroup + correspond to the most ancient time point. +*/ +void TIMES_Set_Root_Given_Tip_Dates(t_tree *tree) +{ + int i,j; + t_node *left,*rght; + int n_left_in, n_left_out; + int n_rght_in, n_rght_out; + t_edge *b,*best; + phydbl eps,score,max_score; + + Free_Bip(tree); + Alloc_Bip(tree); + Get_Bip(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + + left = rght = NULL; + b = best = NULL; + n_left_in = n_left_out = -1; + n_rght_in = n_rght_out = -1; + eps = 1.E-6; + score = max_score = -1.; + + For(i,2*tree->n_otu-3) + { + left = tree->a_edges[i]->left; + rght = tree->a_edges[i]->rght; + b = tree->a_edges[i]; + + n_left_in = 0; + For(j,left->bip_size[b->l_r]) + if(FABS(tree->rates->nd_t[left->bip_node[b->l_r][j]->num] - tree->rates->time_slice_lims[0]) < eps) + n_left_in++; + + n_left_out = left->bip_size[b->l_r]-n_left_in; + + n_rght_in = 0; + For(j,rght->bip_size[b->r_l]) + if(FABS(tree->rates->nd_t[rght->bip_node[b->r_l][j]->num] - tree->rates->time_slice_lims[0]) < eps) + n_rght_in++; + + n_rght_out = rght->bip_size[b->r_l]-n_rght_in; + + + /* score = POW((phydbl)(n_left_in)/(phydbl)(n_left_in+n_left_out)- */ + /* (phydbl)(n_rght_in)/(phydbl)(n_rght_in+n_rght_out),2); */ + /* score = (phydbl)(n_left_in * n_rght_out + eps)/(n_left_out * n_rght_in + eps); */ + /* score = (phydbl)(n_left_in * n_rght_out + eps); */ + score = FABS((phydbl)((n_left_in+1.) * (n_rght_out+1.)) - (phydbl)((n_left_out+1.) * (n_rght_in+1.))); + + if(score > max_score) + { + max_score = score; + best = b; + } + } + + Add_Root(best,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Get_Survival_Duration(t_tree *tree) +{ + Get_Survival_Duration_Post(tree->n_root,tree->n_root->v[2],tree); + Get_Survival_Duration_Post(tree->n_root,tree->n_root->v[1],tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Get_Survival_Duration_Post(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax) + { + tree->rates->survival_dur[d->num] = tree->rates->nd_t[d->num]; + return; + } + else + { + int i; + t_node *v1, *v2; + + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + Get_Survival_Duration_Post(d,d->v[i],tree); + + v1 = v2 = NULL; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(!v1) v1 = d->v[i]; + else v2 = d->v[i]; + } + } + + tree->rates->survival_dur[d->num] = MAX(tree->rates->survival_dur[v1->num], + tree->rates->survival_dur[v2->num]); + } +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Update the ranking of node heights. Use bubble sort algorithm */ +/* t_rank[i] is the node number that has rank i */ + +void TIMES_Update_Node_Ordering(t_tree *tree) +{ + int buff; + int i; + phydbl *t; + int swap = NO; + + for(i=0;i<2*tree->n_otu-1;++i) tree->rates->t_rank[i] = i; + + t = tree->rates->nd_t; + + do + { + swap = NO; + for(i=0;i<2*tree->n_otu-2;++i) + { + if(t[tree->rates->t_rank[i]] > t[tree->rates->t_rank[i+1]]) // Sort in ascending order + { + swap = YES; + buff = tree->rates->t_rank[i]; + tree->rates->t_rank[i] = tree->rates->t_rank[i+1]; + tree->rates->t_rank[i+1] = buff; + } + } + } + while(swap == YES); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIMES_Set_Calibration(t_tree *tree) +{ + t_cal *cal; + int i; + + For(i,2*tree->n_otu-1) + { + tree->rates->t_has_prior[i] = NO; + tree->rates->t_prior_min[i] = BIG; + tree->rates->t_prior_max[i] = BIG; + } + + cal = tree->rates->a_cal[0]; + while(cal) + { + /* if(cal->is_active == YES) */ + /* { */ + /* tree->rates->t_has_prior[cal->node_num] = YES; */ + /* tree->rates->t_prior_min[cal->node_num] = cal->lower; */ + /* tree->rates->t_prior_max[cal->node_num] = cal->upper; */ + /* } */ + cal = cal->next; + } + + TIMES_Set_All_Node_Priors(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Record_Prior_Times(t_tree *tree) +{ + int i; + for(i=0;i<2*tree->n_otu-1;++i) + { + tree->rates->t_prior_min_ori[i] = tree->rates->t_prior_min[i]; + tree->rates->t_prior_max_ori[i] = tree->rates->t_prior_max[i]; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Reset_Prior_Times(t_tree *tree) +{ + int i; + For(i,2*tree->n_otu-1) + { + tree->rates->t_prior_min[i] = tree->rates->t_prior_min_ori[i]; + tree->rates->t_prior_max[i] = tree->rates->t_prior_max_ori[i]; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Returns the conditional density of internal node heights +// given the tree height under the Yule model. Uses the order +// statistics 'simplification' as described in Yang and Rannala, 2005. +phydbl TIMES_Lk_Yule_Order_Root_Cond(t_tree *tree) +{ + int j; + phydbl *t,*tf; + t_node *n; + phydbl loglk; + phydbl loglbda; + phydbl lbda; + phydbl *tp_min,*tp_max; + phydbl lower_bound,upper_bound; + phydbl root_height; + + tp_min = tree->rates->t_prior_min; + tp_max = tree->rates->t_prior_max; + tf = tree->rates->t_floor; + t = tree->rates->nd_t; + n = NULL; + loglbda = log(tree->rates->birth_rate); + lbda = tree->rates->birth_rate; + lower_bound = -1.; + upper_bound = -1.; + root_height = FABS(tree->rates->nd_t[tree->n_root->num]); + + /*! Adapted from Equation (6) in T. Stadler's Systematic Biology, 2012 paper with + sampling fraction set to 1 and death rate set to 0. Dropped the 1/(n-1) scaling + factor. */ + + /* loglk = 0.0; */ + /* For(j,2*tree->n_otu-2) */ + /* { */ + /* n = tree->a_nodes[j]; */ + /* lower_bound = MAX(FABS(tf[j]),FABS(tp_max[j])); */ + /* upper_bound = MIN(FABS(t[tree->n_root->num]),FABS(tp_min[j])); */ + + /* if(n->tax == NO) */ + /* { */ + /* loglk += (loglbda - lbda * FABS(t[j])); */ + /* /\* loglk -= log(exp(-lbda*lower_bound) - exp(-lbda*upper_bound)); // incorporate calibration boundaries here. *\/ */ + /* } */ + /* } */ + + + /*! Adapted from Equation (7) in T. Stadler's Systematic Biology, 2012 paper with + sampling fraction set to 1 and death rate set to 0. */ + + // Check that each node is within its calibration-derived interval + For(j,2*tree->n_otu-1) if(t[j] < tp_min[j] || t[j] > tp_max[j]) return(-INFINITY); + + loglk = 0.0; + For(j,2*tree->n_otu-2) + { + n = tree->a_nodes[j]; + lower_bound = MAX(FABS(tf[j]),FABS(tp_max[j])); + upper_bound = MIN(FABS(tp_min[j]),root_height); + + if(n->tax == NO) + { + loglk += (loglbda - lbda * FABS(t[j])); + loglk -= log(exp(-lbda*lower_bound) - exp(-lbda*upper_bound)); // incorporate calibration boundaries here. + } + + if(isinf(loglk) || isnan(loglk)) + { + PhyML_Fprintf(stderr,"\n. Lower bound: %f",lower_bound); + PhyML_Fprintf(stderr,"\n. Upper bound: %f",upper_bound); + PhyML_Fprintf(stderr,"\n. tf: %f tp_max: %f tp_min: %f root: %f",tf[j],tp_max[j],tp_min[j],root_height); + Exit("\n"); + } + + } + + /* lower_bound = MAX(FABS(tf[tree->n_root->num]),FABS(tp_max[tree->n_root->num])); */ + /* upper_bound = FABS(tp_min[tree->n_root->num]); */ + /* loglk += log(2) + loglbda - 2.*lbda * FABS(t[tree->n_root->num]); */ + /* loglk -= log(exp(-2.*lbda*lower_bound) - exp(-2.*lbda*upper_bound)); */ + + + return(loglk); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Log of prob density of internal node ages conditional on tree height, under +// the birth death process with incomplete sampling. +phydbl TIMES_Lk_Birth_Death(int verbose, t_tree *tree) +{ + int i,n; + phydbl lnL; + phydbl t,b,d,bmd,logbmd,expmbmd,logb; + phydbl bmin,bmax; + phydbl dmin,dmax; + phydbl lognut1,logp_1t,troot,pt,nut1; + + lnL = 0.0; + b = tree->rates->birth_rate; + d = tree->rates->death_rate; + bmin = tree->rates->birth_rate_min; + bmax = tree->rates->birth_rate_max; + dmin = tree->rates->death_rate_min; + dmax = tree->rates->death_rate_max; + bmd = b-d; + logbmd = -1.; + expmbmd = -1.; + logb = -1.; + t = 0.0; + n = tree->n_otu; + troot = fabs(tree->rates->nd_t[tree->n_root->num]); + logb = log(b); + + if(b < d) + { + tree->rates->c_lnL_times = UNLIKELY; + if(verbose) PhyML_Printf("\n. b < d"); + return UNLIKELY; + } + + // Verify that calibration constraints are satisfied + for(i=0;i<2*tree->n_otu-1;++i) + if(tree->a_nodes[i]->tax == NO) + { + if(tree->rates->nd_t[i] < tree->rates->t_prior_min[i] || + tree->rates->nd_t[i] > tree->rates->t_prior_max[i]) + { + tree->rates->c_lnL_times = UNLIKELY; + if(verbose) + { + PhyML_Printf("\n. Time outside calibration range : %G [%G,%G]",tree->rates->nd_t[i],tree->rates->t_prior_min[i],tree->rates->t_prior_max[i]); + PhyML_Printf("\n. Clade incriminated: "); + if(tree->a_nodes[i] == tree->n_root) + { + List_Taxa_In_Clade(tree->n_root,tree->n_root->v[1],tree); + List_Taxa_In_Clade(tree->n_root,tree->n_root->v[2],tree); + } + else + { + assert(tree->a_nodes[i]->anc); + List_Taxa_In_Clade(tree->a_nodes[i]->anc,tree->a_nodes[i],tree); + } + PhyML_Printf("\n"); + } + return UNLIKELY; + } + } + + if(b > bmin && d > dmin && Are_Equal(bmd,0.0,bmin/10.) == NO) + { + logbmd = log(bmd); + expmbmd = exp(d-b); + + pt = bmd/(b-d*pow(expmbmd,troot)); + nut1 = 1. - pt*pow(expmbmd,troot); + lognut1 = log(nut1); + /* printf("\n. lognut1: %G pt: %G b: %G d: %G exp: %G",nut1,pt,b,d,expmbmd); fflush(NULL); */ + + for(i=0;i<2*tree->n_otu-1;++i) + if(tree->a_nodes[i]->tax == NO && tree->a_nodes[i] != tree->n_root) + { + t = fabs(tree->rates->nd_t[i]); + + /* // Equation 3.19 in Tanja Stadler's PhD thesis */ + /* lnL += 2*logbmd - bmd*t - 2.*log(b-d*pow(expmbmd,t)); */ + + // Equation 6 in Yang and Rannala, 1997 with rho=1 + logp_1t = 2.*logbmd - 2.*log(b-d*exp((d-b)*t)) + (d-b)*t; + lnL += logb + logp_1t - lognut1; + + + if(!(lnL > UNLIKELY)) + { + PhyML_Printf("\n. logb: %G pt: %G nut1: %G lognut1: %G t: %G logp_1t: %G\n",logb,pt,nut1,lognut1,t,logp_1t); + tree->rates->c_lnL_times = UNLIKELY; + return UNLIKELY; + } + } + + lnL += LnGamma(n-1); + + + /* t = FABS(tree->rates->nd_t[tree->n_root->num]); */ + /* lnL += -bmd*t - log(b-d*pow(expmbmd,t)); */ + /* lnL += log(bmd) + (tree->n_otu-1)*log(b) + LnGamma(tree->n_otu+1); */ + + // Divide joint density p(x(1),...,x(n-1)) by p(x(1)) in order to get + // the conditional density p(x(2),...,x(n-1)|x(1)). The log of the marginal p(x(1)) + // (Theorem 3.4.11 in Tanja's PhD thesis) is given below and subtracted to lnL. + /* k = 1; */ + /* s = FABS(tree->rates->nd_t[tree->n_root->num]); */ + /* phydbl p_x1 = (k+1)*Choose(n,k+1)*pow(b,n-k)*pow(bmd,k+2)*exp(-bmd*(k+1)*s)*pow(1.-exp(-bmd*s),n-k-1)/pow(b-d*exp(-bmd*s),n+1); */ + /* lnL -= log(p_x1); */ + } + else if(b > bmin && d < dmin) // Yule process + { + lognut1 = log(1.-exp(-b*troot)); + + for(i=0;i<2*tree->n_otu-1;++i) + if(tree->a_nodes[i]->tax == NO && tree->a_nodes[i] != tree->n_root) + { + t = fabs(tree->rates->nd_t[i]); + /* // Equation 3.19 in Tanja Stadler's PhD thesis (Yule case) */ + /* lnL -= b*t; */ + + // Equation 6 in Yang and Rannala, 1997 with rho=1 + logp_1t = - b*t; + lnL += logb + logp_1t - lognut1; + + if(!(lnL > UNLIKELY)) + { + PhyML_Printf("\n. lognut1: %G t: %G logp_1t: %G",lognut1,t,logp_1t); + tree->rates->c_lnL_times = UNLIKELY; + return UNLIKELY; + } + } + + lnL += LnGamma(n-1); + + /* t = fabs(tree->rates->nd_t[tree->n_root->num]); */ + /* lnL -= b*t; */ + /* lnL += (tree->n_otu-1)*log(b) + LnGamma(tree->n_otu+1); */ + + + // Divide joint density p(x(1),...,x(n-1)) by p(x(1)) in order to get + // the conditional density p(x(2),...,x(n-1)|x(1)). The log of the marginal p(x(1)) + // (Theorem 3.4.11, remark 3.4.12 in Tanja's PhD thesis) is given below and subtracted to lnL. + /* k = 1; */ + /* s = FABS(tree->rates->nd_t[tree->n_root->num]); */ + /* phydbl p_x1 = (k+1)*Choose(n,k+1)*b*pow(exp(b*s)-1.,n-k-1)/exp(b*s*n); */ + /* lnL -= log(p_x1); */ + } + else if(b < bmin && d > dmin) + { + PhyML_Printf("\n. b: %G bmin: %G d: %G dmin: %G",b,bmin,d,dmin); + tree->rates->c_lnL_times = UNLIKELY; + return UNLIKELY; + } + else if(Are_Equal(bmd,0.0,bmin/10.) == YES) // Critical birth-death process + { + logb = log(b); + + for(i=0;i<2*tree->n_otu-1;++i) + if(tree->a_nodes[i]->tax == NO && tree->a_nodes[i] != tree->n_root) + { + t = fabs(tree->rates->nd_t[i]); + + /* // Equation 3.19 in Tanja Stadler's PhD thesis (Critical case) */ + /* lnL += logb - 2.*log(1.+b*t); */ + + + // Equation 7 in Yang and Rannala, 1997 with rho=1 + lnL += log((1.+d)/pow(1.+d*t,2)); + + if(!(lnL > UNLIKELY)) + { + PhyML_Printf("\n. logb: %G t: %G",logb,t); + tree->rates->c_lnL_times = UNLIKELY; + return UNLIKELY; + } + } + + lnL += LnGamma(n-1); + + /* t = fabs(tree->rates->nd_t[tree->n_root->num]); */ + /* lnL -= log(b*t); */ + /* lnL += LnGamma(tree->n_otu+1); */ + + // Divide joint density p(x(1),...,x(n-1)) by p(x(1)) in order to get + // the conditional density p(x(2),...,x(n-1)|x(1)). The log of the marginal p(x(1)) + // (Theorem 3.4.11, remark 3.4.12 in Tanja's PhD thesis) is given below and subtracted to lnL. + /* k = 1; */ + /* s = fabs(tree->rates->nd_t[tree->n_root->num]); */ + /* phydbl p_x1 = (k+1)*Choose(n,k+1)*pow(b,n-k)*pow(s,n-k-1)/pow(1.+b*s,n+1); */ + /* lnL -= log(p_x1); */ + } + else if(b < bmin && d < dmin) // Birth and death rates are below their limits + { + PhyML_Fprintf(stderr,"\n. b: %G bmin: %G d: %G dmin: %G",b,bmin,d,dmin); + tree->rates->c_lnL_times = UNLIKELY; + return -INFINITY; + } + else if(b > bmax && d > dmax) + { + PhyML_Fprintf(stderr,"\n. b: %G bmax: %G d: %G dmax: %G",b,bmax,d,dmax); + tree->rates->c_lnL_times = UNLIKELY; + return -INFINITY; + } + else + { + assert(FALSE); + } + + if(isnan(lnL) || isinf(fabs(lnL)) || !(lnL > UNLIKELY)) + { + PhyML_Fprintf(stderr,"\n. lnL times: %f",lnL); + tree->rates->c_lnL_times = UNLIKELY; + return UNLIKELY; + } + + tree->rates->c_lnL_times = lnL; + + return(lnL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +// Generate a subtree including all taxa in tax_list. The age of the root of that +// subtree is t_mrca. All nodes in the subtree are thus younger than that. +void TIMES_Connect_List_Of_Taxa(t_node **tax_list, int list_size, phydbl t_mrca, phydbl *times, int *nd_num, t_tree *mixt_tree) +{ + phydbl t_upper_bound, t_lower_bound,up,lo; + int i,j,n_anc,*permut,rand_idx; + t_node *n,**anc,*new_mrca; + + // Calibration of a tip node + if(list_size == 1) + { + times[tax_list[0]->num] = t_mrca; + return; + } + else + { + t_lower_bound = t_mrca; + t_upper_bound = +INFINITY; + n = NULL; + anc = NULL; + new_mrca = NULL; + permut = NULL; + + // Find the upper bound for all the new node ages that + // will be created in this function + for(i=0;iv[0] != NULL) n = n->v[0]; + if(times[n->num] < t_upper_bound) t_upper_bound = times[n->num]; + } + + if(t_upper_bound < t_lower_bound) + { + PhyML_Printf("\n. upper: %f lower: %f t_mrca: %f\n",t_upper_bound,t_lower_bound,t_mrca); + assert(FALSE); + } + + // Get the list of current mrcas to all taxa in tax_list. There should be + // at least one of these + n_anc = 0; + for(i=0;iv[0] != NULL) n = n->v[0]; + for(j=0;jnum); */ + + if(n_anc == 1) // All the nodes in tax_list are already connected. Bail out. + { + Free(anc); + return; + } + + // Connect randomly and set ages + permut = Permutate(n_anc); + /* permut = (int *)mCalloc(n_anc,sizeof(int)); */ + /* for(i=0;ia_nodes[*nd_num]; + anc[permut[i]]->v[0] = new_mrca; + anc[permut[i+1]]->v[0] = new_mrca; + new_mrca->v[1] = anc[permut[i]]; + new_mrca->v[2] = anc[permut[i+1]]; + new_mrca->v[0] = NULL; + up = MIN(times[new_mrca->v[1]->num],times[new_mrca->v[2]->num]); + lo = up - (up - t_mrca)/5.; + times[new_mrca->num] = Uni()*(up - lo) + lo; + + /* times[new_mrca->num] = t_upper_bound - ((phydbl)(i+1.)/n_anc)*(t_upper_bound - t_lower_bound); */ + + /* printf("\n. new_mrca->num: %d time: %f [%f %f] t_mrca: %f %d connect to %d %d %d [%f %f]", */ + /* new_mrca->num, */ + /* times[new_mrca->num], */ + /* t_lower_bound, */ + /* t_upper_bound, */ + /* t_mrca, */ + /* new_mrca->num, */ + /* new_mrca->v[0] ? new_mrca->v[0]->num : -1, */ + /* new_mrca->v[1] ? new_mrca->v[1]->num : -1, */ + /* new_mrca->v[2] ? new_mrca->v[2]->num : -1, */ + /* times[new_mrca->v[1]->num], */ + /* times[new_mrca->v[2]->num] */ + /* ); */ + /* fflush(NULL); */ + + anc[permut[i+1]] = new_mrca; + + rand_idx = Rand_Int(i+1,n_anc-1); + n = anc[permut[i+1]]; + anc[permut[i+1]] = anc[permut[rand_idx]]; + anc[permut[rand_idx]] = n; + + + i++; + (*nd_num) += 1; + if(n_anc == i+1) { times[new_mrca->num] = t_mrca; break; } + } + while(1); + + Free(permut); + Free(anc); + } +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Generate a random rooted tree with node ages fullfiling the +// time constraints defined in the list of calibration cal_list +void TIMES_Randomize_Tree_With_Time_Constraints(t_cal *cal_list, t_tree *mixt_tree) +{ + t_node **tips,**nd_list; + phydbl *times,*cal_times,time_oldest_cal; + int i,j,nd_num,*cal_ordering,n_cal,swap,list_size,tmp,orig_is_mixt_tree,repeat,n_max_repeats,tip_num,*no_cal_tip_num,n_no_cal_tip_num,*permut,*tip_is_in_cal_clad; + t_cal *cal; + t_clad *clade; + + assert(mixt_tree->rates); + + if(mixt_tree->mod->s_opt->opt_topo == NO) + { + PhyML_Fprintf(stderr,"\n. Fixing the tree topology is only allowed when calibrating tip nodes only."); + PhyML_Fprintf(stderr,"\n. You are most likely calibrating here the MRCA of at least one clade with more than two tips."); + PhyML_Fprintf(stderr,"\n. It is difficult to set the age of that clade within the limit of the calibration constraints,"); + PhyML_Fprintf(stderr,"\n. and fix the tree topology at the same time. Please contact me (guindon@lirmm.fr) for a more"); + PhyML_Fprintf(stderr,"\n. detailed diagnostic."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + tips = (t_node **)mCalloc(mixt_tree->n_otu,sizeof(t_node *)); + nd_list = (t_node **)mCalloc(2*mixt_tree->n_otu-1,sizeof(t_node *)); + tip_is_in_cal_clad = (int *)mCalloc(mixt_tree->n_otu,sizeof(t_node *)); + + times = mixt_tree->rates->nd_t; + orig_is_mixt_tree = mixt_tree->is_mixt_tree; + mixt_tree->is_mixt_tree = NO; + n_max_repeats = 1000; + cal = NULL; + clade = NULL; + + + // Is tip in calibrated clade or not? + for(i=0;in_otu;++i) + { + cal = cal_list; + clade = NULL; + while(cal != NULL) + { + while(cal && cal->clade_list == NULL) cal = cal->next; + if(cal == NULL) break; + clade = cal->clade_list[cal->current_clade_idx]; + for(j=0;jn_tax;++j) if(clade->tip_list[j] == mixt_tree->a_nodes[i]) break; + if(j != clade->n_tax) break; + cal = cal->next; + } + + if(cal != NULL) tip_is_in_cal_clad[i] = YES; + else tip_is_in_cal_clad[i] = NO; + } + + // List node indices that are not in any calibration set + no_cal_tip_num = NULL; + n_no_cal_tip_num = 0; + for(i=0;in_otu;++i) + { + cal = cal_list; + while(cal != NULL) + { + while(cal && cal->clade_list == NULL) cal = cal->next; + if(cal == NULL) break; + clade = cal->clade_list[cal->current_clade_idx]; + for(j=0;jn_tax;++j) if(clade->tip_list[j] == mixt_tree->a_nodes[i]) break; + if(j != clade->n_tax) break; + cal = cal->next; + } + + if(cal == NULL) + { + if(n_no_cal_tip_num == 0) no_cal_tip_num = (int *)mCalloc(1,sizeof(int)); + else no_cal_tip_num = (int *)mRealloc(no_cal_tip_num,n_no_cal_tip_num+1,sizeof(int)); + no_cal_tip_num[n_no_cal_tip_num] = i; + n_no_cal_tip_num++; + } + } + + + for(repeat=0;repeatn_otu; + + /* PhyML_Printf("\n\n. Repeat %d",repeat); */ + + for(i=0;in_otu;++i) tips[i] = mixt_tree->a_nodes[i]; + for(i=0;in_otu;++i) mixt_tree->a_nodes[i]->v[0] = NULL; + + + // Set a time for each calibration + cal_times = (phydbl *)mCalloc(1,sizeof(phydbl)); + time_oldest_cal = 0.0; + n_cal = 0; + cal = cal_list; + while(cal != NULL) + { + if(cal->is_primary == YES) + { + if(n_cal > 0) cal_times = (phydbl *)mRealloc(cal_times,n_cal+1,sizeof(phydbl)); + cal_times[n_cal] = Uni()*(cal->upper - cal->lower) + cal->lower; + if(cal_times[n_cal] < time_oldest_cal) time_oldest_cal = cal_times[n_cal]; + n_cal++; + } + cal = cal->next; + } + + cal_ordering = (int *)mCalloc(n_cal,sizeof(int)); + for(i=0;iis_primary == YES) j++; + cal = cal->next; + assert(cal); + } + + list_size = 0; + + /* printf("\n. n_cal: %d n_no_cal_tip_num: %d [%d %d] n_otu: %d", */ + /* n_cal, */ + /* n_no_cal_tip_num, */ + /* n_no_cal_tip_num-1, */ + /* (int)(2*n_no_cal_tip_num/(n_cal)), */ + /* mixt_tree->n_otu); fflush(NULL); */ + + // Add some taxa that are not in any calibration set + if(n_no_cal_tip_num > 0) + { + permut = Permutate(n_no_cal_tip_num); + j = 0; + do + { + tip_num = no_cal_tip_num[permut[j]]; + if(tips[tip_num]->v[0] == NULL) + { + nd_list[list_size] = tips[tip_num]; + /* PhyML_Printf("\n# %s",tips[tip_num]->name); */ + list_size++; + assert(list_size <= mixt_tree->n_otu); + } + } + while(j++ < MIN(n_no_cal_tip_num-1,(int)(2*n_no_cal_tip_num/(n_cal)))); + Free(permut); + } + + + // Add all the taxa that are in the calibration set of cal + // This should be done here so that the last node in nd_list + // belongs to the taxa in the calibration + + if(cal->clade_list != NULL) + { + clade = cal->clade_list[cal->current_clade_idx]; + for(j=0;jn_tax;j++) + { + nd_list[list_size] = tips[clade->tip_list[j]->num]; + list_size++; + assert(list_size <= mixt_tree->n_otu); + } + + TIMES_Connect_List_Of_Taxa(nd_list, + list_size, + cal_times[cal_ordering[i]], + times, + &nd_num, + mixt_tree); + } + } + + Free(cal_times); + Free(cal_ordering); + + + // Connect all remaining taxa + for(i=0;in_otu;i++) nd_list[i] = NULL; + list_size = 0; + for(i=0;in_otu;++i) + { + if(tip_is_in_cal_clad[tips[i]->num] == NO) // Tip is not in a calibrated clade + { + nd_list[list_size] = tips[i]; + list_size++; + assert(list_size <= mixt_tree->n_otu); + } + } + + cal = cal_list; + do + { + while(cal && cal->clade_list == NULL) cal = cal->next; + if(cal == NULL) break; + clade = cal->clade_list[cal->current_clade_idx]; + nd_list[list_size] = clade->tip_list[0]; + list_size++; + assert(list_size <= 2*mixt_tree->n_otu-1); + cal = cal->next; + } + while(cal); + + /* for(i=0;inum,time_oldest_cal); */ + + + TIMES_Connect_List_Of_Taxa(nd_list, + list_size, + 10.*time_oldest_cal-1.E-3, // 1.E-3 required in case time_oldest_cal = 0. + times, + &nd_num, + mixt_tree); + + // Adding root node + mixt_tree->n_root = mixt_tree->a_nodes[2*mixt_tree->n_otu-2]; + mixt_tree->n_root->v[1]->v[0] = mixt_tree->n_root->v[2]; + mixt_tree->n_root->v[2]->v[0] = mixt_tree->n_root->v[1]; + mixt_tree->n_root->anc = NULL; + + Connect_Edges_To_Nodes_Serial(mixt_tree); + + + // Adding root edge + for(i=0;i<2*mixt_tree->n_otu-3;++i) + { + if(((mixt_tree->a_edges[i]->left == mixt_tree->n_root->v[1]) || (mixt_tree->a_edges[i]->rght == mixt_tree->n_root->v[1])) && + ((mixt_tree->a_edges[i]->left == mixt_tree->n_root->v[2]) || (mixt_tree->a_edges[i]->rght == mixt_tree->n_root->v[2]))) + { + mixt_tree->e_root = mixt_tree->a_edges[i]; + break; + } + } + + Update_Ancestors(mixt_tree->n_root,mixt_tree->n_root->v[2],mixt_tree); + Update_Ancestors(mixt_tree->n_root,mixt_tree->n_root->v[1],mixt_tree); + DATE_Assign_Primary_Calibration(mixt_tree); + DATE_Update_T_Prior_MinMax(mixt_tree); + + + /* for(int i=0;irates->n_cal;i++) */ + /* { */ + /* int idx; */ + /* cal = mixt_tree->rates->a_cal[i]; */ + + /* if(cal->clade_list != NULL) */ + /* { */ + /* clade = cal->clade_list[cal->current_clade_idx]; */ + /* idx = Find_Clade(clade->tax_list,clade->n_tax,mixt_tree); */ + /* PhyML_Printf("\n. Calibration %3d | Node number to which calibration applies is [%d]",i,idx); */ + /* PhyML_Printf("\n. Calibration %3d | Lower bound set to: %15f time units.",i,mixt_tree->rates->a_cal[i]->lower); */ + /* PhyML_Printf("\n. Calibration %3d | Upper bound set to: %15f time units.",i,mixt_tree->rates->a_cal[i]->upper); */ + /* PhyML_Printf("\n. Calibration %3d | t_prior_min: %G t_prior_max: %G",i,mixt_tree->rates->t_prior_min[idx],mixt_tree->rates->t_prior_max[idx]); */ + /* PhyML_Printf("\n. Calibration %3d | Time set to %G",i,mixt_tree->rates->nd_t[idx]); */ + /* } */ + /* } */ + + if(!DATE_Check_Calibration_Constraints(mixt_tree)) + { + /* PhyML_Printf("\n. Could not generate tree (DATE_Check_Calibration_Constraints)\n\n"); */ + } + else if(!DATE_Check_Time_Constraints(mixt_tree)) + { + /* PhyML_Printf("\n. Could not generate tree (DATE_Check_Time_Constraints)\n\n"); */ + } + else break; // Tree successfully generated + } + + + if(repeat == n_max_repeats) + { + PhyML_Fprintf(stderr,"\n\n"); + PhyML_Fprintf(stderr,"\n. A random tree satisfying the calibration constraints provided"); + PhyML_Fprintf(stderr,"\n. could not be generated. It probably means that there are some"); + PhyML_Fprintf(stderr,"\n. inconsistencies in the calibration data. For instance, the calibration"); + PhyML_Fprintf(stderr,"\n. time interval for the MRCA of a clade with taxa {X,Y} (noted as [a,b])"); + PhyML_Fprintf(stderr,"\n. cannot be strictly older than the interval corresponding to taxa "); + PhyML_Fprintf(stderr,"\n. {X,Z,Y} (noted as [c,d]), i.e., b cannot be smaller (older) than c. "); + PhyML_Fprintf(stderr,"\n. Also, please remember that the present time corresponds to a time"); + PhyML_Fprintf(stderr,"\n. value equal to zero and past events have negative time values."); + + PhyML_Fprintf(stderr,"\n\n"); + if(!DATE_Check_Calibration_Constraints(mixt_tree)) + { + PhyML_Fprintf(stderr,"\n. Could not generate tree (DATE_Check_Calibration_Constraints)\n\n"); + } + else if(!DATE_Check_Time_Constraints(mixt_tree)) + { + PhyML_Fprintf(stderr,"\n. Could not generate tree (DATE_Check_Time_Constraints)\n\n"); + } + + Exit("\n"); + } + + /* assert(i != 2*mixt_tree->n_otu-3); */ + + mixt_tree->is_mixt_tree = orig_is_mixt_tree; + + Free(tips); + Free(nd_list); + Free(no_cal_tip_num); + Free(tip_is_in_cal_clad); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int TIMES_Check_Node_Height_Ordering(t_tree *tree) +{ + if(!TIMES_Check_Node_Height_Ordering_Post(tree->n_root,tree->n_root->v[1],tree)) return NO; + if(!TIMES_Check_Node_Height_Ordering_Post(tree->n_root,tree->n_root->v[2],tree)) return NO; + return YES; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int TIMES_Check_Node_Height_Ordering_Post(t_node *a, t_node *d, t_tree *tree) +{ + + if(d->anc != a) + { + PhyML_Printf("\n. d=%d d->anc=%d a=%d root=%d",d->num,d->anc->num,a->num,tree->n_root->num); + return NO; + } + if(tree->rates->nd_t[d->num] < tree->rates->nd_t[a->num]) + { + PhyML_Printf("\n. a->t = %f [num:%d] d->t %f [num:%d]", + tree->rates->nd_t[a->num], + a->num, + tree->rates->nd_t[d->num], + d->num); + return NO; + } + if(d->tax == YES) return YES; + else + { + int i; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + if(!TIMES_Check_Node_Height_Ordering_Post(d,d->v[i],tree)) + return NO; + } + } + return YES; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* + 2n-2 edge lengths (in a rooted tree), n-1 internal node + ages. Return \sum_i (l_i - delta t_i)^2 where delta t_i is the + calendar time elapsed along the edge of length l_i +*/ +phydbl TIMES_Least_Square_Criterion(t_tree *tree) +{ + phydbl score; + score = 0.0; + assert(tree->n_root); + assert(tree->rates); + TIMES_Pre_Least_Square_Criterion(tree->n_root,tree->n_root->v[1],tree->n_root->b[1],&score,tree); + TIMES_Pre_Least_Square_Criterion(tree->n_root,tree->n_root->v[2],tree->n_root->b[2],&score,tree); + return(score); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Pre_Least_Square_Criterion(t_node *a, t_node *d, t_edge *b, phydbl *score, t_tree *tree) +{ + int i; + + (*score) += pow(b->l->v - fabs(tree->rates->nd_t[a->num] + tree->rates->nd_t[d->num])*tree->rates->clock_r,2); + + if(d->tax) return; + + for(i=0;i<3;++i) + if(d->v[i] != a && d->b[i] != tree->e_root) + TIMES_Pre_Least_Square_Criterion(d,d->v[i],d->b[i],score,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Randomize_Node_Ages(t_tree *tree) +{ + assert(tree->n_root); + assert(tree->rates); + TIMES_Post_Randomize_Node_Ages(tree->n_root,tree->n_root->v[1],tree); + TIMES_Post_Randomize_Node_Ages(tree->n_root,tree->n_root->v[2],tree); + tree->rates->nd_t[tree->n_root->num] = + MIN(tree->rates->nd_t[tree->n_root->v[1]->num], + tree->rates->nd_t[tree->n_root->v[2]->num]) + - Rexp(1.); + /* PhyML_Printf("\n. RAND TIMES node %3d %15f",tree->n_root->num,tree->rates->nd_t[tree->n_root->num]); */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Post_Randomize_Node_Ages(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax == YES) return; + else + { + int i,dir1,dir2; + + for(i=0;i<3;++i) + if(d->v[i] != a && d->b[i] != tree->e_root) + TIMES_Post_Randomize_Node_Ages(d,d->v[i],tree); + + dir1 = dir2 = -1; + for(i=0;i<3;++i) + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(dir1 < 0) dir1 = i; + else dir2 = i; + } + + tree->rates->nd_t[d->num] = + MIN(tree->rates->nd_t[d->v[dir1]->num], + tree->rates->nd_t[d->v[dir2]->num]) + - Rexp(1.); + /* PhyML_Printf("\n. RAND TIMES node %3d %15f",d->num,tree->rates->nd_t[d->num]); */ + } +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int TIMES_Calibrations_Apply_To_Tips_Only(t_tree *tree) +{ + t_cal *cal; + t_clad *clade; + + cal = tree->rates->a_cal[0]; + assert(cal); + clade = NULL; + + do + { + while(cal && cal->clade_list == NULL) cal = cal->next; + if(cal == NULL) break; + clade = cal->clade_list[cal->current_clade_idx]; + if(clade && clade->n_tax > 1) break; + cal = cal->next; + } + while(cal); + + if(cal == NULL) return YES; + + return NO; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Randomize_Tip_Times_Given_Calibrations(t_tree *tree) +{ + + t_cal *cal; + t_clad *clade; + + cal = tree->rates->a_cal[0]; + assert(cal); + + do + { + clade = cal->clade_list[cal->current_clade_idx]; + + if(clade->n_tax == 1) + { + assert(clade->target_nd->tax == YES); + tree->rates->nd_t[clade->target_nd->num] = Uni()*(cal->upper - cal->lower) + cal->lower; + } + + cal = cal->next; + } + while(cal); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Time_To_Bl(t_tree *tree) +{ + TIMES_Time_To_Bl_Pre(tree->n_root,tree->n_root->v[1],tree->n_root->b[1],tree); + TIMES_Time_To_Bl_Pre(tree->n_root,tree->n_root->v[2],tree->n_root->b[2],tree); + tree->n_root->b[1]->l->v = tree->rates->nd_t[tree->n_root->v[1]->num] - tree->rates->nd_t[tree->n_root->num]; + tree->n_root->b[2]->l->v = tree->rates->nd_t[tree->n_root->v[2]->num] - tree->rates->nd_t[tree->n_root->num]; + tree->e_root->l->v = tree->n_root->b[1]->l->v + tree->n_root->b[2]->l->v; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Time_To_Bl_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree) +{ + int i; + + b->l->v = tree->rates->nd_t[d->num] - tree->rates->nd_t[a->num]; + + if(d->tax) return; + else + { + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + TIMES_Time_To_Bl_Pre(d,d->v[i],d->b[i],tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl TIMES_Tree_Length(t_tree *tree) +{ + phydbl sum; + + assert(tree->rates); + assert(tree->e_root); + + sum = 0.0; + for(int i=0;i<2*tree->n_otu-1;++i) + if(tree->a_edges[i] != tree->e_root) + sum += fabs(tree->rates->nd_t[tree->a_edges[i]->left->num]- + tree->rates->nd_t[tree->a_edges[i]->rght->num]); + + sum += fabs(tree->rates->nd_t[tree->n_root->num] - tree->rates->nd_t[tree->n_root->v[1]->num]); + sum += fabs(tree->rates->nd_t[tree->n_root->num] - tree->rates->nd_t[tree->n_root->v[2]->num]); + + return(sum); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Bl_To_Times(t_tree *tree) +{ + t_node *v1,*v2; + int dir1,dir2; + phydbl t1,t2; + + TIMES_Bl_To_Times_Post(tree->n_root,tree->n_root->v[1],tree->n_root->b[1],tree); + TIMES_Bl_To_Times_Post(tree->n_root,tree->n_root->v[2],tree->n_root->b[2],tree); + + dir1 = 1; + dir2 = 2; + + v1 = tree->n_root->v[dir1]; + v2 = tree->n_root->v[dir2]; + + t1 = tree->rates->nd_t[v1->num] - MIXT_Get_Mean_Edge_Len(tree->n_root->b[1],tree) / (tree->rates->clock_r * tree->rates->br_r[v1->num]); + t2 = tree->rates->nd_t[v2->num] - MIXT_Get_Mean_Edge_Len(tree->n_root->b[2],tree) / (tree->rates->clock_r * tree->rates->br_r[v2->num]); + + if(Are_Equal(t1,t2,1.E-6) == NO) + { + PhyML_Fprintf(stderr,"\n. It looks as if the edge lengths suplied do not define an ultrametric tree."); + PhyML_Fprintf(stderr,"\n. Please amend these lengths so as it becomes straightforward to transform your tree"); + PhyML_Fprintf(stderr,"\n. into a time-tree. Please contact me (guindon@lirmm.fr) for more information."); + PhyML_Fprintf(stderr,"\n. l1: %f l2: %f",MIXT_Get_Mean_Edge_Len(tree->n_root->b[1],tree),MIXT_Get_Mean_Edge_Len(tree->n_root->b[2],tree)); + PhyML_Fprintf(stderr,"\n. t1: %f t2: %f",tree->rates->nd_t[v1->num],tree->rates->nd_t[v2->num]); + PhyML_Fprintf(stderr,"\n. rr1: %f rr2: %f",tree->rates->br_r[v1->num],tree->rates->br_r[v2->num]); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + tree->rates->nd_t[tree->n_root->num] = t1; + + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void TIMES_Bl_To_Times_Post(t_node *a, t_node *d, t_edge *b, t_tree *tree) +{ + if(d->tax == YES) return; + else + { + t_node *v1,*v2; + int dir1,dir2; + phydbl t1,t2; + + dir1 = dir2 = -1; + for(int i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + TIMES_Bl_To_Times_Post(d,d->v[i],d->b[i],tree); + if(dir1 < 0) dir1 = i; + else dir2 = i; + } + + v1 = d->v[dir1]; + v2 = d->v[dir2]; + + t1 = tree->rates->nd_t[v1->num] - MIXT_Get_Mean_Edge_Len(d->b[dir1],tree) / (tree->rates->clock_r * tree->rates->br_r[v1->num]); + t2 = tree->rates->nd_t[v2->num] - MIXT_Get_Mean_Edge_Len(d->b[dir2],tree) / (tree->rates->clock_r * tree->rates->br_r[v2->num]); + + if(Are_Equal(t1,t2,1.E-6) == NO) + { + PhyML_Fprintf(stderr,"\n. It looks at if the edge lengths suplied do not define an ultrametric tree."); + PhyML_Fprintf(stderr,"\n. Please amend these lengths so as it becomes straightforward to transform your tree"); + PhyML_Fprintf(stderr,"\n. into a time-tree."); + PhyML_Fprintf(stderr,"\n. l1: %f l2: %f",MIXT_Get_Mean_Edge_Len(d->b[dir1],tree),MIXT_Get_Mean_Edge_Len(d->b[dir2],tree)); + PhyML_Fprintf(stderr,"\n. t1: %f t2: %f",tree->rates->nd_t[v1->num],tree->rates->nd_t[v2->num]); + PhyML_Fprintf(stderr,"\n. rr1: %f rr2: %f",tree->rates->br_r[v1->num],tree->rates->br_r[v2->num]); + PhyML_Fprintf(stderr,"\n. est: %f %f diff: %G",t1,t2,t1-t2); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + tree->rates->nd_t[d->num] = t1; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + diff --git a/phyml/times.h b/phyml/times.h new file mode 100644 index 0000000..99220cb --- /dev/null +++ b/phyml/times.h @@ -0,0 +1,90 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef TIMES_H +#define TIMES_H + +#include "utilities.h" + +int TIMES_main(int argc, char **argv); +void TIMES_Bl_From_T_Post(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void TIMES_Bl_From_T(t_tree *tree); +void TIMES_Optimize_Node_Times_Serie(t_node *a, t_node *d, t_tree *tree); +void TIMES_Round_Optimize(t_tree *tree); +void TIMES_Print_Node_Times(t_node *a, t_node *d, t_tree *tree); +t_edge *TIMES_Find_Best_Root_Position(t_tree *tree); +void TIMES_Least_Square_Node_Times(t_edge *e_root, t_tree *tree); +void TIMES_Least_Square_Node_Times_Pre(t_node *a, t_node *d, phydbl *A, phydbl *b, int n, t_tree *tree); +void TIMES_Mult_Time_Stamps(t_tree *tree); +void TIMES_Div_Time_Stamps(t_tree *tree); +void TIMES_Optimize_Tree_Height(t_tree *tree); +void TIMES_Adjust_Node_Times(t_tree *tree); +void TIMES_Adjust_Node_Times_Pre(t_node *a, t_node *d, t_tree *tree); +void TIMES_Optimize_Root_Height(t_tree *tree); +void TIMES_Estimate_Branch_Rates(t_tree *tree); +t_edge *TIMES_Find_Best_Root_Position_Approx(t_tree *tree); +void TIMES_Estimate_Branch_Rate_Parameter(t_tree *tree); +phydbl TIMES_Classify_Branch_In_Rate_Class(t_tree *tree); +void TIMES_Compute_Rates_And_Times_Least_Square_Adjustments(t_tree *tree); +void TIMES_Compute_Rates_And_Times_Least_Square_Adjustments_Post(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void TIMES_Classify_Branch_Rates(t_tree *tree); +int TIMES_Check_MC(t_tree *tree); +void TIMES_Set_All_Node_Priors(t_tree *tree); +void TIMES_Set_All_Node_Priors_Bottom_Up(t_node *a, t_node *d, t_tree *tree); +void TIMES_Set_All_Node_Priors_Top_Down(t_node *a, t_node *d, t_tree *tree); +void TIMES_Set_Floor(t_tree *tree); +void TIMES_Set_Floor_Post(t_node *a, t_node *d, t_tree *tree); +phydbl TIMES_Log_Conditional_Uniform_Density(t_tree *tree); +phydbl TIMES_Log_Yule(t_tree *tree); +phydbl TIMES_Lk_Times(int verbose, t_tree *tree); +void TIMES_Lk_Times_Trav(t_node *a, t_node *d, phydbl lim_inf, phydbl lim_sup, phydbl *logdens, t_tree *tree); +phydbl TIMES_Log_Number_Of_Ranked_Labelled_Histories(t_node *root, int per_slice, t_tree *tree); +void TIMES_Log_Number_Of_Ranked_Labelled_Histories_Post(t_node *a, t_node *d, int per_slice, phydbl *logn, t_tree *tree); +phydbl TIMES_Lk_Uniform_Core(t_tree *tree); +void TIMES_Get_Number_Of_Time_Slices(t_tree *tree); +void TIMES_Get_Number_Of_Time_Slices_Post(t_node *a, t_node *d, t_tree *tree); +void TIMES_Get_N_Slice_Spans(t_tree *tree); +void TIMES_Allocate_Vectors_Time_Slice_Combin(t_tree *tree); +void TIMES_Allocate_Vectors_Time_Slice_Combin_Post(t_node *a, t_node *d, t_tree *tree); +void TIMES_Update_Curr_Slice(t_tree *tree); +void TIMES_Lk_Uniform_Post(t_node *a, t_node *d, t_tree *tree); +void TIMES_Set_Root_Given_Tip_Dates(t_tree *tree); +void Get_Survival_Duration(t_tree *tree); +void Get_Survival_Duration_Post(t_node *a, t_node *d, t_tree *tree); +phydbl TIMES_Lk_Yule_Root_Marginal(t_tree *tree); +phydbl TIMES_Lk_Yule_Joint(t_tree *tree); +void TIMES_Update_Node_Ordering(t_tree *tree); +phydbl TIMES_Lk_Yule_Order(t_tree *tree); +void TIMES_Record_Prior_Times(t_tree *tree); +void TIMES_Reset_Prior_Times(t_tree *tree); +phydbl TIMES_Lk_Yule_Order_Root_Cond(t_tree *tree); +void TIMES_Connect_List_Of_Taxa(t_node **tax_list, int list_size, phydbl t_mrca, phydbl *times, int *nd_num, t_tree *mixt_tree); +void TIMES_Randomize_Tree_With_Time_Constraints(t_cal *cal_list, t_tree *tree); +phydbl TIMES_Lk_Birth_Death(int verbose, t_tree *tree); +int TIMES_Check_Node_Height_Ordering(t_tree *tree); +int TIMES_Check_Node_Height_Ordering_Post(t_node *a, t_node *d, t_tree *tree); +phydbl TIMES_Lk_Birth_Death_One_Node(phydbl t, phydbl min, phydbl max, t_tree *tree); +phydbl TIMES_Least_Square_Criterion(t_tree *tree); +void TIMES_Pre_Least_Square_Criterion(t_node *a, t_node *d, t_edge *b, phydbl *score, t_tree *tree); +void TIMES_Post_Randomize_Node_Ages(t_node *a, t_node *d, t_tree *tree); +void TIMES_Randomize_Node_Ages(t_tree *tree); +int TIMES_Calibrations_Apply_To_Tips_Only(t_tree *tree); +void TIMES_Randomize_Tip_Times_Given_Calibrations(t_tree *tree); +void TIMES_Time_To_Bl(t_tree *tree); +void TIMES_Time_To_Bl_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void TIMES_Bl_To_Times_Post(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void TIMES_Bl_To_Times(t_tree *tree); +phydbl TIMES_Tree_Length(t_tree *tree); + +#endif diff --git a/phyml/tiporder.c b/phyml/tiporder.c new file mode 100644 index 0000000..15722bf --- /dev/null +++ b/phyml/tiporder.c @@ -0,0 +1,1388 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + + +/* Routines for molecular clock trees and molecular dating */ + + +#include "tiporder.h" + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +/* int TIPO_main(int argc, char **argv) */ +/* { */ +/* t_tree **list_tree,*ref_tree,*tree; */ +/* FILE *fp_ref_tree,*fp_list_tree,*fp_coord,*ps_tree; */ +/* int i,j,k; */ +/* int n_trees; */ +/* option *ref_io,*list_io; */ +/* char **name_table; */ +/* int r_seed; */ + +/* r_seed = time(NULL); */ +/* srand(r_seed); */ + + +/* ref_io = (option *)Make_Input(); */ +/* list_io = (option *)Make_Input(); */ + +/* fp_ref_tree = (FILE *)fopen(argv[1],"r"); */ +/* fp_list_tree = (FILE *)fopen(argv[2],"r"); */ +/* fp_coord = (FILE *)fopen(argv[3],"r"); */ + +/* if(!fp_ref_tree) */ +/* { */ +/* PhyML_Printf("\n. Can't find %s",argv[1]); */ +/* PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); */ +/* Warn_And_Exit(""); */ +/* } */ + +/* if(!fp_list_tree) */ +/* { */ +/* PhyML_Printf("\n. Can't find %s",argv[2]); */ +/* PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); */ +/* Warn_And_Exit(""); */ +/* } */ + +/* ref_io->fp_in_tree = fp_ref_tree; */ +/* Read_Tree_File(ref_io); */ +/* fclose(ref_io->fp_in_tree); */ +/* ref_tree = ref_io->treelist->tree[0]; */ +/* ref_tree->io = ref_io; */ + + +/* list_io->fp_in_tree = fp_list_tree; */ +/* Read_Tree_File(list_io); */ +/* fclose(list_io->fp_in_tree); */ +/* list_tree = list_io->treelist->tree; */ +/* n_trees = list_io->treelist->list_size; */ +/* PhyML_Printf("\n. Read %d trees\n",n_trees); */ + +/* for(i=0;iio = list_io; */ + +/* name_table = (char **)mCalloc(ref_tree->n_otu,sizeof(char **)); */ +/* for(i=0;in_otu;i++) name_table[i] = (char *)mCalloc(T_MAX_NAME,sizeof(char)); */ + + +/* /\* Sort translation table such that tree->a_nodes[i]->name == tree->io->short_tax_name[i] for all i *\/ */ +/* TIPO_Sort_Translation_Table(ref_tree); */ + +/* ref_tree->io->z_scores = (phydbl *)mCalloc(ref_tree->n_otu,sizeof(phydbl)); */ + +/* /\* TIPO_Read_Taxa_Zscores(fp_coord,ref_tree); *\/ */ + +/* for(i=0;in_otu;i++) ref_tree->io->z_scores[i] = TIPO_Read_One_Taxon_Zscore(fp_coord,ref_tree->a_nodes[i]->name,ref_tree); */ + +/* TIPO_Normalize_Zscores(ref_tree); */ + +/* /\* Find matching tips *\/ */ +/* for(i=0;in_otu;j++) */ +/* { */ +/* for(k=0;kn_otu;k++) */ +/* { */ +/* if(!strcmp(ref_io->long_tax_names[j],list_io->long_tax_names[k])) */ +/* { */ +/* list_tree[i]->a_nodes[k]->ext_node = ref_tree->a_nodes[j]; */ +/* break; */ +/* } */ +/* } */ +/* if(k == ref_tree->n_otu) */ +/* { */ +/* PhyML_Printf("\n. Could not find matching tips for \"%s\" (tree %d)",ref_tree->a_nodes[j]->name,i); */ +/* PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); */ +/* Warn_And_Exit(""); */ +/* } */ +/* } */ +/* } */ + +/* PhyML_Printf("\n. Getting ancestors"); fflush(NULL); */ +/* Update_Ancestors(ref_tree->n_root,ref_tree->n_root->v[2],ref_tree); */ +/* Update_Ancestors(ref_tree->n_root,ref_tree->n_root->v[1],ref_tree); */ + +/* for(i=0;in_root,list_tree[i]->n_root->v[2],list_tree[i]); */ +/* Update_Ancestors(list_tree[i]->n_root,list_tree[i]->n_root->v[1],list_tree[i]); */ +/* list_tree[i]->n_root->anc = NULL; */ +/* } */ + +/* PhyML_Printf("\n. Getting bipartitions"); fflush(NULL); */ + +/* Free_Bip(ref_tree); */ +/* Alloc_Bip(ref_tree); */ +/* Get_Bip(ref_tree->a_nodes[0], */ +/* ref_tree->a_nodes[0]->v[0], */ +/* ref_tree); */ + +/* for(i=0;ia_nodes[0], */ +/* list_tree[i]->a_nodes[0]->v[0], */ +/* list_tree[i]); */ +/* } */ + + +/* PhyML_Printf("\n. Getting tip ranks"); fflush(NULL); */ +/* /\* TIPO_Get_Tips_Y_Rank(ref_tree); *\/ */ + +/* TIPO_Get_Tips_Y_Rank_From_Zscores(ref_tree); */ + +/* /\* PhyML_Printf("\n. Minimizing"); fflush(NULL); *\/ */ +/* /\* TIPO_Minimize_Tip_Order_Score(n_trees,list_tree,ref_tree); *\/ */ + +/* PhyML_Printf("\n. N_OTU = %d",ref_tree->n_otu); */ +/* TIPO_Untangle_Tree(ref_tree); */ +/* PhyML_Printf("\n ** ORIGINAL %f",ref_tree->tip_order_score); */ + +/* /\* i = 0; *\/ */ +/* /\* do *\/ */ +/* /\* { *\/ */ +/* /\* /\\* TIPO_Get_Tips_Y_Rank_From_Zscores(ref_tree); *\\/ *\/ */ +/* /\* TIPO_Randomize_Tip_Y_Ranks(ref_tree); *\/ */ +/* /\* TIPO_Untangle_Tree(ref_tree); *\/ */ +/* /\* PhyML_Printf("\n ** %f",ref_tree->tip_order_score); *\/ */ +/* /\* i++; *\/ */ +/* /\* }while(i < 5000); *\/ */ + +/* Test_Node_Table_Consistency(ref_tree); */ + +/* ref_tree->ps_tree = DR_Make_Tdraw_Struct(ref_tree); */ +/* DR_Get_Tree_Coord(ref_tree); */ +/* for(j=0;jn_otu;j++) */ +/* { */ +/* ref_tree->ps_tree->ycoord[j] = */ +/* (ref_tree->a_nodes[j]->y_rank/ref_tree->n_otu)* */ +/* ref_tree->ps_tree->page_height; */ +/* } */ + +/* ps_tree = (FILE *)fopen("order_tree.ps","w"); */ + + +/* list_io->z_scores = (phydbl *)mCalloc(ref_tree->n_otu,sizeof(phydbl)); */ + +/* DR_Print_Postscript_Header(1,ps_tree); */ +/* for(i=0;irates = RATES_Make_Rate_Struct(tree->n_otu); */ +/* RATES_Init_Rate_Struct(tree->rates,tree->n_otu); */ +/* TIMES_Least_Square_Node_Times(tree->e_root,tree); */ +/* TIMES_Adjust_Node_Times(tree); */ +/* RATES_Update_Cur_Bl(tree); */ + +/* tree->ps_tree = DR_Make_Tdraw_Struct(tree); */ +/* DR_Init_Tdraw_Struct(tree->ps_tree); */ +/* DR_Get_Tree_Box_Width(tree->ps_tree,tree); */ +/* Dist_To_Root(tree); */ +/* tree->ps_tree->max_dist_to_root = DR_Get_Max_Dist_To_Root(tree); */ + +/* for(j=0;jn_otu;j++) tree->io->z_scores[j] = ref_tree->io->z_scores[tree->a_nodes[j]->ext_node->num]; */ +/* TIPO_Get_Tips_Y_Rank_From_Zscores(tree); */ +/* TIPO_Untangle_Tree(tree); */ +/* for(j=0;jn_otu;j++) tree->ps_tree->ycoord[j] = (tree->a_nodes[j]->y_rank/tree->n_otu)*tree->ps_tree->page_height; */ + +/* /\* for(j=0;jn_otu;j++) tree->ps_tree->ycoord[j] = ref_tree->ps_tree->ycoord[tree->a_nodes[j]->ext_node->num]; *\/ */ +/* for(j=0;jn_otu;j++) list_io->z_scores[j] = ref_io->z_scores[tree->a_nodes[j]->ext_node->num]; */ + +/* DR_Get_Y_Coord(YES,tree->ps_tree,tree); */ +/* DR_Get_X_Coord( NO,tree->ps_tree,tree); */ + +/* if(!i) DR_Print_Tree_Postscript(1,YES,ps_tree,tree); */ +/* else DR_Print_Tree_Postscript(1, NO,ps_tree,tree); */ +/* } */ +/* DR_Print_Postscript_EOF(ps_tree); */ +/* fclose(ps_tree); */ + + +/* ps_tree = (FILE *)fopen("ref_tree.ps","w"); */ + +/* DR_Print_Postscript_Header(1,ps_tree); */ +/* tree = ref_tree; */ +/* tree->rates = RATES_Make_Rate_Struct(tree->n_otu); */ +/* RATES_Init_Rate_Struct(tree->rates,tree->n_otu); */ +/* TIMES_Least_Square_Node_Times(tree->e_root,tree); */ +/* TIMES_Adjust_Node_Times(tree); */ +/* RATES_Update_Cur_Bl(tree); */ +/* DR_Init_Tdraw_Struct(tree->ps_tree); */ +/* DR_Get_Tree_Box_Width(tree->ps_tree,tree); */ +/* Dist_To_Root(tree->n_root,tree); */ +/* tree->ps_tree->max_dist_to_root = DR_Get_Max_Dist_To_Root(tree); */ + +/* TIPO_Get_Tips_Y_Rank_From_Zscores(tree); */ +/* /\* TIPO_Untangle_Tree(tree); *\/ */ +/* for(j=0;jn_otu;j++) tree->ps_tree->ycoord[j] = (tree->a_nodes[j]->y_rank/tree->n_otu)*tree->ps_tree->page_height; */ + +/* DR_Get_Y_Coord(YES,tree->ps_tree,tree); */ +/* DR_Get_X_Coord( NO,tree->ps_tree,tree); */ +/* DR_Print_Tree_Postscript(1,YES,ps_tree,tree); */ +/* DR_Print_Postscript_EOF(ps_tree); */ +/* fclose(ps_tree); */ + + +/* PhyML_Printf("\n"); */ + +/* fclose(fp_ref_tree); */ +/* fclose(fp_list_tree); */ +/* fclose(fp_coord); */ +/* } */ + +int TIPO_main(int argc, char **argv) +{ + t_tree *tree; + option *io; + FILE *fp_tree_file, *fp_coord_file; + int i; + +/* Rprintf("%s\n",tree_file_name[0]); */ +/* Rprintf("%s\n",coord_file_name[0]); */ + + + srand(time(NULL)); rand(); + + + fp_tree_file = (FILE *)fopen(argv[1],"r"); + fp_coord_file = (FILE *)fopen(argv[2],"r"); + + io = (option *)Make_Input(); + io->fp_in_tree = fp_tree_file; + /* Read_Tree_File(io); */ + tree = io->treelist->tree[0]; + tree->io = io; + + tree->io->z_scores = (phydbl *)mCalloc(tree->n_otu,sizeof(phydbl)); + + for(i=0;in_otu;i++) tree->io->z_scores[i] = TIPO_Read_One_Taxon_Zscore(fp_coord_file,tree->a_nodes[i]->name,1,tree); + /* TIPO_Normalize_Zscores(tree); */ + Free_Bip(tree); + Alloc_Bip(tree); + Get_Bip(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + TIPO_Get_Tips_Y_Rank_From_Zscores(tree); + /* TIPO_Get_Tips_Y_Rank(tree); */ + + + tree->geo_mig_sd = 0.1; + Generic_Brent_Lk(&(tree->geo_mig_sd), + 1.E-3,1.E+2,1.E-6, + 100,NO, + &Wrap_Geo_Lk, + NULL,tree,NULL,NO); + + PhyML_Printf("\n. sd=%f",tree->geo_mig_sd); + + + fclose(fp_tree_file); + fclose(fp_coord_file); + + return 0; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Z_scores have already been recorder here */ +void TIPO_Get_Min_Number_Of_Tip_Permut(t_tree *tree) +{ + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + + Free_Bip(tree); + Alloc_Bip(tree); + Get_Bip(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + + TIPO_Get_Tips_Y_Rank_From_Zscores(tree); + + TIPO_Untangle_Tree(tree); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Get_Tips_Y_Rank(t_tree *tree) +{ + phydbl curr_rank; + + curr_rank = .0; + TIPO_Get_Tips_Y_Rank_Pre(tree->n_root,tree->n_root->v[2],&curr_rank,tree); + TIPO_Get_Tips_Y_Rank_Pre(tree->n_root,tree->n_root->v[1],&curr_rank,tree); + + if(curr_rank != tree->n_otu) + { + PhyML_Printf("\n. tree->n_otu = %d curr_rank = %d",tree->n_otu,curr_rank); + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Get_Tips_Y_Rank_Pre(t_node *a, t_node *d, phydbl *curr_rank, t_tree *tree) +{ + if(d->tax) + { + d->y_rank = *curr_rank; + *curr_rank += 1.; + return; + } + else + { + int i; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + TIPO_Get_Tips_Y_Rank_Pre(d,d->v[i],curr_rank,tree); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Get_All_Y_Rank(t_tree *tree) +{ + tree->sum_y_dist_sq = .0; + tree->sum_y_dist = .0; + TIPO_Get_All_Y_Rank_Pre(tree->n_root,tree->n_root->v[2],tree); + TIPO_Get_All_Y_Rank_Pre(tree->n_root,tree->n_root->v[1],tree); + tree->n_root->y_rank = (tree->n_root->v[2]->y_rank+tree->n_root->v[1]->y_rank)/2.; + tree->n_root->y_rank_min = MIN(tree->n_root->v[2]->y_rank_min,tree->n_root->v[1]->y_rank_min); + tree->n_root->y_rank_max = MAX(tree->n_root->v[2]->y_rank_max,tree->n_root->v[1]->y_rank_max); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Get_All_Y_Rank_Pre(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax) + { + d->y_rank_min = d->y_rank; + d->y_rank_max = d->y_rank; + return; + } + else + { + int i; + int dir1,dir2; + phydbl v1,v2; + + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + TIPO_Get_All_Y_Rank_Pre(d,d->v[i],tree); + } + } + + dir1 = dir2 = -1; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(dir1 < 0) dir1 = i; + else dir2 = i; + } + } + + v1 = d->v[dir1]->y_rank; + v2 = d->v[dir2]->y_rank; + + d->y_rank = (v1+v2)/2.; + tree->sum_y_dist_sq += POW(v1-v2,2); + tree->sum_y_dist += FABS(v1-v2); + d->y_rank_min = MIN(d->v[dir1]->y_rank_min,d->v[dir2]->y_rank_min); + d->y_rank_max = MAX(d->v[dir1]->y_rank_max,d->v[dir2]->y_rank_max); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Swap_One_Node(t_node *d, t_tree *tree) +{ + if(d->tax) return; + else + { + int i; + int dir1, dir2; + t_node *tmp_n; + t_edge *tmp_e; + + if(d != tree->n_root) + { + dir1 = dir2 = -1; + for(i=0;i<3;i++) + { + if((d->v[i] != d->anc) && (d->b[i] != tree->e_root)) + { + if(dir1 < 0) dir1 = i; + else dir2 = i; + } + } + } + else + { + dir1 = 0; + dir2 = 1; + } + + tmp_n = d->v[dir2]; + d->v[dir2] = d->v[dir1]; + d->v[dir1] = tmp_n; + + tmp_e = d->b[dir2]; + d->b[dir2] = d->b[dir1]; + d->b[dir1] = tmp_e; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Minimize_Tip_Order_Score(int n_trees, t_tree **list_tree, t_tree *ref_tree) +{ + int i,j; + phydbl score,min_score,old_min_score; + phydbl diff,eps; + t_node **node_table; + int swapped; + t_node *tmp; + + eps = 1.E-3; + old_min_score = min_score = score = INT_MAX; + /* TIPO_Print_Tip_Ordered(ref_tree); */ + + do + { + for(i=ref_tree->n_otu;i<2*ref_tree->n_otu-1;i++) + { + TIPO_Swap_One_Node(ref_tree->a_nodes[i],ref_tree); + TIPO_Get_Tips_Y_Rank(ref_tree); + score = (phydbl)TIPO_Untangle_Tree_List(n_trees,list_tree,ref_tree); + if(score == -1) + { + return; + } + + if(score < min_score) + { + min_score = score; + PhyML_Printf("\n- Score = %f",score); + } + else + { + TIPO_Swap_One_Node(ref_tree->a_nodes[i],ref_tree); + TIPO_Get_Tips_Y_Rank(ref_tree); +/* PhyML_Printf("\n+ Score = %f",score); */ + } + } + diff = fabs(old_min_score - min_score); + old_min_score = min_score; + }while(diff > eps); + + PhyML_Printf("\n"); + + node_table = (t_node **)mCalloc(ref_tree->n_otu,sizeof(t_node *)); + + + for(i=0;in_otu;i++) + { + for(j=0;jn_otu;j++) + { + if(!strcmp(ref_tree->io->short_tax_names[i],ref_tree->a_nodes[j]->name)) + { + Free(ref_tree->a_nodes[j]->name); + ref_tree->a_nodes[j]->name = (char *)mCalloc((int)strlen(ref_tree->io->long_tax_names[i])+1,sizeof(char)); + strcpy(ref_tree->a_nodes[j]->name,ref_tree->io->long_tax_names[i]); + break; + } + } + } + + for(i=0;in_otu;i++) node_table[i] = ref_tree->a_nodes[i]; + +/* bubble sort of conflict nodes according to their y_rank */ + do + { + swapped = NO; + for(i=0;in_otu-1;i++) + { + if(node_table[i]->y_rank > node_table[i+1]->y_rank) + { + swapped = YES; + tmp = node_table[i]; + node_table[i] = node_table[i+1]; + node_table[i+1] = tmp; + } + } + }while(swapped == YES); + + for(i=0;in_otu;i++) + { + PhyML_Printf("\n%s",node_table[i]->name,node_table[i]->y_rank); + } + + + + Free(node_table); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Print_Tip_Ordered(t_tree *tree) +{ + TIPO_Print_Tip_Ordered_Pre(tree->n_root,tree->n_root->v[2],tree); + TIPO_Print_Tip_Ordered_Pre(tree->n_root,tree->n_root->v[1],tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Print_Tip_Ordered_Pre(t_node *a, t_node *d, t_tree *tree) +{ + + if(d->tax) + { + PhyML_Printf("\n. %f \"%s\"",d->y_rank,d->name); + } + else + { + int i,dir1,dir2; + + dir1 = dir2 = -1; + for(i=0;i<3;i++) + { + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + { + if(dir1 < 0) dir1 = i; + else dir2 = i; + } + } + if(d->v[dir1]->y_rank < d->v[dir2]->y_rank) + { + TIPO_Print_Tip_Ordered_Pre(d,d->v[dir1],tree); + TIPO_Print_Tip_Ordered_Pre(d,d->v[dir2],tree); + } + else + { + TIPO_Print_Tip_Ordered_Pre(d,d->v[dir2],tree); + TIPO_Print_Tip_Ordered_Pre(d,d->v[dir1],tree); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int TIPO_Untangle_Tree_List(int n_trees, t_tree **list_tree, t_tree *ref_tree) +{ + int i,j; + int tree_score,score; + + score = 0; + for(i=0;in_otu;j++) list_tree[i]->a_nodes[j]->y_rank = list_tree[i]->a_nodes[j]->ext_node->y_rank; + tree_score = TIPO_Untangle_Tree(list_tree[i]); +/* PhyML_Printf(" score = %3d",tree_score); */ + score += tree_score; + if(tree_score < 0) + { + return -1; + } + } + + return score; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl TIPO_Untangle_Tree(t_tree *tree) +{ + int conflict; + int n_trials; + t_node **node_table; + int i,swapped; + t_node *tmp; + + node_table = (t_node **)mCalloc(tree->n_otu,sizeof(t_node *)); + + for(i=0;in_otu;i++) node_table[i] = tree->a_nodes[i]; + for(i=0;in_otu;i++) tree->a_nodes[i]->y_rank_ori = tree->a_nodes[i]->y_rank; + + +/* bubble sort of nodes according to their y_rank */ + do + { + swapped = NO; + for(i=0;in_otu-1;i++) + { + if(node_table[i]->y_rank > node_table[i+1]->y_rank) + { + swapped = YES; + tmp = node_table[i]; + node_table[i] = node_table[i+1]; + node_table[i+1] = tmp; + } + } + } + while(swapped == YES); + + + /* Work out the y_rank values for every internal node given the external node ranks */ + TIPO_Get_All_Y_Rank(tree); + + tree->tip_order_score = .0; + + n_trials = 0; + do + { + conflict= NO; + /* Recusrssive untangling of the tree */ + TIPO_Untangle_Node(tree->n_root,tree->n_root->v[2],node_table,&conflict,tree); + TIPO_Untangle_Node(tree->n_root,tree->n_root->v[1],node_table,&conflict,tree); + n_trials++; + + + if(n_trials > 2) /* We should have been able to untangle the tree after just one tree traversal */ + { + int i; + FILE *ps_tree; + + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + ps_tree = (FILE *)fopen("failed_tree.ps","w"); + + Test_Node_Table_Consistency(tree); + tree->rates = RATES_Make_Rate_Struct(tree->n_otu); + RATES_Init_Rate_Struct(tree->rates,tree->io->rates,tree->n_otu); + TIMES_Least_Square_Node_Times(tree->e_root,tree); + TIMES_Adjust_Node_Times(tree); + RATES_Update_Cur_Bl(tree); + + DR_Print_Postscript_Header(1,ps_tree); + tree->ps_tree = DR_Make_Tdraw_Struct(tree); + DR_Init_Tdraw_Struct(tree->ps_tree); + DR_Get_Tree_Box_Width(tree->ps_tree,tree); + Dist_To_Root(tree); + tree->ps_tree->max_dist_to_root = DR_Get_Max_Dist_To_Root(tree); + for(i=0;in_otu;i++) tree->ps_tree->ycoord[i] = tree->a_nodes[i]->y_rank * (int)(tree->ps_tree->page_height / (tree->n_otu)); + DR_Get_X_Coord(NO,tree->ps_tree,tree); + DR_Get_Y_Coord(YES,tree->ps_tree,tree); + DR_Print_Tree_Postscript(1,NO,ps_tree,tree); + DR_Print_Postscript_EOF(ps_tree); + fclose(ps_tree); + Warn_And_Exit(""); + } + }while(conflict == YES); + + Free(node_table); + return tree->tip_order_score; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Untangle_Node(t_node *a, t_node *d, t_node **node_table, int *conflict, t_tree *tree) +{ + + if(d->tax) return; + else + { + int i,j; + int d_a; + int beg,end; + phydbl min,max; + t_node *lca; + t_node **conflict_tips, **anc_conflict; + int n_conflicts; + phydbl eps,tmp_rank; + t_node *tmp_node; + int n_moved; + int n_anc_conflicts; + + anc_conflict = NULL; + d_a = -1; + + /* It is a post order traversal */ + for(i=0;i<3;i++) + { + if((d->v[i] != d->anc) && (d->b[i] != tree->e_root)) + { + TIPO_Untangle_Node(d,d->v[i],node_table,conflict,tree); + } + } + + + lca = NULL; + eps = 1.E-10; + + /* Find direction fron node d ((d)escendant) to a ((a)ncestor) */ + for(i=0;i<3;i++) + { + if((d->v[i] == d->anc) || (d->b[i] == tree->e_root)) + { + d_a = i; + break; + } + } + + + /* y_rank_min is the minimum rank among all the ranks of the tips that + can be reached when going from a to d */ + min = d->y_rank_min; + max = d->y_rank_max; + + /* Get the list of tip nodes which ranks are between d->y_rank_min and d->y_rank_max */ + n_conflicts = 0; + for(i=0;in_otu;i++) + { + if((node_table[i]->y_rank > min - eps) && (node_table[i]->y_rank < max + eps)) + { + n_conflicts++; + } + } + + conflict_tips = NULL; + for(i=0;in_otu;i++) + { + if(node_table[i]->y_rank > min - eps) + { + conflict_tips = node_table+i; + break; + } + } + + + beg = 0; + end = n_conflicts; + n_moved = 0; + n_anc_conflicts = 0; + do + { + for(i=beg;ibip_size[d_a]) if(conflict_tips[i] == d->bip_node[d_a][j]) break; + + if(j == d->bip_size[d_a]) + /* conflict_tips[i] does not belong to the list of descendant of node d. It is + therefore responsible for a conflict */ + { + *conflict = YES; + +/* printf("\n. Moving %d with rank %f",conflict_tips[i]->num,conflict_tips[i]->y_rank); */ + + n_moved++; + + /* Move from conflict_tips[i] towards the root as long as the rank of the node lca is between min and max */ + lca = conflict_tips[i]; + while(lca->y_rank_min > min && lca->y_rank_max < max) lca = lca->anc; + + + if(lca->y_rank_min > max && lca->y_rank_max > max) + { + PhyML_Printf("\n. lca = %d (%d)",lca->num,lca==tree->n_root); + PhyML_Printf("\n. Err in file %s at line %d",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if(lca->y_rank_min < min && lca->y_rank_max < min) + { + PhyML_Printf("\n. lca = %d (root ? %d) (tip ? %d)",lca->num,lca==tree->n_root,lca->tax); + PhyML_Printf("\n. lca->y_rank_min = %f lca->y_rank_max = %f",lca->y_rank_min,lca->y_rank_max); + PhyML_Printf("\n. min=%f max=%f",min,max); + PhyML_Printf("\n. Err in file %s at line %d",__FILE__,__LINE__); + Warn_And_Exit(""); + } + if(lca->tax) + { + PhyML_Printf("\n. lca (%d) cannot be a tip.",lca->num); + PhyML_Printf("\n. lca->anc->y_rank=%f",lca->anc->y_rank); + PhyML_Printf("\n. lca->y_rank=%f",lca->y_rank); + PhyML_Printf("\n. lca->y_rank_min=%f lca=>y_rank_max=%f",lca->y_rank_min,lca->y_rank_max); + PhyML_Printf("\n. min=%f max=%f",min,max); + PhyML_Printf("\n. %p %p",lca,conflict_tips[i]); + PhyML_Printf("\n. Err in file %s at line %d",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + /* Have you found lca previously ? */ + for(j=0;jtip_order_score+=1.; */ + /* tree->tip_order_score+=(lca->y_rank_max-lca->y_rank_min); */ + n_anc_conflicts++; + anc_conflict = (t_node **)realloc(anc_conflict,n_anc_conflicts*sizeof(t_node *)); + anc_conflict[n_anc_conflicts-1] = lca; + } + + /* PhyML_Printf("\n. Detected conflict for ``%s'' (rank:%f min=%f max=%f lca=%f)", */ + /* conflict_tips[i]->name, */ + /* conflict_tips[i]->y_rank, */ + /* min,max,lca->y_rank); */ + + /* Solve the conflict by shifting tip nodes to the left or to the right */ + if(lca->y_rank > d->y_rank) + { + end--; +/* max-=1.; */ + max = conflict_tips[end-1]->y_rank; +/* printf("\n. max=%f %f",max,conflict_tips[end-1]->y_rank); */ + + for(j=i;jnum,conflict_tips[j+1]->num, */ +/* conflict_tips[j]->y_rank,conflict_tips[j+1]->y_rank); */ + + tmp_rank = conflict_tips[j]->y_rank; + conflict_tips[j]->y_rank = conflict_tips[j+1]->y_rank; + conflict_tips[j+1]->y_rank = tmp_rank; + + tmp_node = conflict_tips[j]; + conflict_tips[j] = conflict_tips[j+1]; + conflict_tips[j+1] = tmp_node; + + tree->tip_order_score += fabs(conflict_tips[j]->y_rank - conflict_tips[j+1]->y_rank)/n_conflicts; + +/* PhyML_Printf(" to (%d,%d) (%f,%f)", */ +/* conflict_tips[j]->num,conflict_tips[j+1]->num, */ +/* conflict_tips[j]->y_rank,conflict_tips[j+1]->y_rank); */ + } + } + else + { + beg++; +/* min+=1.; */ + min = conflict_tips[beg]->y_rank; +/* printf("\n. min=%f %f",min,conflict_tips[beg]->y_rank); */ + + for(j=i;j>0;j--) + { +/* PhyML_Printf("\n- Moved (%d,%d) from (%f,%f)", */ +/* conflict_tips[j]->num,conflict_tips[j-1]->num, */ +/* conflict_tips[j]->y_rank,conflict_tips[j-1]->y_rank); */ + + + tmp_rank = conflict_tips[j]->y_rank; + conflict_tips[j]->y_rank = conflict_tips[j-1]->y_rank; + conflict_tips[j-1]->y_rank = tmp_rank; + + tmp_node = conflict_tips[j]; + conflict_tips[j] = conflict_tips[j-1]; + conflict_tips[j-1] = tmp_node; + + tree->tip_order_score += fabs(conflict_tips[j]->y_rank - conflict_tips[j+1]->y_rank)/n_conflicts; + +/* PhyML_Printf(" to (%d,%d) (%f,%f)", */ +/* conflict_tips[j]->num,conflict_tips[j-1]->num, */ +/* conflict_tips[j]->y_rank,conflict_tips[j-1]->y_rank); */ + } + } + +/* printf("\n"); */ +/* for(j=0;jy_rank); */ +/* printf("\n. min=%f max=%f",min,max); */ +/* printf("\n. Node %d has now rank %f",c_node->num,c_node->y_rank); */ + + + /* Update internal nodes y ranks */ + TIPO_Get_All_Y_Rank(tree); + + break; + } + } + }while(n_moved + d->bip_size[d_a] != n_conflicts); + + + for(i=0;in_otu;i++) + { + if((tree->a_nodes[i]->y_rank > min - eps) && (tree->a_nodes[i]->y_rank < max + eps)) + { + For(j,d->bip_size[d_a]) + { + if(tree->a_nodes[i] == d->bip_node[d_a][j]) break; + } + if(j == d->bip_size[d_a]) + { + printf("\n. Conflict remaining for node %d (%d)",d->num,a->num); + PhyML_Printf("\n. Err in file %s at line %d",__FILE__,__LINE__); + Warn_And_Exit(""); + } + } + } + + if(anc_conflict) Free(anc_conflict); + + return; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int TIPO_Check_Tip_Ranks(t_tree *tree) +{ + int i,j; + phydbl eps; + + eps = 1.E-6; + + for(i=0;in_otu-1;i++) + { + for(j=i+1;jn_otu;j++) + { + if(fabs(tree->a_nodes[i]->y_rank - tree->a_nodes[j]->y_rank) < eps) + { + return 0; + } + } + } + return 1; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Read_Taxa_Zscores(FILE *fp_coord, t_tree *tree) +{ + char *name,*line; + phydbl z; + int i; + + name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + + if(!fgets(line,T_MAX_LINE,fp_coord)) + { + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + Free(line); + + + do + { + if(fscanf(fp_coord,"%s\t%lf\n",name,&z) == EOF) break; + PhyML_Printf("\n. Read %s. Z-score: %f",name,z); + + for(i=0;in_otu;i++) if(!strcmp(tree->io->long_tax_names[i],name)) break; + + if(i == tree->n_otu) + { + PhyML_Printf("\n. Could not find taxon '%s' in coordinate file.",name); + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + tree->io->z_scores[i] = z; + + }while(1); + + Free(name); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Read_Taxa_Coordinates(FILE *fp_coord, t_tree *tree) +{ + char *name,*line; + phydbl lon, lat; + int i; + + name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + + if(!fgets(line,T_MAX_LINE,fp_coord)) + { + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + Free(line); + + tree->io->lat = (phydbl *)mCalloc(tree->n_otu,sizeof(phydbl)); + tree->io->lon = (phydbl *)mCalloc(tree->n_otu,sizeof(phydbl)); + + do + { + if(fscanf(fp_coord,"%s\t%lf\t%lf\n",name,&lat,&lon) == EOF) break; + PhyML_Printf("\n. Read %s %f %f",name,lat,lon); + + for(i=0;in_otu;i++) if(!strcmp(tree->io->long_tax_names[i],name)) break; + + if(i == tree->n_otu) + { + PhyML_Printf("\n. Could not find taxon '%s' in coordinate file.",name); + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + tree->io->lat[i] = lat; + tree->io->lon[i] = lon; + + }while(1); + + Free(name); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Get_Tips_Y_Rank_From_Zscores(t_tree *tree) +{ + int i; + + for(i=0;in_otu;i++) tree->a_nodes[i]->y_rank = .0; + + /* Randomization in order to avoid ties */ + for(i=0;in_otu;i++) tree->io->z_scores[i] += Rnorm(0.0,0.001); + + for(i=0;in_otu;i++) tree->a_nodes[i]->y_rank = tree->io->z_scores[i]; + +/* for(i=0;in_otu;i++) tree->a_nodes[i]->y_rank = .0; */ + +/* for(i=0;in_otu-1;i++) */ +/* { */ +/* for(j=i+1;jn_otu;j++) */ +/* { */ +/* if(tree->io->z_scores[i] > tree->io->z_scores[j]) */ +/* { */ +/* tree->a_nodes[i]->y_rank += 1.0; */ +/* } */ +/* else */ +/* if(tree->io->z_scores[i] < tree->io->z_scores[j]) */ +/* { */ +/* tree->a_nodes[j]->y_rank += 1.0; */ +/* } */ +/* else */ +/* { */ +/* PhyML_Printf("\n. Ties not allowed.\n"); */ +/* PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); */ +/* Warn_And_Exit(""); */ +/* } */ +/* } */ +/* } */ + +/* for(i=0;in_otu;i++) printf("- %f\n",tree->a_nodes[i]->y_rank); */ + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/* Sort translation table such that tree->a_nodes[i]->name == tree->io->short_tax_name[i] for all i */ +void TIPO_Sort_Translation_Table(t_tree *tree) +{ + int i,j; + char *s; + + + Test_Node_Table_Consistency(tree); + + for(i=0;in_otu-1;i++) + { + for(j=i+1;jn_otu;j++) + { + if(!strcmp(tree->a_nodes[i]->name,tree->io->short_tax_names[j])) + { + s = tree->io->short_tax_names[i]; + tree->io->short_tax_names[i] = tree->io->short_tax_names[j]; + tree->io->short_tax_names[j] = s; + + s = tree->io->long_tax_names[i]; + tree->io->long_tax_names[i] = tree->io->long_tax_names[j]; + tree->io->long_tax_names[j] = s; + + break; + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Randomize_Tip_Y_Ranks(t_tree *tree) +{ + + int i; + phydbl rk_tmp; + int rnd_node_num; + + for(i=0;in_otu;i++) tree->a_nodes[i]->y_rank_ori = tree->a_nodes[i]->y_rank; + + for(i=0;in_otu;i++) + { + rnd_node_num = Rand_Int(0,tree->n_otu-1); + + rk_tmp = tree->a_nodes[rnd_node_num]->y_rank; + tree->a_nodes[rnd_node_num]->y_rank = tree->a_nodes[i]->y_rank; + tree->a_nodes[i]->y_rank = rk_tmp; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl TIPO_Read_One_Taxon_Zscore(FILE *fp_coord, char *seqname_qry, int col, t_tree *tree) +{ + char *seqname, *place; + phydbl lat; + + seqname = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + place = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + + rewind(fp_coord); + + /* skip first line */ +/* if(!fgets(line,T_MAX_LINE,fp_coord)) */ +/* { */ +/* PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); */ +/* Warn_And_Exit(""); */ +/* } */ +/* Free(line); */ + + do + { +/* if(fscanf(fp_coord,"%s\t%s\t%lf\t%lf\t%d\n",seqname,place,&lat,&lon,&year) == EOF) */ +/* if(fscanf(fp_coord,"%s\t%s\t%lf\t%lf\n",seqname,place,&lat,&lon) == EOF) */ +/* if(fscanf(fp_coord,"%s\t%lf\t%lf\n",seqname,&lat,&lon) == EOF) */ + if(fscanf(fp_coord,"%s %lf\n",seqname,&lat) == EOF) + { + PhyML_Printf("\n. Could not find sequence '%s' in coordinate file",seqname_qry); + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + + if(!strcmp(seqname,seqname_qry)) break; + + }while(1); + +/* PhyML_Printf("\n. Found %20s %s @ %10.2f %10.2f. Recording %10.2f",seqname,place,lat,lon,(col==1)?lat:lon); */ + + Free(seqname); + Free(place); + +/* if(col == 1) return lat; */ +/* else if(col == 2) return lon; */ +/* else return -1.; */ + + return lat; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void TIPO_Normalize_Zscores(t_tree *tree) +{ + int i; + phydbl min_z,max_z; + phydbl eps; + + eps = 1.E-10; + + min_z = FLT_MAX; + for(i=0;in_otu;i++) + { + if(tree->io->z_scores[i] < min_z) + { + min_z = tree->io->z_scores[i]; + } + } + + max_z = -FLT_MAX; + for(i=0;in_otu;i++) + { + if(tree->io->z_scores[i] > max_z) + { + max_z = tree->io->z_scores[i]; + } + } + + for(i=0;in_otu;i++) tree->io->z_scores[i] = (tree->io->z_scores[i] - min_z)/(max_z-min_z+eps); + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl TIPO_Lk(t_tree *tree) +{ + tree->geo_lnL = 0.0; + TIPO_Lk_Post(tree->n_root,tree->n_root->v[2],tree); + TIPO_Lk_Post(tree->n_root,tree->n_root->v[1],tree); + TIPO_Lk_Core(NULL,tree->n_root,tree); + return(tree->geo_lnL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl TIPO_Lk_Post(t_node *a, t_node *d, t_tree *tree) +{ + if(!d->tax) + { + int i; + + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + TIPO_Lk_Post(d,d->v[i],tree); + } + } + TIPO_Lk_Core(a,d,tree); + } + + return .0; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl TIPO_Lk_Core(t_node *a, t_node *d, t_tree *tree) +{ + + int i,j; + int d_v1,d_v2,v1_d,v2_d; + t_node *v1, *v2; + phydbl dist,dens,min_dist; + + + if(d->tax) + { + PhyML_Printf("\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + + if(d == tree->n_root) + { + d_v1 = 0; + d_v2 = 1; + } + else + { + d_v1 = d_v2 = -1; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(d_v1 < 0) d_v1 = i; + else d_v2 = i; + } + } + } + + v1 = d->v[d_v1]; + v2 = d->v[d_v2]; + + v1_d = v2_d = -1; + if(d == tree->n_root) + { + for(i=0;i<3;i++) + { + if(v1->b[i] == tree->e_root) v1_d = i; + if(v2->b[i] == tree->e_root) v2_d = i; + } + } + else + { + for(i=0;i<3;i++) + { + if(v1->v[i] == d) v1_d = i; + if(v2->v[i] == d) v2_d = i; + } + } + + + dens = 0.0; + min_dist = FLT_MAX; + For(i,v1->bip_size[v1_d]) + { + For(j,v2->bip_size[v2_d]) + { + dist = fabs(v1->bip_node[v1_d][i]->y_rank - + v2->bip_node[v2_d][j]->y_rank); + + if(dist < min_dist) min_dist = dist; + + dens += Dnorm(dist,0.0,tree->geo_mig_sd); + /* printf("\n. dist=%f dens=%f %f %f", */ + /* dist,Dnorm(dist,0.0,tree->geo_mig_sd), */ + /* v1->bip_node[v1_d][i]->y_rank, */ + /* v2->bip_node[v2_d][j]->y_rank); */ + } + } + + /* printf("\n. min_dist=%f dens=%f", */ + /* min_dist,Dnorm(dist,0.0,tree->geo_mig_sd)); */ + + /* dens = Dnorm(min_dist,0.0,tree->geo_mig_sd); */ + tree->geo_lnL += log(dens); + + return tree->geo_lnL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + diff --git a/phyml/tiporder.h b/phyml/tiporder.h new file mode 100644 index 0000000..9b3b0a0 --- /dev/null +++ b/phyml/tiporder.h @@ -0,0 +1,64 @@ +/* + +PhyML: a program that computes maximum likelihood phylogenies from +DNA or AA homologous sequences. + +Copyright (C) Stephane Guindon. Oct 2003 onward. + +All parts of the source except where indicated are distributed under +the GNU public licence. See http://www.opensource.org for details. + +*/ + +#include + +#ifndef TIPORDER_H +#define TIPORDER_H + +#include "times.h" +#include "spr.h" +#include "utilities.h" +#include "lk.h" +#include "optimiz.h" +#include "bionj.h" +#include "models.h" +#include "free.h" +#include "help.h" +#include "simu.h" +#include "eigen.h" +#include "pars.h" +#include "alrt.h" +#include "m4.h" +#include "draw.h" +#include "rates.h" +#include "mcmc.h" +#include "io.h" +#include "stats.h" + +void TIPO_Get_Tips_Y_Rank(t_tree *tree); +void TIPO_Get_Tips_Y_Rank_Pre(t_node *a, t_node *d, phydbl *curr_rank, t_tree *tree); +void TIPO_Get_All_Y_Rank(t_tree *tree); +void TIPO_Get_All_Y_Rank_Pre(t_node *a, t_node *d, t_tree *tree); +void TIPO_Swap_One_Node(t_node *d, t_tree *tree); +void TIPO_Minimize_Tip_Order_Score(int n_trees, t_tree **list_tree, t_tree *ref_tree); +void TIPO_Print_Tip_Ordered(t_tree *ref_tree); +void TIPO_Print_Tip_Ordered_Pre(t_node *a, t_node *d, t_tree *ref_tree); +phydbl TIPO_Untangle_Tree(t_tree *tree); +void TIPO_Untangle_Node(t_node *a, t_node *d, t_node **node_table, int *conflict, t_tree *tree); +int TIPO_Untangle_Tree_List(int n_trees, t_tree **list_tree, t_tree *ref_tree); +int TIPO_Check_Tip_Ranks(t_tree *tree); +void TIPO_Read_Taxa_Coordinates(FILE *fp_coord, t_tree *tree); +void TIPO_Get_Tips_Y_Rank_From_Zscores(t_tree *tree); +void TIPO_Init_Tip_Num(t_tree *tree); +void TIPO_Read_Taxa_Zscores(FILE *fp_coord, t_tree *tree); +void TIPO_Sort_Translation_Table(t_tree *tree); +void TIPO_Randomize_Tip_Y_Ranks(t_tree *tree); +phydbl TIPO_Read_One_Taxon_Zscore(FILE *fp, char *seqname_qry, int col, t_tree *tree); +void TIPO_Normalize_Zscores(t_tree *tree); +void TIPO_Get_Min_Number_Of_Tip_Permut(t_tree *tree); +phydbl TIPO_Lk(t_tree *tree); +phydbl TIPO_Lk_Post(t_node *a, t_node *d, t_tree *tree); +phydbl TIPO_Lk_Core(t_node *a, t_node *d, t_tree *tree); + + +#endif diff --git a/phyml/utilities.c b/phyml/utilities.c index d324294..3dc24ea 100644 --- a/phyml/utilities.c +++ b/phyml/utilities.c @@ -1,5 +1,4 @@ /* - PhyML: a program that computes maximum likelihood phylogenies from DNA or AA homologous sequences. @@ -10,10233 +9,12639 @@ the GNU public licence. See http://www.opensource.org for details. */ -#include "spr.h" #include "utilities.h" -#include "lk.h" -#include "optimiz.h" -#include "models.h" -#include "free.h" -#include "bionj.h" -#include "simu.h" -#include "eigen.h" -#include "pars.h" -#include "alrt.h" -#include "m4.h" -#include "mc.h" - -#ifdef MG -#include "mg.h" -#endif +#include "tbe.h" +#include "assert.h" +#ifdef BEAGLE +#include "beagle_utils.h" +#endif -/*********************************************************/ - -double Uni() -{ - double r; - r=rand(); - r/=RAND_MAX; - return r; -} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************************/ -/********************* random Gamma generator ************************ -* Properties: -* (1) X = Gamma(alpha,lambda) = Gamma(alpha,1)/lambda -* (2) X1 = Gamma(alpha1,1), X2 = Gamma(alpha2,1) independent -* then X = X1+X2 = Gamma(alpha1+alpha2,1) -* (3) alpha = k = integer then -* X = Gamma(k,1) = Erlang(k,1) = -sum(log(Ui)) = -log(prod(Ui)) -* where U1,...Uk iid uniform(0,1) -* -* Decompose alpha = k+delta with k = [alpha], and 00.) + if(!string) { - double y = 0.; - double b = (alpha+exp(1.))/exp(1.); - double p = 1./alpha; - int go = 0; - while (go==0) - { - double u = Uni(); - double w = Uni(); - double v = b*u; - if (v<=1.) - { - x = pow(v,p); - y = exp(-x); - } - else - { - x = -log(p*(b-v)); - y = pow(x,alpha-1.); - } - go = (w=1.) + if(string == endptr || errno == ERANGE) { - int k = (int) floor(shape); - delta = shape - k; - double u = 1.; - for (i=0; i0, accurate to 10 decimal places. */ -/* Stirling's formula is used for the central polynomial part of the procedure. */ -/* Pike MC & Hill ID (1966) Algorithm 291: Logarithm of the gamma function. */ -/* Communications of the Association for Computing Machinery, 9:684 */ -/* *\/ */ -/* phydbl x=alpha, f=0, z; */ - -/* if (x<7) { */ -/* f=1; z=x-1; */ -/* while (++z<7) f*=z; */ -/* x=z; f=-(phydbl)log(f); */ -/* } */ -/* z = 1/(x*x); */ -/* return f + (x-0.5)*(phydbl)log(x) - x + .918938533204673 */ -/* + (((-.000595238095238*z+.000793650793651)*z-.002777777777778)*z */ -/* +.083333333333333)/x; */ -/* } */ + char **tmp_sub; + int degree,i,j; + PhyML_Printf("\n. Removing the root...\n"); -/*********************************************************/ + tmp_sub = Sub_Trees(subtrees[0],°ree); + if(degree >= 2) + { + strcpy(subtrees[2],subtrees[1]); + Clean_Multifurcation(tmp_sub,degree,2); + for(j=0;j<2;j++) strcpy(subtrees[j],tmp_sub[j]); + } + else + { + tmp_sub = Sub_Trees(subtrees[1],°ree); + strcpy(subtrees[2],subtrees[0]); + Clean_Multifurcation(tmp_sub,degree,2); + for(j=0;j<2;j++) strcpy(subtrees[j],tmp_sub[j]); + } -/* phydbl IncompleteGamma(phydbl x, phydbl alpha, phydbl ln_gamma_alpha) */ -/* { */ -/* /\* returns the incomplete gamma ratio I(x,alpha) where x is the upper */ -/* limit of the integration and alpha is the shape parameter. */ -/* returns (-1) if in error */ -/* ln_gamma_alpha = ln(Gamma(alpha)), is almost redundant. */ -/* (1) series expansion if (alpha>x || x<=1) */ -/* (2) continued fraction otherwise */ -/* RATNEST FORTRAN by */ -/* Bhattacharjee GP (1970) The incomplete gamma integral. Applied Statistics, */ -/* 19: 285-287 (AS32) */ -/* *\/ */ -/* int i; */ -/* phydbl p=alpha, g=ln_gamma_alpha; */ -/* phydbl accurate=1e-8, overflow=1e30; */ -/* phydbl factor, gin=0, rn=0, a=0,b=0,an=0,dif=0, term=0, pn[6]; */ - -/* if (x==0) return (0); */ -/* if (x<0 || p<=0) return (-1); */ - -/* factor=(phydbl)exp(p*(phydbl)log(x)-x-g); */ -/* if (x>1 && x>=p) goto l30; */ -/* /\* (1) series expansion *\/ */ -/* gin=1; term=1; rn=p; */ -/* l20: */ -/* rn++; */ -/* term*=x/rn; gin+=term; */ - -/* if (term > accurate) goto l20; */ -/* gin*=factor/p; */ -/* goto l50; */ -/* l30: */ -/* /\* (2) continued fraction *\/ */ -/* a=1-p; b=a+x+1; term=0; */ -/* pn[0]=1; pn[1]=x; pn[2]=x+1; pn[3]=x*b; */ -/* gin=pn[2]/pn[3]; */ -/* l32: */ -/* a++; b+=2; term++; an=a*term; */ -/* for (i=0; i<2; i++) pn[i+4]=b*pn[i+2]-an*pn[i]; */ -/* if (pn[5] == 0) goto l35; */ -/* rn=pn[4]/pn[5]; dif=fabs(gin-rn); */ -/* if (dif>accurate) goto l34; */ -/* if (dif<=accurate*rn) goto l42; */ -/* l34: */ -/* gin=rn; */ -/* l35: */ -/* for (i=0; i<4; i++) pn[i]=pn[i+2]; */ -/* if (fabs(pn[4]) < overflow) goto l32; */ -/* for (i=0; i<4; i++) pn[i]/=overflow; */ -/* goto l32; */ -/* l42: */ -/* gin=1-factor*gin; */ - -/* l50: */ -/* return (gin); */ -/* } */ + for(i=0;i.999998 || v<=0) return (-1); */ - -/* g = LnGamma (v/2); */ -/* xx=v/2; c=xx-1; */ -/* if (v >= -1.24*(phydbl)log(p)) goto l1; */ - -/* ch=pow((p*xx*(phydbl)exp(g+xx*aa)), 1/xx); */ -/* if (ch-e<0) return (ch); */ -/* goto l4; */ -/* l1: */ -/* if (v>.32) goto l3; */ -/* ch=0.4; a=(phydbl)log(1-p); */ -/* l2: */ -/* q=ch; p1=1+ch*(4.67+ch); p2=ch*(6.73+ch*(6.66+ch)); */ -/* t=-0.5+(4.67+2*ch)/p1 - (6.73+ch*(13.32+3*ch))/p2; */ -/* ch-=(1-(phydbl)exp(a+g+.5*ch+c*aa)*p2/p1)/t; */ -/* if (fabs(q/ch-1)-.01 <= 0) goto l4; */ -/* else goto l2; */ - -/* l3: */ -/* x=PointNormal (p); */ -/* p1=0.222222/v; ch=v*pow((x*sqrt(p1)+1-p1), 3.0); */ -/* if (ch>2.2*v+6) ch=-2*((phydbl)log(1-p)-c*(phydbl)log(.5*ch)+g); */ -/* l4: */ -/* q=ch; p1=.5*ch; */ -/* if ((t=IncompleteGamma (p1, xx, g))<0) { */ -/* printf ("\nerr IncompleteGamma"); */ -/* return (-1); */ -/* } */ -/* p2=p-t; */ -/* t=p2*(phydbl)exp(xx*aa+g+p1-c*(phydbl)log(ch)); */ -/* b=t/ch; a=0.5*t-b*c; */ - -/* s1=(210+a*(140+a*(105+a*(84+a*(70+60*a))))) / 420; */ -/* s2=(420+a*(735+a*(966+a*(1141+1278*a))))/2520; */ -/* s3=(210+a*(462+a*(707+932*a)))/2520; */ -/* s4=(252+a*(672+1182*a)+c*(294+a*(889+1740*a)))/5040; */ -/* s5=(84+264*a+c*(175+606*a))/2520; */ -/* s6=(120+c*(346+127*c))/5040; */ -/* ch+=t*(1+0.5*t*s1-b*c*(s1-b*(s2-b*(s3-b*(s4-b*(s5-b*s6)))))); */ -/* if (fabs(q/ch-1) > e) goto l4; */ - -/* return (ch); */ -/* } */ + if(a == b->rght) + { + PhyML_Fprintf(stderr,"\n. a->num = %d ; d->num = %d",a->num,d->num); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } -/* /\*********************************************************\/ */ + if(d == b->left) + { + PhyML_Fprintf(stderr,"\n. a->num = %d ; d->num = %d",a->num,d->num); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } -/* phydbl PointNormal (phydbl prob) */ -/* { */ -/* /\* returns z so that Prob{xl_r = b->r_l = -1; + for(i=0;i<3;i++) + { + /* if((a->v[i]) && ((a->v[i] == d) || (e_root && a->b[i] == e_root))) */ + if((a->v[i]) && ((a->v[i] == d))) + { + b->l_r = i; /* we consider here that 'a' is on the left handside of 'b'*/ + a->b[i] = b; + } + /* if((d->v[i]) && ((d->v[i] == a) || (e_root && d->b[i] == e_root))) */ + if((d->v[i]) && ((d->v[i] == a))) + { + b->r_l = i; /* we consider here that 'd' is on the right handside of 'b'*/ + d->b[i] = b; + } + } -/* int DiscreteGamma (phydbl freqK[], phydbl rK[], */ -/* phydbl alfa, phydbl beta, int K, int median) */ -/* { */ -/* /\* discretization of gamma distribution with equal proportions in each */ -/* category */ -/* *\/ */ - -/* int i; */ -/* phydbl gap05=1.0/(2.0*K), t, factor=alfa/beta*K, lnga1; */ + if(a->tax) {b->r_l = 0; for(i=0;i<3;i++) if(d->v[i]==a) {b->l_r = i; break;}} -/* if(K==1) */ -/* { */ -/* rK[0] = 1.0; */ -/* return 0; */ -/* } */ + b->l_v1 = b->l_v2 = b->r_v1 = b->r_v2 = -1; + for(i=0;i<3;i++) + { + if(b->left->v[i] != b->rght) + { + if(b->l_v1 < 0) b->l_v1 = i; + else b->l_v2 = i; + } -/* if (median) */ -/* { */ -/* for (i=0; irght->v[i] != b->left) + { + if(b->r_v1 < 0) b->r_v1 = i; + else b->r_v2 = i; + } + } +} -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl CDF_Normal(phydbl x, phydbl mean, phydbl var) +void Restrict_To_Coding_Position(align **data, option *io) { - const double b1 = 0.319381530; - const double b2 = -0.356563782; - const double b3 = 1.781477937; - const double b4 = -1.821255978; - const double b5 = 1.330274429; - const double p = 0.2316419; - const double c = 0.39894228; - - x = (x-mean)/var; - - if(x >= 0.0) - { - double t = 1.0 / ( 1.0 + p * x ); - return (1.0 - c * exp( -x * x / 2.0 ) * t * - ( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )); - } - else + int i,j,curr_pos; + + if(io->codpos != -1) { - double t = 1.0 / ( 1.0 - p * x ); - return ( c * exp( -x * x / 2.0 ) * t * - ( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )); + for(i=0;in_otu;i++) + { + curr_pos = 0; + for(j=io->codpos-1;jlen;j+=3) + { + data[i]->state[curr_pos] = data[i]->state[j]; + curr_pos++; + } + data[i]->len /= 3; + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl CDF_Gamma(phydbl x, phydbl mean, phydbl var) +void Uppercase(char *ch) { - phydbl scale,shape; - - scale = var / mean; - shape = mean * mean / var; - -/* scale = mean; */ -/* shape = var; */ - - printf("\n. shape=%f, scale=%f",shape,scale); - return IncompleteGamma(x/scale,shape,LnGamma(shape)); + /* convert ch to upper case -- either ASCII or EBCDIC */ + *ch = isupper((int)*ch) ? *ch : toupper((int)*ch); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Rand_Normal_Deviate(phydbl mean, phydbl sd) +void Lowercase(char *ch) { - int i; - phydbl x=.0; - For(i,12) x += (phydbl)rand()/(RAND_MAX); - return sd * (x-6.0) + mean; + /* convert ch to upper case -- either ASCII or EBCDIC */ + *ch = isupper((int)*ch) ? tolower((int)*ch) : *ch; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -arbre *Read_Tree(char *s_tree) +calign *Compact_Data(align **data, option *io) { - char **subs; - int i,n_ext,n_int,n_otu; - arbre *tree; - int degree; - + calign *cdata_tmp,*cdata; + int i,j,k,site; + int n_patt,which_patt; + char **sp_names; + int n_otu; + pnode *proot; + int compress; + int n_ambigu,is_ambigu; + scalar_dbl *io_wght; + phydbl len,inc,n_invar; - n_otu=0; - For(i,(int)strlen(s_tree)) if(s_tree[i] == ',') n_otu++; - n_otu+=1; - tree = (arbre *)Make_Tree(n_otu); - Init_Tree(tree,tree->n_otu); - Make_All_Tree_Nodes(tree); - Make_All_Tree_Edges(tree); - Make_Tree_Path(tree); - Make_List_Of_Reachable_Tips(tree); + n_otu = io->n_otu; + n_patt = 0; + which_patt = 0; - tree->noeud[n_otu]->num = n_otu; - tree->noeud[n_otu]->tax = 0; + sp_names = (char **)mCalloc(n_otu,sizeof(char *)); + for(i=0;iname); + } - subs = Sub_Trees(s_tree,°ree); - Clean_Multifurcation(subs,degree,3); - if(degree == 2) Unroot_Tree(subs); - degree = 3; + cdata_tmp = Make_Calign(n_otu,data[0]->len,io->state_len,data[0]->len,sp_names,0,NULL); + Init_Calign(n_otu,data[0]->len,data[0]->len,cdata_tmp); - tree->has_branch_lengths = 0; - tree->num_curr_branch_available = 0; - n_int = n_ext = 0; - For(i,degree) R_rtree(s_tree,subs[i],tree->noeud[n_otu],tree,&n_int,&n_ext); + proot = (pnode *)Create_Pnode(T_MAX_ALPHABET); - For(i,NODE_DEG_MAX) Free(subs[i]); - Free(subs); - return tree; -} + for(i=0;ilen%io->state_len) + { + PhyML_Fprintf(stderr,"\n. Sequence length is not a multiple of %d\n",io->state_len); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } -/* void Make_All_Edges_Light(node *a, node *d, int *curr_num_edge) */ -/* { */ -/* int i; */ + // Read in weights given in input file + io_wght = NULL; + if(io->has_io_weights == YES) + { + io_wght = Read_Io_Weights(io); + if(Scalar_Len(io_wght) - data[0]->len > 0) + { + PhyML_Fprintf(stderr,"\n. Sequence length (%d) differs from number of weights (%d).\n", + data[0]->len, + Scalar_Len(io_wght)); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } -/* Make_Edge_Light(a,d,*curr_num_edge); */ -/* (*curr_num_edge)++; */ -/* if(d->tax) return; */ -/* else */ -/* { */ -/* For(i,3) */ -/* { */ -/* if(d->v[i] != a) */ -/* Make_All_Edges_Light(d,d->v[i],curr_num_edge); */ -/* } */ -/* } */ -/* } */ + compress = io->colalias; + n_ambigu = 0; + is_ambigu = NO; -/*********************************************************/ + if(!io->quiet && !compress) PhyML_Printf("\n. WARNING: sequences are not compressed !\n"); -void Make_All_Edges_Lk(node *a, node *d, arbre *tree) -{ - int i; + inc = -1.0; + len = 0.0; + Fors(site,data[0]->len,io->state_len) + { + if(io->has_io_weights == YES) + inc = Scalar_Elem(site,io_wght); + else + inc = 1.; + + // Sequence length taking into account input weights, if any + len += inc; - For(i,3) if((a->v[i]) && (a->v[i] == d)) Make_Edge_Lk(a->b[i],tree); - if(d->tax) return; - else - { - For(i,3) - { - if(d->v[i] != a) - Make_All_Edges_Lk(d,d->v[i],tree); - } + if(io->rm_ambigu == YES) + { + is_ambigu = NO; + for(j=0;jstate+site,io->datatype,io->state_len)) break; + if(j != n_otu) + { + is_ambigu = YES; + n_ambigu++; + } + } + + if(!is_ambigu) + { + if(compress) + { + which_patt = -1; + + Traverse_Prefix_Tree(site,-1,&which_patt,&n_patt,data,io,proot); + if(which_patt == n_patt-1) /* New pattern found */ + { + n_patt--; + k = n_patt; + } + else + { + k = n_patt-10; + } + } + else + { + k = n_patt; + } + + if(k == n_patt) /* add a new site pattern */ + { + for(j=0;jstate+site, + cdata_tmp->c_seq[j]->state+n_patt*io->state_len, + io->state_len); + + for(j=0;jc_seq[j]->state[n_patt*io->state_len+1] = '\0'; + + for(i=0;ic_seq[i]->state+n_patt*io->state_len, + cdata_tmp->c_seq[j]->state+n_patt*io->state_len, + io->state_len, + io->datatype))) break; + } + if(j != n_otu) break; + } + + if((j == n_otu) && (i == n_otu)) /* all characters at that site are compatible with one another: + the site may be invariant */ + { + for(j=0;jinvar[n_patt] = Assign_State(cdata_tmp->c_seq[j]->state+n_patt*io->state_len, + io->datatype, + io->state_len); + + if(cdata_tmp->invar[n_patt] > -1.) break; + } + } + else cdata_tmp->invar[n_patt] = -1; + + cdata_tmp->sitepatt[site] = n_patt; + cdata_tmp->wght[n_patt] += inc; + n_patt += 1; + } + else + { + cdata_tmp->sitepatt[site] = which_patt; + cdata_tmp->wght[which_patt] += inc; + } + } } -} + + data[0]->len -= n_ambigu; + + cdata_tmp->init_len = data[0]->len; + cdata_tmp->crunch_len = n_patt; + for(i=0;ic_seq[i]->len = n_patt; + for(i=0;ic_seq[i]->num = i; + + if(!io->quiet) PhyML_Printf("\n. %d patterns found (out of a total of %d sites). \n",n_patt,data[0]->len); -/*********************************************************/ -/* 'a' in node a stands for ancestor. 'd' stands for descendant */ -void R_rtree(char *s_tree_a, char *s_tree_d, node *a, arbre *tree, int *n_int, int *n_ext) -{ - int i; - node *d; - int n_otu = tree->n_otu; + if((io->rm_ambigu == YES) && (n_ambigu > 0)) PhyML_Printf("\n. Removed %d columns of the alignment as they contain ambiguous characters (e.g., gaps) \n",n_ambigu); - if(strstr(s_tree_a," ")) Warn_And_Exit("\n Err : tree must not contain a ' ' character\n"); + n_invar=0.0; + for(i=0;icrunch_len;i++) if(cdata_tmp->invar[i] > -1.) n_invar+=cdata_tmp->wght[i]; - if(s_tree_d[0] == '(') + if(io->quiet == NO) { - char **subs; - int degree; - - (*n_int)+=1; - d = tree->noeud[n_otu+*n_int]; - d->num = n_otu+*n_int; - d->tax = 0; + if((n_invar - ceil(n_invar)) < 1.E-10) + PhyML_Printf("\n. %d sites without polymorphism (%.2f%c).\n",(int)n_invar,100.*(phydbl)n_invar/len,'%'); + else + PhyML_Printf("\n. %f sites without polymorphism (%.2f%c).\n",n_invar,100.*(phydbl)n_invar/len,'%'); + } - Read_Branch_Label(s_tree_d,s_tree_a,tree->t_edges[tree->num_curr_branch_available]); - Read_Branch_Length(s_tree_d,s_tree_a,tree); + cdata_tmp->obs_pinvar = (phydbl)n_invar/len; - For(i,3) - { - if(!a->v[i]) - { - a->v[i]=d; - d->l[0]=a->l[i]=tree->t_edges[tree->num_curr_branch_available]->l; - break; - } - } - d->v[0]=a; + cdata_tmp->io = io; - Connect_One_Edge_To_Two_Nodes(a,d,tree->t_edges[tree->num_curr_branch_available],tree); - tree->num_curr_branch_available++; + + if(io->datatype == NT) Get_Base_Freqs(cdata_tmp); + else if(io->datatype == AA) Get_AA_Freqs(cdata_tmp); + else {/* Uniform state frequency distribution.*/} - subs=Sub_Trees(s_tree_d,°ree); - Clean_Multifurcation(subs,degree,2); - R_rtree(s_tree_d,subs[0],d,tree,n_int,n_ext); - R_rtree(s_tree_d,subs[1],d,tree,n_int,n_ext); - For(i,NODE_DEG_MAX) Free(subs[i]); - Free(subs); - } + cdata = Copy_Cseq(cdata_tmp,io); - else - { - int i; + Free_Calign(cdata_tmp); + Free_Prefix_Tree(proot,T_MAX_ALPHABET); - d = tree->noeud[*n_ext]; - d->tax = 1; + Check_Ambiguities(cdata,io->datatype,io->state_len); + Set_D_States(cdata,io->datatype,io->state_len); - Read_Branch_Label(s_tree_d,s_tree_a,tree->t_edges[tree->num_curr_branch_available]); - Read_Branch_Length(s_tree_d,s_tree_a,tree); - Read_Node_Name(d,s_tree_d,tree); - - For(i,3) - { - if(!a->v[i]) - { - a->v[i]=d; - d->l[0]=a->l[i]=tree->t_edges[tree->num_curr_branch_available]->l; - break; - } - } - d->v[0]=a; + if(io_wght != NULL) Free_Scalar_Dbl(io_wght); - Connect_One_Edge_To_Two_Nodes(a,d,tree->t_edges[tree->num_curr_branch_available],tree); - tree->num_curr_branch_available++; - - d->num=*n_ext; - (*n_ext)+=1; - } + return cdata; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Read_Branch_Label(char *s_d, char *s_a, edge *b) + +calign *Compact_Cdata(calign *data, option *io) { - char *sub_tp; - char *p; - int i,pos; + calign *cdata; + int i,j,k,site; + int n_patt,which_patt; + int n_otu; - sub_tp = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + n_otu = data->n_otu; - strcpy(sub_tp,s_d); - strcat(sub_tp,"#"); - p = strstr(s_a,sub_tp); - i = 0; - b->n_labels = 0; - if(p) - { - if(!(b->n_labels%BLOCK_LABELS)) Make_New_Edge_Label(b); - b->n_labels++; - - pos = 0; - do - { - b->labels[b->n_labels-1][pos] = p[i+strlen(s_d)+1]; - i++; - pos++; - if(p[i+strlen(s_d)+1] == '#') - { - b->labels[b->n_labels-1][pos] = '\0'; - b->n_labels++; - if(!(b->n_labels%BLOCK_LABELS)) Make_New_Edge_Label(b); - i++; - pos=0; - } - } - while((p[i+strlen(s_d)+1] != ':') && - (p[i+strlen(s_d)+1] != ',') && - (p[i+strlen(s_d)+1] != '(')); + cdata = (calign *)mCalloc(1,sizeof(calign)); + cdata->n_otu = n_otu; + cdata->c_seq = (align **)mCalloc(n_otu,sizeof(align *)); + cdata->wght = (phydbl *)mCalloc(data->crunch_len,sizeof(phydbl)); + cdata->obs_state_frq = (phydbl *)mCalloc(io->mod->ns,sizeof(phydbl)); + cdata->ambigu = (short int *)mCalloc(data->crunch_len,sizeof(short int)); + cdata->invar = (short int *)mCalloc(data->crunch_len,sizeof(short int)); - b->labels[b->n_labels-1][pos] = '\0'; + cdata->crunch_len = cdata->init_len = -1; + for(j=0;jc_seq[j] = (align *)mCalloc(1,sizeof(align)); + cdata->c_seq[j]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + strcpy(cdata->c_seq[j]->name,data->c_seq[j]->name); + cdata->c_seq[j]->state = (char *)mCalloc(data->crunch_len,sizeof(char)); + cdata->c_seq[j]->is_ambigu = (short int *)mCalloc(data->crunch_len,sizeof(short int)); + cdata->c_seq[j]->state[0] = data->c_seq[j]->state[0]; } - if(p) + + n_patt = which_patt = 0; + + for(site=0;sitecrunch_len;site++) { - if(b->n_labels == 1) - printf("\n. Found label '%s' on edge %3d.",b->labels[0],b->num); - else - { - printf("\n. Found labels "); - For(i,b->n_labels) printf("'%s' ",b->labels[i]); - printf("on edge %3d.",b->num); - } + if(data->wght[site] > 0.0) + { + for(k=0;kc_seq[j]->state+k*io->state_len, + data->c_seq[j]->state+site*io->state_len, + io->state_len)) + break; + } + + if(j == n_otu) + { + which_patt = k; + break; + } + } + + if(k == n_patt) + { + for(j=0;jc_seq[j]->state+site*io->state_len, + cdata->c_seq[j]->state+n_patt*io->state_len, + io->state_len); + + for(i=0;ic_seq[i]->state+n_patt*io->state_len, + cdata->c_seq[j]->state+n_patt*io->state_len, + io->state_len, + io->datatype))) break; + } + if(j != n_otu) break; + } + + if((j == n_otu) && (i == n_otu)) + { + for(j=0;jinvar[n_patt] = Assign_State(cdata->c_seq[j]->state+n_patt*io->state_len, + io->datatype, + io->state_len); + + if(cdata->invar[n_patt] > -1.) break; + } + } + else cdata->invar[n_patt] = -1; + + cdata->wght[n_patt] += data->wght[site]; + n_patt+=1; + } + else cdata->wght[which_patt] += data->wght[site]; + + /* Print_Site(cdata,k,n_otu,"\n",io->stepsize); */ + } } + + cdata->init_len = data->crunch_len; + cdata->crunch_len = n_patt; + for(i=0;ic_seq[i]->len = n_patt; + + if(io->datatype == NT) Get_Base_Freqs(cdata); + else if(io->datatype == AA) Get_AA_Freqs(cdata); + else {/* Not implemented yet */} - Free(sub_tp); + return cdata; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Read_Branch_Length(char *s_d, char *s_a, arbre *tree) +void Traverse_Prefix_Tree(int site, int seqnum, int *patt_num, int *n_patt, align **data, option *io, pnode *n) { - char *sub_tp; - char *p; - edge *b; - int i; - - b = tree->t_edges[tree->num_curr_branch_available]; - - sub_tp = (char *)mCalloc(T_MAX_LINE,sizeof(char)); - - For(i,b->n_labels) + if(seqnum == io->n_otu-1) { - strcat(s_d,"#"); - strcat(s_d,b->labels[i]); + n->weight++; + if(n->weight == 1) + { + n->num = *n_patt; + (*n_patt) += 1; + } + (*patt_num) = n->num; + return; } - - strcpy(sub_tp,s_d); - strcat(sub_tp,":"); - p = strstr(s_a,sub_tp); - if(p) + else { - b->l = atof((char *)p+(int)strlen(sub_tp)+1); - tree->has_branch_lengths = 1; + int next_state; + + next_state = -1; + next_state = Assign_State_With_Ambiguity(data[seqnum+1]->state+site, + io->datatype, + io->state_len); + + if(!n->next[next_state]) n->next[next_state] = Create_Pnode(T_MAX_ALPHABET); + Traverse_Prefix_Tree(site,seqnum+1,patt_num,n_patt,data,io,n->next[next_state]); } - Free(sub_tp); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void Read_Node_Name(node *d, char *s_tree_d, arbre *tree) +pnode *Create_Pnode(int size) { + pnode *n; int i; - if(!tree->t_edges[tree->num_curr_branch_available]->n_labels) - { - strcpy(d->name,s_tree_d); - } - else - { - i = 0; - do - { - d->name[i] = s_tree_d[i]; - i++; - } - while(s_tree_d[i] != '#'); - d->name[i] = '\0'; - } + n = (pnode *)mCalloc(1,sizeof(pnode )); + n->next = (pnode **)mCalloc(size,sizeof(pnode *)); + for(i=0;inext[i] = NULL; + n->weight = 0; + n->num = -1; + return n; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Unroot_Tree(char **subtrees) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Get_Base_Freqs(calign *data) { - char **tmp_sub; - int degree,i,j; + int i,j,k; + phydbl A,C,G,T; + phydbl fA,fC,fG,fT; + phydbl w; - printf("\n. Removing the root...\n"); - - tmp_sub = Sub_Trees(subtrees[0],°ree); - if(degree >= 2) - { - strcpy(subtrees[2],subtrees[1]); - Clean_Multifurcation(tmp_sub,degree,2); - For(j,2) strcpy(subtrees[j],tmp_sub[j]); - } - else + fA = fC = fG = fT = .25; + + for(k=0;k<8;k++) { - tmp_sub = Sub_Trees(subtrees[1],°ree); - strcpy(subtrees[2],subtrees[0]); - Clean_Multifurcation(tmp_sub,degree,2); - For(j,2) strcpy(subtrees[j],tmp_sub[j]); + A = C = G = T = .0; + for(i=0;in_otu;i++) + { + for(j=0;jcrunch_len;j++) + { + w = data->wght[j]; + if(w) + { + switch(data->c_seq[i]->state[j]) + { + case 'A' : A+=w; + break; + case 'C' : C+=w; + break; + case 'G' : G+=w; + break; + case 'T' : T+=w; + break; + case 'U' : T+=w; + break; + case 'M' : C+=w*fC/(fC+fA); A+=w*fA/(fA+fC); + break; + case 'R' : G+=w*fG/(fA+fG); A+=w*fA/(fA+fG); + break; + case 'W' : T+=w*fT/(fA+fT); A+=w*fA/(fA+fT); + break; + case 'S' : C+=w*fC/(fC+fG); G+=w*fG/(fC+fG); + break; + case 'Y' : C+=w*fC/(fC+fT); T+=w*fT/(fT+fC); + break; + case 'K' : G+=w*fG/(fG+fT); T+=w*fT/(fT+fG); + break; + case 'B' : C+=w*fC/(fC+fG+fT); G+=w*fG/(fC+fG+fT); T+=w*fT/(fC+fG+fT); + break; + case 'D' : A+=w*fA/(fA+fG+fT); G+=w*fG/(fA+fG+fT); T+=w*fT/(fA+fG+fT); + break; + case 'H' : A+=w*fA/(fA+fC+fT); C+=w*fC/(fA+fC+fT); T+=w*fT/(fA+fC+fT); + break; + case 'V' : A+=w*fA/(fA+fC+fG); C+=w*fC/(fA+fC+fG); G+=w*fG/(fA+fC+fG); + break; + case 'N' : case 'X' : case '?' : case 'O' : case '-' : + A+=w*fA; C+=w*fC; G+=w*fG; T+=w*fT; break; + default : break; + } + } + } + } + fA = A/(A+C+G+T); + fC = C/(A+C+G+T); + fG = G/(A+C+G+T); + fT = T/(A+C+G+T); } - - For(i,degree) Free(tmp_sub[i]); - Free(tmp_sub); + + data->obs_state_frq[0] = fA; + data->obs_state_frq[1] = fC; + data->obs_state_frq[2] = fG; + data->obs_state_frq[3] = fT; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Clean_Multifurcation(char **subtrees, int current_deg, int end_deg) +void Get_AA_Freqs(calign *data) { + int i,j,k; + phydbl A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y; + phydbl fA,fC,fD,fE,fF,fG,fH,fI,fK,fL,fM,fN,fP,fQ,fR,fS,fT,fV,fW,fY; + int w; + phydbl sum; - if(current_deg <= end_deg) return; - else - { - char *s_tmp; - int i; - - s_tmp = (char *)mCalloc(T_MAX_LINE,sizeof(char)); - - strcat(s_tmp,"(\0"); - strcat(s_tmp,subtrees[0]); - strcat(s_tmp,",\0"); - strcat(s_tmp,subtrees[1]); - strcat(s_tmp,")\0"); - Free(subtrees[0]); - subtrees[0] = s_tmp; - - for(i=1;in_otu;i++) + { + for(j=0;jcrunch_len;j++) + { + w = data->wght[j]; + if(w) + { + switch(data->c_seq[i]->state[j]) + { + case 'A' : A+=w; break; + case 'C' : C+=w; break; + case 'D' : D+=w; break; + case 'E' : E+=w; break; + case 'F' : F+=w; break; + case 'G' : G+=w; break; + case 'H' : H+=w; break; + case 'I' : I+=w; break; + case 'K' : K+=w; break; + case 'L' : L+=w; break; + case 'M' : M+=w; break; + case 'N' : N+=w; break; + case 'P' : P+=w; break; + case 'Q' : Q+=w; break; + case 'R' : R+=w; break; + case 'S' : S+=w; break; + case 'T' : T+=w; break; + case 'V' : V+=w; break; + case 'W' : W+=w; break; + case 'Y' : Y+=w; break; + case 'Z' : Q+=w; break; + case 'X' : case '?' : case 'O' : case '-' : + A+=w*fA; + C+=w*fC; + D+=w*fD; + E+=w*fE; + F+=w*fF; + G+=w*fG; + H+=w*fH; + I+=w*fI; + K+=w*fK; + L+=w*fL; + M+=w*fM; + N+=w*fN; + P+=w*fP; + Q+=w*fQ; + R+=w*fR; + S+=w*fS; + T+=w*fT; + V+=w*fV; + W+=w*fW; + Y+=w*fY; + break; + default : break; + } + } + } + } + sum = (A+C+D+E+F+G+H+I+K+L+M+N+P+Q+R+S+T+V+W+Y); + fA = A/sum; fC = C/sum; fD = D/sum; fE = E/sum; + fF = F/sum; fG = G/sum; fH = H/sum; fI = I/sum; + fK = K/sum; fL = L/sum; fM = M/sum; fN = N/sum; + fP = P/sum; fQ = Q/sum; fR = R/sum; fS = S/sum; + fT = T/sum; fV = V/sum; fW = W/sum; fY = Y/sum; } + + data->obs_state_frq[0] = fA; data->obs_state_frq[1] = fR; data->obs_state_frq[2] = fN; data->obs_state_frq[3] = fD; + data->obs_state_frq[4] = fC; data->obs_state_frq[5] = fQ; data->obs_state_frq[6] = fE; data->obs_state_frq[7] = fG; + data->obs_state_frq[8] = fH; data->obs_state_frq[9] = fI; data->obs_state_frq[10] = fL; data->obs_state_frq[11] = fK; + data->obs_state_frq[12] = fM; data->obs_state_frq[13] = fF; data->obs_state_frq[14] = fP; data->obs_state_frq[15] = fS; + data->obs_state_frq[16] = fT; data->obs_state_frq[17] = fW; data->obs_state_frq[18] = fY; data->obs_state_frq[19] = fV; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -char **Sub_Trees(char *tree, int *degree) +// Swap the nodes on the left and right of e1 with the nodes +// on the left and right of e2 respectively, or on the +// right and left of e2 if swap == YES + +void Swap_Nodes_On_Edges(t_edge *e1, t_edge *e2, int swap, t_tree *tree) { - char **subs; - int posbeg,posend; - int i; + t_node *buff; - if(tree[0] != '(') {*degree = 1; return NULL;} + printf("\n. Swap edge %d (%d %d) with %d (%d %d)",e1->num,e1->left->num,e1->rght->num,e2->num,e2->left->num,e2->rght->num); - subs=(char **)mCalloc(NODE_DEG_MAX,sizeof(char *)); + if(swap == NO) + { + buff = e1->left; + e1->left = e2->left; + e2->left = buff; - For(i,NODE_DEG_MAX) subs[i]=(char *)mCalloc(strlen(tree)+1,sizeof(char)); + buff = e1->rght; + e1->rght = e2->rght; + e2->rght = buff; - - posbeg=posend=1; - (*degree)=0; - do + } + else { - posbeg = posend; - if(tree[posend] != '(') - { - while((tree[posend] != ',' ) && - (tree[posend] != ':' ) && - (tree[posend] != '#' ) && - (tree[posend] != ')' )) - { - posend++ ; - } - posend -= 1; - } - else posend=Next_Par(tree,posend); - - while((tree[posend+1] != ',') && - (tree[posend+1] != ':') && - (tree[posend+1] != '#') && - (tree[posend+1] != ')')) {posend++;} + buff = e1->left; + e1->left = e2->rght; + e2->rght = buff; + buff = e1->rght; + e1->rght = e2->left; + e2->left = buff; + } - strncpy(subs[(*degree)],tree+posbeg,posend-posbeg+1); - strcat(subs[(*degree)],"\0"); + Connect_One_Edge_To_Two_Nodes(e1->left,e1->rght,e1,tree); + Connect_One_Edge_To_Two_Nodes(e2->left,e2->rght,e2,tree); +} - posend += 1; - while((tree[posend] != ',') && - (tree[posend] != ')')) {posend++;} - posend+=1; +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* As opposed to Connect_Edges_To_Nodes_Recur, the ordering of + edges connected to tips does not depend on the topology. + Use this function when you just have a table of edges not + not connected to any node and the reciprocal is true. +*/ +void Connect_Edges_To_Nodes_Serial(t_tree *tree) +{ + int i,j; + /* Reset */ + for(i=0;i<2*tree->n_otu-1;++i) for(j=0;j<3;j++) if(tree->a_nodes[i] != NULL) tree->a_nodes[i]->b[j] = NULL; + + for(i=0;in_otu;i++) + { + assert(tree->a_nodes[i]->tax); + assert(tree->a_nodes[i] != tree->a_nodes[i]->v[0]); - (*degree)++; - if((*degree) == NODE_DEG_MAX) - { - For(i,(*degree)) - printf("\n. Subtree %d : %s\n",i+1,subs[i]); + // Required so that p_lk_tip_r corresponds to the sequence at tree->a_nodes[i] + if(tree->a_edges[i]->p_lk_tip_r != NULL) assert(tree->a_edges[i]->rght == tree->a_nodes[i]); - printf("\n. The degree of a node cannot be greater than %d\n",NODE_DEG_MAX); - Warn_And_Exit("\n"); - } + Connect_One_Edge_To_Two_Nodes(tree->a_nodes[i], + tree->a_nodes[i]->v[0], + tree->a_edges[i], + tree); } - while(tree[posend-1] != ')'); - return subs; -} + tree->num_curr_branch_available = tree->n_otu; -/*********************************************************/ + for(i=tree->n_otu;i<2*tree->n_otu-3;i++) + { + assert(!tree->a_nodes[i]->tax); -int Next_Par(char *s, int pos) -{ - int curr; + for(j=0;j<3;j++) + if(!tree->a_nodes[i]->b[j]) + { + assert(tree->a_nodes[i] != tree->a_nodes[i]->v[j]); - curr=pos+1; + Connect_One_Edge_To_Two_Nodes(tree->a_nodes[i], + tree->a_nodes[i]->v[j], + tree->a_edges[tree->num_curr_branch_available], + tree); + } + } - while(*(s+curr) != ')') + if(tree->n_root != NULL) { - if(*(s+curr) == '(') curr=Next_Par(s,curr); - curr++; + tree->a_edges[tree->num_curr_branch_available]->left = tree->n_root; + tree->a_edges[tree->num_curr_branch_available]->rght = tree->n_root->v[1]; + tree->n_root->b[1] = tree->a_edges[tree->num_curr_branch_available]; + tree->a_edges[tree->num_curr_branch_available]->num = tree->num_curr_branch_available; + tree->num_curr_branch_available++; + + tree->a_edges[tree->num_curr_branch_available]->left = tree->n_root; + tree->a_edges[tree->num_curr_branch_available]->rght = tree->n_root->v[2]; + tree->n_root->b[2] = tree->a_edges[tree->num_curr_branch_available]; + tree->a_edges[tree->num_curr_branch_available]->num = tree->num_curr_branch_available; + tree->num_curr_branch_available++; } - - return curr; } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Print_Tree(FILE *fp, arbre *tree) +void Connect_Edges_To_Nodes_Recur(t_node *a, t_node *d, t_tree *tree) { - char *s_tree; int i; - s_tree = (char *)Write_Tree(tree); + assert(a!=d); + Connect_One_Edge_To_Two_Nodes(a,d,tree->a_edges[tree->num_curr_branch_available],tree); - if(OUTPUT_TREE_FORMAT == 0) - fprintf(fp,"%s\n",s_tree); - else if(OUTPUT_TREE_FORMAT == 1) - { - fprintf(fp,"#NEXUS\n"); - fprintf(fp,"BEGIN TREES;\n"); - fprintf(fp,"\tTRANSLATE\n"); - For(i,tree->n_otu) fprintf(fp,"\t%3d\t%s,\n",i+1,tree->noeud[i]->name); - fprintf(fp,"\tUTREE PAUP_1=\n"); - fprintf(fp,"%s\n",s_tree); - fprintf(fp,"ENDBLOCK;"); - } - Free(s_tree); + if(d->tax) return; + else + for(i=0;i<3;i++) + if(d->v[i] != a) /* Don't add d->b[i] != tree->e_root condition here since tree is not wired yet... */ + Connect_Edges_To_Nodes_Recur(d,d->v[i],tree); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -char *Write_Tree(arbre *tree) +void Connect_One_Edge_To_Two_Nodes(t_node *a, t_node *d, t_edge *b, t_tree *tree) { + int i,dir_a_d,dir_d_a; - char *s; - int i; + assert(a != tree->n_root); + assert(b); + + if(a == NULL || d == NULL || a->num == d->num) + { + PhyML_Fprintf(stderr,"\n. a: %d d: %d b: %d root: %d",a?a->num:-1,d?d->num:-1,b?b->num:-1,tree->n_root?tree->n_root->num:-1); + assert(FALSE); + } - s=(char *)mCalloc(T_MAX_LINE,sizeof(char)); + dir_a_d = -1; + for(i=0;i<3;i++) if(a->v[i] == d) { dir_a_d = i; break; } + + dir_d_a = -1; + for(i=0;i<3;i++) if(d->v[i] == a) { dir_d_a = i; break; } - s[0]='('; + if(dir_a_d == -1 || dir_d_a == -1) + { + PhyML_Printf("\n. a:%d a->v[0]:%d a->v[1]:%d a->v[2]:%d d:%d d->v[0]:%d d->v[1]:%d d->v[2]:%d root:%d", + a->num, + a->v[0]?a->v[0]->num:-1, + a->v[1]?a->v[1]->num:-1, + a->v[2]?a->v[2]->num:-1, + d->num, + d->v[0]?d->v[0]->num:-1, + d->v[1]?d->v[1]->num:-1, + d->v[2]?d->v[2]->num:-1, + tree->n_root ? tree->n_root->num : -1); + assert(FALSE); + } - #ifdef PHYML - tree->n_root = NULL; - tree->e_root = NULL; - #endif + a->b[dir_a_d] = b; + d->b[dir_d_a] = b; + b->left = a; + b->rght = d; + if(a->tax) {b->rght = a; b->left = d;} /* root */ + /* a tip is necessarily on the righthand side of the t_edge */ -/* if(!tree->n_root) */ -/* { */ - i = 0; - while((!tree->noeud[tree->n_otu+i]->v[0]) || - (!tree->noeud[tree->n_otu+i]->v[1]) || - (!tree->noeud[tree->n_otu+i]->v[2])) i++; - - R_wtree(tree->noeud[tree->n_otu+i],tree->noeud[tree->n_otu+i]->v[0],s,tree); - R_wtree(tree->noeud[tree->n_otu+i],tree->noeud[tree->n_otu+i]->v[1],s,tree); - R_wtree(tree->noeud[tree->n_otu+i],tree->noeud[tree->n_otu+i]->v[2],s,tree); -/* } */ -/* else */ -/* { */ -/* R_wtree(tree->n_root,tree->n_root->v[0],s,tree); */ -/* R_wtree(tree->n_root,tree->n_root->v[1],s,tree); */ -/* } */ + if(a->tax == NO && d->tax == NO) + { + b->num = tree->num_curr_branch_available; + tree->num_curr_branch_available++; + } + else if(d->tax) b->num = d->num; + else if(a->tax) b->num = a->num; + else assert(FALSE); - s[(int)strlen(s)-1]=')'; - s[(int)strlen(s)]=';'; + assert(a != d); + + (b->left == a)? + (Set_Edge_Dirs(b,a,d,tree)): + (Set_Edge_Dirs(b,d,a,tree)); - return s; + b->l_old->v = b->l->v; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void R_wtree(node *pere, node *fils, char *s_tree, arbre *tree) +void Update_Dirs(t_tree *tree) { - int i,p; - - p = -1; - if(fils->tax) - { - if(OUTPUT_TREE_FORMAT == 0) - strcat(s_tree,fils->name); - else - sprintf(s_tree+(int)strlen(s_tree),"%d",fils->num+1); + int i; + int buff; + t_edge *b; - if((fils->b[0]) && (fils->b[0]->l != -1)) - { - if(tree->print_labels) - { - if(fils->b[0]->n_labels < 10) - For(i,fils->b[0]->n_labels) sprintf(s_tree+(int)strlen(s_tree),"#%s",fils->b[0]->labels[i]); - else - sprintf(s_tree+(int)strlen(s_tree),"#%d_labels",fils->b[0]->n_labels); - } - - strcat(s_tree,":"); -/* sprintf(s_tree+(int)strlen(s_tree),"%.10f",fils->b[0]->l); */ - sprintf(s_tree+(int)strlen(s_tree),"%f",fils->b[0]->l); - } - sprintf(s_tree+(int)strlen(s_tree),","); - } - else + b = NULL; + buff = -1; + for(i=0;i<2*tree->n_otu-3;++i) { - s_tree[(int)strlen(s_tree)]='('; - For(i,3) - { -/* if((fils->v[i] != pere) && (fils->b[i] != tree->e_root)) */ - if(fils->v[i] != pere) - R_wtree(fils,fils->v[i],s_tree,tree); - else p=i; - } - s_tree[(int)strlen(s_tree)-1]=')'; - if(fils->b[0]->l != -1) - { - if(tree->print_boot_val) - sprintf(s_tree+(int)strlen(s_tree),"%d",fils->b[p]->bip_score); - else if(tree->print_alrt_val) - sprintf(s_tree+(int)strlen(s_tree),"%f",fils->b[p]->ratio_test); + b = tree->a_edges[i]; - if(tree->print_labels) - { - if(fils->b[p]->n_labels < 10) - For(i,fils->b[p]->n_labels) sprintf(s_tree+(int)strlen(s_tree),"#%s",fils->b[p]->labels[i]); - else - sprintf(s_tree+(int)strlen(s_tree),"#%d_labels",fils->b[p]->n_labels); - } - - strcat(s_tree,":"); - sprintf(s_tree+(int)strlen(s_tree),"%f",fils->b[p]->l); - - strcat(s_tree,","); - } + if((!b->left->tax) && (b->left->v[b->l_v1]->num < b->left->v[b->l_v2]->num)) + { + buff = b->l_v1; + b->l_v1 = b->l_v2; + b->l_v2 = buff; + } + if((!b->rght->tax) && (b->rght->v[b->r_v1]->num < b->rght->v[b->r_v2]->num)) + { + buff = b->r_v1; + b->r_v1 = b->r_v2; + b->r_v2 = buff; + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Init_Tree(arbre *tree, int n_otu) +void Exit(char *message) { - tree->n_otu = n_otu; - tree->best_tree = NULL; - tree->old_tree = NULL; - tree->mat = NULL; - tree->n_root = NULL; - tree->e_root = NULL; - tree->ps_tree = NULL; - - tree->depth_curr_path = 0; - tree->has_bip = 0; - tree->n_moves = 0; - tree->n_improvements = 0; - tree->number_of_lk_calls = 0; - tree->number_of_branch_lk_calls = 0; - tree->bl_from_node_stamps = 0; - tree->lock_topo = 0; - tree->ps_page_number = 0; - tree->init_lnL = UNLIKELY; - tree->best_lnL = UNLIKELY; - tree->c_lnL = UNLIKELY; - tree->n_swap = 0; - - tree->n_pattern = -1; - tree->prop_of_sites_to_consider = 1.; - tree->n_root_pos = -1.; - tree->print_labels = 1; - - tree->print_boot_val = 0; - tree->print_alrt_val = 0; - tree->num_curr_branch_available = 0; + fflush(NULL); + PhyML_Fprintf(stderr,"%s",message); + exit(1); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Make_New_Edge_Label(edge *b) +void *mCalloc(int nb, size_t size) { - int i; - - b->labels = (char **)realloc(b->labels,(b->n_labels+BLOCK_LABELS)*sizeof(char *)); + void *allocated; - if(!b->labels) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } + if((allocated = calloc((size_t)nb,size)) != NULL) +/* if((allocated = malloc((size_t)nb*(size_t)size)) != NULL) */ + return allocated; else - { - for(i=b->n_labels;in_labels+100;i++) b->labels[i] = (char *)mCalloc(T_MAX_LABEL,sizeof(char)); - } + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + return NULL; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -edge *Make_Edge_Light(node *a, node *d, int num) +void *mRealloc(void *p,int nb, size_t size) { - edge *b; - - b = (edge *)mCalloc(1,sizeof(edge)); - + if((p = realloc(p,(size_t)nb*size)) != NULL) + return p; + else + Exit("\n. Err.: low memory\n"); - Init_Edge_Light(b,num); + return NULL; +} - if(a && b) - { - b->left = a; b->rght = d; - if(a->tax) {b->rght = a; b->left = d;} /* root */ - /* a tip is necessary on the right side of the edge */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - (b->left == a)? - (Make_Edge_Dirs(b,a,d)): - (Make_Edge_Dirs(b,d,a)); - b->l = a->l[b->l_r]; - if(a->tax) b->l = a->l[b->r_l]; - if(b->l < BL_MIN) b->l = BL_MIN; - else if(b->l > BL_MAX) b->l = BL_MAX; - b->l_old = b->l; - } - else - { - b->left = NULL; - b->rght = NULL; - } +/* t_tree *Make_Light_Tree_Struct(int n_otu) */ +/* { */ +/* t_tree *tree; */ +/* int i; */ - return b; +/* tree = (t_tree *)mCalloc(1,sizeof(t_tree )); */ +/* tree->a_edges = (t_edge **)mCalloc(2*n_otu-3,sizeof(t_edge *)); */ +/* tree->a_nodes = (t_node **)mCalloc(2*n_otu-2,sizeof(t_node *)); */ +/* tree->n_otu = n_otu; */ -} +/* For(i,2*n_otu-3) */ +/* tree->a_edges[i] = Make_Edge_Light(NULL,NULL,i); */ -/*********************************************************/ +/* For(i,2*n_otu-2) */ +/* tree->a_nodes[i] = Make_Node_Light(i); */ -void Init_Edge_Light(edge *b, int num) -{ - b->num = num; - b->bip_score = 0; - b->dist_btw_edges = .0; - b->topo_dist_btw_edges = 0; - b->has_zero_br_len = 0; - b->is_p_lk_l_u2d = 0; - b->is_p_lk_r_u2d = 0; +/* return tree; */ +/* } */ - b->p_lk_left = NULL; - b->p_lk_rght = NULL; - b->Pij_rr = NULL; -} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ -void Init_Node_Light(node *n, int num) +int Sort_Phydbl_Decrease(const void *a, const void *b) { - n->list_of_reachable_tips = NULL; - n->num = num; - n->tax = -1; - n->dist_to_root = .0; + if((*(phydbl *)(a)) >= (*(phydbl *)(b))) return -1; + else return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void Make_Edge_Dirs(edge *b, node *a, node *d) +void Qksort_Int(int *A, int *B, int ilo, int ihi) { - int i; + phydbl pivot; // pivot value for partitioning array + int ulo, uhi; // indices at ends of unpartitioned region + int ieq; // least index of array entry with value equal to pivot + int tempEntry; // temporary entry used for swapping - if(a == b->rght) - { - printf("\n. a->num = %3d ; d->num = %3d",a->num,d->num); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - if(d == b->left) - { - printf("\n. a->num = %3d ; d->num = %3d",a->num,d->num); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + if (ilo >= ihi) { + return; } + // Select a pivot value. + pivot = A[(ilo + ihi)/2]; + // Initialize ends of unpartitioned region and least index of entry + // with value equal to pivot. + ieq = ulo = ilo; + uhi = ihi; + // While the unpartitioned region is not empty, try to reduce its size. + while (ulo <= uhi) { + if (A[uhi] > pivot) { + // Here, we can reduce the size of the unpartitioned region and + // try again. + uhi--; + } else { + // Here, A[uhi] <= pivot, so swap entries at indices ulo and + // uhi. + tempEntry = A[ulo]; + A[ulo] = A[uhi]; + A[uhi] = tempEntry; + + if(B) + { + tempEntry = B[ulo]; + B[ulo] = B[uhi]; + B[uhi] = tempEntry; + } + + // After the swap, A[ulo] <= pivot. + if (A[ulo] < pivot) + { + // Swap entries at indices ieq and ulo. + tempEntry = A[ieq]; + A[ieq] = A[ulo]; + A[ulo] = tempEntry; + - b->l_r = b->r_l = -1; - For(i,3) - { - if((a->v[i]) && (a->v[i] == d)) - { - b->l_r = i; /* we consider here that 'a' is on the left handside of 'b'*/ - a->b[i] = b; - } - if((d->v[i]) && (d->v[i] == a)) - { - b->r_l = i; /* we consider here that 'd' is on the right handside of 'b'*/ - d->b[i] = b; - } + if(B) + { + tempEntry = B[ieq]; + B[ieq] = B[ulo]; + B[ulo] = tempEntry; + } + + + // After the swap, A[ieq] < pivot, so we need to change + // ieq. + ieq++; + // We also need to change ulo, but we also need to do + // that when A[ulo] = pivot, so we do it after this if + // statement. + } + // Once again, we can reduce the size of the unpartitioned + // region and try again. + ulo++; + } } + // Now, all entries from index ilo to ieq - 1 are less than the pivot + // and all entries from index uhi to ihi + 1 are greater than the + // pivot. So we have two regions of the array that can be sorted + // recursively to put all of the entries in order. + Qksort_Int(A, B, ilo, ieq - 1); + Qksort_Int(A, B, uhi + 1, ihi); +} - if(a->tax) {b->r_l = 0; For(i,3) if(d->v[i]==a) {b->l_r = i; break;}} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - b->l_v1 = b->l_v2 = b->r_v1 = b->r_v2 = -1; - For(i,3) - { - if(b->left->v[i] != b->rght) - { - if(b->l_v1 < 0) b->l_v1 = i; - else b->l_v2 = i; - } +/* Sort in ascending order. Elements in B (if provided) are also re-ordered according to the ordering of A */ +void Qksort(phydbl *A, phydbl *B, int ilo, int ihi) +{ + phydbl pivot; // pivot value for partitioning array + int ulo, uhi; // indices at ends of unpartitioned region + int ieq; // least index of array entry with value equal to pivot + phydbl tempEntry; // temporary entry used for swapping - if(b->rght->v[i] != b->left) - { - if(b->r_v1 < 0) b->r_v1 = i; - else b->r_v2 = i; - } + if (ilo >= ihi) { + return; } -} - -/*********************************************************/ + // Select a pivot value. + pivot = A[(ilo + ihi)/2]; + // Initialize ends of unpartitioned region and least index of entry + // with value equal to pivot. + ieq = ulo = ilo; + uhi = ihi; + // While the unpartitioned region is not empty, try to reduce its size. + while (ulo <= uhi) { + if (A[uhi] > pivot) { + // Here, we can reduce the size of the unpartitioned region and + // try again. + uhi--; + } else { + // Here, A[uhi] <= pivot, so swap entries at indices ulo and + // uhi. + tempEntry = A[ulo]; + A[ulo] = A[uhi]; + A[uhi] = tempEntry; + + if(B) + { + tempEntry = B[ulo]; + B[ulo] = B[uhi]; + B[uhi] = tempEntry; + } -void Make_Edge_Pars(edge *b, arbre *tree) -{ - int site; - b->pars_l = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); - b->pars_r = (int *)mCalloc(tree->data->crunch_len,sizeof(int)); - b->ui_l = (unsigned int *)mCalloc(tree->data->crunch_len,sizeof(unsigned int)); - b->ui_r = (unsigned int *)mCalloc(tree->data->crunch_len,sizeof(unsigned int)); + // After the swap, A[ulo] <= pivot. + if (A[ulo] < pivot) { + // Swap entries at indices ieq and ulo. + tempEntry = A[ieq]; + A[ieq] = A[ulo]; + A[ulo] = tempEntry; - b->p_pars_l = (int **)mCalloc(tree->data->crunch_len,sizeof(int *)); - b->p_pars_r = (int **)mCalloc(tree->data->crunch_len,sizeof(int *)); - For(site,tree->data->crunch_len) - { - b->p_pars_l[site] = (int *)mCalloc(tree->mod->ns,sizeof(int)); - b->p_pars_r[site] = (int *)mCalloc(tree->mod->ns,sizeof(int)); - } -} + if(B) + { + tempEntry = B[ieq]; + B[ieq] = B[ulo]; + B[ulo] = tempEntry; + } -/*********************************************************/ -void Make_Edge_Lk(edge *b, arbre *tree) -{ - int i,j,k; + // After the swap, A[ieq] < pivot, so we need to change + // ieq. + ieq++; + // We also need to change ulo, but we also need to do + // that when A[ulo] = pivot, so we do it after this if + // statement. + } + // Once again, we can reduce the size of the unpartitioned + // region and try again. + ulo++; + } + } + // Now, all entries from index ilo to ieq - 1 are less than the pivot + // and all entries from index uhi to ihi + 1 are greater than the + // pivot. So we have two regions of the array that can be sorted + // recursively to put all of the entries in order. + Qksort(A, B, ilo, ieq - 1); + Qksort(A, B, uhi + 1, ihi); +} - b->l_old = b->l; +/********************************************************/ - b->div_post_pred_left = (short int *)mCalloc((tree->mod->datatype == NT)?(4):(20),sizeof(short int)); - b->div_post_pred_rght = (short int *)mCalloc((tree->mod->datatype == NT)?(4):(20),sizeof(short int)); +void Qksort_Matrix(phydbl **A, int col, int ilo, int ihi) +{ + phydbl pivot; // pivot value for partitioning array + int ulo, uhi; // indices at ends of unpartitioned region + int ieq; // least index of array entry with value equal to pivot + phydbl *tempEntry; // temporary entry used for swapping - b->Pij_rr = (double ***)mCalloc(tree->mod->n_catg,sizeof(double **)); - For(i,tree->mod->n_catg) - { - b->Pij_rr[i] = (double **)mCalloc(tree->mod->ns,sizeof(double *)); - For(j,tree->mod->ns) b->Pij_rr[i][j] = (double *)mCalloc(tree->mod->ns,sizeof(double )); + tempEntry = NULL; + + if (ilo >= ihi) { + return; + } + // Select a pivot value. + pivot = A[(ilo + ihi)/2][col]; + // Initialize ends of unpartitioned region and least index of entry + // with value equal to pivot. + ieq = ulo = ilo; + uhi = ihi; + // While the unpartitioned region is not empty, try to reduce its size. + while (ulo <= uhi) { + if (A[uhi][col] > pivot) { + // Here, we can reduce the size of the unpartitioned region and + // try again. + uhi--; + } else { + // Here, A[uhi] <= pivot, so swap entries at indices ulo and + // uhi. + tempEntry = A[ulo]; + A[ulo] = A[uhi]; + A[uhi] = tempEntry; + // After the swap, A[ulo] <= pivot. + if (A[ulo][col] < pivot) { + // Swap entries at indices ieq and ulo. + tempEntry = A[ieq]; + A[ieq] = A[ulo]; + A[ulo] = tempEntry; + // After the swap, A[ieq] < pivot, so we need to change + // ieq. + ieq++; + // We also need to change ulo, but we also need to do + // that when A[ulo] = pivot, so we do it after this if + // statement. + } + // Once again, we can reduce the size of the unpartitioned + // region and try again. + ulo++; } - - b->scale_left = b->scale_rght = 0; - - if(!b->left->tax) - b->sum_scale_f_left = (phydbl *)mCalloc(tree->data->crunch_len,sizeof(phydbl )); - else - b->sum_scale_f_left = NULL; - - if(!b->rght->tax) - b->sum_scale_f_rght = (phydbl *)mCalloc(tree->data->crunch_len,sizeof(phydbl )); - else - b->sum_scale_f_rght = NULL; - - - if((!b->left->tax) || (tree->mod->s_opt->greedy)) - { - b->p_lk_left = (phydbl ***)mCalloc(tree->data->crunch_len,sizeof(phydbl **)); - For(j,tree->data->crunch_len) - { - b->p_lk_left[j] = (phydbl **)mCalloc(tree->mod->n_catg,sizeof(phydbl *)); - For(k,tree->mod->n_catg) b->p_lk_left[j][k] = (phydbl *)mCalloc(tree->mod->ns,sizeof(phydbl )); - } - b->p_lk_tip_l = NULL; } - else if(b->left->tax) + // Now, all entries from index ilo to ieq - 1 are less than the pivot + // and all entries from index uhi to ihi + 1 are greater than the + // pivot. So we have two regions of the array that can be sorted + // recursively to put all of the entries in order. + Qksort_Matrix(A, col, ilo, ieq - 1); + Qksort_Matrix(A, col, uhi + 1, ihi); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +char *Add_Taxa_To_Constraint_Tree(FILE *fp, calign *cdata) +{ + char *line,*long_line; + t_tree *tree; + int i,j,open; + + rewind(fp); + + line = Return_Tree_String_Phylip(fp); + tree = Read_Tree(&line); + + long_line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + strcpy(long_line,line); + i = 1; + open = 1; + while(open) { - b->p_lk_left = NULL; - - b->p_lk_tip_l = (short int **)mCalloc(tree->data->crunch_len,sizeof(short int *)); - For(j,tree->data->crunch_len) b->p_lk_tip_l[j] = (short int *)mCalloc(tree->mod->ns,sizeof(short int)); + if(line[i]=='(') open++; + if(line[i]==')') open--; + if(i > T_MAX_LINE) assert(FALSE); + i++; } + long_line[i-1] = '\0'; - - if((!b->rght->tax) || (tree->mod->s_opt->greedy)) + for(i=0;in_otu;i++) { - b->p_lk_rght = (phydbl ***)mCalloc(tree->data->crunch_len,sizeof(phydbl **)); + for(j=0;jn_otu;j++) + { + if(!strcmp(tree->a_nodes[j]->name,cdata->c_seq[i]->name)) + break; + } - For(j,tree->data->crunch_len) - { - b->p_lk_rght[j] = (phydbl **)mCalloc(tree->mod->n_catg,sizeof(phydbl *)); - - For(k,tree->mod->n_catg) b->p_lk_rght[j][k] = (phydbl *)mCalloc(tree->mod->ns,sizeof(phydbl )); - } - b->p_lk_tip_r = NULL; - } - else if(b->rght->tax) - { - b->p_lk_rght = NULL; + if(j == tree->n_otu) + { + strcat(long_line,","); + strcat(long_line,cdata->c_seq[i]->name); + } - b->p_lk_tip_r = (short int **)mCalloc(tree->data->crunch_len,sizeof(short int *)); - For(j,tree->data->crunch_len) b->p_lk_tip_r[j] = (short int *)mCalloc(tree->mod->ns,sizeof(short int)); } -} - -/*********************************************************/ + + strcat(long_line,");"); -void Make_Edge_NNI(edge *b) -{ - b->nni = Make_NNI(); - b->nni->b = b; - b->nni->left = b->left; - b->nni->rght = b->rght; -} + Free_Tree(tree); + Free(line); -/*********************************************************/ -nni *Make_NNI() -{ - nni *a_nni; - a_nni = (nni *)mCalloc(1,sizeof(nni )); - Init_NNI(a_nni); - return a_nni; + return long_line; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Init_NNI(nni *a_nni) +void Check_Constraint_Tree_Taxa_Names(t_tree *tree, calign *cdata) { - a_nni->left = NULL; - a_nni->rght = NULL; - a_nni->b = NULL; - a_nni->init_l = -1.; - a_nni->init_lk = .0; - a_nni->score = +1.0; - a_nni->best_l = -1.; - a_nni->swap_node_v1 = NULL; - a_nni->swap_node_v2 = NULL; - a_nni->swap_node_v3 = NULL; - a_nni->swap_node_v4 = NULL; - a_nni->lk0 = UNLIKELY; - a_nni->lk1 = UNLIKELY; - a_nni->lk2 = UNLIKELY; - a_nni->l0 = -1.0; - a_nni->l1 = -1.0; - a_nni->l2 = -1.0; -} + int i,j,n_otu_tree,n_otu_cdata; -/*********************************************************/ + n_otu_tree = tree->n_otu; + n_otu_cdata = cdata->n_otu; -node *Make_Node_Light(int num) -{ - node *n; - n = (node *)mCalloc(1,sizeof(node)); - n->v = (node **)mCalloc(3,sizeof(node *)); - n->l = (phydbl *)mCalloc(3,sizeof(phydbl)); - n->b = (edge **)mCalloc(3,sizeof(edge *)); - n->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); - n->score = (phydbl *)mCalloc(3,sizeof(phydbl)); - Init_Node_Light(n,num); - return n; + for(i=0;ia_nodes[i]->name,cdata->c_seq[j]->name)) + break; + } + + if(j==n_otu_cdata) + { + PhyML_Fprintf(stderr,"\n. '%s' was not found in sequence data set\n",tree->a_nodes[i]->name); + Warn_And_Exit("\n. PhyML finished prematurely."); + } + } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - -void Make_Node_Lk(node *n) +void Copy_Tax_Names_To_Tip_Labels(t_tree *tree, calign *data) { -/* n->n_ex_nodes = (int *)mCalloc(2,sizeof(int)); */ - return; + int i; + + for(i=0;in_otu;i++) + { + tree->a_nodes[i]->name = (char *)mCalloc((int)strlen(data->c_seq[i]->name)+1,sizeof(char)); + tree->a_nodes[i]->ori_name = tree->a_nodes[i]->name; + strcpy(tree->a_nodes[i]->name,data->c_seq[i]->name); + tree->a_nodes[i]->tax = 1; + tree->a_nodes[i]->num = i; + } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -seq **Get_Seq(option *io, int rw) +void Share_Lk_Struct(t_tree *t_full, t_tree *t_empt) { - seq **data; - int i,j; - char **buff; - int n_unkn,n_removed,pos; - int *remove; - - -/* rewind(fp_seq); */ - - if(io->interleaved) data = Read_Seq_Interleaved(io->fp_in_seq,&(io->mod->n_otu)); - else data = Read_Seq_Sequential(io->fp_in_seq,&(io->mod->n_otu)); + int i,j,n_otu; + t_edge *b_e,*b_f; + t_node *n_e, *n_f; + + n_otu = t_full->n_otu; + t_empt->c_lnL_sorted = t_full->c_lnL_sorted; + t_empt->unscaled_site_lk_cat = t_full->unscaled_site_lk_cat; + t_empt->cur_site_lk = t_full->cur_site_lk; + t_empt->old_site_lk = t_full->old_site_lk; + t_empt->log_lks_aLRT = t_full->log_lks_aLRT; + t_empt->site_lk_cat = t_full->site_lk_cat; + t_empt->fact_sum_scale = t_full->fact_sum_scale; + t_empt->eigen_lr_left = t_full->eigen_lr_left; + t_empt->eigen_lr_rght = t_full->eigen_lr_rght; + t_empt->dot_prod = t_full->dot_prod; + t_empt->expl = t_full->expl; - if(data) + For(i,2*n_otu-3) { - buff = (char **)mCalloc(io->mod->n_otu,sizeof(char *)); - For(i,io->mod->n_otu) buff[i] = (char *)mCalloc(data[0]->len,sizeof(char)); - remove = (int *)mCalloc(data[0]->len,sizeof(int)); + b_f = t_full->a_edges[i]; + b_e = t_empt->a_edges[i]; - n_removed = 0; - - For(i,data[0]->len) - { - For(j,io->mod->n_otu) - { - if((data[j]->state[i] == '?') || (data[j]->state[i] == '-')) data[j]->state[i] = 'X'; - if((io->mod->datatype == NT) && (data[j]->state[i] == 'N')) data[j]->state[i] = 'X'; - if(data[j]->state[i] == 'U') data[j]->state[i] = 'T'; - } + b_e->Pij_rr = b_f->Pij_rr; + b_e->tPij_rr = b_f->tPij_rr; - n_unkn = 0; - For(j,io->mod->n_otu) if(data[j]->state[i] == 'X') n_unkn++; + b_e->nni = b_f->nni; + } - if(n_unkn == io->mod->n_otu) - { - remove[i] = 1; - n_removed++; - } - For(j,io->mod->n_otu) buff[j][i] = data[j]->state[i]; - } + for(i=n_otu;i<2*n_otu-2;i++) + { + n_f = t_full->a_nodes[i]; + n_e = t_empt->a_nodes[i]; - if(n_removed > 0) - { - if(io->mod->datatype == NT) - printf("\n. %d sites are made from completely undetermined states ('X', '-', '?' or 'N')...\n",n_removed); - else - printf("\n. %d sites are made from completely undetermined states ('X', '-', '?')...\n",n_removed); - } + for(j=0;j<3;j++) + { + if(n_f->b[j]->left == n_f) + { + if(n_e->b[j]->left == n_e) + { + n_e->b[j]->p_lk_left = n_f->b[j]->p_lk_left; + n_e->b[j]->p_lk_loc_left = n_f->b[j]->p_lk_loc_left; + n_e->b[j]->patt_id_left = n_f->b[j]->patt_id_left; + n_e->b[j]->sum_scale_left = n_f->b[j]->sum_scale_left; + n_e->b[j]->sum_scale_left_cat = n_f->b[j]->sum_scale_left_cat; + n_e->b[j]->p_lk_tip_l = n_f->b[j]->p_lk_tip_l; + } + else + { + n_e->b[j]->p_lk_rght = n_f->b[j]->p_lk_left; + n_e->b[j]->p_lk_loc_rght = n_f->b[j]->p_lk_loc_left; + n_e->b[j]->patt_id_rght = n_f->b[j]->patt_id_left; + n_e->b[j]->sum_scale_rght = n_f->b[j]->sum_scale_left; + n_e->b[j]->sum_scale_rght_cat = n_f->b[j]->sum_scale_left_cat; + n_e->b[j]->p_lk_tip_r = n_f->b[j]->p_lk_tip_l; + } + } + else + { + if(n_e->b[j]->rght == n_e) + { + n_e->b[j]->p_lk_rght = n_f->b[j]->p_lk_rght; + n_e->b[j]->p_lk_loc_rght = n_f->b[j]->p_lk_loc_rght; + n_e->b[j]->patt_id_rght = n_f->b[j]->patt_id_rght; + n_e->b[j]->sum_scale_rght = n_f->b[j]->sum_scale_rght; + n_e->b[j]->sum_scale_rght_cat = n_f->b[j]->sum_scale_rght_cat; + n_e->b[j]->p_lk_tip_r = n_f->b[j]->p_lk_tip_r; + } + else + { + n_e->b[j]->p_lk_left = n_f->b[j]->p_lk_rght; + n_e->b[j]->p_lk_loc_left = n_f->b[j]->p_lk_loc_rght; + n_e->b[j]->patt_id_left = n_f->b[j]->patt_id_rght; + n_e->b[j]->sum_scale_left = n_f->b[j]->sum_scale_rght; + n_e->b[j]->sum_scale_left_cat = n_f->b[j]->sum_scale_rght_cat; + n_e->b[j]->p_lk_tip_l = n_f->b[j]->p_lk_tip_r; + } + } + } + } - pos = 0; - For(i,data[0]->len) - { -/* if(!remove[i]) */ -/* { */ - For(j,io->mod->n_otu) data[j]->state[pos] = buff[j][i]; - pos++; -/* } */ - } + for(i=0;ia_nodes[i]; + n_e = t_empt->a_nodes[i]; - For(i,io->mod->n_otu) data[i]->len = pos; - For(i,io->mod->n_otu) Free(buff[i]); - Free(buff); - Free(remove); + if(n_f->b[0]->rght == n_f) + { + n_e->b[0]->p_lk_rght = n_f->b[0]->p_lk_rght; + n_e->b[0]->p_lk_loc_rght = n_f->b[0]->p_lk_loc_rght; + n_e->b[0]->patt_id_rght = n_f->b[0]->patt_id_rght; + n_e->b[0]->sum_scale_rght = n_f->b[0]->sum_scale_rght; + n_e->b[0]->sum_scale_rght_cat = n_f->b[0]->sum_scale_rght_cat; + n_e->b[0]->p_lk_tip_r = n_f->b[0]->p_lk_tip_r; + } + else + { + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } } - return data; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -seq **Read_Seq_Sequential(FILE *in, int *n_otu) +void Share_Spr_Struct(t_tree *t_full, t_tree *t_empt) { - int i; - char *line; - int len,readok; - seq **data; - char c; - char *format = (char *)mCalloc(T_MAX_NAME, sizeof(char)); - - line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + t_empt->size_spr_list_one_edge = t_full->size_spr_list_one_edge; + t_empt->spr_list_one_edge = t_full->spr_list_one_edge; + t_empt->best_spr = t_full->best_spr; + t_empt->spr_list_all_edge = t_full->spr_list_all_edge; + t_empt->size_spr_list_all_edge = t_full->size_spr_list_all_edge; +} - readok = len = 0; - do - { - if(fscanf(in,"%s",line) == EOF) - { - Free(line); return NULL; - } - else - { - if(strcmp(line,"\n") && strcmp(line,"\n") && strcmp(line,"\t")) - { - *n_otu = atoi(line); - data = (seq **)mCalloc(*n_otu,sizeof(seq *)); - if(*n_otu <= 0) Warn_And_Exit("\n. Problem with sequence format\n"); - fscanf(in,"%s",line); - len = atoi(line); - if(len <= 0) Warn_And_Exit("\n. Problem with sequence format\n"); - else readok = 1; - } - } - }while(!readok); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +void Share_Pars_Struct(t_tree *t_full, t_tree *t_empt) +{ + int i; -/* while((c=fgetc(in))!='\n'); */ - while(((c=fgetc(in))!='\n') && (c != ' ') && (c != '\r') && (c != '\t')); + t_empt->site_pars = t_full->site_pars; + t_empt->step_mat = t_full->step_mat; - For(i,*n_otu) + For(i,2*t_full->n_otu-3) { - data[i] = (seq *)mCalloc(1,sizeof(seq)); - data[i]->len = 0; - data[i]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); - data[i]->state = (char *)mCalloc(T_MAX_SEQ,sizeof(char)); - data[i]->is_ambigu = NULL; - sprintf(format, "%%%ds", T_MAX_NAME); - fscanf(in, format, data[i]->name); + t_empt->a_edges[i]->ui_l = t_full->a_edges[i]->ui_l; + t_empt->a_edges[i]->ui_r = t_full->a_edges[i]->ui_r; - while(data[i]->len < len) - Read_One_Line_Seq(&data,i,in); + t_empt->a_edges[i]->pars_l = t_full->a_edges[i]->pars_l; + t_empt->a_edges[i]->pars_r = t_full->a_edges[i]->pars_r; - if(data[i]->len != len) - { - printf("\n. Err: Problem with species %s's sequence (check the format)\n", - data[i]->name); - Warn_And_Exit(""); - } + t_empt->a_edges[i]->p_pars_l = t_full->a_edges[i]->p_pars_l; + t_empt->a_edges[i]->p_pars_r = t_full->a_edges[i]->p_pars_r; } - - /* fgets(line,T_MAX_LINE,in); */ - /* inter data sets */ - - Free(format); - Free(line); - return data; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -seq **Read_Seq_Interleaved(FILE *in, int *n_otu) +int Sort_Edges_NNI_Score(t_tree *tree, t_edge **sorted_edges, int n_elem) { - int i,end,num_block; - char *line; - int len,readok; - seq **data; - char c; - char *format; - - line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); - format = (char *)mCalloc(T_MAX_NAME, sizeof(char)); + int i,j,done; + t_edge *buff; - readok = len = 0; do { - if(fscanf(in,"%s",line) == EOF) - { - Free(format); - Free(line); return NULL; - } - else - { - if(strcmp(line,"\n") && strcmp(line,"\r") && strcmp(line,"\t")) - { - *n_otu = atoi(line); - data = (seq **)mCalloc(*n_otu,sizeof(seq *)); - if(*n_otu <= 0) Warn_And_Exit("\n. Problem with sequence format\n"); - fscanf(in,"%s",line); - len = atoi(line); - if(len <= 0) Warn_And_Exit("\n. Problem with sequence format\n"); - else readok = 1; - } - } - }while(!readok); + done = YES; + for(i=0;inni->score < sorted_edges[i]->nni->score) + { + done = NO; + buff = sorted_edges[j]; + sorted_edges[j] = sorted_edges[i]; + sorted_edges[i] = buff; + } + } + } + } + while(done == NO); + return 1; +} - while(((c=fgetc(in))!='\n') && (c != ' ') && (c != '\r') && (c != '\t')); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - end = 0; - For(i,*n_otu) - { - data[i] = (seq *)mCalloc(1,sizeof(seq)); - data[i]->len = 0; - data[i]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); - data[i]->state = (char *)mCalloc(T_MAX_SEQ,sizeof(char)); - data[i]->is_ambigu = NULL; - sprintf(format, "%%%ds", T_MAX_NAME); - fscanf(in, format, data[i]->name); - if(!Read_One_Line_Seq(&data,i,in)) - { - end = 1; - if((i != *n_otu) && (i != *n_otu-1)) - { - printf("\n. Err: Problem with species %s's sequence\n",data[i]->name); - Warn_And_Exit(""); - } - break; - } - } +int Sort_Edges_Depth(t_tree *tree, t_edge **sorted_edges, int n_elem) +{ + int i,j; + t_edge *buff; + phydbl *depth,buff_depth; - if(data[0]->len == len) end = 1; + depth = (phydbl *)mCalloc(n_elem,sizeof(phydbl)); - if(!end) - { - end = 0; + for(i=0;ileft->bip_size[sorted_edges[i]->l_r] * + sorted_edges[i]->rght->bip_size[sorted_edges[i]->r_l] ; - num_block = 1; - do - { - num_block++; - /* interblock */ - if(!fgets(line,T_MAX_LINE,in)) break; + for(i=0;i depth[j]) + { + buff = sorted_edges[i]; + sorted_edges[i] = sorted_edges[j]; + sorted_edges[j] = buff; - if(line[0] != 13 && line[0] != 10) - { - printf("\n. One or more missing sequences in block %d\n",num_block-1); - Warn_And_Exit(""); - } - - For(i,*n_otu) - if(data[i]->len != len) - break; - - if(i == *n_otu) break; - - - For(i,*n_otu) - { - if(data[i]->len > len) - { - printf("\n. Observed length=%d expected length=%d\n",data[i]->len,len); - printf("\n. Err: Problem with species %s's sequence\n",data[i]->name); - Warn_And_Exit(""); - } - else if(!Read_One_Line_Seq(&data,i,in)) - { - end = 1; - if((i != *n_otu) && (i != *n_otu-1)) - { - printf("\n. Err: Problem with species %s's sequence\n",data[i]->name); - Warn_And_Exit(""); - } - break; - } - } - }while(!end); - } - - For(i,*n_otu) - { - if(data[i]->len != len) - { - printf("\n. Check sequence '%s' length...\n",data[i]->name); - Warn_And_Exit(""); - } + buff_depth = depth[i]; + depth[i] = depth[j]; + depth[j] = buff_depth; + } + } } - Free(format); - Free(line); - return data; + Free(depth); + + return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Read_One_Line_Seq(seq ***data, int num_otu, FILE *in) +void NNI(t_tree *tree, t_edge *b_fcus, int do_swap) { - char c; + t_node *v1,*v2,*v3,*v4; + phydbl lk0, lk1, lk2; + phydbl lk0_init, lk1_init, lk2_init; + scalar_dbl *len0,*len1,*len2; + scalar_dbl *var0,*var1,*var2; + phydbl l_infa, l_infb; + phydbl lk_init; + + if(tree->prev) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); - c=' '; - while(1) - { -/* if((c == EOF) || (c == '\n') || (c == '\r')) break; */ - if((c == EOF) || (c == 13) || (c == 10)) break; - else if((c==' ') || (c=='\t')) {c=(char)fgetc(in); continue;} - Uppercase(&c); + lk_init = tree->c_lnL; + b_fcus->nni->init_lk = tree->c_lnL;; + b_fcus->nni->best_conf = 0; + b_fcus->nni->score = +1.0; + lk0 = lk1 = lk2 = UNLIKELY; + v1 = v2 = v3 = v4 = NULL; - if (strchr("ABCDEFGHIKLMNOPQRSTUVWXYZ?-.", c) == NULL) - { - printf("\n. Err: bad symbol: \"%c\" at position %d of species %s\n", - c,(*data)[num_otu]->len,(*data)[num_otu]->name); - Warn_And_Exit(""); - } + if(b_fcus->nni->init_l != NULL) Copy_Scalar_Dbl(b_fcus->l,b_fcus->nni->init_l); + else b_fcus->nni->init_l = Duplicate_Scalar_Dbl(b_fcus->l); - if(c == '.') - { - c = (*data)[0]->state[(*data)[num_otu]->len]; - if(!num_otu) - Warn_And_Exit("\n. Err: Symbol \".\" should not appear in the first sequence\n"); - } - (*data)[num_otu]->state[(*data)[num_otu]->len]=c; - (*data)[num_otu]->len++; - c = (char)fgetc(in); - } - if(c == EOF) return 0; - else return 1; -} + v1 = b_fcus->left->v[b_fcus->l_v1]; + v2 = b_fcus->left->v[b_fcus->l_v2]; + v3 = b_fcus->rght->v[b_fcus->r_v1]; + v4 = b_fcus->rght->v[b_fcus->r_v2]; -/*********************************************************/ + Record_Br_Len(tree); -void Uppercase(char *ch) -{ - /* convert ch to upper case -- either ASCII or EBCDIC */ - *ch = isupper((int)*ch) ? *ch : toupper((int)*ch); -} + if(v1->num < v2->num) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(v3->num < v4->num) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); -/*********************************************************/ + /************************************************************/ + Swap(v2,b_fcus->left,b_fcus->rght,v3,tree); + Set_Both_Sides(YES,tree); -allseq *Compact_Seq(seq **data, option *io) -{ - allseq *alldata_tmp,*alldata; - int i,j,k,site; - int n_patt,which_patt,n_invar; - char **sp_names; - int n_otu, n_sites; - pnode *proot; - int compress; - int n_ambigu,is_ambigu; + MIXT_Set_Alias_Subpatt(YES,tree); + lk1_init = Update_Lk_At_Given_Edge(b_fcus,tree); + MIXT_Set_Alias_Subpatt(NO,tree); - n_otu = io->mod->n_otu; - n_patt = 0; - which_patt = 0; + l_infa = 1.; + l_infb = 1.E-4; + lk1 = lk1_init; - sp_names = (char **)mCalloc(n_otu,sizeof(char *)); - For(i,n_otu) + if(tree->mod->s_opt->nni_br_len_opt == YES) { - sp_names[i] = (char *)mCalloc(T_MAX_NAME,sizeof(char)); - strcpy(sp_names[i],data[i]->name); + if(tree->mod->s_opt->fast_nni) + { + lk1 = Fast_Br_Len(b_fcus,tree,YES); + } + else + { + lk1 = Br_Len_Opt(&(b_fcus->l->v),b_fcus,tree); + } } - alldata_tmp = Make_Cseq(n_otu,data[0]->len,data[0]->len,sp_names); - proot = (pnode *)Create_Pnode(T_MAX_ALPHABET); - - For(i,n_otu) Free(sp_names[i]); - Free(sp_names); - - - if(data[0]->len%io->mod->stepsize) + if(lk1 < lk1_init - tree->mod->s_opt->min_diff_lk_local) { - printf("\n. Sequence length is not a multiple of %d\n",io->mod->stepsize); - Warn_And_Exit(""); + PhyML_Printf("\n. %f %f %G",l_infa,l_infb,b_fcus->l->v); + PhyML_Printf("\n. %f -- %f",lk1_init,lk1); + PhyML_Printf("\n. Err. in NNI (1)"); } - - compress = 1; -/* compress = 0; */ - n_ambigu = 0; - is_ambigu = 0; - Fors(site,data[0]->len,io->mod->stepsize) - { - if(io->rm_ambigu) - { - is_ambigu = 0; - For(j,n_otu) - { - if(Is_Ambigu(data[j]->state+site,io->mod->datatype,io->mod->stepsize)) - { - break; - } - } - if(j != n_otu) - { - is_ambigu = 1; - n_ambigu++; - } - } + len1 = Duplicate_Scalar_Dbl(b_fcus->l); + var1 = Duplicate_Scalar_Dbl(b_fcus->l_var); + Swap(v3,b_fcus->left,b_fcus->rght,v2,tree); + /************************************************************/ - if(!is_ambigu) - { - if(compress) - { - which_patt = -1; - Traverse_Prefix_Tree(site,-1,&which_patt,&n_patt,data,io,proot); - if(which_patt == n_patt-1) /* New pattern found */ - { - n_patt--; - k=n_patt; - } - else - { - k = n_patt-10; - } - } - else - { - printf("\n. WARNING: sequences are not compressed !"); - k = n_patt; - } - - if(k == n_patt) /* add a new site pattern */ - { - For(j,n_otu) - Copy_One_State(data[j]->state+site, - alldata_tmp->c_seq[j]->state+n_patt, - io->mod->stepsize); - - - For(i,n_otu) - { - For(j,n_otu) - { - if(!(Are_Compatible(alldata_tmp->c_seq[i]->state+n_patt, - alldata_tmp->c_seq[j]->state+n_patt, - io->mod->stepsize, - io->mod->datatype))) break; - } - if(j != n_otu) break; - } - - if((j == n_otu) && (i == n_otu)) /* all characters at that site are compatible -> the site is invariant */ - { - For(j,n_otu) - { - alldata_tmp->invar[n_patt] = Assign_State(alldata_tmp->c_seq[j]->state+n_patt, - io->mod->datatype, - io->mod->stepsize); - if(alldata_tmp->invar[n_patt] > -1.) break; - } - } - else alldata_tmp->invar[n_patt] = -1; - - alldata_tmp->sitepatt[site] = n_patt; - alldata_tmp->wght[n_patt] += 1; - n_patt += io->mod->stepsize; - } - else - { - alldata_tmp->sitepatt[site] = which_patt; - alldata_tmp->wght[which_patt] += 1; - } - } - } - - data[0]->len -= n_ambigu; - - alldata_tmp->init_len = data[0]->len; - alldata_tmp->crunch_len = n_patt; - For(i,n_otu) alldata_tmp->c_seq[i]->len = n_patt; - - /* wash. */ - /* printf("\n. %d patterns found. (out of a total of %d sites) \n",n_patt,data[0]->len);*/ - - if((io->rm_ambigu) && (n_ambigu)) - { - printf("\n. Removed %d columns of the alignment as the contain ambiguous characters (e.g., gaps) \n",n_ambigu); - } - n_invar=0; - For(i,alldata_tmp->crunch_len) if(alldata_tmp->invar[i] > -1.) n_invar+=(int)alldata_tmp->wght[i]; + /************************************************************/ + Swap(v2,b_fcus->left,b_fcus->rght,v4,tree); + Restore_Br_Len(tree); + Set_Both_Sides(YES,tree); - /* wash. */ - /* printf("\n. %d sites without polymorphism (%.2f%c).\n",n_invar,100.*(phydbl)n_invar/data[0]->len,'%');*/ + MIXT_Set_Alias_Subpatt(YES,tree); + lk2_init = Update_Lk_At_Given_Edge(b_fcus,tree); + MIXT_Set_Alias_Subpatt(NO,tree); - alldata_tmp->obs_pinvar = (phydbl)n_invar/data[0]->len; + l_infa = 1.; + l_infb = 1.E-4; + + lk2 = lk2_init; - n_sites = 0; - For(i,alldata_tmp->crunch_len) n_sites += alldata_tmp->wght[i]; - if(n_sites != data[0]->len) + if(tree->mod->s_opt->nni_br_len_opt == YES) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + if(tree->mod->s_opt->fast_nni) + { + lk2 = Fast_Br_Len(b_fcus,tree,YES); + } + else + { + lk2 = Br_Len_Opt(&(b_fcus->l->v),b_fcus,tree); + } } - if(io->mod->datatype == NT) Get_Base_Freqs(alldata_tmp); - else Get_AA_Freqs(alldata_tmp); - - alldata = Copy_Cseq(alldata_tmp, alldata_tmp->crunch_len, io->mod->ns); + if(lk2 < lk2_init - tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Printf("\n. %f %f %G",l_infa,l_infb,b_fcus->l->v); + PhyML_Printf("\n. %f -- %f",lk2_init,lk2); + PhyML_Printf("\n. Err. in NNI (2)"); + } - Free_Cseq(alldata_tmp); - Free_Prefix_Tree(proot,T_MAX_ALPHABET); + len2 = Duplicate_Scalar_Dbl(b_fcus->l); + var2 = Duplicate_Scalar_Dbl(b_fcus->l_var); + Swap(v4,b_fcus->left,b_fcus->rght,v2,tree); + /************************************************************/ - return alldata; -} -/*********************************************************/ -allseq *Compact_CSeq(allseq *data, model *mod) -{ - allseq *alldata; - int i,j,k,site; - int n_patt,which_patt; - int n_otu; + /************************************************************/ + Restore_Br_Len(tree); + Set_Both_Sides(YES,tree); - n_otu = data->n_otu; + MIXT_Set_Alias_Subpatt(YES,tree); + lk0_init = Update_Lk_At_Given_Edge(b_fcus,tree); + MIXT_Set_Alias_Subpatt(NO,tree); - alldata = (allseq *)mCalloc(1,sizeof(allseq)); - alldata->n_otu = n_otu; - alldata->c_seq = (seq **)mCalloc(n_otu,sizeof(seq *)); - alldata->wght = (int *)mCalloc(data->crunch_len,sizeof(int)); - alldata->b_frq = (phydbl *)mCalloc(mod->ns,sizeof(phydbl)); - alldata->ambigu = (short int *)mCalloc(data->crunch_len,sizeof(short int)); - alldata->invar = (short int *)mCalloc(data->crunch_len,sizeof(short int)); - alldata->crunch_len = alldata->init_len = -1; - For(j,n_otu) + if(FABS(lk0_init - lk_init) > tree->mod->s_opt->min_diff_lk_local) { - alldata->c_seq[j] = (seq *)mCalloc(1,sizeof(seq)); - alldata->c_seq[j]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); - strcpy(alldata->c_seq[j]->name,data->c_seq[j]->name); - alldata->c_seq[j]->state = (char *)mCalloc(data->crunch_len,sizeof(char)); - alldata->c_seq[j]->is_ambigu = (short int *)mCalloc(data->crunch_len,sizeof(short int)); - alldata->c_seq[j]->state[0] = data->c_seq[j]->state[0]; + PhyML_Fprintf(stderr,"\n. lk_init = %f; lk = %f diff = %f l = %G", + lk_init, + lk0_init, + lk_init-lk0_init, + b_fcus->l->v); + PhyML_Fprintf(stderr,"\n. Curr_lnL = %f",Lk(NULL,tree)); + Exit("\n. Err. in NNI (3)"); } - n_patt = which_patt = 0; + l_infa = 1.; + l_infb = 1.E-4; + lk0 = lk0_init; - Fors(site,data->crunch_len,mod->stepsize) + if(tree->mod->s_opt->nni_br_len_opt == YES) { - if(data->wght[site]) - { - Fors(k,n_patt,mod->stepsize) - { - For(j,n_otu) - { - if(strncmp(alldata->c_seq[j]->state+k, - data->c_seq[j]->state+site, - mod->stepsize)) - break; - } - - if(j == n_otu) - { - which_patt = k; - break; - } - } - - /* /\* TO DO *\/ */ - /* k = n_patt; */ - - if(k == n_patt) - { - For(j,n_otu) Copy_One_State(data->c_seq[j]->state+site, - alldata->c_seq[j]->state+n_patt, - mod->stepsize); - - For(i,n_otu) - { - For(j,n_otu) - { - if(!(Are_Compatible(alldata->c_seq[i]->state+n_patt, - alldata->c_seq[j]->state+n_patt, - mod->stepsize, - mod->datatype))) break; - } - if(j != n_otu) break; - } - - if((j == n_otu) && (i == n_otu)) - { - For(j,n_otu) - { - alldata->invar[n_patt] = Assign_State(alldata->c_seq[j]->state+n_patt, - mod->datatype, - mod->stepsize); - if(alldata->invar[n_patt] > -1.) break; - } - } - else alldata->invar[n_patt] = -1; - - alldata->wght[n_patt] += data->wght[site]; - n_patt+=mod->stepsize; - } - else alldata->wght[which_patt] += data->wght[site]; - - /* Print_Site(alldata,k,n_otu,"\n",mod->stepsize); */ - } + if(tree->mod->s_opt->fast_nni) + { + lk0 = Fast_Br_Len(b_fcus,tree,YES); + } + else + { + lk0 = Br_Len_Opt(&(b_fcus->l->v),b_fcus,tree); + } } + + if(lk0 < lk_init - tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Printf("\n. %f %f %f",l_infa,l_infb,b_fcus->l->v); + PhyML_Printf("\n. %f -- %f",lk0_init,lk0); + PhyML_Printf("\n. Err. in NNI (3)\n"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + len0 = Duplicate_Scalar_Dbl(b_fcus->l); + var0 = Duplicate_Scalar_Dbl(b_fcus->l_var); + /************************************************************/ + + b_fcus->nni->lk0 = lk0; + b_fcus->nni->lk1 = lk1; + b_fcus->nni->lk2 = lk2; - alldata->init_len = data->crunch_len; - alldata->crunch_len = n_patt; - For(i,n_otu) alldata->c_seq[i]->len = n_patt; + if(b_fcus->nni->l0 == NULL) b_fcus->nni->l0 = Duplicate_Scalar_Dbl(len0); + else Copy_Scalar_Dbl(len0,b_fcus->nni->l0); - (mod->datatype == NT)? - (Get_Base_Freqs(alldata)): - (Get_AA_Freqs(alldata)); + if(b_fcus->nni->l1 == NULL) b_fcus->nni->l1 = Duplicate_Scalar_Dbl(len1); + else Copy_Scalar_Dbl(len1,b_fcus->nni->l1); - return alldata; -} + if(b_fcus->nni->l2 == NULL) b_fcus->nni->l2 = Duplicate_Scalar_Dbl(len2); + else Copy_Scalar_Dbl(len2,b_fcus->nni->l2); -/*********************************************************/ + if(b_fcus->nni->v0 == NULL) b_fcus->nni->v0 = Duplicate_Scalar_Dbl(var0); + else Copy_Scalar_Dbl(var0,b_fcus->nni->v0); -void Traverse_Prefix_Tree(int site, int seqnum, int *patt_num, int *n_patt, seq **data, option *io, pnode *n) -{ - int ret_val; + if(b_fcus->nni->v1 == NULL) b_fcus->nni->v1 = Duplicate_Scalar_Dbl(var1); + else Copy_Scalar_Dbl(var1,b_fcus->nni->v1); + + if(b_fcus->nni->v2 == NULL) b_fcus->nni->v2 = Duplicate_Scalar_Dbl(var2); + else Copy_Scalar_Dbl(var2,b_fcus->nni->v2); - ret_val = -1; + b_fcus->nni->score = lk0 - MAX(lk1,lk2); - if(seqnum == io->mod->n_otu-1) + if((b_fcus->nni->score < tree->mod->s_opt->min_diff_lk_local) && + (b_fcus->nni->score > -tree->mod->s_opt->min_diff_lk_local)) { - n->weight++; - if(n->weight == 1) - { - n->num = *n_patt; - (*n_patt) += 1; - } - (*patt_num) = n->num; - return; + b_fcus->nni->score = .0; + b_fcus->nni->lk1 = b_fcus->nni->lk0; + b_fcus->nni->lk2 = b_fcus->nni->lk0; } - else + + if(lk0 > MAX(lk1,lk2)) { - int next_state; + b_fcus->nni->best_conf = 0; + b_fcus->nni->swap_node_v1 = NULL; + b_fcus->nni->swap_node_v2 = NULL; + b_fcus->nni->swap_node_v3 = NULL; + b_fcus->nni->swap_node_v4 = NULL; + + if(b_fcus->nni->best_l == NULL) b_fcus->nni->best_l = Duplicate_Scalar_Dbl(len0); + else Copy_Scalar_Dbl(len0,b_fcus->nni->best_l); - next_state = -1; - next_state = Assign_State_With_Ambiguity(data[seqnum+1]->state+site, - io->mod->datatype, - io->mod->stepsize); + if(b_fcus->nni->best_v == NULL) b_fcus->nni->best_v = Duplicate_Scalar_Dbl(var0); + else Copy_Scalar_Dbl(var0,b_fcus->nni->best_v); + } + else if(lk1 > MAX(lk0,lk2)) + { + b_fcus->nni->best_conf = 1; + b_fcus->nni->swap_node_v1 = v2; + b_fcus->nni->swap_node_v2 = b_fcus->left; + b_fcus->nni->swap_node_v3 = b_fcus->rght; + b_fcus->nni->swap_node_v4 = v3; + + if(b_fcus->nni->best_l == NULL) b_fcus->nni->best_l = Duplicate_Scalar_Dbl(len1); + else Copy_Scalar_Dbl(len1,b_fcus->nni->best_l); - if(!n->next[next_state]) - { - n->next[next_state] = Create_Pnode(T_MAX_ALPHABET); - } - Traverse_Prefix_Tree(site,seqnum+1,patt_num,n_patt,data,io,n->next[next_state]); + if(b_fcus->nni->best_v == NULL) b_fcus->nni->best_v = Duplicate_Scalar_Dbl(var1); + else Copy_Scalar_Dbl(var1,b_fcus->nni->best_v); } -} + else if(lk2 > MAX(lk0,lk1)) + { + b_fcus->nni->best_conf = 2; + b_fcus->nni->swap_node_v1 = v2; + b_fcus->nni->swap_node_v2 = b_fcus->left; + b_fcus->nni->swap_node_v3 = b_fcus->rght; + b_fcus->nni->swap_node_v4 = v4; -/*********************************************************/ + if(b_fcus->nni->best_l == NULL) b_fcus->nni->best_l = Duplicate_Scalar_Dbl(len2); + else Copy_Scalar_Dbl(len2,b_fcus->nni->best_l); -pnode *Create_Pnode(int size) -{ - pnode *n; - int i; + if(b_fcus->nni->best_v == NULL) b_fcus->nni->best_v = Duplicate_Scalar_Dbl(var2); + else Copy_Scalar_Dbl(var2,b_fcus->nni->best_v); + } + else + { + b_fcus->nni->score = +1.0; + b_fcus->nni->best_conf = 0; + b_fcus->nni->swap_node_v1 = NULL; + b_fcus->nni->swap_node_v2 = NULL; + b_fcus->nni->swap_node_v3 = NULL; + b_fcus->nni->swap_node_v4 = NULL; - n = (pnode *)mCalloc(1,sizeof(pnode )); - n->next = (pnode **)mCalloc(size,sizeof(pnode *)); - For(i,size) n->next[i] = NULL; - n->weight = 0; - n->num = -1; - return n; -} -/*********************************************************/ -/*********************************************************/ + if(b_fcus->nni->best_l == NULL) b_fcus->nni->best_l = Duplicate_Scalar_Dbl(len0); + else Copy_Scalar_Dbl(len0,b_fcus->nni->best_l); -void Get_Base_Freqs(allseq *data) -{ - int i,j,k; - phydbl A,C,G,T; - phydbl fA,fC,fG,fT; - int w; + if(b_fcus->nni->best_v == NULL) b_fcus->nni->best_v = Duplicate_Scalar_Dbl(var0); + else Copy_Scalar_Dbl(var0,b_fcus->nni->best_v); + } - fA = fC = fG = fT = .25; - For(k,8) + if(do_swap == YES) { - A = C = G = T = .0; - For(i,data->n_otu) - { - For(j,data->crunch_len) - { - w = data->wght[j]; - if(w) - { - switch(data->c_seq[i]->state[j]) - { - case 'A' : A+=w; - break; - case 'C' : C+=w; - break; - case 'G' : G+=w; - break; - case 'T' : T+=w; - break; - case 'U' : T+=w; - break; - case 'M' : C+=w*fC/(fC+fA); A+=w*fA/(fA+fC); - break; - case 'R' : G+=w*fG/(fA+fG); A+=w*fA/(fA+fG); - break; - case 'W' : T+=w*fT/(fA+fT); A+=w*fA/(fA+fT); - break; - case 'S' : C+=w*fC/(fC+fG); G+=w*fG/(fC+fG); - break; - case 'Y' : C+=w*fC/(fC+fT); T+=w*fT/(fT+fC); - break; - case 'K' : G+=w*fG/(fG+fT); T+=w*fT/(fT+fG); - break; - case 'B' : C+=w*fC/(fC+fG+fT); G+=w*fG/(fC+fG+fT); T+=w*fT/(fC+fG+fT); - break; - case 'D' : A+=w*fA/(fA+fG+fT); G+=w*fG/(fA+fG+fT); T+=w*fT/(fA+fG+fT); - break; - case 'H' : A+=w*fA/(fA+fC+fT); C+=w*fC/(fA+fC+fT); T+=w*fT/(fA+fC+fT); - break; - case 'V' : A+=w*fA/(fA+fC+fG); C+=w*fC/(fA+fC+fG); G+=w*fG/(fA+fC+fG); - break; - case 'N' : case 'X' : case '?' : case 'O' : case '-' : - A+=w*fA; C+=w*fC; G+=w*fG; T+=w*fT; break; - default : break; - } - } - } - } - fA = A/(A+C+G+T); - fC = C/(A+C+G+T); - fG = G/(A+C+G+T); - fT = T/(A+C+G+T); + if((lk1 > lk0) || (lk2 > lk0)) + { + tree->n_swap++; + + if(lk1 > lk2) + { + Swap(v2,b_fcus->left,b_fcus->rght,v3,tree); + + if(b_fcus->nni->best_l == NULL) b_fcus->nni->best_l = Duplicate_Scalar_Dbl(len1); + else Copy_Scalar_Dbl(len1,b_fcus->nni->best_l); + + if(b_fcus->nni->best_v == NULL) b_fcus->nni->best_v = Duplicate_Scalar_Dbl(var1); + else Copy_Scalar_Dbl(var1,b_fcus->nni->best_v); + } + else + { + Swap(v2,b_fcus->left,b_fcus->rght,v4,tree); + + if(b_fcus->nni->best_l == NULL) b_fcus->nni->best_l = Duplicate_Scalar_Dbl(len2); + else Copy_Scalar_Dbl(len2,b_fcus->nni->best_l); + + if(b_fcus->nni->best_v == NULL) b_fcus->nni->best_v = Duplicate_Scalar_Dbl(var2); + else Copy_Scalar_Dbl(var2,b_fcus->nni->best_v); + } + } } - - data->b_frq[0] = fA; - data->b_frq[1] = fC; - data->b_frq[2] = fG; - data->b_frq[3] = fT; -} - -/*********************************************************/ - -void Get_AA_Freqs(allseq *data) -{ - int i,j,k; - phydbl A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y; - phydbl fA,fC,fD,fE,fF,fG,fH,fI,fK,fL,fM,fN,fP,fQ,fR,fS,fT,fV,fW,fY; - int w; - phydbl sum; - - fA = fC = fD = fE = fF = fG = fH = fI = fK = fL = - fM = fN = fP = fQ = fR = fS = fT = fV = fW = fY = 1./20.; - - For(k,8) + else { - A = C = D = E = F = G = H = I = K = L = - M = N = P = Q = R = S = T = V = W = Y = .0; - - For(i,data->n_otu) - { - For(j,data->crunch_len) - { - w = data->wght[j]; - if(w) - { - switch(data->c_seq[i]->state[j]) - { - case 'A' : A+=w; break; - case 'C' : C+=w; break; - case 'D' : D+=w; break; - case 'E' : E+=w; break; - case 'F' : F+=w; break; - case 'G' : G+=w; break; - case 'H' : H+=w; break; - case 'I' : I+=w; break; - case 'K' : K+=w; break; - case 'L' : L+=w; break; - case 'M' : M+=w; break; - case 'N' : N+=w; break; - case 'P' : P+=w; break; - case 'Q' : Q+=w; break; - case 'R' : R+=w; break; - case 'S' : S+=w; break; - case 'T' : T+=w; break; - case 'V' : V+=w; break; - case 'W' : W+=w; break; - case 'Y' : Y+=w; break; - case 'Z' : Q+=w; break; - case 'X' : case '?' : case 'O' : case '-' : - A+=w*fA; - C+=w*fC; - D+=w*fD; - E+=w*fE; - F+=w*fF; - G+=w*fG; - H+=w*fH; - I+=w*fI; - K+=w*fK; - L+=w*fL; - M+=w*fM; - N+=w*fN; - P+=w*fP; - Q+=w*fQ; - R+=w*fR; - S+=w*fS; - T+=w*fT; - V+=w*fV; - W+=w*fW; - Y+=w*fY; - break; - default : break; - } - } - } - } - sum = (A+C+D+E+F+G+H+I+K+L+M+N+P+Q+R+S+T+V+W+Y); - fA = A/sum; fC = C/sum; fD = D/sum; fE = E/sum; - fF = F/sum; fG = G/sum; fH = H/sum; fI = I/sum; - fK = K/sum; fL = L/sum; fM = M/sum; fN = N/sum; - fP = P/sum; fQ = Q/sum; fR = R/sum; fS = S/sum; - fT = T/sum; fV = V/sum; fW = W/sum; fY = Y/sum; + Restore_Br_Len(tree); + Update_PMat_At_Given_Edge(b_fcus,tree); + tree->c_lnL = lk_init; } - data->b_frq[0] = fA; data->b_frq[1] = fR; data->b_frq[2] = fN; data->b_frq[3] = fD; - data->b_frq[4] = fC; data->b_frq[5] = fQ; data->b_frq[6] = fE; data->b_frq[7] = fG; - data->b_frq[8] = fH; data->b_frq[9] = fI; data->b_frq[10] = fL; data->b_frq[11] = fK; - data->b_frq[12] = fM; data->b_frq[13] = fF; data->b_frq[14] = fP; data->b_frq[15] = fS; - data->b_frq[16] = fT; data->b_frq[17] = fW; data->b_frq[18] = fY; data->b_frq[19] = fV; -} - -/*********************************************************/ + Free_Scalar_Dbl(len0); + Free_Scalar_Dbl(len1); + Free_Scalar_Dbl(len2); + Free_Scalar_Dbl(var0); + Free_Scalar_Dbl(var1); + Free_Scalar_Dbl(var2); -arbre *Read_Tree_File(FILE *fp_input_tree) -{ - char *line; - arbre *tree; - int i; - char c; +} - line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - do - c=fgetc(fp_input_tree); - while((c != '(') && (c != EOF)); - if(c==EOF) - { - Free(line); - return NULL; - } +void NNI_Pars(t_tree *tree, t_edge *b_fcus, int do_swap) +{ + t_node *v1,*v2,*v3,*v4; + int pars0, pars1, pars2; + int pars_init; - i=0; - for(;;) - { - if((c == ' ') || (c == '\n')) - { - c=fgetc(fp_input_tree); - if(c==EOF) break; - else continue; - } + pars_init = tree->c_pars; + b_fcus->nni->best_conf = 0; + b_fcus->nni->score = +1.0; - line[i]=c; - i++; - c=fgetc(fp_input_tree); - if(c==EOF || c==';') break; - } + pars0 = pars1 = pars2 = 0; + v1 = v2 = v3 = v4 = NULL; - tree = Read_Tree(line); - Free(line); - return tree; -} -/*********************************************************/ + v1 = b_fcus->left->v[b_fcus->l_v1]; + v2 = b_fcus->left->v[b_fcus->l_v2]; + v3 = b_fcus->rght->v[b_fcus->r_v1]; + v4 = b_fcus->rght->v[b_fcus->r_v2]; -void Connect_Edges_To_Nodes_Recur(node *a, node *d, arbre *tree) -{ - int i; + if(v1->num < v2->num) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + if(v3->num < v4->num) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); - Connect_One_Edge_To_Two_Nodes(a,d,tree->t_edges[tree->num_curr_branch_available],tree); - tree->num_curr_branch_available += 1; - if(d->tax) return; - else For(i,3) if(d->v[i] != a) Connect_Edges_To_Nodes_Recur(d,d->v[i],tree); -} + /***********/ + Swap(v2,b_fcus->left,b_fcus->rght,v3,tree); + Set_Both_Sides(YES,tree); + pars1 = Update_Pars_At_Given_Edge(b_fcus,tree); + Swap(v3,b_fcus->left,b_fcus->rght,v2,tree); + /***********/ -/*********************************************************/ + /***********/ + Swap(v2,b_fcus->left,b_fcus->rght,v4,tree); + Set_Both_Sides(YES,tree); + pars2 = Update_Pars_At_Given_Edge(b_fcus,tree); + Swap(v4,b_fcus->left,b_fcus->rght,v2,tree); + /***********/ -void Connect_One_Edge_To_Two_Nodes(node *a, node *d, edge *b, arbre *tree) -{ - int i,dir_a_d; - dir_a_d = -1; - For(i,3) if(a->v[i] == d) {dir_a_d = i; break;} + /***********/ + Set_Both_Sides(YES,tree); + pars0 = Update_Pars_At_Given_Edge(b_fcus,tree); + if(pars0 != pars_init) + { + PhyML_Fprintf(stderr,"\n. pars_init = %d; pars0 = %d\n", + pars_init, + pars0); + Warn_And_Exit("\n. Err. in NNI (3)\n"); + } + /***********/ - a->b[dir_a_d] = b; - b->num = tree->num_curr_branch_available; - b->left = a; - b->rght = d; - if(a->tax) {b->rght = a; b->left = d;} /* root */ - /* a tip is necessary on the right side of the edge */ + tree->c_pars = pars0; - (b->left == a)? - (Make_Edge_Dirs(b,a,d)): - (Make_Edge_Dirs(b,d,a)); + b_fcus->nni->score = MIN(pars1,pars2) - pars0; - b->l = a->l[b->l_r]; - if(a->tax) b->l = a->l[b->r_l]; - if(b->l < BL_MIN) b->l = BL_MIN; - else if(b->l > BL_MAX) b->l = BL_MAX; - b->l_old = b->l; + if(pars0 < MIN(pars1,pars2)) + { + b_fcus->nni->best_conf = 0; + b_fcus->nni->swap_node_v1 = NULL; + b_fcus->nni->swap_node_v2 = NULL; + b_fcus->nni->swap_node_v3 = NULL; + b_fcus->nni->swap_node_v4 = NULL; + } + else if(pars1 < MIN(pars0,pars2)) + { + b_fcus->nni->best_conf = 1; + b_fcus->nni->swap_node_v1 = v2; + b_fcus->nni->swap_node_v2 = b_fcus->left; + b_fcus->nni->swap_node_v3 = b_fcus->rght; + b_fcus->nni->swap_node_v4 = v3; + } + else if(pars2 > MIN(pars0,pars1)) + { + b_fcus->nni->best_conf = 2; + b_fcus->nni->swap_node_v1 = v2; + b_fcus->nni->swap_node_v2 = b_fcus->left; + b_fcus->nni->swap_node_v3 = b_fcus->rght; + b_fcus->nni->swap_node_v4 = v4; + } + else + { + b_fcus->nni->score = +1.0; + b_fcus->nni->swap_node_v1 = NULL; + b_fcus->nni->swap_node_v2 = NULL; + b_fcus->nni->swap_node_v3 = NULL; + b_fcus->nni->swap_node_v4 = NULL; + } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Update_Dirs(arbre *tree) + +void Swap(t_node *a, t_node *b, t_node *c, t_node *d, t_tree *tree) { + int ab, ba, cd, dc, bc; int i; - int buff; - edge *b; - - b = NULL; - buff = -1; - For(i,2*tree->n_otu-3) - { - b = tree->t_edges[i]; - - if((!b->left->tax) && (b->left->v[b->l_v1]->num < b->left->v[b->l_v2]->num)) - { - buff = b->l_v1; - b->l_v1 = b->l_v2; - b->l_v2 = buff; - } - if((!b->rght->tax) && (b->rght->v[b->r_v1]->num < b->rght->v[b->r_v2]->num)) - { - buff = b->r_v1; - b->r_v1 = b->r_v2; - b->r_v2 = buff; - } - } -} - -/*********************************************************/ + /* \ /d \ /a + * \ / \ / + * \b__...__c/ -> \b__...__c/ + * / \ / \ + * / \ / \ + * /a \ /d \ + * + * nodes b and c are not necessarily on the same branch + */ -void Exit(char *message) -{ - fflush(NULL); - fprintf(stderr,"%s",message); - exit(1); -} + if(!tree) return; -/*********************************************************/ + if(!a || !b || !c || !d) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); -void *mCalloc(int nb, size_t size) -{ - void *allocated; + ab = ba = cd = dc = bc = -1; + + for(i=0;i<3;i++) if(a->v[i] == b) { ab = i; break; } + for(i=0;i<3;i++) if(b->v[i] == a) { ba = i; break; } + for(i=0;i<3;i++) if(c->v[i] == d) { cd = i; break; } + for(i=0;i<3;i++) if(d->v[i] == c) { dc = i; break; } + for(i=0;i<3;i++) if(b->v[i] == c) { bc = i; break; } + + if(ab < 0 || ba < 0 || cd < 0 || dc < 0) + { + PhyML_Fprintf(stderr,"\n. ab=%d ba=%d cd=%d dc=%d bc=%d",ab,ba,cd,dc,bc); + PhyML_Fprintf(stderr,"\n. Nodes %d %d %d %d.",a->num,b->num,c->num,d->num); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + a->v[ab] = c; + d->v[dc] = b; + b->v[ba] = d; + c->v[cd] = a; + b->b[ba] = d->b[dc]; + c->b[cd] = a->b[ab]; + + (a->b[ab]->left == b)? + (a->b[ab]->left = c): + (a->b[ab]->rght = c); + + (d->b[dc]->left == c)? + (d->b[dc]->left = b): + (d->b[dc]->rght = b); + + for(i=0;i<3;i++) + { + if(a->b[ab]->left->v[i] == a->b[ab]->rght) a->b[ab]->l_r = i; + if(a->b[ab]->rght->v[i] == a->b[ab]->left) a->b[ab]->r_l = i; + if(d->b[dc]->left->v[i] == d->b[dc]->rght) d->b[dc]->l_r = i; + if(d->b[dc]->rght->v[i] == d->b[dc]->left) d->b[dc]->r_l = i; + } + + a->b[ab]->l_v1 = a->b[ab]->l_v2 = + a->b[ab]->r_v1 = a->b[ab]->r_v2 = + d->b[dc]->l_v1 = d->b[dc]->l_v2 = + d->b[dc]->r_v1 = d->b[dc]->r_v2 = -1; + + for(i=0;i<3;i++) + { + if(i != a->b[ab]->l_r) + { + if(a->b[ab]->l_v1 < 0) a->b[ab]->l_v1 = i; + else a->b[ab]->l_v2 = i; + } + if(i != a->b[ab]->r_l) + { + if(a->b[ab]->r_v1 < 0) a->b[ab]->r_v1 = i; + else a->b[ab]->r_v2 = i; + } + if(i != d->b[dc]->l_r) + { + if(d->b[dc]->l_v1 < 0) d->b[dc]->l_v1 = i; + else d->b[dc]->l_v2 = i; + } + if(i != d->b[dc]->r_l) + { + if(d->b[dc]->r_v1 < 0) d->b[dc]->r_v1 = i; + else d->b[dc]->r_v2 = i; + } + } - if((allocated = calloc((size_t)nb,(size_t)size)) != NULL) + Update_Dirs(tree); + + if(tree->n_root != NULL) { - return allocated; + tree->n_root->v[1] = tree->e_root->left; + tree->n_root->v[2] = tree->e_root->rght; + tree->n_root->b[1]->rght = tree->e_root->left; + tree->n_root->b[2]->rght = tree->e_root->rght; } - else - Warn_And_Exit("\n. Err: low memory\n"); - return NULL; + if(tree->next) + Swap(a->next,b->next,c->next,d->next,tree->next); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void *mRealloc(void *p,int nb, size_t size) +void Update_SubTree_Partial_Lk(t_edge *b_fcus, t_node *a, t_node *d, t_tree *tree) { - if((p = realloc(p,(size_t)nb*size)) != NULL) - return p; - else - Warn_And_Exit("\n. Err: low memory\n"); - - return NULL; + int i; + Update_Partial_Lk(tree,b_fcus,a); + if(d->tax) return; + else for(i=0;i<3;++i) if(d->v[i] != a) Update_SubTree_Partial_Lk(d->b[i],d,d->v[i],tree); } -/*********************************************************/ - -/* arbre *Make_Light_Tree_Struct(int n_otu) */ -/* { */ -/* arbre *tree; */ -/* int i; */ - -/* tree = (arbre *)mCalloc(1,sizeof(arbre )); */ -/* tree->t_edges = (edge **)mCalloc(2*n_otu-3,sizeof(edge *)); */ -/* tree->noeud = (node **)mCalloc(2*n_otu-2,sizeof(node *)); */ -/* tree->n_otu = n_otu; */ - -/* For(i,2*n_otu-3) */ -/* tree->t_edges[i] = Make_Edge_Light(NULL,NULL,i); */ - -/* For(i,2*n_otu-2) */ -/* tree->noeud[i] = Make_Node_Light(i); */ - -/* return tree; */ -/* } */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ - -int Sort_Phydbl_Decrease(const void *a, const void *b) +void Copy_Seq_Names_To_Tip_Labels(t_tree *tree, calign *data) { - if((*(phydbl *)(a)) >= (*(phydbl *)(b))) return -1; - else return 1; + int i; + for(i=0;in_otu;++i) strcpy(tree->a_nodes[i]->name,data->c_seq[i]->name); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Qksort(phydbl* A, int ilo, int ihi) +calign *Copy_Cseq(calign *ori, option *io) { - phydbl pivot; // pivot value for partitioning array - int ulo, uhi; // indices at ends of unpartitioned region - int ieq; // least index of array entry with value equal to pivot - phydbl tempEntry; // temporary entry used for swapping + calign *new; + int i,j,k,n_otu,n_rm,c_len; + char **sp_names_in,**sp_names_out; - if (ilo >= ihi) { - return; - } - // Select a pivot value. - pivot = A[(ilo + ihi)/2]; - // Initialize ends of unpartitioned region and least index of entry - // with value equal to pivot. - ieq = ulo = ilo; - uhi = ihi; - // While the unpartitioned region is not empty, try to reduce its size. - while (ulo <= uhi) { - if (A[uhi] > pivot) { - // Here, we can reduce the size of the unpartitioned region and - // try again. - uhi--; - } else { - // Here, A[uhi] <= pivot, so swap entries at indices ulo and - // uhi. - tempEntry = A[ulo]; - A[ulo] = A[uhi]; - A[uhi] = tempEntry; - // After the swap, A[ulo] <= pivot. - if (A[ulo] < pivot) { - // Swap entries at indices ieq and ulo. - tempEntry = A[ieq]; - A[ieq] = A[ulo]; - A[ulo] = tempEntry; - // After the swap, A[ieq] < pivot, so we need to change - // ieq. - ieq++; - // We also need to change ulo, but we also need to do - // that when A[ulo] = pivot, so we do it after this if - // statement. - } - // Once again, we can reduce the size of the unpartitioned - // region and try again. - ulo++; - } + n_otu = ori->n_otu; + c_len = ori->crunch_len; + n_rm = ori->n_rm; + + sp_names_in = (char **)mCalloc(n_otu+n_rm,sizeof(char *)); + for(i=0;ic_seq[i]->name)+1,sizeof(char)); + strcpy(sp_names_in[i],ori->c_seq[i]->name); } - // Now, all entries from index ilo to ieq - 1 are less than the pivot - // and all entries from index uhi to ihi + 1 are greater than the - // pivot. So we have two regions of the array that can be sorted - // recursively to put all of the entries in order. - Qksort(A, ilo, ieq - 1); - Qksort(A, uhi + 1, ihi); -} - -/********************************************************/ - -void Qksort_Matrix(phydbl **A, int col, int ilo, int ihi) -{ - phydbl pivot; // pivot value for partitioning array - int ulo, uhi; // indices at ends of unpartitioned region - int ieq; // least index of array entry with value equal to pivot - phydbl *tempEntry; // temporary entry used for swapping - tempEntry = NULL; - - if (ilo >= ihi) { - return; - } - // Select a pivot value. - pivot = A[(ilo + ihi)/2][col]; - // Initialize ends of unpartitioned region and least index of entry - // with value equal to pivot. - ieq = ulo = ilo; - uhi = ihi; - // While the unpartitioned region is not empty, try to reduce its size. - while (ulo <= uhi) { - if (A[uhi][col] > pivot) { - // Here, we can reduce the size of the unpartitioned region and - // try again. - uhi--; - } else { - // Here, A[uhi] <= pivot, so swap entries at indices ulo and - // uhi. - tempEntry = A[ulo]; - A[ulo] = A[uhi]; - A[uhi] = tempEntry; - // After the swap, A[ulo] <= pivot. - if (A[ulo][col] < pivot) { - // Swap entries at indices ieq and ulo. - tempEntry = A[ieq]; - A[ieq] = A[ulo]; - A[ulo] = tempEntry; - // After the swap, A[ieq] < pivot, so we need to change - // ieq. - ieq++; - // We also need to change ulo, but we also need to do - // that when A[ulo] = pivot, so we do it after this if - // statement. - } - // Once again, we can reduce the size of the unpartitioned - // region and try again. - ulo++; - } + sp_names_out = (char **)mCalloc(n_rm,sizeof(char *)); + for(i=0;in_rm;i++) + { + sp_names_out[i] = (char *)mCalloc(strlen(ori->c_seq_rm[i]->name)+1,sizeof(char)); + strcpy(sp_names_out[i],ori->c_seq_rm[i]->name); } - // Now, all entries from index ilo to ieq - 1 are less than the pivot - // and all entries from index uhi to ihi + 1 are greater than the - // pivot. So we have two regions of the array that can be sorted - // recursively to put all of the entries in order. - Qksort_Matrix(A, col, ilo, ieq - 1); - Qksort_Matrix(A, col, uhi + 1, ihi); -} -/********************************************************/ + new = Make_Calign(n_otu+n_rm,c_len+1,io->state_len,ori->init_len,sp_names_in,ori->n_rm,sp_names_out); + new->n_rm = ori->n_rm; + Init_Calign(n_otu,c_len+1,ori->init_len,new); -void Print_Site(allseq *alldata, int num, int n_otu, char *sep, int stepsize) -{ - int i,j; - For(i,n_otu) + for(i=0;in_rm;++i) { - printf("%s ",alldata->c_seq[i]->name); - For(j,stepsize) - printf("%c",alldata->c_seq[i]->state[num+j]); - printf("%s",sep); - } - fprintf(stderr,"%s",sep); -} + strcpy(new->c_seq_rm[i]->name,ori->c_seq_rm[i]->name); + for(j=0;jcrunch_len;j++) + { + for(k=0;kstate_len;++k) + new->c_seq_rm[i]->state[j*io->state_len+k] = + ori->c_seq_rm[i]->state[j*io->state_len+k]; -/*********************************************************/ + new->c_seq_rm[i]->is_ambigu[j] = ori->c_seq_rm[i]->is_ambigu[j]; + } + new->c_seq_rm[i]->len = ori->c_seq_rm[i]->len; + new->c_seq_rm[i]->state[c_len*io->state_len] = '\0'; + new->c_seq_rm[i]->is_duplicate = YES; + } + + new->obs_pinvar = ori->obs_pinvar; -void Print_Site_Lk(arbre *tree, FILE *fp) -{ - int site; - int catg; - char *s; - phydbl postmean; + for(i=0;in_otu;i++) new->c_seq[i]->num = ori->c_seq[i]->num; + for(i=0;in_rm;i++) new->c_seq_rm[i]->num = ori->c_seq_rm[i]->num; - if(!tree->io->print_site_lnl) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } + for(i=0;iinit_len;i++) new->sitepatt[i] = ori->sitepatt[i]; - if(!tree->io->print_trace) + for(j=0;jcrunch_len;j++) { - s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); - - fprintf(fp,"Note : P(D|M) is the probability of site D given the model M (i.e., the site likelihood)\n"); - if(tree->mod->n_catg > 1 || tree->mod->invar) - fprintf(fp,"P(D|M,rr[x]) is the probability of site D given the model M and the relative rate\nof evolution rr[x], where x is the class of rate to be considered.\nWe have P(D|M) = \\sum_x P(x) x P(D|M,rr[x]).\n"); - fprintf(fp,"\n\n"); - - sprintf(s,"Site"); - fprintf(fp, "%-7s",s); - - sprintf(s,"P(D|M)"); - fprintf(fp,"%-16s",s); - - if(tree->mod->n_catg > 1) - { - For(catg,tree->mod->n_catg) - { - sprintf(s,"P(D|M,rr[%d]=%5.4f)",catg+1,tree->mod->gamma_rr[catg]); - fprintf(fp,"%-22s",s); - } - - sprintf(s,"Posterior mean"); - fprintf(fp,"%-22s",s); - } - - - if(tree->mod->invar) - { - sprintf(s,"P(D|M,rr[0]=0)"); - fprintf(fp,"%-16s",s); - } - fprintf(fp,"\n"); + for(i=0;in_otu;i++) + { + for(k=0;kstate_len;k++) + { + new->c_seq[i]->state[j*io->state_len+k] = + ori->c_seq[i]->state[j*io->state_len+k]; + } + new->c_seq[i]->is_ambigu[j] = ori->c_seq[i]->is_ambigu[j]; + } - For(site,tree->data->init_len) - { - fprintf(fp,"%-7d",site+1); - fprintf(fp,"%-16g",(phydbl)exp(tree->site_lk[tree->data->sitepatt[site]])); - if(tree->mod->n_catg > 1) - { - For(catg,tree->mod->n_catg) - fprintf(fp,"%-22g",(phydbl)exp(tree->log_site_lk_cat[catg][tree->data->sitepatt[site]])); - - postmean = .0; - For(catg,tree->mod->n_catg) - postmean += - tree->mod->gamma_rr[catg] * - exp(tree->log_site_lk_cat[catg][tree->data->sitepatt[site]]) * - tree->mod->gamma_r_proba[catg]; - postmean /= exp(tree->site_lk[tree->data->sitepatt[site]]); - - fprintf(fp,"%-22g",postmean); - } - if(tree->mod->invar) - { - if((phydbl)tree->data->invar[tree->data->sitepatt[site]] > -0.5) - fprintf(fp,"%-16g",tree->mod->pi[tree->data->invar[tree->data->sitepatt[site]]]); - else - fprintf(fp,"%-16g",0.0); - } - fprintf(fp,"\n"); - } - Free(s); - } - else - { - For(site,tree->data->init_len) - fprintf(fp,"%.2f\t",tree->site_lk[tree->data->sitepatt[site]]); - fprintf(fp,"\n"); + new->wght[j] = ori->wght[j]; + new->ambigu[j] = ori->ambigu[j]; + new->invar[j] = ori->invar[j]; } -} - - -/*********************************************************/ - -void Print_Seq(seq **data, int n_otu) -{ - int i,j; - - printf("%d\t%d\n",n_otu,data[0]->len); - For(i,n_otu) + + for(i=0;in_otu;i++) { -/* For(j,30) */ -/* { */ -/* if(j<(int)strlen(data[i]->name)) */ -/* putchar(data[i]->name[j]); */ -/* else putchar(' '); */ -/* } */ - printf("%10d ",i); - For(j,data[i]->len) - { - printf("%c",data[i]->state[j]); - } - printf("\n"); + new->c_seq[i]->len = ori->c_seq[i]->len; + strcpy(new->c_seq[i]->name,ori->c_seq[i]->name); + new->c_seq[i]->is_duplicate = NO; } -} + + for(i=0;in_otu;i++) new->c_seq[i]->state[c_len*io->state_len] = '\0'; -/*********************************************************/ + for(i=0;iobs_state_frq[i] = ori->obs_state_frq[i]; -void Print_CSeq(FILE *fp, allseq *alldata) -{ - int i,j,k; - int n_otu; + new->init_len = ori->init_len; + new->clean_len = ori->clean_len; + new->crunch_len = ori->crunch_len; + new->n_otu = ori->n_otu; + new->io = ori->io; - n_otu = alldata->n_otu; - fprintf(fp,"%d\t%d\n",n_otu,alldata->init_len); - For(i,n_otu) - { - For(j,50) - { - if(j<(int)strlen(alldata->c_seq[i]->name)) - fputc(alldata->c_seq[i]->name[j],fp); - else fputc(' ',fp); - } + for(i=n_otu;ic_seq[i] = new->c_seq_rm[i-n_otu]; + + for(i=0;in_otu;i++) Free(sp_names_in[i]); + Free(sp_names_in); - For(j,alldata->crunch_len) - { - For(k,alldata->wght[j]) - fprintf(fp,"%c",alldata->c_seq[i]->state[j]); - } - fprintf(fp,"\n"); - } - fprintf(fp,"\n"); + for(i=0;in_rm;i++) Free(sp_names_out[i]); + Free(sp_names_out); -/* printf("\t"); */ -/* For(j,alldata->crunch_len) */ -/* printf("%.0f ",alldata->wght[j]); */ -/* printf("\n"); */ + return new; } -/*********************************************************/ - -void Order_Tree_Seq(arbre *tree, seq **data) -{ - int i,j,n_otu; - seq *buff; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - n_otu = tree->n_otu; - For(i,n_otu) - { - For(j,n_otu) - { - if(!strcmp(tree->noeud[i]->name,data[j]->name)) - break; - } - buff = data[j]; - data[j] = data[i]; - data[i] = buff; - } +int Filexists(char *filename) +{ + FILE *fp; + fp =fopen(filename,"r"); + if (fp) { + fclose(fp); + return 1; + } else + return 0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Order_Tree_CSeq(arbre *tree, allseq *data) +matrix *K80_dist(calign *data, phydbl g_shape) { - int i,j,n_otu_tree,n_otu_seq; - seq *buff; + int i,j,k; + int diff; + matrix *mat; + phydbl **len; + len = (phydbl **)mCalloc(data->n_otu,sizeof(phydbl *)); + for(i=0;in_otu;i++) + len[i] = (phydbl *)mCalloc(data->n_otu,sizeof(phydbl)); - n_otu_tree = tree->n_otu; - n_otu_seq = data->n_otu; + mat = Make_Mat(data->n_otu); + Init_Mat(mat,data); - if(n_otu_tree != n_otu_seq) - { - /* printf("%d(tree) != %d(seq) \n",n_otu_tree,n_otu_seq); */ - Warn_And_Exit("\n. The number of tips in the tree is not the same as the number of sequences\n"); - } - For(i,MAX(n_otu_tree,n_otu_seq)) + diff = 0; + + For(i,data->c_seq[0]->len) + { + for(j=0;jn_otu-1;j++) { - For(j,MIN(n_otu_tree,n_otu_seq)) - { - if(!strcmp(tree->noeud[i]->name,data->c_seq[j]->name)) - break; - } - - if(j==MIN(n_otu_tree,n_otu_seq)) + for(k=j+1;kn_otu;k++) + { + if(((data->c_seq[j]->state[i] == 'A' || data->c_seq[j]->state[i] == 'G') && + (data->c_seq[k]->state[i] == 'C' || data->c_seq[k]->state[i] == 'T'))|| + ((data->c_seq[j]->state[i] == 'C' || data->c_seq[j]->state[i] == 'T') && + (data->c_seq[k]->state[i] == 'A' || data->c_seq[k]->state[i] == 'G'))) { - printf("\n. Err: %s is not found in sequence data set\n", - tree->noeud[i]->name); - Warn_And_Exit(""); + diff++; + mat->Q[j][k]+=data->wght[i]; + len[j][k]+=data->wght[i]; + len[k][j]=len[j][k]; } - buff = data->c_seq[j]; - data->c_seq[j] = data->c_seq[i]; - data->c_seq[i] = buff; + + else + if(((data->c_seq[j]->state[i] == 'A' && data->c_seq[k]->state[i] == 'G') || + (data->c_seq[j]->state[i] == 'G' && data->c_seq[k]->state[i] == 'A'))|| + ((data->c_seq[j]->state[i] == 'C' && data->c_seq[k]->state[i] == 'T') || + (data->c_seq[j]->state[i] == 'T' && data->c_seq[k]->state[i] == 'C'))) + { + diff++; + mat->P[j][k]+=data->wght[i]; + len[j][k]+=data->wght[i]; + len[k][j]=len[j][k]; + } + else + if((data->c_seq[j]->state[i] == 'A' || + data->c_seq[j]->state[i] == 'C' || + data->c_seq[j]->state[i] == 'G' || + data->c_seq[j]->state[i] == 'T')&& + (data->c_seq[k]->state[i] == 'A' || + data->c_seq[k]->state[i] == 'C' || + data->c_seq[k]->state[i] == 'G' || + data->c_seq[k]->state[i] == 'T')) + { + len[j][k]+=data->wght[i]; + len[k][j]=len[j][k]; + } + } } -} - -/*********************************************************/ + } + + + for(i=0;in_otu-1;i++) + for(j=i+1;jn_otu;j++) + { + if(len[i][j] > .0) + { + mat->P[i][j] /= len[i][j]; + mat->Q[i][j] /= len[i][j]; + } + else + { + mat->P[i][j] = .5; + mat->Q[i][j] = .5; + } -matrix *Make_Mat(int n_otu) -{ - matrix *mat; - int i; + mat->P[j][i] = mat->P[i][j]; + mat->Q[j][i] = mat->Q[i][j]; - mat = (matrix *)mCalloc(1,sizeof(matrix)); - mat->n_otu = n_otu; + if((1-2*mat->P[i][j]-mat->Q[i][j] <= .0) || (1-2*mat->Q[i][j] <= .0)) + { + mat->dist[i][j] = -1.; + mat->dist[j][i] = -1.; + continue; + } - mat->P = (phydbl **)mCalloc(n_otu,sizeof(phydbl *)); - mat->Q = (phydbl **)mCalloc(n_otu,sizeof(phydbl *)); - mat->dist = (phydbl **)mCalloc(n_otu,sizeof(phydbl *)); - mat->on_off = (int *)mCalloc(n_otu,sizeof(int)); - mat->name = (char **)mCalloc(n_otu,sizeof(char *)); - mat->tip_node = (node **)mCalloc(n_otu,sizeof(node *)); + mat->dist[i][j] = (g_shape/2)* + (POW(1-2*mat->P[i][j]-mat->Q[i][j],-1./g_shape) + + 0.5*POW(1-2*mat->Q[i][j],-1./g_shape) - 1.5); + if(mat->dist[i][j] > DIST_MAX) mat->dist[i][j] = DIST_MAX; - For(i,n_otu) - { - mat->P[i] = (phydbl *)mCalloc(n_otu,sizeof(phydbl)); - mat->Q[i] = (phydbl *)mCalloc(n_otu,sizeof(phydbl)); - mat->dist[i] = (phydbl *)mCalloc(n_otu,sizeof(phydbl)); - mat->name[i] = (char *)mCalloc(T_MAX_NAME,sizeof(char)); - } + mat->dist[j][i] = mat->dist[i][j]; + } + for(i=0;in_otu;i++) free(len[i]); + free(len); return mat; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Init_Mat(matrix *mat, allseq *data) + +matrix *JC69_Dist(calign *data, t_mod *mod) { - int i; + int site,i,j,k; + matrix *mat; + phydbl **len; + int datatype; - mat->n_otu = data->n_otu; - mat->r = mat->n_otu; - mat->curr_int = mat->n_otu; - mat->method = 1; - For(i,data->n_otu) - { - strcpy(mat->name[i],data->c_seq[i]->name); - mat->on_off[i] = 1; - } -} + len = (phydbl **)mCalloc(data->n_otu,sizeof(phydbl *)); + for(i=0;in_otu;i++) + len[i] = (phydbl *)mCalloc(data->n_otu,sizeof(phydbl)); -/*********************************************************/ + mat = Make_Mat(data->n_otu); + Init_Mat(mat,data); -arbre *Make_Tree_From_Scratch(int n_otu, allseq *data) -{ - arbre *tree; + datatype = mod->io->datatype; - tree = Make_Tree(n_otu); - Make_All_Tree_Nodes(tree); - Make_All_Tree_Edges(tree); - Make_Tree_Path(tree); - Make_List_Of_Reachable_Tips(tree); - if(data) + For(site,data->c_seq[0]->len) { - Copy_Tax_Names_To_Tip_Labels(tree,data); - tree->data = data; - } - return tree; -} + for(j=0;jn_otu-1;j++) + { + for(k=j+1;kn_otu;k++) + { + if((!Is_Ambigu(data->c_seq[j]->state+site*mod->io->state_len,datatype,mod->io->state_len)) && + (!Is_Ambigu(data->c_seq[k]->state+site*mod->io->state_len,datatype,mod->io->state_len))) + { + len[j][k]+=data->wght[site]; + len[k][j]=len[j][k]; -/*********************************************************/ -arbre *Make_Tree(int n_otu) -{ - arbre *tree; - int i; - tree = (arbre *)mCalloc(1,sizeof(arbre )); - Init_Tree(tree,n_otu); - tree->t_dir = (int **)mCalloc(2*n_otu-2,sizeof(int *)); - For(i,2*n_otu-2) tree->t_dir[i] = (int *)mCalloc(2*n_otu-2,sizeof(int)); - return tree; -} + if(strncmp(data->c_seq[j]->state+site*mod->io->state_len, + data->c_seq[k]->state+site*mod->io->state_len,mod->io->state_len)) +/* if(!Are_Compatible(data->c_seq[j]->state+site*mod->io->state_len, */ +/* data->c_seq[k]->state+site*mod->io->state_len, */ +/* mod->io->state_len, */ +/* mod->io->datatype)) */ + mat->P[j][k]+=data->wght[site]; + } + } + } + } -/*********************************************************/ -void Make_Tree_Path(arbre *tree) -{ - tree->curr_path = (node **)mCalloc(tree->n_otu,sizeof(node *)); -} + for(i=0;in_otu-1;i++) + for(j=i+1;jn_otu;j++) + { + if(len[i][j] > .0) mat->P[i][j] /= len[i][j]; + else mat->P[i][j] = 1.; -/*********************************************************/ + mat->P[j][i] = mat->P[i][j]; -void Make_All_Tree_Nodes(arbre *tree) -{ - int i; - tree->noeud = (node **)mCalloc(2*tree->n_otu-2,sizeof(node *)); - tree->t_dead_nodes = (node **)mCalloc(2*tree->n_otu-2,sizeof(node *)); + if((1.-(mod->ns)/(mod->ns-1.)*mat->P[i][j]) < .0) mat->dist[i][j] = -1.; + else + mat->dist[i][j] = -(mod->ns-1.)/(mod->ns)*(phydbl)log(1.-(mod->ns)/(mod->ns-1.)*mat->P[i][j]); - For(i,2*tree->n_otu-2) - { - tree->noeud[i] = (node *)Make_Node_Light(i); - if(i < tree->n_otu) tree->noeud[i]->tax = 1; - else tree->noeud[i]->tax = 0; - } -} +/* PhyML_Printf("\n. Incorrect JC distances"); */ +/* mat->dist[i][j] = len[i][j]; */ -/*********************************************************/ + if(mat->dist[i][j] > DIST_MAX) mat->dist[i][j] = DIST_MAX; -void Make_All_Tree_Edges(arbre *tree) -{ - int i; + mat->dist[j][i] = mat->dist[i][j]; + } - tree->t_edges = (edge **)mCalloc(2*tree->n_otu-3,sizeof(edge *)); - tree->t_dead_edges = (edge **)mCalloc(2*tree->n_otu-3,sizeof(edge *)); + for(i=0;in_otu;i++) free(len[i]); + free(len); - For(i,2*tree->n_otu-3) tree->t_edges[i] = (edge *)Make_Edge_Light(NULL,NULL,i); + return mat; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Copy_Tax_Names_To_Tip_Labels(arbre *tree, allseq *data) +matrix *Hamming_Dist(calign *data, t_mod *mod) { - int i; + int i,j,k; + matrix *mat; + phydbl **len; + int datatype; - For(i,tree->n_otu) + len = (phydbl **)mCalloc(data->n_otu,sizeof(phydbl *)); + for(i=0;in_otu;i++) + len[i] = (phydbl *)mCalloc(data->n_otu,sizeof(phydbl)); + + mat = Make_Mat(data->n_otu); + Init_Mat(mat,data); + + datatype = mod->io->datatype; + + for(i=0;icrunch_len;i++) { - strcpy(tree->noeud[i]->name,data->c_seq[i]->name); - tree->noeud[i]->tax = 1; - tree->noeud[i]->num = i; + for(j=0;jn_otu-1;j++) + { + for(k=j+1;kn_otu;k++) + { + if((!Is_Ambigu(data->c_seq[j]->state+i*mod->io->state_len,datatype,mod->io->state_len)) && + (!Is_Ambigu(data->c_seq[k]->state+i*mod->io->state_len,datatype,mod->io->state_len))) + { + len[j][k]+=data->wght[i]; + len[k][j]=len[j][k]; + /* if(data->c_seq[j]->state[i] != data->c_seq[k]->state[i]) */ + if(!Are_Compatible(data->c_seq[j]->state+i*mod->io->state_len, + data->c_seq[k]->state+i*mod->io->state_len, + mod->io->state_len, + mod->io->datatype)) + { + mat->P[j][k]+=data->wght[i]; + } + } + } + } } + + for(i=0;in_otu-1;i++) + for(j=i+1;jn_otu;j++) + { + if(len[i][j] > .0) + { + mat->P[i][j] /= len[i][j]; + } + else + { + mat->P[i][j] = 1.; + } + + mat->P[j][i] = mat->P[i][j]; + + mat->dist[i][j] = mat->P[i][j]; + + + if(mat->dist[i][j] > DIST_MAX) + { + mat->dist[i][j] = DIST_MAX; + } + mat->dist[j][i] = mat->dist[i][j]; + } + + for(i=0;in_otu;i++) free(len[i]); + free(len); + + return mat; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Print_Dist(matrix *mat) +short int Are_Sequences_Identical(align *seq1, align *seq2) { - int i,j; + for(int i=0; ilen; ++i) if(seq1->state[i] != seq2->state[i]) return NO; + return YES; +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,mat->n_otu) +void Remove_Duplicates(calign *data, option *io, t_tree *tree) +{ + int n_duplicates,n_removed,n_otu_orig,i,j,k; + align *tmp; + + if(data->n_rm > 0) return; // Already removed duplicates + if(io->leave_duplicates == YES) return; + + n_otu_orig = data->n_otu; + + if(n_otu_orig < 4) return; + + n_duplicates = 0; + + for(i=0; in_otu-1; ++i) { - printf("%s ",mat->name[i]); + if(data->c_seq[i]->is_duplicate == YES) continue; + else + { + for(j=i+1; j < data->n_otu; ++j) + { + if(Are_Sequences_Identical(data->c_seq[i],data->c_seq[j]) == YES) + { + for(k=0;ka_nodes[k]->name,data->c_seq[j]->name)) break; + assert(k < n_otu_orig); + + if(tree->a_nodes[k]->b[0] != tree->e_root) data->c_seq[j]->is_duplicate = YES; + else data->c_seq[i]->is_duplicate = YES; + + if(n_duplicates == 0) PhyML_Printf("\n"); + PhyML_Printf("\n. Note: taxon '%s' is a duplicate of taxon '%s'.", + data->c_seq[j]->name,data->c_seq[i]->name); - For(j,mat->n_otu) - printf("%9.6f ",mat->dist[i][j]); - printf("\n"); + n_duplicates++; + } + } + } } -} -/*********************************************************/ + n_removed = 0; + for(i=0; i < n_otu_orig; ++i) + { + if(data->c_seq[i]->is_duplicate == YES) + { + if(!n_removed) data->c_seq_rm = (align **)mCalloc(1,sizeof(align *)); + else data->c_seq_rm = (align **)mRealloc(data->c_seq_rm,n_removed+1,sizeof(align *)); + data->c_seq_rm[n_removed] = data->c_seq[i]; + n_removed++; + if(n_otu_orig - n_removed == 3) + { + for(j=i+1; j < n_otu_orig; ++j) data->c_seq[j]->is_duplicate = NO; + i = n_otu_orig+1; + } + } + } + + data->n_rm = n_removed; + + if(!n_removed) return; -void Print_Node(node *a, node *d, arbre *tree) -{ - int i; - int dir; - dir = -1; - For(i,3) if(a->v[i] == d) {dir = i; break;} - printf("Node nums = %3d %3d (dir=%d);",a->num,d->num,dir); - printf("Node names = '%s' '%s' ; ",a->name,d->name); - For(i,3) if(a->v[i] == d) + + for(i=0; i < n_otu_orig; ++i) { - printf("Branch num = %3d (%d %d) %f", - a->b[i]->num,a->b[i]->left->num, - a->b[i]->rght->num,a->b[i]->l); - if(a->b[i]->left->tax) printf(" WARNING LEFT->TAX!"); - break; + if(data->c_seq[i]->is_duplicate == YES) + { + for(int j=i+1; j < n_otu_orig; j++) + { + if(data->c_seq[j]->is_duplicate == NO) + { + tmp = data->c_seq[i]; + data->c_seq[i] = data->c_seq[j]; + data->c_seq[j] = tmp; + break; + } + } + } } - printf("\n"); - if(d->tax) return; - else - For(i,3) - if(d->v[i] != a) Print_Node(d,d->v[i],tree); + Remove_Duplicates_From_Tree(data,tree); + + data->n_otu = tree->n_otu; + io->n_otu = tree->n_otu; + } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Share_Lk_Struct(arbre *t_full, arbre *t_empt) +void Remove_Duplicates_From_Tree(calign *data, t_tree *tree) { - int i,j,n_otu; - edge *b_e,*b_f; - node *n_e, *n_f; - - n_otu = t_full->n_otu; - t_empt->n_root = t_full->n_root; - t_empt->e_root = t_full->e_root; - t_empt->c_lnL_sorted = t_full->c_lnL_sorted; - t_empt->log_site_lk_cat = t_full->log_site_lk_cat; - t_empt->site_lk = t_full->site_lk; - t_empt->triplet_struct = t_full->triplet_struct; - t_empt->log_lks_aLRT = t_full->log_lks_aLRT; + int i,j; + int n_otu_orig,idx; + t_edge *res_edge; - For(i,2*n_otu-3) + n_otu_orig = tree->n_otu; + idx = -1; + + for(i=0;it_edges[i]; - b_e = t_empt->t_edges[i]; - - b_e->Pij_rr = b_f->Pij_rr; - - b_e->nni = b_f->nni; + for(j=0;jc_seq[j]->is_duplicate == YES && + !strcmp(tree->a_nodes[i]->name,data->c_seq[j]->name) && + tree->a_nodes[i]->b[0] != tree->e_root) + { + Prune_Subtree(tree->a_nodes[i]->v[0], + tree->a_nodes[i], + NULL,&res_edge,tree); + + assert(tree->a_edges[tree->a_nodes[i]->b[0]->num] == tree->a_nodes[i]->b[0]); + idx = tree->a_nodes[i]->b[0]->num; + Free_Edge_Length(tree->a_nodes[i]->b[0]); + Free_Edge(tree->a_nodes[i]->b[0]); + tree->a_edges[idx] = NULL; + idx = res_edge->num; + assert(tree->a_edges[res_edge->num] == res_edge); + Free_Edge_Length(res_edge); + Free_Edge(res_edge); + tree->a_edges[idx] = NULL; + + idx = tree->a_nodes[i]->v[0]->num; + Free_Node(tree->a_nodes[i]->v[0]); + tree->a_nodes[idx] = NULL; + + Free_Node(tree->a_nodes[i]); + tree->a_nodes[i] = NULL; + + break; + } + } } + tree->a_nodes[2*tree->n_otu-2 - 2*data->n_rm] = tree->a_nodes[2*tree->n_otu-2]; + tree->a_edges[2*tree->n_otu-3 - 2*data->n_rm] = tree->a_edges[2*tree->n_otu-3]; + tree->a_edges[2*tree->n_otu-2 - 2*data->n_rm] = tree->a_edges[2*tree->n_otu-2]; - for(i=n_otu;i<2*n_otu-2;i++) + if(data->n_rm > 0) { - n_f = t_full->noeud[i]; - n_e = t_empt->noeud[i]; - - For(j,3) - { - if(n_f->b[j]->left == n_f) - { - if(n_e->b[j]->left == n_e) - { - n_e->b[j]->p_lk_left = n_f->b[j]->p_lk_left; - n_e->b[j]->sum_scale_f_left = n_f->b[j]->sum_scale_f_left; - n_e->b[j]->p_lk_tip_l = n_f->b[j]->p_lk_tip_l; - } - else - { - n_e->b[j]->p_lk_rght = n_f->b[j]->p_lk_left; - n_e->b[j]->sum_scale_f_rght = n_f->b[j]->sum_scale_f_left; - n_e->b[j]->p_lk_tip_r = n_f->b[j]->p_lk_tip_l; - } - } - else - { - if(n_e->b[j]->rght == n_e) - { - n_e->b[j]->p_lk_rght = n_f->b[j]->p_lk_rght; - n_e->b[j]->sum_scale_f_rght = n_f->b[j]->sum_scale_f_rght; - n_e->b[j]->p_lk_tip_r = n_f->b[j]->p_lk_tip_r; - } - else - { - n_e->b[j]->p_lk_left = n_f->b[j]->p_lk_rght; - n_e->b[j]->sum_scale_f_left = n_f->b[j]->sum_scale_f_rght; - n_e->b[j]->p_lk_tip_l = n_f->b[j]->p_lk_tip_r; - } - } - } + tree->n_otu -= data->n_rm; + Refactor_Tree(tree); } + +} - For(i,n_otu) - { - n_f = t_full->noeud[i]; - n_e = t_empt->noeud[i]; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if(n_f->b[0]->rght == n_f) - { - n_e->b[0]->p_lk_rght = n_f->b[0]->p_lk_rght; - n_e->b[0]->sum_scale_f_rght = n_f->b[0]->sum_scale_f_rght; - n_e->b[0]->p_lk_tip_r = n_f->b[0]->p_lk_tip_r; - } - else - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } +void Insert_Duplicates(t_tree *tree) +{ + unsigned int i,j; + unsigned int idx_new_edge,idx_new_node,idx_root; + t_edge *link_daughter,*residual,**new_a_edges,*b1,*b2; + t_node *link,*daughter,**new_a_nodes,*n0; + + link_daughter = NULL; + residual = NULL; + link = NULL; + daughter = NULL; + idx_root = (tree->n_root) ? 1 : 3; + + n0 = tree->a_nodes[2*tree->n_otu-2]; + b1 = tree->a_edges[2*tree->n_otu-2]; + b2 = tree->a_edges[2*tree->n_otu-3]; + + new_a_nodes = (t_node **)mCalloc(2*tree->n_otu-1 + tree->data->n_rm * 2,sizeof(t_node *)); + + for(i=0;in_otu;++i) new_a_nodes[i] = tree->a_nodes[i]; + for(i=tree->n_otu;i<2*tree->n_otu-1;++i) + { + new_a_nodes[i+tree->data->n_rm] = tree->a_nodes[i]; + new_a_nodes[i+tree->data->n_rm]->num = i+tree->data->n_rm; + } + + Free(tree->a_nodes); + tree->a_nodes = new_a_nodes; + + new_a_edges = (t_edge **)mCalloc(2*tree->n_otu-1+tree->data->n_rm*2,sizeof(t_edge *)); + for(i=0;i<2*tree->n_otu-1;++i) new_a_edges[i] = tree->a_edges[i]; + + + idx_new_edge = 0; + idx_new_node = 0; + + for(i=0;idata->n_rm;++i) + { + for(j=0;jn_otu;++j) + { + if(Are_Sequences_Identical(tree->data->c_seq_rm[i],tree->a_nodes[j]->c_seq) == YES) + { + link = Make_Node_Light(2*tree->n_otu-idx_root+tree->data->n_rm+idx_new_node+1); + daughter = Make_Node_Light(tree->n_otu+idx_new_node); + + new_a_nodes[tree->n_otu+idx_new_node] = daughter; + new_a_nodes[2*tree->n_otu-idx_root+tree->data->n_rm+idx_new_node+1] = link; + + idx_new_node += 1; + + daughter->c_seq = tree->data->c_seq_rm[i]; + + daughter->name = (char *)mCalloc((int)strlen(tree->data->c_seq_rm[i]->name)+1,sizeof(char)); + daughter->ori_name = daughter->name; + strcpy(daughter->name,tree->data->c_seq_rm[i]->name); + + link->v[0] = daughter; + link->v[1] = NULL; + link->v[2] = NULL; + + daughter->v[0] = link; + daughter->v[1] = NULL; + daughter->v[2] = NULL; + + daughter->tax = YES; + link->tax = NO; + + link_daughter = Make_Edge_Light(link,daughter,2*tree->n_otu-idx_root+idx_new_edge); + residual = Make_Edge_Light(daughter,link,2*tree->n_otu-idx_root+idx_new_edge+1); + + new_a_edges[2*tree->n_otu-idx_root+idx_new_edge] = link_daughter; + new_a_edges[2*tree->n_otu-idx_root+idx_new_edge+1] = residual; + + new_a_edges[2*tree->n_otu-idx_root+idx_new_edge]->rght = daughter; + new_a_edges[2*tree->n_otu-idx_root+idx_new_edge]->left = link; + + new_a_edges[2*tree->n_otu-idx_root+idx_new_edge+1]->rght = link; + new_a_edges[2*tree->n_otu-idx_root+idx_new_edge+1]->left = tree->a_nodes[j]->b[0]->left; + + daughter->b[0] = link_daughter; + link->b[0] = link_daughter; + + idx_new_edge += 2; + + Set_Scalar_Dbl(tree->mod->l_min,link_daughter->l); + + Multiply_Scalar_Dbl(2.0,tree->a_nodes[j]->b[0]->l); + Graft_Subtree(tree->a_nodes[j]->b[0], + link, + daughter, + residual, + tree->a_nodes[j], + tree); + Set_Scalar_Dbl(tree->a_nodes[j]->b[0]->l->v,residual->l); + Set_Scalar_Dbl(tree->mod->l_min,tree->a_nodes[j]->b[0]->l); + residual->support_val = -1.; + + break; + + } + } } -} -/*********************************************************/ -void Share_Spr_Struct(arbre *t_full, arbre *t_empt) -{ - t_empt->size_spr_list = t_full->size_spr_list; - t_empt->spr_list = t_full->spr_list; - t_empt->best_spr = t_full->best_spr; + Free(tree->a_edges); + tree->a_edges = new_a_edges; + + tree->n_otu += tree->data->n_rm; + + Refactor_Tree(tree); + + tree->a_nodes[2*tree->n_otu-2] = n0; + tree->a_edges[2*tree->n_otu-2] = b1; + tree->a_edges[2*tree->n_otu-3] = b2; } -/*********************************************************/ -void Share_Pars_Struct(arbre *t_full, arbre *t_empt) -{ - int i; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - t_empt->site_pars = t_full->site_pars; - t_empt->step_mat = t_full->step_mat; - For(i,2*t_full->n_otu-3) - { - t_empt->t_edges[i]->ui_l = t_full->t_edges[i]->ui_l; - t_empt->t_edges[i]->ui_r = t_full->t_edges[i]->ui_r; +/* Test if the given site pattern is invariant. Does not handle ambiguities */ - t_empt->t_edges[i]->pars_l = t_full->t_edges[i]->pars_l; - t_empt->t_edges[i]->pars_r = t_full->t_edges[i]->pars_r; +int Is_Invar(int patt_num, int stepsize, int datatype, calign *data) +{ + int i, j; - t_empt->t_edges[i]->p_pars_l = t_full->t_edges[i]->p_pars_l; - t_empt->t_edges[i]->p_pars_r = t_full->t_edges[i]->p_pars_r; + for(i=0;in_otu;i++) + { + for(j=0;jn_otu;j++) + { + if(!(Are_Compatible(data->c_seq[i]->state+patt_num, + data->c_seq[j]->state+patt_num, + stepsize, + datatype))) + { + break; + } + } + if(j != data->n_otu) break; } + + if(i == data->n_otu) return 1; + else return 0; } -/*********************************************************/ -void Share_List_Of_Reachable_Tips_Struct(arbre *t_full, arbre *t_empt) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int Is_Ambigu(char *state, int datatype, int stepsize) { - int i; + int val,i; - For(i,2*t_full->n_otu-2) + val = -1; + if(datatype == NT) + { + for(i=0;inoeud[i]->list_of_reachable_tips = t_full->noeud[i]->list_of_reachable_tips; - t_empt->noeud[i]->n_of_reachable_tips = t_full->noeud[i]->n_of_reachable_tips; + int i; + for(i=0;in_otu); - printf("\n"); - - For(i,mat->n_otu) + for(j=0;jcrunch_len;j++) { - For(j,13) - { - if(j>=(int)strlen(mat->name[i])) putchar(' '); - else putchar(mat->name[i][j]); - } - - For(j,mat->n_otu) - { - if(mat->dist[i][j] == -1) - printf(" - "); - else - printf("%7.8f ",mat->dist[i][j]); - } - printf("\n"); + data->ambigu[j] = NO; + for(i=0;in_otu;i++) + { + data->c_seq[i]->is_ambigu[j] = NO; + } + + for(i=0;in_otu;i++) + { + if(Is_Ambigu(data->c_seq[i]->state+j*stepsize, + datatype, + stepsize)) + { + data->ambigu[j] = YES; + data->c_seq[i]->is_ambigu[j] = YES; + } + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Sort_Edges_NNI_Score(arbre *tree, edge **sorted_edges, int n_elem) +void Set_D_States(calign *data, int datatype, int stepsize) { int i,j; - edge *buff; - For(i,n_elem-1) + for(j=0;jcrunch_len;j++) { - for(j=i+1;jnni->score < sorted_edges[i]->nni->score) - { - buff = sorted_edges[j]; - sorted_edges[j] = sorted_edges[i]; - sorted_edges[i] = buff; - } - } + for(i=0;in_otu;i++) + { + if(data->c_seq[i]->is_ambigu[j] == NO) + { + data->c_seq[i]->d_state[j] = Assign_State(data->c_seq[i]->state+j, + datatype, + stepsize); + } + } } - return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void NNI(arbre *tree, edge *b_fcus, int do_swap) +int Get_State_From_Ui(int ui, int datatype) { - int l_r, r_l, l_v1, l_v2, r_v3, r_v4; - node *v1,*v2,*v3,*v4; - phydbl lk0, lk1, lk2; - phydbl lk0_init, lk1_init, lk2_init; - phydbl bl_init; - phydbl l0,l1,l2; - phydbl l_infa, l_infb, l_max; -/* phydbl lk_infa, lk_infb, lk_max; */ - phydbl lk_init; - - bl_init = b_fcus->l; - lk_init = tree->c_lnL; - - b_fcus->nni->init_l = b_fcus->l; - b_fcus->nni->init_lk = tree->c_lnL;; - - b_fcus->nni->best_conf = 0; - b_fcus->nni->score = +1.0; - - lk0 = lk1 = lk2 = UNLIKELY; - v1 = v2 = v3 = v4 = NULL; - - l_r = r_l = l_v1 = l_v2 = r_v3 = r_v4 = -1; - - l_r = b_fcus->l_r; - r_l = b_fcus->r_l; - - v1 = b_fcus->left->v[b_fcus->l_v1]; - v2 = b_fcus->left->v[b_fcus->l_v2]; - v3 = b_fcus->rght->v[b_fcus->r_v1]; - v4 = b_fcus->rght->v[b_fcus->r_v2]; - - if(v1->num < v2->num) + if(datatype == NT) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + switch(ui) + { + case 1 : {return 0; break;} + case 2 : {return 1; break;} + case 4 : {return 2; break;} + case 8 : {return 3; break;} + default : + { + PhyML_Fprintf(stderr,"\n. ui=%d",ui); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + break; + } } - if(v3->num < v4->num) + } + else if(datatype == AA) + { + switch(ui) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + case 1 : {return 0; break;} + case 2 : {return 1; break;} + case 4 : {return 2; break;} + case 8 : {return 3; break;} + case 16 : {return 4; break;} + case 32 : {return 5; break;} + case 64 : {return 6; break;} + case 128 : {return 7; break;} + case 256 : {return 8; break;} + case 512 : {return 9; break;} + case 1024 : {return 10; break;} + case 2048 : {return 11; break;} + case 4096 : {return 12; break;} + case 8192 : {return 13; break;} + case 16384 : {return 14; break;} + case 32768 : {return 15; break;} + case 65536 : {return 16; break;} + case 131072 : {return 17; break;} + case 262144 : {return 18; break;} + case 524288 : {return 19; break;} + default : + { + PhyML_Fprintf(stderr,"\n. ui=%d",ui); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } } + } + else Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + return -1; +} - l0 = l1 = l2 = -1.; - - - /***********/ - Swap(v2,b_fcus->left,b_fcus->rght,v3,tree); - tree->both_sides = 1; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - lk1_init = Update_Lk_At_Given_Edge(b_fcus,tree); - l_infa = 10.*b_fcus->l; - l_max = b_fcus->l; - l_infb = BL_MIN; +int Assign_State(char *c, int datatype, int stepsize) +{ + int state[3]; + int i; - if(tree->mod->s_opt->fast_nni) + state[0] = state[1] = state[2] = -1; + if(datatype == NT) { - Fast_Br_Len(b_fcus,tree); - lk1 = Lk_At_Given_Edge(b_fcus,tree); + for(i=0;i1)?(state[0]*16+state[1]*4+state[2]):(state[0]); } - else + else if(datatype == AA) + { + switch(c[0]) { - lk1 = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus,tree, - tree->mod->s_opt->brent_it_max); + case 'A' : {state[0]=0 ; break;} + case 'R' : {state[0]=1 ; break;} + case 'N' : {state[0]=2 ; break;} + case 'D' : {state[0]=3 ; break;} + case 'C' : {state[0]=4 ; break;} + case 'Q' : {state[0]=5 ; break;} + case 'E' : {state[0]=6 ; break;} + case 'G' : {state[0]=7 ; break;} + case 'H' : {state[0]=8 ; break;} + case 'I' : {state[0]=9 ; break;} + case 'L' : {state[0]=10; break;} + case 'K' : {state[0]=11; break;} + case 'M' : {state[0]=12; break;} + case 'F' : {state[0]=13; break;} + case 'P' : {state[0]=14; break;} + case 'S' : {state[0]=15; break;} + case 'T' : {state[0]=16; break;} + case 'W' : {state[0]=17; break;} + case 'Y' : {state[0]=18; break;} + case 'V' : {state[0]=19; break;} + + case 'B' : {state[0] = 2; break;} + case 'Z' : {state[0] = 5; break;} + default : {state[0]=-1; break;} + } + return state[0]; } + else if(datatype == GENERIC) + { + char format[6]; + int ret; - if(lk1 < lk1_init - tree->mod->s_opt->min_diff_lk_local) + sprintf(format,"%%%dd",stepsize); + ret = sscanf(c,format,state); + if(!ret) state[0] = -1; + return state[0]; + } + else { - printf("%f %f %f %f\n",l_infa,l_max,l_infb,b_fcus->l); - printf("%f -- %f \n",lk1_init,lk1); - printf("\n. Err. in NNI (1)\n"); + PhyML_Printf("\n. Not implemented yet.\n"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); } - l1 = b_fcus->l; - Swap(v3,b_fcus->left,b_fcus->rght,v2,tree); - /***********/ - - - /***********/ - Swap(v2,b_fcus->left,b_fcus->rght,v4,tree); - b_fcus->l = bl_init; - tree->both_sides = 1; - - lk2_init = Update_Lk_At_Given_Edge(b_fcus,tree); + return -1; +} - l_infa = 10.*b_fcus->l; - l_max = b_fcus->l; - l_infb = BL_MIN; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if(tree->mod->s_opt->fast_nni) +char Reciproc_Assign_State(int i_state, int datatype) +{ + if(datatype == NT) { - Fast_Br_Len(b_fcus,tree); - lk2 = Lk_At_Given_Edge(b_fcus,tree); + i_state = i_state%4; + switch(i_state) + { + case 0 : {return 'A'; break;} + case 1 : {return 'C'; break;} + case 2 : {return 'G'; break;} + case 3 : {return 'T'; break;} + default : + { + PhyML_Printf("\n. i_state = %d",i_state); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + break; + } + } } - else + else if(datatype == AA) { - lk2 = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus,tree, - tree->mod->s_opt->brent_it_max); + i_state = i_state%20; + switch(i_state) + { + case 0 : {return 'A' ; break;} + case 1 : {return 'R' ; break;} + case 2 : {return 'N' ; break;} + case 3 : {return 'D' ; break;} + case 4 : {return 'C' ; break;} + case 5 : {return 'Q' ; break;} + case 6 : {return 'E' ; break;} + case 7 : {return 'G' ; break;} + case 8 : {return 'H' ; break;} + case 9 : {return 'I' ; break;} + case 10 : {return 'L'; break;} + case 11 : {return 'K'; break;} + case 12 : {return 'M'; break;} + case 13 : {return 'F'; break;} + case 14 : {return 'P'; break;} + case 15 : {return 'S'; break;} + case 16 : {return 'T'; break;} + case 17 : {return 'W'; break;} + case 18 : {return 'Y'; break;} + case 19 : {return 'V'; break;} + default : + { + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + break; + } + } } - - if(lk2 < lk2_init - tree->mod->s_opt->min_diff_lk_local) + else if(datatype == GENERIC) { - printf("%f %f %f %f\n",l_infa,l_max,l_infb,b_fcus->l); - printf("%f -- %f \n",lk2_init,lk2); - printf("\n. Err. in NNI (2)\n"); - } + return i_state + '0'; + } + return -1; +} - l2 = b_fcus->l; - Swap(v4,b_fcus->left,b_fcus->rght,v2,tree); - /***********/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +int Assign_State_With_Ambiguity(char *c, int datatype, int stepsize) +{ + int state[3]; + int i; - /***********/ - b_fcus->l = bl_init; - tree->both_sides = 1; + state[0] = state[1] = state[2] = -1; + if(datatype == NT) + { + for(i=0;i1)?(state[0]*16+state[1]*4+state[2]):(state[0]); + } + } + else if(datatype == AA) + { + switch(c[0]) + { + case 'A' : {state[0]= 0; break;} + case 'R' : {state[0]= 1; break;} + case 'N' : {state[0]= 2; break;} + case 'D' : {state[0]= 3; break;} + case 'C' : {state[0]= 4; break;} + case 'Q' : {state[0]= 5; break;} + case 'E' : {state[0]= 6; break;} + case 'G' : {state[0]= 7; break;} + case 'H' : {state[0]= 8; break;} + case 'I' : {state[0]= 9; break;} + case 'L' : {state[0]=10; break;} + case 'K' : {state[0]=11; break;} + case 'M' : {state[0]=12; break;} + case 'F' : {state[0]=13; break;} + case 'P' : {state[0]=14; break;} + case 'S' : {state[0]=15; break;} + case 'T' : {state[0]=16; break;} + case 'W' : {state[0]=17; break;} + case 'Y' : {state[0]=18; break;} + case 'V' : {state[0]=19; break;} + case 'B' : {state[0]= 2; break;} + case 'Z' : {state[0]= 5; break;} + case 'X' : case '?' : case '-' : {state[0]=T_MAX_ALPHABET-1; break;} + default : + { + PhyML_Printf("\n. Unknown character state : '%c'\n",state[0]); + Warn_And_Exit("\n. Init failed (data type supposed to be amino-acids)\n"); + break; + } + } + return state[0]; + } + else if(datatype == GENERIC) + { + if(Is_Ambigu(c,GENERIC,stepsize)) state[0] = T_MAX_ALPHABET-1; + else + { + char format[6]; + sprintf(format,"%%%dd",stepsize); + if(!sscanf(c,format,state)) + { + PhyML_Printf("\n. Error reading character. Was expecting an integer, got '%c' instead.\n",c[0]); + PhyML_Printf("\n. Err. in file %s at line %d (function '%s')\n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } + } + return state[0]; + } + + return -1; +} - lk0_init = Update_Lk_At_Given_Edge(b_fcus,tree); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if(fabs(lk0_init - lk_init) > tree->mod->s_opt->min_diff_lk_local) - { - printf("\n. lk_init = %f; lk = %f diff = %f\n", - lk_init, - lk0_init, - lk_init-lk0_init); - printf("\n. Curr_lnL = %f\n",Return_Lk(tree)); - Warn_And_Exit("\n. Err. in NNI (3)\n"); - } +void Clean_Tree_Connections(t_tree *tree) +{ - l_infa = 10.*b_fcus->l; - l_max = b_fcus->l; - l_infb = BL_MIN; + int i; + For(i,2*tree->n_otu-2) + { + tree->a_nodes[i]->v[0] = NULL; + tree->a_nodes[i]->v[1] = NULL; + tree->a_nodes[i]->v[2] = NULL; + tree->a_nodes[i]->b[0] = NULL; + tree->a_nodes[i]->b[1] = NULL; + tree->a_nodes[i]->b[2] = NULL; + } +} - if(tree->mod->s_opt->fast_nni) - { - Fast_Br_Len(b_fcus,tree); - lk0 = Lk_At_Given_Edge(b_fcus,tree); - } - else - { - lk0 = Br_Len_Brent(l_infa,l_max,l_infb, - tree->mod->s_opt->min_diff_lk_local, - b_fcus,tree, - tree->mod->s_opt->brent_it_max); - } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if(lk0 < lk_init - tree->mod->s_opt->min_diff_lk_local) - { - printf("\n\n%f %f %f %f\n",l_infa,l_max,l_infb,b_fcus->l); - printf("%f -- %f \n",lk0_init,lk0); - printf("\n. Err. in NNI (3)\n"); - Warn_And_Exit("\n"); - } +/* + if tbe_bootstrap == 0 => Classical FBP (Felsenstein bootstrap proportions) + else => TBE (Transfer bootstrap expectation) +*/ +void Bootstrap(t_tree *tree) +{ + int *site_num, n_site; + int replicate,j,k; + int position,init_len; + calign *boot_data; + t_tree *boot_tree; + t_mod *boot_mod; + matrix *boot_mat; + char *s; +/* phydbl rf; */ - l0 = b_fcus->l; - /***********/ - b_fcus->nni->lk0 = lk0; - b_fcus->nni->lk1 = lk1; - b_fcus->nni->lk2 = lk2; + if(tree->is_mixt_tree == YES) + { + PhyML_Printf("\n. Bootstrap option not yet available for partition/mixture analysis."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } - b_fcus->nni->l0 = l0; - b_fcus->nni->l1 = l1; - b_fcus->nni->l2 = l2; - b_fcus->nni->score = lk0 - MAX(lk1,lk2); + tree->io->print_support_val = YES; + + boot_tree = NULL; - if((b_fcus->nni->score < tree->mod->s_opt->min_diff_lk_local) && - (b_fcus->nni->score > -tree->mod->s_opt->min_diff_lk_local)) - { - b_fcus->nni->score = .0; - b_fcus->nni->lk1 = b_fcus->nni->lk0; - b_fcus->nni->lk2 = b_fcus->nni->lk0; - } + site_num = (int *)mCalloc(tree->data->init_len,sizeof(int)); - if(lk0 > MAX(lk1,lk2)) - { - b_fcus->nni->best_conf = 0; - b_fcus->nni->best_l = l0; - b_fcus->nni->swap_node_v1 = NULL; - b_fcus->nni->swap_node_v2 = NULL; - b_fcus->nni->swap_node_v3 = NULL; - b_fcus->nni->swap_node_v4 = NULL; + Free_Bip(tree); + Alloc_Bip(tree); + Get_Bip(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + + n_site = 0; + for(j=0;jdata->crunch_len;j++) + for(k=0;kdata->wght[j];++k) + { + site_num[n_site] = j; + n_site++; } - else if(lk1 > MAX(lk0,lk2)) - { - b_fcus->nni->best_conf = 1; - b_fcus->nni->best_l = l1; - b_fcus->nni->swap_node_v1 = v2; - b_fcus->nni->swap_node_v2 = b_fcus->left; - b_fcus->nni->swap_node_v3 = b_fcus->rght; - b_fcus->nni->swap_node_v4 = v3; - } - else if(lk2 > MAX(lk0,lk1)) - { - b_fcus->nni->best_conf = 2; - b_fcus->nni->best_l = l2; - b_fcus->nni->swap_node_v1 = v2; - b_fcus->nni->swap_node_v2 = b_fcus->left; - b_fcus->nni->swap_node_v3 = b_fcus->rght; - b_fcus->nni->swap_node_v4 = v4; - } - else - { - b_fcus->nni->score = +1.0; - b_fcus->nni->best_conf = 0; - b_fcus->nni->best_l = l0; - b_fcus->nni->swap_node_v1 = NULL; - b_fcus->nni->swap_node_v2 = NULL; - b_fcus->nni->swap_node_v3 = NULL; - b_fcus->nni->swap_node_v4 = NULL; - } - if((do_swap) && ((lk1 > lk0) || (lk2 > lk0))) - { - tree->n_swap++; - printf("Swap edge %d -> %f\n",b_fcus->num,MAX(lk1,lk2)); - - if(lk1 > lk2) - { - tree->best_lnL = lk1; - Swap(v2,b_fcus->left,b_fcus->rght,v3,tree); - b_fcus->l = l1; - tree->both_sides = 1; - Lk(tree); - } - else - { - tree->best_lnL = lk2; - Swap(v2,b_fcus->left,b_fcus->rght,v4,tree); - b_fcus->l = l2; - tree->both_sides = 1; - Lk(tree); - } - } - else - { - b_fcus->l = bl_init; - Update_PMat_At_Given_Edge(b_fcus,tree); - tree->c_lnL = lk_init; - } -} + boot_data = Copy_Cseq(tree->data,tree->io); + + PhyML_Printf("\n\n. Non parametric bootstrap analysis \n\n"); + PhyML_Printf(" ["); -/*********************************************************/ + for(replicate=0;replicateio->n_boot_replicates;replicate++) + { + for(j=0;jcrunch_len;j++) boot_data->wght[j] = 0; -void NNI_Pars(arbre *tree, edge *b_fcus, int do_swap) -{ - int l_r, r_l, l_v1, l_v2, r_v3, r_v4; - node *v1,*v2,*v3,*v4; - int pars0, pars1, pars2; - int pars_init; + init_len = 0; + for(j=0;jinit_len;j++) + { + position = Rand_Int(0,(int)(tree->data->init_len-1.0)); + boot_data->wght[site_num[position]] += 1; + init_len++; + } - pars_init = tree->c_pars; - b_fcus->nni->best_conf = 0; - b_fcus->nni->score = +1.0; + if(init_len != tree->data->init_len) Exit("\n. Pb. when copying sequences\n"); - pars0 = pars1 = pars2 = 0; - v1 = v2 = v3 = v4 = NULL; + init_len = 0; + for(j=0;jcrunch_len;j++) init_len += boot_data->wght[j]; - l_r = r_l = l_v1 = l_v2 = r_v3 = r_v4 = -1; + + if(init_len != tree->data->init_len) Exit("\n. Pb. when copying sequences\n"); - l_r = b_fcus->l_r; - r_l = b_fcus->r_l; + + if(tree->io->datatype == NT) Get_Base_Freqs(boot_data); + else if(tree->io->datatype == AA) Get_AA_Freqs(boot_data); - v1 = b_fcus->left->v[b_fcus->l_v1]; - v2 = b_fcus->left->v[b_fcus->l_v2]; - v3 = b_fcus->rght->v[b_fcus->r_v1]; - v4 = b_fcus->rght->v[b_fcus->r_v2]; + if(tree->io->random_boot_seq_order) Randomize_Sequence_Order(boot_data); - if(v1->num < v2->num) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - if(v3->num < v4->num) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } + Set_D_States(boot_data,tree->io->datatype,tree->io->state_len); - - /***********/ - Swap(v2,b_fcus->left,b_fcus->rght,v3,tree); - tree->both_sides = 1; - pars1 = Update_Pars_At_Given_Edge(b_fcus,tree); - Swap(v3,b_fcus->left,b_fcus->rght,v2,tree); - /***********/ + boot_mod = Copy_Model(tree->mod); - /***********/ - Swap(v2,b_fcus->left,b_fcus->rght,v4,tree); - tree->both_sides = 1; - pars2 = Update_Pars_At_Given_Edge(b_fcus,tree); - Swap(v4,b_fcus->left,b_fcus->rght,v2,tree); - /***********/ + boot_mod->s_opt = tree->mod->s_opt; /* WARNING: re-using the same address here instead of creating a copying + requires to leave the value of s_opt unchanged during the boostrap. */ + boot_mod->io = tree->io; /* WARNING: re-using the same address here instead of creating a copying + requires to leave the value of io unchanged during the boostrap. */ + Init_Model(boot_data,boot_mod,tree->io); - /***********/ - tree->both_sides = 1; - pars0 = Update_Pars_At_Given_Edge(b_fcus,tree); - - if(pars0 != pars_init) - { - printf("\n. pars_init = %d; pars0 = %d\n", - pars_init, - pars0); - Warn_And_Exit("\n. Err. in NNI (3)\n"); - } - /***********/ + if(tree->io->in_tree == 2) + { + rewind(tree->io->fp_in_tree); + boot_tree = Read_Tree_File_Phylip(tree->io->fp_in_tree); + Remove_Duplicates_From_Tree(boot_data,boot_tree); + } + else + { + boot_mat = ML_Dist(boot_data,boot_mod); + boot_mat->tree = Make_Tree_From_Scratch(boot_data->n_otu,boot_data); + Fill_Missing_Dist(boot_mat); + Bionj(boot_mat); + boot_tree = boot_mat->tree; + boot_tree->mat = boot_mat; + } - tree->c_pars = pars0; + boot_tree->mod = boot_mod; + boot_tree->io = tree->io; + boot_tree->data = boot_data; + boot_tree->verbose = VL0; + boot_tree->n_pattern = boot_tree->data->crunch_len; + boot_tree->io->print_site_lnl = NO; + boot_tree->io->print_trace = NO; + boot_tree->io->print_json_trace = NO; + boot_tree->n_root = NULL; + boot_tree->e_root = NULL; - b_fcus->nni->score = MIN(pars1,pars2) - pars0; + Set_Both_Sides(YES,boot_tree); - if(pars0 < MIN(pars1,pars2)) - { - b_fcus->nni->best_conf = 0; - b_fcus->nni->swap_node_v1 = NULL; - b_fcus->nni->swap_node_v2 = NULL; - b_fcus->nni->swap_node_v3 = NULL; - b_fcus->nni->swap_node_v4 = NULL; - } - else if(pars1 < MIN(pars0,pars2)) - { - b_fcus->nni->best_conf = 1; - b_fcus->nni->swap_node_v1 = v2; - b_fcus->nni->swap_node_v2 = b_fcus->left; - b_fcus->nni->swap_node_v3 = b_fcus->rght; - b_fcus->nni->swap_node_v4 = v3; - } - else if(pars2 > MIN(pars0,pars1)) - { - b_fcus->nni->best_conf = 2; - b_fcus->nni->swap_node_v1 = v2; - b_fcus->nni->swap_node_v2 = b_fcus->left; - b_fcus->nni->swap_node_v3 = b_fcus->rght; - b_fcus->nni->swap_node_v4 = v4; - } - else - { - b_fcus->nni->score = +1.0; - b_fcus->nni->swap_node_v1 = NULL; - b_fcus->nni->swap_node_v2 = NULL; - b_fcus->nni->swap_node_v3 = NULL; - b_fcus->nni->swap_node_v4 = NULL; - } -} + if((boot_tree->mod->s_opt->random_input_tree) && (boot_tree->mod->s_opt->topo_search == SPR_MOVE)) Random_Tree(boot_tree); + + Connect_CSeqs_To_Nodes(boot_data,tree->io,boot_tree); -/*********************************************************/ + /* Make_Tree_For_Pars(boot_tree); */ + /* Make_Tree_For_Lk(boot_tree); */ + /* Make_Spr(boot_tree); */ -void Swap(node *a, node *b, node *c, node *d, arbre *tree) -{ - int ab, ba, cd, dc, bc; - int i; + Check_Br_Lens(boot_tree); + Share_Lk_Struct(tree,boot_tree); + Share_Spr_Struct(tree,boot_tree); + Share_Pars_Struct(tree,boot_tree); + Update_Dirs(boot_tree); + Init_Partial_Lk_Tips_Double(boot_tree); + Init_Ui_Tips(boot_tree); + Init_Partial_Pars_Tips(boot_tree); + Br_Len_Not_Involving_Invar(boot_tree); + + if(boot_tree->io->do_alias_subpatt) + { + MIXT_Set_Alias_Subpatt(YES,boot_tree); + Lk(NULL,boot_tree); + MIXT_Set_Alias_Subpatt(NO,boot_tree); + } - /* \ /d \ /a - * \ / \ / - * \b__...__c/ -> \b__...__c/ - * / \ / \ - * / \ / \ - * /a \ /d \ - * - * nodes b and c are not necessarily on the same branch - */ + Set_Update_Eigen(YES,boot_tree->mod); + Lk(NULL,boot_tree); + Set_Update_Eigen(NO,boot_tree->mod); + if(boot_tree->mod->s_opt->opt_topo) + { + Global_Spr_Search(boot_tree); + } + else + { + if(boot_tree->mod->s_opt->opt_subst_param || boot_tree->mod->s_opt->opt_bl) + Round_Optimize(boot_tree,ROUND_MAX); + else + Lk(NULL,boot_tree); + } -#ifdef DEBUG - if(!a || !b || !c || !d) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } -#endif + Free_Bip(boot_tree); + Alloc_Bip(boot_tree); + Match_Tip_Numbers(tree,boot_tree); + Get_Bip(boot_tree->a_nodes[0], + boot_tree->a_nodes[0]->v[0], + boot_tree); + if(tree->io->do_boot) Compare_Bip(tree,boot_tree,NO); + else if(tree->io->do_tbe) Compare_Bip_Distance(tree, boot_tree); + else assert(FALSE); - ab = ba = cd = dc = bc = -1; + Check_Br_Lens(boot_tree); + Br_Len_Involving_Invar(boot_tree); - For(i,3) if(a->v[i] == b) { ab = i; break; } - For(i,3) if(b->v[i] == a) { ba = i; break; } - For(i,3) if(c->v[i] == d) { cd = i; break; } - For(i,3) if(d->v[i] == c) { dc = i; break; } - For(i,3) if(b->v[i] == c) { bc = i; break; } + if(tree->io->print_boot_trees) + { + s = Write_Tree(boot_tree); + PhyML_Fprintf(tree->io->fp_out_boot_tree,"%s\n",s); + Free(s); + Print_Fp_Out_Lines(tree->io->fp_out_boot_stats,0,0,boot_tree,tree->io,replicate+1); + } -#ifdef DEBUG - if(ab < 0 || ba < 0 || cd < 0 || dc < 0) - { - printf("\n. Nodes %d %d %d %d\n",a->num,b->num,c->num,d->num); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } + + PhyML_Printf("."); +#ifndef QUIET + fflush(stdout); #endif + if(!((replicate+1)%tree->io->boot_prog_every)) + { + PhyML_Printf("] %4d/%4d\n ",replicate+1,tree->io->n_boot_replicates); + if(replicate != tree->io->n_boot_replicates-1) PhyML_Printf("["); + } - a->v[ab] = c; - d->v[dc] = b; - b->v[ba] = d; - c->v[cd] = a; - b->b[ba] = d->b[dc]; - c->b[cd] = a->b[ab]; + Free_Tree(boot_tree); + Free_Model(boot_mod); + } - (a->b[ab]->left == b)? - (a->b[ab]->left = c): - (a->b[ab]->rght = c); + if(((replicate)%tree->io->boot_prog_every)) PhyML_Printf("] %4d/%4d\n ",replicate,tree->io->n_boot_replicates); - (d->b[dc]->left == c)? - (d->b[dc]->left = b): - (d->b[dc]->rght = b); + tree->lock_topo = YES; /* Topology should not be modified afterwards */ - For(i,3) + if(tree->io->print_boot_trees) { - if(a->b[ab]->left->v[i] == a->b[ab]->rght) a->b[ab]->l_r = i; - if(a->b[ab]->rght->v[i] == a->b[ab]->left) a->b[ab]->r_l = i; - if(d->b[dc]->left->v[i] == d->b[dc]->rght) d->b[dc]->l_r = i; - if(d->b[dc]->rght->v[i] == d->b[dc]->left) d->b[dc]->r_l = i; + fclose(tree->io->fp_out_boot_tree); + fclose(tree->io->fp_out_boot_stats); } + Free_Calign(boot_data); + Free(site_num); +} - a->b[ab]->l_v1 = a->b[ab]->l_v2 = - a->b[ab]->r_v1 = a->b[ab]->r_v2 = - d->b[dc]->l_v1 = d->b[dc]->l_v2 = - d->b[dc]->r_v1 = d->b[dc]->r_v2 = -1; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +void Br_Len_Involving_Invar(t_tree *tree) +{ + int i; - For(i,3) + if(tree->is_mixt_tree) { - if(i != a->b[ab]->l_r) - { - if(a->b[ab]->l_v1 < 0) a->b[ab]->l_v1 = i; - else a->b[ab]->l_v2 = i; - } - if(i != a->b[ab]->r_l) - { - if(a->b[ab]->r_v1 < 0) a->b[ab]->r_v1 = i; - else a->b[ab]->r_v2 = i; - } - if(i != d->b[dc]->l_r) - { - if(d->b[dc]->l_v1 < 0) d->b[dc]->l_v1 = i; - else d->b[dc]->l_v2 = i; - } - if(i != d->b[dc]->r_l) - { - if(d->b[dc]->r_v1 < 0) d->b[dc]->r_v1 = i; - else d->b[dc]->r_v2 = i; - } + MIXT_Br_Len_Involving_Invar(tree); + return; } - Update_Dirs(tree); -} - -/*********************************************************/ -void Update_All_Partial_Lk(edge *b_fcus, arbre *tree) -{ - - Update_SubTree_Partial_Lk(b_fcus->left->b[b_fcus->l_v1], - b_fcus->left, - b_fcus->left->v[b_fcus->l_v1], - tree); - - Update_SubTree_Partial_Lk(b_fcus->left->b[b_fcus->l_v2], - b_fcus->left, - b_fcus->left->v[b_fcus->l_v2], - tree); - - Update_SubTree_Partial_Lk(b_fcus->rght->b[b_fcus->r_v1], - b_fcus->rght, - b_fcus->rght->v[b_fcus->r_v1], - tree); - - Update_SubTree_Partial_Lk(b_fcus->rght->b[b_fcus->r_v2], - b_fcus->rght, - b_fcus->rght->v[b_fcus->r_v2], - tree); - - tree->c_lnL = Lk_At_Given_Edge(b_fcus,tree); + For(i,2*tree->n_otu-1) tree->a_edges[i]->l->v *= (1.0-tree->mod->ras->pinvar->v); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Update_SubTree_Partial_Lk(edge *b_fcus, node *a, node *d, arbre *tree) +void Br_Len_Not_Involving_Invar(t_tree *tree) { int i; - Update_P_Lk(tree,b_fcus,a); - if(d->tax) return; - else For(i,3) if(d->v[i] != a) - Update_SubTree_Partial_Lk(d->b[i],d,d->v[i],tree); -} - -/*********************************************************/ - -allseq *Make_Cseq(int n_otu, int crunch_len, int init_len, char **sp_names) -{ - allseq *alldata; - int j; - - alldata = (allseq *)mCalloc(1,sizeof(allseq)); - alldata->n_otu = n_otu; - alldata->c_seq = (seq **)mCalloc(n_otu,sizeof(seq *)); - alldata->b_frq = (phydbl *)mCalloc(T_MAX_ALPHABET,sizeof(phydbl)); - alldata->wght = (int *)mCalloc(crunch_len,sizeof(int)); - alldata->ambigu = (short int *)mCalloc(crunch_len,sizeof(short int)); - alldata->invar = (short int *)mCalloc(crunch_len,sizeof(short int)); - alldata->sitepatt = (int *)mCalloc( init_len,sizeof(int )); - - alldata->crunch_len = crunch_len; - alldata->init_len = init_len; - alldata->obs_pinvar = .0; - - For(j,n_otu) + if(tree->is_mixt_tree) { - alldata->c_seq[j] = (seq *)mCalloc(1,sizeof(seq)); - alldata->c_seq[j]->name = (char *)mCalloc((int)(strlen(sp_names[j])+1),sizeof(char)); - strcpy(alldata->c_seq[j]->name,sp_names[j]); - alldata->c_seq[j]->state = (char *)mCalloc(crunch_len,sizeof(char)); - alldata->c_seq[j]->is_ambigu = (short int *)mCalloc(crunch_len,sizeof(short int)); + MIXT_Br_Len_Not_Involving_Invar(tree); + return; } - return alldata; -} - -/*********************************************************/ - -arbrelist *Make_Treelist(int list_size) -{ - arbrelist *tlist; - - tlist = (arbrelist *)mCalloc(1,sizeof(arbrelist)); - tlist->list_size = list_size; - tlist->tree = (arbre **)mCalloc(list_size,sizeof(arbre *)); - - return tlist; + For(i,2*tree->n_otu-1) tree->a_edges[i]->l->v /= (1.0-tree->mod->ras->pinvar->v); } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ -void Copy_Seq_Names_To_Tip_Labels(arbre *tree, allseq *data) +void Getstring_Stdin(char *s) { - int i; - For(i,tree->n_otu) - { - strcpy(tree->noeud[i]->name,data->c_seq[i]->name); - } + if(!fgets(s,T_MAX_LINE,stdin)) Exit(""); + if (strchr(s, '\n') != NULL) + *strchr(s, '\n') = '\0'; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -allseq *Copy_Cseq(allseq *ori, int len, int ns) +phydbl Num_Derivatives_One_Param(phydbl (*func)(t_tree *tree), t_tree *tree, + phydbl f0, phydbl *param, int which, int n_param, phydbl stepsize, int logt, + phydbl *err, int precise, int is_positive) { - allseq *new; - int i,j,n_otu; - char **sp_names; - - n_otu = ori->n_otu; + int i,j; + phydbl errt,fac,hh,**a,ans,*sign; + int n_iter; - sp_names = (char **)mCalloc(n_otu,sizeof(char *)); - For(i,n_otu) - { - sp_names[i] = (char *)mCalloc(strlen(ori->c_seq[i]->name)+1,sizeof(char)); - strcpy(sp_names[i],ori->c_seq[i]->name); - } + sign = (phydbl *)mCalloc(n_param,sizeof(phydbl)); - new = Make_Cseq(n_otu, len, ori->init_len, sp_names); + a = (phydbl **)mCalloc(11,sizeof(phydbl *)); + for(i=0;i<11;i++) a[i] = (phydbl *)mCalloc(11,sizeof(phydbl)); - new->obs_pinvar = ori->obs_pinvar; + n_iter = 10; /* */ - For(i,ori->init_len) new->sitepatt[i] = ori->sitepatt[i]; + ans = .0; - For(j,ori->crunch_len) - { - For(i,ori->n_otu) - { - new->c_seq[i]->state[j] = ori->c_seq[i]->state[j]; - new->c_seq[i]->is_ambigu[j] = ori->c_seq[i]->is_ambigu[j]; - } + if(stepsize < SMALL) Warn_And_Exit("\n. h must be nonzero in Dfridr."); - new->wght[j] = ori->wght[j]; - new->ambigu[j] = ori->ambigu[j]; - new->invar[j] = ori->invar[j]; - } + hh=stepsize; - For(i,ori->n_otu) + if(!precise) { - new->c_seq[i]->len = ori->c_seq[i]->len; - strcpy(new->c_seq[i]->name,ori->c_seq[i]->name); - } - - new->init_len = ori->init_len; - new->clean_len = ori->clean_len; - new->crunch_len = ori->crunch_len; - For(i,ns) new->b_frq[i] = ori->b_frq[i]; - new->n_otu = ori->n_otu; + param[which] = param[which]+hh; - For(i,n_otu) Free(sp_names[i]); - Free(sp_names); + if(logt == YES) for(i=0;i .0 ? 1. : -1.; + if(is_positive == YES) for(i=0;i .0 ? 1. : -1.; + if(is_positive == YES) for(i=0;i .0 ? 1. : -1.; + if(is_positive == YES) for(i=0;i= 2.0*(*err)) break; + } + } + for(i=0;i<11;i++) Free(a[i]); + Free(a); + Free(sign); + + return ans; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -FILE *Openfile(char *filename, int mode) +phydbl Num_Derivatives_One_Param_Nonaligned(phydbl (*func)(t_tree *tree), t_tree *tree, + phydbl f0, phydbl **param, int which, int n_param, phydbl stepsize, int logt, + phydbl *err, int precise, int is_positive) { - /* mode = 0 -> read */ - /* mode = 1 -> write */ - /* mode = 2 -> append */ - - FILE *fp; - char *s; - int open_test=0; - -/* s = (char *)mCalloc(T_MAX_FILE,sizeof(char)); */ - -/* strcpy(s,filename); */ - - s = filename; - - fp = NULL; - - switch(mode) - { - case 0 : - { - while(!(fp = (FILE *)fopen(s,"r")) && ++open_test<10) - { - printf("\n. Can't open file '%s', enter a new name : ",s); - Getstring_Stdin(s); - } - break; - } - case 1 : - { - fp = (FILE *)fopen(s,"w"); - break; - } - case 2 : - { - fp = (FILE *)fopen(s,"a"); - break; - } + int i,j; + phydbl errt,fac,hh,**a,ans,*sign; + int n_iter; - default : break; + sign = (phydbl *)mCalloc(n_param,sizeof(phydbl)); - } + a = (phydbl **)mCalloc(11,sizeof(phydbl *)); + for(i=0;i<11;i++) a[i] = (phydbl *)mCalloc(11,sizeof(phydbl)); -/* Free(s); */ + n_iter = 10; /* */ - return fp; -} + ans = .0; -/*********************************************************/ + if(stepsize < SMALL) Warn_And_Exit("\n. h must be nonzero in Dfridr."); -void Print_Fp_Out(FILE *fp_out, time_t t_beg, time_t t_end, arbre *tree, option *io, int n_data_set, int num_tree) -{ - char *s; - div_t hour,min; + hh=stepsize; - if((!n_data_set) || (!num_tree)) + if(!precise) { - Print_Banner(fp_out); - } - - fprintf(fp_out,"\n\n"); - fprintf(fp_out,". Sequence file : %s\n", io->in_seq_file); + *(param[which]) = *(param[which])+hh; - fprintf(fp_out,". Data set : #%d\n",n_data_set); - - if(io->mod->s_opt->random_input_tree) - fprintf(fp_out,". Random init tree : #%d\n",num_tree+1); - else if(io->n_trees > 1) - fprintf(fp_out,". Starting tree number : #%d\n",num_tree+1); - - if(io->mod->s_opt->opt_topo) - fprintf(fp_out,". Tree search : %s",(io->mod->s_opt->topo_search == SPR_MOVE)?("SPRs"):("NNIs")); + if(logt == YES) for(i=0;i .0 ? 1. : -1.; + if(is_positive == YES) for(i=0;iin_tree) - { - strcat(strcat(strcat(s,"user tree ("),io->in_tree_file),")"); + ans = a[0][0]; } else { - if(!io->mod->s_opt->random_input_tree) - { - strcat(s,"BIONJ"); - } - else - { - strcat(s,"random tree"); - } - } - - fprintf(fp_out,". Initial tree : %s\n",s); - Free(s); - - (tree->mod->datatype == NT)? - (fprintf(fp_out,". Model of nucleotides substitution : %s\n",io->mod->modelname)): - (fprintf(fp_out,". Model of amino acids substitution : %s\n",io->mod->modelname)); - - - - fprintf(fp_out,". Number of taxa : %d\n",tree->n_otu);/*added FLT*/ + *(param[which]) = *(param[which])+hh; - fprintf(fp_out,". Log-likelihood : %.5f\n",tree->c_lnL);/*was last ; moved here FLT*/ - - fprintf(fp_out,". Discrete gamma model : %s\n", - (tree->mod->n_catg>1)?("Yes"):("No")); - if(tree->mod->n_catg > 1) - { - fprintf(fp_out," - Number of categories : %d\n",tree->mod->n_catg); - fprintf(fp_out," - Gamma shape parameter : %.3f\n",tree->mod->alpha); - } + if(logt == YES) for(i=0;i .0 ? 1. : -1.; + if(is_positive == YES) for(i=0;imod->invar) fprintf(fp_out,". Proportion of invariant : %.3f\n",tree->mod->pinvar); + /* *(param[which]) = *(param[which])-2*hh; */ + /* a[0][0] -= (*func)(tree); */ + /* a[0][0] /= (2.0*hh); */ + /* *(param[which]) = *(param[which])+hh; */ - /*was before Discrete gamma model ; moved here FLT*/ - if((tree->mod->whichmodel == K80) || - (tree->mod->whichmodel == HKY85) || - (tree->mod->whichmodel == F84)) - fprintf(fp_out,". Transition/transversion ratio : %.3f\n",tree->mod->kappa); - else if(tree->mod->whichmodel == TN93) - { - fprintf(fp_out,". Transition/transversion ratio for purines : %.3f\n", - tree->mod->kappa*2.*tree->mod->lambda/(1.+tree->mod->lambda)); - fprintf(fp_out,". Transition/transversion ratio for pyrimidines : %.3f\n", - tree->mod->kappa*2./(1.+tree->mod->lambda)); - } + a[0][0] -= f0; + a[0][0] /= hh; + *(param[which]) = *(param[which])-hh; - if(tree->mod->datatype == NT) - { - fprintf(fp_out,". Nucleotides frequencies :\n"); - fprintf(fp_out," - f(A)=%8.5f\n",tree->mod->pi[0]); - fprintf(fp_out," - f(C)=%8.5f\n",tree->mod->pi[1]); - fprintf(fp_out," - f(G)=%8.5f\n",tree->mod->pi[2]); - fprintf(fp_out," - f(T)=%8.5f\n",tree->mod->pi[3]); + *err=1e30; + for(i=1;i .0 ? 1. : -1.; + if(is_positive == YES) for(i=0;i= 2.0*(*err)) break; + } } + for(i=0;i<11;i++) Free(a[i]); + Free(a); + Free(sign); + return ans; +} - /*****************************************/ - if((tree->mod->whichmodel == GTR) || - (tree->mod->whichmodel == CUSTOM)) - { - int i,j; - - Update_Qmat_GTR(tree->mod->rr, - tree->mod->rr_val, - tree->mod->rr_num, - tree->mod->pi, - tree->mod->qmat); - - printf("\n"); - fprintf(fp_out,". GTR relative rate parameters : \n\n"); - fprintf(fp_out,"A <-> C %8.5f\n", tree->mod->rr[0]); - fprintf(fp_out,"A <-> G %8.5f\n", tree->mod->rr[1]); - fprintf(fp_out,"A <-> T %8.5f\n", tree->mod->rr[2]); - fprintf(fp_out,"C <-> G %8.5f\n", tree->mod->rr[3]); - fprintf(fp_out,"C <-> T %8.5f\n", tree->mod->rr[4]); - fprintf(fp_out,"G <-> T %8.5f\n\n",tree->mod->rr[5]); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +int Num_Derivative_Several_Param(t_tree *tree, phydbl *param, int n_param, phydbl stepsize, int logt, + phydbl (*func)(t_tree *tree), phydbl *derivatives, int is_positive) +{ + int i; + phydbl err,f0,*sign; - fprintf(fp_out,"\n. Instantaneous rate matrix : \n"); - fprintf(fp_out,"\n[A---------C---------G---------T------]\n"); - For(i,4) - { - For(j,4) - fprintf(fp_out,"%8.5f ",tree->mod->qmat[i*4+j]); - fprintf(fp_out,"\n"); - } - fprintf(fp_out,"\n"); - } - /*****************************************/ + sign = (phydbl *)mCalloc(n_param,sizeof(phydbl)); + if(logt == YES) for(i=0;i .0 ? 1. : -1.; + if(is_positive == YES) for(i=0;iratio_test == 1) - { - fprintf(fp_out,". aLRT statistics to test branches"); - } - else if(io->ratio_test == 2) + for(i=0;imod->r_mat->n_diff_rr;j++) PhyML_Printf("\n. 00%d %f",i,tree->mod->r_mat->rr_val->v[j]); */ + derivatives[i] = Num_Derivatives_One_Param(func, + tree, + f0, + param, + i, + n_param, + stepsize, + logt, + &err, + NO, + is_positive + ); } + + Free(sign); - - hour = div(t_end-t_beg,3600); - min = div(t_end-t_beg,60 ); - - min.quot -= hour.quot*60; - - fprintf(fp_out,". Time used %dh%dm%ds\n", hour.quot,min.quot,(int)(t_end-t_beg)%60); - if(t_end-t_beg > 60) - fprintf(fp_out,". -> %d seconds\n",(int)(t_end-t_beg)); - - fprintf(fp_out," oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); - + return 1; } -/*********************************************************/ -/*FLT wrote this function*/ -void Print_Fp_Out_Lines(FILE *fp_out, time_t t_beg, time_t t_end, arbre *tree, option *io, int n_data_set) -{ - char *s; - /*div_t hour,min;*/ - - if (n_data_set==1) - { - - fprintf(fp_out,". Sequence file : [%s]\n\n", io->in_seq_file); - - (tree->mod->datatype == NT)? - (fprintf(fp_out,". Model of nucleotides substitution : %s\n\n",io->mod->modelname)): - (fprintf(fp_out,". Model of amino acids substitution : %s\n\n",io->mod->modelname)); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - s = (char *)mCalloc(T_MAX_LINE,sizeof(char)); - fprintf(fp_out,". Initial tree : [%s]\n\n", - (!io->in_tree)?("BIONJ"): - (strcat(strcat(strcat(s,"user tree ("),io->in_tree_file),")"))); - Free(s); - - fprintf(fp_out,"\n"); +int Num_Derivative_Several_Param_Nonaligned(t_tree *tree, phydbl **param, int n_param, phydbl stepsize, int logt, + phydbl (*func)(t_tree *tree), phydbl *derivatives, int is_positive) +{ + int i; + phydbl err,f0,*sign; - /*headline 1*/ - fprintf(fp_out, ". Data\t"); + sign = (phydbl *)mCalloc(n_param,sizeof(phydbl)); - fprintf(fp_out,"Nb of \t"); + if(logt == YES) for(i=0;i .0 ? 1. : -1.; + if(is_positive == YES) for(i=0;imod->n_catg > 1) - fprintf(fp_out, "Number of \tGamma shape\t"); + derivatives[i] = Num_Derivatives_One_Param_Nonaligned(func, + tree, + f0, + param, + i, + n_param, + stepsize, + logt, + &err, + 0, + is_positive + ); + } - fprintf(fp_out,"Proportion of\t"); + Free(sign); - if(tree->mod->whichmodel <= 6) - fprintf(fp_out,"Transition/ \t"); + return 1; +} - fprintf(fp_out,"Nucleotides frequencies \t"); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if((tree->mod->whichmodel == GTR) || - (tree->mod->whichmodel == CUSTOM)) - fprintf(fp_out,"Instantaneous rate matrix \t"); - /* fprintf(fp_out,"Time\t");*/ +int Compare_Two_States(char *state1, char *state2, int state_size) +{ - fprintf(fp_out, "\n"); + /* 1 the two states are identical */ + /* 0 the two states are different */ + int i; + for(i=0;imod->n_catg > 1) - fprintf(fp_out, "categories\tparameter \t"); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - fprintf(fp_out,"invariant \t"); +void Copy_Dist(phydbl **cpy, phydbl **orig, int n) +{ + int i,j; + for(i=0;imod->whichmodel <= 6) - fprintf(fp_out,"transversion\t"); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - fprintf(fp_out,"f(A) f(C) f(G) f(T) \t"); +t_mod *Copy_Model(t_mod *ori) +{ + t_mod *cpy; - if((tree->mod->whichmodel == GTR) || - (tree->mod->whichmodel == CUSTOM)) - fprintf(fp_out,"[A---------C---------G---------T------]\t"); + cpy = Make_Model_Basic(); - /* fprintf(fp_out,"used\t");*/ + cpy->ns = ori->ns; + cpy->ras->n_catg = ori->ras->n_catg; + cpy->whichmodel = ori->whichmodel; + cpy->io = ori->io; + + Make_Model_Complete(cpy); + Record_Model(ori,cpy); - fprintf(fp_out, "\n"); +#ifdef BEAGLE + cpy->b_inst = ori->b_inst; + cpy->optimizing_topology = ori->optimizing_topology; +#endif + return cpy; +} - /*headline 3*/ - if(tree->mod->whichmodel == TN93) - { - fprintf(fp_out," \t \t \t \t"); - if(tree->mod->n_catg > 1) fprintf(fp_out," \t \t"); - fprintf(fp_out," \t"); - fprintf(fp_out,"purines pyrimid.\t"); - fprintf(fp_out, "\n"); - } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - fprintf(fp_out, "\n"); - } +void Record_Model(t_mod *ori, t_mod *cpy) +{ + int i; + cpy->ns = ori->ns; + cpy->ras->n_catg = ori->ras->n_catg; + cpy->ras->normalise_rr = ori->ras->normalise_rr; + cpy->l_var_sigma = ori->l_var_sigma; - /*line items*/ + cpy->kappa->v = ori->kappa->v; + cpy->ras->alpha->v = ori->ras->alpha->v; + cpy->lambda->v = ori->lambda->v; + cpy->ras->pinvar->v = ori->ras->pinvar->v; + cpy->br_len_mult->v = ori->br_len_mult->v; - fprintf(fp_out," #%d\t",n_data_set); + strcpy(cpy->modelname->s,ori->modelname->s); + strcpy(cpy->custom_mod_string->s,ori->custom_mod_string->s); - fprintf(fp_out,"%d \t",tree->n_otu); + cpy->mod_num = ori->mod_num; + cpy->whichmodel = ori->whichmodel; + cpy->update_eigen = ori->update_eigen; + cpy->ras->invar = ori->ras->invar; + cpy->r_mat->n_diff_rr = ori->r_mat->n_diff_rr; + cpy->l_min = ori->l_min; + cpy->l_max = ori->l_max; + cpy->log_l = ori->log_l; + cpy->ras->free_mixt_rates = ori->ras->free_mixt_rates; + cpy->ras->gamma_median = ori->ras->gamma_median; - fprintf(fp_out,"%.5f\t",tree->c_lnL); - fprintf(fp_out,"%s \t", - (tree->mod->n_catg>1)?("Yes"):("No ")); - if(tree->mod->n_catg > 1) + if((ori->whichmodel == CUSTOM) || (ori->whichmodel == GTR)) { - fprintf(fp_out,"%d \t",tree->mod->n_catg); - fprintf(fp_out,"%.3f \t",tree->mod->alpha); + For(i,ori->ns*(ori->ns-1)/2) + { + cpy->r_mat->rr_num->v[i] = ori->r_mat->rr_num->v[i]; + cpy->r_mat->rr_val->v[i] = ori->r_mat->rr_val->v[i]; + cpy->r_mat->rr->v[i] = ori->r_mat->rr->v[i]; + cpy->r_mat->n_rr_per_cat->v[i] = ori->r_mat->n_rr_per_cat->v[i]; + } } - - /*if(tree->mod->invar)*/ - fprintf(fp_out,"%.3f \t",tree->mod->pinvar); - - if(tree->mod->whichmodel <= 5) + + for(i=0;ins;i++) { - fprintf(fp_out,"%.3f \t",tree->mod->kappa); + cpy->e_frq->pi->v[i] = ori->e_frq->pi->v[i]; + cpy->e_frq->pi_unscaled->v[i] = ori->e_frq->pi_unscaled->v[i]; + cpy->e_frq->user_b_freq->v[i] = ori->e_frq->user_b_freq->v[i]; } - else if(tree->mod->whichmodel == TN93) + + For(i,cpy->ns*cpy->ns) cpy->r_mat->qmat->v[i] = ori->r_mat->qmat->v[i]; + + for(i=0;iras->n_catg;i++) { - fprintf(fp_out,"%.3f ", - tree->mod->kappa*2.*tree->mod->lambda/(1.+tree->mod->lambda)); - fprintf(fp_out,"%.3f\t", - tree->mod->kappa*2./(1.+tree->mod->lambda)); + cpy->ras->gamma_r_proba->v[i] = ori->ras->gamma_r_proba->v[i]; + cpy->ras->gamma_rr->v[i] = ori->ras->gamma_rr->v[i]; + cpy->ras->gamma_r_proba_unscaled->v[i] = ori->ras->gamma_r_proba_unscaled->v[i]; + cpy->ras->gamma_rr_unscaled->v[i] = ori->ras->gamma_rr_unscaled->v[i]; } + + cpy->use_m4mod = ori->use_m4mod; + + cpy->eigen->size = ori->eigen->size; + For(i,2*ori->ns) cpy->eigen->space[i] = ori->eigen->space[i]; + For(i,2*ori->ns) cpy->eigen->space_int[i] = ori->eigen->space_int[i]; + for(i=0;ins;i++) cpy->eigen->e_val[i] = ori->eigen->e_val[i]; + for(i=0;ins;i++) cpy->eigen->e_val_im[i] = ori->eigen->e_val_im[i]; + For(i,ori->ns*ori->ns) cpy->eigen->r_e_vect[i] = ori->eigen->r_e_vect[i]; + For(i,ori->ns*ori->ns) cpy->eigen->r_e_vect[i] = ori->eigen->r_e_vect[i]; + For(i,ori->ns*ori->ns) cpy->eigen->r_e_vect_im[i] = ori->eigen->r_e_vect_im[i]; + For(i,ori->ns*ori->ns) cpy->eigen->l_e_vect[i] = ori->eigen->l_e_vect[i]; + For(i,ori->ns*ori->ns) cpy->eigen->q[i] = ori->eigen->q[i]; + +#ifdef BEAGLE + cpy->b_inst = ori->b_inst; + cpy->optimizing_topology = ori->optimizing_topology; +#endif + +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if(tree->mod->datatype == NT) - { - fprintf(fp_out,"%8.5f ",tree->mod->pi[0]); - fprintf(fp_out,"%8.5f ",tree->mod->pi[1]); - fprintf(fp_out,"%8.5f ",tree->mod->pi[2]); - fprintf(fp_out,"%8.5f\t",tree->mod->pi[3]); - } - /* - hour = div(t_end-t_beg,3600); - min = div(t_end-t_beg,60 ); - - min.quot -= hour.quot*60; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - fprintf(fp_out,"%dh%dm%ds\t", hour.quot,min.quot,(int)(t_end-t_beg)%60); - if(t_end-t_beg > 60) - fprintf(fp_out,". -> %d seconds\t",(int)(t_end-t_beg)); - */ +void Test_Node_Table_Consistency(t_tree *tree) +{ + int i; - /*****************************************/ - if((tree->mod->whichmodel == GTR) || (tree->mod->whichmodel == CUSTOM)) + For(i,2*tree->n_otu-2) { - int i,j; - - For(i,4) - { - if (i!=0) { - /*format*/ - fprintf(fp_out," \t \t \t \t"); - if(tree->mod->n_catg > 1) fprintf(fp_out," \t \t"); - fprintf(fp_out," \t \t"); - } - For(j,4) - fprintf(fp_out,"%8.5f ",tree->mod->qmat[i*4+j]); - if (i<3) fprintf(fp_out,"\n"); - } + if(tree->a_nodes[i]->num != i) + { + PhyML_Printf("\n. Node table is not consistent with node numbers."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } } - /*****************************************/ - - fprintf(fp_out, "\n\n"); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -matrix *K80_dist(allseq *data, phydbl g_shape) +void Get_Bip(t_node *a, t_node *d, t_tree *tree) { - int i,j,k; - int diff; - phydbl unc_len; - matrix *mat; - phydbl **len; - - len = (phydbl **)mCalloc(data->n_otu,sizeof(phydbl *)); - For(i,data->n_otu) - len[i] = (phydbl *)mCalloc(data->n_otu,sizeof(phydbl)); - - unc_len = .0; - - mat = Make_Mat(data->n_otu); - Init_Mat(mat,data); + int i,j; + t_node *tmp; + int swapped; + if(!d || !a || !tree) + { + PhyML_Printf("\n. d: %p a: %p tree: %p",d,a,tree); + PhyML_Printf("\n. Err. in file %s at line %d (function '%s').\n",__FILE__,__LINE__,__FUNCTION__); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } - For(i,data->c_seq[0]->len) + if(d->tax) { - For(j,data->n_otu-1) - { - for(k=j+1;kn_otu;k++) - { - if(((data->c_seq[j]->state[i] == 'A' || data->c_seq[j]->state[i] == 'G') && - (data->c_seq[k]->state[i] == 'C' || data->c_seq[k]->state[i] == 'T'))|| - ((data->c_seq[j]->state[i] == 'C' || data->c_seq[j]->state[i] == 'T') && - (data->c_seq[k]->state[i] == 'A' || data->c_seq[k]->state[i] == 'G'))) - { - diff++; - mat->Q[j][k]+=data->wght[i]; - len[j][k]+=data->wght[i]; - len[k][j]=len[j][k]; - } - - else - if(((data->c_seq[j]->state[i] == 'A' && data->c_seq[k]->state[i] == 'G') || - (data->c_seq[j]->state[i] == 'G' && data->c_seq[k]->state[i] == 'A'))|| - ((data->c_seq[j]->state[i] == 'C' && data->c_seq[k]->state[i] == 'T') || - (data->c_seq[j]->state[i] == 'T' && data->c_seq[k]->state[i] == 'C'))) - { - diff++; - mat->P[j][k]+=data->wght[i]; - len[j][k]+=data->wght[i]; - len[k][j]=len[j][k]; - } - else - if((data->c_seq[j]->state[i] == 'A' || - data->c_seq[j]->state[i] == 'C' || - data->c_seq[j]->state[i] == 'G' || - data->c_seq[j]->state[i] == 'T')&& - (data->c_seq[k]->state[i] == 'A' || - data->c_seq[k]->state[i] == 'C' || - data->c_seq[k]->state[i] == 'G' || - data->c_seq[k]->state[i] == 'T')) - { - len[j][k]+=data->wght[i]; - len[k][j]=len[j][k]; - } - } - } + if(d->common) + { + d->bip_node[0] = (t_node **)mCalloc(1,sizeof(t_node *)); + d->bip_node[0][0] = d; + d->bip_size[0] = 1; + d->bip_size[1] = -1; + d->bip_size[2] = -1; + + for(i=0;i<3;i++) + { + if(a->v[i] == d) + { + a->bip_size[i] = 0; + for(j=0;jn_otu;j++) + { + if(strcmp(tree->a_nodes[j]->name,d->name)) + { + a->bip_node[i] = (t_node **)realloc(a->bip_node[i],(a->bip_size[i]+1)*sizeof(t_node *)); + a->bip_node[i][a->bip_size[i]] = tree->a_nodes[j]; + a->bip_size[i]++; + } + } + + /* Sort bipartition */ + do + { + swapped = NO; + For(j,a->bip_size[i]-1) + { + if(a->bip_node[i][j]->num > a->bip_node[i][j+1]->num) + { + swapped = YES; + tmp = a->bip_node[i][j]; + a->bip_node[i][j] = a->bip_node[i][j+1]; + a->bip_node[i][j+1] = tmp; + } + } + }while(swapped == YES); + + + break; + + } + } + } + return; + } + else + { + int k; + int d_a; + + d_a = -1; + + for(i=0;i<3;i++) + { + if(d->v[i] != a) Get_Bip(d,d->v[i],tree); + else if(d->v[i] == a) d_a = i; + } + + d->bip_size[d_a] = 0; + for(i=0;i<3;i++) + if(d->v[i] != a) + { + for(j=0;j<3;j++) + { + if(d->v[i]->v[j] == d) + { + For(k,d->v[i]->bip_size[j]) + { + d->bip_node[d_a] = (t_node **)realloc(d->bip_node[d_a],(d->bip_size[d_a]+1)*sizeof(t_node *)); + d->bip_node[d_a][d->bip_size[d_a]] = d->v[i]->bip_node[j][k]; + d->bip_size[d_a]++; + } + break; + } + } + } + + do + { + swapped = NO; + For(j,d->bip_size[d_a]-1) + { + if(d->bip_node[d_a][j]->num > d->bip_node[d_a][j+1]->num) + { + swapped = YES; + tmp = d->bip_node[d_a][j]; + d->bip_node[d_a][j] = d->bip_node[d_a][j+1]; + d->bip_node[d_a][j+1] = tmp; + } + } + }while(swapped == YES); + + + for(i=0;i<3;i++) + if(a->v[i] == d) + { + a->bip_size[i] = 0; + for(j=0;jn_otu;j++) + { + For(k,d->bip_size[d_a]) + { + if(d->bip_node[d_a][k] == tree->a_nodes[j]) + break; + } + + if((k == d->bip_size[d_a]) && (tree->a_nodes[j]->common)) + { + a->bip_node[i] = (t_node **)realloc(a->bip_node[i],(a->bip_size[i]+1)*sizeof(t_node *)); + a->bip_node[i][a->bip_size[i]] = tree->a_nodes[j]; + a->bip_size[i]++; + } + } + + do + { + swapped = NO; + For(j,a->bip_size[i]-1) + { + if(a->bip_node[i][j]->num > a->bip_node[i][j+1]->num) + { + swapped = YES; + tmp = a->bip_node[i][j]; + a->bip_node[i][j] = a->bip_node[i][j+1]; + a->bip_node[i][j+1] = tmp; + } + } + }while(swapped == YES); + + if(a->bip_size[i] != tree->n_otu - d->bip_size[d_a]) + { + PhyML_Printf("%d %d \n",a->bip_size[i],tree->n_otu - d->bip_size[d_a]); + Warn_And_Exit("\n. Problem in counting bipartitions \n"); + } + break; + } } +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,data->n_otu-1) - for(j=i+1;jn_otu;j++) - { - if(len[i][j]) - { - mat->P[i][j] /= len[i][j]; - mat->Q[i][j] /= len[i][j]; - } - else - { - mat->P[i][j] = .5; - mat->Q[i][j] = .5; - } - - mat->P[j][i] = mat->P[i][j]; - mat->Q[j][i] = mat->Q[i][j]; - - - if((1-2*mat->P[i][j]-mat->Q[i][j] <= .0) || (1-2*mat->Q[i][j] <= .0)) - { - mat->dist[i][j] = -1.; - mat->dist[j][i] = -1.; - continue; - } - - mat->dist[i][j] = (g_shape/2)* - (pow(1-2*mat->P[i][j]-mat->Q[i][j],-1./g_shape) + - 0.5*pow(1-2*mat->Q[i][j],-1./g_shape) - 1.5); - - - if(mat->dist[i][j] > DIST_MAX) - { - mat->dist[i][j] = DIST_MAX; - } - mat->dist[j][i] = mat->dist[i][j]; - } +void Alloc_Bip(t_tree *tree) +{ + int i; - For(i,data->n_otu) free(len[i]); - free(len); - return mat; + if(tree->has_bip) return; + + tree->has_bip = YES; + + For(i,2*tree->n_otu-2) + { + tree->a_nodes[i]->bip_size = (int *)mCalloc(3,sizeof(int)); + tree->a_nodes[i]->bip_node = (t_node ***)mCalloc(3,sizeof(t_node **)); + } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -matrix *JC69_Dist(allseq *data, model *mod) +int *Order_Int(const int *u, const int n) { - int site,i,j,k; - phydbl unc_len; - matrix *mat; - phydbl **len; + unsigned int i,j; + int *v; + + v = (int *)mCalloc(n,sizeof(int)); + for(i=0;in_otu,sizeof(phydbl *)); - For(i,data->n_otu) - len[i] = (phydbl *)mCalloc(data->n_otu,sizeof(phydbl)); +} - unc_len = .0; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - mat = Make_Mat(data->n_otu); - Init_Mat(mat,data); +int *Order_Dbl(const phydbl *u, const int n) +{ + unsigned int i,j; + int *v; + + v = (int *)mCalloc(n,sizeof(int)); - Fors(site,data->c_seq[0]->len,mod->stepsize) + for(i=0;in_otu-1) - { - for(k=j+1;kn_otu;k++) - { - if((!Is_Ambigu(data->c_seq[j]->state+site,mod->datatype,mod->stepsize)) && - (!Is_Ambigu(data->c_seq[k]->state+site,mod->datatype,mod->stepsize))) - { - len[j][k]+=data->wght[site]; - len[k][j]=len[j][k]; - if(strncmp(data->c_seq[j]->state+site, - data->c_seq[k]->state+site, - mod->stepsize)) - mat->P[j][k]+=data->wght[site]; - } - } - } + v[i] = 0; + for(j=0;jn_otu-1) - for(j=i+1;jn_otu;j++) - { - if(len[i][j]) - { - mat->P[i][j] /= len[i][j]; - } - else - { - mat->P[i][j] = 1.; - } - - mat->P[j][i] = mat->P[i][j]; - - if((1.-(mod->ns)/(mod->ns-1.)*mat->P[i][j]) < .0) - { - mat->dist[i][j] = DIST_MAX; - } - else - mat->dist[i][j] = -(mod->ns-1.)/(mod->ns)*(phydbl)log(1.-(mod->ns)/(mod->ns-1.)*mat->P[i][j]); - - - if(mat->dist[i][j] > DIST_MAX) - { - mat->dist[i][j] = DIST_MAX; - } - mat->dist[j][i] = mat->dist[i][j]; - } +} - For(i,data->n_otu) free(len[i]); - free(len); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - return mat; +int Sort_Phydbl_Increase(const void *a, const void *b) +{ + if((*(phydbl *)(a)) <= (*(phydbl *)(b))) return -1; + else return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -matrix *Hamming_Dist(allseq *data, model *mod) +int Sort_String(const void *a, const void *b) { - int i,j,k; - phydbl unc_len; - matrix *mat; - phydbl **len; + return(strcmp((*(const char **)(a)), (*(const char **)(b)))); +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - len = (phydbl **)mCalloc(data->n_otu,sizeof(phydbl *)); - For(i,data->n_otu) - len[i] = (phydbl *)mCalloc(data->n_otu,sizeof(phydbl)); +int Compare_Bip(t_tree *tree1, t_tree *tree2, int on_existing_edges_only) +{ + int i,j,k; + t_edge *b1,*b2; +/* char **bip1,**bip2; */ +/* int *bip1,*bip2; */ + t_node **bip1, **bip2; + int bip_size1, bip_size2, bip_size; + int different,identical; + int n_edges; - unc_len = .0; - mat = Make_Mat(data->n_otu); - Init_Mat(mat,data); - For(i,data->c_seq[0]->len) + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ + /* WARNING: call Match_Tip_Numbers and Get_Bip before using this function. */ + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ + + if(on_existing_edges_only == YES) { - For(j,data->n_otu-1) - { - for(k=j+1;kn_otu;k++) - { - if((!Is_Ambigu(data->c_seq[j]->state+i,mod->datatype,mod->stepsize)) && - (!Is_Ambigu(data->c_seq[k]->state+i,mod->datatype,mod->stepsize))) - { - len[j][k]+=data->wght[i]; - len[k][j]=len[j][k]; - if(data->c_seq[j]->state[i] != data->c_seq[k]->state[i]) - mat->P[j][k]+=data->wght[i]; - } - } - } + n_edges = 0; + for(i=0;i<2*tree1->n_otu-3;++i) + if(tree1->a_edges[i]->does_exist && tree2->a_edges[i]->does_exist) n_edges++; + n_edges -= tree1->n_otu; + } + else + { + n_edges = tree1->n_otu-3; } - For(i,data->n_otu-1) - for(j=i+1;jn_otu;j++) - { - if(len[i][j]) - { - mat->P[i][j] /= len[i][j]; - } - else - { - mat->P[i][j] = 1.; - } - - mat->P[j][i] = mat->P[i][j]; - - mat->dist[i][j] = mat->P[i][j]; - - - if(mat->dist[i][j] > DIST_MAX) - { - mat->dist[i][j] = DIST_MAX; - } - mat->dist[j][i] = mat->dist[i][j]; - } + identical = 0; + different = 0; + for(i=0;i<2*tree1->n_otu-3;++i) + { + b1 = tree1->a_edges[i]; + bip_size1 = MIN(b1->left->bip_size[b1->l_r],b1->rght->bip_size[b1->r_l]); + - For(i,data->n_otu) free(len[i]); - free(len); + if(bip_size1 > 1 && ((on_existing_edges_only == YES && b1->does_exist) || (on_existing_edges_only == NO))) + { + for(j=0;j<2*tree2->n_otu-3;++j) + { + b2 = tree2->a_edges[j]; + bip_size2 = MIN(b2->left->bip_size[b2->l_r],b2->rght->bip_size[b2->r_l]); + + if(bip_size2 > 1 && ((on_existing_edges_only == YES && b2->does_exist) || (on_existing_edges_only == NO))) + { + if(bip_size1 == bip_size2) + { + bip_size = bip_size1; + + if(b1->left->bip_size[b1->l_r] == b1->rght->bip_size[b1->r_l]) + { + /* if(b1->left->bip_name[b1->l_r][0][0] < b1->rght->bip_name[b1->r_l][0][0]) */ + if(b1->left->bip_node[b1->l_r][0]->num < b1->rght->bip_node[b1->r_l][0]->num) + { + /* bip1 = b1->left->bip_name[b1->l_r]; */ + bip1 = b1->left->bip_node[b1->l_r]; + } + else + { + /* bip1 = b1->rght->bip_name[b1->r_l]; */ + bip1 = b1->rght->bip_node[b1->r_l]; + } + } + else if(b1->left->bip_size[b1->l_r] < b1->rght->bip_size[b1->r_l]) + { + /* bip1 = b1->left->bip_name[b1->l_r]; */ + bip1 = b1->left->bip_node[b1->l_r]; + } + else + { + /* bip1 = b1->rght->bip_name[b1->r_l]; */ + bip1 = b1->rght->bip_node[b1->r_l]; + } + + + if(b2->left->bip_size[b2->l_r] == b2->rght->bip_size[b2->r_l]) + { + /* if(b2->left->bip_name[b2->l_r][0][0] < b2->rght->bip_name[b2->r_l][0][0]) */ + if(b2->left->bip_node[b2->l_r][0]->num < b2->rght->bip_node[b2->r_l][0]->num) + { + /* bip2 = b2->left->bip_name[b2->l_r]; */ + bip2 = b2->left->bip_node[b2->l_r]; + } + else + { + /* bip2 = b2->rght->bip_name[b2->r_l]; */ + bip2 = b2->rght->bip_node[b2->r_l]; + } + } + else if(b2->left->bip_size[b2->l_r] < b2->rght->bip_size[b2->r_l]) + { + /* bip2 = b2->left->bip_name[b2->l_r]; */ + bip2 = b2->left->bip_node[b2->l_r]; + } + else + { + /* bip2 = b2->rght->bip_name[b2->r_l]; */ + bip2 = b2->rght->bip_node[b2->r_l]; + } + + if(bip_size == 1) Warn_And_Exit("\n. Problem in Compare_Bip\n"); + + for(k=0;knum != bip2[k]->num) break; + } + + if(k == bip_size) /* Branches b1 and b2 define the same bipartition */ + { + b1->bip_score++; + b2->bip_score++; + identical++; + goto out; + } + else + { + different++; // Bipartitions have identical sizes but distinct elements + } + } + else different++; // Biparition have different sizes + } + } + } + out: ; + } - return mat; + return n_edges - identical; + /* return different; */ } -/*********************************************************/ -/* Test if the given site pattern is invariant. Does not handle ambiguities */ -int Is_Invar(int patt_num, int stepsize, int datatype, allseq *data) -{ - int i, j; +/* + Computes min transfer distance between branches of tree1 and tree2 + And adds these distances to tdist_score of each branches of tree1 + the score is not normalized yet by depth nor by number of bootstrap + trees. + This will be done at the end. +*/ +void Compare_Bip_Distance(t_tree *tree1, t_tree *tree2){ + int i; + t_edge *cur_edge; + short unsigned** i_matrix; + short unsigned** c_matrix; + short unsigned** hamming; + short unsigned* min_dist; + short unsigned* min_dist_edge; + int* cluster_sizes; + + Alloc_TBE_Matrices(tree1->n_otu, &i_matrix, &c_matrix, &hamming, &min_dist, &min_dist_edge, &cluster_sizes); - For(i,data->n_otu) - { - For(j,data->n_otu) - { - if(!(Are_Compatible(data->c_seq[i]->state+patt_num, - data->c_seq[j]->state+patt_num, - stepsize, - datatype))) - { - break; - } - } - if(j != data->n_otu) break; - } + Update_All_IC_Ref_Tree(tree1, tree2, i_matrix, c_matrix, cluster_sizes); + Update_All_IC_Boot_Tree(tree1, tree2, i_matrix, c_matrix,hamming,min_dist, min_dist_edge, cluster_sizes); + + for(i=0; i<2*tree1->n_otu-3; i++){ + cur_edge = tree1->a_edges[i]; + cur_edge->tdist_score+=min_dist[cur_edge->num]; + } - if(i == data->n_otu) return 1; - else return 0; + Free_TBE_Matrices(tree1->n_otu, &i_matrix, &c_matrix, &hamming, &min_dist, &min_dist_edge, &cluster_sizes); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Is_Ambigu(char *state, int datatype, int stepsize) +/* Modifiy the tip numbering in tree2 so that tips in + tree1 and tree2 corresponding to the same taxon name + also have the same tip numbering */ +void Match_Tip_Numbers(t_tree *tree1, t_tree *tree2) { - int i; + int i,j; - if(datatype == NT) + if(tree1->n_otu != tree2->n_otu) { - For(i,stepsize) - { - if(strchr("MRWSYKBDHVNXO?-.",state[i])) - return 1; - } + PhyML_Printf("\n. tree1 and tree2 must have the same number of tips."); + /* Otherwise, if tree2->n_otu < tree->n_otu, then some tips in tree2 + will have a number (->num) that is the same as the number of an + internal node in this tree */ + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); } - else + + for(i=0;in_otu;i++) + { + for(j=0;jn_otu;j++) { - if(strchr("X?-.",state[0])) return 1; + if(!strcmp(tree1->a_nodes[i]->name,tree2->a_nodes[j]->name)) + { + tree2->a_nodes[j]->num = tree1->a_nodes[i]->num; + break; + } + } } - return 0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Check_Ambiguities(allseq *data, int datatype, int stepsize) +void Test_Multiple_Data_Set_Format(option *io) { - int i,j; + char *line; - Fors(j,data->crunch_len,stepsize) - { - For(i,data->n_otu) - { - data->ambigu[j] = 0; - data->c_seq[i]->is_ambigu[j] = 0; - } + line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); - For(i,data->n_otu) - { - if(Is_Ambigu(data->c_seq[i]->state+j, - datatype, - stepsize)) - { - data->ambigu[j] = 1; - data->c_seq[i]->is_ambigu[j] = 1; - } - } - } + io->n_trees = 0; + + while(fgets(line,T_MAX_LINE,io->fp_in_tree)) if(strstr(line,";")) io->n_trees++; + + Free(line); + + if((io->do_boot || io->do_tbe) && (io->n_trees > 1)) + Warn_And_Exit("\n. Bootstrap option is not allowed with multiple input trees !\n"); + + rewind(io->fp_in_tree); + + return; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Get_State_From_Ui(int ui, int datatype) + +int Are_Compatible(char *statea, char *stateb, int stepsize, int datatype) { + int i,j; + char a,b; + if(datatype == NT) { - switch(ui) - { - case 1 : {return 0; break;} - case 2 : {return 1; break;} - case 4 : {return 2; break;} - case 8 : {return 3; break;} - default : - { - printf("\n. ui=%d",ui); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - break; - } - } + for(i=0;i1)?(state[0]*16+state[1]*4+state[2]):(state[0]); - } - else - { - switch(c[0]) - { - case 'A' : {state[0]=0 ; break;} - case 'R' : {state[0]=1 ; break;} - case 'N' : {state[0]=2 ; break;} - case 'D' : {state[0]=3 ; break;} - case 'C' : {state[0]=4 ; break;} - case 'Q' : {state[0]=5 ; break;} - case 'E' : {state[0]=6 ; break;} - case 'G' : {state[0]=7 ; break;} - case 'H' : {state[0]=8 ; break;} - case 'I' : {state[0]=9 ; break;} - case 'L' : {state[0]=10; break;} - case 'K' : {state[0]=11; break;} - case 'M' : {state[0]=12; break;} - case 'F' : {state[0]=13; break;} - case 'P' : {state[0]=14; break;} - case 'S' : {state[0]=15; break;} - case 'T' : {state[0]=16; break;} - case 'W' : {state[0]=17; break;} - case 'Y' : {state[0]=18; break;} - case 'V' : {state[0]=19; break;} - - case 'B' : {state[0] = 2; break;} - case 'Z' : {state[0] = 5; break;} - default : {state[0]=-1; break;} - } - return state[0]; - } - return -1; + for(i=0;icrunch_len;i++) if(data->ambigu[i]) data->wght[i] = 0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -char Reciproc_Assign_State(int i_state, int datatype) +void Copy_Tree(t_tree *ori, t_tree *cpy) { - - if(datatype == NT) + int i,j; + + if(ori->is_mixt_tree == YES || cpy->is_mixt_tree == YES) { - i_state = i_state%4; - switch(i_state) - { - case 0 : {return 'A'; break;} - case 1 : {return 'C'; break;} - case 2 : {return 'G'; break;} - case 3 : {return 'T'; break;} - default : - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - break; - } - } + MIXT_Copy_Tree(ori,cpy); + return; } - else + + for(i=0;i<2*ori->n_otu-1;++i) + { + if(ori->a_nodes[i] != NULL) + { + cpy->a_nodes[i]->anc = + (ori->a_nodes[i]->anc != NULL) ? + cpy->a_nodes[ori->a_nodes[i]->anc->num] : + NULL; + + for(j=0;j<3;++j) + { + if(ori->a_nodes[i]->v[j] != NULL) + { + cpy->a_nodes[i]->v[j] = cpy->a_nodes[ori->a_nodes[i]->v[j]->num]; + cpy->a_nodes[i]->b[j] = cpy->a_edges[ori->a_nodes[i]->b[j]->num]; + } + else + { + cpy->a_nodes[i]->v[j] = NULL; + cpy->a_nodes[i]->b[j] = NULL; + } + } + } + cpy->a_nodes[i]->c_seq = ori->a_nodes[i]->c_seq; + } + + for(i=0;i<2*ori->n_otu-1;++i) { - i_state = i_state%20; - switch(i_state) - { - case 0 : {return 'A' ; break;} - case 1 : {return 'R' ; break;} - case 2 : {return 'N' ; break;} - case 3 : {return 'D' ; break;} - case 4 : {return 'C' ; break;} - case 5 : {return 'Q' ; break;} - case 6 : {return 'E' ; break;} - case 7 : {return 'G' ; break;} - case 8 : {return 'H' ; break;} - case 9 : {return 'I' ; break;} - case 10 : {return 'L'; break;} - case 11 : {return 'K'; break;} - case 12 : {return 'M'; break;} - case 13 : {return 'F'; break;} - case 14 : {return 'P'; break;} - case 15 : {return 'S'; break;} - case 16 : {return 'T'; break;} - case 17 : {return 'W'; break;} - case 18 : {return 'Y'; break;} - case 19 : {return 'V'; break;} - default : - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - break; - } - } + if(ori->a_edges[i] != NULL) + { + cpy->a_edges[i]->l->v = ori->a_edges[i]->l->v; + cpy->a_edges[i]->l_old->v = ori->a_edges[i]->l_old->v; + cpy->a_edges[i]->l_var->v = ori->a_edges[i]->l_var->v; + cpy->a_edges[i]->l_var_old->v = ori->a_edges[i]->l_var_old->v; + cpy->a_edges[i]->left = ori->a_edges[i]->left ? cpy->a_nodes[ori->a_edges[i]->left->num] : NULL; + cpy->a_edges[i]->rght = ori->a_edges[i]->rght ? cpy->a_nodes[ori->a_edges[i]->rght->num] : NULL; + cpy->a_edges[i]->l_v1 = ori->a_edges[i]->l_v1; + cpy->a_edges[i]->l_v2 = ori->a_edges[i]->l_v2; + cpy->a_edges[i]->r_v1 = ori->a_edges[i]->r_v1; + cpy->a_edges[i]->r_v2 = ori->a_edges[i]->r_v2; + cpy->a_edges[i]->l_r = ori->a_edges[i]->l_r; + cpy->a_edges[i]->r_l = ori->a_edges[i]->r_l; + cpy->a_edges[i]->does_exist = ori->a_edges[i]->does_exist; + cpy->a_edges[i]->support_val = ori->a_edges[i]->support_val; + +#ifdef BEAGLE + cpy->a_edges[i]->p_lk_left_idx = ori->a_edges[i]->p_lk_left_idx; + cpy->a_edges[i]->p_lk_rght_idx = ori->a_edges[i]->p_lk_rght_idx; + cpy->a_edges[i]->p_lk_tip_idx = ori->a_edges[i]->p_lk_tip_idx; +#endif + } } - return -1; + + + for(i=0;in_otu;++i) + { + cpy->a_nodes[i]->tax = YES; + + Free(cpy->a_nodes[i]->name); + + cpy->a_nodes[i]->name = (char *)mCalloc(strlen(ori->a_nodes[i]->name)+1,sizeof(char)); + cpy->a_nodes[i]->ori_name = cpy->a_nodes[i]->name ; + + strcpy(cpy->a_nodes[i]->name,ori->a_nodes[i]->name); + } + + + if(ori->n_root) + { + cpy->e_root = cpy->a_edges[ori->e_root->num]; + cpy->n_root = cpy->a_nodes[ori->n_root->num]; + cpy->n_root_pos = ori->n_root_pos; + + cpy->n_root->b[1] = cpy->a_edges[ori->n_root->b[1]->num]; + cpy->n_root->b[2] = cpy->a_edges[ori->n_root->b[2]->num]; + } + + cpy->num_curr_branch_available = 0; + cpy->t_beg = ori->t_beg; + cpy->verbose = ori->verbose; + +#ifdef BEAGLE + cpy->b_inst = ori->b_inst; +#endif } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Assign_State_With_Ambiguity(char *c, int datatype, int stepsize) +t_tree *Duplicate_Tree(t_tree *ori) { - int state[3]; + if(ori->is_mixt_tree == YES) return MIXT_Duplicate_Tree(ori); + t_tree *cpy = Make_Tree_From_Scratch(ori->n_otu,ori->data); + Copy_Tree(ori,cpy); + return(cpy); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Prune_Subtree(t_node *a, t_node *d, t_edge **target, t_edge **residual, t_tree *tree) +{ + t_node *v1, *v2, *buff_nd; + t_edge *b1, *b2; + int dir_v1, dir_v2; int i; + phydbl *buff_p_lk; + int *buff_scale; + int *buff_p_pars; + int *buff_pars; + int *buff_p_lk_loc, *buff_patt_id; + int *buff_ui; + phydbl *buff_p_lk_tip; + + assert(a); + assert(d); + assert(tree); - state[0] = state[1] = state[2] = -1; - if(datatype == NT) + + if(tree->n_root && a == tree->n_root) { - For(i,stepsize) - { - switch(c[i]) - { - case 'A' : {state[i]= 0; break;} - case 'C' : {state[i]= 1; break;} - case 'G' : {state[i]= 2; break;} - case 'T' : {state[i]= 3; break;} - case 'U' : {state[i]= 3; break;} - case 'M' : {state[i]= 4; break;} - case 'R' : {state[i]= 5; break;} - case 'W' : {state[i]= 6; break;} - case 'S' : {state[i]= 7; break;} - case 'Y' : {state[i]= 8; break;} - case 'K' : {state[i]= 9; break;} - case 'B' : {state[i]=10; break;} - case 'D' : {state[i]=11; break;} - case 'H' : {state[i]=12; break;} - case 'V' : {state[i]=13; break;} - case 'N' : case 'X' : case '?' : case 'O' : case '-' : {state[i]=14; break;} - default : - { - printf("\n. Unknown character state : %c\n",state[i]); - Warn_And_Exit("\n. Init failed (check the data type)\n"); - break; - } - } - return (stepsize>1)?(state[0]*16+state[1]*4+state[2]):(state[0]); - } + if(d == tree->e_root->left) a = tree->e_root->rght; + else if(d == tree->e_root->rght) a = tree->e_root->left; + else + { + PhyML_Printf("\n. left: %d right: %d",tree->e_root->left->num,tree->e_root->rght->num); + assert(false); + } } - else + + if(a->tax) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + dir_v1 = dir_v2 = -1; + for(i=0;i<3;++i) { - switch(c[0]) - { - case 'A' : {state[0]= 0; break;} - case 'R' : {state[0]= 1; break;} - case 'N' : {state[0]= 2; break;} - case 'D' : {state[0]= 3; break;} - case 'C' : {state[0]= 4; break;} - case 'Q' : {state[0]= 5; break;} - case 'E' : {state[0]= 6; break;} - case 'G' : {state[0]= 7; break;} - case 'H' : {state[0]= 8; break;} - case 'I' : {state[0]= 9; break;} - case 'L' : {state[0]=10; break;} - case 'K' : {state[0]=11; break;} - case 'M' : {state[0]=12; break;} - case 'F' : {state[0]=13; break;} - case 'P' : {state[0]=14; break;} - case 'S' : {state[0]=15; break;} - case 'T' : {state[0]=16; break;} - case 'W' : {state[0]=17; break;} - case 'Y' : {state[0]=18; break;} - case 'V' : {state[0]=19; break;} - case 'B' : {state[0]= 2; break;} - case 'Z' : {state[0]= 5; break;} - case 'X' : case '?' : case '-' : {state[0]=20; break;} - default : - { - printf("\n. Unknown character state : %c\n",state[0]); - Warn_And_Exit("\n. Init failed (check the data type)\n"); - break; - } - } - return state[0]; + if(a->v[i] != d) + { + if(dir_v1 < 0) dir_v1 = i; + else dir_v2 = i; + } } - return -1; -} -/*********************************************************/ + assert(dir_v1 > -1); + assert(dir_v2 > -1); -void Clean_Tree_Connections(arbre *tree) -{ + assert(a->v[dir_v1] != NULL); + assert(a->v[dir_v2] != NULL); + + if(a->v[dir_v1] == a->anc) a->v[dir_v2]->anc = a->v[dir_v1]; + else a->v[dir_v1]->anc = a->v[dir_v2]; - int i; - For(i,2*tree->n_otu-2) + if(a->v[dir_v1]->num < a->v[dir_v2]->num) + { + v1 = a->v[dir_v1]; + v2 = a->v[dir_v2]; + b1 = a->b[dir_v1]; + b2 = a->b[dir_v2]; + } + else { - tree->noeud[i]->v[0] = NULL; - tree->noeud[i]->v[1] = NULL; - tree->noeud[i]->v[2] = NULL; - tree->noeud[i]->b[0] = NULL; - tree->noeud[i]->b[1] = NULL; - tree->noeud[i]->b[2] = NULL; + v1 = a->v[dir_v2]; + v2 = a->v[dir_v1]; + b1 = a->b[dir_v2]; + b2 = a->b[dir_v1]; } -} -/*********************************************************/ -void Bootstrap(arbre *tree) -{ - int *site_num, n_site; - int replicate,j,k; - int position,init_len; - phydbl buff; - allseq *boot_data; - arbre *boot_tree; - model *boot_mod; - matrix *boot_mat; - char *s; -/* phydbl rf; */ + assert(NULL != b1 && NULL != b2); - tree->print_boot_val = 1; - tree->print_alrt_val = 0; - boot_tree = NULL; + if(target) (*target) = b1; + if(residual) (*residual) = b2; - site_num = (int *)mCalloc(tree->data->init_len,sizeof(int)); - Alloc_Bip(tree); - Get_Bip(tree->noeud[0],tree->noeud[0]->v[0],tree); + a->v[dir_v1] = NULL; + a->v[dir_v2] = NULL; + a->b[dir_v1] = NULL; + a->b[dir_v2] = NULL; - n_site = 0; - For(j,tree->data->crunch_len) For(k,tree->data->wght[j]) +#ifdef BEAGLE + int temp; +#endif + + if(v1 == b1->left) + { + b1->rght = v2; + + if(v2 == b2->left) + { + if(tree->is_mixt_tree == NO) + { + buff_p_lk = b1->p_lk_rght; + b1->p_lk_rght = b2->p_lk_left; + b2->p_lk_left = buff_p_lk; + + buff_p_lk_tip = b1->p_lk_tip_r; + b1->p_lk_tip_r = b2->p_lk_tip_l; + b2->p_lk_tip_l = buff_p_lk_tip; + +#ifdef BEAGLE + temp = b1->p_lk_rght_idx; + b1->p_lk_rght_idx = b2->p_lk_left_idx; + b2->p_lk_left_idx = temp; +#endif + buff_scale = b1->sum_scale_rght; + b1->sum_scale_rght = b2->sum_scale_left; + b2->sum_scale_left = buff_scale; + + buff_scale = b1->sum_scale_rght_cat; + b1->sum_scale_rght_cat = b2->sum_scale_left_cat; + b2->sum_scale_left_cat = buff_scale; + + buff_pars = b1->pars_r; + b1->pars_r = b2->pars_l; + b2->pars_l = buff_pars; + + buff_ui = b1->ui_r; + b1->ui_r = b2->ui_l; + b2->ui_l = buff_ui; + + buff_p_pars = b1->p_pars_r; + b1->p_pars_r = b2->p_pars_l; + b2->p_pars_l = buff_p_pars; + + buff_p_lk_loc = b1->p_lk_loc_rght; + b1->p_lk_loc_rght = b2->p_lk_loc_left; + b2->p_lk_loc_left = buff_p_lk_loc; + + buff_patt_id = b1->patt_id_rght; + b1->patt_id_rght = b2->patt_id_left; + b2->patt_id_left = buff_patt_id; + } + } + else + { + if(tree->is_mixt_tree == NO) + { + buff_p_lk = b1->p_lk_rght; /* b1->p_lk_rght = NULL if b1->rght->tax */ + b1->p_lk_rght = b2->p_lk_rght; /* b2->p_lk_rght = NULL if b2->rght->tax */ + b2->p_lk_rght = buff_p_lk; + + buff_p_lk_tip = b1->p_lk_tip_r; + b1->p_lk_tip_r = b2->p_lk_tip_r; + b2->p_lk_tip_r = buff_p_lk_tip; +#ifdef BEAGLE + temp = b1->p_lk_rght_idx; + b1->p_lk_rght_idx = b2->p_lk_rght_idx; + b2->p_lk_rght_idx = temp; + + b2->p_lk_tip_idx = b1->p_lk_tip_idx; +#endif + buff_scale = b1->sum_scale_rght; + b1->sum_scale_rght = b2->sum_scale_rght; + b2->sum_scale_rght = buff_scale; + + buff_pars = b1->pars_r; + b1->pars_r = b2->pars_r; + b2->pars_r = buff_pars; + + buff_ui = b1->ui_r; + b1->ui_r = b2->ui_r; + b2->ui_r = buff_ui; + + buff_p_pars = b1->p_pars_r; + b1->p_pars_r = b2->p_pars_r; + b2->p_pars_r = buff_p_pars; + + buff_p_lk_loc = b1->p_lk_loc_rght; + b1->p_lk_loc_rght = b2->p_lk_loc_rght; + b2->p_lk_loc_rght = buff_p_lk_loc; + + buff_patt_id = b1->patt_id_rght; + b1->patt_id_rght = b2->patt_id_rght; + b2->patt_id_rght = buff_patt_id; + } + } + } + else + { + b1->left = v2; + + if(v2 == b2->left) + { + if(tree->is_mixt_tree == NO) + { + buff_p_lk = b1->p_lk_left; + b1->p_lk_left = b2->p_lk_left; + b2->p_lk_left = buff_p_lk; + + buff_p_lk_tip = b1->p_lk_tip_l; + b1->p_lk_tip_l = b2->p_lk_tip_l; + b2->p_lk_tip_l = buff_p_lk_tip; +#ifdef BEAGLE + temp = b1->p_lk_left_idx; + b1->p_lk_left_idx = b2->p_lk_left_idx; + b2->p_lk_left_idx = temp; +#endif + buff_scale = b1->sum_scale_left; + b1->sum_scale_left = b2->sum_scale_left; + b2->sum_scale_left = buff_scale; + + buff_scale = b1->sum_scale_left_cat; + b1->sum_scale_left_cat = b2->sum_scale_left_cat; + b2->sum_scale_left_cat = buff_scale; + + buff_pars = b1->pars_l; + b1->pars_l = b2->pars_l; + b2->pars_l = buff_pars; + + buff_ui = b1->ui_l; + b1->ui_l = b2->ui_l; + b2->ui_l = buff_ui; + + buff_p_pars = b1->p_pars_l; + b1->p_pars_l = b2->p_pars_l; + b2->p_pars_l = buff_p_pars; + + buff_p_lk_loc = b1->p_lk_loc_left; + b1->p_lk_loc_left = b2->p_lk_loc_left; + b2->p_lk_loc_left = buff_p_lk_loc; + + buff_patt_id = b1->patt_id_left; + b1->patt_id_left = b2->patt_id_left; + b2->patt_id_left = buff_patt_id; + } + } + else + { + if(tree->is_mixt_tree == NO) + { + buff_p_lk = b1->p_lk_left; + b1->p_lk_left = b2->p_lk_rght; /* b2->p_lk_rght = NULL if b2->rght->tax */ + b2->p_lk_rght = buff_p_lk; + + buff_p_lk_tip = b1->p_lk_tip_l; + b1->p_lk_tip_l = b2->p_lk_tip_r; + b2->p_lk_tip_r = buff_p_lk_tip; +#ifdef BEAGLE + temp = b1->p_lk_left_idx; + b1->p_lk_left_idx = b2->p_lk_rght_idx; + b2->p_lk_rght_idx = temp; + + b2->p_lk_tip_idx = b1->p_lk_tip_idx; +#endif + buff_scale = b1->sum_scale_left; + b1->sum_scale_left = b2->sum_scale_rght; + b2->sum_scale_rght = buff_scale; + + buff_scale = b1->sum_scale_left_cat; + b1->sum_scale_left_cat = b2->sum_scale_rght_cat; + b2->sum_scale_rght_cat = buff_scale; + + buff_pars = b1->pars_l; + b1->pars_l = b2->pars_r; + b2->pars_r = buff_pars; + + buff_ui = b1->ui_l; + b1->ui_l = b2->ui_r; + b2->ui_r = buff_ui; + + buff_p_pars = b1->p_pars_l; + b1->p_pars_l = b2->p_pars_r; + b2->p_pars_r = buff_p_pars; + + buff_p_lk_loc = b1->p_lk_loc_left; + b1->p_lk_loc_left = b2->p_lk_loc_rght; + b2->p_lk_loc_rght = buff_p_lk_loc; + + buff_patt_id = b1->patt_id_left; + b1->patt_id_left = b2->patt_id_rght; + b2->patt_id_rght = buff_patt_id; + } + } + } + + for(i=0;i<3;++i) + if(v2->v[i] == a) + { + v2->v[i] = v1; + v2->b[i] = b1; + break; + } + +#ifdef DEBUG + if(i == 3) + { + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } +#endif + + for(i=0;i<3;++i) + if(v1->v[i] == a) + { + v1->v[i] = v2; + break; + } + +#ifdef DEBUG + if(i == 3) { - site_num[n_site] = j; - n_site++; + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); } +#endif - boot_data = Copy_Cseq(tree->data, tree->data->crunch_len, tree->mod->ns); + if(b1->l->onoff == ON) + { + b1->l->v = (b1->l->v + b2->l->v); + b1->l_var->v = (b1->l_var->v + b2->l_var->v); + } - printf("\n\n. Non parametric bootstrap analysis \n\n"); - printf(" ["); + assert(v1 != v2); + + (v1 == b1->left)? + (Set_Edge_Dirs(b1,v1,v2,tree)): + (Set_Edge_Dirs(b1,v2,v1,tree)); - For(replicate,tree->mod->bootstrap) + if(tree->n_root != NULL) { - For(j,boot_data->crunch_len) boot_data->wght[j] = 0; + // Pruning one of the subtree below n_root->v[2], v2 below a + if(tree->n_root->v[1] == v1 && tree->n_root->v[2] == a) tree->n_root->v[2] = v2; - init_len = 0; - For(j,boot_data->init_len) - { - buff = rand(); - buff /= RAND_MAX; - buff *= (phydbl)(tree->data->init_len-1.0); - if(buff-(int)(buff) > 0.5-MDBL_MAX) position = (int)(buff)+1; - else position = (int)(buff); - boot_data->wght[site_num[position]] += 1; - init_len++; - } + // Pruning one of the subtree below n_root->v[1], v2 below a + else if(tree->n_root->v[2] == v1 && tree->n_root->v[1] == a) tree->n_root->v[1] = v2; + + // Pruning one of the subtree below n_root->v[1], v1 below a + else if((tree->n_root->v[1] == v2 && tree->n_root->v[2] == a) || + (tree->n_root->v[2] == v2 && tree->n_root->v[1] == a)) + { + tree->e_root = b1; + if(tree->n_root->v[1] == v2) tree->n_root->v[2] = v1; + if(tree->n_root->v[2] == v2) tree->n_root->v[1] = v1; + } - if(init_len != tree->data->init_len) Warn_And_Exit("\n. Pb when copying sequences\n"); + // Prune subtree to the left or to the right of the root node + else if((tree->n_root->v[1] == a && tree->n_root->v[2] == d) || + (tree->n_root->v[1] == d && tree->n_root->v[2] == a)) + { + tree->e_root = b1; + tree->n_root->v[1] = v2; + tree->n_root->v[2] = v1; + } - (tree->mod->datatype == NT)? - (Get_Base_Freqs(boot_data)): - (Get_AA_Freqs(boot_data)); - if(tree->io->random_boot_seq_order) Randomize_Sequence_Order(boot_data); + if(tree->n_root->v[1] == tree->e_root->rght) + { + buff_nd = tree->n_root->v[1]; + tree->n_root->v[1] = tree->n_root->v[2]; + tree->n_root->v[2] = buff_nd; + } - boot_mod = Copy_Model(tree->mod); - Init_Model(boot_data,boot_mod); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + tree->n_root->anc = NULL; + } - if(tree->io->in_tree) - { - rewind(tree->io->fp_in_tree); - boot_tree = Read_Tree_File(tree->io->fp_in_tree); - } - else - { - boot_mat = ML_Dist(boot_data,boot_mod); - boot_mat->tree = Make_Tree_From_Scratch(boot_data->n_otu,boot_data); - Fill_Missing_Dist(boot_mat); - Bionj(boot_mat); - boot_tree = boot_mat->tree; - boot_tree->mat = boot_mat; - } +#ifdef DEBUG + if(b1->left->tax == YES && b1->rght->tax == NO) + { + PhyML_Printf("\n. root: %d root->v1: %d root->v2: %d eroot: %d b1: %d b2: %d v1: %d v2: %d", + tree->n_root->num, + tree->n_root->v[1]->num, + tree->n_root->v[2]->num, + tree->e_root->num, + b1->num,b2->num,v1->num,v2->num); + PhyML_Printf("\n. b1->left->num = %d",b1->left->num); + PhyML_Printf("\n. b1->rght->num = %d",b1->rght->num); + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } +#endif - boot_tree->mod = boot_mod; - boot_tree->io = tree->io; - boot_tree->data = boot_data; - boot_tree->both_sides = 1; - boot_tree->mod->s_opt->print = 0; - boot_tree->n_pattern = boot_tree->data->crunch_len/ - boot_tree->mod->stepsize; - boot_tree->io->print_site_lnl = 0; - boot_tree->io->print_trace = 0; + if(tree->is_mixt_tree == YES) MIXT_Prune_Subtree(a,d,target,residual,tree); +} - if((boot_tree->mod->s_opt->random_input_tree) && (boot_tree->mod->s_opt->topo_search == SPR_MOVE)) Random_Tree(boot_tree); - Order_Tree_CSeq(boot_tree,boot_data); - Share_Lk_Struct(tree,boot_tree); - Share_Spr_Struct(tree,boot_tree); - Share_Pars_Struct(tree,boot_tree); - Fill_Dir_Table(boot_tree); - Update_Dirs(boot_tree); - if(tree->mod->s_opt->greedy) Init_P_Lk_Tips_Double(boot_tree); - else Init_P_Lk_Tips_Int(boot_tree); - Init_Ui_Tips(boot_tree); - Init_P_Pars_Tips(boot_tree); - Br_Len_Not_Involving_Invar(boot_tree); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if(boot_tree->mod->s_opt->opt_topo) - { - if(boot_tree->mod->s_opt->topo_search == NNI_MOVE) - { - Simu_Loop(boot_tree); - } - else - { - if(tree->mod->s_opt->steph_spr) - { - Speed_Spr_Loop(boot_tree); - } - else - { - Init_SPR (boot_tree); - Optim_SPR (boot_tree,0,ALL); - Clean_SPR (boot_tree); - } - } - } +void Graft_Subtree(t_edge *target, t_node *link, t_node *link_daughter, t_edge *residual, t_node *target_nd, t_tree *tree) +{ + t_node *v1, *v2; + int i, dir_v1, dir_v2; + phydbl *buff_p_lk; + int *buff_scale; + int *buff_p_pars, *buff_pars; + int *buff_p_lk_loc, *buff_patt_id; + phydbl *buff_p_lk_tip; + int *buff_ui; + t_edge *b_up; + + assert(link); + assert(tree); + assert(target); + + if(link == tree->n_root) + { + assert(link_daughter); + if(link_daughter == tree->n_root->v[1]) link = tree->n_root->v[2]; + else if(link_daughter == tree->n_root->v[2]) link = tree->n_root->v[1]; else - { - if(boot_tree->mod->s_opt->opt_num_param || boot_tree->mod->s_opt->opt_bl) - Round_Optimize(boot_tree,boot_tree->data); - else - Lk(boot_tree); - } + { + PhyML_Printf("\n. link: %d link_daughter: %d", + link->num, + link_daughter ? link_daughter->num : -1); + assert(false); + } + } + + dir_v1 = dir_v2 = -1; + b_up = NULL; + for(i=0;i<3;i++) + { + if(link->v[i] == NULL) + { + if(dir_v1 < 0) dir_v1 = i; + else dir_v2 = i; + } + else b_up = link->b[i]; + } + + if(dir_v1 < 0 || dir_v2 < 0) + { + PhyML_Printf("\n. link: %d was not pruned in a clean manner...\n",link->num); + assert(FALSE); + } + + + if(target->left == target->rght->anc) + { + link->anc = target->left; + target->rght->anc = link; + } + else + { + link->anc = target->rght; + target->left->anc = link; + } + + +#ifdef BEAGLE + int temp; +#endif + + if(target->left->num < target->rght->num) + { + v1 = target->left; + v2 = target->rght; + + assert(v1 != link); + assert(v2 != link); + + if(tree->is_mixt_tree == NO) + { + buff_p_lk = residual->p_lk_rght; + residual->p_lk_rght = target->p_lk_rght; + target->p_lk_rght = buff_p_lk; + + buff_p_lk_tip = residual->p_lk_tip_r; + residual->p_lk_tip_r = target->p_lk_tip_r; + target->p_lk_tip_r = buff_p_lk_tip; + +#ifdef BEAGLE + temp = residual->p_lk_rght_idx; + residual->p_lk_rght_idx = target->p_lk_rght_idx; + target->p_lk_rght_idx = temp; + + temp = residual->p_lk_tip_idx; + residual->p_lk_tip_idx = target->p_lk_tip_idx; + target->p_lk_tip_idx = temp; +#endif + + buff_scale = residual->sum_scale_rght; + residual->sum_scale_rght = target->sum_scale_rght; + target->sum_scale_rght = buff_scale; + + buff_scale = residual->sum_scale_rght_cat; + residual->sum_scale_rght_cat = target->sum_scale_rght_cat; + target->sum_scale_rght_cat = buff_scale; + + buff_pars = residual->pars_r; + residual->pars_r = target->pars_r; + target->pars_r = buff_pars; + + buff_ui = residual->ui_r; + residual->ui_r = target->ui_r; + target->ui_r = buff_ui; + + buff_p_pars = residual->p_pars_r; + residual->p_pars_r = target->p_pars_r; + target->p_pars_r = buff_p_pars; + + buff_p_lk_loc = residual->p_lk_loc_rght; + residual->p_lk_loc_rght = target->p_lk_loc_rght; + target->p_lk_loc_rght = buff_p_lk_loc; + + buff_patt_id = residual->patt_id_rght; + residual->patt_id_rght = target->patt_id_rght; + target->patt_id_rght = buff_patt_id; + } + } + else + { + v1 = target->rght; + v2 = target->left; + + assert(v1 != link); + assert(v2 != link); + + if(tree->is_mixt_tree == NO) + { + buff_p_lk = residual->p_lk_rght; + residual->p_lk_rght = target->p_lk_left; + target->p_lk_left = buff_p_lk; + + buff_p_lk_tip = residual->p_lk_tip_r; + residual->p_lk_tip_r = target->p_lk_tip_l; + target->p_lk_tip_l = buff_p_lk_tip; + +#ifdef BEAGLE + temp = residual->p_lk_rght_idx; + residual->p_lk_rght_idx = target->p_lk_left_idx; + target->p_lk_left_idx = temp; +#endif + + buff_scale = residual->sum_scale_rght; + residual->sum_scale_rght = target->sum_scale_left; + target->sum_scale_left = buff_scale; + + buff_scale = residual->sum_scale_rght_cat; + residual->sum_scale_rght_cat = target->sum_scale_left_cat; + target->sum_scale_left_cat = buff_scale; + + buff_pars = residual->pars_r; + residual->pars_r = target->pars_l; + target->pars_l = buff_pars; + + buff_ui = residual->ui_r; + residual->ui_r = target->ui_l; + target->ui_l = buff_ui; + + buff_p_pars = residual->p_pars_r; + residual->p_pars_r = target->p_pars_l; + target->p_pars_l = buff_p_pars; + + buff_p_lk_loc = residual->p_lk_loc_rght; + residual->p_lk_loc_rght = target->p_lk_loc_left; + target->p_lk_loc_left = buff_p_lk_loc; + + buff_patt_id = residual->patt_id_rght; + residual->patt_id_rght = target->patt_id_left; + target->patt_id_left = buff_patt_id; + } + } + + + + for(i=0;i<3;i++) + if(v2->b[i] == target) + { + v2->v[i] = link; + v2->b[i] = residual; + break; + } + assert(i<3); + + link->v[dir_v2] = v2; + link->b[dir_v2] = residual; + + residual->left = link; + residual->rght = v2; + + if(v1 == target->left) target->rght = link; + else target->left = link; + + link->v[dir_v1] = v1; + link->b[dir_v1] = target; + + + for(i=0;i<3;i++) + if(v1->v[i] == v2) + { + v1->v[i] = link; + break; + } + + + if(target->l->onoff == ON) + { + target->l->v /= 2.0; + target->l_var->v /= 2.0; + } + + if(residual->l->onoff == ON) + { + residual->l->v = target->l->v; + residual->l_var->v = target->l_var->v; + } + + assert(target->left != target->rght); + assert(residual->left != residual->rght); + assert(b_up->left != b_up->rght); + + Set_Edge_Dirs(target,target->left,target->rght,tree); + Set_Edge_Dirs(residual,residual->left,residual->rght,tree); + Set_Edge_Dirs(b_up,b_up->left,b_up->rght,tree); + + if(tree->n_root != NULL) + { + if(target == tree->e_root) + { + assert(target_nd); + if(target_nd == v1) tree->e_root = residual; + else if(target_nd == v2) tree->e_root = target; + else if(target_nd == tree->n_root) tree->e_root = b_up; + } + + tree->n_root->v[1] = tree->e_root->left; + tree->n_root->v[2] = tree->e_root->rght; + + tree->n_root->b[1]->left = tree->n_root; + tree->n_root->b[1]->rght = tree->n_root->v[1]; + tree->n_root->b[1]->p_lk_rght = tree->e_root->p_lk_left; + tree->n_root->b[1]->p_lk_tip_r = tree->e_root->p_lk_tip_l; +#ifdef BEAGLE + tree->n_root->b[1]->p_lk_rght_idx = tree->e_root->p_lk_left_idx; + tree->n_root->b[1]->p_lk_tip_idx = tree->e_root->p_lk_tip_idx; +#endif + tree->n_root->b[1]->sum_scale_rght = tree->e_root->sum_scale_left; + tree->n_root->b[1]->sum_scale_rght_cat = tree->e_root->sum_scale_left_cat; + tree->n_root->b[1]->pars_r = tree->e_root->pars_l; + tree->n_root->b[1]->ui_r = tree->e_root->ui_l; + tree->n_root->b[1]->p_pars_r = tree->e_root->p_pars_l; + tree->n_root->b[1]->p_lk_loc_rght = tree->e_root->p_lk_loc_left; + tree->n_root->b[1]->patt_id_rght = tree->e_root->patt_id_left; + + + tree->n_root->b[2]->left = tree->n_root; + tree->n_root->b[2]->rght = tree->n_root->v[2]; + tree->n_root->b[2]->p_lk_rght = tree->e_root->p_lk_rght; + tree->n_root->b[2]->p_lk_tip_r = tree->e_root->p_lk_tip_r; +#ifdef BEAGLE + tree->n_root->b[2]->p_lk_rght_idx = tree->e_root->p_lk_rght_idx; + tree->n_root->b[2]->p_lk_tip_idx = tree->e_root->p_lk_tip_idx; +#endif + tree->n_root->b[2]->sum_scale_rght = tree->e_root->sum_scale_rght; + tree->n_root->b[2]->sum_scale_rght_cat = tree->e_root->sum_scale_rght_cat; + tree->n_root->b[2]->pars_r = tree->e_root->pars_r; + tree->n_root->b[2]->ui_r = tree->e_root->ui_r; + tree->n_root->b[2]->p_pars_r = tree->e_root->p_pars_r; + tree->n_root->b[2]->p_lk_loc_rght = tree->e_root->p_lk_loc_rght; + tree->n_root->b[2]->patt_id_rght = tree->e_root->patt_id_rght; + + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + tree->n_root->anc = NULL; + } + + if(tree->is_mixt_tree == YES) MIXT_Graft_Subtree(target,link,link_daughter,residual,target_nd,tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Reassign_Node_Nums(t_node *a, t_node *d, unsigned int *curr_ext_node, unsigned int *curr_int_node, t_tree *tree) +{ + t_node *buff; + int i; + + if(a->tax) + { + buff = tree->a_nodes[*curr_ext_node]; + tree->a_nodes[*curr_ext_node] = a; + tree->a_nodes[a->num] = buff; + buff->num = a->num; + a->num = *curr_ext_node; + (*curr_ext_node)++; + } + + if(d->tax) + { + buff = tree->a_nodes[*curr_ext_node]; + tree->a_nodes[*curr_ext_node] = d; + tree->a_nodes[d->num] = buff; + buff->num = d->num; + d->num = *curr_ext_node; + (*curr_ext_node)++; + return; + } + else + { + buff = tree->a_nodes[*curr_int_node]; + tree->a_nodes[*curr_int_node] = d; + tree->a_nodes[d->num] = buff; + buff->num = d->num; + d->num = *curr_int_node; + (*curr_int_node)++; + } + + for(i=0;i<3;i++) + { + if(d->v[i] != a) + Reassign_Node_Nums(d,d->v[i],curr_ext_node,curr_int_node,tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Reassign_Edge_Nums(t_node *a, t_node *d, int *curr_br, t_tree *tree) +{ + t_edge *buff; + int i,j; + + for(i=0;i<3;i++) + if(a->v[i] == d) + { + buff = tree->a_edges[*curr_br]; + For(j,2*N_MAX_OTU-3) if(tree->a_edges[j] == a->b[i]) break; + if(j == 2*N_MAX_OTU-3) + { + PhyML_Printf("\n. Err. in file %s at line %d (function '%s').\n",__FILE__,__LINE__,__FUNCTION__); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + tree->a_edges[*curr_br] = a->b[i]; + tree->a_edges[j] = buff; + a->b[i]->num = *curr_br; + (*curr_br)++; + break; + } + + if(d->tax) return; + else + { + for(i=0;i<3;i++) + if(d->v[i] != a) + Reassign_Edge_Nums(d,d->v[i],curr_br,tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Find_Mutual_Direction(t_node *n1, t_node *n2, short int *dir_n1_to_n2, short int *dir_n2_to_n1) +{ + int scores[3][3]; + int i,j,k,l; + + if(n1 == n2) return; + + + for(i=0;i<3;i++) + { + for(j=0;j<3;j++) + { + scores[i][j] = 0; + + For(k,n1->bip_size[i]) + { + For(l,n2->bip_size[j]) + { + if(n1->bip_node[i][k] == n2->bip_node[j][l]) + { + scores[i][j]++; + break; + } + } + } + } + } + + for(i=0;i<3;i++) + { + for(j=0;j<3;j++) + { + if(!scores[i][j]) + { + *dir_n1_to_n2 = i; + *dir_n2_to_n1 = j; + return; + } + } + } + + PhyML_Printf("\n. n1=%d n2=%d",n1->num,n2->num); + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + + + +/* for(i=0;i<3;i++) */ +/* { */ +/* n_zero_line = 0; */ +/* for(j=0;j<3;j++) */ +/* { */ +/* if(!scores[i][j]) n_zero_line++; */ +/* } */ +/* if(n_zero_line != 2) {*dir_n1_to_n2 = i; break;} */ +/* } */ + + +/* for(i=0;i<3;i++) */ +/* { */ +/* n_zero_col = 0; */ +/* for(j=0;j<3;j++) */ +/* { */ +/* if(!scores[j][i]) n_zero_col++; */ +/* } */ +/* if(n_zero_col != 2) {*dir_n2_to_n1 = i; break;} */ +/* } */ + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Update_Dir_To_Tips(t_node *a, t_node *d, t_tree *tree) +{ + int i,j,k; + short int *inout; + int d_a; + int dim; + + dim = 2*tree->n_otu-2; + + inout = (short int *)mCalloc(tree->n_otu,sizeof(short int)); + + for(i=0;i<3;i++) + { + if(a->v[i] == d) + { + for(j=0;jn_otu;j++) inout[j] = 1; + For(k,a->bip_size[i]) inout[a->bip_node[i][k]->num] = 0; + for(j=0;jn_otu;j++) if(inout[tree->a_nodes[j]->num]) tree->t_dir[a->num*dim+tree->a_nodes[j]->num] = i; + break; + } + } + + + if(!d->tax) + { + d_a = -1; + + for(i=0;i<3;i++) + { + if(d->v[i] != a) Update_Dir_To_Tips(d,d->v[i],tree); + else if(d->v[i] == a) d_a = i; + } + + for(j=0;jn_otu;j++) inout[j] = 1; + For(k,d->bip_size[d_a]) inout[d->bip_node[d_a][k]->num] = 0; + for(j=0;jn_otu;j++) if(inout[tree->a_nodes[j]->num]) tree->t_dir[d->num*dim+tree->a_nodes[j]->num] = d_a; + } + Free(inout); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Fill_Dir_Table(t_tree *tree) +{ + int i,j; + int dim; + + dim = 2*tree->n_otu-2; + For(i,dim*dim) tree->t_dir[i] = 0; + Free_Bip(tree); + Alloc_Bip(tree); + Get_Bip(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + Update_Dir_To_Tips(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + + for(i=tree->n_otu;i<2*tree->n_otu-2;i++) + for(j=i;j<2*tree->n_otu-2;j++) + { + Find_Mutual_Direction(tree->a_nodes[i],tree->a_nodes[j], + &(tree->t_dir[i*dim+j]), + &(tree->t_dir[j*dim+i])); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Get_Subtree_Size(t_node *a, t_node *d) +{ + int size,i; + + if(d->tax) return 1; + else + { + size = 0; + for(i=0;i<3;i++) + if(d->v[i] != a) + size += Get_Subtree_Size(d,d->v[i]); + } + return size; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +/*! + Calculate the joint probability of states (nt or aa) at the + two extremities of a given edge given the matrix of transition + probabilities, the vector of conditional likelihoods on each + side of the branch and the vector of equilibrium frequencies. +*/ +void Joint_Proba_States_Left_Right(phydbl *Pij, phydbl *p_lk_left, phydbl *p_lk_rght, + vect_dbl *pi, int scale_left, int scale_rght, + phydbl *F, int n, int site, t_tree *tree) +{ + int i,j; + phydbl sum = 0.0; + + for(i=0;iv[i] * + Pij[i*n+j] * + p_lk_left[i] * + p_lk_rght[j] * + POW(2.,-(scale_left + scale_rght)); + + sum += F[i*n+j]; + } + } + + For(i,n*n) + { + F[i] /= sum; + if(isnan(F[i]) || isinf(F[i])) + { + for(i=0;iv[i] , + Pij[i*n+j] , + p_lk_left[i] , + p_lk_rght[j] , + POW(2.,-(scale_left + scale_rght))); + + PhyML_Printf("\n. sum = %G",sum); + Print_Site(tree->data,site,tree->n_otu,"\n",1,stderr); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Triple_Dist(t_node *a, t_tree *tree) +{ + if(a->tax) return UNLIKELY; + else + { + Update_PMat_At_Given_Edge(a->b[1],tree); + Update_PMat_At_Given_Edge(a->b[2],tree); + + Update_Partial_Lk(tree,a->b[0],a); + /* Fast_Br_Len(a->b[0],tree,YES); */ + Br_Len_Opt(&(a->b[0]->l->v),a->b[0],tree); + + Update_Partial_Lk(tree,a->b[1],a); + /* Fast_Br_Len(a->b[1],tree,YES); */ + Br_Len_Opt(&(a->b[1]->l->v),a->b[1],tree); + + Update_Partial_Lk(tree,a->b[2],a); + /* Fast_Br_Len(a->b[2],tree,YES); */ + Br_Len_Opt(&(a->b[2]->l->v),a->b[2],tree); + + + Update_Partial_Lk(tree,a->b[1],a); + Update_Partial_Lk(tree,a->b[0],a); + } + + return tree->c_lnL; + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Triple_Dist_Approx(t_node *a, t_edge *b, t_tree *tree) +{ + // !!!!!!!! NOT MIXT PROOF + if(a->tax) return UNLIKELY; + else + { + int i; + + for(i=0;i<3;i++) + if(a->b[i] != b) + Update_PMat_At_Given_Edge(a->b[i],tree); + + Update_Partial_Lk(tree,b,a); + Fast_Br_Len(b,tree,YES); + + return tree->c_lnL; + + /* t_node *v0,*v1,*v2; */ + /* phydbl d01,d02,d12; */ + /* t_ll *tips0,*tips1,*tips2; */ + + /* d01 = d02 = d12 = 0.0; */ + + /* v0 = a->v[0]; */ + /* v1 = a->v[1]; */ + /* v2 = a->v[2]; */ + + /* tips0 = Get_List_Of_Reachable_Tips(a,v0,tree); */ + /* tips1 = Get_List_Of_Reachable_Tips(a,v1,tree); */ + /* tips2 = Get_List_Of_Reachable_Tips(a,v2,tree); */ + + /* d01 = Length_Of_Path_Between_List_Of_Tips(tips0,tips1,tree->mat); */ + /* d02 = Length_Of_Path_Between_List_Of_Tips(tips0,tips2,tree->mat); */ + /* d12 = Length_Of_Path_Between_List_Of_Tips(tips1,tips2,tree->mat); */ + + /* a->b[0]->l->v = (d01 + d02 - d12)/2.; */ + /* a->b[1]->l->v = (d01 + d12 - d02)/2.; */ + /* a->b[2]->l->v = (d02 + d12 - d01)/2.; */ + + /* Free_Linked_List(tips0); */ + /* Free_Linked_List(tips1); */ + /* Free_Linked_List(tips2); */ + + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Make_Symmetric(phydbl **F, int size) +{ + int i,j; + + for(i=0;itax) return; + else + { + int i; + if(d == target) *match = 1; + for(i=0;i<3;i++) + { + if(d->v[i] != a) + Found_In_Subtree(d,d->v[i],target,match,tree); + } + } +} + + + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Get_List_Of_Target_Edges(t_node *a, t_node *d, t_edge **list, int *list_size, t_tree *tree) +{ + int i; + + for(i=0;i<3;i++) + { + if(a->v[i] && a->v[i] == d) + { + list[*list_size] = a->b[i]; + (*list_size)++; + } + } + + if(d->tax) return; + else + { + for(i=0;i<3;i++) + { + if(d->v[i] != a) + Get_List_Of_Target_Edges(d,d->v[i],list,list_size,tree); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Fix_All(t_tree *tree) +{ + int i; + + for(i=tree->n_otu;i<2*tree->n_otu-2;i++) + { + tree->a_nodes[i]->b[0]->l_old->v = tree->a_nodes[i]->b[0]->l->v; + tree->a_nodes[i]->b[1]->l_old->v = tree->a_nodes[i]->b[1]->l->v; + tree->a_nodes[i]->b[2]->l_old->v = tree->a_nodes[i]->b[2]->l->v; + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +phydbl Tree_Length(t_tree *tree) +{ + phydbl sum; + + sum = 0.0; + for(int i=0;i<2*tree->n_otu-3;++i) sum += MIXT_Get_Mean_Edge_Len(tree->a_edges[i],tree); + return(sum); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Record_Br_Len(t_tree *mixt_tree) +{ + int i; + t_tree *tree; + + if(mixt_tree->br_len_recorded == YES) + { + PhyML_Printf("\n. Overwriting recorded edge lengths.\n"); + assert(FALSE); + } + + tree = mixt_tree; + + do + { + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->l_old->v = tree->a_edges[i]->l->v; + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->l_var_old->v = tree->a_edges[i]->l_var->v; + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +scalar_dbl **Copy_Br_Len(t_tree *mixt_tree) +{ + int i; + scalar_dbl **bl, *new_l; + t_edge *e; + + bl = (scalar_dbl **)mCalloc(2*mixt_tree->n_otu-1,sizeof(scalar_dbl *)); + + For(i,2*mixt_tree->n_otu-1) + { + e = mixt_tree->a_edges[i]; + bl[i] = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + do + { + bl[i]->v = e->l->v; + e = e->next; + if(e) + { + new_l = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + bl[i]->next = new_l; + bl[i]->next->prev = bl[i]; + bl[i] = bl[i]->next; + } + } + while(e); + } + + return(bl); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +scalar_dbl **Copy_Br_Len_Var(t_tree *mixt_tree) +{ + int i; + scalar_dbl **bl_var, *new_l_var; + t_edge *e; + + bl_var = (scalar_dbl **)mCalloc(2*mixt_tree->n_otu-1,sizeof(scalar_dbl *)); + + For(i,2*mixt_tree->n_otu-1) + { + e = mixt_tree->a_edges[i]; + bl_var[i] = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + do + { + bl_var[i]->v = e->l_var->v; + e = e->next; + if(e) + { + new_l_var = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + bl_var[i]->next = new_l_var; + bl_var[i]->next->prev = bl_var[i]; + bl_var[i] = bl_var[i]->next; + } + } + while(e); + } + + return(bl_var); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Transfer_Br_Len_To_Tree(scalar_dbl **bl, t_tree *tree) +{ + int i; + scalar_dbl *la, *lb; + + For(i,2*tree->n_otu-1) + { + if(tree->a_edges[i]->l != NULL) + { + la = bl[i]; + lb = tree->a_edges[i]->l; + if(lb != NULL && la != NULL) + { + do + { + lb->v = la->v; + if(la) la = la->next; + if(lb) lb = lb->next; + } + while(la != NULL && lb != NULL); + assert(la == NULL && lb == NULL); + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Restore_Br_Len(t_tree *mixt_tree) +{ + int i; + t_tree *tree; + + mixt_tree->br_len_recorded = NO; + + tree = mixt_tree; + + do + { + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->l->v = tree->a_edges[i]->l_old->v; + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->l_var->v = tree->a_edges[i]->l_var_old->v; + tree = tree->next; + } + while(tree); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Get_Dist_Btw_Edges(t_node *a, t_node *d, t_tree *tree) +{ + int i; + t_edge *b_fcus; + + b_fcus = NULL; + for(i=0;i<3;i++) if(a->v[i] == d) {b_fcus = a->b[i]; break;} + + if(d->tax) return; + else + { + for(i=0;i<3;i++) + if(d->v[i] != a) + { + d->b[i]->topo_dist_btw_edges = b_fcus->topo_dist_btw_edges + 1; + d->b[i]->dist_btw_edges = b_fcus->dist_btw_edges + d->b[i]->l->v / 2.; + Get_Dist_Btw_Edges(d,d->v[i],tree); + } + } + + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Detect_Polytomies(t_edge *b, phydbl l_thresh, t_tree *tree) +{ + if((b->l->v < l_thresh) && (!b->left->tax) && (!b->rght->tax)) + { + b->l->v = 0.0; + b->has_zero_br_len = YES; + } + else b->has_zero_br_len = NO; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Get_List_Of_Nodes_In_Polytomy(t_node *a, t_node *d, t_node ***list, int *size_list) +{ + if(d->tax) return; + else + { + int i; + + for(i=0;i<3;i++) + { + if(d->v[i] != a) + { + if(!d->b[i]->has_zero_br_len) + { + (*list)[*size_list] = d->v[i]; + (*size_list)++; + } + + if(d->b[i]->has_zero_br_len) + Get_List_Of_Nodes_In_Polytomy(d,d->v[i],list,size_list); + } + } + } + +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Path_Length(t_node *dep, t_node *arr, phydbl *len, t_tree *tree) +{ + assert(tree->t_dir); + + if(dep==arr) return; + else + { + t_edge *next; + + next = dep->b[tree->t_dir[dep->num*(2*tree->n_otu-2)+arr->num]]; + + if(next == tree->e_root) + { + (*len) += (tree->n_root->b[1]->l->v + tree->n_root->b[2]->l->v); + } + else + { + (*len) += next->l->v; + } + Path_Length(dep->v[tree->t_dir[dep->num*(2*tree->n_otu-2)+arr->num]],arr,len,tree); + return; + } +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Check_Path(t_node *a, t_node *d, t_node *target, t_tree *tree) +{ + PhyML_Printf("path---------\n"); + if(d==target) return; + else Check_Path(d,d->v[tree->t_dir[d->num*(2*tree->n_otu-2)+target->num]],target,tree); +} + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Connect_Two_Nodes(t_node *a, t_node *d) +{ + a->v[0] = d; + d->v[0] = a; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Get_List_Of_Adjacent_Targets(t_node *a, t_node *d, t_node ***node_list, t_edge ***edge_list, int *list_size, int curr_depth, int max_depth) +{ + int i; + + if(a->tax) return; + + for(i=0;i<3;i++) + if(a->v[i] == d) + { + if(node_list != NULL) (*node_list)[*list_size] = a; + if(edge_list != NULL) (*edge_list)[*list_size] = a->b[i]; + (*list_size)++; + } + if(curr_depth == max_depth) return; + if(d->tax) return; + else + for(i=0;i<3;i++) + if(d->v[i] != a) Get_List_Of_Adjacent_Targets(d,d->v[i],node_list,edge_list,list_size,curr_depth+1,max_depth); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Sort_List_Of_Adjacent_Targets(t_edge ***list, int list_size) +{ + t_edge *buff_edge; + int i,j; + + buff_edge = NULL; + + for(i=0;itopo_dist_btw_edges < (*list)[i]->topo_dist_btw_edges) + { + buff_edge = (*list)[j]; + (*list)[j] = (*list)[i]; + (*list)[i] = buff_edge; + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_node *Common_Nodes_Btw_Two_Edges(t_edge *a, t_edge *b) +{ + if(a->left == b->left) return b->left; + else if(a->left == b->rght) return b->rght; + else if(a->rght == b->left) return b->left; + else if(a->rght == b->rght) return b->rght; + + PhyML_Printf("\n. First t_edge = %d (%d %d); Second t_edge = %d (%d %d)\n", + a->num,a->left->num,a->rght->num, + b->num,b->left->num,b->rght->num); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + + return NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int KH_Test(phydbl *site_lk_M1, phydbl *site_lk_M2, t_tree *tree) +{ + phydbl *delta,mean,sd,obs_stat,threshold; + int i; + + + delta = (phydbl *)mCalloc(tree->data->init_len,sizeof(phydbl)); + + threshold = .0; + mean = .0; + obs_stat = .0; + for(i=0;in_pattern;i++) + { + delta[i] = site_lk_M1[i] - site_lk_M2[i]; + mean += ((int)tree->data->wght[i])*delta[i]; + } + + obs_stat = mean; + + mean /= tree->data->init_len; + + for(i=0;idata->init_len;i++) delta[i] -= mean; + + sd = .0; + for(i=0;idata->init_len;i++) sd += POW(delta[i],2); + sd /= (phydbl)(tree->data->init_len-1.); + +/* threshold = tree->dnorm_thresh*SQRT(sd*tree->data->init_len); */ + + +/* PhyML_Printf("\nObs stat = %f Threshold = %f\n",obs_stat,threshold); */ + Free(delta); + + if(obs_stat > threshold) return 1; + else return 0; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Random_Tree(t_tree *tree) +{ + int *is_available,*list_of_nodes; + int i,node_num,step,n_available; + phydbl min_edge_len; + + assert(tree); + + min_edge_len = 1.E-3; + + is_available = (int *)mCalloc(2*tree->n_otu-2,sizeof(int)); + list_of_nodes = (int *)mCalloc(tree->n_otu, sizeof(int)); + + for(i=0;in_otu;i++) is_available[i] = 1; + for(i=0;in_otu;i++) list_of_nodes[i] = i; + + + step = 0; + do + { +/* node_num = (int)RINT(rand()/(phydbl)(RAND_MAX+1.0)*(tree->n_otu-1-step)); */ + node_num = Rand_Int(0,tree->n_otu-1-step); + node_num = list_of_nodes[node_num]; + is_available[node_num] = 0; + for(i=0;in_otu;i++) list_of_nodes[i] = -1; + n_available = 0; + For(i,2*tree->n_otu-2) if(is_available[i]) {list_of_nodes[n_available++] = i;} + + tree->a_nodes[node_num]->v[0] = tree->a_nodes[tree->n_otu+step]; + tree->a_nodes[tree->n_otu+step]->v[1] = tree->a_nodes[node_num]; + +/* node_num = (int)RINT(rand()/(phydbl)(RAND_MAX+1.0)*(tree->n_otu-2-step)); */ + node_num = Rand_Int(0,tree->n_otu-2-step); + node_num = list_of_nodes[node_num]; + is_available[node_num] = 0; + for(i=0;in_otu;i++) list_of_nodes[i] = -1; + n_available = 0; + For(i,2*tree->n_otu-2) if(is_available[i]) {list_of_nodes[n_available++] = i;} + + tree->a_nodes[node_num]->v[0] = tree->a_nodes[tree->n_otu+step]; + tree->a_nodes[tree->n_otu+step]->v[2] = tree->a_nodes[node_num]; + + is_available[tree->n_otu+step] = 1; + for(i=0;in_otu;i++) list_of_nodes[i] = -1; + n_available = 0; + For(i,2*tree->n_otu-2) if(is_available[i]) list_of_nodes[n_available++] = i; + + step++; + }while(step < tree->n_otu-2); + + tree->a_nodes[list_of_nodes[0]]->v[0] = tree->a_nodes[list_of_nodes[1]]; + tree->a_nodes[list_of_nodes[1]]->v[0] = tree->a_nodes[list_of_nodes[0]]; + + Connect_Edges_To_Nodes_Serial(tree); + + for(i=0;i<2*tree->n_otu-3;++i) if(tree->a_edges[i]->l->v < min_edge_len) tree->a_edges[i]->l->v = min_edge_len; + + Free(is_available); + Free(list_of_nodes); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Make sure internal edges have likelihood vectors on both +// sides and external edges have one likelihood vector on the +// lefthand side only +// Note: make sure p_lk_tips vector are re-initialized after +// calling this function +void Reorganize_Edges_Given_Lk_Struct(t_tree *tree) +{ + int j,i; + + if(tree->is_mixt_tree == YES) return; + + for(i=0;i<2*tree->n_otu-1;++i) + { + if(tree->a_edges[i]->p_lk_left && tree->a_edges[i]->left->tax == YES) + { + for(j=0;j<2*tree->n_otu-1;++j) + { + if(!tree->a_edges[j]->p_lk_left && tree->a_edges[j]->left->tax == NO) + { + Swap_Partial_Lk(tree->a_edges[i],tree->a_edges[j],LEFT,LEFT,tree); + break; + } + if(!tree->a_edges[j]->p_lk_rght && tree->a_edges[j]->rght->tax == NO) + { + Swap_Partial_Lk(tree->a_edges[i],tree->a_edges[j],LEFT,RGHT,tree); + break; + } + } + } + + if(tree->a_edges[i]->p_lk_rght && tree->a_edges[i]->rght->tax == YES) + { + for(j=0;j<2*tree->n_otu-1;++j) + { + if(!tree->a_edges[j]->p_lk_left && tree->a_edges[j]->left->tax == NO) + { + Swap_Partial_Lk(tree->a_edges[i],tree->a_edges[j],RGHT,LEFT,tree); + break; + } + if(!tree->a_edges[j]->p_lk_rght && tree->a_edges[j]->rght->tax == NO) + { + Swap_Partial_Lk(tree->a_edges[i],tree->a_edges[j],RGHT,RGHT,tree); + break; + } + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Swap_Partial_Lk(t_edge *a, t_edge *b, int side_a, int side_b, t_tree *tree) +{ + phydbl *buff_p_lk; + int *buff_scale; + int *buff_p_pars; + int *buff_pars; + int *buff_p_lk_loc, *buff_patt_id; + phydbl *buff_p_lk_tip; + int *buff_ui; + + + if(side_a == LEFT && side_b == LEFT) + { + buff_p_lk = b->p_lk_left; + b->p_lk_left = a->p_lk_left; + a->p_lk_left = buff_p_lk; + + buff_p_lk_tip = b->p_lk_tip_l; + b->p_lk_tip_l = a->p_lk_tip_l; + a->p_lk_tip_l = buff_p_lk_tip; + + buff_scale = b->sum_scale_left_cat; + b->sum_scale_left_cat = a->sum_scale_left_cat; + a->sum_scale_left_cat = buff_scale; + + buff_scale = b->sum_scale_left; + b->sum_scale_left = a->sum_scale_left; + a->sum_scale_left = buff_scale; + + buff_patt_id = b->patt_id_left; + b->patt_id_left = a->patt_id_left; + a->patt_id_left = buff_patt_id; + + buff_p_lk_loc = b->p_lk_loc_left; + b->p_lk_loc_left = a->p_lk_loc_left; + a->p_lk_loc_left = buff_p_lk_loc; + + buff_pars = b->pars_l; + b->pars_l = a->pars_l; + a->pars_l = buff_pars; + + buff_p_pars = b->p_pars_l; + b->p_pars_l = a->p_pars_l; + a->p_pars_l = buff_p_pars; + + buff_ui = b->ui_l; + b->ui_l = a->ui_l; + a->ui_l = buff_ui; + +#ifdef BEAGLE + temp = b->p_lk_left_idx; + b->p_lk_left_idx = a->p_lk_left_idx; + a->p_lk_left_idx = temp; + + temp = b->p_lk_tip_idx; + b->p_lk_tip_idx = a->p_lk_tip_idx; + a->p_lk_tip_idx = temp; +#endif + } + + if(side_a == LEFT && side_b == RGHT) + { + buff_p_lk = b->p_lk_rght; + b->p_lk_rght = a->p_lk_left; + a->p_lk_left = buff_p_lk; + + buff_p_lk_tip = b->p_lk_tip_r; + b->p_lk_tip_r = a->p_lk_tip_l; + a->p_lk_tip_l = buff_p_lk_tip; + + buff_scale = b->sum_scale_rght_cat; + b->sum_scale_rght_cat = a->sum_scale_left_cat; + a->sum_scale_left_cat = buff_scale; + + buff_scale = b->sum_scale_rght; + b->sum_scale_rght = a->sum_scale_left; + a->sum_scale_left = buff_scale; + + buff_patt_id = b->patt_id_rght; + b->patt_id_rght = a->patt_id_left; + a->patt_id_left = buff_patt_id; + + buff_p_lk_loc = b->p_lk_loc_rght; + b->p_lk_loc_rght = a->p_lk_loc_left; + a->p_lk_loc_left = buff_p_lk_loc; + + buff_pars = b->pars_r; + b->pars_r = a->pars_l; + a->pars_l = buff_pars; + + buff_p_pars = b->p_pars_r; + b->p_pars_r = a->p_pars_l; + a->p_pars_l = buff_p_pars; + + buff_ui = b->ui_r; + b->ui_r = a->ui_l; + a->ui_l = buff_ui; + +#ifdef BEAGLE + temp = b->p_lk_rght_idx; + b->p_lk_rght_idx = a->p_lk_left_idx; + a->p_lk_left_idx = temp; + + temp = b->p_lk_tip_idx; + b->p_lk_tip_idx = a->p_lk_tip_idx; + a->p_lk_tip_idx = temp; +#endif + } + + if(side_a == RGHT && side_b == LEFT) + { + buff_p_lk = b->p_lk_left; + b->p_lk_left = a->p_lk_rght; + a->p_lk_rght = buff_p_lk; + + buff_p_lk_tip = b->p_lk_tip_l; + b->p_lk_tip_l = a->p_lk_tip_r; + a->p_lk_tip_r = buff_p_lk_tip; + + buff_scale = b->sum_scale_left_cat; + b->sum_scale_left_cat = a->sum_scale_rght_cat; + a->sum_scale_rght_cat = buff_scale; + + buff_scale = b->sum_scale_left; + b->sum_scale_left = a->sum_scale_rght; + a->sum_scale_rght = buff_scale; + + buff_patt_id = b->patt_id_left; + b->patt_id_left = a->patt_id_rght; + a->patt_id_rght = buff_patt_id; + + buff_p_lk_loc = b->p_lk_loc_left; + b->p_lk_loc_left = a->p_lk_loc_rght; + a->p_lk_loc_rght = buff_p_lk_loc; + + buff_pars = b->pars_l; + b->pars_l = a->pars_r; + a->pars_r = buff_pars; + + buff_p_pars = b->p_pars_l; + b->p_pars_l = a->p_pars_r; + a->p_pars_r = buff_p_pars; + + buff_ui = b->ui_l; + b->ui_l = a->ui_r; + a->ui_r = buff_ui; + +#ifdef BEAGLE + temp = b->p_lk_left_idx; + b->p_lk_left_idx = a->p_lk_rght_idx; + a->p_lk_rght_idx = temp; + + temp = b->p_lk_tip_idx; + b->p_lk_tip_idx = a->p_lk_tip_idx; + a->p_lk_tip_idx = temp; +#endif + } + + if(side_a == RGHT && side_b == RGHT) + { + buff_p_lk = b->p_lk_rght; + b->p_lk_rght = a->p_lk_rght; + a->p_lk_rght = buff_p_lk; + + buff_p_lk_tip = b->p_lk_tip_r; + b->p_lk_tip_r = a->p_lk_tip_r; + a->p_lk_tip_r = buff_p_lk_tip; + + buff_scale = b->sum_scale_rght_cat; + b->sum_scale_rght_cat = a->sum_scale_rght_cat; + a->sum_scale_rght_cat = buff_scale; + + buff_scale = b->sum_scale_rght; + b->sum_scale_rght = a->sum_scale_rght; + a->sum_scale_rght = buff_scale; + + buff_patt_id = b->patt_id_rght; + b->patt_id_rght = a->patt_id_rght; + a->patt_id_rght = buff_patt_id; + + buff_p_lk_loc = b->p_lk_loc_rght; + b->p_lk_loc_rght = a->p_lk_loc_rght; + a->p_lk_loc_rght = buff_p_lk_loc; + + buff_pars = b->pars_r; + b->pars_r = a->pars_r; + a->pars_r = buff_pars; + + buff_p_pars = b->p_pars_r; + b->p_pars_r = a->p_pars_r; + a->p_pars_r = buff_p_pars; + + buff_ui = b->ui_r; + b->ui_r = a->ui_r; + a->ui_r = buff_ui; + +#ifdef BEAGLE + temp = b->p_lk_rght_idx; + b->p_lk_rght_idx = a->p_lk_rght_idx; + a->p_lk_rght_idx = temp; + + temp = b->p_lk_tip_idx; + b->p_lk_tip_idx = a->p_lk_tip_idx; + a->p_lk_tip_idx = temp; +#endif + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Random_NNI(int n_moves, t_tree *tree) +{ + int i,j; + t_edge *b; + t_node *n1,*n2,*n_target; + + n1 = n2 = NULL; + b = NULL; + for(i=0;ia_nodes[tree->n_otu + (int)((phydbl)rand()/RAND_MAX * (2*tree->n_otu-3-tree->n_otu))]; + for(j=0;j<3;++j) if(!n_target->v[j]->tax) {b = n_target->b[j]; break;} + + for(j=0;j<3;++j) if(b->left->v[j] != b->rght) {n1 = b->left->v[j]; break;} + for(j=0;j<3;++j) if(b->rght->v[j] != b->left) {n2 = b->rght->v[j]; break;} + + Swap(n1,b->left,b->rght,n2,tree); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Fill_Missing_Dist(matrix *mat) +{ + int i,j; + + for(i=0;in_otu;i++) + { + for(j=i+1;jn_otu;j++) + { + if(i != j) + { + if(mat->dist[i][j] < .0) + { + Fill_Missing_Dist_XY(i,j,mat); + mat->dist[j][i] = mat->dist[i][j]; + } + } + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +void Fill_Missing_Dist_XY(int x, int y, matrix *mat) +{ + + int i,j; + phydbl *local_mins,**S1S2; + int cpt; + int pos_best_estimate; + phydbl min_crit, curr_crit; + + local_mins = (phydbl *)mCalloc(mat->n_otu*mat->n_otu,sizeof(phydbl )); + S1S2 = (phydbl **)mCalloc(mat->n_otu*mat->n_otu,sizeof(phydbl *)); + For(i,mat->n_otu*mat->n_otu) S1S2[i] = (phydbl *)mCalloc(2,sizeof(phydbl)); + + cpt = 0; + for(i=0;in_otu;i++) + { + if((mat->dist[i][x] > .0) && (mat->dist[i][y] > .0)) + { + for(j=0;jn_otu;j++) + { + if((mat->dist[j][x] > .0) && (mat->dist[j][y] > .0)) + { + if((i != j) && (i != x) && (i != y) && (j != x) && (j != y)) + { + S1S2[cpt][0] = MIN(mat->dist[i][x] + mat->dist[j][y] - mat->dist[i][j] , mat->dist[i][y] + mat->dist[j][x] - mat->dist[i][j]); + S1S2[cpt][1] = MAX(mat->dist[i][x] + mat->dist[j][y] - mat->dist[i][j] , mat->dist[i][y] + mat->dist[j][x] - mat->dist[i][j]); + cpt++; + } + } + } + } + } + + Qksort_Matrix(S1S2,0,0,cpt-1); + + local_mins[0] = S1S2[0][1]; + for(i=1;i S1S2[i][0])) + { + curr_crit = Least_Square_Missing_Dist_XY(x,y,local_mins[i],mat); + if(curr_crit < min_crit) + { + min_crit = curr_crit; + pos_best_estimate = i; + } + } + } + + mat->dist[x][y] = local_mins[pos_best_estimate]; + mat->dist[y][x] = mat->dist[x][y]; + + For(i,mat->n_otu*mat->n_otu) Free(S1S2[i]); + Free(S1S2); + Free(local_mins); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +phydbl Least_Square_Missing_Dist_XY(int x, int y, phydbl dxy, matrix *mat) +{ + int i,j; + phydbl fit; + + fit = .0; + for(i=0;in_otu;i++) + { + if((mat->dist[i][x] > .0) && (mat->dist[i][y] > .0)) + { + for(j=0;jn_otu;j++) + { + if((mat->dist[j][x] > .0) && (mat->dist[j][y] > .0)) + { + if((i != j) && (i != x) && (i != y) && (j != x) && (j != y)) + { + if(dxy < MIN(mat->dist[i][x] + mat->dist[j][y] - mat->dist[i][j] , mat->dist[i][y] + mat->dist[j][x] - mat->dist[i][j])) + { + fit += POW((mat->dist[i][x] + mat->dist[j][y]) - (mat->dist[i][y] + mat->dist[j][x]),2); + } + else if((mat->dist[i][x] + mat->dist[j][y]) < (mat->dist[i][y] + mat->dist[j][x])) + { + fit += POW(dxy - (mat->dist[i][y] + mat->dist[j][x] - mat->dist[i][j]),2); + } + else + { + fit += POW(dxy - (mat->dist[i][x] + mat->dist[j][y] - mat->dist[i][j]),2); + } + } + } + } + } + } + return fit; +} - Alloc_Bip(boot_tree); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - Get_Bip(boot_tree->noeud[0], - boot_tree->noeud[0]->v[0], - boot_tree); +void Check_Memory_Amount(t_tree *tree) +{ + /* Rough estimate of the amount of memory that has to be used */ - if(!tree->io->collapse_boot) - Compare_Bip(tree,boot_tree); - else - Compare_Bip_On_Existing_Edges(1,tree,boot_tree); + long int nbytes; + int n_otu; + t_mod *mod; - Br_Len_Involving_Invar(boot_tree); + mod = tree->mod; + n_otu = tree->io->n_otu; + nbytes = 0; - if(tree->io->print_boot_trees) - { - s = Write_Tree(boot_tree); - fprintf(tree->io->fp_out_boot_tree,"%s\n",s); - Free(s); - Print_Fp_Out_Lines(tree->io->fp_out_boot_stats,0,0,boot_tree,tree->io,replicate+1); - } + /* Partial Pars */ + /* pars_r */ + nbytes += (2*n_otu-3) * 2 * tree->data->crunch_len * sizeof(int); + /* ui_r */ + nbytes += (2*n_otu-3) * 2 * tree->data->crunch_len * sizeof(int); + /* p_pars_r */ + nbytes += (2*n_otu-3) * 2 * tree->data->crunch_len * mod->ns * sizeof(int); + /* n_diff_states_r */ + nbytes += (2*n_otu-3) * 2 * mod->ns * sizeof(int); + /* Pmat */ + /* Pij_rr */ + nbytes += (2*n_otu-3) * mod->ras->n_catg * mod->ns * mod->ns * sizeof(phydbl); + /* tPij_rr */ + nbytes += (2*n_otu-3) * mod->ras->n_catg * mod->ns * mod->ns * sizeof(phydbl); - /* rf = .0; */ - /* For(j,2*tree->n_otu-3) */ - /* rf += tree->t_edges[j]->bip_score; */ + /* Partial Lk */ + /* p_lk */ + nbytes += ((2*n_otu-3) * 2 - tree->n_otu) * tree->data->crunch_len * mod->ras->n_catg * mod->ns * sizeof(phydbl); + /* p_lk_tip */ + nbytes += (tree->n_otu) * tree->data->crunch_len * mod->ns * sizeof(phydbl); - printf("."); -#ifndef QUIET -fflush(stdout); -#endif - if(!((replicate+1)%20)) - { - printf("] %4d/%4d\n ",replicate+1,tree->mod->bootstrap); - if(replicate != tree->mod->bootstrap-1) printf("["); - } - if(boot_tree->mat) Free_Mat(boot_tree->mat); - Free_Tree(boot_tree); - Free_Model(boot_mod); - } + /* Scaling factors */ + /* sum_scale */ + nbytes += ((2*n_otu-3) * 2 - tree->n_otu) * tree->data->crunch_len * mod->ras->n_catg * sizeof(int); - if(((replicate)%20)) printf("] %4d/%4d\n ",replicate,tree->mod->bootstrap); - tree->lock_topo = 1; /* Topology should not be modified afterwards */ + if(((phydbl)nbytes/(1.E+06)) > 256.) +/* if(((phydbl)nbytes/(1.E+06)) > 0.) */ + { + PhyML_Printf("\n\n. WARNING: this analysis requires at least %.0f MB of memory space.\n",(phydbl)nbytes/(1.E+06)); +#ifndef BATCH - if(tree->io->print_boot_trees) + char answer; + if((!tree->io->quiet) && (tree->io->mem_question == YES)) + { + PhyML_Printf("\n. Do you really want to proceed? [Y/n] "); + if(scanf("%c", &answer)) + { + if(answer == '\n') answer = 'Y'; + else if(answer == 'n' || answer == 'N') Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + else getchar(); + } + else + { + Warn_And_Exit("\n\n"); + } + } +#endif + } + else if(((phydbl)nbytes/(1.E+06)) > 100.) { - fclose(tree->io->fp_out_boot_tree); - fclose(tree->io->fp_out_boot_stats); + if(!tree->io->quiet) PhyML_Printf("\n\n. WARNING: this analysis will use at least %.0f MB of memory space...\n",(phydbl)nbytes/(1.E+06)); } + else if(((phydbl)nbytes/(1.E+06)) > 1.) + { + if(!tree->io->quiet) PhyML_Printf("\n\n. This analysis requires at least %.0f MB of memory space.\n",(phydbl)nbytes/(1.E+06)); + } +} - Free_Cseq(boot_data); - Free(site_num); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +int Get_State_From_Partial_Lk(phydbl *p_lk, int pos, t_tree *tree) +{ + int i; + for(i=0;imod->ns;i++) if(p_lk[pos+i] > .0) return i; + return -1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void Br_Len_Involving_Invar(arbre *tree) +int Get_State_From_Partial_Pars(short int *p_pars, int pos, t_tree *tree) { int i; - For(i,2*tree->n_otu-3) tree->t_edges[i]->l *= (1.0-tree->mod->pinvar); + for(i=0;imod->ns;i++) if(p_pars[pos+i] > .0) return i; + return -1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void Br_Len_Not_Involving_Invar(arbre *tree) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Check_Dirs(t_tree *tree) { int i; - For(i,2*tree->n_otu-3) tree->t_edges[i]->l /= (1.0-tree->mod->pinvar); + + For(i,2*tree->n_otu-3) + { + if(!tree->a_edges[i]->left->tax) + { + if(tree->a_edges[i]->left->v[tree->a_edges[i]->l_v1]->num < + tree->a_edges[i]->left->v[tree->a_edges[i]->l_v2]->num) + { + PhyML_Printf("\n. Edge %d ; v1=%d v2=%d", + tree->a_edges[i]->num, + tree->a_edges[i]->left->v[tree->a_edges[i]->l_v1]->num, + tree->a_edges[i]->left->v[tree->a_edges[i]->l_v2]->num); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + } + + if(!tree->a_edges[i]->rght->tax) + { + if(tree->a_edges[i]->rght->v[tree->a_edges[i]->r_v1]->num < + tree->a_edges[i]->rght->v[tree->a_edges[i]->r_v2]->num) + { + PhyML_Printf("\n. Edge %d ; v3=%d v4=%d", + tree->a_edges[i]->num, + tree->a_edges[i]->rght->v[tree->a_edges[i]->r_v1]->num, + tree->a_edges[i]->rght->v[tree->a_edges[i]->r_v2]->num); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } + } + } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Getstring_Stdin(char *file_name) +void Warn_And_Exit(const char *s) { - fgets(file_name,T_MAX_LINE,stdin); - if (strchr(file_name, '\n') != NULL) - *strchr(file_name, '\n') = '\0'; + PhyML_Fprintf(stderr,"%s",s); + fflush(NULL); +#ifndef BATCH + PhyML_Fprintf(stderr,"\n. Type enter to exit.\n"); + Exit(""); +#endif + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Print_Freq(arbre *tree) +// Apply random prune and regraft moves to an existing tree. As opposed to Random_Tree, using this +// function does not break the likelihood structure. +void Randomize_Tree(t_tree *tree, int n_prune_regraft) { + t_node *rnd_node; + t_edge *rnd_edge,*b_target,*b_residual,**target_list; + int n_targets,n_rand,i; - switch(tree->mod->datatype) + target_list = (t_edge **)mCalloc(2*tree->n_otu-3,sizeof(t_edge *)); + + n_rand = n_prune_regraft; + do { - case NT: - { - printf("A : %f\n",tree->mod->pi[0]); - printf("C : %f\n",tree->mod->pi[1]); - printf("G : %f\n",tree->mod->pi[2]); - printf("T : %f\n",tree->mod->pi[3]); - - printf("U : %f\n",tree->mod->pi[4]); - printf("M : %f\n",tree->mod->pi[5]); - printf("R : %f\n",tree->mod->pi[6]); - printf("W : %f\n",tree->mod->pi[7]); - printf("S : %f\n",tree->mod->pi[8]); - printf("Y : %f\n",tree->mod->pi[9]); - printf("K : %f\n",tree->mod->pi[10]); - printf("B : %f\n",tree->mod->pi[11]); - printf("D : %f\n",tree->mod->pi[12]); - printf("H : %f\n",tree->mod->pi[13]); - printf("V : %f\n",tree->mod->pi[14]); - printf("N : %f\n",tree->mod->pi[15]); - break; - } - case AA: - { - printf("A : %f\n",tree->mod->pi[0]); - printf("R : %f\n",tree->mod->pi[1]); - printf("N : %f\n",tree->mod->pi[2]); - printf("D : %f\n",tree->mod->pi[3]); - printf("C : %f\n",tree->mod->pi[4]); - printf("Q : %f\n",tree->mod->pi[5]); - printf("E : %f\n",tree->mod->pi[6]); - printf("G : %f\n",tree->mod->pi[7]); - printf("H : %f\n",tree->mod->pi[8]); - printf("I : %f\n",tree->mod->pi[9]); - printf("L : %f\n",tree->mod->pi[10]); - printf("K : %f\n",tree->mod->pi[11]); - printf("M : %f\n",tree->mod->pi[12]); - printf("F : %f\n",tree->mod->pi[13]); - printf("P : %f\n",tree->mod->pi[14]); - printf("S : %f\n",tree->mod->pi[15]); - printf("T : %f\n",tree->mod->pi[16]); - printf("W : %f\n",tree->mod->pi[17]); - printf("Y : %f\n",tree->mod->pi[18]); - printf("V : %f\n",tree->mod->pi[19]); - - printf("N : %f\n",tree->mod->pi[20]); - break; - } - default : {break;} + rnd_node = tree->a_nodes[Rand_Int(tree->n_otu,2*tree->n_otu-3)]; + assert(rnd_node != tree->n_root && rnd_node->tax == NO); + + rnd_edge = rnd_node->b[Rand_Int(0,2)]; + + Prune_Subtree(rnd_node, + rnd_node == rnd_edge->left ? rnd_edge->rght : rnd_edge->left, + &b_target, + &b_residual, + tree); + + n_targets = 0; + for(i=0;i<3;i++) + if(b_target->left->v[i] != b_target->rght) + Get_List_Of_Adjacent_Targets(b_target->left,b_target->left->v[i],NULL,&target_list,&n_targets,0,tree->n_otu); + + for(i=0;i<3;i++) + if(b_target->rght->v[i] != b_target->left) + Get_List_Of_Adjacent_Targets(b_target->rght,b_target->rght->v[i],NULL,&target_list,&n_targets,0,tree->n_otu); + + if(n_targets > 0) b_target = target_list[Rand_Int(0,n_targets-1)]; + + assert(b_target != NULL); + + Graft_Subtree(b_target,rnd_node,NULL,b_residual,NULL,tree); + + n_rand--; } + while(n_rand > 0); + + Free(target_list); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -phydbl Num_Derivatives_One_Param(phydbl (*func)(arbre *tree), arbre *tree, - phydbl f0, phydbl *param, phydbl stepsize, - phydbl *err, int precise) +void Randomize_Sequence_Order(calign *cdata) { - int i,j; - phydbl errt,fac,hh,**a,ans; - int n_iter; - a = (phydbl **)mCalloc(11,sizeof(phydbl *)); - For(i,11) a[i] = (phydbl *)mCalloc(11,sizeof(phydbl)); + int i,exchange_with; + phydbl buff_dbl; + char *buff_name,*buff_state; + short int *buff_ambigu; + + exchange_with = -1; + for(i=0;in_otu;i++) + { + buff_dbl = rand(); + buff_dbl /= (RAND_MAX+1.); + buff_dbl *= cdata->n_otu; + exchange_with = (int)FLOOR(buff_dbl); + buff_name = cdata->c_seq[i]->name; + cdata->c_seq[i]->name = cdata->c_seq[exchange_with]->name; + cdata->c_seq[exchange_with]->name = buff_name; - n_iter = 10; /* */ + buff_state = cdata->c_seq[i]->state; + cdata->c_seq[i]->state = cdata->c_seq[exchange_with]->state; + cdata->c_seq[exchange_with]->state = buff_state; - ans = .0; + buff_ambigu = cdata->c_seq[i]->is_ambigu; + cdata->c_seq[i]->is_ambigu = cdata->c_seq[exchange_with]->is_ambigu; + cdata->c_seq[exchange_with]->is_ambigu = buff_ambigu; + } +} - if (stepsize == 0.0) Warn_And_Exit("\n. h must be nonzero in Dfridr."); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - hh=stepsize; - if(!precise) +void Update_Root_Pos(t_tree *tree) +{ + if(tree->n_root_pos > -1.0) + { + tree->n_root->b[2]->l->v = tree->e_root->l->v * tree->n_root_pos; + tree->n_root->b[1]->l->v = tree->e_root->l->v * (1.-tree->n_root_pos); + } + else { +/* tree->n_root->l[0]->v = tree->e_root->l->v / 2.; */ +/* tree->n_root->l[1]->v = tree->e_root->l->v / 2.; */ + } +} - *param = *param+hh; - a[0][0] = (*func)(tree); - a[0][0] -= f0; - a[0][0] /= hh; - *param = *param-hh; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - ans = a[0][0]; +void Add_Root(t_edge *target, t_tree *tree) +{ + t_edge *b1, *b2; + + assert(target); + assert(tree); + + #ifndef PHYML + /* PhyML_Printf("\n. Adding root on t_edge %d left = %d right = %d.",target->num,target->left ? target->left->num : -1, target->rght ? target->rght->num : -1); fflush(NULL) */; + #endif + + tree->e_root = target; + + /* Create the root t_node if it does not exist yet */ + if(!tree->a_nodes[2*tree->n_otu-2]) tree->n_root = (t_node *)Make_Node_Light(2*tree->n_otu-2); + else tree->n_root = tree->a_nodes[2*tree->n_otu-2]; + + + tree->a_nodes[2*tree->n_otu-2] = tree->n_root; + + tree->n_root->tax = 0; + + /* Set the position of the root */ + tree->n_root->v[0] = NULL; + tree->n_root->v[1] = tree->e_root->left; + tree->n_root->v[2] = tree->e_root->rght; + + /* tree->n_root->b[2] = tree->e_root; */ + /* tree->n_root->b[1] = tree->e_root; */ + + b1 = tree->a_edges[2*tree->n_otu-3]; + b2 = tree->a_edges[2*tree->n_otu-2]; + + tree->n_root->b[0] = NULL; + tree->n_root->b[1] = b1; + tree->n_root->b[2] = b2; + + if(tree->n_root_pos > -1.0) + { + if(tree->n_root_pos < 1.E-6 && tree->n_root_pos > -1.E-6) + { + printf("\n. WARNING: you put the root at a weird position..."); + } + + tree->n_root->b[2]->l->v = tree->e_root->l->v * tree->n_root_pos; + tree->n_root->b[1]->l->v = tree->e_root->l->v * (1. - tree->n_root_pos); + PhyML_Printf("\n. ROOTPOS: %f L: %f L2: %f", + tree->n_root_pos, + tree->e_root->l->v, + tree->n_root->b[2]->l->v); } else { - *param = *param+hh; - a[0][0] = (*func)(tree); - /* *param = *param-2*hh; */ - /* a[0][0] -= (*func)(tree); */ - /* a[0][0] /= (2.0*hh); */ - /* *param = *param+hh; */ - a[0][0] -= f0; - a[0][0] /= hh; - *param = *param-hh; + tree->n_root->b[2]->l->v = tree->e_root->l->v / 2.; + tree->n_root->b[1]->l->v = tree->e_root->l->v / 2.; + tree->n_root_pos = 0.5; + } - *err=1e30; - for(i=1;inum = tree->num_curr_branch_available; + b2->num = tree->num_curr_branch_available+1; + b1->left = tree->n_root; + b1->rght = tree->n_root->v[1]; + b2->left = tree->n_root; + b2->rght = tree->n_root->v[2]; - /* *param = *param+hh; */ - /* a[0][i] = (*func)(tree); */ - /* *param = *param-2*hh; */ - /* a[0][i] -= (*func)(tree); */ - /* a[0][i] /= (2.0*hh); */ - /* *param = *param+hh; */ + b1->l->v = tree->n_root->b[1]->l->v; + b2->l->v = tree->n_root->b[2]->l->v; + b1->l_old->v = tree->n_root->b[1]->l->v; + b2->l_old->v = tree->n_root->b[2]->l->v; + b1->l_r = 1; + b2->l_r = 2; - *param = *param+hh; - a[0][i] = (*func)(tree); - /* *param = *param-2*hh; */ - /* a[0][i] -= (*func)(tree); */ - /* a[0][i] /= (2.0*hh); */ - /* *param = *param+hh; */ - a[0][i] -= f0; - a[0][i] /= hh; - *param = *param-hh; + b1->r_l = 0; + b2->r_l = 0; + b1->l_v1 = 0; + b1->l_v2 = 2; - fac=1.4*1.4; - for (j=1;j<=i;j++) - { - a[j][i]=(a[j-1][i]*fac-a[j-1][i-1])/(fac-1.0); - fac=1.4*1.4*fac; + b2->l_v1 = 0; + b2->l_v2 = 1; - errt=MAX(fabs(a[j][i]-a[j-1][i]),fabs(a[j][i]-a[j-1][i-1])); + b1->r_v1 = 1; + b1->r_v2 = 2; - if (errt <= *err) - { - *err=errt; - ans=a[j][i]; - } - } + b2->r_v1 = 1; + b2->r_v2 = 2; - if(fabs(a[i][i]-a[i-1][i-1]) >= 2.0*(*err)) break; - } + /* WARNING: make sure you have freed the memory for p_lk_rght on b1 and b2 */ + if(tree->is_mixt_tree == NO) + { + b1->p_lk_rght = tree->e_root->p_lk_left; + b2->p_lk_rght = tree->e_root->p_lk_rght; + + b1->p_lk_tip_r = tree->e_root->p_lk_tip_l; + b2->p_lk_tip_r = tree->e_root->p_lk_tip_r; + + b1->sum_scale_rght = tree->e_root->sum_scale_left; + b2->sum_scale_rght = tree->e_root->sum_scale_rght; + + b1->sum_scale_rght_cat = tree->e_root->sum_scale_left_cat; + b2->sum_scale_rght_cat = tree->e_root->sum_scale_rght_cat; + + b1->p_lk_loc_rght = tree->e_root->p_lk_loc_left; + b2->p_lk_loc_rght = tree->e_root->p_lk_loc_rght; + + b1->pars_r = tree->e_root->pars_l; + b2->pars_r = tree->e_root->pars_r; + + b1->ui_r = tree->e_root->ui_l; + b2->ui_r = tree->e_root->ui_r; + + b1->p_pars_r = tree->e_root->p_pars_l; + b2->p_pars_r = tree->e_root->p_pars_r; + + b1->p_lk_loc_rght = tree->e_root->p_lk_loc_left; + b2->p_lk_loc_rght = tree->e_root->p_lk_loc_rght; + + b1->patt_id_rght = tree->e_root->patt_id_left; + b2->patt_id_rght = tree->e_root->patt_id_rght; } - For(i,11) Free(a[i]); - Free(a); - return ans; + Update_Ancestors(tree->n_root,tree->n_root->v[2],tree); + Update_Ancestors(tree->n_root,tree->n_root->v[1],tree); + tree->n_root->anc = NULL; + + if(tree->is_mixt_tree == YES) MIXT_Add_Root(target,tree); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Num_Derivative_Several_Param(arbre *tree, phydbl *param, int n_param, phydbl stepsize, - phydbl (*func)(arbre *tree), phydbl *derivatives) +void Update_Ancestors(t_node *a, t_node *d, t_tree *tree) { - int i; - phydbl err,f0; + if(d == NULL) + { + PhyML_Printf("\n. d is NULL; a: %d root: %d",a->num,tree->n_root->num); + assert(FALSE); + } - f0 = (*func)(tree); + d->anc = a; + + if(a == tree->n_root) a->anc = NULL; - For(i,n_param) + if(d->tax) return; + else { - derivatives[i] = Num_Derivatives_One_Param(func, - tree, - f0, - param+i, - stepsize, - &err, - 0 - ); + int i; + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + Update_Ancestors(d,d->v[i],tree); } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Compare_Two_States(char *state1, char *state2, int state_size) +/* Generate a random unrooted tree with 'n_otu' OTUs */ +t_tree *Generate_Random_Tree_From_Scratch(int n_otu, int rooted) { - /* 1 the two states are identical */ - /* 0 the two states are different */ - int i; + t_tree *tree; + int *connected,*nonconnected,*available_nodes; + int i,n_connected,n_nonconnected,n1,n2,new_n,n_internal,n_external,n_available; + t_node *root,*curr_n,**internal_nodes, **external_nodes; + phydbl *t,*tmp; - For(i,state_size) if(state1[i] != state2[i]) break; + tree = Make_Tree_From_Scratch(n_otu,NULL); - return (i==state_size)?(1):(0); + tree->rates = RATES_Make_Rate_Struct(tree->n_otu); + RATES_Init_Rate_Struct(tree->rates,NULL,tree->n_otu); + + for(i=0;i<2*tree->n_otu-2;++i) + { + tree->a_nodes[i]->v[1] = NULL; + tree->a_nodes[i]->v[2] = NULL; + } + + root = (t_node *)Make_Node_Light(2*tree->n_otu-2); + + connected = (int *)mCalloc(2*tree->n_otu-2,sizeof(int)); + nonconnected = (int *)mCalloc(2*tree->n_otu-2,sizeof(int)); + available_nodes = (int *)mCalloc(2*tree->n_otu-2,sizeof(int)); + internal_nodes = (t_node **)mCalloc(tree->n_otu-2,sizeof(t_node *)); + external_nodes = (t_node **)mCalloc(tree->n_otu, sizeof(t_node *)); + t = (phydbl *)mCalloc(tree->n_otu-1,sizeof(phydbl )); + tmp = (phydbl *)mCalloc(2*tree->n_otu-2,sizeof(phydbl )); + + n_nonconnected = 2*n_otu-2; + + for(i=0;i<2*tree->n_otu-2;++i) nonconnected[i] = i; + + available_nodes[0] = 2*n_otu-2; + + /* Node times are generated according to a Birth-death process. + Formulae are as described by Yang and Rannala (1997) */ + phydbl phi; + phydbl rho; /* sampling intensity */ + phydbl mu; /* birth rate */ + phydbl lambda; /* death rate */ + phydbl u; /* random U[0,1] */ + phydbl expval; + + /* rho = 1.0 and mu = 0.0 correspond to the Yule process */ + + lambda = 6.7; + mu = 2.5; + rho = 9./150.; + + expval = exp(MIN(1.E+2,mu-lambda)); + phi = (rho*lambda*(expval-1.) + (mu-lambda)*expval)/(expval-1.); /* Equation 16 */ + + for(i=0;in_otu-1;i++) + { + u = rand(); + u /= RAND_MAX; + + if(fabs(lambda - mu) > 1.E-4) + t[i] = (log(phi-u*rho*lambda) - log(phi-u*rho*lambda + u*(lambda-mu)))/(mu-lambda); /* Equation 15 */ + else + t[i] = u / (1.+lambda*rho*(1-u)); /* Equation 17 */ + } + + Qksort(t,NULL,0,tree->n_otu-2); /* Node times ordering in ascending order */ + + for(i=0;in_otu-1;i++) tmp[i] = t[tree->n_otu-2-i]; + for(i=0;in_otu-1;i++) t[i] = -tmp[i]; + + + /* Rescale t_node times such that the time at the root t_node is -100 */ + for(i=1;in_otu-1;i++) + { + t[i] /= -t[0]; + t[i] *= 1.E+02; + } + t[0] = -1.E+02; + + + n_available = 1; + curr_n = root; + n_connected = 0; + do + { + n1 = Rand_Int(0,n_nonconnected-1); + n1 = nonconnected[n1]; + connected[n1] = 1; + + n_nonconnected = 0; + For(i,2*tree->n_otu-2) if(!connected[i]) {nonconnected[n_nonconnected++] = i;} + + n2 = Rand_Int(0,n_nonconnected-1); + n2 = nonconnected[n2]; + connected[n2] = 1; + + n_nonconnected = 0; + For(i,2*tree->n_otu-2) if(!connected[i]) {nonconnected[n_nonconnected++] = i;} + + curr_n->v[1] = tree->a_nodes[n1]; + curr_n->v[2] = tree->a_nodes[n2]; + tree->a_nodes[n1]->v[0] = curr_n; + tree->a_nodes[n2]->v[0] = curr_n; + + tree->rates->nd_t[curr_n->num] = t[n_connected/2]; + + available_nodes[n_available] = tree->a_nodes[n1]->num; + for(i=0;inum) + { + available_nodes[i] = tree->a_nodes[n2]->num; + break; + } + n_available++; + + new_n = Rand_Int(0,n_available-1); + curr_n = tree->a_nodes[available_nodes[new_n]]; + + n_connected+=2; + + }while(n_connected < 2*tree->n_otu-2); + + For(i,2*tree->n_otu-2) tmp[i] = tree->rates->nd_t[i]; + + /* Unroot the tree */ + root->v[2]->v[0] = root->v[2]; + root->v[1]->v[0] = root->v[1]; + + n_internal = n_external = 0; + For(i,2*tree->n_otu-2) + { + if(tree->a_nodes[i]->v[1]) internal_nodes[n_internal++] = tree->a_nodes[i]; + else external_nodes[n_external++] = tree->a_nodes[i]; + } + + + n_internal = n_external = 0; + For(i,2*tree->n_otu-2) + { + if(i < tree->n_otu) + { + tree->a_nodes[i] = external_nodes[n_external++]; + tree->a_nodes[i]->tax = 1; + } + else + { + tree->rates->nd_t[i] = tmp[internal_nodes[n_internal]->num]; + tree->a_nodes[i] = internal_nodes[n_internal++]; + tree->a_nodes[i]->tax = 0; + } + + tree->a_nodes[i]->num = i; + } + + for(i=0;in_otu;i++) tree->rates->nd_t[i] = 0.0; + + for(i=0;in_otu;i++) + { + if(!tree->a_nodes[i]->name) tree->a_nodes[i]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + strcpy(tree->a_nodes[i]->name,"x"); + sprintf(tree->a_nodes[i]->name+1,"%d",i); + } + + Connect_Edges_To_Nodes_Serial(tree); + + /* Add root */ + if(rooted) + { + For(i,2*tree->n_otu-3) + { + if(((tree->a_edges[i]->left == root->v[1]) || (tree->a_edges[i]->rght == root->v[1])) && + ((tree->a_edges[i]->left == root->v[2]) || (tree->a_edges[i]->rght == root->v[2]))) + { + Add_Root(tree->a_edges[i],tree); + break; + } + } + + } + /* Or not... */ + else + { + Free_Node(root); + } + + RATES_Random_Branch_Lengths(tree); + + Free(available_nodes); + Free(connected); + Free(nonconnected); + Free(external_nodes); + Free(internal_nodes); + Free(t); + Free(tmp); + + return tree; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Copy_One_State(char *from, char *to, int state_size) +void Evolve(calign *data, t_mod *mod, int first_site_pos, t_tree *tree) { - int i; - For(i,state_size) to[i] = from[i]; -} + int root_state, root_rate_class; + int site,i; + phydbl *orig_l; + /* phydbl shape,scale,var,mean; */ + int switch_to_yes; + + orig_l = (phydbl *)mCalloc(2*tree->n_otu-3,sizeof(phydbl)); + For(i,2*tree->n_otu-3) orig_l[i] = tree->a_edges[i]->l->v; -/*********************************************************/ + data->n_otu = tree->n_otu; + data->io = tree->io; -model *Make_Model_Basic() -{ - model *mod; + if(mod->use_m4mod) tree->write_labels = YES; + + Set_Br_Len_Var(NULL,tree); + + switch_to_yes = NO; + if(tree->mod->gamma_mgf_bl == YES) switch_to_yes = YES; + + Set_Update_Eigen(YES,mod); + + assert(first_site_pos < data->init_len); + + for(site=first_site_pos;siteinit_len;++site) + { + if(!Set_Model_Parameters(mod)) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + + /* Pick the rate class */ + root_state = root_rate_class = -1; + root_rate_class = Pick_State(mod->ras->n_catg,mod->ras->gamma_r_proba->v); + + + /* /\* Get the change probability matrices *\/ */ + /* For(i,2*tree->n_otu-3) */ + /* { */ + /* var = MAX(0.0,tree->a_edges[i]->l_var->v) * POW(tree->mod->ras->gamma_rr->v[root_rate_class],2); */ + /* mean = orig_l[i]; */ + + /* shape = mean * mean / var; */ + /* scale = var / mean; */ - mod = (model *)mCalloc(1,sizeof(model)); + /* tree->a_edges[i]->l->v = Rgamma(shape,scale); */ - mod->modelname = (char *)mCalloc(T_MAX_NAME,sizeof(char)); - mod->custom_mod_string = (char *)mCalloc(T_MAX_OPTION,sizeof(char)); - mod->user_b_freq = (phydbl *)mCalloc(T_MAX_OPTION,sizeof(phydbl)); + /* } */ - mod->rr = (phydbl *)mCalloc(6,sizeof(phydbl)); - mod->rr_val = (phydbl *)mCalloc(6,sizeof(phydbl)); - mod->rr_num = (int *)mCalloc(6,sizeof(int *)); - mod->n_rr_per_cat = (int *)mCalloc(6,sizeof(int)); - mod->s_opt = (optimiz *)Alloc_Optimiz(); + for(i=0;i<2*tree->n_otu-3;++i) Update_PMat_At_Given_Edge(tree->a_edges[i],tree); + + /* Pick the root nucleotide/aa */ + root_state = Pick_State(mod->ns,mod->e_frq->pi->v); + data->c_seq[0]->state[site] = Reciproc_Assign_State(root_state,tree->io->datatype); + + /* printf("\n. root_state: %d root_rate_class: %d [%f %f %f %f]", */ + /* root_state, */ + /* root_rate_class, */ + /* mod->e_frq->pi->v[0], */ + /* mod->e_frq->pi->v[1], */ + /* mod->e_frq->pi->v[2], */ + /* mod->e_frq->pi->v[3]); */ + /* Generic_Exit(__FILE__,__LINE__,__FUNCTION__); */ + + /* tree->a_nodes[0] is considered as the root t_node */ + Evolve_Recur(tree->a_nodes[0], + tree->a_nodes[0]->v[0], + tree->a_nodes[0]->b[0], + root_state, + root_rate_class, + site, + data, + mod, + tree); + +/* PhyML_Printf("%s\n",Write_Tree(tree)); */ + + data->wght[site] = 1; + } + data->crunch_len = data->init_len; + /* Print_CSeq(stdout,NO,data); */ + For(i,2*tree->n_otu-3) tree->a_edges[i]->l->v = orig_l[i]; + Free(orig_l); - return mod; + if(switch_to_yes == YES) tree->mod->gamma_mgf_bl = YES; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Make_Model_Complete(model *mod) +int Pick_State(int n, phydbl *prob) { - int i,j; - - mod->pi = (phydbl *)mCalloc(mod->ns,sizeof(phydbl)); - mod->gamma_r_proba = (phydbl *)mCalloc(mod->n_catg,sizeof(phydbl)); - mod->gamma_rr = (phydbl *)mCalloc(mod->n_catg,sizeof(phydbl)); - mod->pi_unscaled = (phydbl *)mCalloc(mod->ns,sizeof(phydbl)); - - mod->Pij_rr = (double***)mCalloc(mod->n_catg,sizeof(double **)); - - For(i,mod->n_catg) - { - mod->Pij_rr[i] = (double **)mCalloc(mod->ns,sizeof(double *)); - For(j,mod->ns) mod->Pij_rr[i][j] = (double *)mCalloc(mod->ns,sizeof(double)); - } + int pos; + phydbl uni; - mod->qmat = (double *)mCalloc(mod->ns*mod->ns,sizeof(double)); - mod->qmat_buff = (double *)mCalloc(mod->ns*mod->ns,sizeof(double)); - mod->eigen = (eigen *)Make_Eigen_Struct(mod); - - if(mod->n_rr_branch) + do { - mod->rr_branch = (phydbl *)mCalloc(mod->n_rr_branch,sizeof(phydbl)); - mod->p_rr_branch = (phydbl *)mCalloc(mod->n_rr_branch,sizeof(phydbl)); + pos = rand(); + pos = (pos % n); + uni = (phydbl)rand(); + uni /= (phydbl)RAND_MAX; + if(uni < prob[pos]) break; } -} - -/*********************************************************/ + while(1); -void Copy_Dist(phydbl **cpy, phydbl **orig, int n) -{ - int i,j; - For(i,n) For(j,n) cpy[i][j] = orig[i][j]; + return (int)pos; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -model *Copy_Model(model *ori) +void Evolve_Recur(t_node *a, t_node *d, t_edge *b, int a_state, int r_class, int site_num, calign *gen_data, t_mod *mod, t_tree *tree) { - int i; - model *cpy; - - cpy = Make_Model_Basic(); + int d_state; + int dim1,dim2; - Copy_Optimiz(ori->s_opt,cpy->s_opt); + dim1 = tree->mod->ns * tree->mod->ns; + dim2 = tree->mod->ns; - cpy->ns = ori->ns; - cpy->n_catg = ori->n_catg; - cpy->n_catg = ori->n_catg; + d_state = Pick_State(mod->ns,b->Pij_rr+r_class*dim1+a_state*dim2); - Make_Model_Complete(cpy); + /* PhyML_Printf("\n>> %c (%d) L:%G %G %G %G %G",Reciproc_Assign_State(d_state,mod->io->datatype),d_state, */ + /* b->l->v, */ + /* b->Pij_rr[r_class*dim1+a_state*dim2+0], */ + /* b->Pij_rr[r_class*dim1+a_state*dim2+1], */ + /* b->Pij_rr[r_class*dim1+a_state*dim2+2], */ + /* b->Pij_rr[r_class*dim1+a_state*dim2+3]); */ - cpy->datatype = ori->datatype; - cpy->n_otu = ori->n_otu; - cpy->alpha_old = ori->alpha_old; - cpy->kappa_old = ori->alpha_old; - cpy->lambda_old = ori->lambda_old; - cpy->pinvar_old = ori->pinvar_old; - cpy->whichmodel = ori->whichmodel; - cpy->seq_len = ori->seq_len; - cpy->update_eigen = ori->update_eigen; - cpy->kappa = ori->kappa; - cpy->alpha = ori->alpha; - cpy->lambda = ori->lambda; - cpy->bootstrap = ori->bootstrap; - cpy->invar = ori->invar; - cpy->pinvar = ori->pinvar; - cpy->stepsize = ori->stepsize; - cpy->n_diff_rr = ori->n_diff_rr; - - For(i,6) cpy->rr_num[i] = ori->rr_num[i]; - - For(i,6) - { - cpy->rr_val[i] = ori->rr_val[i]; - cpy->rr[i] = cpy->rr[i]; - } - - For(i,cpy->ns) - { - cpy->pi[i] = ori->pi[i]; - cpy->user_b_freq[i] = ori->user_b_freq[i]; - } - - For(i,cpy->ns*cpy->ns) cpy->qmat[i] = ori->qmat[i]; - For(i,cpy->n_catg) + if(d->tax) { - cpy->gamma_r_proba[i] = ori->gamma_r_proba[i]; - cpy->gamma_rr[i] = ori->gamma_rr[i]; + gen_data->c_seq[d->num]->state[site_num] = Reciproc_Assign_State(d_state,tree->io->datatype); + return; } - -#ifndef PHYML - if(ori->m4mod) + else { - cpy->m4mod = M4_Copy_M4_Model(ori, ori->m4mod); - cpy->use_m4mod = ori->use_m4mod; + int i; + for(i=0;i<3;i++) + if(d->v[i] != a) + Evolve_Recur(d,d->v[i],d->b[i], + d_state,r_class,site_num,gen_data, + mod,tree); } -#endif - - cpy->eigen->size = ori->eigen->size; - For(i,2*ori->ns) cpy->eigen->space[i] = ori->eigen->space[i]; - For(i,2*ori->ns) cpy->eigen->space_int[i] = ori->eigen->space_int[i]; - For(i,ori->ns) cpy->eigen->e_val[i] = ori->eigen->e_val[i]; - For(i,ori->ns) cpy->eigen->e_val_im[i] = ori->eigen->e_val_im[i]; - For(i,ori->ns*ori->ns) cpy->eigen->r_e_vect[i] = ori->eigen->r_e_vect[i]; - For(i,ori->ns*ori->ns) cpy->eigen->r_e_vect[i] = ori->eigen->r_e_vect[i]; - For(i,ori->ns*ori->ns) cpy->eigen->r_e_vect_im[i] = ori->eigen->r_e_vect_im[i]; - For(i,ori->ns*ori->ns) cpy->eigen->l_e_vect[i] = ori->eigen->l_e_vect[i]; - For(i,ori->ns*ori->ns) cpy->eigen->q[i] = ori->eigen->q[i]; - - return cpy; } -/*********************************************************/ - -option *Make_Input() -{ - option* io = (option *)mCalloc(1,sizeof(option)); - io->mod = (model *)Make_Model_Basic(); - io->nt_or_cd = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - - io->in_seq_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - io->in_tree_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - io->out_best_tree_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - io->out_boot_tree_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - io->out_boot_stats_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - io->out_stats_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - io->out_tree_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - io->out_trace_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - io->out_lk_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - io->out_ps_file = (char *)mCalloc(T_MAX_FILE,sizeof(char)); - return io; -} - -/*********************************************************/ - -void Set_Defaults_Input(option* io) -{ - io->fp_in_seq = NULL; - io->fp_in_tree = NULL; - io->fp_out_tree = NULL; - io->fp_out_best_tree = NULL; - io->fp_out_boot_tree = NULL; - io->fp_out_boot_stats = NULL; - io->fp_out_stats = NULL; - - io->tree = NULL; - io->mod->datatype = 0; - strcpy(io->nt_or_cd,"nucleotides"); - io->n_data_sets = 1; - io->interleaved = 1; - io->in_tree = 0; - io->out_tree_file_open_mode = 1; - io->out_stats_file_open_mode = 1; - io->seq_len = -1; - io->n_data_set_asked = -1; - io->print_boot_trees = 1; - io->n_gt = 1; - io->ratio_test = 4; - io->multigene = 0; - io->config_multigene = 0; - io->curr_interface = 0; - io->r_seed = -1; - io->collapse_boot = 0; - io->random_boot_seq_order = 1; - io->print_trace = 0; - io->print_site_lnl = 0; - io->m4_model = NO; - io->rm_ambigu = 0; -} - -/*********************************************************/ - -void Set_Defaults_Model(model *mod) -{ - int i; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - strcpy(mod->modelname,"HKY85"); - strcpy(mod->custom_mod_string,"000000"); - mod->whichmodel = HKY85; - mod->n_catg = 1; - mod->n_catg = 1; - mod->kappa = 4.0; - mod->alpha = 1.0; - mod->lambda = 1.0; - mod->bootstrap = 0; - mod->invar = 0; - mod->pinvar = 0.0; - mod->stepsize = 1; - mod->ns = 4; - mod->n_diff_rr = 0; - For(i,6) mod->rr_val[i] = 1.0; - For(i,4) mod->user_b_freq[i] = -1.; - mod->m4mod = NULL; - mod->use_m4mod = 0; - mod->n_rr_branch = 0; - mod->rr_branch_alpha = 0.1; -} - -/*********************************************************/ - -void Set_Defaults_Optimiz(optimiz *s_opt) -{ - s_opt->print = 1; - s_opt->last_opt = 1; - s_opt->opt_alpha = 0; - s_opt->opt_kappa = 0; - s_opt->opt_bl = 1; - s_opt->opt_lambda = 0; - s_opt->opt_pinvar = 0; - s_opt->opt_num_param = 0; - s_opt->opt_cov_delta = 0; - s_opt->opt_cov_alpha = 0; - s_opt->opt_cov_free_rates = 0; - s_opt->opt_rr = 0; - s_opt->init_lk = UNLIKELY; - s_opt->n_it_max = 1000; - s_opt->opt_topo = 1; - s_opt->topo_search = NNI_MOVE; - s_opt->random_input_tree = 0; - s_opt->n_rand_starts = 5; - s_opt->brent_it_max = 500; - s_opt->steph_spr = 1; - s_opt->user_state_freq = 0; - s_opt->min_diff_lk_local = 1.E-05; - s_opt->min_diff_lk_global = 1.E-03; - s_opt->spr_step_after_nnis = 0; - s_opt->p_moves_to_examine = 0.1; - s_opt->fast_nni = 0; - s_opt->greedy = 0; - s_opt->general_pars = 0; - s_opt->tree_size_mult = 1; - - s_opt->wim_n_rgrft = -1; - s_opt->wim_n_globl = -1; - s_opt->wim_max_dist = -1; - s_opt->wim_n_optim = -1; - s_opt->wim_n_best = -1; - s_opt->wim_inside_opt = 0; -} - -/*********************************************************/ - -void Copy_Optimiz(optimiz *ori, optimiz *cpy) -{ - cpy->print = ori->print; - cpy->last_opt = ori->last_opt; - cpy->opt_alpha = ori->opt_alpha; - cpy->opt_kappa = ori->opt_kappa; - cpy->opt_bl = ori->opt_bl; - cpy->opt_lambda = ori->opt_lambda; - cpy->opt_pinvar = ori->opt_pinvar; - cpy->opt_cov_delta = ori->opt_cov_delta; - cpy->opt_cov_alpha = ori->opt_cov_alpha; - cpy->opt_num_param = ori->opt_num_param; - cpy->opt_cov_free_rates = ori->opt_cov_free_rates; - cpy->opt_rr = ori->opt_rr; - cpy->init_lk = ori->init_lk; - cpy->n_it_max = ori->n_it_max; - cpy->opt_topo = ori->opt_topo; - cpy->topo_search = ori->topo_search; - cpy->random_input_tree = ori->random_input_tree; - cpy->n_rand_starts = ori->n_rand_starts; - cpy->brent_it_max = ori->brent_it_max; - cpy->steph_spr = ori->steph_spr; - cpy->user_state_freq = ori->user_state_freq; - cpy->min_diff_lk_local = ori->min_diff_lk_local; - cpy->min_diff_lk_global = ori->min_diff_lk_global; - cpy->spr_step_after_nnis = ori->spr_step_after_nnis; - cpy->p_moves_to_examine = ori->p_moves_to_examine; - cpy->fast_nni = ori->fast_nni; - cpy->greedy = ori->greedy; - cpy->general_pars = ori->general_pars; - cpy->tree_size_mult = ori->tree_size_mult; - - cpy->wim_n_rgrft = ori->wim_n_rgrft; - cpy->wim_n_globl = ori->wim_n_globl; - cpy->wim_max_dist = ori->wim_max_dist; - cpy->wim_n_optim = ori->wim_n_optim; - cpy->wim_n_best = ori->wim_n_best; - cpy->wim_inside_opt = ori->wim_inside_opt; -} - -/*********************************************************/ - -void Get_Bip(node *a, node *d, arbre *tree) +void Site_Diversity(t_tree *tree) { - if(d->tax) + int i,j,k,ns; + int *div,sum; + + ns = tree->mod->ns; + + div = (int *)mCalloc(ns,sizeof(int)); + + Site_Diversity_Post(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree->a_nodes[0]->b[0],tree); + Site_Diversity_Pre (tree->a_nodes[0],tree->a_nodes[0]->v[0],tree->a_nodes[0]->b[0],tree); + + For(i,2*tree->n_otu-3) { - d->bip_node[0][0] = d; - d->bip_size[0] = 1; - return; + for(j=0;ja_edges[i]->div_post_pred_left[j] = 0; + tree->a_edges[i]->div_post_pred_rght[j] = 0; + } } - else + + for(i=0;in_pattern;i++) { - int i,j,k; - int d_a; - + For(j,2*tree->n_otu-3) + { + Binary_Decomposition(tree->a_edges[j]->ui_l[i],div,ns); + sum = 0; + for(k=0;ka_edges[j]->div_post_pred_left[sum-1] += tree->data->wght[i]; + + Binary_Decomposition(tree->a_edges[j]->ui_r[i],div,ns); + sum = 0; + for(k=0;ka_edges[j]->div_post_pred_rght[sum-1] += tree->data->wght[i]; + } + } + + /* For(j,2*tree->n_otu-3) */ + /* { */ + /* PhyML_Printf("\n. Edge %4d div_left = %4d %4d %4d %4d -- div_rght = %4d %4d %4d %4d", */ + /* j, */ + /* tree->a_edges[j]->div_post_pred_left[0], */ + /* tree->a_edges[j]->div_post_pred_left[1], */ + /* tree->a_edges[j]->div_post_pred_left[2], */ + /* tree->a_edges[j]->div_post_pred_left[3], */ + /* tree->a_edges[j]->div_post_pred_rght[0], */ + /* tree->a_edges[j]->div_post_pred_rght[1], */ + /* tree->a_edges[j]->div_post_pred_rght[2], */ + /* tree->a_edges[j]->div_post_pred_rght[3]); */ + /* } */ + + Free(div); +} - d_a = -1; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,3) - { - if(d->v[i] != a) - Get_Bip(d,d->v[i],tree); - else d_a = i; - } - d->bip_size[d_a] = 0; - For(i,3) - if(d->v[i] != a) - { - For(j,3) - { - if(d->v[i]->v[j] == d) - { - For(k,d->v[i]->bip_size[j]) - { - d->bip_node[d_a][d->bip_size[d_a]] = d->v[i]->bip_node[j][k]; - strcpy(d->bip_name[d_a][d->bip_size[d_a]],d->v[i]->bip_node[j][k]->name); - d->bip_size[d_a]++; - } - break; - } - } - } - - qsort(d->bip_name[d_a],d->bip_size[d_a],sizeof(char *),Sort_String); - - For(i,3) - if(a->v[i] == d) - { - a->bip_size[i] = 0; - For(j,tree->n_otu) - { - For(k,d->bip_size[d_a]) - { - if(d->bip_node[d_a][k] == tree->noeud[j]) - break; - } - - if(k == d->bip_size[d_a]) - { - a->bip_node[i][a->bip_size[i]] = tree->noeud[j]; - strcpy(a->bip_name[i][a->bip_size[i]],tree->noeud[j]->name); - a->bip_size[i]++; - } - } - - qsort(a->bip_name[i],a->bip_size[i],sizeof(char *),Sort_String); - - if(a->bip_size[i] != tree->n_otu - d->bip_size[d_a]) - { - printf("%d %d \n",a->bip_size[i],tree->n_otu - d->bip_size[d_a]); - Warn_And_Exit("\n. Problem in counting bipartitions \n"); - } - break; - } - } -} - -/*********************************************************/ - -void Alloc_Bip(arbre *tree) +void Site_Diversity_Post(t_node *a, t_node *d, t_edge *b, t_tree *tree) { - int i,j,k; - - tree->has_bip = 1; - - For(i,2*tree->n_otu-2) + if(d->tax) return; + else { - tree->noeud[i]->bip_size = (int *)mCalloc(3,sizeof(int)); - tree->noeud[i]->bip_node = (node ***)mCalloc(3,sizeof(node **)); - tree->noeud[i]->bip_name = (char ***)mCalloc(3,sizeof(char **)); - For(j,3) - { - tree->noeud[i]->bip_node[j] = - (node **)mCalloc(tree->n_otu,sizeof(node *)); - - tree->noeud[i]->bip_name[j] = - (char **)mCalloc(tree->n_otu,sizeof(char *)); + int i; - For(k,tree->n_otu) - tree->noeud[i]->bip_name[j][k] = - (char *)mCalloc(T_MAX_NAME,sizeof(char )); - } + for(i=0;i<3;i++) + if(d->v[i] != a) + Site_Diversity_Post(d,d->v[i],d->b[i],tree); + + Subtree_Union(d,b,tree); } } -/*********************************************************/ - -int Sort_Phydbl_Increase(const void *a, const void *b) -{ - if((*(phydbl *)(a)) <= (*(phydbl *)(b))) return -1; - else return 1; -} - -/*********************************************************/ - -int Sort_String(const void *a, const void *b) -{ - return(strcmp((*(const char **)(a)), (*(const char **)(b)))); -} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ -void Compare_Bip_On_Existing_Edges(int discard, arbre *tree1, arbre *tree2) +void Site_Diversity_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree) { - int i,j,k; - edge *b1,*b2; - char **bip1,**bip2; - int bip_size; - - - For(i,2*tree1->n_otu-3) + if(d->tax) return; + else { - if((!tree1->t_edges[i]->left->tax) && - (!tree1->t_edges[i]->rght->tax)) - { - b1 = tree1->t_edges[i]; + int i; - For(j,2*tree2->n_otu-3) - { - if((!tree2->t_edges[j]->left->tax) && - (!tree2->t_edges[j]->rght->tax)) - { - b2 = tree2->t_edges[j]; - - if(MIN(b1->left->bip_size[b1->l_r],b1->rght->bip_size[b1->r_l]) == - MIN(b2->left->bip_size[b2->l_r],b2->rght->bip_size[b2->r_l])) - { - bip_size = MIN(b1->left->bip_size[b1->l_r],b1->rght->bip_size[b1->r_l]); - - if(b1->left->bip_size[b1->l_r] == b1->rght->bip_size[b1->r_l]) - { - if(b1->left->bip_name[b1->l_r][0][0] < b1->rght->bip_name[b1->r_l][0][0]) - { - bip1 = b1->left->bip_name[b1->l_r]; - } - else - { - bip1 = b1->rght->bip_name[b1->r_l]; - } - } - else if(b1->left->bip_size[b1->l_r] < b1->rght->bip_size[b1->r_l]) - { - bip1 = b1->left->bip_name[b1->l_r]; - } - else - { - bip1 = b1->rght->bip_name[b1->r_l]; - } - - if(b2->left->bip_size[b2->l_r] == b2->rght->bip_size[b2->r_l]) - { - if(b2->left->bip_name[b2->l_r][0][0] < b2->rght->bip_name[b2->r_l][0][0]) - { - bip2 = b2->left->bip_name[b2->l_r]; - } - else - { - bip2 = b2->rght->bip_name[b2->r_l]; - } - } - else if(b2->left->bip_size[b2->l_r] < b2->rght->bip_size[b2->r_l]) - { - bip2 = b2->left->bip_name[b2->l_r]; - } - else - { - bip2 = b2->rght->bip_name[b2->r_l]; - } - - if(bip_size == 1) Warn_And_Exit("\n. Problem in Compare_Bip\n"); - - - For(k,bip_size) - { - if(strcmp(bip1[k],bip2[k])) break; - } - - if(k == bip_size) - { - if(!((discard) && (b2->l < .5 / (phydbl)tree2->data->init_len))) - { -/* One_Pars_Step(b2,tree2); */ - b2->bip_score++; - b1->bip_score++; - } - -/* if((b1->l > .5 / (phydbl)tree1->data->init_len) || */ -/* (b2->l > .5 / (phydbl)tree2->data->init_len)) */ -/* { */ -/* b1->bip_score++; */ -/* b2->bip_score++; */ -/* } */ - break; - } - } - } - } - } + for(i=0;i<3;i++) + if(d->v[i] != a) + { + Subtree_Union(d,d->b[i],tree); + Site_Diversity_Pre(d,d->v[i],d->b[i],tree); + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void Compare_Bip(arbre *tree1, arbre *tree2) +void Subtree_Union(t_node *n, t_edge *b_fcus, t_tree *tree) { - int i,j,k; - edge *b1,*b2; - char **bip1,**bip2; - int bip_size; +/* + | + |<- b_cus + | + n + / \ + / \ + / \ +*/ + + int site; + int *ui, *ui_v1, *ui_v2; + ui = ui_v1 = ui_v2 = NULL; - For(i,2*tree1->n_otu-3) + if(n == b_fcus->left) { - if((!tree1->t_edges[i]->left->tax) && - (!tree1->t_edges[i]->rght->tax)) - { + ui = b_fcus->ui_l; - b1 = tree1->t_edges[i]; + ui_v1 = + (n == n->b[b_fcus->l_v1]->left)? + (n->b[b_fcus->l_v1]->ui_r): + (n->b[b_fcus->l_v1]->ui_l); - For(j,2*tree2->n_otu-3) - { - if((!tree2->t_edges[j]->left->tax) && - (!tree2->t_edges[j]->rght->tax)) - { - - b2 = tree2->t_edges[j]; - - if(MIN(b1->left->bip_size[b1->l_r],b1->rght->bip_size[b1->r_l]) == - MIN(b2->left->bip_size[b2->l_r],b2->rght->bip_size[b2->r_l])) - { - bip_size = MIN(b1->left->bip_size[b1->l_r],b1->rght->bip_size[b1->r_l]); - - if(b1->left->bip_size[b1->l_r] == b1->rght->bip_size[b1->r_l]) - { - if(b1->left->bip_name[b1->l_r][0][0] < b1->rght->bip_name[b1->r_l][0][0]) - { - bip1 = b1->left->bip_name[b1->l_r]; - } - else - { - bip1 = b1->rght->bip_name[b1->r_l]; - } - } - else if(b1->left->bip_size[b1->l_r] < b1->rght->bip_size[b1->r_l]) - { - bip1 = b1->left->bip_name[b1->l_r]; - } - else - { - bip1 = b1->rght->bip_name[b1->r_l]; - } - - - if(b2->left->bip_size[b2->l_r] == b2->rght->bip_size[b2->r_l]) - { - if(b2->left->bip_name[b2->l_r][0][0] < b2->rght->bip_name[b2->r_l][0][0]) - { - bip2 = b2->left->bip_name[b2->l_r]; - } - else - { - bip2 = b2->rght->bip_name[b2->r_l]; - } - } - else if(b2->left->bip_size[b2->l_r] < b2->rght->bip_size[b2->r_l]) - { - bip2 = b2->left->bip_name[b2->l_r]; - } - else - { - bip2 = b2->rght->bip_name[b2->r_l]; - } - - if(bip_size == 1) Warn_And_Exit("\n. Problem in Compare_Bip\n"); - - - For(k,bip_size) - { - if(strcmp(bip1[k],bip2[k])) break; - } - - if(k == bip_size) - { - b1->bip_score++; - b2->bip_score++; - break; - } - } - } - } - } + ui_v2 = + (n == n->b[b_fcus->l_v2]->left)? + (n->b[b_fcus->l_v2]->ui_r): + (n->b[b_fcus->l_v2]->ui_l); } -} - -/*********************************************************/ - -void Test_Multiple_Data_Set_Format(option *io) -{ - char *line; - - line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); - - io->n_trees = 0; - - while(fgets(line,T_MAX_LINE,io->fp_in_tree)) if(strstr(line,";")) io->n_trees++; + else + { + ui = b_fcus->ui_r; - Free(line); + ui_v1 = + (n == n->b[b_fcus->r_v1]->left)? + (n->b[b_fcus->r_v1]->ui_r): + (n->b[b_fcus->r_v1]->ui_l); - if((io->mod->bootstrap > 1) && (io->n_trees > 1)) - Warn_And_Exit("\n. Bootstrap option is not allowed with multiple input trees !\n"); + ui_v2 = + (n == n->b[b_fcus->r_v2]->left)? + (n->b[b_fcus->r_v2]->ui_r): + (n->b[b_fcus->r_v2]->ui_l); + } - rewind(io->fp_in_tree); + for(site=0;siten_pattern;site++) ui[site] = ui_v1[site] | ui_v2[site]; - return; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Are_Compatible(char *statea, char *stateb, int stepsize, int datatype) + +void Binary_Decomposition(int value, int *bit_vect, int size) { - int i,j; - char a,b; + int i,cumul; + for(i=0;i=0;i--) { - a = statea[0]; b = stateb[0]; - switch(a) - { - case 'A' : - { - switch(b) - { - case 'A' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'R' : - { - switch(b) - { - case 'R' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'N' : - { - switch(b) - { - case 'N' : - case 'B' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'B' : - { - switch(b) - { - case 'N' : - case 'B' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'D' : - { - switch(b) - { - case 'D' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'C' : - { - switch(b) - { - case 'C' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'Q' : - { - switch(b) - { - case 'Q' : - case 'Z' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'Z' : - { - switch(b) - { - case 'Q' : - case 'Z' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'E' : - { - switch(b) - { - case 'E' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'G' : - { - switch(b) - { - case 'G' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'H' : - { - switch(b) - { - case 'H' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'I' : - { - switch(b) - { - case 'I' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'L' : - { - switch(b) - { - case 'L' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'K' : - { - switch(b) - { - case 'K' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'M' : - { - switch(b) - { - case 'M' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'F' : - { - switch(b) - { - case 'F' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'P' : - { - switch(b) - { - case 'P' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'S' : - { - switch(b) - { - case 'S' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'T' : - { - switch(b) - { - case 'T' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'W' : - { - switch(b) - { - case 'W' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'Y' : - { - switch(b) - { - case 'Y' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'V' : - { - switch(b) - { - case 'V' : - case 'X' : {b=b; break;} - default : return 0; - } - break; - } - case 'X' : - { - switch(b) - { - case 'A':case 'R':case 'N' :case 'B' :case 'D' : - case 'C':case 'Q':case 'Z' :case 'E' :case 'G' : - case 'H':case 'I':case 'L' :case 'K' :case 'M' : - case 'F':case 'P':case 'S' :case 'T' :case 'W' : - case 'Y':case 'V': case 'X' : {b=b; break;} - default : return 0; - } - break; - } - default : - { - printf("\n. Err. in Are_Compatible\n"); - printf("\n. Please check that characters `%c` and `%c`\n",a,b); - printf(" correspond to existing amino-acids.\n"); - Warn_And_Exit("\n"); - return 0; - } - } + if(value - cumul < (int)POW(2,i)) + { + bit_vect[i] = 0; + } + else + { + bit_vect[i] = 1; + cumul += (int)POW(2,i); + } } - return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void Hide_Ambiguities(allseq *data) +void Print_Diversity_Header(FILE *fp, t_tree *tree) { - int i; - For(i,data->crunch_len) if(data->ambigu[i]) data->wght[i] = 0; + /* PhyML_Fprintf(fp,"t_edge side mean\n"); */ + PhyML_Fprintf(fp,"t_edge side diversity count\n"); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Copy_Tree_Topology_With_Labels(arbre *ori, arbre *cpy) +void Best_Of_NNI_And_SPR(t_tree *tree) { - int i,j; - - For(i,2*ori->n_otu-2) - { - For(j,3) - { - if(ori->noeud[i]->v[j]) - { - cpy->noeud[i]->v[j] = cpy->noeud[ori->noeud[i]->v[j]->num]; - cpy->noeud[i]->l[j] = ori->noeud[i]->l[j]; - } - else - cpy->noeud[i]->v[j] = NULL; - } - cpy->noeud[i]->num = ori->noeud[i]->num; - cpy->noeud[i]->tax = 0; - } - - For(i,2*ori->n_otu-3) - { - cpy->t_edges[i]->l = ori->t_edges[i]->l; - } + PhyML_Fprintf(stderr,"Best of NNI and SPR option is deprecated. PhyML nows only relies on SPR moves"); + assert(FALSE); - For(i,ori->n_otu) + if(tree->mod->s_opt->random_input_tree) + Global_Spr_Search(tree); /* Don't do simultaneous NNIs if starting tree is random */ + else { - cpy->noeud[i]->tax = 1; - strcpy(cpy->noeud[i]->name,ori->noeud[i]->name); - } + t_tree *ori_tree,*best_tree; + t_mod *ori_mod,*best_mod; + scalar_dbl **ori_bl,**best_bl; + phydbl best_lnL,ori_lnL,nni_lnL,spr_lnL; + int i; +#ifdef BEAGLE + tree->b_inst = create_beagle_instance(tree, tree->io->quiet, tree->io); +#endif -} + ori_mod = Copy_Model(tree->mod); + best_mod = Copy_Model(tree->mod); -/*********************************************************/ + ori_tree = Make_Tree_From_Scratch(tree->n_otu,tree->data); + best_tree = Make_Tree_From_Scratch(tree->n_otu,tree->data); -void Prune_Subtree(node *a, node *d, edge **target, edge **residual, arbre *tree) -{ - node *v1, *v2; - edge *b1, *b2; - int dir_v1, dir_v2; - int i; - phydbl ***buff_p_lk,*buff_scale; - int **buff_p_pars, *buff_pars; - unsigned int *buff_ui; - short int **buff_p_lk_tip; + Copy_Tree(tree,ori_tree);//Save a backup of the original tree in ori_tree + Record_Br_Len(tree); + ori_bl = Copy_Br_Len(tree); - if(a->tax) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - dir_v1 = dir_v2 = -1; - For(i,3) - { - if(a->v[i] != d) - { - if(dir_v1 < 0) dir_v1 = i; - else dir_v2 = i; - } - } + best_lnL = UNLIKELY; + Lk(NULL,tree); + ori_lnL = tree->c_lnL; /* Record likelihood of the starting tree */ - if(a->v[dir_v1]->num < a->v[dir_v2]->num) - { - v1 = a->v[dir_v1]; - v2 = a->v[dir_v2]; - b1 = a->b[dir_v1]; - b2 = a->b[dir_v2]; - } - else - { - v1 = a->v[dir_v2]; - v2 = a->v[dir_v1]; - b1 = a->b[dir_v2]; - b2 = a->b[dir_v1]; - } + // ****** Perform NNI ****** + Simu_Loop(tree); /* Perform simultaneous NNIs */ + best_lnL = tree->c_lnL; /* Record the likelihood */ + nni_lnL = tree->c_lnL; + //Mark the NNI tree as the "best" tree + Copy_Tree(tree,best_tree); /* Record the tree topology and branch lengths */ + Record_Br_Len(tree); + best_bl = Copy_Br_Len(tree); + Transfer_Br_Len_To_Tree(best_bl,best_tree); + Record_Model(tree->mod,best_mod); - a->v[dir_v1] = NULL; - a->v[dir_v2] = NULL; - a->b[dir_v1] = NULL; - a->b[dir_v2] = NULL; + Copy_Tree(ori_tree,tree); /* Back to the original tree topology */ + Transfer_Br_Len_To_Tree(ori_bl,tree); /* Back to the original branch lengths */ + Record_Model(ori_mod,tree->mod); /* Back to the original model */ + /* Make sure the tree is in its original form */ + Lk(NULL,tree); + if(FABS(tree->c_lnL - ori_lnL) > tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Printf("\n. ori_lnL = %f, c_lnL = %f",ori_lnL,tree->c_lnL); + PhyML_Printf("\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } - if(v1 == b1->left) - { - b1->rght = v2; - if(v2 == b2->left) - { - buff_p_lk = b1->p_lk_rght; - b1->p_lk_rght = b2->p_lk_left; - b2->p_lk_left = buff_p_lk; + // ****** Perform SPR ****** + Global_Spr_Search(tree); + spr_lnL = tree->c_lnL; - buff_p_lk_tip = b1->p_lk_tip_r; - b1->p_lk_tip_r = b2->p_lk_tip_l; - b2->p_lk_tip_l = buff_p_lk_tip; - buff_scale = b1->sum_scale_f_rght; - b1->sum_scale_f_rght = b2->sum_scale_f_left; - b2->sum_scale_f_left = buff_scale; + //Did SPR perform better than NNI? + if(tree->c_lnL > best_lnL) + { +#ifdef BEAGLE + finalize_beagle_instance(best_tree);//Free the old BEAGLE instance associated with the NNI tree (since SPR is better) +#endif + best_lnL = spr_lnL; + Copy_Tree(tree,best_tree); /* Record tree topology, branch lengths and model parameters */ + Record_Br_Len(tree); + For(i,2*tree->n_otu-1) Free_Scalar_Dbl(best_bl[i]); + Free(best_bl); + best_bl = Copy_Br_Len(tree); + Transfer_Br_Len_To_Tree(best_bl,best_tree); + Record_Model(tree->mod,best_mod); + } - buff_pars = b1->pars_r; - b1->pars_r = b2->pars_l; - b2->pars_l = buff_pars; + Copy_Tree(best_tree,tree); + Init_Partial_Lk_Tips_Double(tree); + Init_Ui_Tips(tree); + Init_Partial_Pars_Tips(tree); + Transfer_Br_Len_To_Tree(best_bl,tree); + Record_Model(best_mod,tree->mod); - buff_ui = b1->ui_r; - b1->ui_r = b2->ui_l; - b2->ui_l = buff_ui; + /* Make sure the current tree has the best topology, branch lengths and model parameters */ + Lk(NULL,tree); + if(FABS(tree->c_lnL - best_lnL) > tree->mod->s_opt->min_diff_lk_local) + { + PhyML_Fprintf(stderr,"\n. best_lnL = %f, c_lnL = %f",best_lnL,tree->c_lnL); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } - buff_p_pars = b1->p_pars_r; - b1->p_pars_r = b2->p_pars_l; - b2->p_pars_l = buff_p_pars; - } - else - { - buff_p_lk = b1->p_lk_rght; /* b1->p_lk_rght = NULL if b1->rght->tax */ - b1->p_lk_rght = b2->p_lk_rght; /* b2->p_lk_rght = NULL if b2->rght->tax */ - b2->p_lk_rght = buff_p_lk; + if(tree->verbose > VL0) + { + PhyML_Printf("\n\n. Log likelihood obtained after NNI moves : %f",nni_lnL); + PhyML_Printf("\n. Log likelihood obtained after SPR moves : %f",spr_lnL); + } - buff_p_lk_tip = b1->p_lk_tip_r; - b1->p_lk_tip_r = b2->p_lk_tip_r; - b2->p_lk_tip_r = buff_p_lk_tip; + For(i,2*tree->n_otu-1) Free_Scalar_Dbl(ori_bl[i]); + Free(ori_bl); - buff_scale = b1->sum_scale_f_rght; - b1->sum_scale_f_rght = b2->sum_scale_f_rght; - b2->sum_scale_f_rght = buff_scale; + For(i,2*tree->n_otu-1) Free_Scalar_Dbl(best_bl[i]); + Free(best_bl); - buff_pars = b1->pars_r; - b1->pars_r = b2->pars_r; - b2->pars_r = buff_pars; + Free_Tree(ori_tree); + Free_Tree(best_tree); - buff_ui = b1->ui_r; - b1->ui_r = b2->ui_r; - b2->ui_r = buff_ui; + Free_Model_Complete(ori_mod); + Free_Model_Complete(best_mod); - buff_p_pars = b1->p_pars_r; - b1->p_pars_r = b2->p_pars_r; - b2->p_pars_r = buff_p_pars; - } - } - else - { - b1->left = v2; + Free_Model_Basic(ori_mod); + Free_Model_Basic(best_mod); + } +} - if(v2 == b2->left) - { - buff_p_lk = b1->p_lk_left; - b1->p_lk_left = b2->p_lk_left; - b2->p_lk_left = buff_p_lk; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - buff_p_lk_tip = b1->p_lk_tip_l; - b1->p_lk_tip_l = b2->p_lk_tip_l; - b2->p_lk_tip_l = buff_p_lk_tip; - buff_scale = b1->sum_scale_f_left; - b1->sum_scale_f_left = b2->sum_scale_f_left; - b2->sum_scale_f_left = buff_scale; +/* Polynomial interpolation. Adapted from "Numerical Recipes in C". +Press, Flannery, Teukolsky, Vetterling, 1988. +*/ +int Polint(phydbl *xa, phydbl *ya, int n, phydbl x, phydbl *y, phydbl *dy) +{ + int i,m,ns=1; + phydbl den,dif,dift,ho,hp,w; + phydbl *c,*d; - buff_pars = b1->pars_l; - b1->pars_l = b2->pars_l; - b2->pars_l = buff_pars; + dif=FABS(x-xa[1]); - buff_ui = b1->ui_l; - b1->ui_l = b2->ui_l; - b2->ui_l = buff_ui; + c = (phydbl *)mCalloc(n,sizeof(phydbl)); + d = (phydbl *)mCalloc(n,sizeof(phydbl)); - buff_p_pars = b1->p_pars_l; - b1->p_pars_l = b2->p_pars_l; - b2->p_pars_l = buff_p_pars; - } - else - { - buff_p_lk = b1->p_lk_left; - b1->p_lk_left = b2->p_lk_rght; /* b2->p_lk_rght = NULL if b2->rght->tax */ - b2->p_lk_rght = buff_p_lk; + for(i=1;i<=n;i++) + { + if((dift=FABS(x-xa[i])) < dif) + { + ns=i; + dif=dift; + } + c[i]=ya[i]; + d[i]=ya[i]; + } - buff_p_lk_tip = b1->p_lk_tip_l; - b1->p_lk_tip_l = b2->p_lk_tip_r; - b2->p_lk_tip_r = buff_p_lk_tip; + *y=ya[ns--]; - buff_scale = b1->sum_scale_f_left; - b1->sum_scale_f_left = b2->sum_scale_f_rght; - b2->sum_scale_f_rght = buff_scale; + for (m=1;m -SMALL ) + { +/* Rprintf("\n. Error in routine POLINT.\n"); */ + Exit("\n. Error in routine POLINT.\n"); + return(-1); + } + den=w/den; + d[i]=hp*den; + c[i]=ho*den; + } + *y += (*dy=(2*ns < (n-m) ? c[ns+1] : d[ns--])); + } - buff_pars = b1->pars_l; - b1->pars_l = b2->pars_r; - b2->pars_r = buff_pars; + Free(d); + Free(c); + return(0); +} - buff_ui = b1->ui_l; - b1->ui_l = b2->ui_r; - b2->ui_r = buff_ui; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - buff_p_pars = b1->p_pars_l; - b1->p_pars_l = b2->p_pars_r; - b2->p_pars_r = buff_p_pars; - } - } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,3) - if(v2->v[i] == a) - { - v2->v[i] = v1; - v2->b[i] = b1; - break; - } +t_tree *Dist_And_BioNJ(calign *cdata, t_mod *mod, option *io) +{ + t_tree *tree; + matrix *mat; -#ifdef DEBUG - if(i == 3) + if(mod->s_opt->random_input_tree == NO) { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } -#endif + if(!io->quiet) PhyML_Printf("\n\n. Computing pairwise distances..."); - For(i,3) - if(v1->v[i] == a) - { - v1->v[i] = v2; - break; - } + mat = ML_Dist(cdata,mod); + + Fill_Missing_Dist(mat); -#ifdef DEBUG - if(i == 3) + if(!io->quiet) PhyML_Printf("\n\n. Building BioNJ tree..."); + mat->tree = Make_Tree_From_Scratch(cdata->n_otu,cdata); + Bionj(mat); + + tree = mat->tree; + tree->mat = mat; + } + else { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + tree = Make_Tree_From_Scratch(cdata->n_otu,cdata); + Random_Tree(tree); + tree->mat = NULL; } -#endif - - b1->l += b2->l; - + + return tree; +} - (v1 == b1->left)? - (Make_Edge_Dirs(b1,v1,v2)): - (Make_Edge_Dirs(b1,v2,v1)); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if(target) (*target) = b1; - if(residual) (*residual) = b2; +void Add_BioNJ_Branch_Lengths(t_tree *tree, calign *cdata, t_mod *mod, matrix *mat) +{ + short unsigned int freemat = NO; + if(mat == NULL) freemat = YES; + Connect_CSeqs_To_Nodes(cdata,mod->io,tree); + if(mat == NULL) mat = ML_Dist(cdata,mod); + mat->tree = tree; + mat->method = 0; + Bionj_Br_Length(mat); + if(freemat == YES) Free_Mat(mat); } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ - -void Graft_Subtree(edge *target, node *link, edge *residual, arbre *tree) +char *Bootstrap_From_String(char *s_tree, calign *cdata, t_mod *mod, option *io) { - node *v1, *v2; - int i, dir_v1, dir_v2; - phydbl ***buff_p_lk, *buff_scale; - int **buff_p_pars, *buff_pars; - short int **buff_p_lk_tip; - unsigned int *buff_ui; - edge *b_up; + t_tree *tree; + + tree = Read_Tree(&s_tree); - dir_v1 = dir_v2 = -1; - b_up = NULL; - For(i,3) + tree->n_root = NULL; + tree->e_root = NULL; + + if(!tree) { - if(!link->v[i]) - { - if(dir_v1 < 0) dir_v1 = i; - else dir_v2 = i; - } - else b_up = link->b[i]; + PhyML_Printf("\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Exit(""); } - if(target->left->num < target->rght->num) - { - v1 = target->left; - v2 = target->rght; + tree->mod = mod; + tree->io = io; + tree->data = cdata; + tree->n_pattern = tree->data->crunch_len; + tree->io->print_support_val = YES; + + + Connect_CSeqs_To_Nodes(cdata,io,tree); + if(tree->mod->s_opt->random_input_tree) Random_Tree(tree); + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); + Unscale_Br_Len_Multiplier_Tree(tree); + Br_Len_Not_Involving_Invar(tree); + Make_Spr_List_One_Edge(tree); + Make_Spr_List_All_Edge(tree); + Make_Best_Spr(tree); + + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + +#ifdef MPI + Bootstrap_MPI(tree); +#else + Bootstrap(tree); +#endif - buff_p_lk = residual->p_lk_rght; - residual->p_lk_rght = target->p_lk_rght; - target->p_lk_rght = buff_p_lk; + Free(s_tree); - buff_p_lk_tip = residual->p_lk_tip_r; - residual->p_lk_tip_r = target->p_lk_tip_r; - target->p_lk_tip_r = buff_p_lk_tip; + Rescale_Br_Len_Multiplier_Tree(tree); + Br_Len_Involving_Invar(tree); + Collect_Edge_Support_Values(tree); - buff_scale = residual->sum_scale_f_rght; - residual->sum_scale_f_rght = target->sum_scale_f_rght; - target->sum_scale_f_rght = buff_scale; + s_tree = Write_Tree(tree); - buff_pars = residual->pars_r; - residual->pars_r = target->pars_r; - target->pars_r = buff_pars; + Free_Spr_List_One_Edge(tree); + Free_One_Spr(tree->best_spr); + Free_Spr_List_All_Edge(tree); + Free_Tree_Pars(tree); + Free_Tree_Lk(tree); + Free_Tree(tree); - buff_ui = residual->ui_r; - residual->ui_r = target->ui_r; - target->ui_r = buff_ui; + return s_tree; +} - buff_p_pars = residual->p_pars_r; - residual->p_pars_r = target->p_pars_r; - target->p_pars_r = buff_p_pars; - } - else - { - v1 = target->rght; - v2 = target->left; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - buff_p_lk = residual->p_lk_rght; - residual->p_lk_rght = target->p_lk_left; - target->p_lk_left = buff_p_lk; +char *aLRT_From_String(char *s_tree, calign *cdata, t_mod *mod, option *io) +{ + t_tree *tree; - buff_p_lk_tip = residual->p_lk_tip_r; - residual->p_lk_tip_r = target->p_lk_tip_l; - target->p_lk_tip_l = buff_p_lk_tip; + tree = Read_Tree(&s_tree); - buff_scale = residual->sum_scale_f_rght; - residual->sum_scale_f_rght = target->sum_scale_f_left; - target->sum_scale_f_left = buff_scale; + tree->n_root = NULL; + tree->e_root = NULL; - buff_pars = residual->pars_r; - residual->pars_r = target->pars_l; - target->pars_l = buff_pars; + if(!tree) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d (function '%s') \n",__FILE__,__LINE__,__FUNCTION__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } - buff_ui = residual->ui_r; - residual->ui_r = target->ui_l; - target->ui_l = buff_ui; + tree->mod = mod; + tree->io = io; + tree->data = cdata; + tree->n_pattern = tree->data->crunch_len; - buff_p_pars = residual->p_pars_r; - residual->p_pars_r = target->p_pars_l; - target->p_pars_l = buff_p_pars; - } + Connect_CSeqs_To_Nodes(cdata,io,tree); + if(tree->mod->s_opt->random_input_tree) Random_Tree(tree); + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); - For(i,3) - if(v2->b[i] == target) - { - v2->v[i] = link; - v2->b[i] = residual; - break; - } + Unscale_Br_Len_Multiplier_Tree(tree); + Br_Len_Not_Involving_Invar(tree); - link->v[dir_v2] = v2; - link->b[dir_v2] = residual; + Make_Spr_List_One_Edge(tree); + Make_Spr_List_All_Edge(tree); + Make_Best_Spr(tree); - residual->left = link; - residual->rght = v2; +#ifdef BEAGLE + tree->b_inst = create_beagle_instance(tree, io->quiet, io); +#endif - (v1 == target->left)?(target->rght = link):(target->left = link); + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + + aLRT(tree); - link->v[dir_v1] = v1; - link->b[dir_v1] = target; + Free(s_tree); - For(i,3) - if(v1->v[i] == v2) - { - v1->v[i] = link; - break; - } + Rescale_Br_Len_Multiplier_Tree(tree); + Br_Len_Involving_Invar(tree); + Collect_Edge_Support_Values(tree); + + s_tree = Write_Tree(tree); + +#ifdef BEAGLE + finalize_beagle_instance(tree); +#endif - target->l /= 2.; - residual->l = target->l; + Free_One_Spr(tree->best_spr); + Free_Spr_List_One_Edge(tree); + Free_Spr_List_All_Edge(tree); + Free_Tree_Pars(tree); + Free_Tree_Lk(tree); + Free_Tree(tree); - Make_Edge_Dirs(target,target->left,target->rght); - Make_Edge_Dirs(residual,residual->left,residual->rght); - Make_Edge_Dirs(b_up,b_up->left,b_up->rght); + return s_tree; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Pull_Subtree_From_Dead_Objects(node *a, node *d, arbre *tree) +void Find_Common_Tips(t_tree *tree1, t_tree *tree2) { - int i; - - For(i,3) - if(a->v[i] == d) - { - tree->n_dead_nodes--; - tree->n_dead_edges--; -#ifdef DEBUG - if((tree->n_dead_edges < 0) || (tree->n_dead_nodes < 0)) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } -#endif - break; - } + int i,j; - if(d->tax) return; - else + for(i=0;in_otu;i++) tree1->a_nodes[i]->common = NO; + for(i=0;in_otu;i++) tree2->a_nodes[i]->common = NO; + + for(i=0;in_otu;i++) { - For(i,3) - { - if(d->v[i] != a) - Pull_Subtree_From_Dead_Objects(d,d->v[i],tree); - } + for(j=0;jn_otu;j++) + { + if(!strcmp(tree1->a_nodes[i]->name,tree2->a_nodes[j]->name)) + { + tree1->a_nodes[i]->common = YES; + tree2->a_nodes[j]->common = YES; + break; + } + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Put_Subtree_In_Dead_Objects(node *a, node *d, arbre *tree) +phydbl Get_Tree_Size(t_tree *tree) { int i; + phydbl tree_size; + tree_size = 0.0; + For(i,2*tree->n_otu-3) tree_size += tree->a_edges[i]->l->v; - For(i,3) + if(tree->n_root != NULL) { - if(a->v[i] == d) - { -#ifdef DEBUG - if((tree->n_dead_edges < 0) || (tree->n_dead_nodes < 0)) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } -#endif - tree->t_dead_edges[tree->n_dead_edges] = a->b[i]; - tree->t_dead_nodes[tree->n_dead_nodes] = d; - tree->n_dead_nodes++; - tree->n_dead_edges++; - break; - } + tree_size += tree->n_root->b[1]->l->v; + tree_size += tree->n_root->b[2]->l->v; } - if(d->tax) - return; - else - { - For(i,3) - { - if(d->v[i] != a) - Put_Subtree_In_Dead_Objects(d,d->v[i],tree); - } - } +/* For(i,2*tree->n_otu-3) */ +/* tree_size += */ +/* FABS(tree->rates->nd_t[tree->a_edges[i]->left->num] - */ +/* tree->rates->nd_t[tree->a_edges[i]->rght->num]); */ + + tree->size = tree_size; + return tree_size; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Reassign_Node_Nums(node *a, node *d, int *curr_ext_node, int *curr_int_node, arbre *tree) +void Dist_To_Root_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree) { - node *buff; int i; - if(a->tax) - { - buff = tree->noeud[*curr_ext_node]; - tree->noeud[*curr_ext_node] = a; - tree->noeud[a->num] = buff; - buff->num = a->num; - a->num = *curr_ext_node; - (*curr_ext_node)++; - } + if(b) d->dist_to_root = a->dist_to_root + b->l->v; - if(d->tax) - { - buff = tree->noeud[*curr_ext_node]; - tree->noeud[*curr_ext_node] = d; - tree->noeud[d->num] = buff; - buff->num = d->num; - d->num = *curr_ext_node; - (*curr_ext_node)++; - return; - } + if(d->tax) return; else { - buff = tree->noeud[*curr_int_node]; - tree->noeud[*curr_int_node] = d; - tree->noeud[d->num] = buff; - buff->num = d->num; - d->num = *curr_int_node; - (*curr_int_node)++; - } - - For(i,3) - { - if(d->v[i] != a) - Reassign_Node_Nums(d,d->v[i],curr_ext_node,curr_int_node,tree); + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + Dist_To_Root_Pre(d,d->v[i],d->b[i],tree); } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Reassign_Edge_Nums(node *a, node *d, int *curr_br, arbre *tree) +void Dist_To_Root(t_tree *tree) { - edge *buff; - int i,j; + tree->n_root->dist_to_root = 0.0; + tree->n_root->v[2]->dist_to_root = tree->n_root->b[1]->l->v; + tree->n_root->v[1]->dist_to_root = tree->n_root->b[2]->l->v; - For(i,3) - if(a->v[i] == d) - { - buff = tree->t_edges[*curr_br]; - For(j,2*N_MAX_OTU-3) if(tree->t_edges[j] == a->b[i]) break; - if(j == 2*N_MAX_OTU-3) - { - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - tree->t_edges[*curr_br] = a->b[i]; - tree->t_edges[j] = buff; - a->b[i]->num = *curr_br; - (*curr_br)++; - break; - } + Dist_To_Root_Pre(tree->n_root,tree->n_root->v[2],NULL,tree); + Dist_To_Root_Pre(tree->n_root,tree->n_root->v[1],NULL,tree); +} - if(d->tax) return; - else +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Get_Node_Ranks_From_Dist_To_Root(t_tree *tree) +{ + int buff; + int i; + int swap = NO; + int *rk; + + rk = (int *)mCalloc(2*tree->n_otu-1,sizeof(int)); + + for(i=0;i<2*tree->n_otu-1;++i) rk[i] = i; + + do { - For(i,3) - if(d->v[i] != a) - Reassign_Edge_Nums(d,d->v[i],curr_br,tree); + swap = NO; + for(i=0;i<2*tree->n_otu-2;++i) + { + if(tree->a_nodes[rk[i]]->dist_to_root > + tree->a_nodes[rk[i+1]]->dist_to_root) // Sort in ascending order + { + swap = YES; + + buff = rk[i]; + rk[i] = rk[i+1]; + rk[i+1] = buff; + } + } } + while(swap == YES); + + for(i=0;i<2*tree->n_otu-1;++i) tree->a_nodes[i]->rk_next = NULL; + + for(i=0;i<2*tree->n_otu-2;++i) tree->a_nodes[rk[i]]->rk_next = tree->a_nodes[rk[i+1]]; + + tree->a_nodes[rk[2*tree->n_otu-2]]->rk_next = NULL; + + Free(rk); + } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Make_List_Of_Reachable_Tips(arbre *tree) +void Get_Node_Ranks_From_Times(t_tree *tree) { - int i,j; + int buff; + int i; + int swap = NO; + int *rk; - For(i,2*tree->n_otu-2) + rk = (int *)mCalloc(2*tree->n_otu-1,sizeof(int)); + + for(i=0;i<2*tree->n_otu-1;++i) rk[i] = i; + + do { - tree->noeud[i]->list_of_reachable_tips = (node ***)mCalloc(3,sizeof(node **)); - tree->noeud[i]->n_of_reachable_tips = (int *)mCalloc(3,sizeof(int)); - For(j,3) - tree->noeud[i]->list_of_reachable_tips[j] = (node **)mCalloc(tree->n_otu,sizeof(node *)); + swap = NO; + for(i=0;i<2*tree->n_otu-2;++i) + { + if(tree->rates->nd_t[rk[i+1]] < tree->rates->nd_t[rk[i]]) // Sort in ascending order + { + swap = YES; + + buff = rk[i]; + rk[i] = rk[i+1]; + rk[i+1] = buff; + } + } } + while(swap == YES); + + for(i=0;i<2*tree->n_otu-1;++i) tree->a_nodes[i]->rk_next = NULL; + for(i=0;i<2*tree->n_otu-1;++i) tree->a_nodes[i]->rk_prev = NULL; + + for(i=0;i<2*tree->n_otu-2;++i) tree->a_nodes[rk[i]]->rk_next = tree->a_nodes[rk[i+1]]; + for(i=0;i<2*tree->n_otu-2;++i) tree->a_nodes[rk[i+1]]->rk_prev = tree->a_nodes[rk[i]]; + + Free(rk); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Get_List_Of_Reachable_Tips(arbre *tree) +void Get_Node_Ranks_From_Tip_Times(t_tree *tree) { - int i,j; + int buff; + int i; + int swap = NO; + int *rk; + + rk = (int *)mCalloc(tree->n_otu,sizeof(int)); - For(i,2*tree->n_otu-2) + for(i=0;in_otu;++i) rk[i] = i; + + do { - tree->noeud[i]->n_of_reachable_tips[0] = 0; - tree->noeud[i]->n_of_reachable_tips[1] = 0; - tree->noeud[i]->n_of_reachable_tips[2] = 0; - For(j,tree->n_otu) + swap = NO; + for(i=0;in_otu-1;++i) { - tree->noeud[i]->list_of_reachable_tips[0][j] = NULL; - tree->noeud[i]->list_of_reachable_tips[1][j] = NULL; - tree->noeud[i]->list_of_reachable_tips[2][j] = NULL; + if(tree->rates->nd_t[rk[i+1]] < tree->rates->nd_t[rk[i]]) // Sort in ascending order + { + swap = YES; + + buff = rk[i]; + rk[i] = rk[i+1]; + rk[i+1] = buff; + } } } + while(swap == YES); + + for(i=0;in_otu;++i) tree->a_nodes[i]->rk_next = NULL; + for(i=0;in_otu;++i) tree->a_nodes[i]->rk_prev = NULL; + + for(i=0;in_otu-1;++i) tree->a_nodes[rk[i]]->rk_next = tree->a_nodes[rk[i+1]]; + for(i=0;in_otu-1;++i) tree->a_nodes[rk[i+1]]->rk_prev = tree->a_nodes[rk[i]]; - Get_List_Of_Reachable_Tips_Post(tree->noeud[0], - tree->noeud[0]->v[0], - tree); - Get_List_Of_Reachable_Tips_Pre(tree->noeud[0], - tree->noeud[0]->v[0], - tree); + Free(rk); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Get_List_Of_Reachable_Tips_Post(node *a, node *d, arbre *tree) +/* 'Borrowed' fromn libgen */ +char *Basename(char *path) { - int i,j,k,cpt; + char *p; - if(d->tax) + if( path == NULL || *path == '\0' ) return "."; + + p = path + strlen(path) - 1; + + while( *p == '/' ) { - For(i,3) - if(a->v[i] == d) - { - a->list_of_reachable_tips[i][0] = d; - a->n_of_reachable_tips[i] = 1; - break; - } - return; + if( p == path ) return path; + *p-- = '\0'; } - else - { - For(i,3) - if(d->v[i] != a) - Get_List_Of_Reachable_Tips_Post(d,d->v[i],tree); - For(i,3) - { - if(a->v[i] == d) - { - a->n_of_reachable_tips[i] = 0; - cpt = 0; - For(j,3) - { - if(d->v[j] != a) - { - For(k,d->n_of_reachable_tips[j]) - { - a->list_of_reachable_tips[i][cpt] = d->list_of_reachable_tips[j][k]; - a->n_of_reachable_tips[i]++; - cpt++; - } - } - } - break; - } - } - } + while( p >= path && *p != '/' ) p--; + + return p + 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Get_List_Of_Reachable_Tips_Pre(node *a, node *d, arbre *tree) +/* Find the Last Common Ancestor of n1 and n2 */ +t_node *Find_Lca_Pair_Of_Nodes(t_node *n1, t_node *n2, t_tree *tree) { - int i,j,k,cpt; + t_node **list1, **list2, *lca; + int size1, size2; + + if(n1 == n2) return(n1); - For(i,3) + if(!tree->n_root) { - if(d->v[i] == a) - { - if(a->tax) - { - d->list_of_reachable_tips[i][0] = a; - d->n_of_reachable_tips[i] = 1; - } - else - { - d->n_of_reachable_tips[i] = 0; - cpt = 0; - For(j,3) - { - if(a->v[j] != d) - { - For(k,a->n_of_reachable_tips[j]) - { - d->list_of_reachable_tips[i][cpt] = a->list_of_reachable_tips[j][k]; - d->n_of_reachable_tips[i]++; - cpt++; - } - } - } - } - break; - } + PhyML_Printf("\n. The tree must be rooted in this function."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); } - if(d->tax) return; - else + list1 = (t_node **)mCalloc(2*tree->n_otu-1,sizeof(t_node *)); + list2 = (t_node **)mCalloc(2*tree->n_otu-1,sizeof(t_node *)); + + Get_List_Of_Ancestors(n1,list1,&size1,tree); + Get_List_Of_Ancestors(n2,list2,&size2,tree); + + while(list1[size1] == list2[size2]) { - For(i,3) - if(d->v[i] != a) - Get_List_Of_Reachable_Tips_Pre(d,d->v[i],tree); + size1--; + size2--; + if(size1 < 0 || size2 < 0) break; } -} -/*********************************************************/ + lca = list1[size1+1]; -int Compare_List_Of_Reachable_Tips(node **list1, int size_list1, node **list2, int size_list2) -{ - int i,j,n_matches; + Free(list1); + Free(list2); - n_matches = 0; - For(i,size_list1) + if(lca == NULL) { - For(j,size_list2) - { - if(list1[i] == list2[j]) - { - n_matches++; - } - } + PhyML_Printf("\n. %s",Write_Tree(tree)); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); } - return n_matches; + return lca; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Find_Mutual_Direction(node *n1, node *n2, int *dir_n1_to_n2, int *dir_n2_to_n1) +/* Find the Last Common Ancestor of all the nodes in node_list */ +t_node *Find_Lca_Clade(t_node **node_list, int node_list_size, t_tree *tree) { - int scores[3][3]; - int n_zero_line, n_zero_col; - int i,j; - - For(i,3) For(j,3) scores[i][j] = 0; + t_node ***list, *lca; + int *size; + int i; - For(i,3) + assert(tree->n_root); + + list = (t_node ***)mCalloc(node_list_size,sizeof(t_node **)); + for(i=0;in_otu-1,sizeof(t_node *)); + size = (int *)mCalloc(node_list_size,sizeof(int)); + + for(i=0;ilist_of_reachable_tips[i], - n1->n_of_reachable_tips[i], - n2->list_of_reachable_tips[j], - n2->n_of_reachable_tips[j]); - } + if(!Get_List_Of_Ancestors(node_list[i],list[i],size+i,tree)) + { + for(i=0;iname); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } } - For(i,3) + /* for(i=0;inum, */ + /* node_list[i]->tax ? node_list[i]->name : NULL); */ + /* For(j,size[i]) PhyML_Printf("\n. > %d <",list[i][j]->num); */ + /* } */ + + if(node_list_size > 1) { - n_zero_line = 0; - For(j,3) - { - if(!scores[i][j]) n_zero_line++; - } - if(n_zero_line != 2) {*dir_n1_to_n2 = i; break;} + do + { + for(i=0;inum,size[i],list[i+1][size[i+1]-1]->num,size[i+1]); */ + if(list[i][size[i]-1] != list[i+1][size[i+1]-1]) + { + /* PhyML_Printf("\n. Break at %d %d",list[i][size[i]]->num,list[i+1][size[i+1]]->num); */ + break; + } + } + + if(i != node_list_size-1) break; + + for(i=0;i 0); + } + + if(node_list_size == 1) break; + + }while(1); + lca = list[0][size[0]]; + } + else + { + lca = node_list[0]; } + + for(i=0;inum); */ + + return lca; +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,3) +/* Returns the list of the ancestors of ref_t_node from ref_t_node to the root included */ +int Get_List_Of_Ancestors(t_node *ref_node, t_node **list, int *size, t_tree *tree) +{ + t_node *n; + + n = ref_node; + list[0] = n; + *size = 1; + + if(!n) { - n_zero_col = 0; - For(j,3) - { - if(!scores[j][i]) n_zero_col++; - } - if(n_zero_col != 2) {*dir_n2_to_n1 = i; break;} + PhyML_Printf("\n. There seems to be a problem with the calibration file.\n"); + return 0; } - + + while(n != tree->n_root) + { + n = n->anc; + if(!n) + { + PhyML_Printf("\n. n->anc has not been set properly (call Update_Ancestors first...)\n"); + return 0; + } + list[*size] = n; + *size = *size+1; + } + return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Fill_Dir_Table(arbre *tree) +int Edge_Num_To_Node_Num(int edge_num, t_tree *tree) { - int i,j,k,l; - int found; - - Get_List_Of_Reachable_Tips(tree); - - For(i,tree->n_otu) For(j,2*tree->n_otu-2) tree->t_dir[i][j] = 0; - - for(i=tree->n_otu;i<2*tree->n_otu-2;i++) - For(j,tree->n_otu) - { - found = 0; - For(k,3) - { - For(l,tree->noeud[i]->n_of_reachable_tips[k]) - { - if(tree->noeud[i]->list_of_reachable_tips[k][l] == tree->noeud[j]) - { - found = 1; - tree->t_dir[i][j] = k; - break; - } - } - if(found) break; - } - } + int node_num; + t_edge *b; - for(i=tree->n_otu;i<2*tree->n_otu-2;i++) - for(j=i;j<2*tree->n_otu-2;j++) - { - Find_Mutual_Direction(tree->noeud[i],tree->noeud[j], - &(tree->t_dir[i][j]), - &(tree->t_dir[j][i])); + b = tree->a_edges[edge_num]; + node_num = (b->left == b->rght->anc)?(b->rght->num):(b->left->num); - } + return node_num; } -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Get_Subtree_Size(node *a, node *d) +void Branch_Lengths_To_Rate_Lengths(t_tree *tree) { - int size,i; - - if(d->tax) return 1; - else - { - size = 0; - For(i,3) - if(d->v[i] != a) - size += Get_Subtree_Size(d,d->v[i]); - } - return size; + Branch_Lengths_To_Rate_Lengths_Pre(tree->n_root,tree->n_root->v[2],tree); + Branch_Lengths_To_Rate_Lengths_Pre(tree->n_root,tree->n_root->v[1],tree); } -/*********************************************************/ - +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Triple_Dist_Recur(node *a, node *d, arbre *tree) +void Branch_Lengths_To_Rate_Lengths_Pre(t_node *a, t_node *d, t_tree *tree) { + int i; + + tree->rates->cur_l[d->num] = + tree->rates->br_r[d->num] * + tree->rates->clock_r * + tree->rates->norm_fact; if(d->tax) return; else { - int i; - Triple_Dist(d,tree); - - For(i,3) if(d->v[i] != a) - { - Update_P_Lk(tree,d->b[i],d); - Triple_Dist_Recur(d,d->v[i],tree); - } - For(i,3) if((d->v[i] == a) && !(d->v[i]->tax)) Update_P_Lk(tree,d->b[i],d); + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + Branch_Lengths_To_Rate_Lengths_Pre(d,d->v[i],tree); } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Fast_Br_Len_Recur(node *a, node *d, edge *b, arbre *tree) +int Find_Clade(char **tax_name_list, int list_size, t_tree *tree) { - int i; + int *tax_num_list; + t_node **tax_node_list; + int i,j; + int n_matches; + t_node *lca; - Fast_Br_Len(b,tree); + tax_num_list = (int *)mCalloc(list_size,sizeof(int)); + tax_node_list = (t_node **)mCalloc(list_size,sizeof(t_node *)); - if(d->tax) return; - else For(i,3) if(d->v[i] != a) + for(i=0;ib[i],d); - Fast_Br_Len_Recur(d,d->v[i],d->b[i],tree); + for(j=0;jn_otu;j++) + { + if(!strcmp(tax_name_list[i],tree->a_nodes[j]->name)) + { + tax_num_list[i] = tree->a_nodes[j]->num; + tax_node_list[i] = tree->a_nodes[j]; + n_matches++; + break; + } + } + + if(j == tree->n_otu) + { + PhyML_Printf("\n. Problem with the calibration file."); + PhyML_Printf("\n. Could not find taxon with name '%s' in the sequence or tree file.",tax_name_list[i]); + /* Generic_Exit(__FILE__,__LINE__,__FUNCTION__); */ + } } - For(i,3) if((d->v[i] == a) && !(d->v[i]->tax)) Update_P_Lk(tree,d->b[i],d); + lca = Find_Lca_Clade(tax_node_list,n_matches,tree); + + Free(tax_num_list); + Free(tax_node_list); + + if(lca) return lca->num; + else return -1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -void Fast_Br_Len(edge *b, arbre *tree) +void Find_Clade_Pre(t_node *a, t_node *d, int *tax_num_list, int list_size, int *num, t_tree *tree) { - phydbl sum; - phydbl ***prob, ****core, *F; - int i, j, k, site; - phydbl *pi; - phydbl v_rght; + int i,j,k; + int score; -/* Br_Len_Brent(10.*b->l,b->l,BL_MIN, */ -/* tree->mod->s_opt->min_diff_lk_local, */ -/* b,tree, */ -/* tree->mod->s_opt->brent_it_max); */ + for(i=0;i<3;i++) + if((d->v[i] == a) || (d->b[i] == tree->e_root)) + { + if(list_size == d->bip_size[i]) + { + score = 0; + For(j,d->bip_size[i]) + { + for(k=0;kbip_node[i][j]->num) + { + score++; + break; + } + } + } + if(score == list_size) *num = d->num; + } + break; + } + if(d->tax) return; + else + for(i=0;i<3;i++) + if((d->v[i] != a) && (d->b[i] != tree->e_root)) + Find_Clade_Pre(d,d->v[i],tax_num_list,list_size,num,tree); +} - core = tree->triplet_struct->core; - prob = tree->triplet_struct->p_one_site; - F = tree->triplet_struct->F_bc; - pi = tree->triplet_struct->pi_bc; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,tree->mod->ns) pi[i] = tree->mod->pi[i]; +t_edge *Find_Root_Edge(FILE *fp_input_tree, t_tree *tree) +{ + char **subs; + int degree; + int i,j; + t_node *left, *rght; + int l_r, r_l; + int score; + char *line; + char c; + t_edge *root_edge; - Update_PMat_At_Given_Edge(b,tree); + line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); - For(i,tree->mod->ns) For(j,tree->mod->ns) For(k,tree->mod->n_catg) - core[k][0][i][j] = b->Pij_rr[k][i][j]*tree->mod->pi[i]*tree->mod->gamma_r_proba[k]; + rewind(fp_input_tree); - For(i,tree->mod->ns) For(j,tree->mod->ns) F[tree->mod->ns*i+j] = .0; + do c=fgetc(fp_input_tree); + while((c != '(') && (c != EOF)); - For(site,tree->n_pattern) + if(c==EOF) { - For(i,tree->mod->ns) For(j,tree->mod->ns) prob[0][i][j] = .0; + Free(line); + return NULL; + } - /* Joint probabilities of the states at the two ends of the edge */ - v_rght = -1.; - For(i,tree->mod->ns) - { - For(j,tree->mod->ns) - { - For(k,tree->mod->n_catg) - { - v_rght = (b->rght->tax)?((phydbl)(b->p_lk_tip_r[site][j])):(b->p_lk_rght[site][k][j]); - - prob[0][i][j] += - core[k][0][i][j] * - b->p_lk_left[site][k][i] * - v_rght; - } - } - } + i=0; + for(;;) + { + if((c == ' ') || (c == '\n')) + { + c=fgetc(fp_input_tree); + if(c==EOF) break; + else continue; + } - sum = .0; - For(i,tree->mod->ns) For(j,tree->mod->ns) sum += prob[0][i][j]; + line[i]=c; + i++; + c=fgetc(fp_input_tree); + if(c==EOF || c==';') break; + } - /* Scaling */ - For(i,tree->mod->ns) For(j,tree->mod->ns) prob[0][i][j] /= sum; - /* Expected number of each pair of states */ - For(i,tree->mod->ns) For(j,tree->mod->ns) - F[tree->mod->ns*i+j] += tree->data->wght[site] * prob[0][i][j]; - } + Free_Bip(tree); + Alloc_Bip(tree); + Get_Bip(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); - sum = .0; - For(i,tree->mod->ns) + subs = Sub_Trees(line,°ree); + Clean_Multifurcation(subs,degree,3); + if(degree != 2) { - tree->mod->pi[i] = .0; - For(j,tree->mod->ns) - { - tree->mod->pi[i] += (F[tree->mod->ns*i+j] + F[tree->mod->ns*j+i])/2.; - } - tree->mod->pi[i] /= (phydbl)tree->data->init_len; - sum += tree->mod->pi[i]; + PhyML_Printf("\n. The tree does not seem to be rooted..."); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); } - For(i,tree->mod->ns) tree->mod->pi[i] /= sum; + left = rght = NULL; + l_r = r_l = -1; -#ifdef DEBUG - sum = .0; - For(i,tree->mod->ns) sum += tree->mod->pi[i]; - if((int)rint(sum) != 1) + For(i,2*tree->n_otu-3) { - printf("\n. site %d sum = %f ",site,sum); - printf("pi = "); - For(i,tree->mod->ns) printf("%f ",tree->mod->pi[i]); - printf("\n"); - } -#endif + left = tree->a_edges[i]->left; + rght = tree->a_edges[i]->rght; + l_r = tree->a_edges[i]->l_r; + r_l = tree->a_edges[i]->r_l; - Divide_Cells(&F,(phydbl)tree->data->init_len,tree); - Make_Symmetric(&F,tree->mod->ns); + score = 0; + For(j,left->bip_size[l_r]) if(strstr(subs[1],left->bip_node[l_r][j]->name)) score++; + if(score == left->bip_size[l_r]) break; -#ifdef DEBUG - phydbl lk_a, lk_b; - if(b->l < BL_MIN) b->l = BL_MIN; - else if(b->l > BL_MAX) b->l = BL_MAX; - lk_b = Lk_Dist(F,b->l,tree->mod); -#endif + score = 0; + For(j,rght->bip_size[r_l]) if(strstr(subs[1],rght->bip_node[r_l][j]->name)) score++; + if(score == rght->bip_size[r_l]) break; + } - Opt_Dist_F(&(b->l),F,tree->mod); - - if(b->l < BL_MIN) b->l = BL_MIN; - else if(b->l > BL_MAX) b->l = BL_MAX; + root_edge = tree->a_edges[i]; -#ifdef DEBUG - lk_a = Lk_Dist(F,b->l,tree->mod); + i = 0; + while(subs[i] != NULL) Free(subs[i++]); + Free(subs); + Free(line); - if(lk_b > lk_a + tree->mod->s_opt->min_diff_lk_local) + if(i == 2*tree->n_otu-3) { - printf("\n. b->l = %f %d %f lk_b=%f lk_a=%f", - b->l, - tree->mod->n_catg,tree->mod->alpha, - lk_b,lk_a); + PhyML_Printf("\n. Could not find the root edge..."); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); } -#endif - For(i,tree->mod->ns) tree->mod->pi[i] = pi[i]; + return root_edge; } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ - -eigen *Make_Eigen_Struct(model *mod) +void Copy_Tree_Topology_With_Labels(t_tree *ori, t_tree *cpy) { - eigen *eig; - - eig = (eigen *)mCalloc(1,sizeof(eigen)); - eig->size = mod->ns; - eig->space = (double *)mCalloc(2*mod->ns,sizeof(double)); - eig->space_int = (int *)mCalloc(2*mod->ns,sizeof(int)); - eig->e_val = (double *)mCalloc(mod->ns,sizeof(double)); - eig->e_val_im = (double *)mCalloc(mod->ns,sizeof(double)); - eig->r_e_vect = (double *)mCalloc(mod->ns*mod->ns,sizeof(double)); - eig->r_e_vect_im = (double *)mCalloc(mod->ns*mod->ns,sizeof(double)); - eig->l_e_vect = (double *)mCalloc(mod->ns*mod->ns,sizeof(double)); - eig->q = (double *)mCalloc(mod->ns*mod->ns,sizeof(double)); - - return eig; -} - -/*********************************************************/ + int i,j; -ttriplet *Make_Triplet_Struct(model *mod) -{ - int i,j,k; - ttriplet *triplet_struct; - - triplet_struct = (ttriplet *)mCalloc(1,sizeof(ttriplet)); - triplet_struct->size = mod->ns; - triplet_struct->pi_bc = (phydbl *)mCalloc(mod->ns,sizeof(phydbl )); - triplet_struct->pi_cd = (phydbl *)mCalloc(mod->ns,sizeof(phydbl )); - triplet_struct->pi_bd = (phydbl *)mCalloc(mod->ns,sizeof(phydbl )); - triplet_struct->F_bc = (phydbl *)mCalloc(mod->ns*mod->ns,sizeof(phydbl)); - triplet_struct->F_cd = (phydbl *)mCalloc(mod->ns*mod->ns,sizeof(phydbl)); - triplet_struct->F_bd = (phydbl *)mCalloc(mod->ns*mod->ns,sizeof(phydbl)); - triplet_struct->core = (phydbl ****)mCalloc(mod->n_catg,sizeof(phydbl ***)); - triplet_struct->p_one_site = (phydbl ***)mCalloc(mod->ns,sizeof(phydbl **)); - triplet_struct->sum_p_one_site = (phydbl ***)mCalloc(mod->ns,sizeof(phydbl **)); - triplet_struct->eigen_struct = (eigen *)Make_Eigen_Struct(mod); - triplet_struct->mod = mod; - - For(k,mod->n_catg) - { - triplet_struct->core[k] = (phydbl ***)mCalloc(mod->ns,sizeof(phydbl **)); - For(i,mod->ns) - { - triplet_struct->core[k][i] = (phydbl **)mCalloc(mod->ns,sizeof(phydbl *)); - For(j,mod->ns) - triplet_struct->core[k][i][j] = (phydbl *)mCalloc(mod->ns,sizeof(phydbl )); - } + For(i,2*ori->n_otu-2) + { + for(j=0;j<3;j++) + { + if(ori->a_nodes[i]->v[j]) + { + cpy->a_nodes[i]->v[j] = cpy->a_nodes[ori->a_nodes[i]->v[j]->num]; + } + else + cpy->a_nodes[i]->v[j] = NULL; + } + cpy->a_nodes[i]->num = ori->a_nodes[i]->num; + cpy->a_nodes[i]->tax = 0; } - For(i,mod->ns) + For(i,2*ori->n_otu-3) { - triplet_struct->p_one_site[i] = (phydbl **)mCalloc(mod->ns,sizeof(phydbl *)); - For(j,mod->ns) - triplet_struct->p_one_site[i][j] = (phydbl *)mCalloc(mod->ns,sizeof(phydbl )); + cpy->a_edges[i]->l->v = ori->a_edges[i]->l->v; } - For(i,mod->ns) + for(i=0;in_otu;i++) { - triplet_struct->sum_p_one_site[i] = (phydbl **)mCalloc(mod->ns,sizeof(phydbl *)); - For(j,mod->ns) - triplet_struct->sum_p_one_site[i][j] = (phydbl *)mCalloc(mod->ns,sizeof(phydbl )); + cpy->a_nodes[i]->tax = 1; + strcpy(cpy->a_nodes[i]->name,ori->a_nodes[i]->name); } - return triplet_struct; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Triple_Dist(node *a, arbre *tree) +void Set_Model_Name(t_mod *mod) { - - if(a->tax) return; - else + switch(mod->whichmodel) { - Update_PMat_At_Given_Edge(a->b[1],tree); - Update_PMat_At_Given_Edge(a->b[2],tree); - Update_P_Lk(tree,a->b[0],a); - Fast_Br_Len(a->b[0],tree); - Update_PMat_At_Given_Edge(a->b[0],tree); - - Update_P_Lk(tree,a->b[1],a); - Fast_Br_Len(a->b[1],tree); - Update_PMat_At_Given_Edge(a->b[1],tree); - - Update_P_Lk(tree,a->b[2],a); - Fast_Br_Len(a->b[2],tree); - Update_PMat_At_Given_Edge(a->b[2],tree); + case JC69: + { + strcpy(mod->modelname->s, "JC69"); + break; + } + case K80: + { + strcpy(mod->modelname->s, "K80"); + break; + } + case F81: + { + strcpy(mod->modelname->s, "F81"); + break; + } + case HKY85: + { + strcpy(mod->modelname->s, "HKY85"); + break; + } + case F84: + { + strcpy(mod->modelname->s, "F84"); + break; + } + case TN93: + { + strcpy(mod->modelname->s, "TN93"); + break; + } + case GTR: + { + strcpy(mod->modelname->s, "GTR"); + break; + } + case CUSTOM: + { + strcpy(mod->modelname->s, "Custom"); + break; + } + case DAYHOFF: + { + strcpy(mod->modelname->s, "Dayhoff"); + break; + } + case JTT: + { + strcpy(mod->modelname->s, "JTT"); + break; + } + case MTREV: + { + strcpy(mod->modelname->s, "MtREV"); + break; + } + case LG: + { + strcpy(mod->modelname->s, "LG"); + break; + } + case WAG: + { + strcpy(mod->modelname->s, "WAG"); + break; + } + case DCMUT: + { + strcpy(mod->modelname->s, "DCMut"); + break; + } + case RTREV: + { + strcpy(mod->modelname->s, "RtREV"); + break; + } + case CPREV: + { + strcpy(mod->modelname->s, "CpREV"); + break; + } + case VT: + { + strcpy(mod->modelname->s, "VT"); + break; + } + case BLOSUM62: + { + strcpy(mod->modelname->s, "Blosum62"); + break; + } + case MTMAM: + { + strcpy(mod->modelname->s, "MtMam"); + break; + } + case MTART: + { + strcpy(mod->modelname->s, "MtArt"); + break; + } + case HIVW: + { + strcpy(mod->modelname->s, "HIVw"); + break; + } + case HIVB: + { + strcpy(mod->modelname->s, "HIVb"); + break; + } + case AB: + { + strcpy(mod->modelname->s, "AB"); + break; + } + case CUSTOMAA: + { + strcpy(mod->modelname->s, "Custom"); + break; + } + case FLU: + { + strcpy(mod->modelname->s, "FLU"); + break; + } + default: + { + PhyML_Printf("\n. Unknown model name.\n"); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + break; + } + } +} - Update_P_Lk(tree,a->b[1],a); - Update_P_Lk(tree,a->b[0],a); - - -/* node *b,*c,*d; */ -/* int _a,_b,_c,_d; */ -/* int dir_b,dir_c,dir_d; */ -/* int i, site, gamma; */ -/* phydbl ***p_lk_b,***p_lk_c,***p_lk_d; */ -/* double ***P_ab,***P_ac,***P_ad; */ -/* phydbl ***prob,***sum_prob,****core,*F_bc,*F_cd,*F_bd,*pi_bc,*pi_cd,*pi_bd; */ -/* phydbl sum, len; */ -/* phydbl d_bc, d_cd, d_bd; */ -/* double *eigen_val_real, *eigen_val_im, *eigen_vect_real, *eigen_vect_im, *space; */ - -/* pi_bc = tree->triplet_struct->pi_bc; */ -/* pi_cd = tree->triplet_struct->pi_cd; */ -/* pi_bd = tree->triplet_struct->pi_bd; */ -/* core = tree->triplet_struct->core; */ -/* prob = tree->triplet_struct->p_one_site; */ -/* sum_prob = tree->triplet_struct->sum_p_one_site; */ -/* F_bc = tree->triplet_struct->F_bc; */ -/* F_cd = tree->triplet_struct->F_cd; */ -/* F_bd = tree->triplet_struct->F_bd; */ -/* eigen_val_real = tree->triplet_struct->eigen_struct->eigen_val_real; */ -/* eigen_val_im = tree->triplet_struct->eigen_struct->eigen_val_im; */ -/* eigen_vect_real = tree->triplet_struct->eigen_struct->eigen_vect_real; */ -/* eigen_vect_im = tree->triplet_struct->eigen_struct->eigen_vect_im; */ -/* space = tree->triplet_struct->eigen_struct->space; */ - -/* p_lk_b = p_lk_c = p_lk_d = NULL; */ -/* P_ab = P_ac = P_ad = NULL; */ -/* b = c = d = NULL; */ -/* dir_b = dir_c = dir_d = -1; */ -/* For(i,3) */ -/* { */ -/* if(!b) */ -/* { */ -/* b = a->v[i]; */ -/* p_lk_b = (a == a->b[i]->left)?(a->b[i]->p_lk_rght):(a->b[i]->p_lk_left); */ -/* P_ab = a->b[i]->Pij_rr; */ -/* dir_b = i; */ -/* } */ -/* else if(!c) */ -/* { */ -/* c = a->v[i]; */ -/* p_lk_c = (a == a->b[i]->left)?(a->b[i]->p_lk_rght):(a->b[i]->p_lk_left); */ -/* P_ac = a->b[i]->Pij_rr; */ -/* dir_c = i; */ -/* } */ -/* else if(!d) */ -/* { */ -/* d = a->v[i]; */ -/* p_lk_d = (a == a->b[i]->left)?(a->b[i]->p_lk_rght):(a->b[i]->p_lk_left); */ -/* P_ad = a->b[i]->Pij_rr; */ -/* dir_d = i; */ -/* } */ -/* } */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/* For(_b,tree->mod->ns) For(_c,tree->mod->ns) For(_d,tree->mod->ns) sum_prob[_b][_c][_d] = .0; */ +void Adjust_Min_Diff_Lk(t_tree *tree) +{ + if(sizeof(phydbl) == 4) + { + int exponent; + exponent = (int)FLOOR(log10(FABS(tree->c_lnL))); + tree->mod->s_opt->min_diff_lk_local = POW(10.,exponent - FLT_DIG + 1); + tree->mod->s_opt->min_diff_lk_move = tree->mod->s_opt->min_diff_lk_local; + } +/* PhyML_Printf("\n. Exponent = %d Precision = %E DIG = %d",exponent,tree->mod->s_opt->min_diff_lk_local,FLT_DIG); */ +} -/* For(i,tree->mod->n_catg) */ -/* { */ -/* len = a->b[dir_b]->l * tree->mod->rr[i]; */ -/* if(len < BL_MIN) len = BL_MIN; */ -/* else if(len > BL_MAX) len = BL_MAX; */ -/* PMat(len,tree->mod,&(P_ab[i])); */ -/* } */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/* For(i,tree->mod->n_catg) */ -/* { */ -/* len = a->b[dir_c]->l * tree->mod->rr[i]; */ -/* if(len < BL_MIN) len = BL_MIN; */ -/* else if(len > BL_MAX) len = BL_MAX; */ -/* PMat(len,tree->mod,&(P_ac[i])); */ -/* } */ -/* For(i,tree->mod->n_catg) */ -/* { */ -/* len = a->b[dir_d]->l * tree->mod->rr[i]; */ -/* if(len < BL_MIN) len = BL_MIN; */ -/* else if(len > BL_MAX) len = BL_MAX; */ -/* PMat(len,tree->mod,&(P_ad[i])); */ -/* } */ +/*! + tree->a_nodes[i]->name is initially a number. It is translated into + a string of characters using the names provided in the tax_name + array. + */ +void Translate_Tax_Names(char **tax_names, t_tree *tree) +{ + int i; + int tax_num; -/* /\* PMat(a->b[dir_b]->l,tree->mod,&(P_ab[0])); *\/ */ -/* /\* PMat(a->b[dir_c]->l,tree->mod,&(P_ac[0])); *\/ */ -/* /\* PMat(a->b[dir_d]->l,tree->mod,&(P_ad[0])); *\/ */ + for(i=0;in_otu;i++) + { + tax_num = strtol(tree->a_nodes[i]->name,NULL,10); + tree->a_nodes[i]->name = tax_names[tax_num-1]; + } +} -/* For(gamma,tree->mod->n_catg) */ -/* { */ -/* For(_b,tree->mod->ns) */ -/* { */ -/* For(_c,tree->mod->ns) */ -/* { */ -/* For(_d,tree->mod->ns) */ -/* { */ -/* core[gamma][_b][_c][_d] = .0; */ -/* For(_a,tree->mod->ns) */ -/* { */ -/* core[gamma][_b][_c][_d] += */ -/* tree->mod->r_proba[gamma] * */ -/* tree->mod->pi[_a] * */ -/* P_ab[gamma][_a][_b] * */ -/* P_ac[gamma][_a][_c] * */ -/* P_ad[gamma][_a][_d] ; */ -/* } */ -/* } */ -/* } */ -/* } */ -/* } */ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/* For(site,tree->n_pattern) */ -/* { */ -/* For(_b,tree->mod->ns) For(_c,tree->mod->ns) For(_d,tree->mod->ns) prob[_b][_c][_d] = .0; */ +/*! + Skip coment in NEXUS file. + */ +void Skip_Comment(FILE *fp) +{ + int in_comment; + char c; -/* For(gamma,tree->mod->n_catg) */ -/* For(_b,tree->mod->ns) */ -/* For(_c,tree->mod->ns) */ -/* For(_d,tree->mod->ns) */ -/* prob[_b][_c][_d] += */ -/* core[gamma][_b][_c][_d] * */ -/* p_lk_b[site][gamma][_b] * */ -/* p_lk_c[site][gamma][_c] * */ -/* p_lk_d[site][gamma][_d] ; */ + in_comment = 1; + do + { + c = fgetc(fp); + if(c == EOF) break; + if(c == '[') in_comment++; + else if(c == ']') in_comment--; + } + while(in_comment); +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/* sum = .0; */ -/* For(_b,tree->mod->ns) For(_c,tree->mod->ns) For(_d,tree->mod->ns) sum += prob[_b][_c][_d]; */ +/*! + Determine the most appropriate position of the root if outgroup taxa are specified. + */ -/* For(_b,tree->mod->ns) For(_c,tree->mod->ns) For(_d,tree->mod->ns) prob[_b][_c][_d] /= sum; */ +void Get_Best_Root_Position(t_tree *tree) +{ + int i,j; + phydbl eps; + phydbl s, s_max; + t_edge *best_edge; + int has_outgrp; -/* For(_b,tree->mod->ns) For(_c,tree->mod->ns) For(_d,tree->mod->ns) */ -/* sum_prob[_b][_c][_d] += */ -/* tree->data->wght[site]* */ -/* prob[_b][_c][_d]; */ -/* } */ + best_edge = NULL; + if(tree->n_root) + { + PhyML_Printf("\n. Tree already has a root."); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + PhyML_Printf("\n. PhyML finished prematurely."); + assert(FALSE); + } -/* For(_b,tree->mod->ns) */ -/* { */ -/* pi_bc[_b] = .0; */ -/* For(_c,tree->mod->ns) */ -/* { */ -/* F_bc[tree->mod->ns*_b+_c] = .0; */ -/* For(_d,tree->mod->ns) */ -/* { */ -/* F_bc[tree->mod->ns*_b+_c] += sum_prob[_b][_c][_d]; */ -/* } */ -/* pi_bc[_b] += (F_bc[tree->mod->ns*_b+_c]+F_bc[tree->mod->ns*_c+_b])/2.; */ -/* } */ -/* pi_bc[_b] /= (phydbl)tree->data->init_len; */ -/* } */ + has_outgrp = NO; -/* For(_c,tree->mod->ns) */ -/* { */ -/* pi_cd[_c] = .0; */ -/* For(_d,tree->mod->ns) */ -/* { */ -/* F_cd[tree->mod->ns*_c+_d] = .0; */ -/* For(_b,tree->mod->ns) */ -/* { */ -/* F_cd[tree->mod->ns*_c+_d] += sum_prob[_b][_c][_d]; */ -/* } */ -/* pi_cd[_c] += (F_cd[tree->mod->ns*_c+_d]+F_cd[tree->mod->ns*_d+_c])/2.; */ -/* } */ -/* pi_cd[_c] /= (phydbl)tree->data->init_len; */ -/* } */ + if(strstr(tree->a_nodes[0]->name,"*")) + { + /* PhyML_Printf("\n. Found outgroup taxon: %s",tree->a_nodes[0]->name); */ + tree->a_nodes[0]->s_ingrp[0] = 0; + tree->a_nodes[0]->s_outgrp[0] = 1; + has_outgrp = YES; + } + else + { + tree->a_nodes[0]->s_ingrp[0] = 1; + tree->a_nodes[0]->s_outgrp[0] = 0; + } -/* For(_b,tree->mod->ns) */ -/* { */ -/* pi_bd[_b] = .0; */ -/* For(_d,tree->mod->ns) */ -/* { */ -/* F_bd[tree->mod->ns*_b+_d] = .0; */ -/* For(_c,tree->mod->ns) */ -/* { */ -/* F_bd[tree->mod->ns*_b+_d] += sum_prob[_b][_c][_d]; */ -/* } */ -/* pi_bd[_b] += (F_bd[tree->mod->ns*_b+_d]+F_bd[tree->mod->ns*_d+_b])/2.; */ -/* } */ -/* pi_bd[_b] /= (phydbl)tree->data->init_len; */ -/* } */ + Get_Best_Root_Position_Post(tree->a_nodes[0],tree->a_nodes[0]->v[0],&has_outgrp,tree); + Get_Best_Root_Position_Pre(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); -/* Divide_Cells(&F_bc,(phydbl)tree->data->init_len,tree); */ -/* Divide_Cells(&F_cd,(phydbl)tree->data->init_len,tree); */ -/* Divide_Cells(&F_bd,(phydbl)tree->data->init_len,tree); */ + if(has_outgrp == YES) + { -/* Make_Symmetric(&F_bc,tree->mod->ns); */ -/* Make_Symmetric(&F_cd,tree->mod->ns); */ -/* Make_Symmetric(&F_bd,tree->mod->ns); */ + Free_Edge_Lk_Rght(tree->a_edges[2*tree->n_otu-3]); + Free_Edge_Lk_Rght(tree->a_edges[2*tree->n_otu-2]); + Free_Edge_Pars_Rght(tree->a_edges[2*tree->n_otu-3]); + Free_Edge_Pars_Rght(tree->a_edges[2*tree->n_otu-2]); -/* d_bc = d_cd = d_bd = 0.1; */ + eps = 1.E-10; + s = s_max = 0.0; + for(i=0;i<2*tree->n_otu-2;++i) + { + for(j=0;j<3;j++) + { + s = (tree->a_nodes[i]->s_outgrp[j]+eps) / (tree->a_nodes[i]->s_ingrp[j] + eps) ; + /* printf("\n. [%d %d] %d %d",i,j,tree->a_nodes[i]->s_outgrp[j],tree->a_nodes[i]->s_ingrp[j]); */ + if(s > s_max) + { + s_max = s; + best_edge = tree->a_nodes[i]->b[j]; + } + } + } + Add_Root(best_edge,tree); + } +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/* /\* Dist_F_Brent(&(d_bc),F_bc,BL_MIN,d_bc,BL_MAX,1.E-4,&(d_bc),tree->mod,100); *\/ */ -/* /\* Dist_F_Brent(&(d_cd),F_cd,BL_MIN,d_cd,BL_MAX,1.E-4,&(d_cd),tree->mod,100); *\/ */ -/* /\* Dist_F_Brent(&(d_bd),F_bd,BL_MIN,d_bd,BL_MAX,1.E-4,&(d_bd),tree->mod,100); *\/ */ -/* Opt_Dist_F(&(d_bc),F_bc,tree->mod); */ -/* Opt_Dist_F(&(d_cd),F_cd,tree->mod); */ -/* Opt_Dist_F(&(d_bd),F_bd,tree->mod); */ +/*! + Determine the most appropriate position of the root if outgroup taxa are specified. + Post-traversal. + */ +void Get_Best_Root_Position_Post(t_node *a, t_node *d, int *has_outgrp, t_tree *tree) +{ + if(d->tax) + { + if(strstr(d->name,"*")) + { + *has_outgrp = YES; + /* PhyML_Printf("\n. Found outgroup taxon: %s",d->name); */ + d->s_ingrp[0] = NO; + d->s_outgrp[0] = YES; + } + else + { + d->s_ingrp[0] = YES; + d->s_outgrp[0] = NO; + } + return; + } + else + { + int i; + + for(i=0;i<3;i++) + if(d->v[i] != a && (d->b[i] != tree->e_root)) + Get_Best_Root_Position_Post(d,d->v[i],has_outgrp,tree); + + Get_OutIn_Scores(a,d); - - -/* /\* d_bc = GTR_Dist(F_bc,(tree->mod->n_catg > 1)?(tree->mod->alpha):(-1.),tree->triplet_struct->eigen_struct); *\/ */ -/* /\* d_bd = GTR_Dist(F_bd,(tree->mod->n_catg > 1)?(tree->mod->alpha):(-1.),tree->triplet_struct->eigen_struct); *\/ */ -/* /\* d_cd = GTR_Dist(F_cd,(tree->mod->n_catg > 1)?(tree->mod->alpha):(-1.),tree->triplet_struct->eigen_struct); *\/ */ - -/* a->b[dir_b]->l = (d_bc-d_cd+d_bd)/2.; */ -/* a->b[dir_c]->l = (d_bc-d_bd+d_cd)/2.; */ -/* a->b[dir_d]->l = (d_bd-d_bc+d_cd)/2.; */ - -/* if(a->b[dir_b]->l < BL_MIN) a->b[dir_b]->l = BL_MIN; */ -/* else if(a->b[dir_b]->l > BL_MAX) a->b[dir_b]->l = BL_MAX; */ -/* if(a->b[dir_c]->l < BL_MIN) a->b[dir_c]->l = BL_MIN; */ -/* else if(a->b[dir_c]->l > BL_MAX) a->b[dir_c]->l = BL_MAX; */ -/* if(a->b[dir_d]->l < BL_MIN) a->b[dir_d]->l = BL_MIN; */ -/* else if(a->b[dir_d]->l > BL_MAX) a->b[dir_d]->l = BL_MAX; */ } } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ -void Make_Symmetric(phydbl **F, int size) +/*! + Determine the most appropriate position of the root if outgroup taxa are specified. + Pre-traversal. + */ +void Get_Best_Root_Position_Pre(t_node *a, t_node *d, t_tree *tree) { - int i,j; - - For(i,size) + if(d->tax) { - for(j=i+1;jv[i] != a && (d->b[i] != tree->e_root)) + { + Get_OutIn_Scores(d->v[i],d); + Get_Best_Root_Position_Pre(d,d->v[i],tree); + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Round_Down_Freq_Patt(phydbl **F, arbre *tree) + +/*! + Determine the most appropriate position of the root if outgroup taxa are specified. + Core. + */ +void Get_OutIn_Scores(t_node *a, t_node *d) { - int i,j; + int i,d_v1,d_v2,v1_d,v2_d,d_a; - For(i,tree->mod->ns) + d_a = v1_d = v2_d = -1; + d_v1 = d_v2 = -1; + for(i=0;i<3;i++) { - For(j,tree->mod->ns) - { - (*F)[tree->mod->ns*i+j] = rint((*F)[tree->mod->ns*i+j]); - } + if(d->v[i] != a) + { + if(d_v1 < 0) d_v1 = i; + else d_v2 = i; + } } -} - -/*********************************************************/ -phydbl Get_Sum_Of_Cells(phydbl *F, arbre *tree) -{ - int i,j; - phydbl sum = .0; + for(i=0;i<3;i++) if(d->v[i] == a) { d_a = i; break; } + for(i=0;i<3;i++) if(d->v[d_v1]->v[i] == d) { v1_d = i; break; } + for(i=0;i<3;i++) if(d->v[d_v2]->v[i] == d) { v2_d = i; break; } - For(i,tree->mod->ns) - For(j,tree->mod->ns) - sum += F[tree->mod->ns*i+j]; + d->s_ingrp[d_a] = + d->v[d_v1]->s_ingrp[v1_d] + + d->v[d_v2]->s_ingrp[v2_d] ; - return sum; + d->s_outgrp[d_a] = + d->v[d_v1]->s_outgrp[v1_d] + + d->v[d_v2]->s_outgrp[v2_d] ; } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ - -void Divide_Cells(phydbl **F, phydbl div, arbre *tree) +int Check_Sequence_Name(char *s) { - int i,j; - - For(i,tree->mod->ns) - For(j,tree->mod->ns) - (*F)[tree->mod->ns*i+j] /= div; -} - -/*********************************************************/ + int i; + /* if(rindex(s,':')) */ + For(i,strlen(s)) + { + if(s[i] == ':') + { + PhyML_Printf("\n. Character ':' is not permitted in sequence name (%s).",s); + PhyML_Printf("\n. Err. in file %s at line %d",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } + } + /* if(rindex(s,',')) */ + For(i,strlen(s)) + { + if(s[i] == ',') + { + PhyML_Printf("\n. Character ',' is not permitted in sequence name (%s).",s); + PhyML_Printf("\n. Err in file %s at line %d",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } + } + /* if(rindex(s,' ')) */ + For(i,strlen(s)) + { + if(s[i] == ' ') + { + PhyML_Printf("\n. Character ' ' is not permitted in sequence name (%s).",s); + PhyML_Printf("\n. Err in file %s at line %d",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } + } -void Divide_Mat_By_Vect(phydbl **F, phydbl *vect, int size) -{ - int i,j; - For(i,size) - For(j,size) - (*F)[size*i+j] = (*F)[size*i+j] / vect[j]; + return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Multiply_Mat_By_Vect(phydbl **F, phydbl *vect, int size) +int Scale_Subtree_Height(t_node *a, phydbl K, phydbl floor, int *n_nodes, t_tree *tree) { - int i,j; - For(i,size) - For(j,size) - (*F)[size*i+j] = (*F)[size*i+j] * vect[j]; -} + phydbl new_height; -/*********************************************************/ + if(a->tax == YES) return 0; + + *n_nodes = 0; -int Check_Spr_Move_Validity(spr *this_spr_move, arbre *tree) -{ - int match; + new_height = .0; - match = 0; - Found_In_Subtree(this_spr_move->n_link, - this_spr_move->n_opp_to_link, - this_spr_move->b_target->left, - &match, - tree); + if(!(tree->rates->nd_t[a->num] > floor)) new_height = K*(tree->rates->nd_t[a->num]-floor)+floor; - if(match) return 0; - else return 1; + if(a == tree->n_root) + { + tree->rates->nd_t[tree->n_root->num] = new_height; + *n_nodes = 1; + + Scale_Node_Heights_Post(tree->n_root,tree->n_root->v[2],K,floor,n_nodes,tree); + Scale_Node_Heights_Post(tree->n_root,tree->n_root->v[1],K,floor,n_nodes,tree); + } + else + { + int i; + + if(new_height < tree->rates->nd_t[a->anc->num]) return 0; + else + { + tree->rates->nd_t[a->num] = new_height; + *n_nodes = 1; + } + + for(i=0;i<3;i++) + if(a->v[i] != a->anc && a->b[i] != tree->e_root) + { + Scale_Node_Heights_Post(a,a->v[i],K,floor,n_nodes,tree); + } + } + + return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Found_In_Subtree(node *a, node *d, node *target, int *match, arbre *tree) +void Scale_Node_Heights_Post(t_node *a, t_node *d, phydbl K, phydbl floor, int *n_nodes, t_tree *tree) { + if(d == tree->n_root) + { + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + if(d->tax) return; else { int i; - if(d == target) *match = 1; - For(i,3) - { - if(d->v[i] != a) - Found_In_Subtree(d,d->v[i],target,match,tree); - } + + /* It is tempting to set floor = tree->rates->t_prior_max[d->num]; but + it then becomes possible for nodes with different floor values + to have their orders interverted (i.e., ancestor below descendant) + */ + if((tree->rates->nd_t[d->num] > floor) == NO) // If node is strictly older than floor + { + tree->rates->nd_t[d->num] = K*(tree->rates->nd_t[d->num]-floor)+floor; + *n_nodes = *n_nodes+1; + } + + if(tree->rates->nd_t[d->num] < tree->rates->nd_t[a->num]) + { + PhyML_Printf("\n. K = %f floor = %f t_prior_max(a) = %f t_prior_max(d) = %f a->t = %f d->t %f", + K,floor,tree->rates->t_prior_max[a->num],tree->rates->t_prior_max[d->num], + tree->rates->nd_t[a->num],tree->rates->nd_t[d->num]); + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Warn_And_Exit("\n. PhyML finished prematurely."); + } + + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + Scale_Node_Heights_Post(d,d->v[i],K,floor,n_nodes,tree); + } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Get_List_Of_Target_Edges(node *a, node *d, edge **list, int *list_size, arbre *tree) +int Scale_Subtree_Rates(t_node *a, phydbl mult, int *n_nodes, t_tree *tree) { + int res; int i; + + *n_nodes = 0; + res = 1; - For(i,3) + if(a == tree->n_root) { - if(a->v[i] && a->v[i] == d) - { - list[*list_size] = a->b[i]; - (*list_size)++; - } + res = Scale_Subtree_Rates_Post(a,a->v[2],mult,n_nodes,tree); + if(res) res = Scale_Subtree_Rates_Post(a,a->v[1],mult,n_nodes,tree); + return res; } - - if(d->tax) return; else { - For(i,3) - { - if(d->v[i] != a) - Get_List_Of_Target_Edges(d,d->v[i],list,list_size,tree); - } + for(i=0;i<3;i++) if((a->v[i] != a->anc) && + (a->b[i] != tree->e_root) && + (res == 1)) res = Scale_Subtree_Rates_Post(a,a->v[i],mult,n_nodes,tree); + return res; } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Fix_All(arbre *tree) +int Scale_Subtree_Rates_Post(t_node *a, t_node *d, phydbl mult, int *n_nodes, t_tree *tree) { - int i; - tree->mod->pinvar_old = tree->mod->pinvar; - tree->mod->alpha_old = tree->mod->alpha; - tree->mod->kappa_old = tree->mod->kappa; - tree->mod->lambda_old = tree->mod->lambda; + tree->rates->br_r[d->num] *= mult; + tree->rates->nd_r[d->num] *= mult; - for(i=tree->n_otu;i<2*tree->n_otu-2;i++) + *n_nodes = *n_nodes+1; + + if(tree->rates->br_r[d->num] < tree->rates->min_rate) return 0; + if(tree->rates->br_r[d->num] > tree->rates->max_rate) return 0; + if(tree->rates->nd_r[d->num] < tree->rates->min_rate) return 0; + if(tree->rates->nd_r[d->num] > tree->rates->max_rate) return 0; + + if(d->tax) return 1; + else { - tree->noeud[i]->b[0]->l_old = tree->noeud[i]->b[0]->l; - tree->noeud[i]->b[1]->l_old = tree->noeud[i]->b[1]->l; - tree->noeud[i]->b[2]->l_old = tree->noeud[i]->b[2]->l; + int i,res; + + res = 1; + for(i=0;i<3;++i) + { + if((d->v[i] != a) && + (d->b[i] != tree->e_root) && + (res == 1)) + { + res = Scale_Subtree_Rates_Post(d,d->v[i],mult,n_nodes,tree); + } + } + return res; } } -/*********************************************************/ - -void Record_Br_Len(arbre *tree) -{ - int i; - For(i,2*tree->n_otu-3) tree->t_edges[i]->l_old = tree->t_edges[i]->l; -} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Restore_Br_Len(arbre *tree) +void Get_Node_Ranks(t_tree *tree) { - int i; - For(i,2*tree->n_otu-3) tree->t_edges[i]->l = tree->t_edges[i]->l_old; + tree->n_root->rank = 1; + Get_Node_Ranks_Pre(tree->n_root,tree->n_root->v[2],tree); + Get_Node_Ranks_Pre(tree->n_root,tree->n_root->v[1],tree); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Get_Dist_Btw_Edges(node *a, node *d, arbre *tree) +void Get_Node_Ranks_Pre(t_node *a, t_node *d, t_tree *tree) { - int i; - edge *b_fcus; - - b_fcus = NULL; - For(i,3) if(a->v[i] == d) {b_fcus = a->b[i]; break;} + d->rank = a->rank+1; if(d->tax) return; else { - For(i,3) - if(d->v[i] != a) - { - d->b[i]->topo_dist_btw_edges = b_fcus->topo_dist_btw_edges + 1; - d->b[i]->dist_btw_edges = b_fcus->dist_btw_edges + d->b[i]->l / 2.; - Get_Dist_Btw_Edges(d,d->v[i],tree); - } + int i; + + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + Get_Node_Ranks_Pre(d,d->v[i],tree); + } + } } +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +void Log_Br_Len(t_tree *tree) +{ + int i; + for(i=0;i<2*tree->n_otu-3;++i) tree->a_edges[i]->l->v = log(tree->a_edges[i]->l->v); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Detect_Polytomies(edge *b, phydbl l_thresh, arbre *tree) +phydbl Diff_Lk_Norm_At_Given_Edge(t_edge *b, t_tree *tree) { - if((b->l < l_thresh) && (!b->left->tax) && (!b->rght->tax)) + int i,dim,err; + phydbl lk_exact,lk_norm,sum; + + Record_Br_Len(tree); + + dim = 2*tree->n_otu-3; + sum = 0.0; + + for(i=0;in_short_l;i++) { - b->l = 0.0; - b->has_zero_br_len = 1; + b->l->v = tree->short_l[i]; + + lk_exact = Lk(b,tree); + lk_norm = tree->norm_scale + Log_Dnorm(b->l->v,tree->rates->mean_l[b->num], + tree->rates->cov_l[b->num*dim+b->num],&err); + + if(err) + { + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + sum += pow(lk_exact - lk_norm,2); } - else b->has_zero_br_len = 0; + + Restore_Br_Len(tree); + Lk(b,tree); + + return(sum); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Get_List_Of_Nodes_In_Polytomy(node *a, node *d, node ***list, int *size_list) +void Adjust_Variances(t_tree *tree) { - if(d->tax) return; - else - { - int i; + int i; + phydbl new_diff,curr_diff; - For(i,3) - { - if(d->v[i] != a) - { - if(!d->b[i]->has_zero_br_len) - { - (*list)[*size_list] = d->v[i]; - (*size_list)++; - } - - if(d->b[i]->has_zero_br_len) - Get_List_Of_Nodes_In_Polytomy(d,d->v[i],list,size_list); - } - } + Make_Short_L(tree); + for(i=0;in_short_l;i++) + { + tree->short_l[i] = tree->mod->l_min + i*(0.1 - tree->mod->l_min)/tree->n_short_l; } + + For(i,2*tree->n_otu-3) + { + if(tree->a_edges[i]->l->v < 1.1*tree->mod->l_min) + { + tree->rates->mean_l[i] = -1.00; + tree->rates->cov_l[i*(2*tree->n_otu-3)+i] = 0.1; + tree->norm_scale = -100; + + + new_diff = curr_diff = 10.0; + do + { + curr_diff = new_diff; + + Generic_Brent_Lk(&(tree->norm_scale), + -1E+6, + 0.0, + 1.E-10, + 10000, + NO, + Wrap_Diff_Lk_Norm_At_Given_Edge,tree->a_edges[i],tree,NULL,NO); + + /* Generic_Brent_Lk(&(tree->rates->mean_l[0]), */ + /* -100., */ + /* 10*tree->mod->l_min, */ + /* 1.E-3, */ + /* 10000, */ + /* NO, */ + /* Wrap_Diff_Lk_Norm_At_Given_Edge,tree->a_edges[0],tree,NULL); */ + + Generic_Brent_Lk(&(tree->rates->cov_l[i*(2*tree->n_otu-3)+i]), + 0.0, + 10.0, + 1.E-10, + 10000, + NO, + Wrap_Diff_Lk_Norm_At_Given_Edge,tree->a_edges[i],tree,NULL,NO); + + new_diff = Diff_Lk_Norm_At_Given_Edge(tree->a_edges[i],tree); + }while(FABS(new_diff-curr_diff) > 1.E-3); + } + } } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ -void Check_Path(node *a, node *d, node *target, arbre *tree) +phydbl Effective_Sample_Size(phydbl first_val, phydbl last_val, phydbl sum, phydbl sumsq, phydbl sumcurnext, int n) { - printf("path---------\n"); - if(d==target) return; - else Check_Path(d,d->v[tree->t_dir[d->num][target->num]],target,tree); -} + phydbl numerator,denom; + phydbl mean; + phydbl r; + mean = sum / n; + denom = sumsq - n * POW(mean,2); + numerator = sumcurnext - (n+1.)*POW(mean,2) + (first_val+last_val)*mean; -/*********************************************************/ + r = numerator/denom; -void Connect_Two_Nodes(node *a, node *d) -{ - a->v[0] = d; - d->v[0] = a; + return (phydbl)n * (1.-r)/(1.+r); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Get_List_Of_Adjacent_Targets(node *a, node *d, node ***node_list, edge ***edge_list, int *list_size) +phydbl Rescale_Br_Len_Multiplier_Tree(t_tree *tree) { int i; - For(i,3) - if(a->v[i] == d) - { - (*node_list)[*list_size] = a; - (*edge_list)[*list_size] = a->b[i]; - (*list_size)++; - } - if(d->tax) return; - else - For(i,3) - if(d->v[i] != a) Get_List_Of_Adjacent_Targets(d,d->v[i],node_list,edge_list,list_size); + if(tree->is_mixt_tree) + { + MIXT_Rescale_Br_Len_Multiplier_Tree(tree); + return(-1.); + } + + for(i=0;i<2*tree->n_otu-1;++i) tree->a_edges[i]->l->v *= tree->mod->br_len_mult->v; + return(-1.); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Sort_List_Of_Adjacent_Targets(edge ***list, int list_size) +phydbl Unscale_Br_Len_Multiplier_Tree(t_tree *tree) { - edge *buff_edge; - int i,j; - - buff_edge = NULL; + int i; - For(i,list_size-1) + if(tree->is_mixt_tree) { - for(j=i+1;jtopo_dist_btw_edges < (*list)[i]->topo_dist_btw_edges) - { - buff_edge = (*list)[j]; - (*list)[j] = (*list)[i]; - (*list)[i] = buff_edge; - } + MIXT_Unscale_Br_Len_Multiplier_Tree(tree); + return(-1.); } + + For(i,2*tree->n_otu-1) tree->a_edges[i]->l->v /= tree->mod->br_len_mult->v; + return(-1.); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Make_Best_Spr(arbre *tree) + +phydbl Reflect(phydbl x, phydbl l, phydbl u) { - tree->best_spr = Make_One_Spr(tree); - Init_One_Spr(tree->best_spr); -} + int rounds; + phydbl tmp; + int k; -/*********************************************************/ + if(u < l) + { + tmp = u; + u = l; + l = tmp; + } -void Make_Spr_List(arbre *tree) -{ - int i; + if(x < l) x = x + 2.*(l - x); - tree->size_spr_list = 2*tree->n_otu-3; - tree->spr_list = (spr **)mCalloc(2*tree->n_otu-2,sizeof(spr *)); + if(((x-u) > (u-l)) && (x > u)) + { + k = (x - (2.*u-l))/(2.*(u-l)); + x = x - 2.*k*(u-l); + } - For(i,2*tree->n_otu-2) + rounds = 0; + do { - tree->spr_list[i] = Make_One_Spr(tree); - Init_One_Spr(tree->spr_list[i]); + rounds++; + /* printf("\n. l=%f u=%f x=%f",l,u,x); */ + if(x > u || x < l) + { + if(x > u) x = x - 2.*(x - u); + else x = x + 2.*(l - x); } - tree->perform_spr_right_away = 0; -} + else break; + /* printf(" x'=%f",x); */ + } + while(rounds < 100); -/*********************************************************/ + if(rounds == 100 && (x > u || x < l)) + { + PhyML_Printf("\n. u=%f l=%f x=%f",u,l,x); + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } -void Init_One_Spr(spr *a_spr) -{ - a_spr->lnL = UNLIKELY; - a_spr->pars = 1E+5; - a_spr->depth_path = 0; - a_spr->dist = 0; - a_spr->init_target_l = -1.; - a_spr->l0 = -1.; - a_spr->l1 = -1.; - a_spr->l2 = -1.; - a_spr->n_link = NULL; - a_spr->n_opp_to_link = NULL; - a_spr->b_opp_to_link = NULL; - a_spr->b_target = NULL; - a_spr->b_init_target = NULL; + return x; } -/*********************************************************/ - -spr *Make_One_Spr(arbre *tree) -{ - spr *a_spr; - a_spr = (spr *)mCalloc(1,sizeof(spr)); - a_spr->path = (node **)mCalloc(tree->n_otu,sizeof(node *)); - return a_spr; -} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -/*********************************************************/ -node *Common_Nodes_Btw_Two_Edges(edge *a, edge *b) +int Are_Equal(phydbl a, phydbl b, phydbl eps) { - if(a->left == b->left) return b->left; - else if(a->left == b->rght) return b->rght; - else if(a->rght == b->left) return b->left; - else if(a->rght == b->rght) return b->rght; - - printf("\n. First edge = %d (%d %d); Second edge = %d (%d %d)\n", - a->num,a->left->num,a->rght->num, - b->num,b->left->num,b->rght->num); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - - return NULL; + if(FABS(a-b) < eps) return TRUE; /* a==b */ + else return FALSE; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int KH_Test(phydbl *site_lk_M1, phydbl *site_lk_M2, arbre *tree) +/* Returns 1 if small_tree is displayed by big_tree, 0 otherwise + Does not account for the root positions, if any. +*/ +int Check_Topo_Constraints(t_tree *big_tree, t_tree *small_tree) { - phydbl *delta,mean,sd,obs_stat,threshold; - int i; + if(!small_tree) return 1; - - delta = (phydbl *)mCalloc(tree->data->init_len,sizeof(phydbl)); + if(small_tree->n_otu < 4) return 1; - threshold = .0; - mean = .0; - obs_stat = .0; - For(i,tree->n_pattern) + if(small_tree->n_otu > big_tree->n_otu) { - delta[i] = site_lk_M1[i] - site_lk_M2[i]; - mean += ((int)tree->data->wght[i])*delta[i]; + PhyML_Printf("\n"); + PhyML_Printf("\n. The tree that defines the topological constraints can not"); + PhyML_Printf("\n. display more taxa than %d",big_tree->n_otu); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); } - obs_stat = mean; - - mean /= tree->data->init_len; - - For(i,tree->data->init_len) delta[i] -= mean; + t_tree *big_tree_cpy; + int diffs,i; - sd = .0; - For(i,tree->data->init_len) sd += pow(delta[i],2); - sd /= (phydbl)(tree->data->init_len-1.); + big_tree_cpy = Make_Tree_From_Scratch(big_tree->n_otu,NULL); + Copy_Tree(big_tree,big_tree_cpy); -/* threshold = tree->dnorm_thresh*sqrt(sd*tree->data->init_len); */ + Prune_Tree(big_tree_cpy,small_tree); + /* For(i,2*small_tree->n_otu-3) printf("\nz %d . %d . %d", */ + /* big_tree->a_edges[i]->does_exist, */ + /* big_tree_cpy->a_edges[i]->does_exist, */ + /* small_tree->a_edges[i]->does_exist); */ -/* printf("\nObs stat = %f Threshold = %f\n",obs_stat,threshold); */ - Free(delta); + Free_Bip(small_tree); + Alloc_Bip(small_tree); + Get_Bip(small_tree->a_nodes[0],small_tree->a_nodes[0]->v[0],small_tree); - if(obs_stat > threshold) return 1; - else return 0; -} + Free_Bip(big_tree_cpy); + Alloc_Bip(big_tree_cpy); + Match_Tip_Numbers(small_tree,big_tree_cpy); + Get_Bip(big_tree_cpy->a_nodes[0],big_tree_cpy->a_nodes[0]->v[0],big_tree_cpy); -/*********************************************************/ + for(i=0;i<2*big_tree_cpy->n_otu-3;++i) big_tree_cpy->a_edges[i]->bip_score = 0; + for(i=0;i<2*small_tree->n_otu-3;++i) small_tree->a_edges[i]->bip_score = 0; -void Randomize_Spr_List(arbre *tree) -{ - int i,j; - spr *buff; + diffs = Compare_Bip(small_tree,big_tree_cpy,NO); - For(i,tree->size_spr_list) - { - j = (int)floor(rand()/(RAND_MAX+1.)*tree->size_spr_list); - buff = tree->spr_list[i]; - tree->spr_list[i] = tree->spr_list[j]; - tree->spr_list[j] = buff; - } -} + /* printf("\n"); */ + /* printf("\n. %s",Write_Tree(big_tree_cpy)); */ + /* printf("\n. %s",Write_Tree(small_tree)); */ + /* printf("\n. diffs=%d",diffs); */ -/*********************************************************/ -void Select_Compatible_Spr_Moves(arbre *tree) -{ - int i,j; + Free_Tree(big_tree_cpy); + t_tree *big_tree_cpy_bis; + big_tree_cpy_bis = Make_Tree_From_Scratch(big_tree->n_otu,NULL); + Copy_Tree(big_tree,big_tree_cpy_bis); + Free_Tree(big_tree_cpy_bis); - For(i,tree->size_spr_list-1) - { - for(j=i+1;jsize_spr_list;j++) - { - if((tree->spr_list[j]->b_target) && (tree->spr_list[i]->b_target)) - { - if(tree->spr_list[i]->n_link == tree->spr_list[j]->n_link) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->n_link == tree->spr_list[j]->n_opp_to_link) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->n_link == tree->spr_list[j]->b_target->left) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->n_link == tree->spr_list[j]->b_target->rght) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->n_opp_to_link == tree->spr_list[j]->n_link) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->n_opp_to_link == tree->spr_list[j]->n_opp_to_link) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->n_opp_to_link == tree->spr_list[j]->b_target->left) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->n_opp_to_link == tree->spr_list[j]->b_target->rght) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->b_target->left == tree->spr_list[j]->n_link) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->b_target->left == tree->spr_list[j]->n_opp_to_link) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->b_target->left == tree->spr_list[j]->b_target->left) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->b_target->left == tree->spr_list[j]->b_target->rght) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->b_target->rght == tree->spr_list[j]->n_link) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->b_target->rght == tree->spr_list[j]->n_opp_to_link) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->b_target->rght == tree->spr_list[j]->b_target->left) - { - tree->spr_list[j]->b_target = NULL; - } - else if(tree->spr_list[i]->b_target->rght == tree->spr_list[j]->b_target->rght) - { - tree->spr_list[j]->b_target = NULL; - } - } - } - } + if(diffs == 0) return 1; /* Constraint is satisfied */ + else return 0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Spr(phydbl init_lnL, arbre *tree) +void Prune_Tree(t_tree *big_tree, t_tree *small_tree) { - int spr_moves, best_move, br; + int i,j; + unsigned int curr_ext_node, curr_int_node; + int curr_br, n_pruned_nodes;; + t_node **pruned_nodes; + t_edge **residual_edges; - tree->both_sides = 1; - spr_moves = 0; - Reset_Spr_List(tree); + pruned_nodes = (t_node **)mCalloc(big_tree->n_otu,sizeof(t_node *)); + residual_edges = (t_edge **)mCalloc(big_tree->n_otu,sizeof(t_edge *)); - For(br,2*tree->n_otu-3) + n_pruned_nodes = 0; + for(i=0;in_otu;i++) { - /* Subtree rooted by the node on the left */ - tree->n_moves = 0; - - if(!tree->t_edges[br]->left->tax) Test_All_Spr_Targets(tree->t_edges[br],tree->t_edges[br]->left,tree); + for(j=0;jn_otu;j++) + if(!strcmp(small_tree->a_nodes[j]->name,big_tree->a_nodes[i]->name)) + break; + + if(j == small_tree->n_otu) + { + Prune_Subtree(big_tree->a_nodes[i]->v[0], + big_tree->a_nodes[i], + NULL,&(residual_edges[n_pruned_nodes]), + big_tree); + + pruned_nodes[n_pruned_nodes] = big_tree->a_nodes[i]; + n_pruned_nodes++; + } + } + + if(!n_pruned_nodes) + { + Free(pruned_nodes); + Free(residual_edges); + return; + } + + Free(big_tree->t_dir); + + big_tree->n_otu -= n_pruned_nodes; + - if(tree->perform_spr_right_away) - { - if(tree->n_moves) - { - best_move = Evaluate_List_Of_Regraft_Pos_Triple(tree->spr_list, - (int)ceil(tree->mod->s_opt->p_moves_to_examine*tree->n_moves), - tree); - - if(tree->spr_list[best_move]->lnL > init_lnL) Try_One_Spr_Move_Triple(tree->spr_list[best_move],tree); - else - { - tree->both_sides = 1; - Lk(tree); - Pars(tree); - } - } - Reset_Spr_List(tree); - } + curr_ext_node = 0; + curr_int_node = big_tree->n_otu; + curr_br = 0; + for(i=0;in_otu+n_pruned_nodes;++i) + { + for(j=0;jname,big_tree->a_nodes[i]->name)) + break; + + if(j == n_pruned_nodes) /* That t_node still belongs to the tree */ + { + Reassign_Node_Nums(big_tree->a_nodes[i],big_tree->a_nodes[i]->v[0], + &curr_ext_node,&curr_int_node,big_tree); + break; + } + } + - /* Subtree rooted by the node on the right */ - tree->n_moves = 0; + Reassign_Edge_Nums(big_tree->a_nodes[0],big_tree->a_nodes[0]->v[0],&curr_br,big_tree); + + big_tree->t_dir = (short int *)mCalloc((2*big_tree->n_otu-2)*(2*big_tree->n_otu-2),sizeof(short int)); + + for(i=0;ib[0]); + Free_Node(pruned_nodes[i]->v[0]); + Free_Node(pruned_nodes[i]); + } + + Free(pruned_nodes); + Free(residual_edges); - if(!tree->t_edges[br]->rght->tax) Test_All_Spr_Targets(tree->t_edges[br],tree->t_edges[br]->rght,tree); + big_tree->a_edges[2*big_tree->n_otu-3] = big_tree->a_edges[2*(big_tree->n_otu+n_pruned_nodes)-3]; + big_tree->a_edges[2*big_tree->n_otu-2] = big_tree->a_edges[2*(big_tree->n_otu+n_pruned_nodes)-2]; + big_tree->a_nodes[2*big_tree->n_otu-2] = big_tree->a_nodes[2*(big_tree->n_otu+n_pruned_nodes)-2]; - if(tree->perform_spr_right_away) - { - if(tree->n_moves) - { - best_move = Evaluate_List_Of_Regraft_Pos_Triple(tree->spr_list, - (int)ceil(tree->mod->s_opt->p_moves_to_examine*tree->n_moves), - tree); - - - if(tree->spr_list[best_move]->lnL > init_lnL) Try_One_Spr_Move_Triple(tree->spr_list[best_move],tree); - else - { - tree->both_sides = 1; - Lk(tree); - Pars(tree); - } - } - Reset_Spr_List(tree); - } - } - return 1; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Test_All_Spr_Targets(edge *b_pulled, node *n_link, arbre *tree) +/* For every node in small_tree, find which node in big_tree + it corresponds to and initialize the variable match_node + accordingly (vice versa for big_tree) +*/ +void Match_Nodes_In_Small_Tree(t_tree *small_tree, t_tree *big_tree) { - node *n_opp_to_link,*n_v1,*n_v2,*n_up; - edge *b_target,*b_residual; - int i,dir1,dir2; - phydbl init_len_v1, init_len_v2, init_len_pulled; + int i,j,k,l,m,n,identical; + int *score; - n_up = NULL; - b_target = b_residual = NULL; - n_opp_to_link = (n_link == b_pulled->rght)?(b_pulled->left):(b_pulled->rght); - - init_len_pulled = b_pulled->l; - dir1 = dir2 = -1; - For(i,3) - if(n_link->v[i] != n_opp_to_link) - { - if(dir1<0) dir1 = i; - else dir2 = i; - } - - if(n_link->v[dir1]->num < n_link->v[dir2]->num) + if(small_tree->n_otu > big_tree->n_otu) + { + PhyML_Printf("\n. small_tree->n_otu=%d big_tree->n_otu=%d",small_tree->n_otu,big_tree->n_otu); + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + Free_Bip(big_tree); + Alloc_Bip(big_tree); + Get_Bip(big_tree->a_nodes[0],big_tree->a_nodes[0]->v[0],big_tree); + + Free_Bip(small_tree); + Alloc_Bip(small_tree); + Get_Bip(small_tree->a_nodes[0],small_tree->a_nodes[0]->v[0],small_tree); + + if(!Check_Topo_Constraints(big_tree,small_tree)) + { + PhyML_Printf("\n. small_tree and big_tree cannot have distinct topologies."); + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + For(i,2*small_tree->n_otu-1) small_tree->a_nodes[i]->match_node = NULL; + For(i,2*big_tree->n_otu-1) big_tree->a_nodes[i]->match_node = NULL; + + score = (int *)mCalloc(3,sizeof(int)); + + for(i=0;in_otu;i++) { - n_v1 = n_link->v[dir1]; - n_v2 = n_link->v[dir2]; - init_len_v1 = n_link->b[dir1]->l; - init_len_v2 = n_link->b[dir2]->l; + for(j=0;jn_otu;j++) + { + if(!strcmp(small_tree->a_nodes[i]->name,big_tree->a_nodes[j]->name)) + { + small_tree->a_nodes[i]->match_node = big_tree->a_nodes[j]; + big_tree->a_nodes[j]->match_node = small_tree->a_nodes[i]; + break; + } + } } - else + + For(i,2*small_tree->n_otu-2) { - n_v1 = n_link->v[dir2]; - n_v2 = n_link->v[dir1]; - init_len_v1 = n_link->b[dir2]->l; - init_len_v2 = n_link->b[dir1]->l; + if(small_tree->a_nodes[i]->tax == NO) + { + For(j,2*big_tree->n_otu-2) + { + if(big_tree->a_nodes[j]->tax == NO) + { + for(k=0;k<3;k++) score[k] = 0; + + for(k=0;k<3;k++) + { + for(l=0;l<3;l++) + { + identical = 0; + For(m,small_tree->a_nodes[i]->bip_size[k]) + { + For(n,big_tree->a_nodes[j]->bip_size[l]) + { + if(!strcmp(small_tree->a_nodes[i]->bip_node[k][m]->name,big_tree->a_nodes[j]->bip_node[l][n]->name)) + { + identical++; + break; + } + } + } + if(identical == small_tree->a_nodes[i]->bip_size[k]) + { + score[k]++; + } + } + } + + /* printf("\n. [%d] [%d] %d %d %d -- %d %d %d",i,j, */ + /* score[0],score[1],score[2], */ + /* small_tree->a_nodes[i]->bip_size[0], */ + /* small_tree->a_nodes[i]->bip_size[1], */ + /* small_tree->a_nodes[i]->bip_size[2]); */ + + if( + score[0] == 1 && + score[1] == 1 && + score[2] == 1 + ) + { + small_tree->a_nodes[i]->match_node = big_tree->a_nodes[j]; + big_tree->a_nodes[j]->match_node = small_tree->a_nodes[i]; + break; + } + } + } + } } + + Free(score); +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - Prune_Subtree(n_link,n_opp_to_link,&b_target,&b_residual,tree); - // -/* Update_PMat_At_Given_Edge(b_target,tree); */ - // +void Find_Surviving_Edges_In_Small_Tree(t_tree *small_tree, t_tree *big_tree) +{ + int i; - tree->depth_curr_path = 1; tree->curr_path[0] = b_target->left; - Test_One_Spr_Target_Recur(b_target->rght, - b_target->left, - b_pulled,n_link,b_residual,tree); + Match_Nodes_In_Small_Tree(small_tree,big_tree); - tree->depth_curr_path = 1; tree->curr_path[0] = b_target->rght; - Test_One_Spr_Target_Recur(b_target->left, - b_target->rght, - b_pulled,n_link,b_residual,tree); + For(i,2*small_tree->n_otu-1) small_tree->rates->has_survived[i] = NO; - Graft_Subtree(b_target,n_link,b_residual,tree); + Find_Surviving_Edges_In_Small_Tree_Post(big_tree->n_root,big_tree->n_root->v[2],small_tree,big_tree); + Find_Surviving_Edges_In_Small_Tree_Post(big_tree->n_root,big_tree->n_root->v[1],small_tree,big_tree); +} - if((n_link->v[dir1] != n_v1) || (n_link->v[dir2] != n_v2)) - printf("\n. Warning : -- SWITCH NEEDED -- ! \n"); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - n_link->b[dir1]->l = init_len_v1; Update_PMat_At_Given_Edge(n_link->b[dir1],tree); - n_link->b[dir2]->l = init_len_v2; Update_PMat_At_Given_Edge(n_link->b[dir2],tree); - b_pulled->l = init_len_pulled; - Update_PMat_At_Given_Edge(b_pulled,tree); - // -/* Update_P_Lk(tree,b_pulled, n_link); */ -/* Update_P_Lk(tree,b_target, n_link); */ -/* Update_P_Lk(tree,b_residual,n_link); */ - // +void Find_Surviving_Edges_In_Small_Tree_Post(t_node *a, t_node *d, t_tree *small_tree, t_tree *big_tree) +{ + if(d->match_node && !a->match_node) + { + small_tree->rates->has_survived[d->match_node->num] = YES; + } - Update_P_Pars(tree,b_pulled, n_link); - Update_P_Pars(tree,b_target, n_link); - Update_P_Pars(tree,b_residual,n_link); + if(d->tax == YES) return; + else + { + int i; - if(!tree->perform_spr_right_away) - /* if perform_spr_right_away != 0 --> a spr move - * will be performed anyway. Thus it is not necessary - * to update the partial likelihoods below - */ + for(i=0;i<3;i++) { - For(i,3) - if(n_link->v[i] != n_opp_to_link) - { -/* Pre_Order_Lk(n_link,n_link->v[i],tree); */ - Pre_Order_Pars(n_link,n_link->v[i],tree); - } + if(d->v[i] != a && d->b[i] != big_tree->e_root) + { + Find_Surviving_Edges_In_Small_Tree_Post(d,d->v[i],small_tree,big_tree); + } + } } - return 0; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Test_One_Spr_Target_Recur(node *a, node *d, edge *pulled, node *link, edge *residual, arbre *tree) + +void Set_Taxa_Id_Ranking(t_tree *tree) { - int i; + int i,j; - if(d->tax) return; - else + for(i=0;in_otu;i++) tree->a_nodes[i]->id_rank = 0; + + for(i=0;in_otu;i++) { - For(i,3) - if(d->v[i] != a) - { - // -/* Update_P_Lk(tree,d->b[i],d); */ - // - Update_P_Pars(tree,d->b[i],d); - tree->curr_path[tree->depth_curr_path] = d->v[i]; - tree->depth_curr_path++; - Test_One_Spr_Target(d->b[i],pulled,link,residual,tree); - Test_One_Spr_Target_Recur(d,d->v[i],pulled,link,residual,tree); - tree->depth_curr_path--; - } + for(j=i+1;jn_otu;j++) + { + if(strcmp(tree->a_nodes[i]->name,tree->a_nodes[j]->name) > 0) + tree->a_nodes[i]->id_rank++; + else + tree->a_nodes[j]->id_rank++; } + } + /* for(i=0;in_otu;i++) PhyML_Printf("\n. %20s %4d",tree->a_nodes[i]->name,tree->a_nodes[i]->id_rank); */ } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + -phydbl Test_One_Spr_Target(edge *b_target, edge *b_arrow, node *n_link, edge *b_residual, arbre *tree) +void Get_Edge_Binary_Coding_Number(t_tree *tree) { - phydbl init_target_len, init_arrow_len, init_residual_len; - int i,dir_v0,dir_v1,dir_v2; - phydbl l0,l1,l2; - node *v1, *v2; - phydbl init_lnL, move_lnL; - int init_pars,move_pars; + int i,j; + int list_size; + t_node **list; + t_edge *b; + int max_left,max_rght; + if(tree->n_otu > 1000) + { + PhyML_Printf("\n. Can't work out edge binary code if the number of taxa >1000."); + assert(FALSE); + } - tree->n_moves++; + Free_Bip(tree); + Alloc_Bip(tree); + Get_Bip(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); - move_lnL = UNLIKELY; - init_lnL = tree->c_lnL; - init_pars = tree->c_pars; + Set_Taxa_Id_Ranking(tree); - Graft_Subtree(b_target,n_link,b_residual,tree); + b = NULL; + for(i=0;i<2*tree->n_otu-3;++i) + { + b = tree->a_edges[i]; - init_target_len = b_target->l; - init_arrow_len = b_arrow->l; - init_residual_len = b_residual->l; + max_left = 0; + for(j=0;jleft->bip_size[b->l_r];++j) + if(b->left->bip_node[b->l_r][j]->id_rank > max_left) + max_left = b->left->bip_node[b->l_r][j]->id_rank; - // - /* Triple_Dist(n_link,tree); */ - /* Update_PMat_At_Given_Edge(b_target,tree); */ - /* Update_PMat_At_Given_Edge(b_arrow,tree); */ - /* Update_P_Lk(tree,b_residual,n_link); */ - /* move_lnL = Lk_At_Given_Edge(b_residual,tree); */ - // + max_rght = 0; + for(j=0;jrght->bip_size[b->r_l];++j) + if(b->rght->bip_node[b->r_l][j]->id_rank > max_rght) + max_rght = b->rght->bip_node[b->r_l][j]->id_rank; - Update_P_Pars(tree,b_residual,n_link); - move_pars = Pars_At_Given_Edge(b_residual,tree); - v1 = (b_residual->left == n_link)?(b_residual->rght):(b_residual->left); - v2 = (b_target->left == n_link)?(b_target->rght):(b_target->left); - dir_v1 = dir_v2 = dir_v0 = -1; - For(i,3) - { - if(n_link->v[i] == v1) dir_v1 = i; - else if(n_link->v[i] == v2) dir_v2 = i; - else dir_v0 = i; - } - l0 = n_link->b[dir_v0]->l; - if(n_link->v[dir_v1]->num > n_link->v[dir_v2]->num) - { - l1 = n_link->b[dir_v2]->l; - l2 = n_link->b[dir_v1]->l; - } - else - { - l1 = n_link->b[dir_v1]->l; - l2 = n_link->b[dir_v2]->l; + if(max_left < max_rght) + { + list = b->left->bip_node[b->l_r]; + list_size = b->left->bip_size[b->l_r]; + } + else + { + list = b->rght->bip_node[b->r_l]; + list_size = b->rght->bip_size[b->r_l]; + } + + b->bin_cod_num = 0.; + for(j=0;jbin_cod_num += POW(2,list[j]->id_rank); + /* printf("\n. %f",b->bin_cod_num); */ } +} - For(i,tree->depth_curr_path) tree->spr_list[tree->size_spr_list]->path[i] = tree->curr_path[i]; - tree->spr_list[tree->size_spr_list]->depth_path = tree->depth_curr_path; - tree->spr_list[tree->size_spr_list]->pars = tree->c_pars; - tree->spr_list[tree->size_spr_list]->lnL = tree->c_lnL; - tree->spr_list[tree->size_spr_list]->b_target = b_target; - tree->spr_list[tree->size_spr_list]->n_link = n_link; - tree->spr_list[tree->size_spr_list]->n_opp_to_link = (n_link==b_arrow->left)?(b_arrow->rght):(b_arrow->left); - tree->spr_list[tree->size_spr_list]->b_opp_to_link = b_arrow; - tree->spr_list[tree->size_spr_list]->l0 = l0; - tree->spr_list[tree->size_spr_list]->l1 = l1; - tree->spr_list[tree->size_spr_list]->l2 = l2; - tree->spr_list[tree->size_spr_list]->dist = b_target->topo_dist_btw_edges; - - Include_One_Spr_To_List_Of_Spr(tree->spr_list[tree->size_spr_list],tree); - - b_target->l = init_target_len; - b_arrow->l = init_arrow_len; - b_residual->l = init_residual_len; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - Prune_Subtree(n_link, - (n_link==b_arrow->left)?(b_arrow->rght):(b_arrow->left), - &b_target, - &b_residual, - tree); - // -/* Update_PMat_At_Given_Edge(b_target,tree); */ - // +int Get_Mutmap_Val(int edge, int site, int mut, t_tree *tree) +{ + int dim1,dim2; - tree->c_lnL = init_lnL; - tree->c_pars = init_pars; + dim1 = (tree->n_pattern)*(2*tree->n_otu-3); + dim2 = (tree->n_pattern); - return .0; + return tree->mutmap[mut*dim1 + edge*dim2 + site]; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Speed_Spr_Loop(arbre *tree) +void Get_Mutmap_Coord(int idx, int *edge, int *site, int *mut, t_tree *tree) { - phydbl lk_old; + int dim1,dim2; - do - { - lk_old = tree->c_lnL; - Speed_Spr(tree); - Simu(tree,1000); - Check_NNI_Five_Branches(tree); - } - while(tree->c_lnL > lk_old + tree->mod->s_opt->min_diff_lk_global); + dim1 = (tree->n_pattern)*(2*tree->n_otu-3); + dim2 = (tree->n_pattern); + (*mut) = (int)idx/dim1; + (*edge) = (int)(idx - (*mut)*dim1)/dim2; + (*site) = (int)(idx - (*mut)*dim1 - (*edge)*dim2); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Speed_Spr(arbre *tree) +void Copy_Edge_Lengths(t_tree *to, t_tree *from) { - int step,old_pars; - phydbl old_lnL; + int i; + For(i,2*from->n_otu-1) to->a_edges[i]->l->v = from->a_edges[i]->l->v; +} - if(tree->lock_topo) - { - printf("\n. The tree topology is locked."); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - /* Optimise parameters of the Markov model */ - Optimiz_All_Free_Param(tree,0); +char *To_Lower_String(char *in) +{ + char *out; + int i; + int len; - tree->both_sides = 1; - Pars(tree); - Lk(tree); - Record_Br_Len(tree); + len = (int)strlen(in); - tree->best_lnL = tree->c_lnL; - old_lnL = tree->c_lnL; - old_pars = tree->c_pars; - step = 0; + out = (char *)mCalloc(len+1,sizeof(char)); - do - { - ++step; + for(i=0;imod->s_opt->print) printf("\n\n. Starting a SPR cycle... \n"); + out[len] = '\0'; + return(out); +} - Init_One_Spr(tree->best_spr); - old_lnL = tree->c_lnL; - old_pars = tree->c_pars; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - tree->n_improvements = 0; - tree->perform_spr_right_away = 1; - Spr(UNLIKELY,tree); +char *To_Upper_String(char *in) +{ + char *out; + int i; + int len; - /* Optimise parameters of the Markov model */ - Optimiz_All_Free_Param(tree,tree->mod->s_opt->print); + len = (int)strlen(in); - /* Optimise branch lengths */ - Optimize_Br_Len_Serie(tree->noeud[0], - tree->noeud[0]->v[0], - tree->noeud[0]->b[0], - tree, - tree->data); + out = (char *)mCalloc(len+1,sizeof(char)); - /* Update partial likelihoods & parsimony */ - tree->both_sides = 1; - Lk(tree); - Pars(tree); + for(i=0;imod->s_opt->print) Print_Lk(tree,"[Branch lengths ]"); + out[len] = '\0'; + return(out); +} - /* Record the current best log-likleihood */ - tree->best_lnL = tree->c_lnL; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if(tree->c_lnL < old_lnL) - { - printf("\n. old_lnL = %f c_lnL = %f",old_lnL,tree->c_lnL); - printf("\n. Err in file %s at line %d",__FILE__,__LINE__); - Warn_And_Exit(""); - } +void Connect_CSeqs_To_Nodes(calign *cdata, option *io, t_tree *tree) +{ + int i,j,n_otu_tree,n_otu_cdata; + + n_otu_tree = tree->n_otu; + n_otu_cdata = cdata->n_otu; + + if((n_otu_tree != n_otu_cdata) && (io->fp_in_constraint_tree == NULL)) + { + PhyML_Printf("\n. Number of taxa in the tree: %d, number of sequences: %d.",n_otu_tree,n_otu_cdata); + Warn_And_Exit("\n. The number of tips in the tree is not the same as the number of sequences\n"); + } - /* Record the current best branch lengths */ - Record_Br_Len(tree); + for(i=0;ia_nodes[i]->name,cdata->c_seq[j]->name)) break; + } + + if(j==n_otu_cdata) + { + PhyML_Printf("\n. Taxon '%s' was not found in sequence file '%s'.\n", + tree->a_nodes[i]->name, + io->in_align_file); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + tree->a_nodes[i]->c_seq = cdata->c_seq[j]; + } +} - /* Exit if no improvements after complete optimization */ - if((!tree->n_improvements) || - (fabs(old_lnL-tree->c_lnL) < tree->mod->s_opt->min_diff_lk_global)) break; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - }while(1); +void Set_Both_Sides(int yesno, t_tree *tree) +{ + tree->both_sides = yesno; + if(tree->is_mixt_tree == YES) MIXT_Set_Both_Sides(yesno,tree); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Best_Spr(arbre *tree) +void Set_Use_Eigen_Lr(int yesno, t_tree *tree) { - int best_move,n_moves; - phydbl best_move_lnL,init_lnL; - int i; + tree->use_eigen_lr = yesno; + if(tree->is_mixt_tree == YES) MIXT_Set_Use_Eigen_Lr(yesno,tree); +} - if(tree->mod->s_opt->print) printf("\n\n. Starting a SPR cycle... \n"); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - /* Optimise parameters of the Markov model */ - Optimiz_All_Free_Param(tree,0); +void Set_Update_Eigen_Lr(int yesno, t_tree *tree) +{ + tree->update_eigen_lr = yesno; + if(tree->is_mixt_tree == YES) MIXT_Set_Update_Eigen_Lr(yesno,tree); +} - tree->both_sides = 1; - Pars(tree); - Lk(tree); - Record_Br_Len(tree); - - init_lnL = tree->c_lnL; - tree->best_lnL = tree->c_lnL; - best_move = -1; - best_move_lnL = UNLIKELY; - tree->perform_spr_right_away = 0; - - Spr(UNLIKELY,tree); - tree->both_sides = 1; - Pars(tree); - Lk(tree); - - n_moves = MAX(tree->size_spr_list, - (int)ceil(2*tree->mod->s_opt->p_moves_to_examine*tree->size_spr_list)); - For(i,n_moves) - { - Evaluate_One_Regraft_Pos_Triple(tree->spr_list[i],tree); - tree->both_sides = 1; - Lk(tree); - if(tree->spr_list[i]->lnL > best_move_lnL) - { - best_move_lnL = tree->spr_list[i]->lnL; - best_move = i; - } - } +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - if(best_move > -1) Try_One_Spr_Move_Triple(tree->spr_list[best_move],tree); - - /* Optimise parameters of the Markov model */ - Optimiz_All_Free_Param(tree,tree->mod->s_opt->print); - - /* Optimise branch lengths */ - Optimize_Br_Len_Serie(tree->noeud[0], - tree->noeud[0]->v[0], - tree->noeud[0]->b[0], - tree, - tree->data); - - /* Update partial likelihoods & parsimony */ - tree->both_sides = 1; - Lk(tree); - Pars(tree); - - /* Print log-likelihood and parsimony scores */ - if(tree->mod->s_opt->print) Print_Lk(tree,"[Topology ]"); - - /* Record the current best log-likleihood */ - tree->best_lnL = tree->c_lnL; - - if(tree->c_lnL < init_lnL) - { - printf("\n. init_lnL = %f c_lnL = %f\n",init_lnL,tree->c_lnL); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - - /* Record the current best branch lengths */ - Record_Br_Len(tree); +void Set_Update_Eigen(int yesno, t_mod *mod) +{ + MIXT_Set_Update_Eigen(yesno,mod); } -/*********************************************************/ - -int Evaluate_List_Of_Regraft_Pos_Triple(spr **spr_list, int list_size, arbre *tree) +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +// Returns the matrix of pairwise distances between tips +phydbl *Dist_Btw_Tips(t_tree *tree) { - spr *move; - edge *init_target, *b_residual; - int i,j,best_move; - int dir_v0, dir_v1, dir_v2; - phydbl recorded_l; - phydbl move_lnL, best_lnL; + int i,j; + phydbl *dist; - move_lnL = best_lnL = UNLIKELY; - init_target = b_residual = NULL; - best_move = -1; + dist = (phydbl *)mCalloc(tree->n_otu*tree->n_otu,sizeof(phydbl)); -#ifdef DEBUG - if(!list_size) + for(i=0;in_otu-1;i++) { - printf("\n\n. List size is 0 !"); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + for(j=i+1;jn_otu;j++) + { + Path_Length(tree->a_nodes[i],tree->a_nodes[j],dist+i*tree->n_otu+j,tree); + dist[j*tree->n_otu+i] = dist[i*tree->n_otu+j]; + } } -#endif + return(dist); - For(i,2*tree->n_otu-3) +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Best_Root_Position_IL_Model(t_tree *tree) +{ + + if(tree->n_root) { - tree->t_edges[i]->is_p_lk_r_u2d = 0; - tree->t_edges[i]->is_p_lk_l_u2d = 0; + PhyML_Printf("\n. The tree already has a root node"); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); } - - recorded_l = -1.0; - For(i,list_size) + else { - move = spr_list[i]; - - if(move->b_target) - { - /* Record edge lengths */ - Record_Br_Len(tree); + int i; + t_edge *best_edge; + phydbl best_lnL; - /* Prune subtree */ - Prune_Subtree(move->n_link,move->n_opp_to_link,&init_target,&b_residual,tree); + Free_Edge_Lk_Rght(tree->a_edges[2*tree->n_otu-3]); + Free_Edge_Lk_Rght(tree->a_edges[2*tree->n_otu-2]); + Free_Edge_Pars_Rght(tree->a_edges[2*tree->n_otu-3]); + Free_Edge_Pars_Rght(tree->a_edges[2*tree->n_otu-2]); - if(recorded_l < 0.0) - { - /* Rough optimisation of the branch length at prune site - * We only need to perform this optimisation for the first - * element of spr_list because the pruned subtree is the - * same across all the elements of spr_list. It would not - * be true in the general case - */ - Fast_Br_Len(init_target,tree); - /* Record branch length at prune site */ - move->init_target_l = init_target->l; - recorded_l = init_target->l; - } - else - { - init_target->l = recorded_l; - move->init_target_l = recorded_l; - } - - /* Update the change proba matrix at prune position */ - Update_PMat_At_Given_Edge(init_target,tree); - - /* Update conditional likelihoods along the path from the prune to - the regraft position */ - Update_P_Lk_Along_A_Path(move->path,move->depth_path,tree); - - /* Regraft subtree */ - Graft_Subtree(move->b_target,move->n_link,b_residual,tree); - - Update_PMat_At_Given_Edge(move->b_target,tree); - Update_PMat_At_Given_Edge(b_residual,tree); - Update_P_Lk(tree,move->b_opp_to_link,move->n_link); - move_lnL = Lk_At_Given_Edge(move->b_opp_to_link,tree); - - if(move_lnL > best_lnL) - { - best_lnL = move_lnL; - best_move = i; - } - else - { - /* Estimate the three edge lengths at the regraft site */ - Triple_Dist(move->n_link,tree); - - move_lnL = Lk_At_Given_Edge(move->b_opp_to_link,tree); - - if(move_lnL > best_lnL) - { - best_lnL = move_lnL; - best_move = i; - } - } - - if(move_lnL > tree->best_spr->lnL) - { - tree->best_spr->lnL = move_lnL; - tree->best_spr->pars = tree->c_pars; - tree->best_spr->b_target = move->b_target; - tree->best_spr->n_link = move->n_link; - tree->best_spr->n_opp_to_link = move->n_opp_to_link; - tree->best_spr->b_opp_to_link = move->b_opp_to_link; - } - - /* Record branch lengths */ - dir_v1 = dir_v2 = dir_v0 = -1; - For(j,3) - { - if(move->n_link->v[j] == move->n_opp_to_link) dir_v0 = j; - else if(dir_v1 < 0) dir_v1 = j; - else dir_v2 = j; - } - move->l0 = move->n_link->b[dir_v0]->l; + best_edge = NULL; + best_lnL = UNLIKELY; + For(i,2*tree->n_otu-3) + { + PhyML_Printf("\n. Positionning root node on edge %4d",tree->a_edges[i]->num); + Add_Root(tree->a_edges[i],tree); + tree->ignore_root = NO; + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + + /* Optimize_Br_Len_Serie(2,tree); */ + + Update_Partial_Lk(tree,tree->n_root->b[1],tree->n_root); + Br_Len_Opt(&(tree->n_root->b[1]->l->v),tree->n_root->b[1],tree); + Update_Partial_Lk(tree,tree->n_root->b[2],tree->n_root); + Br_Len_Opt(&(tree->n_root->b[2]->l->v),tree->n_root->b[2],tree); + + PhyML_Printf(" -- lnL: %20f",tree->c_lnL); + if(tree->c_lnL > best_lnL) + { + best_lnL = tree->c_lnL; + best_edge = tree->a_edges[i]; + } + } - if(move->n_link->v[dir_v1]->num > move->n_link->v[dir_v2]->num) - { - move->l1 = move->n_link->b[dir_v2]->l; - move->l2 = move->n_link->b[dir_v1]->l; - } - else - { - move->l1 = move->n_link->b[dir_v1]->l; - move->l2 = move->n_link->b[dir_v2]->l; - } - - /* Record likelihood */ - move->lnL = tree->c_lnL; - - /* Regraft the subtree at its original position */ - Prune_Subtree(move->n_link, - move->n_opp_to_link, - &move->b_target, - &b_residual, - tree); - - Graft_Subtree(init_target, - move->n_link, - b_residual, - tree); - - /* Restore branch lengths */ - Restore_Br_Len(tree); - - /* Update relevant change proba matrices */ - Update_PMat_At_Given_Edge(move->b_target,tree); - } + Add_Root(best_edge,tree); + Set_Both_Sides(YES,tree); + Lk(NULL,tree); + Update_Partial_Lk(tree,tree->n_root->b[1],tree->n_root); + Br_Len_Opt(&(tree->n_root->b[1]->l->v),tree->n_root->b[1],tree); + Update_Partial_Lk(tree,tree->n_root->b[2],tree->n_root); + Br_Len_Opt(&(tree->n_root->b[2]->l->v),tree->n_root->b[2],tree); + tree->ignore_root = YES; } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - For(i,list_size) +void Set_Br_Len_Var(t_edge *b, t_tree *tree) +{ + if(tree->is_mixt_tree) { - move = spr_list[i]; - if(move->b_target) - { - For(j,3) Update_PMat_At_Given_Edge(move->n_link->b[j],tree); - For(j,3) Update_P_Lk(tree,move->n_link->b[j],move->n_link); - break; - } + MIXT_Set_Br_Len_Var(b,tree); + return; } -#ifdef DEBUG - if(best_move < 0) + if(tree->rates == NO && tree->mod->gamma_mgf_bl == YES) { - printf("\n\n. Best_move < 0 !"); - - printf("\n. List size = %d",list_size); - For(i,list_size) - { - move = spr_list[i]; - printf("\n. %p %p",move,move->b_target); - } - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); + phydbl len; + if(b == NULL) + { + int i; + + For(i,2*tree->n_otu-1) + { + len = MAX(0.0,tree->a_edges[i]->l->v); + tree->a_edges[i]->l_var->v = POW(len,2)*tree->mod->l_var_sigma; + } + } + else + { + len = MAX(0.0,b->l->v); + b->l_var->v = POW(len,2)*tree->mod->l_var_sigma; + } } -#endif - - return best_move; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Evaluate_One_Regraft_Pos_Triple(spr *move, arbre *tree) +void Check_Br_Lens(t_tree *tree) { - int j; - edge *init_target, *b_residual; - phydbl move_lnL; - int dir_v0, dir_v1, dir_v2; - - move_lnL = UNLIKELY; - init_target = b_residual = NULL; + int i; + scalar_dbl *l; - For(j,2*tree->n_otu-3) + For(i,2*tree->n_otu-1) { - tree->t_edges[j]->is_p_lk_r_u2d = 0; - tree->t_edges[j]->is_p_lk_l_u2d = 0; + l = tree->a_edges[i]->l; + do + { + /* if(l->v < tree->mod->l_min) l->v = tree->mod->l_min; */ + /* if(l->v > tree->mod->l_max) l->v = tree->mod->l_max; */ + if(l->v < 0.0) l->v = 0.0; + l = l->next; + } + while(l); } +} - if(move->b_target) - { - /* Record edge lengths */ - Record_Br_Len(tree); - - /* Prune subtree */ - Prune_Subtree(move->n_link,move->n_opp_to_link,&init_target,&b_residual,tree); - - /* Rough optimisation of the branch length at prune site */ - Fast_Br_Len(init_target,tree); - - /* Record edge length at prune site */ - move->init_target_l = init_target->l; +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - /* Update the change proba matrix at prune position */ - Update_PMat_At_Given_Edge(init_target,tree); - - /* Update partial likelihood along the path from the prune to - the regraft position */ - Update_P_Lk_Along_A_Path(move->path,move->depth_path,tree); - - /* Regraft subtree */ - Graft_Subtree(move->b_target,move->n_link,b_residual,tree); - - /* Estimate the three edge lengths at the regraft site */ - Triple_Dist(move->n_link,tree); +void Build_Distrib_Number_Of_Diff_States_Under_Model(t_tree *tree) +{ + calign *orig_data; + t_mod *orig_mod; + int iter,n_iter_tot,i,j; + phydbl *n_diff_states_all_l,*n_diff_states_all_r; - move_lnL = Lk_At_Given_Edge(move->b_opp_to_link,tree); - - /* Record branch lengths */ - dir_v1 = dir_v2 = dir_v0 = -1; - For(j,3) - { - if(move->n_link->v[j] == move->n_opp_to_link) dir_v0 = j; - else if(dir_v1 < 0) dir_v1 = j; - else dir_v2 = j; - } - - move->l0 = move->n_link->b[dir_v0]->l; - - if(move->n_link->v[dir_v1]->num > move->n_link->v[dir_v2]->num) - { - move->l1 = move->n_link->b[dir_v2]->l; - move->l2 = move->n_link->b[dir_v1]->l; - } - else - { - move->l1 = move->n_link->b[dir_v1]->l; - move->l2 = move->n_link->b[dir_v2]->l; - } - - /* Record likelihood */ - move->lnL = tree->c_lnL; - - /* Regraft the subtree at its original position */ - Prune_Subtree(move->n_link, - move->n_opp_to_link, - &move->b_target, - &b_residual, - tree); - - Graft_Subtree(init_target, - move->n_link, - b_residual, - tree); - - /* Restore branch lengths */ - Restore_Br_Len(tree); - - /* Update relevant change proba matrices */ - Update_PMat_At_Given_Edge(move->b_target,tree); - For(j,3) Update_PMat_At_Given_Edge(move->n_link->b[j],tree); - - /* Update relevant partial likelihoods */ - For(j,3) Update_P_Lk(tree,move->n_link->b[j],move->n_link); + Calculate_Number_Of_Diff_States(tree); + + PhyML_Printf("\n TRUE edge side states val"); + For(i,2*tree->n_otu-3) + { + if(tree->a_edges[i]->left->tax == NO && tree->a_edges[i]->rght->tax == NO) + { + for(j=0;jmod->ns;j++) + { + PhyML_Printf("\n TRUE %3d 0 %3d %d", + i, + j+1, + tree->a_edges[i]->n_diff_states_l[j]); + + PhyML_Printf("\n TRUE %3d 1 %3d %d", + i, + j+1, + tree->a_edges[i]->n_diff_states_r[j]); + } + } } -} -/*********************************************************/ -int Try_One_Spr_Move_Triple(spr *move, arbre *tree) -{ - edge *init_target, *b_residual; - int j; - int dir_v0, dir_v1, dir_v2; + n_iter_tot = 100; - Record_Br_Len(tree); + n_diff_states_all_l = (phydbl *)mCalloc((n_iter_tot) * (tree->mod->ns) * (2*tree->n_otu-3) * 2, sizeof(phydbl)); + n_diff_states_all_r = (phydbl *)mCalloc((n_iter_tot) * (tree->mod->ns) * (2*tree->n_otu-3) * 2, sizeof(phydbl)); - Prune_Subtree(move->n_link, - move->n_opp_to_link, - &init_target, - &b_residual, - tree); + orig_mod = Copy_Model(tree->mod); + orig_data = Copy_Cseq(tree->data,tree->io); - init_target->l = move->init_target_l; + orig_mod->io = tree->io; + orig_mod->s_opt = tree->mod->s_opt; - Graft_Subtree(move->b_target,move->n_link,b_residual,tree); + iter = 0; - dir_v1 = dir_v2 = dir_v0 = -1; - For(j,3) + do { - if(move->n_link->v[j] == move->n_opp_to_link) dir_v0 = j; - else if(dir_v1 < 0) dir_v1 = j; - else dir_v2 = j; - } + Evolve(tree->data,tree->mod,0,tree); - move->n_link->b[dir_v0]->l = move->l0; + Calculate_Number_Of_Diff_States(tree); - if(move->n_link->v[dir_v1]->num > move->n_link->v[dir_v2]->num) - { - move->n_link->b[dir_v2]->l = move->l1; - move->n_link->b[dir_v1]->l = move->l2; - } - else - { - move->n_link->b[dir_v1]->l = move->l1; - move->n_link->b[dir_v2]->l = move->l2; - } + For(i,2*tree->n_otu-3) + { + for(j=0;jmod->ns;j++) + { + n_diff_states_all_l[j*(2*tree->n_otu-3)*(n_iter_tot) + i*(n_iter_tot) + iter] = tree->a_edges[i]->n_diff_states_l[j]; + n_diff_states_all_r[j*(2*tree->n_otu-3)*(n_iter_tot) + i*(n_iter_tot) + iter] = tree->a_edges[i]->n_diff_states_r[j]; + } + } - if(move->lnL > tree->best_lnL) - { - time(&(tree->t_current)); - tree->both_sides = 1; - Lk(tree); - if(fabs(tree->c_lnL - move->lnL) > tree->mod->s_opt->min_diff_lk_local) - { - if(tree->mod->s_opt->print) printf("\n. c_lnL = %f move_lnL = %f", - tree->c_lnL,move->lnL); - printf("\n. Err in file %s at line %d",__FILE__,__LINE__); - Warn_And_Exit(""); - } + Free_Calign(tree->data); + Free_Model_Complete(tree->mod); + Free_Model_Basic(tree->mod); + + tree->mod = Copy_Model(orig_mod); + tree->data = Copy_Cseq(orig_data,tree->io); - Pars(tree); - if(tree->mod->s_opt->print) Print_Lk(tree,"[Topology ]"); + tree->mod->io = orig_mod->io; + tree->mod->s_opt = orig_mod->s_opt; + Connect_CSeqs_To_Nodes(tree->data,tree->io,tree); - tree->n_improvements++; - tree->best_lnL = tree->c_lnL; - Record_Br_Len(tree); - return 1; + iter++; } -/* else */ -/* { */ -/* Fast_Br_Len_Recur(tree->noeud[0], */ -/* tree->noeud[0]->v[0], */ -/* tree->noeud[0]->b[0], */ -/* tree); */ + while(iter < n_iter_tot); -/* tree->both_sides = 1; */ -/* Lk(tree); */ -/* if(tree->c_lnL > tree->best_lnL) */ -/* { */ -/* Pars(tree); */ -/* if(tree->mod->s_opt->print) Print_Lk_And_Pars(tree); */ -/* tree->n_improvements++; */ -/* tree->best_lnL = tree->c_lnL; */ -/* Record_Br_Len(tree); */ -/* return 1; */ -/* } */ -/* } */ + PhyML_Printf("\n SIM edge side states low up"); + For(i,2*tree->n_otu-3) + { + if(tree->a_edges[i]->left->tax == NO && tree->a_edges[i]->rght->tax == NO) + { + for(j=0;jmod->ns;j++) + { + PhyML_Printf("\n SIM %3d 0 %3d %.0f %.0f", + i, + j+1, + Quantile(n_diff_states_all_l + j*(2*tree->n_otu-3)*(n_iter_tot) + i*(n_iter_tot), n_iter_tot, 0.10), + Quantile(n_diff_states_all_l + j*(2*tree->n_otu-3)*(n_iter_tot) + i*(n_iter_tot), n_iter_tot, 0.90)); + + PhyML_Printf("\n SIM %3d 1 %3d %.0f %.0f", + i, + j+1, + Quantile(n_diff_states_all_r + j*(2*tree->n_otu-3)*(n_iter_tot) + i*(n_iter_tot), n_iter_tot, 0.10), + Quantile(n_diff_states_all_r + j*(2*tree->n_otu-3)*(n_iter_tot) + i*(n_iter_tot), n_iter_tot, 0.90)); + } + } + } - Prune_Subtree(move->n_link, - move->n_opp_to_link, - &move->b_target, - &b_residual, - tree); - Graft_Subtree(init_target, - move->n_link, - b_residual, - tree); + Add_Root(tree->a_edges[0],tree); + DR_Draw_Tree("treefile",tree); - Restore_Br_Len(tree); - tree->both_sides = 1; - Lk(tree); - Pars(tree); - return 0; + + Free(n_diff_states_all_l); + Free(n_diff_states_all_r); + } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -int Try_One_Spr_Move_Full(spr *move, arbre *tree) +/* Calculate the number of sites at which 1,...,n states (n: 4 or 20) */ +/* are observed, for every subtree */ + +void Calculate_Number_Of_Diff_States(t_tree *tree) +{ + Init_Ui_Tips(tree); + Calculate_Number_Of_Diff_States_Post(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree->a_nodes[0]->b[0],tree); + Calculate_Number_Of_Diff_States_Pre(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree->a_nodes[0]->b[0],tree); + + /* int i; */ + + /* For(i,2*tree->n_otu-3) */ + /* { */ + /* if(tree->a_edges[i]->left->tax == NO && tree->a_edges[i]->rght->tax == NO) */ + /* printf("\n. Edge %d left : %d %d %d %d right: %d %d %d %d", */ + /* i, */ + /* tree->a_edges[i]->n_diff_states_l[0], */ + /* tree->a_edges[i]->n_diff_states_l[1], */ + /* tree->a_edges[i]->n_diff_states_l[2], */ + /* tree->a_edges[i]->n_diff_states_l[3], */ + /* tree->a_edges[i]->n_diff_states_r[0], */ + /* tree->a_edges[i]->n_diff_states_r[1], */ + /* tree->a_edges[i]->n_diff_states_r[2], */ + /* tree->a_edges[i]->n_diff_states_r[3]); */ + /* } */ +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Calculate_Number_Of_Diff_States_Post(t_node *a, t_node *d, t_edge *b, t_tree *tree) { - edge *init_target, *b_residual; - - Record_Br_Len(tree); + if(d->tax) return; + else + { + int i; - Prune_Subtree(move->n_link, - move->n_opp_to_link, - &init_target, - &b_residual, - tree); + for(i=0;i<3;i++) + if(d->v[i] != a) + Calculate_Number_Of_Diff_States_Post(d,d->v[i],d->b[i],tree); - Graft_Subtree(move->b_target,move->n_link,b_residual,tree); + Calculate_Number_Of_Diff_States_Core(a,d,b,tree); + } +} - tree->both_sides = 1; - Lk(tree); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// - Optimize_Br_Len_Serie(tree->noeud[0], - tree->noeud[0]->v[0], - tree->noeud[0]->b[0], - tree, - tree->data); -/* Fast_Br_Len_Recur(tree->noeud[0], */ -/* tree->noeud[0]->v[0], */ -/* tree->noeud[0]->b[0], */ -/* tree); */ - - tree->both_sides = 1; - Lk(tree); +void Calculate_Number_Of_Diff_States_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree) +{ - if(tree->c_lnL > tree->best_lnL) - { - Pars(tree); - if(tree->mod->s_opt->print) Print_Lk(tree,"[Topology ]"); - tree->n_improvements++; - tree->best_lnL = tree->c_lnL; - Record_Br_Len(tree); - return 1; - } + if(d->tax) return; else { - Prune_Subtree(move->n_link, - move->n_opp_to_link, - &move->b_target, - &b_residual, - tree); - - Graft_Subtree(init_target, - move->n_link, - b_residual, - tree); - - Restore_Br_Len(tree); - tree->both_sides = 1; - Lk(tree); - Pars(tree); - return 0; - } + int i; - return -1; + for(i=0;i<3;i++) + if(d->v[i] != a) + { + Calculate_Number_Of_Diff_States_Core(d->v[i],d,d->b[i],tree); + Calculate_Number_Of_Diff_States_Pre(d,d->v[i],d->b[i],tree); + } + } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Include_One_Spr_To_List_Of_Spr(spr *move, arbre *tree) +void Calculate_Number_Of_Diff_States_Core(t_node *a, t_node *d, t_edge *b, t_tree *tree) { - int i; - spr *buff_spr; - - if(move->pars <= tree->spr_list[tree->size_spr_list-1]->pars) -/* if(move->lnL > tree->spr_list[tree->size_spr_list-1]->lnL) */ - { - tree->spr_list[tree->size_spr_list-1]->depth_path = move->depth_path; - tree->spr_list[tree->size_spr_list-1]->pars = move->pars; - tree->spr_list[tree->size_spr_list-1]->lnL = move->lnL; - tree->spr_list[tree->size_spr_list-1]->b_target = move->b_target; - tree->spr_list[tree->size_spr_list-1]->n_link = move->n_link; - tree->spr_list[tree->size_spr_list-1]->n_opp_to_link = move->n_opp_to_link; - tree->spr_list[tree->size_spr_list-1]->b_opp_to_link = move->b_opp_to_link; - tree->spr_list[tree->size_spr_list-1]->l0 = move->l0; - tree->spr_list[tree->size_spr_list-1]->l1 = move->l1; - tree->spr_list[tree->size_spr_list-1]->l2 = move->l2; - tree->spr_list[tree->size_spr_list-1]->dist = move->dist; - - For(i,tree->spr_list[tree->size_spr_list-1]->depth_path) - tree->spr_list[tree->size_spr_list-1]->path[i] = move->path[i]; - - for(i=tree->size_spr_list-1;i>0;i--) - { - if(tree->spr_list[i]->pars <= tree->spr_list[i-1]->pars) -/* if(tree->spr_list[i]->lnL > tree->spr_list[i-1]->lnL) */ - { - buff_spr = tree->spr_list[i-1]; - tree->spr_list[i-1] = tree->spr_list[i]; - tree->spr_list[i] = buff_spr; - } - else break; - } - } -} + int *ui, *ui_v1, *ui_v2; + int sum,site,state; + int *diff; + t_node *v1, *v2; -/*********************************************************/ + ui = ui_v1 = ui_v2 = NULL; + v1 = v2 = NULL; -void Random_Tree(arbre *tree) -{ - int *is_available,*list_of_nodes; - int i,node_num,step,n_available; + if(d == b->left) + { + v1 = (d == d->b[b->l_v1]->left)? + (d->b[b->l_v1]->rght): + (d->b[b->l_v1]->left); + + v2 = (d == d->b[b->l_v2]->left)? + (d->b[b->l_v2]->rght): + (d->b[b->l_v2]->left); + + ui = b->ui_l; + diff = b->n_diff_states_l; - is_available = (int *)mCalloc(2*tree->n_otu-2,sizeof(int)); - list_of_nodes = (int *)mCalloc(tree->n_otu, sizeof(int)); + ui_v1 = + (d == d->b[b->l_v1]->left)? + (d->b[b->l_v1]->ui_r): + (d->b[b->l_v1]->ui_l); - For(i,tree->n_otu) is_available[i] = 1; - For(i,tree->n_otu) list_of_nodes[i] = i; + ui_v2 = + (d == d->b[b->l_v2]->left)? + (d->b[b->l_v2]->ui_r): + (d->b[b->l_v2]->ui_l); - step = 0; - do + } + else { - node_num = (int)rint(rand()/(phydbl)(RAND_MAX+1.0)*(tree->n_otu-1-step)); - node_num = list_of_nodes[node_num]; - is_available[node_num] = 0; - For(i,tree->n_otu) list_of_nodes[i] = -1; - n_available = 0; - For(i,2*tree->n_otu-2) if(is_available[i]) {list_of_nodes[n_available++] = i;} + v1 = (d == d->b[b->r_v1]->left)? + (d->b[b->r_v1]->rght): + (d->b[b->r_v1]->left); - tree->noeud[node_num]->v[0] = tree->noeud[tree->n_otu+step]; - tree->noeud[tree->n_otu+step]->v[1] = tree->noeud[node_num]; + v2 = (d == d->b[b->r_v2]->left)? + (d->b[b->r_v2]->rght): + (d->b[b->r_v2]->left); - node_num = (int)rint(rand()/(phydbl)(RAND_MAX+1.0)*(tree->n_otu-2-step)); - node_num = list_of_nodes[node_num]; - is_available[node_num] = 0; - For(i,tree->n_otu) list_of_nodes[i] = -1; - n_available = 0; - For(i,2*tree->n_otu-2) if(is_available[i]) {list_of_nodes[n_available++] = i;} + ui = b->ui_r; + diff = b->n_diff_states_r; + + ui_v1 = + (d == d->b[b->r_v1]->left)? + (d->b[b->r_v1]->ui_r): + (d->b[b->r_v1]->ui_l); + + ui_v2 = + (d == d->b[b->r_v2]->left)? + (d->b[b->r_v2]->ui_r): + (d->b[b->r_v2]->ui_l); - tree->noeud[node_num]->v[0] = tree->noeud[tree->n_otu+step]; - tree->noeud[tree->n_otu+step]->v[2] = tree->noeud[node_num]; + } - is_available[tree->n_otu+step] = 1; - For(i,tree->n_otu) list_of_nodes[i] = -1; - n_available = 0; - For(i,2*tree->n_otu-2) if(is_available[i]) list_of_nodes[n_available++] = i; + for(state=0;statemod->ns;state++) diff[state] = 0; + + for(site=0;siten_pattern;site++) + { + if(v1->tax == YES) + { + int sum; + sum = Sum_Bits(ui_v1[site],tree->mod->ns); + if(sum > 1) + { + int val = ui_v1[site]; + int pos, iter; + phydbl u = Uni(); + + iter = 0; + do + { + pos = Rand_Int(0,tree->mod->ns-1); + if(((val >> pos) & 1) && (u > 1./sum)) break; + } + while(iter++ < 1000); - step++; - }while(step < tree->n_otu-2); - tree->noeud[list_of_nodes[0]]->v[0] = tree->noeud[list_of_nodes[1]]; - tree->noeud[list_of_nodes[1]]->v[0] = tree->noeud[list_of_nodes[0]]; + if(iter == 1000) + { + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } - tree->num_curr_branch_available = 0; - Connect_Edges_To_Nodes_Recur(tree->noeud[0],tree->noeud[0]->v[0],tree); -/* Print_Node(tree->noeud[0],tree->noeud[0]->v[0],tree); */ - - Fill_Dir_Table(tree); - Update_Dirs(tree); - - Free(is_available); - Free(list_of_nodes); -} + ui_v1[site] = POW(2,pos); + } + } -/*********************************************************/ + if(v2->tax == YES) + { + int sum; + sum = Sum_Bits(ui_v2[site],tree->mod->ns); + if(sum > 1) + { + int val = ui_v2[site]; + int pos, iter; + phydbl u = Uni(); + + iter = 0; + do + { + pos = Rand_Int(0,tree->mod->ns-1); + if(((val >> pos) & 1) && (u > 1./sum)) break; + } + while(iter++ < 1000); -void Random_Spr(int n_moves, arbre *tree) -{ - int i; - int br_pulled, br_target; - spr *spr_struct; - edge *target, *residual; + if(iter == 1000) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); - spr_struct = Make_One_Spr(tree); - Init_One_Spr(spr_struct); - target = residual = NULL; - For(i,n_moves) - { - br_pulled = (int)((phydbl)rand()/RAND_MAX * (2*tree->n_otu-3-1)); - do - { - br_target = (int)((phydbl)rand()/RAND_MAX * (2*tree->n_otu-3-1)); - }while(br_target == br_pulled); + ui_v2[site] = POW(2,pos); + } + } - spr_struct->n_link = tree->t_edges[br_pulled]->left; - spr_struct->n_opp_to_link = tree->t_edges[br_pulled]->rght; - spr_struct->b_opp_to_link = tree->t_edges[br_pulled]; - spr_struct->b_target = tree->t_edges[br_target]; - spr_struct->b_init_target = NULL; + ui[site] = ui_v1[site] | ui_v2[site]; + + sum = Sum_Bits(ui[site],tree->mod->ns); - if(!Check_Spr_Move_Validity(spr_struct,tree)) - { - spr_struct->n_link = tree->t_edges[br_pulled]->rght; - spr_struct->n_opp_to_link = tree->t_edges[br_pulled]->left; - } + /* printf("\n. ui_v1: %d ui_v2: %d ui: %d sum: %d",ui_v1[site],ui_v2[site],ui[site],sum); fflush(NULL); */ -#ifdef DEBUG - if(!Check_Spr_Move_Validity(spr_struct,tree)) - { - Warn_And_Exit("\n. Could not find a valid move...\n"); - } -#endif + if(sum-1 > tree->mod->ns-1) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); - Prune_Subtree(spr_struct->n_link, - spr_struct->n_opp_to_link, - &target, - &residual, - tree); + diff[sum-1]++; - Graft_Subtree(spr_struct->b_target, - spr_struct->n_link, - residual,tree); } - Free(spr_struct); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +/* Returns the number of distinct states observed at a particular site */ -void Random_NNI(int n_moves, arbre *tree) +int Number_Of_Diff_States_One_Site(int site, t_tree *tree) { - int i,j; - edge *b; - node *n1,*n2,*n_target; - - n1 = n2 = NULL; - b = NULL; - For(i,n_moves) - { - n_target = tree->noeud[tree->n_otu + (int)((phydbl)rand()/RAND_MAX * (2*tree->n_otu-3-tree->n_otu))]; - For(j,3) if(!n_target->v[j]->tax) {b = n_target->b[j]; break;} + int n_states; + Number_Of_Diff_States_One_Site_Post(tree->a_nodes[0], + tree->a_nodes[0]->v[0], + tree->a_nodes[0]->b[0], + site,tree); + + n_states = Sum_Bits(tree->a_nodes[0]->b[0]->ui_r[site] | tree->a_nodes[0]->b[0]->ui_l[site],tree->mod->ns); - For(j,3) if(b->left->v[j] != b->rght) {n1 = b->left->v[j]; break;} - For(j,3) if(b->rght->v[j] != b->left) {n2 = b->rght->v[j]; break;} - Swap(n1,b->left,b->rght,n2,tree); - } + return(n_states); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Reset_Spr_List(arbre *tree) +void Number_Of_Diff_States_One_Site_Post(t_node *a, t_node *d, t_edge *b, int site, t_tree *tree) { - int i; + if(d->tax) return; + else + { + int i; - tree->spr_list[0]->depth_path = 0; - tree->spr_list[0]->pars = MAX_PARS; - tree->spr_list[0]->lnL = UNLIKELY; - tree->spr_list[0]->n_link = NULL; - tree->spr_list[0]->n_opp_to_link = NULL; - tree->spr_list[0]->b_target = NULL; + for(i=0;i<3;i++) + if(d->v[i] != a && d->b[i] != tree->e_root) + Number_Of_Diff_States_One_Site_Post(d,d->v[i],d->b[i],site,tree); - for(i=1;isize_spr_list;i++) - { - tree->spr_list[i]->depth_path = 0; - tree->spr_list[i]->pars = tree->spr_list[0]->pars; - tree->spr_list[i]->lnL = tree->spr_list[0]->lnL; - tree->spr_list[i]->n_link = NULL; - tree->spr_list[i]->n_opp_to_link = NULL; - tree->spr_list[i]->b_target = NULL; + Number_Of_Diff_States_One_Site_Core(a,d,b,site,tree); } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Print_Settings(option *io) +int Number_Of_Diff_States_One_Site_Core(t_node *a, t_node *d, t_edge *b, int site, t_tree *tree) { - int answer; - - printf("\n\n\n"); - printf("\n\n"); - - printf(" .......................... \n"); - printf(" ooooooooooooooooooooooooooooo CURRENT SETTINGS ooooooooooooooooooooooooooooooooooo\n"); - printf(" .......................... \n"); - - printf("\n . Sequence filename : \t\t\t\t %s", io->in_seq_file); - printf("\n . Data type : \t\t\t %s", (io->mod->datatype ? "aa" : "dna")); - printf("\n . Sequence format : \t\t\t\t %s", io->interleaved ? "interleaved" : "sequential"); - printf("\n . Number of data sets : \t\t\t %d", io->n_data_sets); - - printf("\n . Nb of bootstrapped data sets : \t\t %d", io->mod->bootstrap); - - if (io->mod->bootstrap > 0) - printf("\n . Compute approximate likelihood ratio test : \t no"); + int *ui, *ui_v1, *ui_v2; + int sum; + t_node *v1, *v2; + + ui = ui_v1 = ui_v2 = NULL; + v1 = v2 = NULL; + + if(d == b->left) + { + v1 = (d == d->b[b->l_v1]->left)? + (d->b[b->l_v1]->rght): + (d->b[b->l_v1]->left); + + v2 = (d == d->b[b->l_v2]->left)? + (d->b[b->l_v2]->rght): + (d->b[b->l_v2]->left); + + ui = b->ui_l; + + ui_v1 = + (d == d->b[b->l_v1]->left)? + (d->b[b->l_v1]->ui_r): + (d->b[b->l_v1]->ui_l); + + ui_v2 = + (d == d->b[b->l_v2]->left)? + (d->b[b->l_v2]->ui_r): + (d->b[b->l_v2]->ui_l); + } else { - if(io->ratio_test == 1) - printf("\n . Compute approximate likelihood ratio test : \t yes (aLRT statistics)"); - else if(io->ratio_test == 2) - printf("\n . Compute approximate likelihood ratio test : \t yes (Chi2-based parametric branch supports)"); - else if(io->ratio_test == 3) - printf("\n . Compute approximate likelihood ratio test : \t yes (Minimum of SH-like and Chi2-based branch supports)"); - else if(io->ratio_test == 4) - printf("\n . Compute approximate likelihood ratio test : \t yes (SH-like branch supports)"); + v1 = (d == d->b[b->r_v1]->left)? + (d->b[b->r_v1]->rght): + (d->b[b->r_v1]->left); + + v2 = (d == d->b[b->r_v2]->left)? + (d->b[b->r_v2]->rght): + (d->b[b->r_v2]->left); + + ui = b->ui_r; + + ui_v1 = + (d == d->b[b->r_v1]->left)? + (d->b[b->r_v1]->ui_r): + (d->b[b->r_v1]->ui_l); + + ui_v2 = + (d == d->b[b->r_v2]->left)? + (d->b[b->r_v2]->ui_r): + (d->b[b->r_v2]->ui_l); + } + + if(v1->tax == YES) // Check for ambiguous character state at this tip + { + sum = Sum_Bits(ui_v1[site],tree->mod->ns); + + if(sum > 1) + { + int val = ui_v1[site]; + int pos, iter; + phydbl u = Uni(); + + // Select a state uniformly at random + iter = 0; + do + { + pos = Rand_Int(0,tree->mod->ns-1); + if(((val >> pos) & 1) && (u > 1./sum)) break; + } + while(iter++ < 1000); + + + if(iter == 1000) + { + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + ui_v1[site] = POW(2,pos); + } } - printf("\n . Model name : \t\t\t\t\t %s", io->mod->modelname); - - if (io->mod->datatype == NT) + if(v2->tax == YES) { - if ((io->mod->whichmodel == K80) || - (io->mod->whichmodel == HKY85)|| - (io->mod->whichmodel == F84) || - (io->mod->whichmodel == TN93)) - { - if (io->mod->s_opt->opt_kappa) - printf("\n . Ts/tv ratio : \t\t\t\t estimated"); - else - printf("\n . Ts/tv ratio : \t\t\t\t %f", io->mod->kappa); - } + sum = Sum_Bits(ui_v2[site],tree->mod->ns); + if(sum > 1) + { + int val = ui_v2[site]; + int pos, iter; + phydbl u = Uni(); + + iter = 0; + do + { + pos = Rand_Int(0,tree->mod->ns-1); + if(((val >> pos) & 1) && (u > 1./sum)) break; + } + while(iter++ < 1000); + + if(iter == 1000) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + + ui_v2[site] = POW(2,pos); + } } + + ui[site] = ui_v1[site] | ui_v2[site]; + + sum = Sum_Bits(ui[site],tree->mod->ns); - if (io->mod->s_opt->opt_pinvar) - printf("\n . Proportion of invariable sites :\t\t estimated"); - else - printf("\n . Proportion of invariable sites :\t\t %f", io->mod->pinvar); + /* printf("\n. ui_v1: %d ui_v2: %d ui: %d sum: %d",ui_v1[site],ui_v2[site],ui[site],sum); fflush(NULL); */ + + if(sum-1 > tree->mod->ns-1) + { + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + return sum; +} - printf("\n . Number of subst. rate categs : \t\t %d", io->mod->n_catg); - if(io->mod->s_opt->opt_alpha) - printf("\n . Gamma distribution parameter : \t\t estimated"); - else - printf("\n . Gamma distribution parameter : \t\t %f", io->mod->alpha); - - if(io->mod->datatype == AA) - printf("\n . Amino acid equilibrium frequencies : \t\t %s", (io->mod->s_opt->opt_state_freq) ? ("empirical"):("model")); - else if(io->mod->datatype == NT) - if((io->mod->whichmodel != JC69) && - (io->mod->whichmodel != K80) && - (io->mod->whichmodel != F81)) - printf("\n . Nucleotide equilibrium frequencies : \t\t %s", (io->mod->s_opt->opt_state_freq) ? ("ML"):("empirical")); +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +phydbl Get_Lk(t_tree *tree) +{ + t_tree *loc_tree; - printf("\n . Optimise tree topology : \t\t\t %s", (io->mod->s_opt->opt_topo) ? "yes" : "no"); - if(io->mod->s_opt->opt_topo) - { - printf("\n . Tree topology search : \t\t\t %s%s", - (io->mod->s_opt->topo_search == NNI_MOVE)?("NNIs"):("SPRs"), - (io->mod->s_opt->spr_step_after_nnis)?("+SPRs"):("")); + loc_tree = tree; + /*! Rewind back to the first mixt_tree */ + while(loc_tree->prev) loc_tree = loc_tree->prev; + return loc_tree->c_lnL; - printf("\n . Random input tree : \t\t\t\t %s", (io->mod->s_opt->random_input_tree) ? "yes" : "no"); - if(!io->mod->s_opt->random_input_tree) - printf("\n . Starting tree : \t\t\t\t %s", (!io->in_tree) ? "BIONJ" : io->in_tree_file); - else - printf("\n . Number of random starting trees : \t\t %d", io->mod->s_opt->n_rand_starts); - } - printf("\n . Optimise branch lengths : \t\t\t %s", (io->mod->s_opt->opt_bl) ? "yes" : "no"); +} - answer = 0; - if(io->mod->s_opt->opt_alpha || - io->mod->s_opt->opt_kappa || - io->mod->s_opt->opt_lambda || - io->mod->s_opt->opt_pinvar || - io->mod->s_opt->opt_rr) answer = 1; - - printf("\n . Optimise substitution model parameters : \t %s", (answer) ? "yes" : "no"); +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +phydbl Get_dLk(t_tree *tree) +{ + t_tree *loc_tree; + loc_tree = tree; + /*! Rewind back to the first mixt_tree */ + while(loc_tree->prev) loc_tree = loc_tree->prev; - printf("\n\n oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"); + return loc_tree->c_dlnL; - printf("\n\n"); - fflush(NULL); } +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -/*********************************************************/ - -void Fill_Missing_Dist(matrix *mat) +phydbl Get_d2Lk(t_tree *tree) { - int i,j; - For(i,mat->n_otu) - { - for(j=i+1;jn_otu;j++) - { - if(i != j) - { - if(mat->dist[i][j] < .0) - { - Fill_Missing_Dist_XY(i,j,mat); - mat->dist[j][i] = mat->dist[i][j]; - } - } - } - } -} + t_tree *loc_tree; -/*********************************************************/ + loc_tree = tree; + /*! Rewind back to the first mixt_tree */ + while(loc_tree->prev) loc_tree = loc_tree->prev; -void Fill_Missing_Dist_XY(int x, int y, matrix *mat) -{ + return loc_tree->c_d2lnL; - int i,j; - phydbl *local_mins,**S1S2; - int cpt; - int pos_best_estimate; - phydbl min_crit, curr_crit; +} - local_mins = (phydbl *)mCalloc(mat->n_otu*mat->n_otu,sizeof(phydbl )); - S1S2 = (phydbl **)mCalloc(mat->n_otu*mat->n_otu,sizeof(phydbl *)); - For(i,mat->n_otu*mat->n_otu) S1S2[i] = (phydbl *)mCalloc(2,sizeof(phydbl)); +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ - cpt = 0; - For(i,mat->n_otu) +align **Make_Empty_Alignment(option *io) +{ + int i; + char *line; + align **data; + + line = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + data = (align **)mCalloc(io->n_otu,sizeof(align *)); + + for(i=0;in_otu;i++) { - if((mat->dist[i][x] > .0) && (mat->dist[i][y] > .0)) - { - For(j,mat->n_otu) - { - if((mat->dist[j][x] > .0) && (mat->dist[j][y] > .0)) - { - if((i != j) && (i != x) && (i != y) && (j != x) && (j != y)) - { - S1S2[cpt][0] = MIN(mat->dist[i][x] + mat->dist[j][y] - mat->dist[i][j] , mat->dist[i][y] + mat->dist[j][x] - mat->dist[i][j]); - S1S2[cpt][1] = MAX(mat->dist[i][x] + mat->dist[j][y] - mat->dist[i][j] , mat->dist[i][y] + mat->dist[j][x] - mat->dist[i][j]); - cpt++; - } - } - } - } - } + data[i] = (align *)mCalloc(1,sizeof(align)); + data[i]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + data[i]->state = (char *)mCalloc(io->init_len*io->state_len+1,sizeof(char)); - Qksort_Matrix(S1S2,0,0,cpt-1); + data[i]->is_ambigu = NULL; + data[i]->len = 0; + + Random_String(data[i]->name,5); - local_mins[0] = S1S2[0][1]; - for(i=1;i S1S2[i][0])) - { - curr_crit = Least_Square_Missing_Dist_XY(x,y,local_mins[i],mat); - if(curr_crit < min_crit) - { - min_crit = curr_crit; - pos_best_estimate = i; - } - } + while(data[i]->len < io->init_len * io->state_len) + { + data[i]->state[data[i]->len] = 'X'; + data[i]->len++; + } } - mat->dist[x][y] = local_mins[pos_best_estimate]; - mat->dist[y][x] = mat->dist[x][y]; + for(i=0;in_otu;i++) data[i]->state[data[i]->len] = '\0'; - For(i,mat->n_otu*mat->n_otu) Free(S1S2[i]); - Free(S1S2); - Free(local_mins); -} + Free(line); -/*********************************************************/ + return data; +} -phydbl Least_Square_Missing_Dist_XY(int x, int y, phydbl dxy, matrix *mat) +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Mean observed frequency of difference between the n(n-1)/2 pairs of sequences */ +phydbl Mean_Identity(calign *data) { - int i,j; - phydbl fit; - - fit = .0; - For(i,mat->n_otu) + int i,j,n; + phydbl tot_idt; + + n = data->n_otu; + + tot_idt = 0.0; + for(i=0;idist[i][x] > .0) && (mat->dist[i][y] > .0)) - { - For(j,mat->n_otu) - { - if((mat->dist[j][x] > .0) && (mat->dist[j][y] > .0)) - { - if((i != j) && (i != x) && (i != y) && (j != x) && (j != y)) - { - if(dxy < MIN(mat->dist[i][x] + mat->dist[j][y] - mat->dist[i][j] , mat->dist[i][y] + mat->dist[j][x] - mat->dist[i][j])) - { - fit += pow((mat->dist[i][x] + mat->dist[j][y]) - (mat->dist[i][y] + mat->dist[j][x]),2); - } - else if((mat->dist[i][x] + mat->dist[j][y]) < (mat->dist[i][y] + mat->dist[j][x])) - { - fit += pow(dxy - (mat->dist[i][y] + mat->dist[j][x] - mat->dist[i][j]),2); - } - else - { - fit += pow(dxy - (mat->dist[i][x] + mat->dist[j][y] - mat->dist[i][j]),2); - } - } - } - } - } + for(j=i+1; jcrunch_len;k++) if(data->c_seq[i]->state[k] == data->c_seq[j]->state[k]) div += (phydbl)data->wght[k]; -/*********************************************************/ + /* observed proportion of identity */ + p = 1. - div / (phydbl)data->init_len; + d = 0.0; + if(data->io->datatype == NT) + { + if(p > 3./4.) return 0.25; + else + { + /* Jukes & Cantor distance */ + d = -(3./4.)*log(1. - 4./3.*p); + } + } + else if(data->io->datatype == AA) + { + if(p > 19./20.) return 1./20.; + else + { + /* Jukes & Cantor distance */ + d = -(19./20.)*log(1. - 20./19.*p); + } + } + else Generic_Exit(__FILE__,__LINE__,__FUNCTION__); -void Print_Data_Set_Number(option *io, FILE *fp) -{ - fprintf(fp,"\n"); - fprintf(fp," \n"); - fprintf(fp," [ Data set number %3d ] \n",io->curr_gt+1); - fprintf(fp," \n"); + return(exp(-d)); } -/*********************************************************/ -void Check_Memory_Amount(arbre *tree) +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +phydbl Fst(int i, int j, calign *data) { - /* Rough estimate of the amount of memory that has to be used */ + phydbl FA, Fr; - int nbytes; - model *mod; + FA = Mean_Identity(data); + Fr = Pairwise_Identity(i,j,data); - mod = tree->mod; + return((Fr-FA)/(1-FA)); +} - nbytes = 0; +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +phydbl Nucleotide_Diversity(calign *data) +{ - /* Pmat */ - nbytes += (2*mod->n_otu-3) * mod->n_catg * mod->ns * mod->ns * sizeof(phydbl); - nbytes += (2*mod->n_otu-3) * mod->n_catg * mod->ns * sizeof(phydbl *); - nbytes += (2*mod->n_otu-3) * mod->n_catg * sizeof(phydbl **); - nbytes += (2*mod->n_otu-3) * mod->n_catg * sizeof(phydbl ***); + int i,j,n; + phydbl pair_div; - /* Partial Lk */ - nbytes += (2*mod->n_otu-3) * 2 * tree->n_pattern * mod->n_catg * mod->ns * sizeof(phydbl); - nbytes += (2*mod->n_otu-3) * 2 * tree->n_pattern * mod->n_catg * sizeof(phydbl *); - nbytes += (2*mod->n_otu-3) * 2 * tree->n_pattern * sizeof(phydbl **); - nbytes += (2*mod->n_otu-3) * 2 * tree->n_pattern * sizeof(phydbl ***); - nbytes += (2*mod->n_otu-3) * 2 * tree->n_pattern * sizeof(phydbl); - - /* Partial Pars */ - nbytes += (2*mod->n_otu-3) * 2 * tree->n_pattern * mod->ns * sizeof(int); - nbytes += (2*mod->n_otu-3) * 2 * tree->n_pattern * sizeof(int *); - nbytes += (2*mod->n_otu-3) * 2 * tree->n_pattern * sizeof(int ); - - if(((phydbl)nbytes/(1.E+06)) > 256.) + n = data->n_otu; + + pair_div = 0.0; + for(i=0;i 100.) - printf("\n. WARNING: this analysis will use at least %.0fMo of memory space...",(phydbl)nbytes/(1.E+06)); - else - printf("\n. This analysis requires at least %.0fMo of memory space.",(phydbl)nbytes/(1.E+06)); - + + return(pair_div / (phydbl)(n*(n-1.)/2.)); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -int Get_State_From_P_Lk(phydbl *p_lk, arbre *tree) +void Copy_Scalar_Dbl(scalar_dbl *from, scalar_dbl *to) { - int i; - For(i,tree->mod->ns) if(p_lk[i] > .0) return i; - return -1; + scalar_dbl *f,*t; + f = from; + t = to; + do + { + assert(t); + assert(f); + t->v = f->v; + t = t->next; + f = f->next; + } + while(f); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -int Get_State_From_P_Pars(short int *p_pars, arbre *tree) +scalar_dbl *Duplicate_Scalar_Dbl(scalar_dbl *from) { - int i; - For(i,tree->mod->ns) if(p_pars[i] > .0) return i; - return -1; + scalar_dbl *to,*t,*f; + + to = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + + t = to; + f = from; + do + { + + t->v = f->v; + f = f->next; + if(f) t->next = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + t = t->next; + } + while(f); + + return(to); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Print_Lk(arbre *tree, char *string) +void Multiply_Scalar_Dbl(phydbl mult, scalar_dbl *x) { - time(&(tree->t_current)); - printf("\n. (%5d sec) [%10.6f] %s",(int)(tree->t_current-tree->t_beg),tree->c_lnL,string); -#ifndef QUIET - fflush(NULL); -#endif + scalar_dbl *y; + + y = x; + do + { + y->v = y->v * mult; + y = y->next; + } + while(y); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Print_Pars(arbre *tree) +void Set_Scalar_Dbl(phydbl val, scalar_dbl *from) { - time(&(tree->t_current)); - printf("\n. (%5d sec) [%5d]",(int)(tree->t_current-tree->t_beg),tree->c_pars); -#ifndef QUIET - fflush(NULL); -#endif + scalar_dbl *f; + + f = from; + do + { + f->v = val;; + f = f->next; + } + while(f); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Print_Lk_And_Pars(arbre *tree) -{ - time(&(tree->t_current)); +void Set_Scalar_Dbl_Min_Thresh(phydbl thresh, scalar_dbl *from) +{ + scalar_dbl *f; - printf("\n. (%5d sec) [%10.4f] [%5d]", - (int)(tree->t_current-tree->t_beg), - tree->c_lnL,tree->c_pars); -#ifndef QUIET - fflush(NULL); -#endif + + f = from; + do + { + if(f->v < thresh) f->v = thresh;; + f = f->next; + } + while(f); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Check_Dirs(arbre *tree) +void Set_Scalar_Dbl_Max_Thresh(phydbl thresh, scalar_dbl *from) { - int i; + scalar_dbl *f; - For(i,2*tree->n_otu-3) + f = from; + do { - if(!tree->t_edges[i]->left->tax) - { - if(tree->t_edges[i]->left->v[tree->t_edges[i]->l_v1]->num < - tree->t_edges[i]->left->v[tree->t_edges[i]->l_v2]->num) - { - printf("\n. Edge %d ; v1=%d v2=%d", - tree->t_edges[i]->num, - tree->t_edges[i]->left->v[tree->t_edges[i]->l_v1]->num, - tree->t_edges[i]->left->v[tree->t_edges[i]->l_v2]->num); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - } - - if(!tree->t_edges[i]->rght->tax) - { - if(tree->t_edges[i]->rght->v[tree->t_edges[i]->r_v1]->num < - tree->t_edges[i]->rght->v[tree->t_edges[i]->r_v2]->num) - { - printf("\n. Edge %d ; v3=%d v4=%d", - tree->t_edges[i]->num, - tree->t_edges[i]->rght->v[tree->t_edges[i]->r_v1]->num, - tree->t_edges[i]->rght->v[tree->t_edges[i]->r_v2]->num); - printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); - Warn_And_Exit(""); - } - } + if(f->v > thresh) f->v = thresh;; + f = f->next; } + while(f); } +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -/*********************************************************/ - -void Warn_And_Exit(char *s) +phydbl Scalar_Elem(int pos, scalar_dbl *scl) { - fprintf(stdout,"%s",s); - fflush(NULL); - #ifndef BATCH - char c; - fprintf(stdout,"\n. Type any key to exit.\n"); - fscanf(stdin,"%c",&c); - #endif - Exit("\n"); + scalar_dbl *loc; + loc = scl; + while(--pos >= 0) loc = loc->next; + assert(loc); + return(loc->v); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Read_Qmat(double *daa, phydbl *pi, FILE *fp) +void *Linked_List_Elem(int pos, t_ll *ll) { - int i,j; - phydbl sum; - - for(i=1;i<20;i++) + t_ll *loc; + + if(ll == NULL) return NULL; + + loc = ll->head; + while(--pos >= 0) { - For(j,19) - { - fscanf(fp,"%lf",&(daa[i*20+j])); - daa[j*20+i] = daa[i*20+j]; - if(j == i-1) break; - } + assert(loc); + loc = loc->next; } + assert(loc); + return(loc->v); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +int Scalar_Len(scalar_dbl *scl) +{ + int len; + scalar_dbl *loc; + + if(!scl) return 0; - For(i,20) fscanf(fp,"%lf",pi+i); - sum = .0; - For(i,20) sum += pi[i]; - if(fabs(sum - 1.) > 1.E-06) + loc = scl; + len = 0; + do { - printf("\n. Error : the rate matrix format is incorrect\n"); - Warn_And_Exit("\n"); + len++; + loc = loc->next; } + while(loc != NULL); + + return(len); + } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Print_Qmat_AA(double *daa, phydbl *pi) +int Linked_List_Len(t_ll *list) { - int i,j,cpt; + int len; + t_ll *loc; - cpt = 0; - For(i,20) + if(list == NULL) return 0; + + loc = list->head; + len = 0; + do { - for(j=0;jnext; } + while(loc != NULL); - printf("\n\n"); - printf("for (i=0; itail->v:NULL; */ + /* t_node *o = (*list)?(*list)->head->v:NULL; */ + /* printf("\n. before: push node %d bot %d head: %d --",n?n->num:-1,m?m->num:-1,o?o->num:-1); */ + /* } */ + /* else */ + /* { */ + /* printf("\n. "); */ + /* } */ + /* } */ + + /* if(*list == NULL) printf("\n"); */ - exchange_with = -1; - For(i,data->n_otu) + new = (t_ll *)mCalloc(1,sizeof(t_ll)); + new->v = (void *)what; + + /* t_node *n = what; */ + /* printf("\n push node %p list: %p %p",new,*list,(*list)?(*list)->head:NULL); */ + + + // First elem of list + if(*list == NULL) { - buff_dbl = rand(); - buff_dbl /= (RAND_MAX+1.); - buff_dbl *= data->n_otu; - exchange_with = (int)floor(buff_dbl); - - buff_name = data->c_seq[i]->name; - data->c_seq[i]->name = data->c_seq[exchange_with]->name; - data->c_seq[exchange_with]->name = buff_name; + *list = new; + new->tail = new; + new->head = new; + new->next = NULL; + new->prev = NULL; + } + else + { + ll = (*list)->head; + + if(remove_duplicates == YES) + { + do + { + if(ll->v == what) + { + Free(new); + return; // 'what' already in list + } + ll = ll->next; + } + while(ll); + } - buff_seq = data->c_seq[i]->state; - data->c_seq[i]->state = data->c_seq[exchange_with]->state; - data->c_seq[exchange_with]->state = buff_seq; + new->prev = (*list)->tail; + (*list)->tail->next = new; + new->next = NULL; + new->head = (*list)->head; - buff_ambigu = data->c_seq[i]->is_ambigu; - data->c_seq[i]->is_ambigu = data->c_seq[exchange_with]->is_ambigu; - data->c_seq[exchange_with]->is_ambigu = buff_ambigu; + ll = (*list)->head; + do + { + ll->tail = new; + ll = ll->next; + } + while(ll); } } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Update_Root_Pos(arbre *tree) +void Swap_Partial_Lk_Extra(t_edge *b, t_node *d, int whichone, t_tree *tree) { - if(tree->n_root_pos > -1.0) + void *buff; + + if(whichone == 0) { - tree->n_root->l[0] = tree->e_root->l * tree->n_root_pos; - tree->n_root->l[1] = tree->e_root->l * (1.-tree->n_root_pos); + if(d == b->left) + { + buff = b->div_post_pred_left; + b->div_post_pred_left = tree->div_post_pred_extra_0; + tree->div_post_pred_extra_0 = buff; + + buff = b->sum_scale_left_cat; + b->sum_scale_left_cat = tree->sum_scale_cat_extra_0; + tree->sum_scale_cat_extra_0 = buff; + + if(b->left) + { + if(!b->left->tax) + { + buff = b->sum_scale_left; + b->sum_scale_left = tree->sum_scale_extra_0; + tree->sum_scale_extra_0 = buff; + } + + if(!b->left->tax || tree->mod->s_opt->greedy) + { + buff = b->p_lk_left; + b->p_lk_left = tree->p_lk_extra_0; + tree->p_lk_extra_0 = buff; + } + else if(b->left->tax) + { + buff = b->p_lk_tip_l; + b->p_lk_tip_l = tree->p_lk_tip_extra_0; + tree->p_lk_tip_extra_0 = buff; + } + } + buff = b->patt_id_left; + b->patt_id_left = tree->patt_id_extra_0; + tree->patt_id_extra_0 = buff; + } + else + { + buff = b->div_post_pred_rght; + b->div_post_pred_rght = tree->div_post_pred_extra_0; + tree->div_post_pred_extra_0 = buff; + + buff = b->sum_scale_rght_cat; + b->sum_scale_rght_cat = tree->sum_scale_cat_extra_0; + tree->sum_scale_cat_extra_0 = buff; + + if(b->rght) + { + if(!b->rght->tax) + { + buff = b->sum_scale_rght; + b->sum_scale_rght = tree->sum_scale_extra_0; + tree->sum_scale_extra_0 = buff; + } + + if(!b->rght->tax || tree->mod->s_opt->greedy) + { + buff = b->p_lk_rght; + b->p_lk_rght = tree->p_lk_extra_0; + tree->p_lk_extra_0 = buff; + } + else if(b->rght->tax) + { + buff = b->p_lk_tip_r; + b->p_lk_tip_r = tree->p_lk_tip_extra_0; + tree->p_lk_tip_extra_0 = buff; + } + } + buff = b->patt_id_rght; + b->patt_id_rght = tree->patt_id_extra_0; + tree->patt_id_extra_0 = buff; + } } else { - tree->n_root->l[0] = tree->e_root->l / 2.; - tree->n_root->l[1] = tree->e_root->l / 2.; + if(d == b->left) + { + buff = b->div_post_pred_left; + b->div_post_pred_left = tree->div_post_pred_extra_1; + tree->div_post_pred_extra_1 = buff; + + buff = b->sum_scale_left_cat; + b->sum_scale_left_cat = tree->sum_scale_cat_extra_1; + tree->sum_scale_cat_extra_1 = buff; + + if(b->left) + { + if(!b->left->tax) + { + buff = b->sum_scale_left; + b->sum_scale_left = tree->sum_scale_extra_1; + tree->sum_scale_extra_1 = buff; + } + + if(!b->left->tax || tree->mod->s_opt->greedy) + { + buff = b->p_lk_left; + b->p_lk_left = tree->p_lk_extra_1; + tree->p_lk_extra_1 = buff; + } + else if(b->left->tax) + { + buff = b->p_lk_tip_l; + b->p_lk_tip_l = tree->p_lk_tip_extra_1; + tree->p_lk_tip_extra_1 = buff; + } + } + buff = b->patt_id_left; + b->patt_id_left = tree->patt_id_extra_1; + tree->patt_id_extra_1 = buff; + } + else + { + buff = b->div_post_pred_rght; + b->div_post_pred_rght = tree->div_post_pred_extra_1; + tree->div_post_pred_extra_1 = buff; + + buff = b->sum_scale_rght_cat; + b->sum_scale_rght_cat = tree->sum_scale_cat_extra_1; + tree->sum_scale_cat_extra_1 = buff; + + if(b->rght) + { + if(!b->rght->tax) + { + buff = b->sum_scale_rght; + b->sum_scale_rght = tree->sum_scale_extra_1; + tree->sum_scale_extra_1 = buff; + } + + if(!b->rght->tax || tree->mod->s_opt->greedy) + { + buff = b->p_lk_rght; + b->p_lk_rght = tree->p_lk_extra_1; + tree->p_lk_extra_1 = buff; + } + else if(b->rght->tax) + { + buff = b->p_lk_tip_r; + b->p_lk_tip_r = tree->p_lk_tip_extra_1; + tree->p_lk_tip_extra_1 = buff; + } + } + buff = b->patt_id_rght; + b->patt_id_rght = tree->patt_id_extra_1; + tree->patt_id_extra_1 = buff; + } } } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Add_Root(edge *target, arbre *tree) +void Remove_From_Linked_List(t_ll *elem, void *val, t_ll **list) { - printf("\n. Add root on edge %d left = %d right = %d",target->num,target->left->num,target->rght->num); fflush(NULL); - tree->e_root = target; + t_ll *ll; + + if(*list == NULL) return; + + ll = (*list)->head; - /* Create the root node if it does not exist yet */ - if((!tree->n_root) || (tree->n_root->num != 2*tree->n_otu-2)) - { - tree->n_root = (node *)Make_Node_Light(2*tree->n_otu-2); + /* t_node *n = elem ? elem->v : val; */ + + do + { + if((elem && ll == elem) || (val && ll->v == val)) + { + if(ll == (*list)->head && ll != (*list)->tail) + { + // Re-initialise head of list + t_ll *mm,*newhead; + mm = (*list); + newhead = (*list)->head->next; + do { mm->head = newhead; mm = mm->next; } while(mm); + (*list) = (*list)->head; + (*list)->head->prev = NULL; + } + else if(ll != (*list)->head && ll == (*list)->tail) + { + // Re-initialise tail of list + t_ll *mm,*newtail; + mm = (*list); + newtail = (*list)->tail->prev; + do { mm->tail = newtail; mm = mm->next; } while(mm); + (*list)->tail->next = NULL; + } + else if(ll == (*list)->head && ll == (*list)->tail) + { + (*list)->tail = NULL; + (*list)->head = NULL; + (*list)->next = NULL; + (*list)->prev = NULL; + (*list) = NULL; + /* printf("\n. free %p",ll); */ + Free(ll); + return; + } + else + { + ll->prev->next = ll->next; + ll->next->prev = ll->prev; + } + + ll->next = NULL; + ll->prev = NULL; + ll->head = NULL; + ll->tail = NULL; + /* printf("\n. free %p",ll); */ + Free(ll); + return; + } + ll = ll->next; } + while(ll != NULL); +} - /* Set the position of the root */ - tree->n_root->v[0] = tree->e_root->left; - tree->n_root->v[1] = tree->e_root->rght; +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ - tree->n_root->b[0] = tree->e_root; - tree->n_root->b[1] = tree->e_root; +t_ll *Get_List_Of_Reachable_Tips(t_node *a, t_node *d, t_tree *tree) +{ + t_ll *list; + list = NULL; + Get_List_Of_Reachable_Tips_Post(a,d,&list,tree); + return list; +} - if(tree->n_root_pos > -1.0) - { -/* tree->n_root->l[0] = tree->e_root->l * (tree->n_root_pos/(1.+tree->n_root_pos)); */ -/* tree->n_root->l[1] = tree->e_root->l - tree->n_root->l[0]; */ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ - tree->n_root->l[0] = tree->e_root->l * tree->n_root_pos; - tree->n_root->l[1] = tree->e_root->l * (1. - tree->n_root_pos); +void Get_List_Of_Reachable_Tips_Post(t_node *a, t_node *d, t_ll **list, t_tree *tree) +{ + if(d->tax) + { + /* printf("\n. push %d list: %p",d->num,list->head); */ + Push_Bottom_Linked_List(d,list,YES); + return; } else { - tree->n_root->l[0] = tree->e_root->l / 2.; - tree->n_root->l[1] = tree->e_root->l / 2.; - tree->n_root_pos = 0.5; - } + int i; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + Get_List_Of_Reachable_Tips_Post(d,d->v[i],list,tree); + } + } } -/*********************************************************/ -/* Generate a random unrooted tree with 'n_otu' OTUs */ -arbre *Generate_Random_Tree_From_Scratch(int n_otu) +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// tips0: first list of tips. tips1: second list of tips +phydbl Length_Of_Path_Between_List_Of_Tips(t_ll *tips0, t_ll *tips1, matrix *mat) { - arbre *tree; - int *is_available,*list_of_nodes; - int i,node_num,step,n_available; - phydbl curr_tree_height; - phydbl rand_len; - phydbl wanted_tree_length,curr_tree_length; - phydbl *rates; - phydbl stick_prob; - phydbl lim_inf, lim_sup; - - tree = (arbre *)Make_Tree(n_otu); - Init_Tree(tree,tree->n_otu); - Make_All_Tree_Nodes(tree); - Make_All_Tree_Edges(tree); - Make_Tree_Path(tree); - Make_List_Of_Reachable_Tips(tree); - - rates = (phydbl *)mCalloc(100,sizeof(phydbl)); - is_available = (int *)mCalloc(2*tree->n_otu-2,sizeof(int)); - list_of_nodes = (int *)mCalloc(tree->n_otu, sizeof(int)); + phydbl d,n; + t_ll *x, *y; + t_node *nx, *ny; - For(i,tree->n_otu) is_available[i] = 1; - For(i,tree->n_otu) list_of_nodes[i] = i; - For(i,tree->n_otu) - { - tree->noeud[i]->t = .0; - strcpy(tree->noeud[i]->name,"s"); - sprintf(tree->noeud[i]->name+1,"%d",i); - } + d = 0.0; + n = 0; - curr_tree_height = .0; - step = 0; - rand_len = .0; + /* Print_Mat(mat); */ + + // Add all distances between tips in distinct lists + x = tips0->head; do { - node_num = (int)rint(rand()/(phydbl)(RAND_MAX+1.0)*(tree->n_otu-1-step)); - node_num = list_of_nodes[node_num]; - is_available[node_num] = 0; - For(i,tree->n_otu) list_of_nodes[i] = -1; - n_available = 0; - For(i,2*tree->n_otu-2) if(is_available[i]) {list_of_nodes[n_available++] = i;} - - tree->noeud[node_num]->v[0] = tree->noeud[tree->n_otu+step]; - tree->noeud[tree->n_otu+step]->v[1] = tree->noeud[node_num]; - - node_num = (int)rint(rand()/(phydbl)(RAND_MAX+1.0)*(tree->n_otu-2-step)); - node_num = list_of_nodes[node_num]; - is_available[node_num] = 0; - For(i,tree->n_otu) list_of_nodes[i] = -1; - n_available = 0; - For(i,2*tree->n_otu-2) if(is_available[i]) {list_of_nodes[n_available++] = i;} - - tree->noeud[node_num]->v[0] = tree->noeud[tree->n_otu+step]; - tree->noeud[tree->n_otu+step]->v[2] = tree->noeud[node_num]; - - rand_len = rand(); - rand_len /= RAND_MAX; - rand_len = -log(rand_len)/(tree->n_otu-step); - tree->noeud[tree->n_otu+step]->t = curr_tree_height + rand_len; - curr_tree_height += rand_len; + y = tips1->head; + do + { + nx = (t_node *)x->v; + ny = (t_node *)y->v; - is_available[tree->n_otu+step] = 1; - For(i,tree->n_otu) list_of_nodes[i] = -1; - n_available = 0; - For(i,2*tree->n_otu-2) if(is_available[i]) list_of_nodes[n_available++] = i; + d += mat->dist[nx->c_seq->num][ny->c_seq->num]; - step++; - }while(step < tree->n_otu-2); + /* printf("\n. nx: %d ny: %d [%p %p] d: %G", */ + /* nx->c_seq->num, */ + /* ny->c_seq->num, */ + /* x->head, */ + /* y->head, */ + /* mat->dist[nx->c_seq->num][ny->c_seq->num]); fflush(NULL); */ - tree->noeud[list_of_nodes[0]]->v[0] = tree->noeud[list_of_nodes[1]]; - tree->noeud[list_of_nodes[1]]->v[0] = tree->noeud[list_of_nodes[0]]; - - tree->num_curr_branch_available = 0; - Connect_Edges_To_Nodes_Recur(tree->noeud[0],tree->noeud[0]->v[0],tree); - Add_Root(tree->noeud[list_of_nodes[0]]->b[0],tree); - rand_len = rand(); - rand_len /= RAND_MAX; - rand_len = -log(rand_len)/2; - tree->n_root->t = curr_tree_height + rand_len; - Fill_Dir_Table(tree); - Update_Dirs(tree); - MC_Bl_From_T(tree); - - /* Scale branch lengths such that the sum of branch lengths is uniformly - distributed in the [lim_inf,lim_sup] range */ - lim_inf = 2.0; - lim_sup = 30.0; - wanted_tree_length = rand(); - wanted_tree_length /= RAND_MAX; - wanted_tree_length *= (lim_sup - lim_inf); - wanted_tree_length += lim_inf; - - curr_tree_length = .0; - For(i,2*tree->n_otu-3) curr_tree_length += tree->t_edges[i]->l; - For(i,2*tree->n_otu-3) tree->t_edges[i]->l *= wanted_tree_length/curr_tree_length; - - rates[0] = 0.20; - rates[1] = 0.50; - rates[2] = 1.00; - rates[3] = 2.00; - rates[4] = 5.00; - - if(!(tree->e_root->n_labels%BLOCK_LABELS)) Make_New_Edge_Label(tree->e_root); - strcpy(tree->e_root->labels[tree->e_root->n_labels],"ROOT"); - tree->e_root->n_labels++; - if(!(tree->e_root->n_labels%BLOCK_LABELS)) Make_New_Edge_Label(tree->e_root); - strcpy(tree->e_root->labels[tree->e_root->n_labels],"MEDIUM"); - tree->e_root->n_labels++; - - stick_prob = .8; - Random_Lineage_Rates(tree->n_root,tree->n_root->v[0],NULL,stick_prob,rates,2,5,tree); - Random_Lineage_Rates(tree->n_root,tree->n_root->v[1],NULL,stick_prob,rates,2,5,tree); + n++; // number of pairs of tips, each tip in different lists + y = y->next; + } + while(y); + x = x->next; + } + while(x); + + // Remove distances between tips in tips0 + x = tips0->head; + do + { + y = tips0->head; + do + { + nx = (t_node *)x->v; + ny = (t_node *)y->v; + d -= mat->dist[nx->c_seq->num][ny->c_seq->num]; + y = y->next; + } + while(y); + x = x->next; + } + while(x); - tree->n_root = NULL; - tree->e_root = NULL; - tree->print_labels = 1; - printf("\n\n%s\n",Write_Tree(tree)); - tree->print_labels = 0; - printf("\n\n%s\n",Write_Tree(tree)); - Exit("\n"); - Free(is_available); - Free(list_of_nodes); + // Remove distances between tips in tips1 + x = tips1->head; + do + { + y = tips1->head; + do + { + nx = (t_node *)x->v; + ny = (t_node *)y->v; + d -= mat->dist[nx->c_seq->num][ny->c_seq->num]; + y = y->next; + } + while(y); + x = x->next; + } + while(x); - return tree; + return d/(phydbl)n; } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Random_Lineage_Rates(node *a, node *d, edge *b, phydbl stick_prob, phydbl *rates, int curr_rate, int n_rates, arbre *tree) +void Random_Walk_Along_Tree_On_Radius(t_node *a, t_node *d, t_edge *b, phydbl *radius, t_edge **target_edge, t_node **target_nd, phydbl *target_time, t_tree *tree) { - phydbl uni; - int new_rate; - int i; + assert(tree->rates); + + phydbl delta,ta,td,u; + /* printf("\n. a: %d d: %d radius: %G l->v: %G", */ + /* a->num, */ + /* d->num, */ + /* *radius, */ + /* b->l->v); fflush(NULL); */ + + /* if(tree->rates->nd_t[a->num] < tree->rates->nd_t[d->num]) */ + /* { */ + /* printf("\n. a: %d d: %d radius: %f l: %f [%f] -- %f | %f [%d]", */ + /* a->num, */ + /* d->num, */ + /* *radius, */ + /* b->l->v, */ + /* FABS(tree->rates->nd_t[a->num] - tree->rates->nd_t[d->num]) * tree->rates->clock_r * tree->rates->br_r[d->num], */ + /* tree->rates->cur_l[d->num], */ + /* tree->rates->cur_l[a->num], */ + /* b == tree->e_root); fflush(NULL); */ + /* } */ + /* else */ + /* { */ + /* printf("\n. a: %d d: %d radius: %f l: %f [%f] -- %f | %f [%d]", */ + /* a->num, */ + /* d->num, */ + /* *radius, */ + /* b->l->v, */ + /* FABS(tree->rates->nd_t[a->num] - tree->rates->nd_t[d->num]) * tree->rates->clock_r * tree->rates->br_r[a->num], */ + /* tree->rates->cur_l[d->num], */ + /* tree->rates->cur_l[a->num], */ + /* b == tree->e_root); fflush(NULL); */ + /* } */ + + delta = *radius; - if(b) + if(!(delta > 0.0)) { - uni = rand(); - uni /= RAND_MAX; - - if(uni > stick_prob) /* Randomly pick a new rate */ - { - uni = rand(); - uni /= RAND_MAX; - uni = (phydbl)(uni * (n_rates-1)); - if(uni-(int)(uni) > 0.5-MDBL_MAX) new_rate = (int)(uni)+1; - else new_rate = (int)(uni); - } - else - { - new_rate = curr_rate; - } + PhyML_Fprintf(stderr,"\n. delta=%G",delta); + assert(FALSE); + } + + (*radius) -= b->l->v; + if(*radius < 0.0) + { + *target_edge = b; + ta = tree->rates->nd_t[a->num]; + td = tree->rates->nd_t[d->num]; - For(i,3) - if(a->v[i] == d) - { - a->b[i]->l *= rates[new_rate]; - break; - } - - For(i,3) - if(a->v[i] == d) - { - if(!(a->b[i]->n_labels%BLOCK_LABELS)) Make_New_Edge_Label(a->b[i]); - if(rates[new_rate] > 1.0) strcpy(a->b[i]->labels[a->b[i]->n_labels],"FAST"); - else if(rates[new_rate] < 1.0) strcpy(a->b[i]->labels[a->b[i]->n_labels],"SLOW"); - else strcpy(a->b[i]->labels[a->b[i]->n_labels],"MEDIUM"); - a->b[i]->n_labels++; - break; - } - curr_rate = new_rate; + if(b != tree->e_root) + { + if(ta < td) + { + /* *target_time = ta + delta / (tree->rates->clock_r * tree->rates->br_r[d->num]); */ + *target_time = ta + delta / (tree->rates->cur_l[d->num] / fabs(ta-td)); + *target_nd = d; + /* printf("\n$ %G %G", */ + /* tree->rates->clock_r * tree->rates->br_r[d->num], */ + /* tree->rates->cur_l[d->num] / fabs(ta-td)); */ + + /* PhyML_Fprintf(stderr,"\n< ta: %G td: %G new_time: %G delta: %G c: %G r: %G rad: %G l->v: %G cur_l: %G root_edge ? %d", */ + /* ta, */ + /* td, */ + /* *target_time, */ + /* delta, */ + /* tree->rates->clock_r, */ + /* tree->rates->br_r[d->num], */ + /* *radius, */ + /* b->l->v, */ + /* tree->rates->cur_l[d->num], */ + /* b == tree->e_root); */ + + assert(*target_time > ta && *target_time < td); + } + else + { + /* *target_time = ta - delta / (tree->rates->clock_r * tree->rates->br_r[a->num]); */ + *target_time = ta - delta / (tree->rates->cur_l[a->num] / fabs(ta-td)); + *target_nd = a; + /* printf("\nz %G %G", */ + /* tree->rates->clock_r * tree->rates->br_r[a->num], */ + /* tree->rates->cur_l[a->num] / fabs(ta-td)); */ + + /* PhyML_Fprintf(stderr,"\n> ta: %f td: %f new_time: %f delta: %f c: %f r: %f l->v: %G cur_l: %G root_edge ? %d", */ + /* ta, */ + /* td, */ + /* *target_time, */ + /* delta, */ + /* tree->rates->clock_r, */ + /* tree->rates->br_r[a->num], */ + /* b->l->v, */ + /* tree->rates->cur_l[a->num], */ + /* b == tree->e_root); */ + + assert(*target_time < ta && *target_time > td); + } + } + else + { + phydbl t_root = tree->rates->nd_t[tree->n_root->num]; + + // target falls on edge below root leading to node a + if(delta < tree->rates->cur_l[a->num]) + { + /* *target_time = ta - delta / (tree->rates->clock_r * tree->rates->br_r[a->num]); */ + *target_time = ta - delta / (tree->rates->cur_l[a->num] / fabs(t_root-ta)); + *target_nd = a; + /* printf("\nX %G %G",tree->rates->cur_l[a->num] / fabs(t_root-ta),tree->rates->clock_r * tree->rates->br_r[a->num]); */ + /* PhyML_Fprintf(stderr,"\n.. delta: %f l(a): %f time: %f ta: %f",delta,tree->rates->cur_l[a->num],*target_time,ta); */ + } + else + { + u = Uni(); + if(u < .5) + { + // target falls on edge below root leading to node d + /* *target_time = tree->rates->nd_t[tree->n_root->num] + (delta - tree->rates->cur_l[a->num])/(tree->rates->clock_r * tree->rates->br_r[d->num]); */ + *target_time = tree->rates->nd_t[tree->n_root->num] + (delta - tree->rates->cur_l[a->num])/(tree->rates->cur_l[d->num] / fabs(t_root-td)); + *target_nd = d; + /* printf("\nq %G %G", */ + /* tree->rates->clock_r * tree->rates->br_r[d->num], */ + /* tree->rates->cur_l[d->num] / fabs(t_root-td)); */ + /* PhyML_Fprintf(stderr,"\n<< ta: %f td: %f new_time: %f delta: %f c: %f",ta,td,*target_time,delta,tree->rates->clock_r); */ + } + else + { + // target falls above root + *target_time = tree->rates->nd_t[tree->n_root->num] - (delta - tree->rates->cur_l[a->num])/tree->rates->clock_r; + *target_nd = tree->n_root; + /* PhyML_Fprintf(stderr,"\n>> ta: %f td: %f new_time: %f delta: %f c: %f",ta,td,*target_time,delta,tree->rates->clock_r); */ + } + } + } + + return; } - if(d->tax) return; + if(d->tax == YES) return; else - { - For(i,3) - if((d->v[i] != a) && (d->b[i] != tree->e_root)) - Random_Lineage_Rates(d,d->v[i],d->b[i],stick_prob,rates,curr_rate,n_rates,tree); + { + int i,dir1,dir2; + + dir1 = dir2 = -1; + for(i=0;i<3;++i) + if(d->v[i] != a) + { + if(dir1 < 0) dir1 = i; + else dir2 = i; + } + + u = Uni(); + if(u < .5) + Random_Walk_Along_Tree_On_Radius(d,d->v[dir1],d->b[dir1],radius,target_edge,target_nd,target_time,tree); + else + Random_Walk_Along_Tree_On_Radius(d,d->v[dir2],d->b[dir2],radius,target_edge,target_nd,target_time,tree); } } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -edge *Find_Edge_With_Label(char *label, arbre *tree) +void Table_Top(unsigned int width) { - int i,j; + unsigned int i; + PhyML_Printf("\n\t \u256D"); + for(i=0;in_otu-3) - { - For(j,tree->t_edges[i]->n_labels) - { - if(!strcmp(tree->t_edges[i]->labels[j],label)) return tree->t_edges[i]; - } - } - return NULL; +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Table_Row(unsigned int width) +{ + unsigned int i; + /* PhyML_Printf("\n\t \u2502"); */ + PhyML_Printf("\n\t \u251C"); + for(i=0;icurrent_clade_idx = from->current_clade_idx; + to->lower = from->lower; + to->upper = from->upper; + to->is_primary = from->is_primary; + to->clade_list_size = from->clade_list_size; - printf("\n"); - For(i,n) + to->id = (char *)mCalloc(strlen(from->id)+1,sizeof(char)); + strcpy(to->id,from->id); + + to->alpha_proba_list = (phydbl *)mCalloc(from->clade_list_size,sizeof(phydbl)); + to->clade_list = (t_clad **)mCalloc(from->clade_list_size,sizeof(t_clad *)); + + for(i=0;iclade_list_size;++i) { - For(j,n) - { - printf("%.3f ",mat[i*n+j]); - } - printf("\n"); + to->alpha_proba_list[i] = from->alpha_proba_list[i]; + to->clade_list[i] = Duplicate_Clade(from->clade_list[i]); } - printf("\n"); + + return(to); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Evolve(allseq *data, model *mod, arbre *tree) +t_clad *Duplicate_Clade(t_clad *from) { - int root_state, root_rate_class; - int site,i; + int i; + t_clad *to; - if(mod->use_m4mod) tree->print_labels = 1; + to = Make_Clade(); + + to->id = (char *)mCalloc(strlen(from->id)+1,sizeof(char)); + strcpy(to->id,from->id); - /* Get the change probability matrices */ - Set_Model_Parameters(mod); - For(i,2*tree->n_otu-3) Update_PMat_At_Given_Edge(tree->t_edges[i],tree); + to->n_tax = from->n_tax; + to->target_nd = from->target_nd; - For(site,data->init_len) + to->tax_list = (char **)mCalloc(from->n_tax,sizeof(char *)); + to->tip_list = (t_node **)mCalloc(from->n_tax,sizeof(t_node *)); + + for(i=0;in_tax;++i) { - root_state = root_rate_class = -1; + to->tax_list[i] = (char *)mCalloc(strlen(from->tax_list[i])+1,sizeof(char)); + strcpy(to->tax_list[i],from->tax_list[i]); + to->tip_list[i] = from->tip_list[i]; + } + + return to; + } - /* Pick the root nucleotide/aa */ - root_state = Pick_State(mod->ns,mod->pi); - data->c_seq[0]->state[site] = Reciproc_Assign_State(root_state,mod->datatype); +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ - /* Pick the rate class */ - root_rate_class = Pick_State(mod->n_catg,mod->gamma_r_proba); +char *Mutation_Id(int mut_idx, t_tree *tree) +{ + char *s,c; + int ns; - /* tree->noeud[0] is considered as the root node */ - Evolve_Recur(tree->noeud[0], - tree->noeud[0]->v[0], - tree->noeud[0]->b[0], - root_state, - root_rate_class, - site, - data, - mod, - tree); - -/* printf("%s\n",Write_Tree(tree)); */ - - data->wght[site] = 1; + ns = tree->mod->ns; + + s = (char *)mCalloc(20,sizeof(char)); + + /* strcpy(s,"from "); */ + strcpy(s," "); + c = Reciproc_Assign_State((int)(mut_idx/ns),tree->mod->io->datatype); + sprintf(s+strlen(s),"%c",c); + /* strcat(s," to "); */ + strcat(s," "); + c = Reciproc_Assign_State((int)(mut_idx%ns),tree->mod->io->datatype); + sprintf(s+strlen(s),"%c",c); + + return(s); +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void Random_Tax_Idx(t_node *a, t_node *d, int *idx, t_tree *tree) +{ + + if(d->tax == YES) + { + (*idx) = d->num; + return; + } + else + { + for(int i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + Random_Tax_Idx(d,d->v[i],idx,tree); + } + } + } +} + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + +void List_Taxa_In_Clade(t_node *a, t_node *d, t_tree *tree) +{ + if(d->tax == YES) + { + PhyML_Printf("\n- [%50s]",d->name); + } + else + { + for(int i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + List_Taxa_In_Clade(d,d->v[i],tree); + } + } } - data->crunch_len = data->init_len; } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -int Pick_State(int n, phydbl *prob) +void Alias_Subpatt(t_tree *tree) { - int pos; - phydbl uni; - do + if(tree->n_root && tree->ignore_root == NO) { - pos = rand(); - pos = (pos % n); - uni = (phydbl)rand(); - uni /= (phydbl)RAND_MAX; - if(uni < prob[pos]) break; + Alias_Subpatt_Post(tree->n_root,tree->n_root->v[2],tree); + Alias_Subpatt_Post(tree->n_root,tree->n_root->v[1],tree); + } + else + { + Alias_Subpatt_Post(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); + /* if(tree->both_sides) */ + Alias_Subpatt_Pre(tree->a_nodes[0],tree->a_nodes[0]->v[0],tree); } - while(1); - - return (int)pos; } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Evolve_Recur(node *a, node *d, edge *b, int a_state, int r_class, int site_num, allseq *gen_data, model *mod, arbre *tree) +void Alias_One_Subpatt(t_node *a, t_node *d, t_tree *tree) { - int d_state; + int i,j; + int *patt_id_v1, *patt_id_v2, *patt_id_d; + int *p_lk_loc_d, *p_lk_loc_v1, *p_lk_loc_v2; + t_node *v1, *v2; + t_edge *b0, *b1, *b2; + int curr_patt_id_v1, curr_patt_id_v2; + int curr_p_lk_loc_v1, curr_p_lk_loc_v2; + int num_subpatt; - d_state = Pick_State(mod->ns,b->Pij_rr[r_class][a_state]); - -/* printf("\n>> %c (%d,%d)",Reciproc_Assign_State(d_state,mod->datatype),d_state,(int)d_state/mod->m4mod->n_o); */ + b0 = b1 = b2 = NULL; - if(mod->use_m4mod) + if(d->tax) { - phydbl rrate; /* relative rate of substitutions */ - - rrate = mod->m4mod->multipl[(int)d_state/mod->m4mod->n_o]; - if(!(b->n_labels%BLOCK_LABELS)) Make_New_Edge_Label(b); - if(rrate > 1.0) strcpy(b->labels[b->n_labels],"FASTER"); - else strcpy(b->labels[b->n_labels],"SLOWER"); - b->n_labels++; - } + patt_id_d = (d == d->b[0]->left)?(d->b[0]->patt_id_left):(d->b[0]->patt_id_rght); + p_lk_loc_d = (d == d->b[0]->left)?(d->b[0]->p_lk_loc_left):(d->b[0]->p_lk_loc_rght); - if(d->tax) + for(i=0;in_pattern;i++) { - gen_data->c_seq[d->num]->state[site_num] = Reciproc_Assign_State(d_state,mod->datatype); + for(j=0;jn_pattern;j++) + { + if(patt_id_d[i] == patt_id_d[j]) + { + p_lk_loc_d[i] = j; + break; + } + if(j > i) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + } + } return; } else { - int i; - For(i,3) - if(d->v[i] != a) - Evolve_Recur(d,d->v[i],d->b[i], - d_state,r_class,site_num,gen_data, - mod,tree); + v1 = v2 = NULL; + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(!v1) { v1=d->v[i]; b1=d->b[i];} + else { v2=d->v[i]; b2=d->b[i];} + } + else + { + b0 = d->b[i]; + } } -} - -/*********************************************************/ -void Site_Diversity(arbre *tree) -{ - int i,j,k,ns; - int *div,sum; - ns = (tree->mod->datatype == NT)?(4):(20); + patt_id_v1 = (v1 == b1->left)?(b1->patt_id_left):(b1->patt_id_rght); + patt_id_v2 = (v2 == b2->left)?(b2->patt_id_left):(b2->patt_id_rght); + patt_id_d = (d == b0->left)?(b0->patt_id_left):(b0->patt_id_rght); + p_lk_loc_d = (d == b0->left)?(b0->p_lk_loc_left):(b0->p_lk_loc_rght); + p_lk_loc_v1 = (v1 == b1->left)?(b1->p_lk_loc_left):(b1->p_lk_loc_rght); + p_lk_loc_v2 = (v2 == b2->left)?(b2->p_lk_loc_left):(b2->p_lk_loc_rght); - div = (int *)mCalloc(ns,sizeof(int)); + num_subpatt = 0; + for(i=0;in_pattern;i++) + { + curr_patt_id_v1 = patt_id_v1[i]; + curr_patt_id_v2 = patt_id_v2[i]; + curr_p_lk_loc_v1 = p_lk_loc_v1[i]; + curr_p_lk_loc_v2 = p_lk_loc_v2[i]; - Site_Diversity_Post(tree->noeud[0],tree->noeud[0]->v[0],tree->noeud[0]->b[0],tree); - Site_Diversity_Pre (tree->noeud[0],tree->noeud[0]->v[0],tree->noeud[0]->b[0],tree); + p_lk_loc_d[i] = i; - For(i,2*tree->n_otu-3) - { - For(j,ns) - { - tree->t_edges[i]->div_post_pred_left[j] = 0; - tree->t_edges[i]->div_post_pred_rght[j] = 0; - } + if((curr_p_lk_loc_v1 == i) || (curr_p_lk_loc_v2 == i)) + { + p_lk_loc_d[i] = i; + patt_id_d[i] = num_subpatt; + num_subpatt++; + } + else + if(curr_p_lk_loc_v1 == curr_p_lk_loc_v2) + { + p_lk_loc_d[i] = curr_p_lk_loc_v1; + patt_id_d[i] = patt_id_d[curr_p_lk_loc_v1]; + } + else + { + for(j=MAX(curr_p_lk_loc_v1,curr_p_lk_loc_v2);jn_pattern;j++) + { + if((patt_id_v1[j] == curr_patt_id_v1) && + (patt_id_v2[j] == curr_patt_id_v2)) + { + p_lk_loc_d[i] = j; + + if(j == i) + { + patt_id_d[i] = num_subpatt; + num_subpatt++; + } + else patt_id_d[i] = patt_id_d[j]; + break; + } + if(j > i) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n\n",__FILE__,__LINE__); + Warn_And_Exit(""); + } + } + } } - - For(i,tree->n_pattern) - { - For(j,2*tree->n_otu-3) - { - Binary_Decomposition(tree->t_edges[j]->ui_l[i],div,ns); - sum = 0; - For(k,ns) sum += div[k]; - tree->t_edges[j]->div_post_pred_left[sum-1] += tree->data->wght[i]; - - Binary_Decomposition(tree->t_edges[j]->ui_r[i],div,ns); - sum = 0; - For(k,ns) sum += div[k]; - tree->t_edges[j]->div_post_pred_rght[sum-1] += tree->data->wght[i]; - } } - -/* For(j,2*tree->n_otu-3) */ -/* { */ -/* printf("\n. Edge %4d div_left = %4d %4d %4d %4d -- div_rght = %4d %4d %4d %4d", */ -/* j, */ -/* tree->t_edges[j]->div_post_pred_left[0], */ -/* tree->t_edges[j]->div_post_pred_left[1], */ -/* tree->t_edges[j]->div_post_pred_left[2], */ -/* tree->t_edges[j]->div_post_pred_left[3], */ -/* tree->t_edges[j]->div_post_pred_rght[0], */ -/* tree->t_edges[j]->div_post_pred_rght[1], */ -/* tree->t_edges[j]->div_post_pred_rght[2], */ -/* tree->t_edges[j]->div_post_pred_rght[3]); */ -/* } */ - - Free(div); } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Site_Diversity_Post(node *a, node *d, edge *b, arbre *tree) +void Alias_Subpatt_Post(t_node *a, t_node *d, t_tree *tree) { + if(d->tax) return; else { int i; - For(i,3) - if(d->v[i] != a) - Site_Diversity_Post(d,d->v[i],d->b[i],tree); - - Subtree_Union(d,b,tree); + for(i=0;i<3;i++) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + Alias_Subpatt_Post(d,d->v[i],tree); + } + } + Alias_One_Subpatt(a, d, tree); } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Site_Diversity_Pre(node *a, node *d, edge *b, arbre *tree) +void Alias_Subpatt_Pre(t_node *a, t_node *d, t_tree *tree) { if(d->tax) return; else { int i; - For(i,3) - if(d->v[i] != a) - { - Subtree_Union(d,d->b[i],tree); - Site_Diversity_Pre(d,d->v[i],d->b[i],tree); - } + for(i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + Alias_One_Subpatt(d->v[i],d,tree); + Alias_Subpatt_Pre(d,d->v[i],tree); + } + } } } -/*********************************************************/ +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// -void Subtree_Union(node *n, edge *b_fcus, arbre *tree) +char Integer_To_IUPAC_Code(int x) { -/* - | - |<- b_cus - | - n - / \ - / \ - / \ -*/ - - int site; - unsigned int *ui, *ui_v1, *ui_v2; + char c; - ui = ui_v1 = ui_v2 = NULL; - - if(n == b_fcus->left) - { - ui = b_fcus->ui_l; - - ui_v1 = - (n == n->b[b_fcus->l_v1]->left)? - (n->b[b_fcus->l_v1]->ui_r): - (n->b[b_fcus->l_v1]->ui_l); - - ui_v2 = - (n == n->b[b_fcus->l_v2]->left)? - (n->b[b_fcus->l_v2]->ui_r): - (n->b[b_fcus->l_v2]->ui_l); - } - else + switch(x) { - ui = b_fcus->ui_r; + case 0: + { + assert(FALSE); + break; + } + case 1: + { + c = 'A'; + break; + } + case 2: + { + c = 'C'; + break; + } + case 3: + { + c = 'M'; + break; + } + case 4: + { + c = 'G'; + break; + } + case 5: + { + c = 'R'; + break; + } + case 6: + { + c = 'S'; + break; + } + case 7: + { + c = 'V'; + break; + } + case 8: + { + c = 'T'; + break; + } + case 9: + { + c = 'W'; + break; + } + case 10: + { + c = 'Y'; + break; + } + case 11: + { + c = 'H'; + break; + } + case 12: + { + c = 'K'; + break; + } + case 13: + { + c = 'D'; + break; + } + case 14: + { + c = 'B'; + break; + } + case 15: + { + c = 'N'; + break; + } - ui_v1 = - (n == n->b[b_fcus->r_v1]->left)? - (n->b[b_fcus->r_v1]->ui_r): - (n->b[b_fcus->r_v1]->ui_l); - - ui_v2 = - (n == n->b[b_fcus->r_v2]->left)? - (n->b[b_fcus->r_v2]->ui_r): - (n->b[b_fcus->r_v2]->ui_l); + default : assert(FALSE); } - For(site,tree->n_pattern) ui[site] = ui_v1[site] | ui_v2[site]; + return(c); } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Binary_Decomposition(int value, int *bit_vect, int size) +int *Integer_To_Bit(int val, const int ns) { - int i,cumul; + assert(ns > 0); + + int *res; + unsigned int mask = 1U << (ns-1); + int i; - For(i,size) bit_vect[i] = 0; + res = (int *)mCalloc(ns,sizeof(int)); - cumul = 0; - for(i=size-1;i>=0;i--) + for(i=0;imod->datatype == NT)?(4):(20); - - Print_Diversity_Pre(tree->noeud[0], - tree->noeud[0]->v[0], - tree->noeud[0]->b[0], - fp, - tree); + for(j=0;jlen;++j) + { + u = Uni(); + if(u < prop) + { + for(i=0;istate[j]; + data[i]->state[j] = data[rand_otu]->state[j]; + data[rand_otu]->state[j] = c; + + } + } + } +} -/* mean_div_left = .0; */ -/* For(k,ns) */ -/* { */ -/* mean_div_left += (k+1) * tree->t_edges[j]->div_post_pred_left[k]; */ -/* } */ -/* mean_div_rght = .0; */ -/* For(k,ns) mean_div_rght += (k+1) * tree->t_edges[j]->div_post_pred_rght[k]; */ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -/* mean_div_left /= (phydbl)tree->data->init_len; */ -/* mean_div_rght /= (phydbl)tree->data->init_len; */ +phydbl Tree_Height(t_tree *tree) +{ + phydbl h; + t_node *n,*anc; + int i; + assert(tree->n_root != NULL); -/* fprintf(fp,"%4d 0 %f\n",j,mean_div_left); */ -/* fprintf(fp,"%4d 1 %f\n",j,mean_div_rght); */ + h = 0; + n = tree->n_root; + anc = NULL; + + assert(n->tax == NO); + do + { + for(i=0;i<3;++i) + { + if(n->v[i] && n->v[i] != anc && n->b[i] != tree->e_root) + { + h += n->b[i]->l->v; + break; + } + } + + anc = n; + n = n->v[i]; + } + while(n->tax == NO); -/* mean_div_left = .0; */ -/* For(k,ns) mean_div_left += tree->t_edges[j]->div_post_pred_left[k]; */ + return h; +} -/* mean_div_rght = .0; */ -/* For(k,ns) */ -/* { */ -/* mean_div_rght += tree->t_edges[j]->div_post_pred_rght[k]; */ -/* } */ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Adjust node ages so that every edge in tree has length > min_l. Assume strict + molecular clock +*/ +void Inflate_Times_To_Get_Reasonnable_Edge_Lengths(phydbl min_l, t_tree *tree) +{ + phydbl l1,l2; + + Post_Inflate_Times_To_Get_Reasonnable_Edge_Lengths(tree->n_root,tree->n_root->v[1],tree->n_root->b[1],min_l,tree); + Post_Inflate_Times_To_Get_Reasonnable_Edge_Lengths(tree->n_root,tree->n_root->v[2],tree->n_root->b[2],min_l,tree); -/* if((mean_div_left != tree->data->init_len) || (mean_div_rght != tree->data->init_len)) */ -/* { */ -/* printf("\n. mean_div_left = %f mean_div_rght = %f init_len = %d", */ -/* mean_div_left,mean_div_rght,tree->data->init_len); */ -/* printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); */ -/* Warn_And_Exit(""); */ -/* } */ + l1 = (tree->rates->nd_t[tree->n_root->v[1]->num] - tree->rates->nd_t[tree->n_root->num]) * tree->rates->clock_r; + l2 = (tree->rates->nd_t[tree->n_root->v[2]->num] - tree->rates->nd_t[tree->n_root->num]) * tree->rates->clock_r; + + if(MIN(l1,l2) < min_l) + { + tree->rates->nd_t[tree->n_root->num] = -(min_l / tree->rates->clock_r - + MIN(tree->rates->nd_t[tree->n_root->v[1]->num], + tree->rates->nd_t[tree->n_root->v[2]->num])); + } } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -void Print_Diversity_Pre(node *a, node *d, edge *b, FILE *fp, arbre *tree) +void Post_Inflate_Times_To_Get_Reasonnable_Edge_Lengths(t_node *a, t_node *d, t_edge *b, phydbl min_l, t_tree *tree) { - int k,ns; - - - if(d->tax) return; + if(d->tax == YES) return; else { - ns = (tree->mod->datatype == NT)?(4):(20); - if(d == b->left) For(k,ns) fprintf(fp,"%4d 0 %2d %4d\n",b->num,k,b->div_post_pred_left[k]); - else For(k,ns) fprintf(fp,"%4d 1 %2d %4d\n",b->num,k,b->div_post_pred_rght[k]); + int i,dir1,dir2; + phydbl l1,l2; - For(k,3) if(d->v[k] != a) Print_Diversity_Pre(d,d->v[k],d->b[k],fp,tree); - } + for(i=0;i<3;++i) + if(d->v[i] != a && d->b[i] != tree->e_root) + Post_Inflate_Times_To_Get_Reasonnable_Edge_Lengths(d,d->v[i],d->b[i],min_l,tree); + + dir1 = dir2 = -1; + for(i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + if(dir1 < 0) dir1 = i; + else dir2 = i; + } + } + + l1 = (tree->rates->nd_t[d->v[dir1]->num] - tree->rates->nd_t[d->num]) * tree->rates->clock_r; + l2 = (tree->rates->nd_t[d->v[dir2]->num] - tree->rates->nd_t[d->num]) * tree->rates->clock_r; + if(MIN(l1,l2) < min_l) + { + tree->rates->nd_t[d->num] = -(min_l / tree->rates->clock_r - MIN(tree->rates->nd_t[d->v[dir1]->num],tree->rates->nd_t[d->v[dir2]->num])); + } + + } + } -/*********************************************************/ -/* Estimation of density using kernel smoothing. -- where : point where I want to estimate the density, -- x : data vector, -- sample_size : number of data points in x +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/* Given an up-to-date values of n->v[i] and n->b[i] for i=0,1,2 + and node n in the tree, this function returns up-to-date values + of a_nodes and a_edges array (whereby a_edges[b->num] = b and + a_nodes[n->num] = n, for all b and n in the tree) and updates + n->num and b->num accordingly. */ -phydbl Univariate_Kernel_Density_Estimate(phydbl where, phydbl *x, int sample_size) +void Refactor_Tree(t_tree *tree) { - phydbl sd,h; - phydbl density,sqrt2pi,cons; - int i; - - sqrt2pi = 2.506628; - - sd = sqrt(Var(x,sample_size)); - h = 1.06 * sd * pow(sample_size,-1./5.); /* Quick and dirty way to set the bandwidth */ + int i,idx_nd,idx_br; - cons = (1./sample_size) * (1./h) * (1./sqrt2pi); - - density = .0; - For(i,sample_size) density += exp(-0.5 * pow((x[i] - where)/h,2)); - density *= cons; + idx_nd = idx_br = 0; + + for(i=0;in_otu;++i) + if(tree->a_nodes[i] != NULL) + { + Refactor_External(tree->a_nodes[i], + tree->a_nodes[i]->v[0], + &idx_nd,tree); + break; + } - return density; + assert(i < tree->n_otu); + assert(idx_nd == tree->n_otu); + idx_br = idx_nd; + + for(i=0;in_otu;++i) + if(tree->a_nodes[i] != NULL) + { + Refactor_Internal(tree->a_nodes[i], + tree->a_nodes[i]->v[0], + tree->a_nodes[i]->b[0], + &idx_nd, + &idx_br, + tree); + break; + } } -/*********************************************************/ - -/* Estimation of a multivariate density using kernel smoothing. -- where : vector where I want to estimate the density, -- x : data matrix, i.e., sample of vectors, -- sample_size : number of vectors, -- vect_size : vector length. +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -See "Multivariate Density Estimation" by David Scott. pp 150. -*/ -phydbl Multivariate_Kernel_Density_Estimate(phydbl *where, phydbl **x, int sample_size, int vect_size) +void Refactor_External(t_node *a, t_node *d, int *idx, t_tree *tree) { - phydbl sd,*h,cons,density,tmp; - phydbl _2pi; - int i,j; - h = (phydbl *)mCalloc(vect_size,sizeof(phydbl)); + if(a->tax == YES) + { + tree->a_nodes[*idx] = a; + tree->a_edges[*idx] = a->b[0]; + a->num = *idx; + a->b[0]->num = *idx; + (*idx)+=1; + } - _2pi = 6.283185; - - For(i,vect_size) + if(d->tax == YES) { - sd = sqrt(Var(x[i],sample_size)); - h[i] = sd * pow(4./((vect_size+2.)*sample_size),1./(vect_size+4)); + tree->a_nodes[*idx] = d; + tree->a_edges[*idx] = d->b[0]; + d->num = *idx; + d->b[0]->num = *idx; + (*idx)+=1; + return; } - - cons = sample_size; - For(i,vect_size) cons *= h[i]; - cons *= pow(_2pi,vect_size/2.); - cons = 1./cons; - - density = .0; - For(i,sample_size) + else { - tmp = 1.0; - For(j,vect_size) tmp *= exp(-0.5 * pow((x[j][i] - where[j])/h[j],2)); - density += tmp; + for(int i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + Refactor_External(d,d->v[i],idx,tree); + } + } } - - density *= cons; - - Free(h); - - return density; } -/*********************************************************/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ -phydbl Var(phydbl *x, int n) +void Refactor_Internal(t_node *a, t_node *d, t_edge *b, int *idx_nd, int *idx_br, t_tree *tree) { - phydbl mean, sum2; - int i; - - mean = Mean(x,n); + if(d->tax == YES) return; + else + { + tree->a_nodes[*idx_nd] = d; + d->num = *idx_nd; + (*idx_nd)+=1; - sum2 = .0; - For(i,n) sum2 += pow(x[i],2); - - return (1./n) * (sum2 - n * pow(mean,2)); + if(a->tax == NO) // b is an external edge + { + tree->a_edges[*idx_br] = b; + b->num = *idx_br; + (*idx_br)+=1; + } + + for(int i=0;i<3;++i) + { + if(d->v[i] != a && d->b[i] != tree->e_root) + { + Refactor_Internal(d,d->v[i],d->b[i],idx_nd,idx_br,tree); + } + } + } } -/*********************************************************/ - -phydbl Mean(phydbl *x, int n) +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +// Haversine distance between (lon1,lat1) and (lon2,lat2) where +// coordinates are expressed using decimals +phydbl Haversine_Distance(phydbl lon1, phydbl lat1, phydbl lon2, phydbl lat2) { - int i; - phydbl sum; - sum = .0; + phydbl R = 6371.; // Earth radius, in km + phydbl a,b; + + lon1 = lon1 * PI / 180.; + lat1 = lat1 * PI / 180.; + + lon2 = lon2 * PI / 180.; + lat2 = lat2 * PI / 180.; + + a = pow(sin(.5*(lat2-lat1)),2); + a += cos(lat1)*cos(lat2)*pow(sin(.5*(lon2-lon1)),2); - For(i,n) sum += x[i]; + b = 2.*atan2(sqrt(a),sqrt(1.-a)); - return sum / n; + return(R * b); } -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ + +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ +/*//////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////*/ + diff --git a/phyml/utilities.h b/phyml/utilities.h index 717b12f..277cbe9 100644 --- a/phyml/utilities.h +++ b/phyml/utilities.h @@ -10,42 +10,236 @@ the GNU public licence. See http://www.opensource.org for details. */ +#include + #ifndef UTILITIES_H #define UTILITIES_H +#define _POSIX_C_SOURCE 200112L #include +#include #include #include #include #include #include +#include +#include +#include +#include +#include +#include +/* #include */ +/* #include */ + +#if (defined(__AVX__)) +#include +#include +#include +#elif (defined(__SSE3__)) +#include +#include +#endif + + +#if !defined(__FMA__) && defined(__AVX2__) + #define __FMA__ 1 +#endif +extern int n_sec1; +extern int n_sec2; -/* wash. renamed VERSION to VVERSION because of name clash*/ -#define VVERSION "v3.0" +#define __FUNCTION__ NULL #define For(i,n) for(i=0; i(b)?(a):(b)) -#define MIN(a,b) ((a)<(b)?(a):(b)) #define SIGN(a,b) ((b) > 0.0 ? fabs(a) : -fabs(a)) #define SHFT(a,b,c,d) (a)=(b);(b)=(c);(c)=(d); -#define NNI_MOVE 0 -#define SPR_MOVE 1 +#ifndef MAX +#define MAX(a,b) ((a)>(b)?(a):(b)) +#endif + +#ifndef MIN +#define MIN(a,b) ((a)<(b)?(a):(b)) +#endif + +#define READ 0 +#define WRITE 1 +#define APPEND 2 +#define READWRITE 3 + +#ifndef isnan +# define isnan(x) \ + (sizeof (x) == sizeof (long double) ? isnan_ld (x) \ + : sizeof (x) == sizeof (double) ? isnan_d (x) \ + : isnan_f (x)) +static inline int isnan_f (float x) { return x != x; } +static inline int isnan_d (double x) { return x != x; } +static inline int isnan_ld (long double x) { return x != x; } +#endif + +#ifndef isinf +# define isinf(x) \ + (sizeof (x) == sizeof (long double) ? isinf_ld (x) \ + : sizeof (x) == sizeof (double) ? isinf_d (x) \ + : isinf_f (x)) +static inline int isinf_f (float x) { return isnan (x - x); } +static inline int isinf_d (double x) { return isnan (x - x); } +static inline int isinf_ld (long double x) { return isnan (x - x); } +#endif + + +int CALL; +int TIME; + +#define AC 0 +#define AG 1 +#define AT 2 +#define CG 3 +#define CT 4 +#define GT 5 + +#if (defined __AVX__) +#define BYTE_ALIGN 32 +#elif (defined __SSE3__) +#define BYTE_ALIGN 16 +#else +#define BYTE_ALIGN 1 +#endif + +#ifndef M_1_SQRT_2PI +#define M_1_SQRT_2PI 0.398942280401432677939946059934 /* 1/sqrt(2pi) */ +#endif + +// verbose levels +#define VL0 0 +#define VL1 1 +#define VL2 2 +#define VL3 3 +#define VL4 4 + +#define T_MAX_MCMC_MOVE_NAME 500 + +#define WINDOW_WIDTH 800 +#define WINDOW_HEIGHT 800 + +#define ALPHA_MIN 0.01 +#define ALPHA_MAX 1000. + +#define E_FRQ_WEIGHT_MIN 0.01 +#define E_FRQ_WEIGHT_MAX 100. + +#define R_MAT_WEIGHT_MIN 0.01 +#define R_MAT_WEIGHT_MAX 100. + +#define E_FRQ_MIN 0.01 +#define E_FRQ_MAX 0.99 +#define UNSCALED_E_FRQ_MIN -1000. +#define UNSCALED_E_FRQ_MAX +10. + + +#define TSTV_MIN 0.05 +#define TSTV_MAX 20.0 + +#define PINV_MIN 0.00001 +#define PINV_MAX 0.99999 + +#define RR_MIN 0.01 +#define RR_MAX 100.0 + +#define UNSCALED_RR_MIN log(RR_MIN) +#define UNSCALED_RR_MAX log(RR_MAX) + + +#define GAMMA_RR_UNSCALED_MIN 0.01 +#define GAMMA_RR_UNSCALED_MAX 200. + +#define GAMMA_R_PROBA_UNSCALED_MIN 0.01 +#define GAMMA_R_PROBA_UNSCALED_MAX 200. + +#define PHYREX_UNIFORM 0 +#define PHYREX_NORMAL 1 + +#define MCMC_MOVE_RANDWALK_UNIFORM 0 +#define MCMC_MOVE_LOG_RANDWALK_UNIFORM 1 +#define MCMC_MOVE_RANDWALK_NORMAL 2 +#define MCMC_MOVE_LOG_RANDWALK_NORMAL 3 +#define MCMC_MOVE_SCALE_THORNE 4 +#define MCMC_MOVE_SCALE_GAMMA 5 + +#define N_MAX_MOVES 50 + +#define N_MAX_NEX_COM 20 +#define T_MAX_NEX_COM 100 +#define N_MAX_NEX_PARM 50 +#define T_MAX_TOKEN 200 +#define T_MAX_ID_COORD 10 +#define T_MAX_ID_DISK 10 +#define T_MAX_KEY 200 +#define T_MAX_VAL 1000 + + +#define N_MAX_MIXT_CLASSES 1000 + +#define NEXUS_COM 0 +#define NEXUS_PARM 1 +#define NEXUS_EQUAL 2 +#define NEXUS_VALUE 3 +#define NEXUS_SPACE 4 + +#define NNI_MOVE 0 +#define SPR_MOVE 1 +#define BEST_OF_NNI_AND_SPR 2 + +#define M_1_SQRT_2_PI 0.398942280401432677939946059934 +#define M_SQRT_32 5.656854249492380195206754896838 +#define PI 3.14159265358979311600 +#define SQRT2PI 2.50662827463100024161 +#define LOG2PI 1.83787706640934533908 +#define LOG2 0.69314718055994528623 +#define LOG_SQRT_2_PI 0.918938533204672741780329736406 + +#define NORMAL 1 +#define EXACT 2 + +#define PHYLIP 0 +#define NEXUS 1 +#define IBDSIM 2 + +#ifndef YES #define YES 1 +#endif + +#ifndef NO #define NO 0 +#endif -#define NT 0 /* nucleotides */ -#define AA 1 /* amino acids */ +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#define ON 1 +#define OFF 0 -#define ACGT 0 /* A,G,G,T encoding */ -#define RY 1 /* R,Y encoding */ +#define SMALL_DBL 1.E-20 + +#define NT 0 /*! nucleotides */ +#define AA 1 /*! amino acids */ +#define GENERIC 2 /*! custom alphabet */ +#define UNDEFINED -1 + +#define ACGT 0 /*! A,G,G,T encoding */ +#define RY 1 /*! R,Y encoding */ #define INTERFACE_DATA_TYPE 0 #define INTERFACE_MULTIGENE 1 @@ -53,53 +247,64 @@ the GNU public licence. See http://www.opensource.org for details. #define INTERFACE_TOPO_SEARCH 3 #define INTERFACE_BRANCH_SUPPORT 4 +#define LEFT 0 +#define RGHT 1 -#define N_MAX_OPTIONS 100 +#ifndef INFINITY +#define INFINITY HUGE +#endif -#define T_MAX_FILE 100 +#define MAX_N_CAL 100 +#define N_MAX_OPTIONS 100 + +#define NEXT_BLOCK_SIZE 50 + +#define T_MAX_FILE 200 #define T_MAX_LINE 2000000 -#define T_MAX_NAME 100 +#define T_MAX_NAME 1000 +#define T_MAX_ID 20 #define T_MAX_SEQ 2000000 #define T_MAX_OPTION 100 -#define T_MAX_LABEL 10 -#define N_MAX_LABEL 10 -#define BLOCK_LABELS 100 +#define T_MAX_STATE 5 -#define NODE_DEG_MAX 50 -#define BRENT_ITMAX 10000 +#define NODE_DEG_MAX 2000 +#define BRENT_IT_MAX 1000 #define BRENT_CGOLD 0.3819660 #define BRENT_ZEPS 1.e-10 #define MNBRAK_GOLD 1.618034 #define MNBRAK_GLIMIT 100.0 #define MNBRAK_TINY 1.e-20 -#define ALPHA_MIN 0.04 -#define ALPHA_MAX 100 -#define BL_MIN 1.e-06 #define BL_START 1.e-04 -#define BL_MAX 100.0 #define GOLDEN_R 0.61803399 #define GOLDEN_C (1.0-GOLDEN_R) #define N_MAX_INSERT 20 #define N_MAX_OTU 4000 -#define UNLIKELY -1.e10 +#define UNLIKELY -1.e20 #define NJ_SEUIL 0.1 #define ROUND_MAX 100 #define DIST_MAX 2.00 +#define DIST_MIN 1.e-10 #define AROUND_LK 50.0 #define PROP_STEP 1.0 -#define T_MAX_ALPHABET 100 -#define MDBL_MIN 2.225074E-308 -#define MDBL_MAX 1.797693E+308 +#define T_MAX_ALPHABET 22 +#define MDBL_MIN FLT_MIN +#define MDBL_MAX FLT_MAX #define POWELL_ITMAX 200 #define LINMIN_TOL 2.0E-04 -#define LIM_SCALE 3 -#define LIM_SCALE_VAL 1.E-50 -/* #define LIM_SCALE 3000 */ -/* #define LIM_SCALE_VAL 1.E-500 */ -#define DEFAULT_SIZE_SPR_LIST 20 -#define OUTPUT_TREE_FORMAT 0 /* 0-->Newick; 1-->Nexus */ -#define MAX_PARS 1000000000 +#define SCALE_POW 10 /*! Scaling factor will be 2^SCALE_POW or 2^(-SCALE_POW) [[ WARNING: SCALE_POW < 31 ]]*/ +#define DEFAULT_SIZE_SPR_LIST 20 +#define NEWICK 0 +#define NEXUS 1 +#define OUTPUT_TREE_FORMAT NEWICK +#define MAX_PARS 1000000000 + +#define LIM_SCALE_VAL 1.E-50 /*! Scaling limit (deprecated) */ + +#define MIN_CLOCK_RATE 1.E-10 + +#define MIN_VAR_BL 1.E-8 +#define MAX_VAR_BL 1.E+3 #define JC69 1 #define K80 2 @@ -123,38 +328,250 @@ the GNU public licence. See http://www.opensource.org for details. #define MTART 21 #define HIVW 22 #define HIVB 23 -#define CUSTOMAA 24 -#define LG 25 - +#define FLU 24 +#define CUSTOMAA 25 +#define LG 26 +#define AB 27 +// Amino acid ordering: +// Ala Arg Asn Asp Cys Gln Glu Gly His Ile Leu Lys Met Phe Pro Ser Thr Trp Tyr Val + +#define COMPOUND_COR 0 +#define COMPOUND_NOCOR 1 +#define EXPONENTIAL 2 +#define LOGNORMAL 3 +#define THORNE 4 +#define GUINDON 5 +#define STRICTCLOCK 6 +#define BIRTHDEATH 7 +#define NONE -1 + +#define ALRTSTAT 1 +#define ALRTCHI2 2 +#define MINALRTCHI2SH 3 +#define SH 4 +#define ABAYES 5 + + +/* /\* Uncomment the lines below to switch to single precision *\/ */ +/* typedef float phydbl; */ +/* #define LOG logf */ +/* #define POW powf */ +/* #define EXP expf */ +/* #define FABS fabsf */ +/* #define SQRT sqrtf */ +/* #define CEIL ceilf */ +/* #define FLOOR floorf */ +/* #define RINT rintf */ +/* #define ROUND roundf */ +/* #define TRUNC truncf */ +/* #define COS cosf */ +/* #define SIN sinf */ +/* #define TAN tanf */ +/* #define SMALL FLT_MIN */ +/* #define BIG FLT_MAX */ +/* #define SMALL_PIJ 1.E-10 */ +/* #define BL_MIN 1.E-5 */ +/* #define P_LK_LIM_INF 2.168404e-19 /\* 2^-62 *\/ */ +/* #define P_LK_LIM_SUP 4.611686e+18 /\* 2^62 *\/ */ + +/* Uncomment the line below to switch to double precision */ typedef double phydbl; +#define LOG log +#define POW pow +#define EXP exp +#define FABS fabs +#define SQRT sqrt +#define CEIL ceil +#define FLOOR floor +#define RINT rint +#define ROUND round +#define TRUNC trunc +#define COS cos +#define SIN sin +#define TAN tan +#define SMALL DBL_MIN +#define BIG DBL_MAX +#define SMALL_PIJ 1.E-100 +#define LOGBIG 690. +#define LOGSMALL -690. + + +#if !(defined PHYTIME) +#define BL_MIN 1.E-8 +#define BL_MAX 100. +#else +#define BL_MIN 1.E-6 +#define BL_MAX 1. +#endif -/*********************************************************/ +// Do *not* change the values below and leave the lines with +// curr_scaler_pow = (int)(-XXX.-LOG(smallest_p_lk))/LOG2; +// as XXX depends on what the value of P_LK_LIM_INF is +#define P_LK_LIM_INF 3.054936e-151 /* 2^-500 */ +#define P_LK_LIM_SUP 3.273391e+150 /* 2^500 */ +/* #define P_LK_LIM_INF 1.499697e-241 /\* 2^-800 *\/ */ +/* #define P_LK_LIM_SUP 6.668014e+240 /\* 2^800 *\/ */ + +/* #define LARGE 100 */ +/* #define TWO_TO_THE_LARGE 1267650600228229401496703205376.0 /\* 2^100 In R : sprintf("%.100f", 2^100)*\/ */ + +/* #define LARGE 200 */ +/* #define TWO_TO_THE_LARGE 1606938044258990275541962092341162602522202993782792835301376.0 /\* 2^200 In R : sprintf("%.100f", 2^256)*\/ */ + +#define LARGE 256 +#define TWO_TO_THE_LARGE 115792089237316195423570985008687907853269984665640564039457584007913129639936.0 /* 2^256 In R : sprintf("%.100f", 2^256)*/ + +/* #define LARGE 128 */ +/* #define TWO_TO_THE_LARGE 340282366920938463463374607431768211456.0 /\* 2^128 In R : sprintf("%.100f", 2^128)*\/ */ + +/* #define LARGE 320 */ +/* #define TWO_TO_THE_LARGE 2135987035920910082395021706169552114602704522356652769947041607822219725780640550022962086936576.0 */ + +#define INV_TWO_TO_THE_LARGE (1./TWO_TO_THE_LARGE) + +#define SCALE_RATE_SPECIFIC 1 +#define SCALE_FAST 2 + +#define SCALENO 0 +#define SCALEYES 1 + +#define T_MAX_XML_TAG 64 + +#define NARGS_SEQ(_1,_2,_3,_4,_5,_6,_7,_8,N,...) N +#define NARGS(...) NARGS_SEQ(__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1) +#define PRIMITIVE_CAT(x, y) x ## y +#define CAT(x, y) PRIMITIVE_CAT(x, y) +#define FOR_EACH(macro, ...) CAT(FOR_EACH_, NARGS(__VA_ARGS__))(macro, __VA_ARGS__) +#define FOR_EACH_1(m, x1) m(x1) +#define FOR_EACH_2(m, x1, x2) m(x1) m(x2) +#define FOR_EACH_3(m, x1, x2, x3) m(x1) m(x2) m(x3) +#define FOR_EACH_4(m, x1, x2, x3, x4) m(x1) m(x2) m(x3) m(x4) +#define FOR_EACH_5(m, x1, x2, x3, x4, x5) m(x1) m(x2) m(x3) m(x4) m(x5) +#define FOR_EACH_6(m, x1, x2, x3, x4, x5, x6) m(x1) m(x2) m(x3) m(x4) m(x5) m(x6) +#define FOR_EACH_7(m, x1, x2, x3, x4, x5, x6, x7) m(x1) m(x2) m(x3) m(x4) m(x5) m(x6) m(x7) +#define FOR_EACH_8(m, x1, x2, x3, x4, x5, x6, x7, x8) m(x1) m(x2) m(x3) m(x4) m(x5) m(x6) m(x7) m(x8) +#define DUMP_EACH_INT(v) fprintf(stderr,"\n\t\tDEBUG:%s:\t\t%s--->%i",__PRETTY_FUNCTION__,#v,(v));fflush(stderr); +#define DUMP_EACH_STRING(v) fprintf(stderr,"\n\t\tDEBUG:%s:\t\t%s--->%s",__PRETTY_FUNCTION__,#v,(v));fflush(stderr); +#define DUMP_EACH_DECIMAL(v) fprintf(stderr,"\n\t\tDEBUG:%s:\t\t%s--->%f",__PRETTY_FUNCTION__,#v,(v));fflush(stderr); +#define DUMP_EACH_SCI(v) fprintf(stderr,"\n\t\tDEBUG:%s:\t\t%s--->%e",__PRETTY_FUNCTION__,#v,(v));fflush(stderr); +#define DUMP_I(...) FOR_EACH(DUMP_EACH_INT, __VA_ARGS__) +#define DUMP_S(...) FOR_EACH(DUMP_EACH_STRING, __VA_ARGS__) +#define DUMP_D(...) FOR_EACH(DUMP_EACH_DECIMAL, __VA_ARGS__) +#define DUMP_E(...) FOR_EACH(DUMP_EACH_SCI, __VA_ARGS__) + +/*!********************************************************/ +// Generic linked list +typedef struct __Generic_LL { + void *v; + struct __Generic_LL *next; + struct __Generic_LL *prev; + struct __Generic_LL *tail; + struct __Generic_LL *head; +}t_ll; + +/*!********************************************************/ + +typedef struct __Scalar_Int { + int v; + struct __Scalar_Int *next; + struct __Scalar_Int *prev; +}scalar_int; + + +/*!********************************************************/ + +typedef struct __Scalar_Dbl { + phydbl v; + bool onoff; + struct __Scalar_Dbl *next; + struct __Scalar_Dbl *prev; +}scalar_dbl; + +/*!********************************************************/ + +typedef struct __Vect_Int { + int *v; + int len; + struct __Vect_Int *next; + struct __Vect_Int *prev; +}vect_int; + + +/*!********************************************************/ + +typedef struct __Vect_Dbl { + phydbl *v; + int len; + struct __Vect_Dbl *next; + struct __Vect_Dbl *prev; +}vect_dbl; + +/*!********************************************************/ + +typedef struct __String { + char *s; + int len; + struct __String *next; + struct __String *prev; +}t_string; + +/*!********************************************************/ typedef struct __Node { - struct __Node **v; /* table of pointers to neighbor nodes. Dimension = 2 x n_otu - 3 */ - struct __Node ***bip_node; /* three lists of pointer to tip nodes. One list for each direction */ - struct __Edge **b; /* table of pointers to neighbor branches */ - struct __Node ***list_of_reachable_tips; /* list of tip nodes that can be reached in each direction from that node */ + struct __Node **v; /*! table of pointers to neighbor nodes. Dimension = 3 */ + struct __Node ***bip_node; /*! three lists of pointer to tip nodes. One list for each direction */ + struct __Edge **b; /*! table of pointers to neighbor branches */ + struct __Node *anc; /*! direct ancestor t_node (for rooted tree only) */ + struct __Node *ext_node; + struct __Node *match_node; + struct __Align *c_seq; /*! corresponding compressed sequence */ + struct __Align *c_seq_anc; /*! corresponding compressed ancestral sequence */ + + + struct __Node *next; /*! tree->a_nodes[i]->next <=> tree->next->a_nodes[i] */ + struct __Node *prev; /*! See above */ + struct __Node *next_mixt; /*! Next mixture tree*/ + struct __Node *prev_mixt; /*! Parent mixture tree */ + struct __Calibration **cal; /*! List of calibration constraints attached to this node */ + struct __Lindisk_Node *ldsk; /*! Used in PhyREX. Lineage/Disk this node corresponds to */ + struct __Node *rk_next; /*! Next node in the list of ranked nodes (from oldest to youngest) */ + struct __Node *rk_prev; /*! Previous node in the list of ranked nodes (from oldest to youngest) */ + struct __Label *label; + + + int *bip_size; /*! Size of each of the three lists from bip_node */ + int num; /*! t_node number */ + int tax; /*! tax = 1 -> external node, else -> internal t_node */ + + char *name; /*! taxon name (if exists) */ + char *ori_name; /*! taxon name (if exists) */ + int n_cal; /*! Number of calibration constraints */ + + phydbl *score; /*! score used in BioNJ to determine the best pair of nodes to agglomerate */ + phydbl dist_to_root; /*! distance to the root t_node */ + + short int common; + phydbl y_rank; + phydbl y_rank_ori; + phydbl y_rank_min; + phydbl y_rank_max; + + int *s_ingrp; /*! does the subtree beneath belong to the ingroup */ + int *s_outgrp; /*! does the subtree beneath belong to the outgroup */ - int *n_of_reachable_tips; /* sizes of the list_of_reachable_tips (in each direction) */ - int *bip_size; /* Size of each of the three lists from bip_node */ - int num; /* node number */ - int tax; /* tax = 1 -> external node, else -> internal node */ - int check_branch; /* check_branch=1 is the corresponding branch is labelled with '*' */ - char ***bip_name; /* three lists of tip node names. One list for each direction */ - char *name; /* taxon name (if exists) */ + int id_rank; /*! order taxa alphabetically and use id_rank to store the ranks */ + int rank; + int rank_max; - phydbl *score; /* score used in BioNJ to determine the best pair of nodes to agglomerate */ - phydbl *l; /* lengths of the (three or one) branche(s) connected this node */ - phydbl dist_to_root; /* distance to the root node */ - phydbl t; /* time stamp associated to that node */ -}node; + struct __Geo_Coord *coord; +}t_node; -/*********************************************************/ + +/*!********************************************************/ typedef struct __Edge { - /* + /*! syntax : (node) [edge] (left_1) . .(right_1) \ (left) (right) / @@ -165,487 +582,826 @@ typedef struct __Edge { */ - struct __Node *left,*rght; /* node on the left/right side of the edge */ - int l_r,r_l,l_v1,l_v2,r_v1,r_v2; - /* these are directions (i.e., 0, 1 or 2): */ - /* l_r (left to right) -> left[b_fcus->l_r] = right */ - /* r_l (right to left) -> right[b_fcus->r_l] = left */ - /* l_v1 (left node to first node != from right) -> left[b_fcus->l_v1] = left_1 */ - /* l_v2 (left node to secnd node != from right) -> left[b_fcus->l_v2] = left_2 */ - /* r_v1 (right node to first node != from left) -> right[b_fcus->r_v1] = right_1 */ - /* r_v2 (right node to secnd node != from left) -> right[b_fcus->r_v2] = right_2 */ + struct __Node *left,*rght; /*! t_node on the left/right side of the t_edge */ + short int l_r,r_l,l_v1,l_v2,r_v1,r_v2; + /*! these are directions (i.e., 0, 1 or 2): */ + /*! l_r (left to right) -> left[b_fcus->l_r] = right */ + /*! r_l (right to left) -> right[b_fcus->r_l] = left */ + /*! l_v1 (left t_node to first t_node != from right) -> left[b_fcus->l_v1] = left_1 */ + /*! l_v2 (left t_node to secnd t_node != from right) -> left[b_fcus->l_v2] = left_2 */ + /*! r_v1 (right t_node to first t_node != from left) -> right[b_fcus->r_v1] = right_1 */ + /*! r_v2 (right t_node to secnd t_node != from left) -> right[b_fcus->r_v2] = right_2 */ struct __NNI *nni; + struct __Edge *next; + struct __Edge *prev; + struct __Edge *next_mixt; + struct __Edge *prev_mixt; + struct __Label *label; + + int num; /*! branch number */ + scalar_dbl *l; /*! branch length */ + scalar_dbl *best_l; /*! best branch length found so far */ + scalar_dbl *l_old; /*! old branch length */ + scalar_dbl *l_var; /*! variance of edge length */ + scalar_dbl *l_var_old; /*! variance of edge length (previous value) */ + + + int bip_score; /*! score of the bipartition generated by the corresponding edge + bip_score = 1 iif the branch is found in both trees to be compared, + bip_score = 0 otherwise. */ + phydbl tdist_score; /*! average transfer distance over bootstrap trees */ + + int num_st_left; /*! number of the subtree on the left side */ + int num_st_rght; /*! number of the subtree on the right side */ + + phydbl *Pij_rr; /*! matrix of change probabilities and its first and secnd derivates (rate*state*state) */ + phydbl *tPij_rr; /*! transpose matrix of change probabilities and its first and secnd derivates (rate*state*state) */ +#ifdef BEAGLE + int Pij_rr_idx; +#endif + short int *div_post_pred_left; /*! posterior prediction of nucleotide/aa diversity (left-hand subtree) */ + short int *div_post_pred_rght; /*! posterior prediction of nucleotide/aa diversity (rght-hand subtree) */ + short int does_exist; - int num; /* branch number */ - phydbl l; /* branch length */ - phydbl best_l; /* best branch length found so far */ - phydbl l_old; /* old branch length */ - int bip_score; /* score of the bipartition generated by the corresponding edge - bip_score = 1 iif the branch is fond in both trees to be compared, - bip_score = 0 otherwise. */ - phydbl ***p_lk_left,***p_lk_rght; /* likelihoods of the subtree on the left and - right side (for each site and each relative rate category) */ - short int **p_lk_tip_r,**p_lk_tip_l; - short int *div_post_pred_left; /* posterior prediction of nucleotide/aa diversity (left-hand subtree) */ - short int *div_post_pred_rght; /* posterior prediction of nucleotide/aa diversity (rght-hand subtree) */ + phydbl *p_lk_left,*p_lk_rght; /*! likelihoods of the subtree on the left and right side (for each site and each relative rate category) */ + phydbl *p_lk_tip_r, *p_lk_tip_l; - double ***Pij_rr; /* matrix of change probabilities and its first and secnd derivates */ - int *pars_l,*pars_r; /* parsimony of the subtree on the left and right sides (for each site) */ - unsigned int *ui_l, *ui_r; /* union - intersection vectors used in Fitch's parsimony algorithm */ - int **p_pars_l, **p_pars_r; /* conditional parsimony vectors */ - int num_st_left; /* number of the subtree on the left side */ - int num_st_rght; /* number of the subtree on the right side */ +#ifdef BEAGLE + int p_lk_left_idx, p_lk_rght_idx; + int p_lk_tip_idx; +#endif + int *patt_id_left; + int *patt_id_rght; + int *p_lk_loc_left; + int *p_lk_loc_rght; - /* Below are the likelihood scaling factors (used in functions - `Get_All_Partial_Lk_Scale' in lk.c */ - int scale_left; - int scale_rght; - phydbl *sum_scale_f_left; - phydbl *sum_scale_f_rght; + int *pars_l,*pars_r; /*! parsimony of the subtree on the left and right sides (for each site) */ + int *ui_l, *ui_r; /*! union - intersection vectors used in Fitch's parsimony algorithm */ + int *p_pars_l, *p_pars_r; /*! conditional parsimony vectors */ - phydbl bootval; /* bootstrap value (if exists) */ + /*! Below are the likelihood scaling factors (used in functions + `Get_All_Partial_Lk_Scale' in lk.c. */ + /* + For every site, every subtree and every rate class, PhyML maintains a`sum_scale_pow' value + where sum_scale_pow = sum_scale_pow_v1 + sum_scale_pow_v2 + curr_scale_pow' + sum_scale_pow_v1 and sum_scale_pow_v2 are sum_scale_pow of the left and + right subtrees. curr_scale_pow is an integer greater than one. + The smaller the partials, the larger curr_scale_pow. + + Now the partials for this subtree are scaled by *multiplying* each of + them by 2^curr_scale_pow. The reason for doing the scaling this way is + that multiplications by 2^x (x an integer) can be done in an 'exact' + manner (i.e., there is no loss of numerical precision) + + At the root edge, the log-likelihood is then + logL = logL' - (sum_scale_pow_left + sum_scale_pow_right)log(2), + where L' is the scaled likelihood. + */ + + int *sum_scale_left_cat; + int *sum_scale_rght_cat; + int *sum_scale_left; + int *sum_scale_rght; - short int is_alive; /* is_alive = 1 if this edge is used in a tree */ + phydbl bootval; /*! bootstrap value (if exists) */ + + short int is_alive; /*! is_alive = 1 if this t_edge is used in a tree */ phydbl dist_btw_edges; int topo_dist_btw_edges; int has_zero_br_len; - phydbl ratio_test; /* approximate likelihood ratio test */ - phydbl alrt_statistic; /* aLRT statistic */ - int num_tax_left, num_tax_rght; /* number of taxa in subtrees */ - phydbl avg_dist_left, avg_dist_rght; /* average taxon distance in subtrees */ - - int is_p_lk_l_u2d; /* is the conditional likelihood vector on the left up - to data ? */ - int is_p_lk_r_u2d; /* is the conditional likelihood vector on the right up - to data ? */ - - char **labels; /* string of characters that labels the corresponding edge */ - int n_labels; /* number of labels */ -}edge; - -/*********************************************************/ - -typedef struct __Arbre { - struct __Node *n_root; /* root node */ - struct __Edge *e_root; /* edge on which lies the root */ - struct __Node **noeud; /* array of nodes that defines the tree topology */ - struct __Edge **t_edges; /* array of edges */ - struct __Arbre *old_tree; /* old copy of the tree */ - struct __Arbre *best_tree; /* best tree found so far */ - struct __Model *mod; /* substitution model */ - struct __AllSeq *data; /* sequences */ - struct __Option *io; /* input/output */ - struct __Matrix *mat; /* pairwise distance matrix */ - struct __Edge **t_dead_edges; - struct __Node **t_dead_nodes; - struct __Node **curr_path; /* list of nodes that form a path in the tree */ - struct __SPR **spr_list; - struct __SPR *best_spr; - struct __Tdraw *ps_tree; /* structure for drawing trees in postscript format */ - struct __Trate *rates; /* structure for handling rates of evolution */ - - int ps_page_number; /* when multiple trees are printed, this variable give the current page number */ - int depth_curr_path; /* depth of the node path defined by curr_path */ - int has_bip; /*if has_bip=1, then the structure to compare - tree topologies is allocated, has_bip=0 otherwise */ - int n_otu; /* number of taxa */ - int curr_site; /* current site of the alignment to be processed */ - int curr_catg; /* current class of the discrete gamma rate distribution */ - int n_swap; /* number of NNIs performed */ - int n_pattern; /* number of distinct site patterns */ - int has_branch_lengths; /* =1 iff input tree displays branch lengths */ - int print_boot_val; /* if print_boot_val=1, the bootstrap values are printed */ - int print_alrt_val; /* if print_boot_val=1, the bootstrap values are printed */ - int both_sides; /* both_sides=1 -> a pre-order and a post-order tree - traversals are required to compute the likelihood - of every subtree in the phylogeny*/ - int num_curr_branch_available; /*gives the number of the next cell in t_edges that is free to receive a pointer to a branch */ - int n_dead_edges; - int n_dead_nodes; - int **t_dir; - int n_improvements; - int n_moves; + phydbl ratio_test; /*! approximate likelihood ratio test */ + phydbl alrt_statistic; /*! aLRT statistic */ + phydbl support_val; + + + int n_jumps; /*! number of jumps of substitution rates */ + + int *n_diff_states_l; /*! Number of different states found in the subtree on the left of this edge */ + int *n_diff_states_r; /*! Number of different states found in the subtree on the right of this edge */ + + phydbl bin_cod_num; - int dp; /* Data partition */ - int s_mod_num; /* Substitution model number */ - int number_of_lk_calls; - int number_of_branch_lk_calls; - int lock_topo; /* = 1 any subsequent topological modification will be banished */ - int print_labels; - - phydbl init_lnL; - phydbl best_lnL; /* highest value of the loglikelihood found so far */ - phydbl c_lnL; /* loglikelihood */ - phydbl *c_lnL_sorted; /* used to compute c_lnL by adding sorted terms to minimize CPU errors */ - phydbl *site_lk; /* vector of likelihoods at individual sites */ - phydbl **log_site_lk_cat; /* loglikelihood at individual sites and for each class of rate*/ - phydbl unconstraint_lk; /* unconstrained (or multinomial) likelihood */ - phydbl prop_of_sites_to_consider; - phydbl **log_lks_aLRT; /* used to compute several branch supports */ - phydbl n_root_pos; /* position of the root on its edge */ + short int update_partial_lk_left; + short int update_partial_lk_rght; + + +}t_edge; + +/*!********************************************************/ + +typedef struct __Tree{ + + struct __Node *n_root; /*! root t_node */ + struct __Edge *e_root; /*! t_edge on which lies the root */ + struct __Node **a_nodes; /*! array of nodes that defines the tree topology */ + struct __Edge **a_edges; /*! array of edges */ + struct __Model *mod; /*! substitution model */ + struct __Calign *data; /*! sequences */ + struct __Tree *next; /*! set to NULL by default. Used for mixture models */ + struct __Tree *prev; /*! set to NULL by default. Used for mixture models */ + struct __Tree *next_mixt; /*! set to NULL by default. Used for mixture models */ + struct __Tree *prev_mixt; /*! set to NULL by default. Used for mixture models */ + struct __Tree *mixt_tree; /*! set to NULL by default. Used for mixture models */ + struct __Tree *extra_tree; /*! set to NULL by default. Used a latent variable in molecular dating */ + struct __Option *io; /*! input/output */ + struct __Matrix *mat; /*! pairwise distance matrix */ + struct __Node **curr_path; /*! list of nodes that form a path in the tree */ + struct __SPR **spr_list_one_edge; + struct __SPR **spr_list_all_edge; + struct __SPR *best_spr; + struct __Tdraw *ps_tree; /*! structure for drawing trees in postscript format */ + struct __T_Rate *rates; /*! structure for handling rates of evolution */ + struct __Tmcmc *mcmc; + struct __Phylogeo *geo; + struct __Migrep_Model *mmod; + struct __Disk_Event *young_disk; /*! Youngest disk (i.e., disk which age is the closest to present). Used in PhyREX */ + struct __Disk_Event *old_samp_disk; /*! Oldest sampled disk. Used in PhyREX */ + struct __XML_node *xml_root; + struct __Generic_LL *edge_list; + struct __Generic_LL *node_list; + + + short int eval_alnL; /*! Evaluate likelihood for genetic data */ + short int eval_rlnL; /*! Evaluate likelihood for rates along the tree */ + short int eval_glnL; /*! Evaluate tree likelihood */ + short int scaling_method; + short int fully_nni_opt; + short int numerical_warning; + + short int use_eigen_lr; + int is_mixt_tree; + int tree_num; /*! tree number. Used for mixture models */ + int ps_page_number; /*! when multiple trees are printed, this variable give the current page number */ + int depth_curr_path; /*! depth of the t_node path defined by curr_path */ + int has_bip; /*!if has_bip=1, then the structure to compare + tree topologies is allocated, has_bip=0 otherwise */ + int n_otu; /*! number of taxa */ + int curr_site; /*! current site of the alignment to be processed */ + int curr_catg; /*! current class of the discrete gamma rate distribution */ + int n_swap; /*! number of NNIs performed */ + int n_pattern; /*! number of distinct site patterns */ + int has_branch_lengths; /*! =1 iff input tree displays branch lengths */ + short int both_sides; /*! both_sides=1 -> a pre-order and a post-order tree + traversals are required to compute the likelihood + of every subtree in the phylogeny*/ + int num_curr_branch_available; /*!gives the number of the next cell in a_edges that is free to receive a pointer to a branch */ + short int *t_dir; + int n_moves; + int verbose; + + int dp; /*! Data partition */ + int s_mod_num; /*! Substitution model number */ + int lock_topo; /*! = 1 any subsequent topological modification will be banished */ + int write_labels; + int write_br_lens; + int *mutmap; /*! Mutational map */ + int json_num; + short int update_eigen_lr; + int tip_root; /*! Index of tip node used as the root */ + phydbl *eigen_lr_left; + phydbl *eigen_lr_rght; + phydbl *dot_prod; + + phydbl *expl; + + phydbl init_lnL; + phydbl best_lnL; /*! highest value of the loglikelihood found so far */ + int best_pars; /*! highest value of the parsimony found so far */ + phydbl c_lnL; /*! loglikelihood */ + phydbl old_lnL; /*! old loglikelihood */ + phydbl sum_min_sum_scale; /*! common factor of scaling factors */ + phydbl *c_lnL_sorted; /*! used to compute c_lnL by adding sorted terms to minimize CPU errors */ + phydbl *cur_site_lk; /*! vector of loglikelihoods at individual sites */ + phydbl *old_site_lk; /*! vector of likelihoods at individual sites */ + phydbl annealing_temp; /*! annealing temperature in simulated annealing optimization algo */ + phydbl c_dlnL; /*! First derivative of the log-likelihood with respect to the length of a branch */ + phydbl c_d2lnL; /*! Second derivative of the log-likelihood with respect to the length of a branch */ + + + phydbl *unscaled_site_lk_cat; /*! partially scaled site likelihood at individual sites */ + + phydbl *site_lk_cat; /*! loglikelihood at a single site and for each class of rate*/ + phydbl unconstraint_lk; /*! unconstrained (or multinomial) log-likelihood */ + phydbl composite_lk; /*! composite log-likelihood */ + int *fact_sum_scale; + phydbl **log_lks_aLRT; /*! used to compute several branch supports */ + phydbl n_root_pos; /*! position of the root on its t_edge */ + phydbl size; /*! tree size */ int *site_pars; int c_pars; int *step_mat; + - int size_spr_list; + int size_spr_list_one_edge; + int size_spr_list_all_edge; int perform_spr_right_away; time_t t_beg; time_t t_current; - struct __Triplet *triplet_struct; - - int bl_from_node_stamps; /* == 1 -> Branch lengths are determined by node times */ - -}arbre; + int bl_from_node_stamps; /*! == 1 -> Branch lengths are determined by t_node times */ + phydbl sum_y_dist_sq; + phydbl sum_y_dist; + phydbl tip_order_score; + int write_tax_names; + int update_alias_subpatt; -/*********************************************************/ + phydbl geo_mig_sd; /*! standard deviation of the migration step random variable */ + phydbl geo_lnL; /*! log likelihood of the phylo-geography model */ + + int bl_ndigits; + + phydbl *short_l; /*! Vector of short branch length values */ + int n_short_l; /*! Length of short_l */ + phydbl norm_scale; + + short int br_len_recorded; + + short int apply_lk_scaling; /*! Applying scaling of likelihoods. YES/NO */ + + phydbl *K; /*! a vector of the norm.constants for the node times prior. */ + + short int ignore_root; + short int ignore_mixt_info; +#ifdef BEAGLE + int b_inst; /*! The BEAGLE instance id associated with this tree. */ +#endif -typedef struct __Super_Arbre { - struct __Arbre *tree; - struct __List_Arbre *treelist; /* list of trees. One tree for each data set to be processed */ - struct __AllSeq *data_of_interest; - struct __Option **optionlist; /* list of pointers to input structures (used in supertrees) */ + // Extra partial lk structure for bookkeeping + short int *div_post_pred_extra_0; + int *sum_scale_cat_extra_0; + int *sum_scale_extra_0; + phydbl *p_lk_extra_0; + phydbl *p_lk_tip_extra_0; + int *patt_id_extra_0; + + short int *div_post_pred_extra_1; + int *sum_scale_cat_extra_1; + int *sum_scale_extra_1; + phydbl *p_lk_extra_1; + phydbl *p_lk_tip_extra_1; + int *patt_id_extra_1; + + int n_edges_traversed; + int n_tot_bl_opt; +}t_tree; + +/*!********************************************************/ + +typedef struct __Super_Tree { + struct __Tree *tree; + struct __List_Tree *treelist; /*! list of trees. One tree for each data set to be processed */ + struct __Calign *curr_cdata; + struct __Option **optionlist; /*! list of pointers to input structures (used in supertrees) */ struct __Node ***match_st_node_in_gt; - /* match_st_in_gt_node[subdataset number][supertree node number] - * gives the node in tree estimated from 'subdataset number' that corresponds - * to 'supertree node number' in the supertree + /*! match_st_in_gt_node[subdataset number][supertree t_node number] + * gives the t_node in tree estimated from 'subdataset number' that corresponds + * to 'supertree t_node number' in the supertree */ struct __Node *****map_st_node_in_gt; - /* mat_st_gt_node[gt_num][st_node_num][direction] gives the - * node in gt gt_num that maps node st_node_num in st. + /*! mat_st_gt_node[gt_num][st_node_num][direction] gives the + * t_node in gt gt_num that maps t_node st_node_num in st. */ struct __Edge ***map_st_edge_in_gt; - /* map_st_gt_br[gt_num][st_branch_num] gives the + /*! map_st_gt_br[gt_num][st_branch_num] gives the * branch in gt gt_num that maps branch st_branch_num * in st. */ struct __Edge ****map_gt_edge_in_st; - /* mat_gt_st_br[gt_num][gt_branch_num][] is the list of + /*! mat_gt_st_br[gt_num][gt_branch_num][] is the list of * branches in st that map branch gt_branch_num * in gt gt_num. */ int **size_map_gt_edge_in_st; - /* size_map_gt_st_br[gt_num][gt_branch_num] gives the + /*! size_map_gt_st_br[gt_num][gt_branch_num] gives the * size of the list map_gt_st_br[gt_num][gt_branch_num][] */ struct __Edge ***match_st_edge_in_gt; - /* match_st_edge_in_gt[gt_num][st_branch_num] gives the + /*! match_st_edge_in_gt[gt_num][st_branch_num] gives the * branch in gt gt_num that matches branch st_branch_num */ struct __Edge ***match_gt_edge_in_st; - /* match_gt_edge_in_st[gt_num][gt_branch_num] gives the + /*! match_gt_edge_in_st[gt_num][gt_branch_num] gives the * branch in st that matches branch gt_branch_num */ struct __Node ****closest_match; - /* closest_match[gt_num][st_node_num][dir] gives the - * closest node in st that matches a node in gt gt_num + /*! closest_match[gt_num][st_node_num][dir] gives the + * closest t_node in st that matches a t_node in gt gt_num */ int ***closest_dist; - /* closest_dist[gt_num][st_node_num][dir] gives the + /*! closest_dist[gt_num][st_node_num][dir] gives the * number of edges to traverse to get to node * closest_match[gt_num][st_node_num][dir] */ - int n_gt; - /* number of trees */ + int n_part; + /*! number of trees */ phydbl **bl; - /* bl[gt_num][gt_branch_num] gives the length of + /*! bl[gt_num][gt_branch_num] gives the length of * branch gt_branch_num */ phydbl **bl_cpy; - /* copy of bl */ + /*! copy of bl */ phydbl **bl0; - /* bl estimated during NNI (original topo) + /*! bl estimated during NNI (original topo) * See Mg_NNI. */ phydbl **bl1; - /* bl estimated during NNI (topo conf 1) + /*! bl estimated during NNI (topo conf 1) * See Mg_NNI. */ phydbl **bl2; - /* bl estimated during NNI (topo conf 2) + /*! bl estimated during NNI (topo conf 2) * See Mg_NNI. */ int *bl_partition; - /* partition[gt_num] gives the edge partition number + /*! partition[gt_num] gives the t_edge partition number * gt_num belongs to. */ - int n_bl_partition; + int n_bl_part; - struct __Model **s_mod; /* substitution model */ + struct __Model **s_mod; /*! substitution model */ int n_s_mod; int lock_br_len; -}superarbre; - -/*********************************************************/ - -typedef struct __List_Arbre { /* a list of trees */ - struct __Arbre **tree; - int list_size; /* number of trees in the list */ -}arbrelist; - -/*********************************************************/ - -typedef struct __Seq { - char *name; /* sequence name */ - int len; /* sequence length */ - char *state; /* sequence itself */ - short int *is_ambigu; /* is_ambigu[site] = 1 if state[site] is an ambiguous character. 0 otherwise */ -}seq; - -/*********************************************************/ - - -typedef struct __AllSeq { - struct __Seq **c_seq; /* compressed sequences */ - phydbl *b_frq; /* observed state frequencies */ - short int *invar; /* 1 -> states are identical, 0 states vary */ - int *wght; /* # of each site in c_seq */ - short int *ambigu; /* ambigu[i]=1 is one or more of the sequences at site - i display an ambiguous character */ - phydbl obs_pinvar; - int n_otu; /* number of taxa */ - int clean_len; /* uncrunched sequences lenghts without gaps */ - int crunch_len; /* crunched sequences lengths */ - int init_len; /* length of the uncompressed sequences */ - int *sitepatt; /* this array maps the position of the patterns in the - compressed alignment to the positions in the uncompressed - one */ -}allseq; - -/*********************************************************/ - -typedef struct __Matrix { /* mostly used in BIONJ */ - phydbl **P,**Q,**dist; /* observed proportions of transition, transverion and distances - between pairs of sequences */ - - arbre *tree; /* tree... */ - int *on_off; /* on_off[i]=1 if column/line i corresponds to a node that has not - been agglomerated yet */ - int n_otu; /* number of taxa */ - char **name; /* sequence names */ - int r; /* number of nodes that have not been agglomerated yet */ - struct __Node **tip_node; /* array of pointer to the leaves of the tree */ - int curr_int; /* used in the NJ/BIONJ algorithms */ - int method; /* if method=1->NJ method is used, BIONJ otherwise */ +}supert_tree; + +/*!********************************************************/ + +typedef struct __List_Tree { /*! a list of trees */ + struct __Tree **tree; + int list_size; /*! number of trees in the list */ +}t_treelist; + +/*!********************************************************/ + +typedef struct __Align { + char *name; /*! sequence name */ + int len; /*! sequence length */ + char *state; /*! sequence itself */ + short int *d_state; /*! sequence itself (digits) */ + short int *is_ambigu; /*! is_ambigu[site] = 1 if state[site] is an ambiguous character. 0 otherwise */ + short int is_duplicate; + int num; +}align; + +/*!********************************************************/ + +typedef struct __Calign { + struct __Align **c_seq; /*! compressed sequences */ + struct __Align **c_seq_rm; /*! removed sequences */ + struct __Option *io; /*! input/output */ + phydbl *obs_state_frq; /*! observed state frequencies */ + short int *invar; /*! < 0 -> polymorphism observed */ + phydbl *wght; /*! # of each site in c_align */ + short int *ambigu; /*! ambigu[i]=1 is one or more of the sequences at site + i display an ambiguous character */ + phydbl obs_pinvar; + int n_otu; /*! number of taxa */ + int n_rm; /*! number of taxa removed */ + int clean_len; /*! uncrunched sequences lenghts without gaps */ + int crunch_len; /*! crunched sequences lengths */ + int init_len; /*! length of the uncompressed sequences */ + int *sitepatt; /*! this array maps the position of the patterns in the + compressed alignment to the positions in the uncompressed + one */ + int format; /*! 0 (default): PHYLIP. 1: NEXUS. */ + scalar_dbl *io_wght; /*! weight of each *site* (not pattern) given as input */ +}calign; + +/*!********************************************************/ + +typedef struct __Matrix { /*! mostly used in BIONJ */ + phydbl **P,**Q,**dist; /*! observed proportions of transition, transverion and distances + between pairs of sequences */ + + t_tree *tree; /*! tree... */ + int *on_off; /*! on_off[i]=1 if column/line i corresponds to a t_node that has not + been agglomerated yet */ + int n_otu; /*! number of taxa */ + char **name; /*! sequence names */ + int r; /*! number of nodes that have not been agglomerated yet */ + struct __Node **tip_node; /*! array of pointer to the leaves of the tree */ + int curr_int; /*! used in the NJ/BIONJ algorithms */ + int method; /*! if method=1->NJ method is used, BIONJ otherwise */ }matrix; -/*********************************************************/ +/*!********************************************************/ + +typedef struct __RateMatrix { + int n_diff_rr; /*! number of different relative substitution rates in the custom model */ + vect_dbl *rr; /*! relative rate parameters of the GTR or custom model (rescaled) */ + vect_dbl *rr_val; /*! log of relative rate parameters of the GTR or custom model (unscaled) */ + vect_int *rr_num; + vect_int *n_rr_per_cat; /*! number of rate parameters in each category */ + vect_dbl *qmat; + vect_dbl *qmat_buff; + + struct __RateMatrix *next; + struct __RateMatrix *prev; +}t_rmat; + +/*!********************************************************/ + +typedef struct __RAS { + /*! Rate across sites */ + int n_catg; /*! number of categories in the discrete gamma distribution */ + int invar; /*! =1 iff the substitution model takes into account invariable sites */ + int gamma_median; /*! 1: use the median of each bin in the discrete gamma distribution. 0: the mean is used */ + vect_dbl *gamma_r_proba; /*! probabilities of the substitution rates defined by the discrete gamma distribution */ + vect_dbl *gamma_r_proba_unscaled; + vect_dbl *gamma_rr; /*! substitution rates defined by the RAS distribution */ + vect_dbl *gamma_rr_unscaled; /*! substitution rates defined by the RAS distribution (unscaled) */ + scalar_dbl *alpha; /*! gamma shapa parameter */ + int free_mixt_rates; + scalar_dbl *free_rate_mr; /*! mean relative rate as given by the FreeRate model */ + + + int parent_class_number; + scalar_dbl *pinvar; /*! proportion of invariable sites */ + + short int init_rr; + short int init_r_proba; + short int normalise_rr; + + short int *skip_rate_cat; /*! indicates whether of not the the likelihood for a given rate class shall be calculated. + The default model in PhyML has four rate classes and the likelihood at a given site is + then \sum_{i=1}^{4} \Pr(D|R=i) \Pr(R=i). Now, when optimising + the rate for say the first rate class (i=1) one does not need to + re-compute \Pr(D|R=2), \Pr(D|R=3) and \Pr(D|R=4) (which is the time + consuming part of the likelihood calculation). This is where + 'skip_rate_category' comes in handy. */ + + short int sort_rate_classes; /*! When doing MCMC moves on rate classes, one needs to have the rate classes sorted */ + + struct __RAS *next; + struct __RAS *prev; + +}t_ras; + +/*!********************************************************/ + +typedef struct __EquFreq { + /*! Equilibrium frequencies */ + vect_dbl *pi; /*! states frequencies */ + vect_dbl *pi_unscaled; /*! states frequencies (unscaled) */ + + phydbl *b_frq; /*! vector of empirical state frequencies */ + + short int empirical_state_freq; + short int user_state_freq; + vect_dbl *user_b_freq; /*! user-defined nucleotide frequencies */ + + struct __EquFreq *next; + struct __EquFreq *prev; + +}t_efrq; + +/*!********************************************************/ typedef struct __Model { - struct __Optimiz *s_opt; /* pointer to parameters to optimize */ - struct __Eigen *eigen; - struct __M4 *m4mod; - - char *modelname; - char *custom_mod_string; /* string of characters used to define custom models of substitution */ - - int *rr_num; - int *n_rr_per_cat; /* number of rate parameters in each category */ - int n_diff_rr; /* number of different relative substitution rates in the custom model */ - int update_eigen; /* update_eigen=1-> eigen values/vectors need to be updated */ - int whichmodel; - int datatype; /* 0->DNA, 1->AA */ - int n_catg; /* number of categories in the discrete gamma distribution */ - int invar; /* =1 iff the substitution model takes into account invariable sites */ - int ns; /* number of states (4 for ADN, 20 for AA) */ - int seq_len; /* sequence length */ - int stepsize; /* stepsize=1 for nucleotide models, 3 for codon models */ - int n_otu; /* number of taxa */ - int bootstrap; /* Number of bootstrap replicates (0 : no bootstrap analysis is launched) */ - int use_m4mod; /* Use a Makrkov modulated Markov model ? */ - - phydbl *pi; /* states frequencies */ - phydbl *pi_unscaled; /* states frequencies (unscaled) */ - - phydbl *gamma_r_proba; /* probabilities of the substitution rates defined by the discrete gamma distribution */ - phydbl *gamma_rr; /* substitution rates defined by the discrete gamma distribution */ - phydbl kappa; /* transition/transversion rate */ - phydbl lambda; /* parameter used to define the ts/tv ratios in the F84 and TN93 models */ - phydbl alpha; /* gamma shapa parameter */ - phydbl pinvar; /* proportion of invariable sites */ - phydbl alpha_old; - phydbl kappa_old; - phydbl lambda_old; - phydbl pinvar_old; - - phydbl *rr; /* relative rate parameters of the GTR or custom model (given by rr_val[rr_num[i]]) */ - phydbl *rr_val; /* relative rate parameters of the GTR or custom model */ - double ***Pij_rr; /* matrix of change probabilities */ - phydbl mr; /* mean rate = branch length/time interval mr = -sum(i)(vct_pi[i].mat_Q[ii]) */ - phydbl *user_b_freq; /* user-defined nucleotide frequencies */ - phydbl *qmat; - phydbl *qmat_buff; - - phydbl *rr_branch; /* relative substitution rates on each branch, for the whole set of sites */ - phydbl *p_rr_branch; /* corresponding frequencies */ - int n_rr_branch; /* number of classes */ - phydbl rr_branch_alpha; /* Shape of the gamma distribution that defines the rr_branch and p_rr_branch values */ -}model; - -/*********************************************************/ + struct __Optimiz *s_opt; /*! pointer to parameters to optimize */ + struct __Eigen *eigen; + struct __M4 *m4mod; + struct __Option *io; + struct __Model *next; + struct __Model *prev; + struct __Model *next_mixt; + struct __Model *prev_mixt; + struct __RateMatrix *r_mat; + struct __EquFreq *e_frq; + struct __RAS *ras; + + t_string *aa_rate_mat_file; + FILE *fp_aa_rate_mat; + + t_string *modelname; + t_string *custom_mod_string; /*! string of characters used to define custom models of substitution */ + + int mod_num; /*! model number */ + + int update_eigen; /*! update_eigen=1-> eigen values/vectors need to be updated */ + + int whichmodel; + int is_mixt_mod; + int augmented; + int ns; /*! number of states (4 for ADN, 20 for AA) */ + + int use_m4mod; /*! Use a Markov modulated Markov model ? */ + + scalar_dbl *kappa; /*! transition/transversion rate */ + scalar_dbl *lambda; /*! parameter used to define the ts/tv ratios in the F84 and TN93 models */ + scalar_dbl *br_len_mult; /*! when users want to fix the relative length of edges and simply estimate the total length of the tree. This multiplier does the trick */ + scalar_dbl *br_len_mult_unscaled; + + vect_dbl *Pij_rr; /*! matrix of change probabilities */ + scalar_dbl *mr; /*! mean rate = branch length/time interval mr = -sum(i)(vct_pi[i].mat_Q[ii]) */ + + short int log_l; /*! Edge lengths are actually log(Edge lengths) if log_l == YES !*/ + phydbl l_min; /*! Minimum branch length !*/ + phydbl l_max; /*! Maximum branch length !*/ + + phydbl l_var_sigma; /*! For any edge b we have b->l_var->v = l_var_sigma * (b->l->v)^2 */ + phydbl l_var_min; /*! Min of variance of branch lengths (used in conjunction with gamma_mgf_bl == YES) */ + phydbl l_var_max; /*! Max of variance of branch lengths (used in conjunction with gamma_mgf_bl == YES) */ + + int gamma_mgf_bl; /*! P = \int_0^inf exp(QL) p(L) where L=\int_0^t R(s) ds and p(L) is the gamma density. Set to NO by default !*/ + + int n_mixt_classes; /* Number of classes in the mixture model. */ + + scalar_dbl *r_mat_weight; + scalar_dbl *e_frq_weight; +#ifdef BEAGLE + int b_inst; + bool optimizing_topology; /*! This is a flag that prevents the resetting of category weights. Why? Read */ + /* Recall that while optimizing the toplogy, PhyML temporarily only uses 2 + * rate categories. Recall also that a BEAGLE instance is created with all the + * required categories, but we temporarily assign 0 weight to the other categories + * thus effectively using only 2 categories. However, subsequent calls to + * update the rates (i.e. update_beagle_ras()) will reset the weights. This flag + * prevents this resetting from happening */ +#endif + +}t_mod; + +/*!********************************************************/ typedef struct __Eigen{ - int size; - double *q; /* matrix which eigen values and vectors are computed */ - double *space; + int size; /*! matrix is size * size */ + phydbl *q; /*! matrix for which eigen values and vectors are computed */ + phydbl *space; int *space_int; - double *e_val; /* eigen values (vector), real part. */ - double *e_val_im; /* eigen values (vector), imaginary part */ - double *r_e_vect; /* right eigen vector (matrix), real part */ - double *r_e_vect_im; /* right eigen vector (matrix), imaginary part */ - double *l_e_vect; /* left eigen vector (matrix), real part */ + phydbl *e_val; /*! eigen values (vector), real part. */ + phydbl *e_val_im; /*! eigen values (vector), imaginary part */ + phydbl *r_e_vect_im; /*! right eigen vector (matrix), imaginary part */ + phydbl *l_e_vect; /*! left eigen vector (matrix), real part */ + phydbl *r_e_vect; /*! right eigen vector (matrix), real part */ + phydbl *dum; /*! dummy ns*ns space */ + + struct __Eigen *prev; + struct __Eigen *next; }eigen; -/*********************************************************/ +/*!********************************************************/ + +typedef struct __Option { /*! mostly used in 'help.c' */ + struct __Model *mod; /*! pointer to a substitution model */ + struct __Tree *tree; /*! pointer to the current tree */ + struct __Align **data; /*! pointer to the uncompressed sequences */ + struct __Tree *cstr_tree; /*! pointer to a constraint tree (can be a multifurcating one) */ + struct __Calign *cdata; /*! pointer to the compressed sequences */ + struct __Super_Tree *st; /*! pointer to supertree */ + struct __Tnexcom **nex_com_list; + struct __List_Tree *treelist; /*! list of trees. */ + struct __Option *next; + struct __Option *prev; + struct __Tmcmc *mcmc; + struct __T_Rate *rates; + + int interleaved; /*! interleaved or sequential sequence file format ? */ + int in_tree; /*! =1 iff a user input tree is used as input */ -typedef struct __Option { /* mostly used in 'options.c' */ - struct __Model *mod; /* pointer to a substitution model */ - struct __Arbre *tree; /* pointer to the current tree */ - struct __Seq **data; /* pointer to the uncompressed sequences */ - struct __AllSeq *alldata; /* pointer to the compressed sequences */ - struct __Super_Arbre *st; /* pointer to supertree */ - int interleaved; /* interleaved or sequential sequence file format ? */ - int in_tree; /* =1 iff a user input tree is used as input */ + char *in_align_file; /*! alignment file name */ + FILE *fp_in_align; /*! pointer to the alignment file */ - char *in_seq_file; /* sequence file name */ - FILE *fp_in_seq; /* pointer to the sequence file */ + char *in_tree_file; /*! input tree file name */ + FILE *fp_in_tree; /*! pointer to the input tree file */ - char *in_tree_file; /* input tree file name */ - FILE *fp_in_tree; /* pointer to the input tree file */ + char *in_constraint_tree_file; /*! input constraint tree file name */ + FILE *fp_in_constraint_tree; /*! pointer to the input constraint tree file */ - char *out_tree_file; /* name of the tree file */ + char *out_tree_file; /*! name of the tree file */ FILE *fp_out_tree; - char *out_best_tree_file; /* name of the tree file */ - FILE *fp_out_best_tree; /* pointer to the best tree file */ + char *weight_file; /*! name of the file containing site weights */ + FILE *fp_weight_file; + + char *out_trees_file; /*! name of the tree file */ + FILE *fp_out_trees; /*! pointer to the tree file containing all the trees estimated using random starting trees */ - char *out_boot_tree_file; /* name of the tree file */ - FILE *fp_out_boot_tree; /* pointer to the bootstrap tree file */ + char *out_boot_tree_file; /*! name of the tree file */ + FILE *fp_out_boot_tree; /*! pointer to the bootstrap tree file */ - char *out_boot_stats_file; /* name of the tree file */ - FILE *fp_out_boot_stats; /* pointer to the statistics file */ + char *out_boot_stats_file; /*! name of the tree file */ + FILE *fp_out_boot_stats; /*! pointer to the statistics file */ - char *out_stats_file; /* name of the statistics file */ + char *out_stats_file; /*! name of the statistics file */ FILE *fp_out_stats; - char *out_trace_file; /* name of the file in which the likelihood of the model is written */ + char *out_trace_file; /*! name of the file in which the trace is written */ FILE *fp_out_trace; - char *out_lk_file; /* name of the file in which the likelihood of the model is written */ + char *out_json_trace_file; /*! name of the file in which json trace is written */ + FILE *fp_out_json_trace; + + char *out_lk_file; /*! name of the file in which the likelihood of the model is written */ FILE *fp_out_lk; - char *out_ps_file; /* name of the file in which tree(s) is(are) written */ + char *out_summary_file; /*! name of the file in which summary statistics are written */ + FILE *fp_out_summary; + + char *out_ps_file; /*! name of the file in which tree(s) is(are) written */ FILE *fp_out_ps; - int print_boot_trees; /* =1 if the bootstrapped trees are printed in output */ - int out_stats_file_open_mode; /* opening file mode for statistics file */ - int out_tree_file_open_mode; /* opening file mode for tree file */ - int n_data_sets; /* number of data sets to be analysed */ - int n_trees; /* number of trees */ - int seq_len; /* sequence length */ - int n_data_set_asked; /* number of bootstrap replicates */ - char *nt_or_cd; /* nucleotide or codon data ? (not used) */ - int multigene; /* if=1 -> analyse several partitions. */ + char *out_ancestral_seq_file; /*! name of the file containing the ancestral sequences */ + char *out_ancestral_tree_file; /*! name of the file containing the tree with internal node labelled according to refs in ancestral_seq_file */ + + FILE *fp_out_ancestral_seq; /*! pointer to the file containing the ancestral sequences */ + FILE *fp_out_ancestral_tree; /*! pointer to the file containing the tree with labels on internal nodes */ + + char *in_coord_file; /*! name of input file containing coordinates */ + FILE *fp_in_coord; /*! pointer to the file containing coordinates */ + + char *out_file; /*! name of the output file */ + + char *clade_list_file; + + int datatype; /*! 0->DNA, 1->AA */ + int print_boot_trees; /*! =1 if the bootstrapped trees are printed in output */ + int out_stats_file_open_mode; /*! opening file mode for statistics file */ + int out_tree_file_open_mode; /*! opening file mode for tree file */ + int n_data_sets; /*! number of data sets to be analysed */ + int n_trees; /*! number of trees */ + int init_len; /*! sequence length */ + int n_otu; /*! number of taxa */ + int n_data_set_asked; /*! number of bootstrap replicates */ + char *nt_or_cd; /*! nucleotide or codon data ? (not used) */ + int multigene; /*! if=1 -> analyse several partitions. */ int config_multigene; - int n_gt; /* number of gene trees */ + int n_part; /*! number of data partitions */ int curr_gt; - int ratio_test; /* from 1 to 4 for specific branch supports, 0 of not */ + int ratio_test; /*! from 1 to 4 for specific branch supports, 0 of not */ int ready_to_go; + int data_file_format; /*! Data format: Phylip or Nexus */ + int tree_file_format; /*! Tree format: Phylip or Nexus */ + int state_len; int curr_interface; - int r_seed; /* random seed */ - int collapse_boot; /* 0 -> branch length on bootstrap trees are not collapsed if too small */ - int random_boot_seq_order; /* !0 -> sequence order in bootstrapped data set is random */ + int r_seed; /*! random seed */ + int collapse_boot; /*! 0 -> branch length on bootstrap trees are not collapsed if too small */ + int random_boot_seq_order; /*! !0 -> sequence order in bootstrapped data set is random */ int print_trace; + int print_json_trace; int print_site_lnl; int m4_model; - int rm_ambigu; /* 0 is the default. 1: columns with ambiguous characters are discarded prior further analysis */ + int rm_ambigu; /*! 0 is the default. 1: columns with ambiguous characters are discarded prior further analysis */ + int colalias; + int append_run_ID; + char *run_id_string; + int quiet; /*! 0 is the default. 1: no interactive question (for batch mode) */ + int lk_approx; /* EXACT or NORMAL */ + char **alphabet; + int codpos; + int mutmap; + int use_xml; + + char **long_tax_names; + char **short_tax_names; + int size_tax_names; + + phydbl *z_scores; + phydbl *lat; + phydbl *lon; + + int boot_prog_every; + + int mem_question; + int do_alias_subpatt; + +#ifdef BEAGLE + int beagle_resource; +#endif + + int ancestral; + int has_io_weights; + int tbe_bootstrap;/* Replace standard bootstrap with tbe bootstrap (only when b>0) */ + + int leave_duplicates;/* Leave duplicated sequences */ + int precision;/* Decimal output precision for values in stats file */ + int n_boot_replicates; + + short int print_node_num; /*! print node numbers if print_node_num=1 */ + short int print_support_val; + + short int do_tbe; + short int do_boot; + short int do_alrt; + }option; -/*********************************************************/ - -typedef struct __Optimiz { /* parameters to be optimised (mostly used in 'optimiz.c') */ - int print; /* =1 -> verbose mode */ - - int opt_alpha; /* =1 -> the gamma shape parameter is optimised */ - int opt_kappa; /* =1 -> the ts/tv ratio parameter is optimised */ - int opt_lambda; /* =1 -> the F84|TN93 model specific parameter is optimised */ - int opt_pinvar; /* =1 -> the proportion of invariants is optimised */ - int opt_state_freq; /* =1 -> the nucleotide frequencies are optimised */ - int opt_rr; /* =1 -> the relative rate parameters of the GTR or the customn model are optimised */ - int opt_num_param; /* if opt_topo=0 and opt_num_param=1 -> the numerical parameters of the - model are optimised. if opt_topo=0 and opt_free_param=0 -> no parameter is - optimised */ - int opt_cov_delta; - int opt_cov_alpha; - int opt_cov_free_rates; - - - int opt_bl; /* =1 -> the branch lengths are optimised */ - int opt_topo; /* =1 -> the tree topology is optimised */ - int topo_search; - phydbl init_lk; /* initial loglikelihood value */ - int n_it_max; /* maximum bnumber of iteration during an optimisation step */ - int last_opt; /* =1 -> the numerical parameters are optimised further while the - tree topology remains fixed */ - int random_input_tree; /* boolean */ - int n_rand_starts; /* number of random starting points */ - int brent_it_max; - int steph_spr; - int user_state_freq; - int spr_step_after_nnis; - - - phydbl tree_size_mult; /* tree size multiplier */ - phydbl min_diff_lk_local; - phydbl min_diff_lk_global; - phydbl p_moves_to_examine; - int fast_nni; - int greedy; - int general_pars; - - - - int wim_n_rgrft; - int wim_n_globl; - int wim_max_dist; - int wim_n_optim; - int wim_n_best; - int wim_inside_opt; - -}optimiz; - -/*********************************************************/ +/*!********************************************************/ + +typedef struct __Optimiz { /*! parameters to be optimised (mostly used in 'optimiz.c') */ + short int opt_alpha; /*! =1 -> the gamma shape parameter is optimised */ + short int opt_kappa; /*! =1 -> the ts/tv ratio parameter is optimised */ + short int opt_lambda; /*! =1 -> the F84|TN93 model specific parameter is optimised */ + short int opt_pinvar; /*! =1 -> the proportion of invariants is optimised */ + short int opt_state_freq; /*! =1 -> the nucleotide frequencies are optimised */ + short int opt_rr; /*! =1 -> the relative rate parameters of the GTR or the customn model are optimised */ + short int opt_subst_param; /*! if opt_topo=0 and opt_subst_param=1 -> the numerical parameters of the + model are optimised. if opt_topo=0 and opt_free_param=0 -> no parameter is + optimised */ + short int opt_cov_delta; + short int opt_cov_alpha; + short int opt_cov_free_rates; + + short int opt_clock_r; + + short int opt_bl; /*! =1 -> the branch lengths are optimised */ + short int opt_topo; /*! =1 -> the tree topology is optimised */ + short int topo_search; + phydbl init_lk; /*! initial loglikelihood value */ + int n_it_max; /*! maximum bnumber of iteration during an optimisation step */ + int last_opt; /*! =1 -> the numerical parameters are optimised further while the + tree topology remains fixed */ + int random_input_tree; /*! boolean */ + int n_rand_starts; /*! number of random starting points */ + int brent_it_max; + int steph_spr; + int opt_five_branch; + int pars_thresh; + int hybrid_thresh; + int opt_br_len_mult; + int min_n_triple_moves; + int max_rank_triple_move; + int n_improvements; + int max_spr_depth; + int max_no_better_tree_found; + + phydbl tree_size_mult; /*! tree size multiplier */ + phydbl min_diff_lk_local; + phydbl min_diff_lk_global; + phydbl min_diff_lk_move; + phydbl p_moves_to_examine; + int fast_nni; + int greedy; + int general_pars; + int quickdirty; + int spr_pars; + int spr_lnL; + int max_depth_path; + int min_depth_path; + int deepest_path; + int eval_list_regraft; + phydbl max_delta_lnL_spr; + phydbl max_delta_lnL_spr_current; + phydbl worst_lnL_spr; + int br_len_in_spr; + int opt_free_mixt_rates; + int constrained_br_len; + int opt_gamma_br_len; + int first_opt_free_mixt_rates; + int wim_n_rgrft; + int wim_n_globl; + int wim_max_dist; + int wim_n_optim; + int wim_n_best; + int wim_inside_opt; + + int opt_rmat_weight; + int opt_efrq_weight; + + int skip_tree_traversal; + int serial_free_rates; + + int curr_opt_free_rates; + + int nni_br_len_opt; + + int apply_spr_right_away; + int apply_spr; + + phydbl l_min_spr; +}t_opt; + +/*!********************************************************/ typedef struct __NNI{ @@ -654,24 +1410,27 @@ typedef struct __NNI{ struct __Edge *b; phydbl score; - phydbl init_l; + scalar_dbl *init_l; + scalar_dbl *init_v; phydbl init_lk; - phydbl best_l; + scalar_dbl *best_l; + scalar_dbl *best_v; phydbl lk0,lk1,lk2; - phydbl l0,l1,l2; + scalar_dbl *l0,*l1,*l2; + scalar_dbl *v0,*v1,*v2; struct __Node *swap_node_v1; struct __Node *swap_node_v2; struct __Node *swap_node_v3; struct __Node *swap_node_v4; - int best_conf; /* best topological configuration : - ((left_1,left_2),right_1,right_2) or - ((left_1,right_2),right_1,left_2) or - ((left_1,right_1),right_1,left_2) */ -}nni; + int best_conf; /*! best topological configuration : + ((left_1,left_2),right_1,right_2) or + ((left_1,right_2),right_1,left_2) or + ((left_1,right_1),right_1,left_2) */ +}t_nni; -/*********************************************************/ +/*!********************************************************/ typedef struct __SPR{ struct __Node *n_link; @@ -680,33 +1439,28 @@ typedef struct __SPR{ struct __Edge *b_target; struct __Edge *b_init_target; struct __Node **path; - phydbl init_target_l; - phydbl l0,l1,l2; + + scalar_dbl *init_target_l; + scalar_dbl *init_target_v; + + scalar_dbl *l0,*l1,*l2; + scalar_dbl *v0,*v1,*v2; + phydbl lnL; int depth_path; int pars; int dist; -}spr; - -/*********************************************************/ - -typedef struct __Triplet{ - int size; - phydbl *F_bc; - phydbl *F_cd; - phydbl *F_bd; - phydbl ****core; - phydbl ***p_one_site; - phydbl ***sum_p_one_site; - phydbl *pi_bc; - phydbl *pi_cd; - phydbl *pi_bd; - struct __Eigen *eigen_struct; - struct __Model *mod; -}ttriplet; -/* wash renamed triplet to ttriplet because of name clash with SISSI */ - -/*********************************************************/ + + struct __SPR *next; + struct __SPR *prev; + struct __SPR *next_mixt; + struct __SPR *prev_mixt; + struct __SPR *path_prev; + struct __SPR *path_next; + +}t_spr; + +/*!********************************************************/ typedef struct __Pnode{ struct __Pnode **next; @@ -714,312 +1468,930 @@ typedef struct __Pnode{ int num; }pnode; -/*********************************************************/ +/*!********************************************************/ typedef struct __M4 { - int n_h; /* number of hidden states */ - int n_o; /* number of observable states */ + int n_h; /*! number of hidden states */ + int n_o; /*! number of observable states */ int use_cov_alpha; int use_cov_free; - phydbl **o_mats; /* set of matrices of substitution rates across observable states */ - phydbl *multipl; /* vector of values that multiply each o_mats matrix */ - phydbl *o_rr; /* relative rates (symmetric) of substitution between observable states */ - phydbl *h_rr; /* relative rates (symmetric) of substitution between hidden states */ - phydbl *h_mat; /* matrix that describes the substitutions between hidden states (aka switches) */ - phydbl *o_fq; /* equilibrium frequencies for the observable states */ - phydbl *h_fq; /* equilibrium frequencies for the hidden states */ - phydbl *h_fq_unscaled; /* unscaled equilibrium frequencies for the hidden states */ - phydbl *multipl_unscaled; /* unscaled vector of values that multiply each o_mats matrix */ - - phydbl delta; /* switching rate */ - phydbl alpha; /* gamma shape parameter */ + phydbl **o_mats; /*! set of matrices of substitution rates across observable states */ + phydbl *multipl; /*! vector of values that multiply each o_mats matrix */ + phydbl *o_rr; /*! relative rates (symmetric) of substitution between observable states */ + phydbl *h_rr; /*! relative rates (symmetric) of substitution between hidden states */ + phydbl *h_mat; /*! matrix that describes the substitutions between hidden states (aka switches) */ + phydbl *o_fq; /*! equilibrium frequencies for the observable states */ + phydbl *h_fq; /*! equilibrium frequencies for the hidden states */ + phydbl *h_fq_unscaled; /*! unscaled equilibrium frequencies for the hidden states */ + phydbl *multipl_unscaled; /*! unscaled vector of values that multiply each o_mats matrix */ + + phydbl delta; /*! switching rate */ + phydbl alpha; /*! gamma shape parameter */ }m4; -/*********************************************************/ +/*!********************************************************/ typedef struct __Tdraw { - int *xcoord; /* node coordinates on the x axis */ - int *ycoord; /* node coordinates on the y axis */ + phydbl *xcoord; /*! t_node coordinates on the x axis */ + phydbl *ycoord; /*! t_node coordinates on the y axis */ + phydbl *xcoord_s; /*! t_node coordinates on the x axis (scaled) */ + phydbl *ycoord_s; /*! t_node coordinates on the y axis (scaled) */ int page_width; int page_height; int tree_box_width; - double max_dist_to_root; + int *cdf_mat; + phydbl *cdf_mat_x; + phydbl *cdf_mat_y; + + phydbl max_dist_to_root; }tdraw; -/*********************************************************/ - - -typedef struct __Trate { - int n_mc_runs; /* Number of Monte Carlo runs to estimate the probability density of mean rates on each branch */ - int curr_mc_run; /* Current Monte Carlo run */ - phydbl mean_r; /* Mean substitution rate, i.e., 'molecular clock' rate */ - phydbl *br_r; /* Relative substitution rate, i.e., multiplier of mean_r on each branch */ - phydbl *lexp; /* Parameter of the exponential distribution that governs the rate at which substitution between rate classes ocur */ - phydbl **mc_mr; /* probability density of mean rates on each branch */ -}trate; - - -/*********************************************************/ -/*********************************************************/ -/*********************************************************/ - -phydbl Rand_Normal_Deviate(phydbl mean, phydbl sd); -phydbl bico(int n,int k); -phydbl factln(int n); -phydbl gammln(phydbl xx); -phydbl Pbinom(int N,int ni,phydbl p); -void Plim_Binom(phydbl pH0,int N,phydbl *pinf,phydbl *psup); -phydbl LnGamma(phydbl alpha); -phydbl IncompleteGamma(phydbl x,phydbl alpha,phydbl ln_gamma_alpha); -phydbl PointChi2(phydbl prob,phydbl v); -phydbl PointNormal(phydbl prob); -int DiscreteGamma(phydbl freqK[],phydbl rK[],phydbl alfa,phydbl beta,int K,int median); -arbre *Read_Tree(char *s_tree); -void Make_All_Edges_Light(node *a,node *d); -void Make_All_Edges_Lk(node *a,node *d,arbre *tree); -void R_rtree(char *s_tree_a, char *s_tree_d, node *a, arbre *tree, int *n_int, int *n_ext); -void Clean_Multifurcation(char **subtrees,int current_deg,int end_deg); -char **Sub_Trees(char *tree,int *degree); -int Next_Par(char *s,int pos); -char *Write_Tree(arbre *tree); -void R_wtree(node *pere,node *fils,char *s_tree,arbre *tree); -void Init_Tree(arbre *tree, int n_otu); -edge *Make_Edge_Light(node *a, node *d, int num); -void Init_Edge_Light(edge *b, int num); -void Make_Edge_Dirs(edge *b,node *a,node *d); -void Make_Edge_Lk(edge *b, arbre *tree); -node *Make_Node_Light(int num); -void Make_Node_Lk(node *n); -seq **Get_Seq(option *input,int rw); -seq **Read_Seq_Sequential(FILE *in,int *n_otu); -seq **Read_Seq_Interleaved(FILE *in,int *n_otu); -int Read_One_Line_Seq(seq ***data,int num_otu,FILE *in); +/*!********************************************************/ + +typedef struct __T_Rate { + phydbl lexp; /*! Parameter of the exponential distribution that governs the rate at which substitution between rate classes ocur */ + phydbl alpha; + phydbl less_likely; + phydbl birth_rate; + phydbl birth_rate_min; + phydbl birth_rate_max; + phydbl birth_rate_pivot; + phydbl death_rate; + phydbl death_rate_min; + phydbl death_rate_max; + phydbl death_rate_pivot; + phydbl min_rate; + phydbl max_rate; + phydbl c_lnL1; + phydbl c_lnL2; + phydbl c_lnL_rates; /*! Prob(Br len | time stamps, model of rate evolution) */ + phydbl c_lnL_times; /*! Prob(time stamps) */ + phydbl c_lnL_jps; /*! Prob(# Jumps | time stamps, rates, model of rate evolution) */ + phydbl clock_r; /*! Mean substitution rate, i.e., 'molecular clock' rate */ + phydbl min_clock; + phydbl max_clock; + phydbl lbda_nu; + phydbl min_dt; + phydbl step_rate; + phydbl true_tree_size; + phydbl p_max; + phydbl norm_fact; + phydbl nu; /*! Parameter of the Exponential distribution for the corresponding model */ + phydbl min_nu; + phydbl max_nu; + phydbl covdet; + phydbl sum_invalid_areas; + + + phydbl *nd_r; /*! Current rates at nodes */ + phydbl *br_r; /*! Current rates along edges */ + phydbl *nd_t; /*! Current t_node times */ + phydbl *triplet; + phydbl *true_t; /*! true t_node times (including root node) */ + phydbl *true_r; /*! true t_edge rates (on rooted tree) */ + phydbl *buff_t; + phydbl *buff_br_r; + phydbl *buff_nd_r; + phydbl *dens; /*! Probability densities of mean substitution rates at the nodes */ + phydbl *ml_l; /*! ML t_edge lengths (rooted) */ + phydbl *cur_l; /*! Current t_edge lengths (rooted) */ + phydbl *u_ml_l; /*! ML t_edge lengths (unrooted) */ + phydbl *u_cur_l; /*! Current t_edge lengths (unrooted) */ + phydbl *invcov; + phydbl *cov_r; + phydbl *mean_r; /*! average values of br_r taken across the sampled values during the MCMC */ + phydbl *mean_t; /*! average values of nd_t taken across the sampled values during the MCMC */ + phydbl *_2n_vect1; + phydbl *_2n_vect2; + phydbl *_2n_vect3; + phydbl *_2n_vect4; + short int *_2n_vect5; + phydbl *_2n2n_vect1; + phydbl *_2n2n_vect2; + phydbl *trip_cond_cov; + phydbl *trip_reg_coeff; + phydbl *cond_var; + phydbl *reg_coeff; + phydbl *t_prior; + phydbl *t_prior_min; + phydbl *t_prior_max; + phydbl *t_floor; + phydbl *t_mean; + int *t_rank; /* rank of nodes, e.g., tree->nd_a[tree->rates->t_rank[0]] is the oldest node */ + phydbl *mean_l; + phydbl *cov_l; + phydbl *grad_l; /* gradient */ + phydbl inflate_var; + phydbl *time_slice_lims; + phydbl *survival_rank; + phydbl *survival_dur; + phydbl *calib_prob; + + int adjust_rates; /*! if = 1, branch rates are adjusted such that a modification of a given t_node time + does not modify any branch lengths */ + int use_rates; /*! if = 0, branch lengths are expressed as differences between t_node times */ + int bl_from_rt; /*! if =1, branch lengths are obtained as the product of cur_r and t */ + int approx; + int model; /*! Model number */ + char *model_name; + int is_allocated; + int met_within_gibbs; + + int update_mean_l; + int update_cov_l; + + int *n_jps; + int *t_jps; + int n_time_slices; + int *n_time_slice_spans; + int *curr_slice; + int *n_tips_below; + + short int *t_has_prior; + struct __Node **lca; /*! 2-way table of common ancestral nodes for each pair of nodes */ + + short int *br_do_updt; + phydbl *cur_gamma_prior_mean; + phydbl *cur_gamma_prior_var; + + short int nd_t_recorded; + short int br_r_recorded; + + int *has_survived; + + struct __Calibration **a_cal; /* array of calibration data */ + int n_cal; /* number of elements in a_cal */ + + phydbl *t_prior_min_ori; + phydbl *t_prior_max_ori; + phydbl *times_partial_proba; + + phydbl log_K_cur; + int cur_comb_numb; + int *numb_calib_chosen; + int update_time_norm_const; + + struct __T_Rate *next; + struct __T_Rate *prev; + + short int is_asynchronous; +}t_rate; + +/*!********************************************************/ + +typedef struct __Tmcmc { + struct __Option *io; + + phydbl *tune_move; + phydbl *move_weight; + + phydbl *acc_rate; + int *acc_move; + int *run_move; + int *prev_acc_move; + int *prev_run_move; + int *num_move; + int *move_type; + char **move_name; + + int num_move_nd_r; + int num_move_br_r; + int num_move_times; + int num_move_times_and_rates; + int num_move_times_and_rates_root; + int num_move_root_time; + int num_move_nu; + int num_move_clock_r; + int num_move_tree_height; + int num_move_time_slice; + int num_move_subtree_height; + int num_move_kappa; + int num_move_rr; + int num_move_spr; + int num_move_spr_weighted; + int num_move_spr_local; + int num_move_spr_root; + int num_move_tree_rates; + int num_move_subtree_rates; + int num_move_updown_nu_cr; + int num_move_updown_t_cr; + int num_move_updown_t_br; + int num_move_ras; + int num_move_cov_rates; + int num_move_cov_switch; + int num_move_birth_rate; + int num_move_death_rate; + int num_move_birth_death_updown; + int num_move_jump_calibration; + int num_move_geo_lambda; + int num_move_geo_sigma; + int num_move_geo_tau; + int num_move_geo_dum; + int num_move_geo_updown_tau_lbda; + int num_move_geo_updown_lbda_sigma; + int num_move_phyrex_lbda; + int num_move_phyrex_mu; + int num_move_phyrex_rad; + int num_move_phyrex_indel_disk; + int num_move_phyrex_move_disk_ct; + int num_move_phyrex_move_disk_ud; + int num_move_phyrex_swap_disk; + int num_move_phyrex_indel_hit; + int num_move_phyrex_spr; + int num_move_phyrex_spr_local; + int num_move_phyrex_scale_times; + int num_move_phyrex_ldscape_lim; + int num_move_phyrex_sigsq; + int num_move_phyrex_sim; + int num_move_phyrex_traj; + int num_move_phyrex_indel_disk_serial; + int num_move_phyrex_sim_plus; + int num_move_phyrex_indel_hit_serial; + int num_move_phyrex_ldsk_and_disk; + int num_move_phyrex_ldsk_multi; + int num_move_phyrex_disk_multi; + int num_move_phyrex_ldsk_given_disk; + int num_move_phyrex_disk_given_ldsk; + int num_move_phyrex_add_remove_jump; + int num_move_clade_change; + int num_move_phyrex_ldsk_tip_to_root; + + int nd_t_digits; + int *monitor; + + char *out_filename; + + time_t t_beg; + time_t t_cur; + time_t t_last_print; + + FILE *out_fp_stats; + FILE *out_fp_trees; + FILE *out_fp_means; + FILE *out_fp_last; + FILE *out_fp_constree; + FILE *in_fp_par; + + int *adjust_tuning; + int n_moves; + int move_idx; + int randomize; + int norm_freq; + int run; + int chain_len; + int sample_interval; + int chain_len_burnin; + int print_every; + int is_burnin; + int max_lag; + + phydbl max_tune; + phydbl min_tune; + + phydbl *sampled_val; + int sample_size; + int sample_num; + phydbl *ess; + int *ess_run; + int *start_ess; + phydbl *mode; + int always_yes; /* Always accept proposed move (as long as log-likelihood > UNLIKELY) */ + int is; /* Importance sampling? Yes or NO */ +}t_mcmc; + +/*!********************************************************/ + +typedef struct __Tpart { + int *ns; /*! number of states for each partition (e.g., 2, 4, 3) */ + int *cum_ns; /*! cumulative number of states (e.g., 0, 2, 6) */ + int ns_max; /*! maximum number of states */ + int ns_min; /*! minimum number of states */ + int n_partitions; /*! number of partitions */ + struct __Eigen *eigen; +}part; + +/*!********************************************************/ + +typedef struct __Tnexcom { + char *name; + int nparm; + int nxt_token_t; + int cur_token_t; + struct __Tnexparm **parm; +}nexcom; + +/*!********************************************************/ + +typedef struct __Tnexparm { + char *name; + char *value; + int nxt_token_t; + int cur_token_t; + int (*fp)(char *, struct __Tnexparm *, struct __Option *); + struct __Tnexcom *com; +}nexparm; + +/*!********************************************************/ + +typedef struct __ParamInt { + int val; +}t_param_int; + +/*!********************************************************/ + +typedef struct __ParamDbl { + phydbl val; +}t_param_dbl; + +/*!********************************************************/ + +typedef struct __XML_node { + + struct __XML_attr *attr; // Pointer to the first element of a list of attributes + int n_attr; // Number of attributes + struct __XML_node *next; // Next sibling + struct __XML_node *prev; // Previous sibling + struct __XML_node *parent; // Parent of this node + struct __XML_node *child; // Child of this node + char *id; + char *name; + char *value; + struct __Generic_Data_Structure *ds; // Pointer to a data strucuture. Can be a scalar, a vector, anything. +}xml_node; + +/*!********************************************************/ + +typedef struct __Generic_Data_Structure { + void *obj; + struct __Generic_Data_Structure *next; +}t_ds; + + +/*!********************************************************/ + +typedef struct __XML_attr { + char *name; + char *value; + struct __XML_attr *next; // Next attribute + struct __XML_attr *prev; // Previous attribute +}xml_attr; + +/*!********************************************************/ + +typedef struct __Calibration { + struct __Calibration *next; // Next calibration + struct __Calibration *prev; // Previous calibration + struct __Clade **clade_list; + + phydbl *alpha_proba_list; // list of alpha proba, one for each clade in clade_list + + int current_clade_idx; // index of the clade the calibration time interval currently applies to + int clade_list_size; + + phydbl lower; // lower bound + phydbl upper; // upper bound + + short int is_primary; // Is it a primary or secondary calibration interval? + + char *id; // calibration ID +}t_cal; + +/*!********************************************************/ + +typedef struct __Clade{ + char *id; + struct __Node **tip_list; // list of tips defining the clade + char **tax_list; // list of names of tips defining the clade + int n_tax; // number of taxa in the clade + struct __Node *target_nd; // The node this calibration applies to +}t_clad; + +/*!********************************************************/ + +typedef struct __Phylogeo{ + phydbl *cov; // Covariance of migrations (n_dim x n_dim) + phydbl *r_mat; // R matrix. Gives the rates of migrations between locations. See article. + phydbl *f_mat; // F matrix. See article. + int *occup; // Vector giving the number of lineages that occupy each location + int *idx_loc; // Index of location for each lineage + int *idx_loc_beneath; // Gives the index of location occupied beneath each node in the tree + int ldscape_sz; // Landscape size: number of locations + int n_dim; // Dimension of the data (e.g., longitude + lattitude -> n_dim = 2) + int update_fmat; + struct __Geo_Coord **coord_loc; // Coordinates of the observed locations + + phydbl sigma; // Dispersal parameter + phydbl min_sigma; + phydbl max_sigma; + phydbl sigma_thresh; // beyond sigma_thresh, there is no dispersal bias. + + phydbl lbda; // Competition parameter + phydbl min_lbda; + phydbl max_lbda; + + phydbl c_lnL; + + struct __Node **sorted_nd; // Table of nodes sorted wrt their heights. + + phydbl tau; // overall migration rate parameter + phydbl min_tau; + phydbl max_tau; + + phydbl dum; // dummy parameter use to assess non-identifiability issues + phydbl min_dum; + phydbl max_dum; + + +}t_geo; + +/*!********************************************************/ +// Structure for the Etheridge-Barton migration/reproduction model +typedef struct __Migrep_Model{ + struct __Geo_Coord *lim_up; // max longitude and lattitude + struct __Geo_Coord *lim_do; // min longitude and lattitude + struct __SampArea *samp_area; + + int name; + int n_dim; + int safe_phyrex; + int max_num_of_intervals; + int update_rad; + + phydbl lbda; // rate at which events occur + phydbl min_lbda; // min of rate at which events occur + phydbl max_lbda; // max of rate at which events occur + phydbl prior_param_lbda; // parameter of the parameter for the prior on lbda + + phydbl mu; // per-capita and per event death probability + phydbl min_mu; // min of per-capita and per event death probability + phydbl max_mu; // max of per-capita and per event death probability + phydbl prior_param_mu; // parameter of the parameter for the prior on mu + + phydbl rad; // radius of the migrep disk + phydbl min_rad; // min of radius of the migrep disk + phydbl max_rad; // max of radius of the migrep disk + phydbl prior_param_rad; // parameter of the parameter for the prior on radius + + phydbl sigsq; // parent to offspring distance variance (i.e., gene flow) parameter. + phydbl min_sigsq; // min + phydbl max_sigsq; // max + phydbl prior_param_sigsq; // parameter of the parameter for the prior + + phydbl rho; // intensity parameter of the Poisson point processs + phydbl gen_cal_time; // duration of one generation in calendar time unit + + + phydbl c_lnL; // current value of log-likelihood + phydbl c_ln_prior_rad; // current value of log prior for the prior on radius + phydbl c_ln_prior_lbda; // current value of log prior for the prior on lbda + phydbl c_ln_prior_mu; // current value of log prior for the prior on mu + phydbl c_ln_prior_sigsq; // current value of log prior for the prior on sigsq=4.pi.lbda.mu.rad^4 + + phydbl soft_bound_area; + + +}t_phyrex_mod; + +/*!********************************************************/ + +typedef struct __Disk_Event{ + struct __Geo_Coord *centr; + phydbl time; + struct __Disk_Event *next; + struct __Disk_Event *prev; + struct __Lindisk_Node **ldsk_a; // array of lindisk nodes corresponding to this disk event. + int n_ldsk_a; // size of ldsk_a. + struct __Lindisk_Node *ldsk; + struct __Migrep_Model *mmod; + char *id; + + phydbl c_lnL; + short int age_fixed; // time is fixed for disks corresponding to samples. +}t_dsk; + +/*!********************************************************/ + +typedef struct __Geo_Coord{ + phydbl *lonlat; /* longitude-latitude vector */ + int dim; + char *id; + struct __Geo_Coord *cpy; /* keep a copy of this coordinate */ + +}t_geo_coord; + +/*!********************************************************/ + +typedef struct __Lindisk_Node{ + struct __Disk_Event *disk; + struct __Lindisk_Node **next; + struct __Lindisk_Node *prev; + struct __Geo_Coord *coord; + struct __Geo_Coord *cpy_coord; + short int is_hit; + int n_next; + struct __Node *nd; +}t_ldsk; + +/*!********************************************************/ + +typedef struct __Polygon{ + struct __Geo_Coord **poly_vert; /* array of polygon vertex coordinates */ + int n_poly_vert; /* number of vertices */ +}t_poly; + +/*!********************************************************/ + +typedef struct __SampArea { + int n_poly; /* Number of polygons making the sampling area */ + t_poly **a_poly; /* Polygons making the sampling area */ +}t_sarea; + + +/*!********************************************************/ + +typedef struct __JSON_KeyVal { + char *key; + char *value; + struct __JSON_Object *object; + struct __JSON_Array *array; + struct __JSON_KeyVal *next; +}json_kv; + +/*!********************************************************/ + +typedef struct __JSON_Object { + struct __JSON_KeyVal *kv; + struct __JSON_Object *next; +}json_o; + +/*!********************************************************/ + +typedef struct __JSON_Array { + struct __JSON_Object *object; +}json_a; + +/*!********************************************************/ + + +typedef struct __Label{ + char *key; + char *val; + char sep; + struct __Label *next; +}t_label; + + + + +/*!********************************************************/ +/*!********************************************************/ +/*!********************************************************/ + +void Unroot_Tree(char **subtrees); +void Set_Edge_Dirs(t_edge *b,t_node *a,t_node *d,t_tree *tree); +void Init_Nexus_Format(nexcom **com); +void Restrict_To_Coding_Position(align **data,option *io); void Uppercase(char *ch); -allseq *Compact_Seq(seq **data,option *input); -allseq *Compact_CSeq(allseq *data,model *mod); -void Get_Base_Freqs(allseq *data); -void Get_AA_Freqs(allseq *data); -arbre *Read_Tree_File(FILE *fp_input_tree); -void Connect_Edges_To_Nodes(node *a,node *d,arbre *tree,int *cur); +void Lowercase(char *ch); +calign *Compact_Data(align **data,option *io); +calign *Compact_Cdata(calign *data,option *io); +void Traverse_Prefix_Tree(int site,int seqnum,int *patt_num,int *n_patt,align **data,option *io,pnode *n); +pnode *Create_Pnode(int size); +void Get_Base_Freqs(calign *data); +void Get_AA_Freqs(calign *data); +void Swap_Nodes_On_Edges(t_edge *e1,t_edge *e2,int swap,t_tree *tree); +void Connect_Edges_To_Nodes_Recur(t_node *a,t_node *d,t_tree *tree); +void Connect_One_Edge_To_Two_Nodes(t_node *a,t_node *d,t_edge *b,t_tree *tree); +void Update_Dirs(t_tree *tree); void Exit(char *message); void *mCalloc(int nb,size_t size); void *mRealloc(void *p,int nb,size_t size); -/* arbre *Make_Light_Tree_Struct(int n_otu); */ -int Sort_Phydbl_Decrease(const void *a, const void *b); -void Qksort(phydbl *A,int ilo,int ihi); -void Print_Site(allseq *alldata,int num,int n_otu,char *sep,int stepsize); -void Print_Seq(seq **data,int n_otu); -void Print_CSeq(FILE *fp,allseq *alldata); -void Order_Tree_Seq(arbre *tree,seq **data); -void Order_Tree_CSeq(arbre *tree,allseq *data); -matrix *Make_Mat(int n_otu); -void Init_Mat(matrix *mat,allseq *data); -void Print_Dist(matrix *mat); -void Print_Node(node *a,node *d,arbre *tree); -void Share_Lk_Struct(arbre *t_full,arbre *t_empt); -void Init_Constant(); -void Print_Mat(matrix *mat); -int Sort_Edges_NNI_Score(arbre *tree, edge **sorted_edges, int n_elem); -void NNI(arbre *tree, edge *b_fcus, int do_swap); -void Swap(node *a,node *b,node *c,node *d,arbre *tree); -void Update_All_Partial_Lk(edge *b_fcus,arbre *tree); -void Update_SubTree_Partial_Lk(edge *b_fcus,node *a,node *d,arbre *tree); -allseq *Make_Cseq(int n_otu, int crunch_len, int init_len, char **sp_names); -allseq *Copy_Cseq(allseq *ori, int len, int ns); -optimiz *Alloc_Optimiz(); +int Sort_Phydbl_Decrease(const void *a,const void *b); +void Qksort_Int(int *A,int *B,int ilo,int ihi); +void Qksort(phydbl *A,phydbl *B,int ilo,int ihi); +void Qksort_Matrix(phydbl **A,int col,int ilo,int ihi); +void Order_Tree_Seq(t_tree *tree,align **data); +char *Add_Taxa_To_Constraint_Tree(FILE *fp,calign *cdata); +void Check_Constraint_Tree_Taxa_Names(t_tree *tree,calign *cdata); +void Order_Tree_CSeq(t_tree *tree,calign *cdata); +void Init_Mat(matrix *mat,calign *data); +void Copy_Tax_Names_To_Tip_Labels(t_tree *tree,calign *data); +void Share_Lk_Struct(t_tree *t_full,t_tree *t_empt); +void Share_Spr_Struct(t_tree *t_full,t_tree *t_empt); +void Share_Pars_Struct(t_tree *t_full,t_tree *t_empt); +int Sort_Edges_NNI_Score(t_tree *tree,t_edge **sorted_edges,int n_elem); +int Sort_Edges_Depth(t_tree *tree,t_edge **sorted_edges,int n_elem); +void NNI(t_tree *tree,t_edge *b_fcus,int do_swap); +void NNI_Pars(t_tree *tree,t_edge *b_fcus,int do_swap); +void Swap(t_node *a,t_node *b,t_node *c,t_node *d,t_tree *tree); +void Update_SubTree_Partial_Lk(t_edge *b_fcus,t_node *a,t_node *d,t_tree *tree); +void Copy_Seq_Names_To_Tip_Labels(t_tree *tree,calign *data); +calign *Copy_Cseq(calign *ori,option *io); int Filexists(char *filename); -FILE *Openfile(char *filename,int mode); -void Print_Fp_Out(FILE *fp_out, time_t t_beg, time_t t_end, arbre *tree, option *input, int n_data_set, int num_rand_tree); -void Print_Fp_Out_Lines(FILE *fp_out,time_t t_beg,time_t t_end,arbre *tree,option *input,int n_data_set); -matrix *K80_dist(allseq *data,phydbl g_shape); -matrix *JC69_Dist(allseq *data,model *mod); -matrix *Hamming_Dist(allseq *data,model *mod); +int Is_Invar(int patt_num,int stepsize,int datatype,calign *data); int Is_Ambigu(char *state,int datatype,int stepsize); -void Check_Ambiguities(allseq *data,int datatype,int stepsize); +void Check_Ambiguities(calign *data,int datatype,int stepsize); +int Get_State_From_Ui(int ui,int datatype); int Assign_State(char *c,int datatype,int stepsize); -void Bootstrap(arbre *tree); -void Br_Len_Involving_Invar(arbre *tree); -void Br_Len_Not_Involving_Invar(arbre *tree); -void Getstring_Stdin(char *file_name); -void Print_Freq(arbre *tree); -phydbl Num_Derivatives_One_Param(phydbl(*func)(arbre *tree),arbre *tree,phydbl f0,phydbl *param,phydbl stepsize,phydbl *err,int precise); -void Num_Derivative_Several_Param(arbre *tree,phydbl *param,int n_param,phydbl stepsize,phydbl(*func)(arbre *tree),phydbl *derivatives); +char Reciproc_Assign_State(int i_state,int datatype); +int Assign_State_With_Ambiguity(char *c,int datatype,int stepsize); +void Clean_Tree_Connections(t_tree *tree); +void Bootstrap(t_tree *tree); +void Br_Len_Involving_Invar(t_tree *tree); +void Br_Len_Not_Involving_Invar(t_tree *tree); +void Getstring_Stdin(char *s); +phydbl Num_Derivatives_One_Param(phydbl (*func)(t_tree *tree), t_tree *tree, + phydbl f0, phydbl *param, int which, int n_param, phydbl stepsize, int logt, + phydbl *err, int precise, int is_positive); +phydbl Num_Derivatives_One_Param_Nonaligned(phydbl (*func)(t_tree *tree), t_tree *tree, + phydbl f0, phydbl **param, int which, int n_param, phydbl stepsize, int logt, + phydbl *err, int precise, int is_positive); +int Num_Derivative_Several_Param(t_tree *tree,phydbl *param,int n_param,phydbl stepsize,int logt,phydbl(*func)(t_tree *tree),phydbl *derivatives, int is_positive); +int Num_Derivative_Several_Param_Nonaligned(t_tree *tree, phydbl **param, int n_param, phydbl stepsize, int logt, + phydbl (*func)(t_tree *tree), phydbl *derivatives, int is_positive); int Compare_Two_States(char *state1,char *state2,int state_size); void Copy_One_State(char *from,char *to,int state_size); -model *Make_Model_Basic(); -void Make_Model_Complete(model *mod); -model *Copy_Model(model *ori); -void Set_Defaults_Input(option *input); -void Set_Defaults_Model(model *mod); -void Set_Defaults_Optimiz(optimiz *s_opt); -void Copy_Optimiz(optimiz *ori,optimiz *cpy); -void Get_Bip(node *a,node *d,arbre *tree); -void Alloc_Bip(arbre *tree); +void Copy_Dist(phydbl **cpy,phydbl **orig,int n); +t_mod *Copy_Model(t_mod *ori); +void Record_Model(t_mod *ori,t_mod *cpy); +void Set_Defaults_Input(option *io); +void Set_Defaults_Model(t_mod *mod); +void Set_Defaults_Optimiz(t_opt *s_opt); +void Test_Node_Table_Consistency(t_tree *tree); +void Get_Bip(t_node *a,t_node *d,t_tree *tree); +void Alloc_Bip(t_tree *tree); int Sort_Phydbl_Increase(const void *a,const void *b); int Sort_String(const void *a,const void *b); -void Compare_Bip(arbre *tree1,arbre *tree2); -void Test_Multiple_Data_Set_Format(option *input); +int Compare_Bip(t_tree *tree1,t_tree *tree2,int on_existing_edges_only); +void Compare_Bip_Distance(t_tree *tree1,t_tree *tree2); +void Match_Tip_Numbers(t_tree *tree1,t_tree *tree2); +void Test_Multiple_Data_Set_Format(option *io); int Are_Compatible(char *statea,char *stateb,int stepsize,int datatype); -void Hide_Ambiguities(allseq *data); -void Print_Site_Lk(arbre *tree, FILE *fp); -arbrelist *Make_Tree_List(int n_trees); -option *Make_Input(); -arbre *Make_Tree(); -void Make_All_Tree_Nodes(arbre *tree); -void Make_All_Tree_Edges(arbre *tree); -void Copy_Tax_Names_To_Tip_Labels(arbre *tree, allseq *data); -arbre *Make_And_Init_Tree(allseq *data); -void Connect_Edges_To_Nodes_Recur(node *a, node *d, arbre *tree); -void Connect_One_Edge_To_Two_Nodes(node *a, node *d, edge *b, arbre *tree); -arbre *Make_Tree_From_Scratch(int n_otu, allseq *data); -arbrelist *Make_Treelist(int list_size); -void Put_Subtree_In_Dead_Objects(node *a, node *d, arbre *tree); -void Prune_Subtree(node *a, node *d, edge **target, edge **residual, arbre *tree); -void Reassign_Node_Nums(node *a, node *d, int *curr_ext_node, int *curr_int_node, arbre *tree); -void Copy_Tree_Topology_With_Labels(arbre *ori, arbre *cpy); -void Reassign_Edge_Nums(node *a, node *d, int *curr_br, arbre *tree); -void Init_Node_Light(node *n, int num); -void Make_All_Edge_Dirs(node *a, node *d, arbre *tree); -void Get_List_Of_Reachable_Tips(arbre *tree); -void Get_List_Of_Reachable_Tips_Post(node *a, node *d, arbre *tree); -void Get_List_Of_Reachable_Tips_Pre(node *a, node *d, arbre *tree); -void Make_List_Of_Reachable_Tips(arbre *tree); -void Graft_Subtree(edge *target, node *link, edge *add_br, arbre *tree); -int Get_Subtree_Size(node *a, node *d); -void Pull_Subtree_From_Dead_Objects(node *a, node *d, arbre *tree); -void Make_Edge_NNI(edge *b); -nni *Make_NNI(); -void Init_NNI(nni *a_nni); -void Insert(arbre *tree); -void Connect_Two_Nodes(node *a, node *d); -void Get_List_Of_Target_Edges(node *a, node *d, edge **list, int *list_size, arbre *tree); -void Fix_All(arbre *tree); -void Record_Br_Len(arbre *tree); -void Restore_Br_Len(arbre *tree); -void Get_Dist_Btw_Edges(node *a, node *d, arbre *tree); -void Detect_Polytomies(edge *b, phydbl l_thresh, arbre *tree); -int Compare_List_Of_Reachable_Tips(node **list1, int size_list1, node **list2, int size_list2); -void Find_Mutual_Direction(node *n1, node *n2, int *dir_n1_to_n2, int *dir_n2_to_n1); -void Fill_Dir_Table(arbre *tree); -void Get_List_Of_Nodes_In_Polytomy(node *a, node *d, node ***list, int *size_list); -void NNI_Polytomies(arbre *tree, edge *b_fcus, int do_swap); -void Check_Path(node *a, node *d, node *target, arbre *tree); -void Get_List_Of_Adjacent_Targets(node *a, node *d, node ***node_list, edge ***edge_list, int *list_size); -void Sort_List_Of_Adjacent_Targets(edge ***list, int list_size); -void Speed_Spr(arbre *tree); -void Speed_Spr_Loop(arbre *tree); -void Make_Spr_List(arbre *tree); -void Init_One_Spr(spr *a_spr); -spr *Make_One_Spr(arbre *tree); -int Spr(phydbl init_lnL, arbre *tree); -int Spr_Recur(node *a, node *d, arbre *tree); -int Test_All_Spr_Targets(edge *pulled, node *link, arbre *tree); -node *Common_Nodes_Btw_Two_Edges(edge *a, edge *b); -void Make_Site_Lk_Backup(arbre *tree); -int KH_Test(phydbl *site_lk_m1, phydbl *site_lk_M2, arbre *tree); -void Store_P_Lk(phydbl ****ori, phydbl ****cpy, arbre *tree); -void Select_Compatible_Spr_Moves(arbre *tree); -void Triple_Dist(node *a, arbre *tree); -void Make_Symmetric(phydbl **F, int n); -void Round_Down_Freq_Patt(phydbl **F, arbre *tree); -phydbl Get_Sum_Of_Cells(phydbl *F, arbre *tree); -void Divide_Cells(phydbl **F, phydbl div, arbre *tree); -void Divide_Mat_By_Vect(phydbl **F, phydbl *vect, int size); -void Multiply_Mat_By_Vect(phydbl **F, phydbl *vect, int size); -void Triple_Dist_Recur(node *a, node *d, arbre *tree); -ttriplet *Make_Triplet_Struct(model *mod); -void Fast_Br_Len(edge *b, arbre *tree); -void Fast_Br_Len_Recur(node *a, node *d, edge *b, arbre *tree); -void Print_Tree(FILE *fp, arbre *tree); -int Check_Spr_Move_Validity(spr *this_spr_move, arbre *tree); -void Found_In_Subtree(node *a, node *d, node *target, int *match, arbre *tree); -void Randomize_Spr_List(arbre *tree); -void Test_One_Spr_Target_Recur(node *a, node *d, edge *pulled, node *link, edge *residual, arbre *tree); -phydbl Test_One_Spr_Target(edge *target, edge *arrow, node *link, edge *residual, arbre *tree); -void Apply_Spr_Moves_One_By_One(arbre *tree); -int Try_One_Spr_Move_Triple(spr *move, arbre *tree); -int Try_One_Spr_Move_Full(spr *move, arbre *tree); -void Make_Best_Spr(arbre *tree); -void Random_Tree(arbre *tree); -void Copy_Dist(phydbl **cpy, phydbl **orig, int n); -eigen *Make_Eigen_Struct(model *mod); -void Random_Spr(int n_moves, arbre *tree); -void Random_NNI(int n_moves, arbre *tree); -void Make_Edge_Pars(edge *b, arbre *tree); -void Include_One_Spr_To_List_Of_Spr(spr *move, arbre *tree); -void Reset_Spr_List(arbre *tree); -void Make_Tree_Path(arbre *tree); -int Evaluate_List_Of_Regraft_Pos_Triple(spr **spr_list, int list_size, arbre *tree); -void Share_Pars_Struct(arbre *t_full, arbre *t_empt); -void Share_Spr_Struct(arbre *t_full, arbre *t_empt); -void Share_List_Of_Reachable_Tips_Struct(arbre *t_full, arbre *t_empt); -void Clean_Tree_Connections(arbre *tree); -void Print_Settings(option *input); +void Hide_Ambiguities(calign *data); +void Copy_Tree(t_tree *ori, t_tree *cpy); +void Prune_Subtree(t_node *a,t_node *d,t_edge **target,t_edge **residual,t_tree *tree); +void Graft_Subtree(t_edge *target, t_node *link, t_node *link_daughter, t_edge *residual, t_node *target_nd, t_tree *tree); +void Reassign_Node_Nums(t_node *a,t_node *d, unsigned int *curr_ext_node, unsigned int *curr_int_node,t_tree *tree); +void Reassign_Edge_Nums(t_node *a,t_node *d,int *curr_br,t_tree *tree); +void Find_Mutual_Direction(t_node *n1,t_node *n2,short int *dir_n1_to_n2,short int *dir_n2_to_n1); +void Update_Dir_To_Tips(t_node *a,t_node *d,t_tree *tree); +void Fill_Dir_Table(t_tree *tree); +int Get_Subtree_Size(t_node *a,t_node *d); +void Init_Eigen_Struct(eigen *this); +phydbl Triple_Dist(t_node *a,t_tree *tree); +phydbl Triple_Dist_Approx(t_node *a, t_edge *b, t_tree *tree); +void Make_Symmetric(phydbl **F,int size); +void Divide_Mat_By_Vect(phydbl **F,phydbl *vect,int size); +void Found_In_Subtree(t_node *a,t_node *d,t_node *target,int *match,t_tree *tree); +void Get_List_Of_Target_Edges(t_node *a,t_node *d,t_edge **list,int *list_size,t_tree *tree); +void Fix_All(t_tree *tree); +void Record_Br_Len(t_tree *tree); +void Restore_Br_Len(t_tree *tree); +void Get_Dist_Btw_Edges(t_node *a,t_node *d,t_tree *tree); +void Detect_Polytomies(t_edge *b,phydbl l_thresh,t_tree *tree); +void Get_List_Of_Nodes_In_Polytomy(t_node *a,t_node *d,t_node ***list,int *size_list); +void Check_Path(t_node *a,t_node *d,t_node *target,t_tree *tree); +void Connect_Two_Nodes(t_node *a,t_node *d); +void Get_List_Of_Adjacent_Targets(t_node *a, t_node *d, t_node ***node_list, t_edge ***edge_list, int *list_size, int curr_depth, int max_depth); +void Sort_List_Of_Adjacent_Targets(t_edge ***list,int list_size); +t_node *Common_Nodes_Btw_Two_Edges(t_edge *a,t_edge *b); +int KH_Test(phydbl *site_lk_M1,phydbl *site_lk_M2,t_tree *tree); +void Random_Tree(t_tree *tree); +void Reorganize_Edges_Given_Lk_Struct(t_tree *tree); +void Random_NNI(int n_moves,t_tree *tree); void Fill_Missing_Dist(matrix *mat); -void Fill_Missing_Dist_XY(int x, int y, matrix *mat); -phydbl Least_Square_Missing_Dist_XY(int x, int y, phydbl dxy, matrix *mat); -void Update_Dirs(arbre *tree); -void Print_Banner(FILE *fp); -void Qksort_matrix(phydbl **A, int col, int ilo, int ihi); -void Check_Memory_Amount(arbre *tree); -int Get_State_From_P_Lk(phydbl *p_lk, arbre *tree); -int Get_State_From_P_Pars(short int *p_pars, arbre *tree); -void Unroot_Tree(char **subtrees); -void Print_Lk(arbre *tree, char *string); -void Print_Pars(arbre *tree); -void Print_Lk_And_Pars(arbre *tree); -void Check_Dirs(arbre *tree); -void Warn_And_Exit(char *s); -void Print_Data_Set_Number(option *input, FILE *fp); -void Compare_Bip_On_Existing_Edges(int discard, arbre *tree1, arbre *tree2); -void NNI_Pars(arbre *tree, edge *b_fcus, int do_swap); -void Best_Spr(arbre *tree); -void Evaluate_One_Regraft_Pos_Triple(spr *move, arbre *tree); -int Get_State_From_Ui(int ui, int datatype); -void Read_Qmat(double *daa, phydbl *pi, FILE *fp); -void Traverse_Prefix_Tree(int site, int seqnum, int *patt_num, int *n_patt, seq **data, option *input, pnode *n); -pnode *Create_Pnode(int size); -int Assign_State_With_Ambiguity(char *c, int datatype, int stepsize); -void Randomize_Sequence_Order(allseq *data); -void Dist_To_Node_Pre(node *a, node *d, edge *b, arbre *tree); -void Add_Root(edge *target, arbre *tree); -int Is_Invar(int patt_num, int stepsize, int datatype, allseq *data); -void Update_Root_Pos(arbre *tree); -void Read_Branch_Label(char *sub_part, char *full_part, edge *b); -void Read_Branch_Length(char *s_d, char *s_a, arbre *tree); -void Read_Node_Name(node *d, char *s_tree_d, arbre *tree); -arbre *Generate_Random_Tree_From_Scratch(int n_otu); -void Random_Lineage_Rates(node *a, node *d, edge *b, phydbl stick_prob, phydbl *rates, int curr_rate, int n_rates, arbre *tree); -edge *Find_Edge_With_Label(char *label, arbre *tree); -void Print_Square_Matrix_Generic(int n, phydbl *mat); -int Pick_State(int n, phydbl *prob); -char Reciproc_Assign_State(int i_state, int datatype); -void Evolve(allseq *data, model *mod, arbre *tree); -int Pick_State(int n, phydbl *prob); -void Evolve_Recur(node *a, node *d, edge *b, int a_state, int r_class, int site_num, allseq *gen_data, model *mod, arbre *tree); -void Site_Diversity(arbre *tree); -void Site_Diversity_Post(node *a, node *d, edge *b, arbre *tree); -void Site_Diversity_Pre(node *a, node *d, edge *b, arbre *tree); -void Subtree_Union(node *n, edge *b_fcus, arbre *tree); -void Binary_Decomposition(int value, int *bit_vect, int size); -void Print_Diversity(FILE *fp, arbre *tree); -void Print_Diversity_Header(FILE *fp, arbre *tree); -void Print_Diversity_Pre(node *a, node *d, edge *b, FILE *fp, arbre *tree); -void Make_New_Edge_Label(edge *b); -void Print_Qmat_AA(double *daa, phydbl *pi); -trate *Make_Rate_Struct(arbre *tree); -void Init_Rate_Struct(trate *rates, arbre *tree); -phydbl CDF_Normal(phydbl x, phydbl mean, phydbl var); -phydbl CDF_Gamma(phydbl x, phydbl mean, phydbl var); -double Uni(); -double Ahrensdietergamma(double alpha); -double Rgamma(double shape, double scale); -double Rexp(double lambda); -phydbl Univariate_Kernel_Density_Estimate(phydbl where, phydbl *x, int n); -phydbl Var(phydbl *x, int n); -phydbl Mean(phydbl *x, int n); -phydbl Multivariate_Kernel_Density_Estimate(phydbl *where, phydbl **x, int sample_size, int vect_size); +void Fill_Missing_Dist_XY(int x,int y,matrix *mat); +phydbl Least_Square_Missing_Dist_XY(int x,int y,phydbl dxy,matrix *mat); +void Check_Memory_Amount(t_tree *tree); +int Get_State_From_P_Lk(phydbl *p_lk,int pos,t_tree *tree); +int Get_State_From_P_Pars(short int *p_pars,int pos,t_tree *tree); +void Check_Dirs(t_tree *tree); +void Warn_And_Exit(const char *s); +void Randomize_Sequence_Order(calign *cdata); +void Update_Root_Pos(t_tree *tree); +void Add_Root(t_edge *target,t_tree *tree); +void Update_Ancestors(t_node *a,t_node *d,t_tree *tree); +#if (defined PHYTIME || defined SERGEII) +t_tree *Generate_Random_Tree_From_Scratch(int n_otu,int rooted); +#endif +void Random_Lineage_Rates(t_node *a,t_node *d,t_edge *b,phydbl stick_prob,phydbl *rates,int curr_rate,int n_rates,t_tree *tree); +t_edge *Find_Edge_With_Label(char *label,t_tree *tree); +void Evolve(calign *data, t_mod *mod, int first_site_pos, t_tree *tree); +int Pick_State(int n,phydbl *prob); +void Evolve_Recur(t_node *a,t_node *d,t_edge *b,int a_state,int r_class,int site_num,calign *gen_data,t_mod *mod,t_tree *tree); +void Site_Diversity(t_tree *tree); +void Site_Diversity_Post(t_node *a,t_node *d,t_edge *b,t_tree *tree); +void Site_Diversity_Pre(t_node *a,t_node *d,t_edge *b,t_tree *tree); +void Subtree_Union(t_node *n,t_edge *b_fcus,t_tree *tree); +void Binary_Decomposition(int value,int *bit_vect,int size); +void Print_Diversity_Header(FILE *fp,t_tree *tree); +void Best_Of_NNI_And_SPR(t_tree *tree); +int Polint(phydbl *xa,phydbl *ya,int n,phydbl x,phydbl *y,phydbl *dy); +t_tree *Dist_And_BioNJ(calign *cdata,t_mod *mod,option *io); +void Add_BioNJ_Branch_Lengths(t_tree *tree, calign *cdata, t_mod *mod, matrix *mat); +char *Bootstrap_From_String(char *s_tree,calign *cdata,t_mod *mod,option *io); +char *aLRT_From_String(char *s_tree,calign *cdata,t_mod *mod,option *io); +void Find_Common_Tips(t_tree *tree1,t_tree *tree2); +phydbl Get_Tree_Size(t_tree *tree); +void Dist_To_Root_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void Dist_To_Root(t_tree *tree); +char *Basename(char *path); +t_node *Find_Lca_Pair_Of_Nodes(t_node *n1,t_node *n2,t_tree *tree); +t_node *Find_Lca_Clade(t_node **node_list,int node_list_size,t_tree *tree); +int Get_List_Of_Ancestors(t_node *ref_node,t_node **list,int *size,t_tree *tree); +int Edge_Num_To_Node_Num(int edge_num,t_tree *tree); +void Branch_Lengths_To_Rate_Lengths(t_tree *tree); +void Branch_Lengths_To_Rate_Lengths_Pre(t_node *a,t_node *d,t_tree *tree); +int Find_Clade(char **tax_name_list,int list_size,t_tree *tree); +void Find_Clade_Pre(t_node *a,t_node *d,int *tax_num_list,int list_size,int *num,t_tree *tree); +t_edge *Find_Root_Edge(FILE *fp_input_tree,t_tree *tree); +void Copy_Tree_Topology_With_Labels(t_tree *ori,t_tree *cpy); +void Set_Model_Name(t_mod *mod); +void Adjust_Min_Diff_Lk(t_tree *tree); +void Translate_Tax_Names(char **tax_names,t_tree *tree); +void Skip_Comment(FILE *fp); +void Get_Best_Root_Position(t_tree *tree); +void Get_Best_Root_Position_Post(t_node *a,t_node *d,int *has_outgrp,t_tree *tree); +void Get_Best_Root_Position_Pre(t_node *a,t_node *d,t_tree *tree); +void Get_OutIn_Scores(t_node *a,t_node *d); +int Check_Sequence_Name(char *s); +int Scale_Subtree_Height(t_node *a,phydbl K,phydbl floor,int *n_nodes,t_tree *tree); +void Scale_Node_Heights_Post(t_node *a,t_node *d,phydbl K,phydbl floor,int *n_nodes,t_tree *tree); +int Scale_Subtree_Rates(t_node *a,phydbl mult,int *n_nodes,t_tree *tree); +void Check_Br_Len_Bounds(t_tree *tree); +int Scale_Subtree_Rates_Post(t_node *a,t_node *d,phydbl mult,int *n_nodes,t_tree *tree); +void Get_Node_Ranks(t_tree *tree); +void Get_Node_Ranks_Pre(t_node *a,t_node *d,t_tree *tree); +void Log_Br_Len(t_tree *tree); +phydbl Diff_Lk_Norm_At_Given_Edge(t_edge *b,t_tree *tree); +void Adjust_Variances(t_tree *tree); +phydbl Effective_Sample_Size(phydbl first_val,phydbl last_val,phydbl sum,phydbl sumsq,phydbl sumcurnext,int n); +void Rescale_Free_Rate_Tree(t_tree *tree); +phydbl Rescale_Br_Len_Multiplier_Tree(t_tree *tree); +phydbl Unscale_Br_Len_Multiplier_Tree(t_tree *tree); +phydbl Reflect(phydbl x,phydbl l,phydbl u); +int Are_Equal(phydbl a,phydbl b,phydbl eps); +int Check_Topo_Constraints(t_tree *big_tree,t_tree *small_tree); +void Prune_Tree(t_tree *big_tree,t_tree *small_tree); +void Match_Nodes_In_Small_Tree(t_tree *small_tree,t_tree *big_tree); +void Find_Surviving_Edges_In_Small_Tree(t_tree *small_tree,t_tree *big_tree); +void Find_Surviving_Edges_In_Small_Tree_Post(t_node *a,t_node *d,t_tree *small_tree,t_tree *big_tree); +void Set_Taxa_Id_Ranking(t_tree *tree); +void Get_Edge_Binary_Coding_Number(t_tree *tree); +void Make_Ancestral_Seq(t_tree *tree); +void Make_MutMap(t_tree *tree); +int Get_Mutmap_Val(int edge,int site,int mut,t_tree *tree); +void Get_Mutmap_Coord(int idx,int *edge,int *site,int *mut,t_tree *tree); +void Copy_Edge_Lengths(t_tree *to,t_tree *from); +void Init_Scalar_Dbl(scalar_dbl *p); +void Init_Scalar_Int(scalar_int *p); +void Init_Vect_Dbl(int len,vect_dbl *p); +void Init_Vect_Int(int len,vect_int *p); +char *To_Lower_String(char *in); +phydbl String_To_Dbl(char *string); +int String_To_Int(char *string); +char *To_Upper_String(char *in); +void Connect_CSeqs_To_Nodes(calign *cdata, option *io, t_tree *tree); +void Joint_Proba_States_Left_Right(phydbl *Pij, phydbl *p_lk_left, phydbl *p_lk_rght, + vect_dbl *pi, int scale_left, int scale_rght, + phydbl *F, int n, int site, t_tree *tree); +void Set_Both_Sides(int yesno, t_tree *tree); +void Set_D_States(calign *data, int datatype, int stepsize); +void Path_Length(t_node *dep, t_node *arr, phydbl *len, t_tree *tree); +phydbl *Dist_Btw_Tips(t_tree *tree); +void Best_Root_Position_IL_Model(t_tree *tree); +void Set_Br_Len_Var(t_edge *b, t_tree *tree); +void Check_Br_Lens(t_tree *tree); +void Calculate_Number_Of_Diff_States_Post(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void Calculate_Number_Of_Diff_States_Pre(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void Calculate_Number_Of_Diff_States_Core(t_node *a, t_node *d, t_edge *b, t_tree *tree); +void Calculate_Number_Of_Diff_States(t_tree *tree); +void Build_Distrib_Number_Of_Diff_States_Under_Model(t_tree *tree); +int Number_Of_Diff_States_One_Site(int site, t_tree *tree); +void Number_Of_Diff_States_One_Site_Post(t_node *a, t_node *d, t_edge *b, int site, t_tree *tree); +int Number_Of_Diff_States_One_Site_Core(t_node *a, t_node *d, t_edge *b, int site, t_tree *tree); +phydbl Get_Lk(t_tree *tree); +phydbl Get_d2Lk(t_tree *tree); +phydbl Get_dLk(t_tree *tree); +align **Make_Empty_Alignment(option *io); +void Connect_Edges_To_Nodes_Serial(t_tree *tree); +phydbl Mean_Identity(calign *data); +phydbl Pairwise_Identity(int i, int j, calign *data); +phydbl Fst(int i, int j, calign *data); +phydbl Nucleotide_Diversity(calign *data); +void Swap_Partial_Lk(t_edge *a, t_edge *b, int side_a, int side_b, t_tree *tree); +scalar_dbl **Copy_Br_Len_Var(t_tree *mixt_tree); +scalar_dbl **Copy_Br_Len(t_tree *mixt_tree); +void Transfer_Br_Len_To_Tree(scalar_dbl **bl, t_tree *tree); +void Copy_Scalar_Dbl(scalar_dbl *from, scalar_dbl *to); +scalar_dbl *Duplicate_Scalar_Dbl(scalar_dbl *from); +scalar_dbl *Read_Weights(option *io); +phydbl Scalar_Elem(int pos, scalar_dbl *scl); +int Scalar_Len(scalar_dbl *scl); +void Set_Scalar_Dbl(phydbl val, scalar_dbl *from); +void Set_Scalar_Dbl_Min_Thresh(phydbl thresh, scalar_dbl *from); +void Set_Scalar_Dbl_Max_Thresh(phydbl thresh, scalar_dbl *from); +void List_Of_Regraft_Nodes(t_node *a, t_node *d, phydbl time_thresh, t_ll *list, t_tree *tree); +void Push_Bottom_Linked_List(void *what, t_ll **list, bool remove_duplicates); +void Remove_From_Linked_List(t_ll *elem, void *val, t_ll **list); +int Linked_List_Len(t_ll *list); +void *Linked_List_Elem(int pos, t_ll *ll); +void Randomize_Tree(t_tree *tree, int n_prune_regraft); +t_ll *Get_List_Of_Reachable_Tips(t_node *a, t_node *d, t_tree *tree); +void Get_List_Of_Reachable_Tips_Post(t_node *a, t_node *d, t_ll **list, t_tree *tree); +phydbl Length_Of_Path_Between_List_Of_Tips(t_ll *tips0, t_ll *tips1, matrix *mat); +void Set_Update_Eigen_Lr(int yn, t_tree *tree); +void Set_Use_Eigen_Lr(int yn, t_tree *tree); +void Random_Walk_Along_Tree_On_Radius(t_node *a, t_node *d, t_edge *b, phydbl *radius, t_edge **target_edge, t_node **target_nd, phydbl *target_time, t_tree *tree); +void Table_Top(unsigned int width); +void Table_Row(unsigned int width); +void Table_Bottom(unsigned int width); +t_cal *Duplicate_Calib(t_cal *from); +t_clad *Duplicate_Clade(t_clad *from); +void Swap_Partial_Lk_Extra(t_edge *b, t_node *d, int whichone, t_tree *tree); +void Remove_Duplicates(calign *data, option *io, t_tree *tree); +short int Are_Sequences_Identical(align *seq1, align *seq2); +char *Mutation_Id(int mut_idx, t_tree *tree); +void Random_Tax_Idx(t_node *a, t_node *d, int *idx, t_tree *tree); +void List_Taxa_In_Clade(t_node *a, t_node *d, t_tree *tree); +void Alias_Subpatt_Pre(t_node *a, t_node *d, t_tree *tree); +void Alias_Subpatt_Post(t_node *a, t_node *d, t_tree *tree); +void Alias_One_Subpatt(t_node *a, t_node *d, t_tree *tree); +void Alias_Subpatt(t_tree *tree); +void Map_Mutations(t_node *a, t_node *d, int sa, int sd, t_edge *b, int site, int rcat, int *muttype, phydbl *muttime, int *muttax, int *n_mut, t_tree *tree); +void Set_Update_Eigen(int yesno, t_mod *mod); +int *Order_Int(const int *u, const int n); +int *Order_Dbl(const phydbl *u, const int n); +char Integer_To_IUPAC_Code(int x); +void Shuffle_Sites(const phydbl prop, align **data, const int n_otu); +void Multiply_Scalar_Dbl(phydbl mult, scalar_dbl *x); +void Insert_Duplicates(t_tree *tree); +void Get_Node_Ranks_From_Dist_To_Root(t_tree *tree); +void Get_Node_Ranks_From_Times(t_tree *tree); +void Get_Node_Ranks_From_Tip_Times(t_tree *tree); +phydbl Tree_Height(t_tree *tree); +void Post_Inflate_Times_To_Get_Reasonnable_Edge_Lengths(t_node *a, t_node *d, t_edge *b, phydbl min_l, t_tree *tree); +void Inflate_Times_To_Get_Reasonnable_Edge_Lengths(phydbl min_l, t_tree *tree); +void Refactor_Tree(t_tree *tree); +void Refactor_External(t_node *a, t_node *d, int *idx, t_tree *tree); +void Refactor_Internal(t_node *a, t_node *d, t_edge *b, int *idx_nd, int *idx_br, t_tree *tree); +int *Integer_To_Bit(int val, const int ns); +char *Bit_To_Character_String(int *bit, int ns); +t_tree *Duplicate_Tree(t_tree *ori); +matrix *K80_dist(calign *data, phydbl g_shape); +matrix *JC69_Dist(calign *data, t_mod *mod); +matrix *Hamming_Dist(calign *data, t_mod *mod); +phydbl Haversine_Distance(phydbl lon1, phydbl lat1, phydbl lon2, phydbl lat2); +phydbl Tree_Length(t_tree *tree); +void Remove_Duplicates_From_Tree(calign *data, t_tree *tree); + + +#include "xml.h" +#include "free.h" +#include "spr.h" +#include "lk.h" +#include "optimiz.h" +#include "models.h" +#include "bionj.h" +#include "simu.h" +#include "eigen.h" +#include "pars.h" +#include "alrt.h" +#include "stats.h" +#include "help.h" +#include "io.h" +#include "make.h" +#include "nexus.h" +#include "init.h" +#include "mcmc.h" +#include "ancestral.h" + +#ifdef GEO +#include "geo.h" +#endif + +#ifdef PHYREX +#include "phyrex.h" +#endif + +#ifdef MPI +#include "mpi_boot.h" +#endif + +#ifdef MG +#include "mg.h" +#endif + +#ifdef TIME +#include "times.h" +#include "rates.h" +#endif + +#ifdef _NOT_NEEDED_A_PRIORI +#include "m4.h" +#endif + #endif diff --git a/phyml/xml.c b/phyml/xml.c new file mode 100644 index 0000000..7ea0c79 --- /dev/null +++ b/phyml/xml.c @@ -0,0 +1,2716 @@ +#include "xml.h" + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +t_tree *XML_Process_Base(char *xml_filename) +{ + FILE *fp; + xml_node *root,*p_elem,*m_elem,*parent,*instance; + option *io; + void *buff; + t_mod *mod,*iomod; + t_tree *tree,*mixt_tree,*root_tree; + int select; + char *component; + int i,j,n_components; + int first_m_elem; + int class_number; + scalar_dbl **lens,**lens_var,**ori_lens,**lens_old,**lens_var_old,**ori_lens_old,**ori_lens_var,**ori_lens_var_old; + t_ds *ds; + char *outputfile; + char *alignment; + char *s; + int lens_size; + int first; + int *class_num; + + + fp = fopen(xml_filename,"r"); + if(!fp) + { + PhyML_Fprintf(stderr,"\n. Could not find the XML file '%s'.\n",xml_filename); + Exit("\n"); + } + + root = XML_Load_File(fp); + + if(!root) + { + PhyML_Fprintf(stderr,"\n. Encountered an issue while loading the XML file.\n"); + Exit("\n"); + } + + class_num = (int *)mCalloc(N_MAX_MIXT_CLASSES,sizeof(int)); + for(i=0;i 1) + { + PhyML_Fprintf(stderr,"\n. There should not more than one 'topology' node."); + PhyML_Fprintf(stderr,"\n. Found %d. Please fix your XML file",count); + Exit("\n"); + } + else if(count < 1) + { + PhyML_Fprintf(stderr,"\n. There should be at least one 'topology' node."); + PhyML_Fprintf(stderr,"\n. Found none. Please fix your XML file"); + Exit("\n"); + } + +#if defined PHYML + p_elem = XML_Search_Node_Name("phyml",NO,p_elem); +#elif defined PHYTIME + p_elem = XML_Search_Node_Name("phytime",NO,p_elem); +#endif + + if(!p_elem) + { +#if defined PHYML + PhyML_Fprintf(stderr,"\n. The 'phyml' tag is mandatory."); +#elif defined PHYTIME + PhyML_Fprintf(stderr,"\n. The 'phytime' tag is mandatory."); +#endif + PhyML_Fprintf(stderr,"\n. Please amend your XML file accordingly."); + assert(false); + } + + + /*! Input file + */ + outputfile = XML_Get_Attribute_Value(p_elem,"output.file"); + + if(!outputfile || !(strlen(outputfile)>0)) + { +#if defined PHYML + PhyML_Fprintf(stderr,"\n. The 'outputfile' attribute in 'phyml' tag is mandatory."); +#elif defined PHYTIME + PhyML_Fprintf(stderr,"\n. The 'outputfile' attribute in 'phytime' tag is mandatory."); +#endif + PhyML_Fprintf(stderr,"\n. Please amend your XML file accordingly."); + assert(false); + } + + io = (option *)Make_Input(); + Set_Defaults_Input(io); + + s = XML_Get_Attribute_Value(p_elem,"run.id"); + if(s && strlen(s)>0) + { + io->append_run_ID = YES; + strcpy(io->run_id_string,s); + } + + s = XML_Get_Attribute_Value(p_elem,"r.seed"); + if(s && strlen(s)>0) io->r_seed = (int)atoi(s); + + strcpy(io->out_file,outputfile); + strcpy(io->out_tree_file,outputfile); + strcpy(io->out_stats_file,outputfile); + + + +# if defined(PHYTIME) + strcat(io->out_tree_file,"_phytime_tree"); +# elif defined(PHYREX) + strcat(io->out_tree_file,"_phyrex_tree"); +# elif defined(PHYML) + strcat(io->out_tree_file,"_phyml_tree"); +#endif + + +# if defined(PHYTIME) + strcat(io->out_stats_file,"_phytime_stats"); +# elif defined(PHYREX) + strcat(io->out_stats_file,"_phyrex_stats"); +# elif defined(PHYML) + strcat(io->out_stats_file,"_phyml_stats"); +#endif + + + if(io->append_run_ID) { strcat(io->out_tree_file,"_"); strcat(io->out_tree_file,io->run_id_string); } + if(io->append_run_ID) { strcat(io->out_stats_file,"_"); strcat(io->out_stats_file,io->run_id_string); } + + strcat(io->out_stats_file,".txt"); + strcat(io->out_tree_file,".txt"); + + if(XML_Search_Node_Attribute_Value("add","true",NO,root) != NULL) + { + io->fp_out_tree = Openfile(io->out_tree_file,APPEND); + io->fp_out_stats = Openfile(io->out_stats_file,APPEND); + } + else + { + io->fp_out_tree = Openfile(io->out_tree_file,WRITE); + io->fp_out_stats = Openfile(io->out_stats_file,WRITE); + } + + + s = XML_Get_Attribute_Value(p_elem,"print.trace"); + + if(s) + { + select = XML_Validate_Attr_Int(s,6, + "true","yes","y", + "false","no","n"); + + if(select < 3) + { + io->print_trace = YES; + strcpy(io->out_trace_file,outputfile); + strcat(io->out_trace_file,"_phyml_trace"); + if(io->append_run_ID) { strcat(io->out_trace_file,"_"); strcat(io->out_trace_file,io->run_id_string); } + strcat(io->out_trace_file,".txt"); + io->fp_out_trace = Openfile(io->out_trace_file,1); + } + } + + + s = XML_Get_Attribute_Value(p_elem,"print.json.trace"); + + if(s) + { + select = XML_Validate_Attr_Int(s,6, + "true","yes","y", + "false","no","n"); + + if(select < 3) + { + io->print_json_trace = YES; + strcpy(io->out_json_trace_file,outputfile); + strcat(io->out_json_trace_file,"_phyml_trace"); + if(io->append_run_ID) { strcat(io->out_json_trace_file,"_"); strcat(io->out_json_trace_file,io->run_id_string); } + strcat(io->out_json_trace_file,".json"); + io->fp_out_json_trace = Openfile(io->out_json_trace_file,READWRITE); + } + } + + s = XML_Get_Attribute_Value(p_elem,"print.site.lk"); + + if(s) + { + select = XML_Validate_Attr_Int(s,6, + "true","yes","y", + "false","no","n"); + if(select < 3) io->print_site_lnl = YES; + + strcpy(io->out_lk_file,outputfile); + strcat(io->out_lk_file, "_phyml_lk"); + if(io->append_run_ID) { strcat(io->out_lk_file,"_"); strcat(io->out_lk_file,io->run_id_string); } + strcat(io->out_lk_file, ".txt"); + io->fp_out_lk = Openfile(io->out_lk_file,WRITE); + } + + + s = XML_Get_Attribute_Value(p_elem,"branch.test"); + if(s) + { + if(!strcmp(s,"aLRT")) + { + io->ratio_test = ALRTSTAT; + } + else if(!strcmp(s,"aBayes")) + { + io->ratio_test = ABAYES; + } + else if(!strcmp(s,"SH")) + { + io->ratio_test = SH; + } + else if(!strcmp(s,"no") || !strcmp(s,"none")) + { + io->ratio_test = 0; + } + else + { + PhyML_Fprintf(stderr,"\n. '%s' is not a valid option for 'branch.test'.",s); + PhyML_Fprintf(stderr,"\n. Please use 'aLRT' or 'aBayes' or 'SH'."); + Exit("\n"); + } + } + + s = XML_Get_Attribute_Value(p_elem,"quiet"); + if(s) + { + select = XML_Validate_Attr_Int(s,6, + "true","yes","y", + "false","no","n"); + if(select < 3) io->quiet = YES; + } + + s = XML_Get_Attribute_Value(p_elem,"memory.check"); + if(s) + { + select = XML_Validate_Attr_Int(s,6, + "true","yes","y", + "false","no","n"); + if(select >= 3) io->mem_question = NO; + } + + /*! Read all partitionelem nodes and mixturelem nodes in each of them + */ + do + { + p_elem = XML_Search_Node_Name("partitionelem",YES,p_elem); + + if(p_elem == NULL) break; + + buff = (option *)Make_Input(); + Set_Defaults_Input(buff); + io->next = buff; + io->next->prev = io; + + io = io->next; + if(first == YES) + { + io = io->prev; + io->next = NULL; + Free_Input(buff); + first = NO; + } + + + /*! Set the datatype (required when compressing data) + */ + char *dt = NULL; + dt = XML_Get_Attribute_Value(p_elem,"data.type"); + if(!dt) + { + PhyML_Fprintf(stderr,"\n. Please specify the type of data ('aa' or 'nt') for partition element '%s'", + XML_Get_Attribute_Value(p_elem,"id")); + PhyML_Fprintf(stderr,"\n. Syntax: 'data.type=\"aa\"' or 'data.type=\"nt\"'"); + Exit("\n"); + } + + select = XML_Validate_Attr_Int(dt,2,"aa","nt"); + switch(select) + { + case 0: + { + io->datatype = AA; + break; + } + case 1: + { + io->datatype = NT; + break; + } + default: + { + PhyML_Fprintf(stderr,"\n. Unknown data type. Must be either 'aa' or 'nt'."); + Exit("\n"); + } + } + + + char *format = NULL; + format = XML_Get_Attribute_Value(p_elem,"format"); + if(format) + { + if(!strcmp(format,"interleave") || + !strcmp(format,"interleaved")) + { + io->interleaved = YES; + } + else if(!strcmp(format,"sequential")) + { + io->interleaved = NO; + } + } + + + /*! Attach a model to this io struct + */ + io->mod = (t_mod *)Make_Model_Basic(); + Set_Defaults_Model(io->mod); + io->mod->ras->n_catg = 1; + io->mod->io = io; + iomod = io->mod; + + if(io->datatype == AA) io->mod->ns = 20; + else if(io->datatype == NT) io->mod->ns = 4; + else assert(FALSE); + + + /*! Attach an optimization structure to this model + */ + iomod->s_opt = (t_opt *)Make_Optimiz(); + Set_Defaults_Optimiz(iomod->s_opt); + + iomod->s_opt->opt_kappa = NO; + iomod->s_opt->opt_lambda = NO; + iomod->s_opt->opt_rr = NO; + iomod->s_opt->opt_subst_param = NO; + + /*! Input file + */ + alignment = XML_Get_Attribute_Value(p_elem,"file.name"); + + if(!alignment) + { + PhyML_Fprintf(stderr,"\n. 'file.name' tag is mandatory. Please amend your"); + PhyML_Fprintf(stderr,"\n. XML file accordingly."); + Exit("\n"); + } + + strcpy(io->in_align_file,alignment); + + /*! Open pointer to alignment + */ + io->fp_in_align = Openfile(io->in_align_file,READ); + + + /*! Load sequence file + */ + io->data = Get_Seq(io); + + /*! Close pointer to alignment + */ + fclose(io->fp_in_align); + + /*! Compress alignment + */ + io->cdata = Compact_Data(io->data,io); + + /*! Free uncompressed alignment + */ + Free_Seq(io->data,io->n_otu); + + /*! Create new mixture tree + */ + buff = (t_tree *)Make_Tree_From_Scratch(io->cdata->n_otu,io->cdata); + + if(mixt_tree) + { + mixt_tree->next_mixt = buff; + mixt_tree->next_mixt->prev_mixt = mixt_tree; + mixt_tree = mixt_tree->next_mixt; + mixt_tree->dp = mixt_tree->prev_mixt->dp+1; + } + else mixt_tree = buff; + + /*! Connect mixt_tree to xml struct + */ + mixt_tree->xml_root = root; + + /*! Connect mixt_tree to io struct + */ + mixt_tree->io = io; + + /*! Connect mixt_tree to model struct + */ + mixt_tree->mod = iomod; + + /*! mixt_tree is a mixture tree + */ + mixt_tree->is_mixt_tree = YES; + + /*! mixt_tree is a mixture tree + */ + mixt_tree->mod->is_mixt_mod = YES; + + /*! Connect mixt_tree to compressed data + */ + mixt_tree->data = io->cdata; + + /*! Set total number of patterns + */ + mixt_tree->n_pattern = io->cdata->crunch_len; + + /*! Remove branch lengths from mixt_tree */ + for(i=0;i<2*mixt_tree->n_otu-1;++i) + { + Free_Scalar_Dbl(mixt_tree->a_edges[i]->l); + Free_Scalar_Dbl(mixt_tree->a_edges[i]->l_old); + Free_Scalar_Dbl(mixt_tree->a_edges[i]->l_var); + Free_Scalar_Dbl(mixt_tree->a_edges[i]->l_var_old); + } + + /*! Connect last tree of the mixture for the + previous partition element to the next mixture tree + */ + if(tree) + { + tree->next = mixt_tree; + mixt_tree->prev = tree; + } + + /*! Do the same for the model + */ + if(mod) + { + mod->next = iomod; + iomod->prev = mod; + } + + if(!root_tree) root_tree = mixt_tree; + + /*! Tree size scaling factor */ + char *scale_tree = NULL; + scale_tree = XML_Get_Attribute_Value(p_elem,"optimise.tree.scale"); + + if(scale_tree) + { + int select; + + select = XML_Validate_Attr_Int(scale_tree,6, + "true","yes","y", + "false","no","n"); + + if(select < 3) mixt_tree->mod->s_opt->opt_br_len_mult = YES; + } + + scale_tree = NULL; + scale_tree = XML_Get_Attribute_Value(p_elem,"tree.scale"); + + if(scale_tree) + { + char *scale_val; + + scale_val = XML_Get_Attribute_Value(p_elem,"tree.scale"); + if(scale_val) + { + mixt_tree->mod->br_len_mult->v = String_To_Dbl(scale_val); + mixt_tree->mod->br_len_mult_unscaled->v = String_To_Dbl(scale_val); + Free(scale_val); + } + } + + /*! Process all the mixtureelem tags in this partition element + */ + n_components = 0; + m_elem = p_elem; + first_m_elem = 0; + mod = NULL; + tree = NULL; + class_number = 0; + do + { + m_elem = XML_Search_Node_Name("mixtureelem",YES,m_elem); + if(m_elem == NULL) break; + + + if(!strcmp(m_elem->name,"mixtureelem")) + { + first_m_elem++; + + /*! Rewind tree and model when processing a new mixtureelem node + */ + if(first_m_elem > 1) + { + while(tree->prev && tree->prev->is_mixt_tree == NO) { tree = tree->prev; } + while(mod->prev && mod->prev->is_mixt_mod == NO) { mod = mod->prev; } + } + + /*! Read and process model components + */ + char *list; + list = XML_Get_Attribute_Value(m_elem,"list"); + + j = 0; + for(i=0;i<(int)strlen(list);++i) if(list[i] == ',') j++; + + if(j != n_components && first_m_elem > 1) + { + PhyML_Fprintf(stderr,"\n. Discrepancy in the number of elements in nodes 'mixtureelem' partitionelem id '%s'",p_elem->id); + PhyML_Fprintf(stderr,"\n. Check 'mixturelem' node with list '%s'",list); + Exit("\n"); + } + n_components = j; + + i = j = 0; + component[0] = '\0'; + while(1) + { + if(list[j] == ',' || j == (int)strlen(list)) + { + /*! Reading a new component + */ + + if(first_m_elem == YES) /* Only true when processing the first mixtureelem node */ + { + t_tree *this_tree; + t_mod *this_mod; + + /*! Create new tree + */ + this_tree = (t_tree *)Make_Tree_From_Scratch(io->cdata->n_otu,io->cdata); + + /*! Update the number of mixtures */ + iomod->n_mixt_classes++; + + if(tree) + { + tree->next = this_tree; + tree->next->prev = tree; + } + else + { + mixt_tree->next = this_tree; + mixt_tree->next->prev = mixt_tree; + } + + tree = this_tree; + tree->mixt_tree = mixt_tree; + + + /*! Create a new model + */ + this_mod = (t_mod *)Make_Model_Basic(); + Set_Defaults_Model(this_mod); + this_mod->ras->n_catg = 1; + this_mod->ns = iomod->ns; + /*! All br_len_multiplier point to the corresponding */ + /*! parameter in the relevant mixt_tree */ + Free_Scalar_Dbl(this_mod->br_len_mult); + this_mod->br_len_mult = iomod->br_len_mult; + + Free_Scalar_Dbl(this_mod->br_len_mult_unscaled); + this_mod->br_len_mult_unscaled = iomod->br_len_mult_unscaled; + + if(mod) + { + mod->next = this_mod; + mod->next->prev = mod; + } + else + { + this_mod->prev = iomod; + } + + mod = this_mod; + if(!iomod->next) iomod->next = mod; + mod->io = io; + + mod->s_opt = (t_opt *)Make_Optimiz(); + Set_Defaults_Optimiz(mod->s_opt); + + mod->s_opt->opt_alpha = NO; + mod->s_opt->opt_pinvar = NO; + + tree->data = io->cdata; + tree->n_pattern = io->cdata->crunch_len; + tree->io = io; + tree->mod = mod; + + if(tree->n_pattern != tree->prev->n_pattern) Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + /*! Read a component */ + component[i] = '\0'; + if(j != (int)strlen(list)-1) i = 0; + + /*! Find which node this ID corresponds to + */ + instance = XML_Search_Node_ID(component,YES,root); + + if(!instance) + { + PhyML_Fprintf(stderr,"\n. Could not find a node with id: '%s'.",component); + PhyML_Fprintf(stderr,"\n. Problem with 'mixtureelem' node, list '%s'.",list); + Exit("\n"); + } + + if(!instance->parent) + { + PhyML_Fprintf(stderr,"\n. Node '%s' with id:'%s' has no parent.",instance->name,component); + Exit("\n"); + } + + parent = instance->parent; + + //////////////////////////////////////// + // SUBSTITUTION MODEL // + //////////////////////////////////////// + + if(!strcmp(parent->name,"ratematrices")) + { + /* ! First time we process this 'instance' node which has this 'ratematrices' parent */ + if(instance->ds->obj == NULL) + { + Make_Ratematrix_From_XML_Node(instance,io,mod); + + ds = instance->ds; + + /*! Connect the data structure n->ds to mod->r_mat */ + ds->obj = (t_rmat *)(mod->r_mat); + + /*! Create and connect the data structure n->ds->next to mod->kappa */ + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (scalar_dbl *)(mod->kappa); + + /*! Create and connect the data structure n->ds->next to mod->s_opt->opt_kappa */ + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (int *)(&mod->s_opt->opt_kappa); + + /*! Create and connect the data structure n->ds->next to mod->s_opt->opt_rr */ + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (int *)(&mod->s_opt->opt_rr); + + /*! Create and connect the data structure n->ds->next to mod->whichmodel */ + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (int *)(&mod->whichmodel); + + /*! Create and connect the data structure n->ds->next to mod->modelname */ + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (t_string *)(mod->modelname); + + /*! Create and connect the data structure n->ds->next to mod->ns */ + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (int *)(&mod->ns); + + /*! Create and connect the data structure n->ds->next to mod->modelname */ + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (t_string *)(mod->custom_mod_string); + + + /*! Create and connect the data structure n->ds->next to mod->fp_aa_rate_mat */ + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (FILE *)(mod->fp_aa_rate_mat); + + /*! Create and connect the data structure n->ds->next to mod->aa_rate_mat_file */ + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (t_string *)mod->aa_rate_mat_file; + } + else + { + /*! Connect to already extisting r_mat & kappa structs. */ + t_ds *ds; + + + ds = instance->ds; + Free(mod->r_mat); + mod->r_mat = (t_rmat *)ds->obj; + + ds = ds->next; + Free_Scalar_Dbl(mod->kappa); + mod->kappa = (scalar_dbl *)ds->obj; + + ds = ds->next; + mod->s_opt->opt_kappa = *((int *)ds->obj); + + ds = ds->next; + mod->s_opt->opt_rr = *((int *)ds->obj); + + ds = ds->next; + mod->whichmodel = *((int *)ds->obj); + + ds = ds->next; + Free_String(mod->modelname); + mod->modelname = (t_string *)ds->obj; + + ds = ds->next; + mod->ns = *((int *)ds->obj); + + ds = ds->next; + Free_String(mod->custom_mod_string); + mod->custom_mod_string = (t_string *)ds->obj; + + ds = ds->next; + mod->fp_aa_rate_mat = (FILE *)ds->obj; + + ds = ds->next; + Free_String(mod->aa_rate_mat_file); + mod->aa_rate_mat_file = (t_string *)ds->obj; + + } + } + + //////////////////////////////////////// + // STATE FREQS // + //////////////////////////////////////// + + else if(!strcmp(parent->name,"equfreqs")) + { + /* If n->ds == NULL, the corrresponding node data structure, n->ds, has not */ + /* been initialized. If not, do nothing. */ + if(instance->ds->obj == NULL) + { + Make_Efrq_From_XML_Node(instance,io,mod); + + t_ds *ds; + + ds = instance->ds; + ds->obj = (t_efrq *)mod->e_frq; + + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (int *)(&mod->s_opt->opt_state_freq); + + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (int *)(&mod->e_frq->user_state_freq); + + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (vect_dbl *)(mod->e_frq->user_b_freq); + } + else + { + /* Connect the data structure n->ds to mod->e_frq */ + + ds = instance->ds; + mod->e_frq = (t_efrq *)ds->obj; + + ds = ds->next; + mod->s_opt->opt_state_freq = *((int *)ds->obj); + + ds = ds->next; + mod->e_frq->user_state_freq = *((int *)ds->obj); + + ds = ds->next; + mod->e_frq->user_b_freq = (vect_dbl *)ds->obj; + } + } + + ////////////////////////////////////////// + // TOPOLOGY // + ////////////////////////////////////////// + + else if(!strcmp(parent->name,"topology")) + { + if(parent->ds->obj == NULL) Make_Topology_From_XML_Node(instance,io,iomod); + + ds = parent->ds; + + int buff; + ds->obj = (int *)(& buff); + } + + ////////////////////////////////////////// + // RAS // + ////////////////////////////////////////// + + else if(!strcmp(parent->name,"siterates")) + { + char *rate_value = NULL; + /* scalar_dbl *r; */ + phydbl val; + + + /*! First time we process this 'siterates' node, check that its format is valid. + and process it afterwards. + */ + if(parent->ds->obj == NULL) + { + class_number = 0; + + Make_RAS_From_XML_Node(parent,iomod); + + ds = parent->ds; + + ds->obj = (t_ras *)iomod->ras; + + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (int *)(&iomod->s_opt->opt_alpha); + + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (int *)(&iomod->s_opt->opt_free_mixt_rates); + } + else /*! Connect ras struct to an already defined one. Same for opt_alpha & opt_free_mixt_rates */ + { + ds = parent->ds; + + if(iomod->ras != (t_ras *)ds->obj) Free_RAS(iomod->ras); + iomod->ras = (t_ras *)ds->obj; + + ds = ds->next; + iomod->s_opt->opt_alpha = *((int *)ds->obj); + + ds = ds->next; + iomod->s_opt->opt_free_mixt_rates = *((int *)ds->obj); + } + + rate_value = XML_Get_Attribute_Value(instance,"init.value"); + + val = 1.; + if(rate_value) val = String_To_Dbl(rate_value); + + if(instance->ds->obj == NULL) + { + instance->ds->obj = (phydbl *)(&val); + instance->ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + instance->ds->next->obj = (int *)(class_num + class_number); + + iomod->ras->gamma_rr->v[class_number] = val; + iomod->ras->init_rr = NO; + + if(Are_Equal(val,0.0,1E-20) == NO) class_number++; + } + + + /*! Note: ras is already connected to the relevant t_ds stucture. No need + to connect ras->gamma_rr or ras->p_invar */ + + /*! Invariant */ + if(Are_Equal(val,0.0,1E-20)) + { + mod->ras->invar = YES; + } + else + { + mod->ras->parent_class_number = *((int *)instance->ds->next->obj); + } + + xml_node *orig_w = NULL; + orig_w = XML_Search_Node_Attribute_Value("appliesto",instance->id,YES,instance->parent); + + + if(orig_w) + { + char *weight; + weight = XML_Get_Attribute_Value(orig_w,"value"); + if(mod->ras->invar == YES) + { + iomod->ras->pinvar->v = String_To_Dbl(weight); + } + else + { + int class; + class = *((int *)instance->ds->next->obj); + iomod->ras->gamma_r_proba->v[class] = String_To_Dbl(weight); + iomod->ras->init_r_proba = NO; + } + } + } + + ////////////////////////////////////////////// + // BRANCH LENGTHS // + ////////////////////////////////////////////// + + else if(!strcmp(parent->name,"branchlengths")) + { + int i; + int n_otu; + + n_otu = tree->n_otu; + + if(instance->ds->obj == NULL) + { + if(!lens) + { + ori_lens = (scalar_dbl **)mCalloc(2*tree->n_otu-1,sizeof(scalar_dbl *)); + ori_lens_old = (scalar_dbl **)mCalloc(2*tree->n_otu-1,sizeof(scalar_dbl *)); + + ori_lens_var = (scalar_dbl **)mCalloc(2*tree->n_otu-1,sizeof(scalar_dbl *)); + ori_lens_var_old = (scalar_dbl **)mCalloc(2*tree->n_otu-1,sizeof(scalar_dbl *)); + + lens = ori_lens; + lens_old = ori_lens_old; + + lens_var = ori_lens_var; + lens_var_old = ori_lens_var_old; + + lens_size = 2*tree->n_otu-1; + } + else + { + ori_lens = (scalar_dbl **)mRealloc(ori_lens,2*tree->n_otu-1+lens_size,sizeof(scalar_dbl *)); + ori_lens_old = (scalar_dbl **)mRealloc(ori_lens_old,2*tree->n_otu-1+lens_size,sizeof(scalar_dbl *)); + + ori_lens_var = (scalar_dbl **)mRealloc(ori_lens_var,2*tree->n_otu-1+lens_size,sizeof(scalar_dbl *)); + ori_lens_var_old = (scalar_dbl **)mRealloc(ori_lens_var_old,2*tree->n_otu-1+lens_size,sizeof(scalar_dbl *)); + + lens = ori_lens + lens_size;; + lens_old = ori_lens_old + lens_size;; + + lens_var = ori_lens_var + lens_size;; + lens_var_old = ori_lens_var_old + lens_size;; + + lens_size += 2*tree->n_otu-1; + } + + for(i=0;i<2*tree->n_otu-1;++i) + { + lens[i] = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(lens[i]); + + lens_old[i] = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(lens_old[i]); + + lens_var[i] = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(lens_var[i]); + + lens_var_old[i] = (scalar_dbl *)mCalloc(1,sizeof(scalar_dbl)); + Init_Scalar_Dbl(lens_var_old[i]); + + Free_Scalar_Dbl(tree->a_edges[i]->l); + Free_Scalar_Dbl(tree->a_edges[i]->l_old); + + Free_Scalar_Dbl(tree->a_edges[i]->l_var); + Free_Scalar_Dbl(tree->a_edges[i]->l_var_old); + + if(tree->prev && + tree->prev->a_edges[i]->l == mixt_tree->a_edges[i]->l && + tree->prev->is_mixt_tree == NO) + { + PhyML_Fprintf(stderr,"\n. %p %p",tree->a_edges[i]->l,mixt_tree->a_edges[i]->l); + PhyML_Fprintf(stderr,"\n. Only one set of edge lengths is allowed "); + PhyML_Fprintf(stderr,"\n. in a 'partitionelem'. Please fix your XML file."); + Exit("\n"); + } + } + + char *l_min = NULL; + l_min = XML_Get_Attribute_Value(instance,"l.min"); + + if(l_min) + { + iomod->l_min = String_To_Dbl(l_min); + } + + + char *opt_bl = NULL; + opt_bl = XML_Get_Attribute_Value(instance,"optimise.lens"); + + if(opt_bl) + { + if(!strcmp(opt_bl,"yes") || !strcmp(opt_bl,"true")) + { + iomod->s_opt->opt_bl = YES; + } + else + { + iomod->s_opt->opt_bl = NO; + } + } + + ds = instance->ds; + + ds->obj = (scalar_dbl **)lens; + + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (scalar_dbl **)lens_old; + + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (scalar_dbl **)lens_var; + + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (scalar_dbl **)lens_var_old; + + ds->next = (t_ds *)mCalloc(1,sizeof(t_ds)); + ds = ds->next; + ds->obj = (int *)(&iomod->s_opt->opt_bl); + } + else + { + for(i=0;i<2*tree->n_otu-1;++i) + { + Free_Scalar_Dbl(tree->a_edges[i]->l); + Free_Scalar_Dbl(tree->a_edges[i]->l_old); + Free_Scalar_Dbl(tree->a_edges[i]->l_var); + Free_Scalar_Dbl(tree->a_edges[i]->l_var_old); + } + + ds = instance->ds; + + lens = (scalar_dbl **)ds->obj; + + ds = ds->next; + lens_old = (scalar_dbl **)ds->obj; + + ds = ds->next; + lens_var = (scalar_dbl **)ds->obj; + + ds = ds->next; + lens_var_old = (scalar_dbl **)ds->obj; + + ds = ds->next; + iomod->s_opt->opt_bl = *((int *)ds->obj); + } + + if(n_otu != tree->n_otu) + { + PhyML_Fprintf(stderr,"\n. All the data sets should display the same number of sequences."); + PhyML_Fprintf(stderr,"\n. Found at least one data set with %d sequences and one with %d sequences.",n_otu,tree->n_otu); + Exit("\n"); + } + + For(i,2*tree->n_otu-1) + { + tree->a_edges[i]->l = lens[i]; + mixt_tree->a_edges[i]->l = lens[i]; + tree->a_edges[i]->l_old = lens_old[i]; + mixt_tree->a_edges[i]->l_old = lens_old[i]; + + tree->a_edges[i]->l_var = lens_var[i]; + mixt_tree->a_edges[i]->l_var = lens_var[i]; + tree->a_edges[i]->l_var_old = lens_var_old[i]; + mixt_tree->a_edges[i]->l_var_old = lens_var_old[i]; + } + } + + /////////////////////////////////////////////// + /////////////////////////////////////////////// + /////////////////////////////////////////////// + + if(first_m_elem > 1) // Done with this component, move to the next tree and model + { + if(tree->next) tree = tree->next; + if(mod->next) mod = mod->next; + } + } + else if(list[j] != ' ') + { + component[i] = list[j]; + i++; + } + j++; + if(j == (int)strlen(list)+1) break; + + } // end of mixtureelem processing + } // end of partitionelem processing + } + while(1); + } + while(1); + + + if(ori_lens) Free(ori_lens); + if(ori_lens_old) Free(ori_lens_old); + if(ori_lens_var) Free(ori_lens_var); + if(ori_lens_var_old) Free(ori_lens_var_old); + + while(io->prev != NULL) io = io->prev; + while(mixt_tree->prev != NULL) mixt_tree = mixt_tree->prev; + + + /*! Finish making the models */ + mod = mixt_tree->mod; + do + { + Make_Model_Complete(mod); + mod = mod->next; + } + while(mod); + + Check_Taxa_Sets(mixt_tree); + +#if defined PHYML + Check_Mandatory_XML_Node(root,"phyml"); +#elif defined PHYTIME + Check_Mandatory_XML_Node(root,"phytime"); +#endif + + Check_Mandatory_XML_Node(root,"topology"); + Check_Mandatory_XML_Node(root,"branchlengths"); + Check_Mandatory_XML_Node(root,"ratematrices"); + Check_Mandatory_XML_Node(root,"equfreqs"); + Check_Mandatory_XML_Node(root,"siterates"); + Check_Mandatory_XML_Node(root,"partitionelem"); + Check_Mandatory_XML_Node(root,"mixtureelem"); + + if(!io->mod->s_opt->random_input_tree) io->mod->s_opt->n_rand_starts = 1; + + + /* int r_seed = (io->r_seed < 0)?(time(NULL)):(io->r_seed); */ + /* srand(r_seed); */ + /* io->r_seed = r_seed; */ + + Free(component); + Free(class_num); + + fclose(fp); + return mixt_tree; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +xml_node *XML_Load_File(FILE *fp) +{ + int c; + char *buffer,*bufptr; + int bufsize; + xml_node *parent,*node; + + buffer = (char *)mCalloc(T_MAX_XML_TAG,sizeof(char)); + + bufsize = T_MAX_XML_TAG; + bufptr = buffer; + parent = NULL; + node = NULL; + + while((c = fgetc(fp)) != EOF) + { + if(c == '<' && bufptr > buffer) + { + *bufptr = '\0'; + + /* PhyML_Printf("\n. Read value '%s' for node '%s'",buffer,node->name); */ + /* fflush(NULL); */ + + XML_Set_Node_Value(node,buffer); + bufptr = buffer; + } + + if(c == '<') + { + bufptr = buffer; + + while((c = fgetc(fp)) != EOF) + { + if(isspace(c) != NO || c == '>' || (c == '/' && bufptr > buffer)) break; // End of open or close tag + else if(c == '<') + { + Exit("\n. Bare < in element!"); + } + else if(XML_Add_Character(c,&bufptr,&buffer,&bufsize)) + { + PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + + *bufptr = '\0'; + + if(!strcmp(buffer,"!--")) // Get the rest of the comment + { + while((c = fgetc(fp)) != EOF) + { + + if(c == '>' && bufptr > (buffer + 4) && bufptr[-3] != '-' && + bufptr[-2] == '-' && bufptr[-1] == '-') break; + else if(XML_Add_Character(c,&bufptr,&buffer,&bufsize)) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + *bufptr = '\0'; + + if(c != '>') + { + PhyML_Fprintf(stderr,"\n. Early EOF in comment node."); + Exit("\n"); + } + } + else if(buffer[0] == '/') // Close tag + { + if(strcmp(buffer+1,parent->name)) + { + PhyML_Fprintf(stderr,"\n. Opened tag with name '%s' and closed it with '%s'...",node->name,buffer+1); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + /* printf("\n. Closing node with name '%s'",node->name); */ + + if(node->parent) + { + parent = parent->parent; + node = parent; + } + } + else if(buffer[0] == '?') + { + while((c = fgetc(fp)) != EOF) + { + if (c == '>' && bufptr > buffer && bufptr[-1] == '?') + break; + else if (XML_Add_Character(c, &bufptr, &buffer, &bufsize)) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + + if(c != '>') + { + PhyML_Fprintf(stderr,"\n. An error occurred when reading the processing instruction."); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + *bufptr = '\0'; + + } + else // Open tag + { + node = XML_Make_Node(buffer); + XML_Init_Node(parent,node,buffer); + if(!parent) parent = node; + + if(isspace(c) != NO) c=XML_Parse_Element(fp,node); + else if(c == '/') + { + if((c=fgetc(fp)) != '>') + { + PhyML_Fprintf(stderr,"\n. Expected '>' but read '%c' instead",c); + Exit("\n"); + } + c = '/'; + } + + if(c != '/') parent = node; + + buffer[0] = '\0'; + } + bufptr = buffer; + } + else if(isspace(c) == NO) + { + if(XML_Add_Character(c,&bufptr,&buffer,&bufsize)) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + } + Free(buffer); + return node; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int XML_Add_Character(int c, char **bufptr, char **buffer, int *bufsize) +{ + char *newbuffer; + + if(*bufptr >= (*buffer + *bufsize - 4)) + { + // Increase the size of the buffer... + + if (*bufsize < 1024) + (*bufsize) *= 2; + else + (*bufsize) += 1024; + + if((newbuffer = realloc(*buffer, *bufsize)) == NULL) + { + Free(*buffer); + PhyML_Fprintf(stderr,"\n. Unable to expand string buffer to %d bytes!", *bufsize); + Exit("\n"); + } + + *bufptr = newbuffer + (*bufptr - *buffer); + *buffer = newbuffer; + } + + /* *(*bufptr)++ = tolower(c); */ + *(*bufptr)++ = c; + return 0; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int XML_Parse_Element(FILE *fp, xml_node *n) +{ + int c; + int quote; + char *name, *value, *ptr; + int namesize, valsize; + + name = (char *)mCalloc(64,sizeof(char)); + value = (char *)mCalloc(64,sizeof(char)); + + namesize = 64; + valsize = 64; + + while((c = fgetc(fp)) != EOF) + { + + if(isspace(c) != NO) continue; + + if(c == '/') // End of tag + { + /* printf("\n. Closing node '%s'.",n->name); */ + + quote = fgetc(fp); + if(quote != '>') + { + PhyML_Fprintf(stderr,"\n. Expected '>' after '%c' but read '%c' instead",c,quote); + Exit("\n"); + } + break; + } + else if(c == '<') + { + Exit("\n. Bare < in element!"); + } + else if(c == '>') // End of tag + { + break; + } + + name[0] = c; + ptr = name + 1; + + if(c == '\"' || c == '\'') // Name is in quotes + { + quote = c; + + while((c = fgetc(fp)) != EOF) + { + if(XML_Add_Character(c,&ptr,&name,&namesize)) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + if(c == quote) break; + } + } + else // Name not in quotes + { + while((c = fgetc(fp)) != EOF) + { + if(isspace(c) != NO || c == '=' || c == '/' || c == '>' || c == '?') + break; + else + { + if(XML_Add_Character(c,&ptr,&name,&namesize)) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + } + } + + *ptr = '\0'; + + while(c != EOF && isspace(c) != NO) c = fgetc(fp); + + if(c == '=') // Read the attribute value + { + while((c = fgetc(fp)) != EOF && isspace(c) != NO); + + if(c == EOF) + { + PhyML_Fprintf(stderr,"\n. Missing value in attribute."); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + if(c == '\'' || c == '\"') + { + quote = c; + ptr = value; + + while((c = fgetc(fp)) != EOF) + { + if(c == quote) break; + else + { + if(XML_Add_Character(c,&ptr,&value,&valsize)) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + } + *ptr = '\0'; + } + else + { + value[0] = c; + ptr = value + 1; + + while((c = fgetc(fp)) != EOF) + { + if(isspace(c) != NO || c == '=' || c == '/' || c == '>') + break; + else + { + if(XML_Add_Character(c,&ptr,&value,&valsize)) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + } + } + } + + /* printf("\n. Setting attribute '%s=%s' to node '%s'",name,value,n->name); */ + XML_Make_And_Set_Attribute(n,name,value); + + if(c == '>') break; + + + } + Free(name); + Free(value); + + /* printf("\n. Return '%c'\n",c); */ + return(c); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +xml_attr *XML_Search_Attribute(xml_node *n, char *target_attr_name) +{ + xml_attr *attr; + + attr = n->attr; + do + { + if(!strcmp(attr->name,target_attr_name)) return attr; + attr = attr->next; + } + while(attr); + + return(NULL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int XML_Make_And_Set_Attribute(xml_node *n, char *attr_name, char *attr_value) +{ + xml_attr *prev; + char *s; + + prev = NULL; + while(n->attr != NULL) + { + prev = n->attr; + n->attr = n->attr->next; + } + + n->attr = XML_Make_Attribute(prev,attr_name,attr_value); + XML_Init_Attribute(n->attr); + n->n_attr++; + + // rewind + while(n->attr->prev != NULL) n->attr = n->attr->prev; + + s = To_Lower_String(attr_name); + if(!strcmp(s,"id")) + { + XML_Set_Node_Id(n,attr_value); + /* printf("\n. Node '%s' id is '%s'",n->name,n->id); */ + } + Free(s); + + return(0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int XML_Set_Attribute_Value(xml_node *n, char *attr_name, char *attr_value) +{ + xml_attr *attr; + char *s; + + attr = XML_Search_Attribute(n,attr_name); + if(attr == NULL) return(-1); + + s = To_Lower_String(attr_value); + strcpy(attr->value,s); + + Free(s); + + return(0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int XML_Add_Attribute(xml_node *n, char *attr_name, char *attr_value) +{ + xml_attr *attr; + + attr = n->attr; + while(attr->next != NULL) attr = attr->next; + assert(attr); + + attr->next = XML_Make_Attribute(attr,attr_name,attr_value); + XML_Init_Attribute(attr); + n->n_attr++; + + return(0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +xml_node *XML_Add_Node(xml_node *parent, char *nd_name) +{ + xml_node *n; + n = XML_Make_Node(nd_name); + XML_Init_Node(parent,n,nd_name); + return(n); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int XML_Set_Node_Id(xml_node *n, char *id) +{ + XML_Make_Node_Id(n,id); + strcpy(n->id,id); + return(0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int XML_Set_Node_Value(xml_node *n, char *val) +{ + XML_Make_Node_Value(n,val); + strcpy(n->value,val); + return(0); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +xml_node *XML_Search_Node_Generic(char *nd_name, char *attr_name, char *attr_val, int skip, xml_node *node) +{ + + xml_node *match; + + /* if(nd_name) printf("\n. [1] nd_name:%s attr_name:%s attr_val:%s \n", nd_name, attr_name, attr_val); */ + /* else printf("\n. attr_name:%s attr_val:%s \n", attr_name, attr_val); */ + + /* printf("\n. name:%s child:%s next:%s ", */ + /* node?node->name:"xx", */ + /* node->child?node->child->name:"xx", */ + /* node->next?node->next->name:"xx"); fflush(NULL); */ + + + match = NULL; + if(skip == NO && nd_name && attr_name && attr_val) + { + if(!strcmp(nd_name, node -> name)) + { + xml_attr *attr = XML_Search_Attribute(node, attr_name); + if(attr && !strcmp(attr -> value, attr_val)) match = node; + } + } + else if(skip == NO && !nd_name && attr_name && attr_val) + { + xml_attr *attr = XML_Search_Attribute(node, attr_name); + if(attr && !strcmp(attr -> value, attr_val)) match = node; + } + else if(skip == NO && nd_name && !attr_name && attr_val) + { + if(!strcmp(nd_name, node -> name)) + { + do + { + if(!strcmp(node -> attr -> value, attr_val)) + { + match = node; + break; + } + node -> attr = node -> attr -> next; + if(!node -> attr) break; + } + while(1); + } + } + else if(skip == NO && nd_name && attr_name && !attr_val) + { + if(!strcmp(nd_name, node -> name)) + { + do + { + if(!strcmp(node -> attr -> name, attr_name)) + { + match = node; + break; + } + node -> attr = node -> attr -> next; + if(!node -> attr) break; + } + while(1); + } + } + else if(skip == NO && nd_name && !attr_name && !attr_val) + { + if(!strcmp(nd_name, node -> name)) match = node; + } + else if(skip == NO && !nd_name && attr_name && !attr_val) + { + xml_attr *attr = XML_Search_Attribute(node, attr_name); + if(attr) match = node; + } + else if(skip == NO && !nd_name && !attr_name && attr_val) + { + do + { + if(!strcmp(node -> attr -> value, attr_val)) + { + match = node; + break; + } + node -> attr = node -> attr -> next; + if(!node -> attr) break; + } + while(1); + } + + // If node has a child, node = child, else if node has next, node = next, else if node + // has parent, node = parent->next else node = NULL + + if(match) return(match); + if(node -> child) + { + match = XML_Search_Node_Generic(nd_name, attr_name, attr_val, NO, node -> child); + } + if(!match && node -> next) + { + match = XML_Search_Node_Generic(nd_name, attr_name, attr_val, NO, node -> next); + } + if(match == NULL && node -> parent) + { + if(node -> parent == NULL) // Reached the root + { + PhyML_Fprintf(stderr,"\n. Could not find a node with name '%s'.", attr_name); + Exit("\n"); + } + return NULL; + } + return match; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +xml_node *XML_Search_Node_Name(char *name, int skip, xml_node *node) +{ + xml_node *match; + + /* printf("\n. name:%s child:%s next:%s ", */ + /* node?node->name:"xx", */ + /* node->child?node->child->name:"xx", */ + /* node->next?node->next->name:"xx"); fflush(NULL); */ + + match = NULL; + if(skip == NO && !strcmp(node->name,name)) match = node; + else + { + // If node has a child, node = child, else if node has next, node = next, else if node + // has parent, node = parent->next else node = NULL + if(node->child) + { + match = XML_Search_Node_Name(name,NO,node->child); + } + if(match == NULL && node->next) + { + match = XML_Search_Node_Name(name,NO,node->next); + } + if(match == NULL && node->parent) + { + if(node->parent == NULL) // Reached the root + { + PhyML_Fprintf(stderr,"\n. Could not find a node with name '%s'.",name); + Exit("\n"); + } + return NULL; + } + } + return match; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +xml_node *XML_Search_Node_ID(char *id, int skip, xml_node *node) +{ + xml_node *match; + + if(!node) + { + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + + match = NULL; + if(skip == NO && node->id && !strcmp(node->id,id)) match = node; + else + { + // If node has a child, node = child, else if node has next, node = next, else if node + // has parent, node = parent->next else node = NULL + if(node->child) + { + match = XML_Search_Node_ID(id,NO,node->child); + } + if(match == NULL && node->next) + { + match = XML_Search_Node_ID(id,NO,node->next); + } + if(match == NULL && node->parent) + { + if(node->parent == NULL) // Reached the root + { + PhyML_Fprintf(stderr,"\n. Could not find a node with id '%s'.",id); + Exit("\n"); + } + + return NULL; + } + } + return match; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +xml_node *XML_Search_Node_Attribute_Value(char *attr_name, char *value, int skip, xml_node *node) +{ + xml_node *match; + + + if(!node) + { + PhyML_Fprintf(stderr,"\n. node: %p attr: %p",node,node?node->attr:NULL); + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + match = NULL; + + if(skip) + { + match = XML_Search_Node_Attribute_Value(attr_name, value, NO, node->child); + return match; + } + + if(skip == NO && node->attr) + { + xml_attr *attr; + char *sname, *sval; + char *qname, *qval; + + qname = To_Lower_String(attr_name); + qval = To_Lower_String(value); + + attr = node->attr; + do + { + sname = To_Lower_String(attr->name); + sval = To_Lower_String(attr->value); + + if(!strcmp(sname,qname) && !strcmp(sval,qval)) + { + match = node; + Free(sname); + Free(sval); + break; + } + + Free(sname); + Free(sval); + + attr = attr->next; + + if(!attr) break; + } + while(1); + + Free(qval); + Free(qname); + } + + if(match) return(match); + + if(node->child) + { + match = XML_Search_Node_Attribute_Value(attr_name,value,NO,node->child); + return match; + } + if(node->next && !match) + { + match = XML_Search_Node_Attribute_Value(attr_name,value,NO,node->next); + return match; + } + return NULL; +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +char *XML_Get_Attribute_Value(xml_node *node, char *attr_name) +{ + xml_attr *attr; + + attr = node->attr; + + while(attr && strcmp(attr->name,attr_name)) attr = attr->next; + + return(attr?attr->value:NULL); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int XML_Validate_Attr_Int(char *target, int num, ...) +{ + va_list args; + int i; + char *s,*sc_s; + char *sc_target; + + sc_target = To_Lower_String(target); + + va_start(args,num); + for(i=0;iname,"siterates")) + { + PhyML_Fprintf(stderr,"\n. Node name '%s' should be 'siterates'",parent->name); + Exit("\n"); + } + + // Check that only one 'weights' node is present + n_weights_nodes = 0; + n = parent->child; + do + { + if(!strcmp(n->name,"weights")) n_weights_nodes++; + if(n_weights_nodes > 1) + { + PhyML_Fprintf(stderr,"\n. Only one distribution is authorized for 'siterates' nodes."); + Exit("\n"); + } + n = n->next; + if(!n) break; + } + while(1); + + // Check that one rate value is set to zero if gamma+inv model is used + n = XML_Search_Node_Attribute_Value("family","gamma+inv",YES,parent); + if(!n) return; + else + { + n_zeros = 0; + n = parent->child; + do + { + if(!strcmp(n->name,"instance")) + { + rate_value = NULL; + rate_value = XML_Get_Attribute_Value(n,"init.value"); + + if(rate_value) + { + errno = 0; + buff = strtod(rate_value,&endptr); + + if(rate_value == endptr || errno == ERANGE) + { + PhyML_Fprintf(stderr,"\n. value: %s",rate_value); + PhyML_Fprintf(stderr,"\n. Error in reading attribute 'init.value' in node 'instance'."); + Exit("\n"); + } + + if(buff < 1.E-20) n_zeros++; + } + } + n = n->next; + if(!n) break; + } + while(1); + + if(n_zeros != 1) + { + PhyML_Fprintf(stderr,"\n. # of zero-rates: %d",n_zeros); + PhyML_Fprintf(stderr,"\n. Exactly one rate value has to be set to zero when using the 'gamma+inv' model."); + PhyML_Fprintf(stderr,"\n. Component id: %s",parent->id); + Exit("\n"); + } + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int XML_Get_Number_Of_Classes_Siterates(xml_node *parent) +{ + xml_node *n; + int n_classes; + + if(!parent) + { + PhyML_Printf("\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + n_classes = 0; + n = parent->child; + do + { + if(!strcmp(n->name,"instance")) n_classes++; + n = n->next; + if(!n) break; + } + while(1); + + n = NULL; + n = XML_Search_Node_Attribute_Value("family","gamma+inv",YES,parent); + + if(!n) return n_classes; + else return n_classes-1; +} + +////////////////////////////////////////////////////////////// + +int XML_Siterates_Has_Invariants(xml_node *parent) +{ + xml_node *n; + + if(!parent) + { + PhyML_Fprintf(stderr,"\n. Err in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + n = NULL; + n = XML_Search_Node_Attribute_Value("family","gamma+inv",YES,parent); + + if(!n) return NO; + else return YES; +} + +////////////////////////////////////////////////////////////// + +void XML_Count_Number_Of_Node_With_ID(char *id, int *count, xml_node *n) +{ + if(!id) return; + if(n->id && !strcmp(n->id,id)) (*count)++; + + if(n->child) XML_Count_Number_Of_Node_With_ID(id,count,n->child); + if(n->next) XML_Count_Number_Of_Node_With_ID(id,count,n->next); + +} + +////////////////////////////////////////////////////////////// + +void XML_Count_Number_Of_Node_With_Name(char *name, int *count, xml_node *n) +{ + if(!name) return; + if(n->name && !strcmp(n->name,name)) (*count)++; + + if(n->child) XML_Count_Number_Of_Node_With_Name(name,count,n->child); + if(n->next) XML_Count_Number_Of_Node_With_Name(name,count,n->next); + +} + +////////////////////////////////////////////////////////////// + +void XML_Check_Duplicate_ID(xml_node *n) +{ + int count; + + count = 0; + XML_Count_Number_Of_Node_With_ID(n->id,&count,n); + + if(count > 1) + { + PhyML_Fprintf(stderr,"\n. Node ID '%s' was found more than once.",n->id); + PhyML_Fprintf(stderr,"\n. Each ID must be unique. Please amend your XML"); + PhyML_Fprintf(stderr,"\n. file accordingly."); + Exit("\n"); + } + + if(n->child) XML_Check_Duplicate_ID(n->child); + if(n->next) XML_Check_Duplicate_ID(n->next); +} + +////////////////////////////////////////////////////////////// + +xml_node *XML_Copy_XML_Graph(xml_node *root) +{ + xml_node *cpy_root; + + cpy_root = XML_Make_Node(root->name); + XML_Copy_XML_Node(cpy_root,root); + + return(cpy_root); +} + +////////////////////////////////////////////////////////////// + +void XML_Copy_XML_Node(xml_node *cpy_root, xml_node *root) +{ + xml_attr *attr,*cpy_attr; + + strcpy(cpy_root->name,root->name); + + XML_Make_Node_Id(cpy_root,root->id); + if(root->id) strcpy(cpy_root->id,root->id); + + XML_Make_Node_Value(cpy_root,root->value); + if(root->value) strcpy(cpy_root->value,root->value); + + cpy_root->n_attr = root->n_attr; + + if(root->attr) + { + cpy_root->attr = XML_Make_Attribute(NULL,root->attr->name,root->attr->value); + XML_Init_Attribute(cpy_root->attr); + attr = root->attr; + cpy_attr = cpy_root->attr; + while(attr->next) + { + fflush(NULL); + cpy_attr->next = XML_Make_Attribute(cpy_attr,attr->next->name,attr->next->value); + XML_Init_Attribute(cpy_attr->next); + attr = attr->next; + cpy_attr = cpy_attr->next; + } + } + + if(root->child) + { + cpy_root->child = XML_Make_Node(root->child->name); + cpy_root->child->parent = cpy_root; + XML_Copy_XML_Node(cpy_root->child,root->child); + } + + if(root->next) + { + cpy_root->next = XML_Make_Node(root->next->name); + cpy_root->next->prev = cpy_root; + XML_Copy_XML_Node(cpy_root->next,root->next); + } +} + +////////////////////////////////////////////////////////////// + +void XML_Write_XML_Graph(FILE *fp, xml_node *root) +{ + int indent; + indent = 0; + XML_Write_XML_Node(fp,&indent,root); +} + +////////////////////////////////////////////////////////////// + +void XML_Write_XML_Node(FILE *fp, int *indent, xml_node *root) +{ + xml_node *n; + xml_attr *attr; + char *s; + int i; + + s = (char *)mCalloc((*indent)+1,sizeof(char)); + for(i=0;i<(*indent);++i) s[i]='\t'; + s[i]='\0'; + + + PhyML_Fprintf(fp,"\n%s",s); + + n = root; + + PhyML_Fprintf(fp,"<%s",n->name); + + attr = n->attr; + while(attr) + { + PhyML_Fprintf(fp," %s=\"%s\"",attr->name,attr->value); + attr = attr->next; + } + PhyML_Fprintf(fp,">"); + + if(n->value != NULL) XML_Write_Node_Value(fp,s,n); + + if(n->child) + { + (*indent)++; + XML_Write_XML_Node(fp,indent,n->child); + (*indent)--; + } + + PhyML_Fprintf(fp,"\n%s",s,n->name); + + PhyML_Fprintf(fp,"\n"); + + if(n->next) XML_Write_XML_Node(fp,indent,n->next); + + Free(s); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Write_Node_Value(FILE *fp, char *indent, xml_node *n) +{ + PhyML_Fprintf(fp,"\n"); + + char *tk = strtok(n->value,"\n"); + + do + { + PhyML_Fprintf(fp,"%s%s",indent,tk); + tk = strtok(NULL,"\n"); + if(tk != NULL) PhyML_Fprintf(fp,"\n"); + } + while(tk != NULL); + +} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void Check_Mandatory_XML_Node(xml_node *root, char *name) +{ + if(!XML_Search_Node_Name(name,NO,root)) + { + PhyML_Fprintf(stderr,"\n. Could not find mandatory XML node with name '%s'.",name); + PhyML_Fprintf(stderr,"\n. Please amend your XML file."); + Exit("\n"); + } +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +int XML_Number_Of_Taxa_In_Clade(xml_node *n_clade) +{ + int clade_size = 0; + if(n_clade) + { + do + { + clade_size++; + if(n_clade->next) n_clade = n_clade -> next; + else break; + } + while(n_clade); + } + else + { + PhyML_Fprintf(stderr,"\n. Clade is empty."); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + return(clade_size); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +char **XML_Read_Clade(xml_node *xnd_clade, t_tree *tree) +{ + int i; + char **clade; + + clade = (char **)mCalloc(tree->n_otu, sizeof(char *)); + + if(xnd_clade) + { + i = 0; + do + { + clade[i] = xnd_clade->attr->value; + i++; + if(xnd_clade->next) xnd_clade = xnd_clade->next; + else break; + } + while(xnd_clade); + } + else + { + PhyML_Fprintf(stderr,"== Clade is empty. \n"); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + + return(clade); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Read_Calibration(xml_node *xroot, t_tree *tree) +{ + xml_node *xnd_clade,*xnd_cal,*xnd,*xnd_dum; + phydbl low,up,alpha_proba_dbl,t,t_ref; + t_cal *cal; + t_clad *clade; + char *calib_id,*clade_id,*clade_name,*alpha_proba_string; + int i,j; + + clade = NULL; + cal = NULL; + + xnd = xroot->child; + assert(xnd); + + do + { + if(!strcmp(xnd->name,"calibration")) // Found a XML node . + { + // TO DO: make sure calibs are shared across partition elements -> need to write chain function to + // call once the calib struct on the first mixt_tree is initialized. + /* mixt_tree->rates->tot_num_cal++; */ + /* if (mixt_tree->rates->calib == NULL) mixt_tree->rates->calib = Make_Calib(mixt_tree->n_otu); */ + + xnd_cal = xnd; + + low = 0.0; + up = BIG; + + cal = Make_Calibration(); + Init_Calibration(cal); + + xnd_dum = XML_Search_Node_Name("lower",YES,xnd_cal); + if(xnd_dum != NULL) low = String_To_Dbl(xnd_dum->value); + + xnd_dum = XML_Search_Node_Name("upper",YES,xnd_cal); + if(xnd_dum != NULL) up = String_To_Dbl(xnd_dum->value); + + calib_id = XML_Get_Attribute_Value(xnd_cal,"id"); + cal->id = (char *)mCalloc(strlen(calib_id)+1,sizeof(char)); + strcpy(cal->id,calib_id); + + cal->clade_list_size = 0; + cal->current_clade_idx = 0; + cal->lower = low; + cal->upper = up; + cal->is_primary = YES; + + tree->rates->a_cal[tree->rates->n_cal] = cal; + tree->rates->n_cal++; + + if(tree->rates->n_cal > 10 * tree->n_otu) + { + PhyML_Fprintf(stderr,"\n. There are too many clades defined that are not found in the tree..."); + PhyML_Fprintf(stderr,"\n. Please remove some of them."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + + xnd_dum = xnd_cal->child; + do + { + clade_name = NULL; + if(!strcmp("appliesto",xnd_dum->name)) + { + clade_name = XML_Get_Attribute_Value(xnd_dum,"clade.id"); + + if(!clade_name) + { + PhyML_Fprintf(stderr,"\n. Attribute 'value=CLADE_NAME' is mandatory"); + PhyML_Fprintf(stderr,"\n. Please amend your XML file accordingly."); + Exit("\n"); + } + + alpha_proba_string = XML_Get_Attribute_Value(xnd_dum,"probability"); + + alpha_proba_dbl = -1; + if(!alpha_proba_string) alpha_proba_dbl = 1.0; + else alpha_proba_dbl = String_To_Dbl(alpha_proba_string); + assert(!(alpha_proba_dbl < 0. || alpha_proba_dbl > 1.)); + + if(strcmp("root",clade_name)) + { + xnd_clade = XML_Search_Node_Generic("clade","id",clade_name,YES,xroot); + + if(xnd_clade != NULL) // found clade with a given name + { + char **xclade; + int clade_size,nd_num; + int i; + + xclade = XML_Read_Clade(xnd_clade->child,tree); + clade_size = XML_Number_Of_Taxa_In_Clade(xnd_clade->child); + + clade = Make_Clade(); + + clade->n_tax = clade_size; + clade->tax_list = (char **)mCalloc(clade_size,sizeof(char *)); + for(i=0;itax_list[i] = (char *)mCalloc(strlen(xclade[i])+1,sizeof(char)); + for(i=0;itax_list[i],xclade[i]); + + clade_id = XML_Get_Attribute_Value(xnd_dum,"clade.id"); + if(clade_id == NULL) + { + PhyML_Fprintf(stderr,"\n. Attribute \"clade.id\" is missing in \"appliesto\" tag."); + Generic_Exit(__FILE__,__LINE__,__FUNCTION__); + } + clade->id = (char *)mCalloc(strlen(clade_id)+1,sizeof(char)); + strcpy(clade->id,clade_id); + + nd_num = Find_Clade(clade->tax_list,clade_size,tree); + + if(nd_num > -1) + { + clade->target_nd = tree->a_nodes[nd_num]; + clade->tip_list = Make_Target_Tip(clade->n_tax); + Init_Target_Tip(clade,tree); + + if(cal->clade_list_size == 0) cal->clade_list = (t_clad **)mCalloc(1,sizeof(t_clad *)); + else cal->clade_list = (t_clad **)mRealloc(cal->clade_list,cal->clade_list_size+1,sizeof(t_clad *)); + if(cal->clade_list_size == 0) cal->alpha_proba_list = (phydbl *)mCalloc(1,sizeof(phydbl)); + else cal->alpha_proba_list = (phydbl *)mRealloc(cal->alpha_proba_list,cal->clade_list_size+1,sizeof(phydbl)); + + cal->clade_list[cal->clade_list_size] = clade; + cal->alpha_proba_list[cal->clade_list_size] = alpha_proba_dbl; + cal->clade_list_size++; + } + else + { + Free_Clade(clade); + } + + Free(xclade); + } + else + { + PhyML_Fprintf(stderr,"\n. Calibration information for clade [%s] was not found.", clade_name); + PhyML_Fprintf(stderr,"\n. Err. in file %s at line %d\n",__FILE__,__LINE__); + Exit("\n"); + } + } + } + xnd_dum = xnd_dum->next; + } + while(xnd_dum != NULL); + if(clade_name == NULL) + { + PhyML_Fprintf(stderr,"\n. Could not find calibration information for calibration `%s'",cal->id); + PhyML_Fprintf(stderr,"\n. Please amend your XML file."); + Exit("\n"); + } + } + xnd = xnd->next; + } + while(xnd != NULL); + + + PhyML_Printf("\n\n......................................................................."); + for(i=0;irates->n_cal;++i) + { + cal = tree->rates->a_cal[i]; + + phydbl sum = 0.0; + for(j=0;jclade_list_size;j++) sum += cal->alpha_proba_list[j]; + for(j=0;jclade_list_size;j++) cal->alpha_proba_list[j] /= sum; + + for(j=0;jclade_list_size;j++) + { + clade = cal->clade_list[j]; + PhyML_Printf("\n Calibration id: %s.",cal->id); + PhyML_Printf("\n Lower bound set to: %15f time units.",cal->lower); + PhyML_Printf("\n Upper bound set to: %15f time units.",cal->upper); + PhyML_Printf("\n This calibration applies to node %d with probability %G.",clade->target_nd->num,cal->alpha_proba_list[j]); + PhyML_Printf("\n......................................................................."); + } + } + + + t_ref = t = -1.; + + for(i=0;irates->n_cal;++i) + { + cal = tree->rates->a_cal[i]; + for(j=0;jclade_list_size;j++) + { + clade = cal->clade_list[j]; + if(clade->target_nd->tax == YES) + { + if(t_ref < -.5) + { + t_ref = Uni()*(cal->upper - cal->lower) + cal->lower; + t_ref = fabs(t_ref); + } + else + { + t = Uni()*(cal->upper - cal->lower) + cal->lower; + t = fabs(t); + + if(Are_Equal(t,t_ref,1.E-10) == NO) + { + tree->rates->is_asynchronous = YES; + break; + } + } + } + } + } + + PhyML_Printf("\n\n"); + PhyML_Printf("\n. Is asynchronous: %s",tree->rates->is_asynchronous ? "yes" : "no"); +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +void XML_Update_XML_Struct_Given_Model_Params(t_tree *tree) +{ + xml_node *parent,*child,*x; + char *s,*val; + t_ds *ds; + phydbl v; + + val = (char *)mCalloc(T_MAX_LINE,sizeof(char)); + + parent = XML_Search_Node_Name("ratematrices",YES,tree->xml_root); + if(parent != NULL) + { + child = parent->child; + + assert(child != NULL); + + do + { + ds = child->ds; + + assert(ds); + + x = XML_Search_Node_Name("rr",YES,child); + + if(x != NULL) + { + s = XML_Get_Attribute_Value(x,"AC"); + if(s != NULL) + { + sprintf(val,"%f",((t_rmat *)(ds->obj))->rr->v[0]); + XML_Set_Attribute_Value(x,"AC",val); + } + + s = XML_Get_Attribute_Value(x,"AG"); + if(s != NULL) + { + sprintf(val,"%f",((t_rmat *)(ds->obj))->rr->v[1]); + XML_Set_Attribute_Value(x,"AC",val); + } + + s = XML_Get_Attribute_Value(x,"AT"); + if(s != NULL) + { + sprintf(val,"%f",((t_rmat *)(ds->obj))->rr->v[2]); + XML_Set_Attribute_Value(x,"AT",val); + } + + s = XML_Get_Attribute_Value(x,"CG"); + if(s != NULL) + { + sprintf(val,"%f",((t_rmat *)(ds->obj))->rr->v[3]); + XML_Set_Attribute_Value(x,"CG",val); + } + + s = XML_Get_Attribute_Value(x,"CT"); + if(s != NULL) + { + sprintf(val,"%f",((t_rmat *)(ds->obj))->rr->v[4]); + XML_Set_Attribute_Value(x,"CT",val); + } + } + + + ds = ds->next; + assert(ds); + + s = XML_Get_Attribute_Value(child,"tstv"); + if(s != NULL) + { + sprintf(val,"%f",((scalar_dbl *)(ds->obj))->v); + XML_Set_Attribute_Value(child,"tstv",val); + } + + child = child->next; + } + while(child); + } + + + parent = XML_Search_Node_Name("siterates",YES,tree->xml_root); + + if(parent != NULL) + { + child = parent->child; + assert(child != NULL); + + int class = 0; + do + { + s = XML_Get_Attribute_Value(child,"init.value"); + if(s != NULL) + { + v = atof(s); + if(Are_Equal(v,0.0,1E-20) == NO) + { + sprintf(val,"%f",((t_ras *)(parent->ds->obj))->gamma_rr->v[class]); + XML_Set_Attribute_Value(child,"init.value",val); + class++; + } + } + + child = child->next; + } + while(child); + + + child = XML_Search_Node_Name("weights",YES,parent); + assert(child != NULL); + s = XML_Get_Attribute_Value(child,"family"); + assert(s != NULL); + if(!strcmp(s,"gamma")) + { + s = XML_Get_Attribute_Value(child,"alpha"); + if(s != NULL) + { + sprintf(val,"%f",((t_ras *)(parent->ds->obj))->alpha->v); + XML_Set_Attribute_Value(child,"alpha",val); + } + } + else if(!strcmp(s,"gamma+inv")) + { + s = XML_Get_Attribute_Value(child,"alpha"); + if(s != NULL) + { + sprintf(val,"%f",((t_ras *)(parent->ds->obj))->alpha->v); + XML_Set_Attribute_Value(child,"alpha",val); + + sprintf(val,"%f",((t_ras *)(parent->ds->obj))->pinvar->v); + XML_Set_Attribute_Value(child,"pinv",val); + } + } + + + child = XML_Search_Node_Name("weights",YES,parent); + child = child->child; + assert(child); + + + class = 0; + do + { + // Find the rate class that this weight instance points to + s = XML_Get_Attribute_Value(child,"appliesto"); + assert(s); + x = XML_Search_Node_Attribute_Value("id",s,YES,parent); + assert(x); + + s = XML_Get_Attribute_Value(x,"init.value"); + if(s != NULL) + { + v = atof(s); + if(Are_Equal(v,0.0,1E-20) == NO) + { + sprintf(val,"%f",((t_ras *)(parent->ds->obj))->gamma_r_proba->v[class]); + XML_Set_Attribute_Value(child,"value",val); + class++; + } + else + { + sprintf(val,"%f",0.0); + XML_Set_Attribute_Value(child,"value",val); + } + } + child = child->next; + } + while(child); + + + } + + + + + + +} + + + + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// diff --git a/phyml/xml.h b/phyml/xml.h new file mode 100644 index 0000000..953a368 --- /dev/null +++ b/phyml/xml.h @@ -0,0 +1,51 @@ +#include + +#ifndef XML_H +#define XML_H + +#include "utilities.h" + +xml_node *XML_Load_File(FILE *fp); +int XML_Add_Character(int c, char **bufptr, char **buffer, int *bufsize); +int XML_Parse_Element(FILE *fp, xml_node *n); +int XML_Make_And_Set_Attribute(xml_node *n, char *attr_name, char *attr_value); +xml_attr *XML_Make_Attribute(xml_attr *prev, char *attr_name, char *attr_value); +void XML_Make_Node_Id(xml_node *n, char *id); +int XML_Set_Node_Id(xml_node *n, char *id); +int XML_Set_Node_Value(xml_node *n, char *val); +void XML_Make_Node_Value(xml_node *n, char *val); +xml_node *XML_Search_Node_Name(char *name, int skip, xml_node *node); +char *XML_Get_Attribute_Value(xml_node *node, char *id); +int XML_Validate_Attr_Int(char *target, int num, ...); +void XML_Free_XML_Attr(xml_attr *attr); +void XML_Free_XML_Node(xml_node *node); +void XML_Free_XML_Tree(xml_node *node); +xml_node *XML_Search_Node_ID(char *id, int skip, xml_node *node); +xml_node *XML_Make_Node(char *name); +xml_node *XML_Search_Node_Attribute_Value(char *attr_name, char *value, int skip, xml_node *node); +void XML_Check_Siterates_Node(xml_node *prev); +int XML_Get_Number_Of_Classes_Siterates(xml_node *prev); +int XML_Siterates_Number_Of_Classes(xml_node *sr_node); +void XML_Check_Duplicate_ID(xml_node *n); +void XML_Count_Number_Of_Node_With_ID(char *id, int *count, xml_node *n); +void XML_Count_Number_Of_Node_With_Name(char *name, int *count, xml_node *n); +void XML_Write_XML_Graph(FILE *fp, xml_node *root); +void XML_Write_XML_Node(FILE *fp, int *indent, xml_node *root); +xml_attr *XML_Search_Attribute(xml_node *n, char *target_attr_name); +xml_node *XML_Copy_XML_Graph(xml_node *root); +void XML_Copy_XML_Node(xml_node *cpy_root, xml_node *root); +void Check_Mandatory_XML_Node(xml_node *root, char *name); +xml_node *XML_Search_Node_Generic(char *nd_name, char *attr_name, char *attr_val, int skip, xml_node *node); +t_tree *XML_Process_Base(char *xml_filename); +int XML_Number_Of_Taxa_In_Clade(xml_node *n_clade); +char **XML_Read_Clade(xml_node *n_clade, t_tree *tree); +void DATE_XML(char *xml_filename); +void XML_Read_Calibration(xml_node *root, t_tree *tree); +int XML_Add_Attribute(xml_node *n, char *attr_name, char *attr_value); +xml_node *XML_Add_Node(xml_node *parent, char *nd_name); +void XML_Write_Node_Value(FILE *fp, char *indent, xml_node *n); +void XML_Update_XML_Struct_Given_Model_Params(t_tree *tree); +int XML_Set_Attribute_Value(xml_node *n, char *attr_name, char *attr_value); + + +#endif diff --git a/seqgen/Makefile b/seqgen/Makefile new file mode 100644 index 0000000..6820b94 --- /dev/null +++ b/seqgen/Makefile @@ -0,0 +1,547 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# seqgen/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/RNAcode +pkgincludedir = $(includedir)/RNAcode +pkglibdir = $(libdir)/RNAcode +pkglibexecdir = $(libexecdir)/RNAcode +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = seqgen +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +AR = ar +ARFLAGS = cru +AM_V_AR = $(am__v_AR_$(V)) +am__v_AR_ = $(am__v_AR_$(AM_DEFAULT_VERBOSITY)) +am__v_AR_0 = @echo " AR " $@; +am__v_AR_1 = +libseqgen_a_AR = $(AR) $(ARFLAGS) +libseqgen_a_LIBADD = +am_libseqgen_a_OBJECTS = aamodels.$(OBJEXT) eigen.$(OBJEXT) \ + evolve.$(OBJEXT) gamma.$(OBJEXT) global.$(OBJEXT) \ + model.$(OBJEXT) nucmodels.$(OBJEXT) progress.$(OBJEXT) \ + treefile.$(OBJEXT) twister.$(OBJEXT) +libseqgen_a_OBJECTS = $(am_libseqgen_a_OBJECTS) +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I. -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libseqgen_a_SOURCES) +DIST_SOURCES = $(libseqgen_a_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} /home/work/projects/RNAcode/missing aclocal-1.15 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 1 +AUTOCONF = ${SHELL} /home/work/projects/RNAcode/missing autoconf +AUTOHEADER = ${SHELL} /home/work/projects/RNAcode/missing autoheader +AUTOMAKE = ${SHELL} /home/work/projects/RNAcode/missing automake-1.15 +AWK = gawk +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -g -O2 +CPP = gcc -E +CPPFLAGS = +CXX = g++ +CXXDEPMODE = depmode=gcc3 +CXXFLAGS = -g -O2 +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +EXEEXT = +GREP = /bin/grep +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +ISODATE = 2020-08-24 +LDFLAGS = +LIBOBJS = +LIBS = +LTLIBOBJS = +MAKEINFO = ${SHELL} /home/work/projects/RNAcode/missing makeinfo +MKDIR_P = /bin/mkdir -p +OBJEXT = o +PACKAGE = RNAcode +PACKAGE_BUGREPORT = wash@mit.edu +PACKAGE_NAME = RNAcode +PACKAGE_STRING = RNAcode 0.3 +PACKAGE_TARNAME = RNAcode +PACKAGE_URL = +PACKAGE_VERSION = 0.3 +PATH_SEPARATOR = : +RANLIB = ranlib +SET_MAKE = +SHELL = /bin/bash +STRIP = +VERSION = 0.3 +abs_builddir = /home/work/projects/RNAcode/seqgen +abs_srcdir = /home/work/projects/RNAcode/seqgen +abs_top_builddir = /home/work/projects/RNAcode +abs_top_srcdir = /home/work/projects/RNAcode +ac_ct_CC = gcc +ac_ct_CXX = g++ +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build_alias = +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host_alias = +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /home/work/projects/RNAcode/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../ +top_builddir = .. +top_srcdir = .. +noinst_LIBRARIES = libseqgen.a +libseqgen_a_SOURCES = aamodels.c eigen.c evolve.c gamma.c global.c model.c nucmodels.c progress.c treefile.c twister.c +noinst_HEADERS = aamodels.h eigen.h evolve.h gamma.h global.h model.h nucmodels.h progress.h treefile.h tree.h twister.h +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu seqgen/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu seqgen/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +libseqgen.a: $(libseqgen_a_OBJECTS) $(libseqgen_a_DEPENDENCIES) $(EXTRA_libseqgen_a_DEPENDENCIES) + $(AM_V_at)-rm -f libseqgen.a + $(AM_V_AR)$(libseqgen_a_AR) libseqgen.a $(libseqgen_a_OBJECTS) $(libseqgen_a_LIBADD) + $(AM_V_at)$(RANLIB) libseqgen.a + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +include ./$(DEPDIR)/aamodels.Po +include ./$(DEPDIR)/eigen.Po +include ./$(DEPDIR)/evolve.Po +include ./$(DEPDIR)/gamma.Po +include ./$(DEPDIR)/global.Po +include ./$(DEPDIR)/model.Po +include ./$(DEPDIR)/nucmodels.Po +include ./$(DEPDIR)/progress.Po +include ./$(DEPDIR)/treefile.Po +include ./$(DEPDIR)/twister.Po + +.c.o: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ $< + +.c.obj: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-noinstLIBRARIES cscopelist-am ctags ctags-am distclean \ + distclean-compile distclean-generic distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/seqgen/Makefile.am b/seqgen/Makefile.am index eb0bf98..ca3f5c2 100644 --- a/seqgen/Makefile.am +++ b/seqgen/Makefile.am @@ -4,3 +4,5 @@ libseqgen_a_SOURCES = aamodels.c eigen.c evolve.c gamma.c global.c model.c noinst_HEADERS = aamodels.h eigen.h evolve.h gamma.h global.h model.h nucmodels.h progress.h treefile.h tree.h twister.h +all-local: + objcopy --weaken libseqgen.a libseqgen.a diff --git a/seqgen/Makefile.in b/seqgen/Makefile.in new file mode 100644 index 0000000..0e33110 --- /dev/null +++ b/seqgen/Makefile.in @@ -0,0 +1,547 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = seqgen +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +AR = ar +ARFLAGS = cru +AM_V_AR = $(am__v_AR_@AM_V@) +am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@) +am__v_AR_0 = @echo " AR " $@; +am__v_AR_1 = +libseqgen_a_AR = $(AR) $(ARFLAGS) +libseqgen_a_LIBADD = +am_libseqgen_a_OBJECTS = aamodels.$(OBJEXT) eigen.$(OBJEXT) \ + evolve.$(OBJEXT) gamma.$(OBJEXT) global.$(OBJEXT) \ + model.$(OBJEXT) nucmodels.$(OBJEXT) progress.$(OBJEXT) \ + treefile.$(OBJEXT) twister.$(OBJEXT) +libseqgen_a_OBJECTS = $(am_libseqgen_a_OBJECTS) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libseqgen_a_SOURCES) +DIST_SOURCES = $(libseqgen_a_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +ISODATE = @ISODATE@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +noinst_LIBRARIES = libseqgen.a +libseqgen_a_SOURCES = aamodels.c eigen.c evolve.c gamma.c global.c model.c nucmodels.c progress.c treefile.c twister.c +noinst_HEADERS = aamodels.h eigen.h evolve.h gamma.h global.h model.h nucmodels.h progress.h treefile.h tree.h twister.h +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu seqgen/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu seqgen/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +libseqgen.a: $(libseqgen_a_OBJECTS) $(libseqgen_a_DEPENDENCIES) $(EXTRA_libseqgen_a_DEPENDENCIES) + $(AM_V_at)-rm -f libseqgen.a + $(AM_V_AR)$(libseqgen_a_AR) libseqgen.a $(libseqgen_a_OBJECTS) $(libseqgen_a_LIBADD) + $(AM_V_at)$(RANLIB) libseqgen.a + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/aamodels.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eigen.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/evolve.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gamma.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/global.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nucmodels.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/progress.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/treefile.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/twister.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-noinstLIBRARIES cscopelist-am ctags ctags-am distclean \ + distclean-compile distclean-generic distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/seqgen/treefile.c b/seqgen/treefile.c index a8b148f..ae7855c 100755 --- a/seqgen/treefile.c +++ b/seqgen/treefile.c @@ -287,7 +287,7 @@ void ReadUntil(FILE *fv, char stopChar, char *what) char ch; ch=fgetc(fv); - while (!feof(fv) && ch!=stopChar && + while (!feof(fv) && ch!=stopChar && ch!='(' && ch!=',' && ch!=':' && ch!=')' && ch!=';') ch=fgetc(fv); diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..32f8b37 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,612 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# src/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/RNAcode +pkgincludedir = $(includedir)/RNAcode +pkglibdir = $(libdir)/RNAcode +pkglibexecdir = $(libexecdir)/RNAcode +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +bin_PROGRAMS = RNAcode$(EXEEXT) +subdir = src +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +PROGRAMS = $(bin_PROGRAMS) +am_RNAcode_OBJECTS = RNAcode.$(OBJEXT) rnaz_utils.$(OBJEXT) \ + utils.$(OBJEXT) cmdline.$(OBJEXT) treeSimulate.$(OBJEXT) \ + treeML.$(OBJEXT) code.$(OBJEXT) postscript.$(OBJEXT) \ + extreme_fit.$(OBJEXT) score.$(OBJEXT) misc.$(OBJEXT) +RNAcode_OBJECTS = $(am_RNAcode_OBJECTS) +RNAcode_LDADD = $(LDADD) +RNAcode_DEPENDENCIES = +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I. -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(RNAcode_SOURCES) +DIST_SOURCES = $(RNAcode_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} /home/work/projects/RNAcode/missing aclocal-1.15 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 1 +AUTOCONF = ${SHELL} /home/work/projects/RNAcode/missing autoconf +AUTOHEADER = ${SHELL} /home/work/projects/RNAcode/missing autoheader +AUTOMAKE = ${SHELL} /home/work/projects/RNAcode/missing automake-1.15 +AWK = gawk +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -g -rdynamic -O0 -ggdb3 -Wall --pedantic -Wuninitialized -Winit-self -Wmaybe-uninitialized +CPP = gcc -E +CPPFLAGS = +CXX = g++ +CXXDEPMODE = depmode=gcc3 +CXXFLAGS = -g -O2 -ggdb3 +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +EXEEXT = +GREP = /bin/grep +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +ISODATE = 2020-08-24 +LDFLAGS = +LIBOBJS = +LIBS = +LTLIBOBJS = +MAKEINFO = ${SHELL} /home/work/projects/RNAcode/missing makeinfo +MKDIR_P = /bin/mkdir -p +OBJEXT = o +PACKAGE = RNAcode +PACKAGE_BUGREPORT = wash@mit.edu +PACKAGE_NAME = RNAcode +PACKAGE_STRING = RNAcode 0.3 +PACKAGE_TARNAME = RNAcode +PACKAGE_URL = +PACKAGE_VERSION = 0.3 +PATH_SEPARATOR = : +RANLIB = ranlib +SET_MAKE = +SHELL = /bin/bash +STRIP = +VERSION = 0.3 +abs_builddir = /home/work/projects/RNAcode/src +abs_srcdir = /home/work/projects/RNAcode/src +abs_top_builddir = /home/work/projects/RNAcode +abs_top_srcdir = /home/work/projects/RNAcode +ac_ct_CC = gcc +ac_ct_CXX = g++ +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build_alias = +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host_alias = +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /home/work/projects/RNAcode/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../ +top_builddir = .. +top_srcdir = .. +AM_CPPFLAGS = -I../phyml3/src -I../seqgen -I../levmar -I../librna +RNAcode_SOURCES = \ + RNAcode.c \ + RNAcode.h \ + rnaz_utils.h \ + rnaz_utils.c \ + utils.h \ + utils.c \ + cmdline.c \ + cmdline.h \ + treeSimulate.c \ + treeSimulate.h \ + treeML.h \ + treeML.c \ + code.c \ + postscript.c \ + code.h \ + extreme_fit.c \ + extreme_fit.h \ + postscript.h \ + score.c \ + score.h \ + misc.c \ + misc.h + +LDADD = \ + -L../levmar -llevmar \ + -L../seqgen -lseqgen \ + -L../librna -lRNA \ + -lm\ + -L../phyml3/src -lPHYML \ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p \ + ; then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' \ + -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' \ + `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +RNAcode$(EXEEXT): $(RNAcode_OBJECTS) $(RNAcode_DEPENDENCIES) $(EXTRA_RNAcode_DEPENDENCIES) + @rm -f RNAcode$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(RNAcode_OBJECTS) $(RNAcode_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +include ./$(DEPDIR)/RNAcode.Po +include ./$(DEPDIR)/cmdline.Po +include ./$(DEPDIR)/code.Po +include ./$(DEPDIR)/extreme_fit.Po +include ./$(DEPDIR)/misc.Po +include ./$(DEPDIR)/postscript.Po +include ./$(DEPDIR)/rnaz_utils.Po +include ./$(DEPDIR)/score.Po +include ./$(DEPDIR)/treeML.Po +include ./$(DEPDIR)/treeSimulate.Po +include ./$(DEPDIR)/utils.Po + +.c.o: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ $< + +.c.obj: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \ + clean-binPROGRAMS clean-generic cscopelist-am ctags ctags-am \ + distclean distclean-compile distclean-generic distclean-tags \ + distdir dvi dvi-am html html-am info info-am install \ + install-am install-binPROGRAMS install-data install-data-am \ + install-dvi install-dvi-am install-exec install-exec-am \ + install-html install-html-am install-info install-info-am \ + install-man install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \ + ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-binPROGRAMS + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000..5682360 --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,612 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +bin_PROGRAMS = RNAcode$(EXEEXT) +subdir = src +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +PROGRAMS = $(bin_PROGRAMS) +am_RNAcode_OBJECTS = RNAcode.$(OBJEXT) rnaz_utils.$(OBJEXT) \ + utils.$(OBJEXT) cmdline.$(OBJEXT) treeSimulate.$(OBJEXT) \ + treeML.$(OBJEXT) code.$(OBJEXT) postscript.$(OBJEXT) \ + extreme_fit.$(OBJEXT) score.$(OBJEXT) misc.$(OBJEXT) +RNAcode_OBJECTS = $(am_RNAcode_OBJECTS) +RNAcode_LDADD = $(LDADD) +RNAcode_DEPENDENCIES = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(RNAcode_SOURCES) +DIST_SOURCES = $(RNAcode_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +ISODATE = @ISODATE@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AM_CPPFLAGS = -I../phyml -I../seqgen -I../levmar -I../librna +RNAcode_SOURCES = \ + RNAcode.c \ + RNAcode.h \ + rnaz_utils.h \ + rnaz_utils.c \ + utils.h \ + utils.c \ + cmdline.c \ + cmdline.h \ + treeSimulate.c \ + treeSimulate.h \ + treeML.h \ + treeML.c \ + code.c \ + postscript.c \ + code.h \ + extreme_fit.c \ + extreme_fit.h \ + postscript.h \ + score.c \ + score.h \ + misc.c \ + misc.h + +LDADD = \ + -L../levmar -llevmar \ + -L../phyml -lPHYML \ + -L../seqgen -lseqgen \ + -L../librna -lRNA \ + -lm + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p \ + ; then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' \ + -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' \ + `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +RNAcode$(EXEEXT): $(RNAcode_OBJECTS) $(RNAcode_DEPENDENCIES) $(EXTRA_RNAcode_DEPENDENCIES) + @rm -f RNAcode$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(RNAcode_OBJECTS) $(RNAcode_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RNAcode.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmdline.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/code.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/extreme_fit.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/postscript.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rnaz_utils.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/score.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/treeML.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/treeSimulate.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \ + clean-binPROGRAMS clean-generic cscopelist-am ctags ctags-am \ + distclean distclean-compile distclean-generic distclean-tags \ + distdir dvi dvi-am html html-am info info-am install \ + install-am install-binPROGRAMS install-data install-data-am \ + install-dvi install-dvi-am install-exec install-exec-am \ + install-html install-html-am install-info install-info-am \ + install-man install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \ + ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-binPROGRAMS + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/RNAcode.c b/src/RNAcode.c index afa00bf..97ad240 100644 --- a/src/RNAcode.c +++ b/src/RNAcode.c @@ -22,6 +22,7 @@ #include #include + #include "RNAcode.h" #include "rnaz_utils.h" #include "treeML.h" @@ -50,7 +51,6 @@ long int hitCounter; void freeModels(bgModel* models, int N); int main(int argc, char *argv[]){ - int i,j,k,x,L,N,hssCount, alnCounter; char *tmpSeq, *treeString; float kappa, maxScore; @@ -155,6 +155,7 @@ int main(int argc, char *argv[]){ continue; } + tree=string2tree(treeString); free(treeString); diff --git a/src/html/RNAcode_8c.html b/src/html/RNAcode_8c.html new file mode 100644 index 0000000..c3ffd04 --- /dev/null +++ b/src/html/RNAcode_8c.html @@ -0,0 +1,488 @@ + + + + + + + +My Project: RNAcode.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
RNAcode.c File Reference
+
+
+
#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <math.h>
+#include "RNAcode.h"
+#include "rnaz_utils.h"
+#include "treeML.h"
+#include "cmdline.h"
+#include "code.h"
+#include "score.h"
+#include "tree.h"
+#include "treeSimulate.h"
+#include "extreme_fit.h"
+#include "postscript.h"
+#include "misc.h"
+#include "utils.h"
+
+Include dependency graph for RNAcode.c:
+
+
+ + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + +

+Functions

void freeModels (bgModel *models, int N)
 
int main (int argc, char *argv[])
 
void usage (void)
 
void help (void)
 
void version (void)
 
void read_commandline (int argc, char *argv[])
 
+ + + + + + + + + + + + + + + +

+Variables

parameters pars
 
bgModelmodels
 
bgModelmodelsRev
 
float **** Sk
 
float **** Sk_native
 
float **** Sk_native_rev
 
long int hitCounter
 
+

Function Documentation

+ +

◆ freeModels()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void freeModels (bgModelmodels,
int N 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ help()

+ +
+
+ + + + + + + + +
void help (void )
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ main()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int main (int argc,
char * argv[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ read_commandline()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void read_commandline (int argc,
char * argv[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ usage()

+ +
+
+ + + + + + + + +
void usage (void )
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ version()

+ +
+
+ + + + + + + + +
void version (void )
+
+ +
+
+

Variable Documentation

+ +

◆ hitCounter

+ +
+
+ + + + +
long int hitCounter
+
+ +
+
+ +

◆ models

+ +
+
+ + + + +
bgModel* models
+
+ +
+
+ +

◆ modelsRev

+ +
+
+ + + + +
bgModel * modelsRev
+
+ +
+
+ +

◆ pars

+ +
+
+ + + + +
parameters pars
+
+ +
+
+ +

◆ Sk

+ +
+
+ + + + +
float**** Sk
+
+ +
+
+ +

◆ Sk_native

+ +
+
+ + + + +
float**** Sk_native
+
+ +
+
+ +

◆ Sk_native_rev

+ +
+
+ + + + +
float**** Sk_native_rev
+
+ +
+
+
+ + + + diff --git a/src/html/RNAcode_8c__incl.map b/src/html/RNAcode_8c__incl.map new file mode 100644 index 0000000..817ba9d --- /dev/null +++ b/src/html/RNAcode_8c__incl.map @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/html/RNAcode_8c__incl.md5 b/src/html/RNAcode_8c__incl.md5 new file mode 100644 index 0000000..7a5aaf7 --- /dev/null +++ b/src/html/RNAcode_8c__incl.md5 @@ -0,0 +1 @@ +c2ff13573c4209ea47636ae1263d393d \ No newline at end of file diff --git a/src/html/RNAcode_8c__incl.png b/src/html/RNAcode_8c__incl.png new file mode 100644 index 0000000..c1ec9ce Binary files /dev/null and b/src/html/RNAcode_8c__incl.png differ diff --git a/src/html/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.map b/src/html/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.map new file mode 100644 index 0000000..83c876b --- /dev/null +++ b/src/html/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 b/src/html/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 new file mode 100644 index 0000000..4b7c4b5 --- /dev/null +++ b/src/html/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 @@ -0,0 +1 @@ +7a0d5a3a3ccbb85a003b23ab3597cd3a \ No newline at end of file diff --git a/src/html/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.png b/src/html/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.png new file mode 100644 index 0000000..f01134c Binary files /dev/null and b/src/html/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.png differ diff --git a/src/html/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.map b/src/html/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.map new file mode 100644 index 0000000..561262f --- /dev/null +++ b/src/html/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.map @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/html/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.md5 b/src/html/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.md5 new file mode 100644 index 0000000..7611ab6 --- /dev/null +++ b/src/html/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.md5 @@ -0,0 +1 @@ +0c0fb10d55b065ee69ba1dfac13317ff \ No newline at end of file diff --git a/src/html/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.png b/src/html/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.png new file mode 100644 index 0000000..7e13f03 Binary files /dev/null and b/src/html/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.png differ diff --git a/src/html/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.map b/src/html/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.map new file mode 100644 index 0000000..75770a3 --- /dev/null +++ b/src/html/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 b/src/html/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 new file mode 100644 index 0000000..cae0587 --- /dev/null +++ b/src/html/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 @@ -0,0 +1 @@ +5f04263cb7c095ccf3a4bb50a8b6254b \ No newline at end of file diff --git a/src/html/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.png b/src/html/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.png new file mode 100644 index 0000000..95fb8ea Binary files /dev/null and b/src/html/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.png differ diff --git a/src/html/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.map b/src/html/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.map new file mode 100644 index 0000000..ccb178d --- /dev/null +++ b/src/html/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.map @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/html/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 b/src/html/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 new file mode 100644 index 0000000..d09c19b --- /dev/null +++ b/src/html/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 @@ -0,0 +1 @@ +03b21d78080ce4b0e82c5180fd7c3a7b \ No newline at end of file diff --git a/src/html/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.png b/src/html/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.png new file mode 100644 index 0000000..ddf154d Binary files /dev/null and b/src/html/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.png differ diff --git a/src/html/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.map b/src/html/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.map new file mode 100644 index 0000000..aadc1ef --- /dev/null +++ b/src/html/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 b/src/html/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 new file mode 100644 index 0000000..d1c6050 --- /dev/null +++ b/src/html/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 @@ -0,0 +1 @@ +38bfc3121cde3581fe7bd18c11d526cf \ No newline at end of file diff --git a/src/html/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.png b/src/html/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.png new file mode 100644 index 0000000..7e9aa4e Binary files /dev/null and b/src/html/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.png differ diff --git a/src/html/RNAcode_8h.html b/src/html/RNAcode_8h.html new file mode 100644 index 0000000..b81da37 --- /dev/null +++ b/src/html/RNAcode_8h.html @@ -0,0 +1,250 @@ + + + + + + + +My Project: RNAcode.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
RNAcode.h File Reference
+
+
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + + +
+
+

Go to the source code of this file.

+ + + + +

+Classes

struct  _parameters
 
+ + + +

+Typedefs

typedef struct _parameters parameters
 
+ + + + + + + + + +

+Functions

void usage (void)
 
void help (void)
 
void version (void)
 
void read_commandline (int argc, char *argv[])
 
+

Typedef Documentation

+ +

◆ parameters

+ +
+
+ + + + +
typedef struct _parameters parameters
+
+ +
+
+

Function Documentation

+ +

◆ help()

+ +
+
+ + + + + + + + +
void help (void )
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ read_commandline()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void read_commandline (int argc,
char * argv[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ usage()

+ +
+
+ + + + + + + + +
void usage (void )
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ version()

+ +
+
+ + + + + + + + +
void version (void )
+
+ +
+
+
+ + + + diff --git a/src/html/RNAcode_8h__dep__incl.map b/src/html/RNAcode_8h__dep__incl.map new file mode 100644 index 0000000..7a4904a --- /dev/null +++ b/src/html/RNAcode_8h__dep__incl.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/RNAcode_8h__dep__incl.md5 b/src/html/RNAcode_8h__dep__incl.md5 new file mode 100644 index 0000000..07e0d04 --- /dev/null +++ b/src/html/RNAcode_8h__dep__incl.md5 @@ -0,0 +1 @@ +b36095bd2eb0d468b00d39d435a20704 \ No newline at end of file diff --git a/src/html/RNAcode_8h__dep__incl.png b/src/html/RNAcode_8h__dep__incl.png new file mode 100644 index 0000000..48ce99d Binary files /dev/null and b/src/html/RNAcode_8h__dep__incl.png differ diff --git a/src/html/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.map b/src/html/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.map new file mode 100644 index 0000000..83c876b --- /dev/null +++ b/src/html/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 b/src/html/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 new file mode 100644 index 0000000..718ed3c --- /dev/null +++ b/src/html/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 @@ -0,0 +1 @@ +172857f0fdcde32d445ed314cf77f188 \ No newline at end of file diff --git a/src/html/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.png b/src/html/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.png new file mode 100644 index 0000000..f01134c Binary files /dev/null and b/src/html/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.png differ diff --git a/src/html/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.map b/src/html/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.map new file mode 100644 index 0000000..ccb178d --- /dev/null +++ b/src/html/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.map @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/html/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 b/src/html/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 new file mode 100644 index 0000000..cb0c45f --- /dev/null +++ b/src/html/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 @@ -0,0 +1 @@ +539d97259d759119f4233383ac09660d \ No newline at end of file diff --git a/src/html/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.png b/src/html/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.png new file mode 100644 index 0000000..ddf154d Binary files /dev/null and b/src/html/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.png differ diff --git a/src/html/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.map b/src/html/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.map new file mode 100644 index 0000000..aadc1ef --- /dev/null +++ b/src/html/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 b/src/html/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 new file mode 100644 index 0000000..c81eca1 --- /dev/null +++ b/src/html/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 @@ -0,0 +1 @@ +1a6de43050d2fc778f2e6c6b859ecf89 \ No newline at end of file diff --git a/src/html/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.png b/src/html/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.png new file mode 100644 index 0000000..7e9aa4e Binary files /dev/null and b/src/html/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.png differ diff --git a/src/html/RNAcode_8h_source.html b/src/html/RNAcode_8h_source.html new file mode 100644 index 0000000..8919007 --- /dev/null +++ b/src/html/RNAcode_8h_source.html @@ -0,0 +1,101 @@ + + + + + + + +My Project: RNAcode.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
RNAcode.h
+
+
+Go to the documentation of this file.
1 /* Copyright 2009, Stefan Washietl
2 
3  This file is part of RNAcode.
4 
5  RNAcode is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  RNAcode is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with RNAcode. If not, see <http://www.gnu.org/licenses/>. */
17 
18 
19 #ifndef _RNACODE_H_
20 #define _RNACODE_H_
21 
22 void usage(void);
23 void help(void);
24 void version(void);
25 void read_commandline(int argc, char *argv[]);
26 
27 typedef struct _parameters parameters;
28 
29 struct _parameters{
30  float omega;
31  float Omega;
32  float Delta;
35  FILE *inputFile;
36  FILE *outputFile;
37  FILE *debugFile;
38  int sampleN;
39  char limit[10000];
40  float cutoff;
42  int stopEarly;
43  int bestOnly;
45  int blosum;
46  char debugFileName[1024];
47  char inputFileName[1024];
48  float printIfBelow;
49  float printIfAbove;
52  char postscriptDir[1024];
53 
54 };
55 
56 #endif
float Delta
Definition: RNAcode.h:32
+
float stopPenalty_k
Definition: RNAcode.h:34
+
int bestRegion
Definition: RNAcode.h:44
+
int outputFormat
Definition: RNAcode.h:41
+
void read_commandline(int argc, char *argv[])
Definition: RNAcode.c:266
+
float printIfBelow
Definition: RNAcode.h:48
+
int postscript
Definition: RNAcode.h:50
+
void help(void)
Definition: RNAcode.c:240
+
void version(void)
Definition: RNAcode.c:261
+
float stopPenalty_0
Definition: RNAcode.h:33
+
void usage(void)
Definition: RNAcode.c:236
+
FILE * inputFile
Definition: RNAcode.h:35
+
char inputFileName[1024]
Definition: RNAcode.h:47
+
FILE * outputFile
Definition: RNAcode.h:36
+
float printIfAbove
Definition: RNAcode.h:49
+
float postscript_cutoff
Definition: RNAcode.h:51
+
float omega
Definition: RNAcode.h:30
+
int blosum
Definition: RNAcode.h:45
+
char debugFileName[1024]
Definition: RNAcode.h:46
+
int bestOnly
Definition: RNAcode.h:43
+
float cutoff
Definition: RNAcode.h:40
+
Definition: RNAcode.h:29
+
int stopEarly
Definition: RNAcode.h:42
+
int sampleN
Definition: RNAcode.h:38
+
float Omega
Definition: RNAcode.h:31
+
char postscriptDir[1024]
Definition: RNAcode.h:52
+
char limit[10000]
Definition: RNAcode.h:39
+
FILE * debugFile
Definition: RNAcode.h:37
+
+ + + + diff --git a/src/html/annotated.html b/src/html/annotated.html new file mode 100644 index 0000000..e1bf0bf --- /dev/null +++ b/src/html/annotated.html @@ -0,0 +1,85 @@ + + + + + + + +My Project: Class List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
Class List
+
+
+
Here are the classes, structs, unions and interfaces with brief descriptions:
+ + + + + + + + + +
 C_backtrackData
 C_bgModel
 C_parameters
 C_segmentStats
 Caln
 Ccmdline_parser_paramsThe additional parameters to pass to parser functions
 Cgengetopt_args_infoWhere the command line options are stored
 Coption
+
+
+ + + + diff --git a/src/html/bc_s.png b/src/html/bc_s.png new file mode 100644 index 0000000..224b29a Binary files /dev/null and b/src/html/bc_s.png differ diff --git a/src/html/bdwn.png b/src/html/bdwn.png new file mode 100644 index 0000000..940a0b9 Binary files /dev/null and b/src/html/bdwn.png differ diff --git a/src/html/classes.html b/src/html/classes.html new file mode 100644 index 0000000..a631bdc --- /dev/null +++ b/src/html/classes.html @@ -0,0 +1,89 @@ + + + + + + + +My Project: Class Index + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
Class Index
+
+
+
_ | a | c | g | o
+ + + + + + + + +
  _  
+
_parameters   
  c  
+
  o  
+
_segmentStats   
_backtrackData   
  a  
+
cmdline_parser_params   option   
_bgModel   
  g  
+
aln   
gengetopt_args_info   
+
_ | a | c | g | o
+
+ + + + diff --git a/src/html/closed.png b/src/html/closed.png new file mode 100644 index 0000000..98cc2c9 Binary files /dev/null and b/src/html/closed.png differ diff --git a/src/html/cmdline_8c.html b/src/html/cmdline_8c.html new file mode 100644 index 0000000..e409db9 --- /dev/null +++ b/src/html/cmdline_8c.html @@ -0,0 +1,1258 @@ + + + + + + + +My Project: cmdline.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
cmdline.c File Reference
+
+
+
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "getopt.h"
+#include "cmdline.h"
+
+Include dependency graph for cmdline.c:
+
+
+ + + + +
+
+ + + +

+Enumerations

enum  cmdline_parser_arg_type {
+  ARG_NO, +ARG_FLAG, +ARG_STRING, +ARG_INT, +
+  ARG_FLOAT +
+ }
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

static void clear_given (struct gengetopt_args_info *args_info)
 
static void clear_args (struct gengetopt_args_info *args_info)
 
static int cmdline_parser_internal (int argc, char *const *argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params, const char *additional_error)
 
static char * gengetopt_strdup (const char *s)
 replacement of strdup, which is not standard More...
 
static void init_args_info (struct gengetopt_args_info *args_info)
 
void cmdline_parser_print_version (void)
 
static void print_help_common (void)
 
void cmdline_parser_print_help (void)
 
void cmdline_parser_init (struct gengetopt_args_info *args_info)
 
void cmdline_parser_params_init (struct cmdline_parser_params *params)
 
struct cmdline_parser_paramscmdline_parser_params_create (void)
 
static void free_string_field (char **s)
 
static void cmdline_parser_release (struct gengetopt_args_info *args_info)
 
static void write_into_file (FILE *outfile, const char *opt, const char *arg, char *values[])
 
int cmdline_parser_dump (FILE *outfile, struct gengetopt_args_info *args_info)
 
int cmdline_parser_file_save (const char *filename, struct gengetopt_args_info *args_info)
 
void cmdline_parser_free (struct gengetopt_args_info *args_info)
 
int cmdline_parser (int argc, char *const *argv, struct gengetopt_args_info *args_info)
 
int cmdline_parser_ext (int argc, char *const *argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params)
 
int cmdline_parser2 (int argc, char *const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
 
int cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
 
static int update_arg (void *field, char **orig_field, unsigned int *field_given, unsigned int *prev_given, char *value, char *possible_values[], const char *default_value, cmdline_parser_arg_type arg_type, int check_ambiguity, int override, int no_free, int multiple_option, const char *long_opt, char short_opt, const char *additional_error)
 updates an option More...
 
+ + + + + + + + + + + + + + +

+Variables

const char * gengetopt_args_info_purpose = ""
 the purpose string of the program More...
 
const char * gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]... [FILES]..."
 the usage string of the program More...
 
const char * gengetopt_args_info_description = ""
 
const char * gengetopt_args_info_help []
 all the lines making the help output More...
 
static char * package_name = 0
 
+

Enumeration Type Documentation

+ +

◆ cmdline_parser_arg_type

+ +
+
+ + + + +
enum cmdline_parser_arg_type
+
+ + + + + + +
Enumerator
ARG_NO 
ARG_FLAG 
ARG_STRING 
ARG_INT 
ARG_FLOAT 
+ +
+
+

Function Documentation

+ +

◆ clear_args()

+ +
+
+ + + + + +
+ + + + + + + + +
static void clear_args (struct gengetopt_args_infoargs_info)
+
+static
+
+ +
+
+ +

◆ clear_given()

+ +
+
+ + + + + +
+ + + + + + + + +
static void clear_given (struct gengetopt_args_infoargs_info)
+
+static
+
+ +
+
+ +

◆ cmdline_parser()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int cmdline_parser (int argc,
char *constargv,
struct gengetopt_args_infoargs_info 
)
+
+

The command line parser

Parameters
+ + + + +
argcthe number of command line options
argvthe command line options
args_infothe structure where option information will be stored
+
+
+
Returns
0 if everything went fine, NON 0 if an error took place
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + +
+ +
+
+ +

◆ cmdline_parser2()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int cmdline_parser2 (int argc,
char *constargv,
struct gengetopt_args_infoargs_info,
int override,
int initialize,
int check_required 
)
+
+

The command line parser (version with additional parameters - deprecated)

Parameters
+ + + + + + + +
argcthe number of command line options
argvthe command line options
args_infothe structure where option information will be stored
overridewhether to override possibly already present options
initializewhether to initialize the option structure my_args_info
check_requiredwhether to check that all required options were provided
+
+
+
Returns
0 if everything went fine, NON 0 if an error took place
+
Deprecated:
use cmdline_parser_ext() instead
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + +
+ +
+
+ +

◆ cmdline_parser_dump()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int cmdline_parser_dump (FILE * outfile,
struct gengetopt_args_infoargs_info 
)
+
+

Save the contents of the option struct into an already open FILE stream.

Parameters
+ + + +
outfilethe stream where to dump options
args_infothe option struct to dump
+
+
+
Returns
0 if everything went fine, NON 0 if an error took place
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ cmdline_parser_ext()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int cmdline_parser_ext (int argc,
char *constargv,
struct gengetopt_args_infoargs_info,
struct cmdline_parser_paramsparams 
)
+
+

The command line parser (version with additional parameters)

Parameters
+ + + + + +
argcthe number of command line options
argvthe command line options
args_infothe structure where option information will be stored
paramsadditional parameters for the parser
+
+
+
Returns
0 if everything went fine, NON 0 if an error took place
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + +
+ +
+
+ +

◆ cmdline_parser_file_save()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int cmdline_parser_file_save (const char * filename,
struct gengetopt_args_infoargs_info 
)
+
+

Save the contents of the option struct into a (text) file. This file can be read by the config file parser (if generated by gengetopt)

Parameters
+ + + +
filenamethe file where to save
args_infothe option struct to save
+
+
+
Returns
0 if everything went fine, NON 0 if an error took place
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ cmdline_parser_free()

+ +
+
+ + + + + + + + +
void cmdline_parser_free (struct gengetopt_args_infoargs_info)
+
+

Deallocates the string fields of the gengetopt_args_info structure (but does not deallocate the structure itself)

Parameters
+ + +
args_infothe structure to deallocate
+
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ cmdline_parser_init()

+ +
+
+ + + + + + + + +
void cmdline_parser_init (struct gengetopt_args_infoargs_info)
+
+

Initializes the passed gengetopt_args_info structure's fields (also set default values for options that have a default)

Parameters
+ + +
args_infothe structure to initialize
+
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ cmdline_parser_internal()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int cmdline_parser_internal (int argc,
char *constargv,
struct gengetopt_args_infoargs_info,
struct cmdline_parser_paramsparams,
const char * additional_error 
)
+
+static
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + +
+ +
+
+ +

◆ cmdline_parser_params_create()

+ +
+
+ + + + + + + + +
struct cmdline_parser_params* cmdline_parser_params_create (void )
+
+

Allocates dynamically a cmdline_parser_params structure and initializes all its fields to their default values

Returns
the created and initialized cmdline_parser_params structure
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ cmdline_parser_params_init()

+ +
+
+ + + + + + + + +
void cmdline_parser_params_init (struct cmdline_parser_paramsparams)
+
+

Initializes all the fields a cmdline_parser_params structure to their default values

Parameters
+ + +
paramsthe structure to initialize
+
+
+ +
+
+ +

◆ cmdline_parser_print_help()

+ +
+
+ + + + + + + + +
void cmdline_parser_print_help (void )
+
+

Print the help

+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ cmdline_parser_print_version()

+ +
+
+ + + + + + + + +
void cmdline_parser_print_version (void )
+
+

Print the version

+ +
+
+ +

◆ cmdline_parser_release()

+ +
+
+ + + + + +
+ + + + + + + + +
static void cmdline_parser_release (struct gengetopt_args_infoargs_info)
+
+static
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ cmdline_parser_required()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int cmdline_parser_required (struct gengetopt_args_infoargs_info,
const char * prog_name 
)
+
+

Checks that all the required options were specified

Parameters
+ + + +
args_infothe structure to check
prog_namethe name of the program that will be used to print possible errors
+
+
+
Returns
+ +
+
+ +

◆ free_string_field()

+ +
+
+ + + + + +
+ + + + + + + + +
static void free_string_field (char ** s)
+
+static
+
+ +
+
+ +

◆ gengetopt_strdup()

+ +
+
+ + + + + +
+ + + + + + + + +
char * gengetopt_strdup (const char * s)
+
+static
+
+ +

replacement of strdup, which is not standard

+ +
+
+ +

◆ init_args_info()

+ +
+
+ + + + + +
+ + + + + + + + +
static void init_args_info (struct gengetopt_args_infoargs_info)
+
+static
+
+ +
+
+ +

◆ print_help_common()

+ +
+
+ + + + + +
+ + + + + + + + +
static void print_help_common (void )
+
+static
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ update_arg()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
static int update_arg (void * field,
char ** orig_field,
unsigned int * field_given,
unsigned int * prev_given,
char * value,
char * possible_values[],
const char * default_value,
cmdline_parser_arg_type arg_type,
int check_ambiguity,
int override,
int no_free,
int multiple_option,
const char * long_opt,
char short_opt,
const char * additional_error 
)
+
+static
+
+ +

updates an option

+
Parameters
+ + + + + + + + + + +
fieldthe generic pointer to the field to update
orig_fieldthe pointer to the orig field
field_giventhe pointer to the number of occurrence of this option
prev_giventhe pointer to the number of occurrence already seen
valuethe argument for this option (if null no arg was specified)
possible_valuesthe possible values for this option (if specified)
default_valuethe default value (in case the option only accepts fixed values)
arg_typethe type of this option
check_ambiguity
+
+
+
See also
cmdline_parser_params.check_ambiguity
+
Parameters
+ + +
override
+
+
+
See also
cmdline_parser_params.override
+
Parameters
+ + + + + + +
no_freewhether to free a possible previous value
multiple_optionwhether this is a multiple option
long_optthe corresponding long option
short_optthe corresponding short option (or '-' if none)
additional_errorpossible further error specification
+
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ write_into_file()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
static void write_into_file (FILE * outfile,
const char * opt,
const char * arg,
char * values[] 
)
+
+static
+
+ +
+
+

Variable Documentation

+ +

◆ gengetopt_args_info_description

+ +
+
+ + + + +
const char* gengetopt_args_info_description = ""
+
+ +
+
+ +

◆ gengetopt_args_info_help

+ +
+
+ + + + +
const char* gengetopt_args_info_help[]
+
+Initial value:
= {
" -h, --help Print help and exit",
" -V, --version Print version and exit",
" -o, --outfile=STRING Output filename",
" -g, --gtf GTF output (default=off)",
" -t, --tabular Tab delimited output (default=off)",
" -b, --best-only Print only best hit per alignment (default=off)",
" -r, --best-region Print all best non-overlapping hits per alignment \n (default=off)",
" -c, --pars=STRING String with parameters",
" -s, --stop-early Don't calculate p-values if below cutoff \n (default=off)",
" -n, --num-samples=INT Number of samples",
" -p, --cutoff=FLOAT p-value cutoff",
" -z, --debug-file=STRING Debug file",
" -e, --eps Postscript output (default=off)",
" -i, --eps-cutoff=FLOAT Postscript output p-value cutoff",
" -d, --eps-dir=STRING Postscript directory",
" -l, --limit=STRING limit to species",
" -m, --blosum=INT BLOSUM matrix version",
0
}
+

all the lines making the help output

+ +
+
+ +

◆ gengetopt_args_info_purpose

+ +
+
+ + + + +
const char* gengetopt_args_info_purpose = ""
+
+ +

the purpose string of the program

+ +
+
+ +

◆ gengetopt_args_info_usage

+ +
+
+ + + + +
const char* gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]... [FILES]..."
+
+ +

the usage string of the program

+ +
+
+ +

◆ package_name

+ +
+
+ + + + + +
+ + + + +
char* package_name = 0
+
+static
+
+ +
+
+
+ + + + diff --git a/src/html/cmdline_8c__incl.map b/src/html/cmdline_8c__incl.map new file mode 100644 index 0000000..f748d3f --- /dev/null +++ b/src/html/cmdline_8c__incl.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/cmdline_8c__incl.md5 b/src/html/cmdline_8c__incl.md5 new file mode 100644 index 0000000..1838f59 --- /dev/null +++ b/src/html/cmdline_8c__incl.md5 @@ -0,0 +1 @@ +dbe3b15ee07313d91cf89f49c9ae6222 \ No newline at end of file diff --git a/src/html/cmdline_8c__incl.png b/src/html/cmdline_8c__incl.png new file mode 100644 index 0000000..1b6300d Binary files /dev/null and b/src/html/cmdline_8c__incl.png differ diff --git a/src/html/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.map b/src/html/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.map new file mode 100644 index 0000000..797970e --- /dev/null +++ b/src/html/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.map @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/html/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 b/src/html/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 new file mode 100644 index 0000000..21559e7 --- /dev/null +++ b/src/html/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 @@ -0,0 +1 @@ +abf457e6fc0a6f90052c9ffbc6118a05 \ No newline at end of file diff --git a/src/html/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.png b/src/html/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.png new file mode 100644 index 0000000..963debf Binary files /dev/null and b/src/html/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.png differ diff --git a/src/html/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.map b/src/html/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.map new file mode 100644 index 0000000..f316d0b --- /dev/null +++ b/src/html/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 b/src/html/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 new file mode 100644 index 0000000..4f6e404 --- /dev/null +++ b/src/html/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 @@ -0,0 +1 @@ +c09cf4436e1f46c238edd28470b65f45 \ No newline at end of file diff --git a/src/html/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.png b/src/html/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.png new file mode 100644 index 0000000..7e57ec4 Binary files /dev/null and b/src/html/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.png differ diff --git a/src/html/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.map b/src/html/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.map new file mode 100644 index 0000000..238d8ae --- /dev/null +++ b/src/html/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.md5 b/src/html/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.md5 new file mode 100644 index 0000000..ae8c238 --- /dev/null +++ b/src/html/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.md5 @@ -0,0 +1 @@ +25459aa72aec83a1711c9b23d388aa64 \ No newline at end of file diff --git a/src/html/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.png b/src/html/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.png new file mode 100644 index 0000000..3f26258 Binary files /dev/null and b/src/html/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.png differ diff --git a/src/html/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.map b/src/html/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.map new file mode 100644 index 0000000..f4507d3 --- /dev/null +++ b/src/html/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 b/src/html/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 new file mode 100644 index 0000000..d3ece98 --- /dev/null +++ b/src/html/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 @@ -0,0 +1 @@ +0817aac4507aaa4b01fb7ef05261f19a \ No newline at end of file diff --git a/src/html/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.png b/src/html/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.png new file mode 100644 index 0000000..5babdec Binary files /dev/null and b/src/html/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.png differ diff --git a/src/html/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.map b/src/html/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.map new file mode 100644 index 0000000..9fcd358 --- /dev/null +++ b/src/html/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.map @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/html/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 b/src/html/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 new file mode 100644 index 0000000..995024d --- /dev/null +++ b/src/html/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 @@ -0,0 +1 @@ +2a29fbb14990871dfeccc81cd8a681a3 \ No newline at end of file diff --git a/src/html/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.png b/src/html/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.png new file mode 100644 index 0000000..f8d6437 Binary files /dev/null and b/src/html/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.png differ diff --git a/src/html/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.map b/src/html/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.map new file mode 100644 index 0000000..918609a --- /dev/null +++ b/src/html/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.map @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/html/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 b/src/html/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 new file mode 100644 index 0000000..2a7d411 --- /dev/null +++ b/src/html/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 @@ -0,0 +1 @@ +662330f6de0feb250bc065cab30c76d1 \ No newline at end of file diff --git a/src/html/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.png b/src/html/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.png new file mode 100644 index 0000000..5e7b2a3 Binary files /dev/null and b/src/html/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.png differ diff --git a/src/html/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.map b/src/html/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.map new file mode 100644 index 0000000..fb29f74 --- /dev/null +++ b/src/html/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.map @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/html/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.md5 b/src/html/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.md5 new file mode 100644 index 0000000..a525b81 --- /dev/null +++ b/src/html/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.md5 @@ -0,0 +1 @@ +c69b7517ea3faf6b48c88cc8a59b7d5e \ No newline at end of file diff --git a/src/html/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.png b/src/html/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.png new file mode 100644 index 0000000..bef4e9f Binary files /dev/null and b/src/html/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.png differ diff --git a/src/html/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.map b/src/html/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.map new file mode 100644 index 0000000..df1943a --- /dev/null +++ b/src/html/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 b/src/html/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 new file mode 100644 index 0000000..e58cfb5 --- /dev/null +++ b/src/html/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 @@ -0,0 +1 @@ +ebfcb4afb785dc11508fcde57516715c \ No newline at end of file diff --git a/src/html/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.png b/src/html/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.png new file mode 100644 index 0000000..4c521d1 Binary files /dev/null and b/src/html/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.png differ diff --git a/src/html/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.map b/src/html/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.map new file mode 100644 index 0000000..2e9ec2f --- /dev/null +++ b/src/html/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.md5 b/src/html/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.md5 new file mode 100644 index 0000000..72282b2 --- /dev/null +++ b/src/html/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.md5 @@ -0,0 +1 @@ +a1e9960424a4cc0526128489fee9919a \ No newline at end of file diff --git a/src/html/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.png b/src/html/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.png new file mode 100644 index 0000000..6874c80 Binary files /dev/null and b/src/html/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.png differ diff --git a/src/html/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.map b/src/html/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.map new file mode 100644 index 0000000..0e5c7fa --- /dev/null +++ b/src/html/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 b/src/html/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 new file mode 100644 index 0000000..a05f1ad --- /dev/null +++ b/src/html/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 @@ -0,0 +1 @@ +4e73c2d683a3049a9a2f50e79fd46f83 \ No newline at end of file diff --git a/src/html/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.png b/src/html/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.png new file mode 100644 index 0000000..5e591fa Binary files /dev/null and b/src/html/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.png differ diff --git a/src/html/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.map b/src/html/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.map new file mode 100644 index 0000000..b904b93 --- /dev/null +++ b/src/html/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.md5 b/src/html/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.md5 new file mode 100644 index 0000000..77837ac --- /dev/null +++ b/src/html/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.md5 @@ -0,0 +1 @@ +c5e1afef0fad551178ea34b1ce7fa5c4 \ No newline at end of file diff --git a/src/html/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.png b/src/html/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.png new file mode 100644 index 0000000..6efbf61 Binary files /dev/null and b/src/html/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.png differ diff --git a/src/html/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.map b/src/html/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.map new file mode 100644 index 0000000..0814954 --- /dev/null +++ b/src/html/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 b/src/html/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 new file mode 100644 index 0000000..17b8db2 --- /dev/null +++ b/src/html/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 @@ -0,0 +1 @@ +7e7ec187fc4ebc0bef70528b0c6f3a18 \ No newline at end of file diff --git a/src/html/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.png b/src/html/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.png new file mode 100644 index 0000000..d2e20a9 Binary files /dev/null and b/src/html/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.png differ diff --git a/src/html/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.map b/src/html/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.map new file mode 100644 index 0000000..77abd42 --- /dev/null +++ b/src/html/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 b/src/html/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 new file mode 100644 index 0000000..b394ed7 --- /dev/null +++ b/src/html/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 @@ -0,0 +1 @@ +b5d19aba3a121ae4d9b2ff0e7d5a30e3 \ No newline at end of file diff --git a/src/html/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.png b/src/html/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.png new file mode 100644 index 0000000..a1ec2cd Binary files /dev/null and b/src/html/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.png differ diff --git a/src/html/cmdline_8h.html b/src/html/cmdline_8h.html new file mode 100644 index 0000000..177700e --- /dev/null +++ b/src/html/cmdline_8h.html @@ -0,0 +1,748 @@ + + + + + + + +My Project: cmdline.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
cmdline.h File Reference
+
+
+ +

The header file for the command line option parser generated by GNU Gengetopt version 2.22.1 http://www.gnu.org/software/gengetopt. DO NOT modify this file, since it can be overwritten. +More...

+
#include <stdio.h>
+
+Include dependency graph for cmdline.h:
+
+
+ + +
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + +
+
+

Go to the source code of this file.

+ + + + + + + + +

+Classes

struct  gengetopt_args_info
 Where the command line options are stored. More...
 
struct  cmdline_parser_params
 The additional parameters to pass to parser functions. More...
 
+ + + + + + + +

+Macros

#define CMDLINE_PARSER_PACKAGE   PACKAGE
 the program name More...
 
#define CMDLINE_PARSER_VERSION   VERSION
 the program version More...
 
+ + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

int cmdline_parser (int argc, char *const *argv, struct gengetopt_args_info *args_info)
 
int cmdline_parser2 (int argc, char *const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
 
int cmdline_parser_ext (int argc, char *const *argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params)
 
int cmdline_parser_dump (FILE *outfile, struct gengetopt_args_info *args_info)
 
int cmdline_parser_file_save (const char *filename, struct gengetopt_args_info *args_info)
 
void cmdline_parser_print_help (void)
 
void cmdline_parser_print_version (void)
 
void cmdline_parser_params_init (struct cmdline_parser_params *params)
 
struct cmdline_parser_paramscmdline_parser_params_create (void)
 
void cmdline_parser_init (struct gengetopt_args_info *args_info)
 
void cmdline_parser_free (struct gengetopt_args_info *args_info)
 
int cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
 
+ + + + + + + + + + +

+Variables

const char * gengetopt_args_info_purpose
 the purpose string of the program More...
 
const char * gengetopt_args_info_usage
 the usage string of the program More...
 
const char * gengetopt_args_info_help []
 all the lines making the help output More...
 
+

Detailed Description

+

The header file for the command line option parser generated by GNU Gengetopt version 2.22.1 http://www.gnu.org/software/gengetopt. DO NOT modify this file, since it can be overwritten.

+
Author
GNU Gengetopt by Lorenzo Bettini
+

Macro Definition Documentation

+ +

◆ CMDLINE_PARSER_PACKAGE

+ +
+
+ + + + +
#define CMDLINE_PARSER_PACKAGE   PACKAGE
+
+ +

the program name

+ +
+
+ +

◆ CMDLINE_PARSER_VERSION

+ +
+
+ + + + +
#define CMDLINE_PARSER_VERSION   VERSION
+
+ +

the program version

+ +
+
+

Function Documentation

+ +

◆ cmdline_parser()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int cmdline_parser (int argc,
char *constargv,
struct gengetopt_args_infoargs_info 
)
+
+

The command line parser

Parameters
+ + + + +
argcthe number of command line options
argvthe command line options
args_infothe structure where option information will be stored
+
+
+
Returns
0 if everything went fine, NON 0 if an error took place
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + +
+ +
+
+ +

◆ cmdline_parser2()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int cmdline_parser2 (int argc,
char *constargv,
struct gengetopt_args_infoargs_info,
int override,
int initialize,
int check_required 
)
+
+

The command line parser (version with additional parameters - deprecated)

Parameters
+ + + + + + + +
argcthe number of command line options
argvthe command line options
args_infothe structure where option information will be stored
overridewhether to override possibly already present options
initializewhether to initialize the option structure my_args_info
check_requiredwhether to check that all required options were provided
+
+
+
Returns
0 if everything went fine, NON 0 if an error took place
+
Deprecated:
use cmdline_parser_ext() instead
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + +
+ +
+
+ +

◆ cmdline_parser_dump()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int cmdline_parser_dump (FILE * outfile,
struct gengetopt_args_infoargs_info 
)
+
+

Save the contents of the option struct into an already open FILE stream.

Parameters
+ + + +
outfilethe stream where to dump options
args_infothe option struct to dump
+
+
+
Returns
0 if everything went fine, NON 0 if an error took place
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ cmdline_parser_ext()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int cmdline_parser_ext (int argc,
char *constargv,
struct gengetopt_args_infoargs_info,
struct cmdline_parser_paramsparams 
)
+
+

The command line parser (version with additional parameters)

Parameters
+ + + + + +
argcthe number of command line options
argvthe command line options
args_infothe structure where option information will be stored
paramsadditional parameters for the parser
+
+
+
Returns
0 if everything went fine, NON 0 if an error took place
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + +
+ +
+
+ +

◆ cmdline_parser_file_save()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int cmdline_parser_file_save (const char * filename,
struct gengetopt_args_infoargs_info 
)
+
+

Save the contents of the option struct into a (text) file. This file can be read by the config file parser (if generated by gengetopt)

Parameters
+ + + +
filenamethe file where to save
args_infothe option struct to save
+
+
+
Returns
0 if everything went fine, NON 0 if an error took place
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ cmdline_parser_free()

+ +
+
+ + + + + + + + +
void cmdline_parser_free (struct gengetopt_args_infoargs_info)
+
+

Deallocates the string fields of the gengetopt_args_info structure (but does not deallocate the structure itself)

Parameters
+ + +
args_infothe structure to deallocate
+
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ cmdline_parser_init()

+ +
+
+ + + + + + + + +
void cmdline_parser_init (struct gengetopt_args_infoargs_info)
+
+

Initializes the passed gengetopt_args_info structure's fields (also set default values for options that have a default)

Parameters
+ + +
args_infothe structure to initialize
+
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ cmdline_parser_params_create()

+ +
+
+ + + + + + + + +
struct cmdline_parser_params* cmdline_parser_params_create (void )
+
+

Allocates dynamically a cmdline_parser_params structure and initializes all its fields to their default values

Returns
the created and initialized cmdline_parser_params structure
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ cmdline_parser_params_init()

+ +
+
+ + + + + + + + +
void cmdline_parser_params_init (struct cmdline_parser_paramsparams)
+
+

Initializes all the fields a cmdline_parser_params structure to their default values

Parameters
+ + +
paramsthe structure to initialize
+
+
+ +
+
+ +

◆ cmdline_parser_print_help()

+ +
+
+ + + + + + + + +
void cmdline_parser_print_help (void )
+
+

Print the help

+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ cmdline_parser_print_version()

+ +
+
+ + + + + + + + +
void cmdline_parser_print_version (void )
+
+

Print the version

+ +
+
+ +

◆ cmdline_parser_required()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int cmdline_parser_required (struct gengetopt_args_infoargs_info,
const char * prog_name 
)
+
+

Checks that all the required options were specified

Parameters
+ + + +
args_infothe structure to check
prog_namethe name of the program that will be used to print possible errors
+
+
+
Returns
+ +
+
+

Variable Documentation

+ +

◆ gengetopt_args_info_help

+ +
+
+ + + + +
const char* gengetopt_args_info_help[]
+
+ +

all the lines making the help output

+ +
+
+ +

◆ gengetopt_args_info_purpose

+ +
+
+ + + + +
const char* gengetopt_args_info_purpose
+
+ +

the purpose string of the program

+ +
+
+ +

◆ gengetopt_args_info_usage

+ +
+
+ + + + +
const char* gengetopt_args_info_usage
+
+ +

the usage string of the program

+ +
+
+
+ + + + diff --git a/src/html/cmdline_8h__dep__incl.map b/src/html/cmdline_8h__dep__incl.map new file mode 100644 index 0000000..c095369 --- /dev/null +++ b/src/html/cmdline_8h__dep__incl.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/cmdline_8h__dep__incl.md5 b/src/html/cmdline_8h__dep__incl.md5 new file mode 100644 index 0000000..e9190f9 --- /dev/null +++ b/src/html/cmdline_8h__dep__incl.md5 @@ -0,0 +1 @@ +7129c8b97bcd57f7f64221e6e7de4cac \ No newline at end of file diff --git a/src/html/cmdline_8h__dep__incl.png b/src/html/cmdline_8h__dep__incl.png new file mode 100644 index 0000000..9de2c77 Binary files /dev/null and b/src/html/cmdline_8h__dep__incl.png differ diff --git a/src/html/cmdline_8h__incl.map b/src/html/cmdline_8h__incl.map new file mode 100644 index 0000000..58682f8 --- /dev/null +++ b/src/html/cmdline_8h__incl.map @@ -0,0 +1,2 @@ + + diff --git a/src/html/cmdline_8h__incl.md5 b/src/html/cmdline_8h__incl.md5 new file mode 100644 index 0000000..34844c3 --- /dev/null +++ b/src/html/cmdline_8h__incl.md5 @@ -0,0 +1 @@ +e1759bd5ab49a7a00ca1b5ce8fad59ea \ No newline at end of file diff --git a/src/html/cmdline_8h__incl.png b/src/html/cmdline_8h__incl.png new file mode 100644 index 0000000..329bfaf Binary files /dev/null and b/src/html/cmdline_8h__incl.png differ diff --git a/src/html/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.map b/src/html/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.map new file mode 100644 index 0000000..797970e --- /dev/null +++ b/src/html/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.map @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/html/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 b/src/html/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 new file mode 100644 index 0000000..0417c4e --- /dev/null +++ b/src/html/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 @@ -0,0 +1 @@ +42e0e134354e9614d61cd4d418735e27 \ No newline at end of file diff --git a/src/html/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.png b/src/html/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.png new file mode 100644 index 0000000..963debf Binary files /dev/null and b/src/html/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.png differ diff --git a/src/html/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.map b/src/html/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.map new file mode 100644 index 0000000..f316d0b --- /dev/null +++ b/src/html/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 b/src/html/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 new file mode 100644 index 0000000..012c3b3 --- /dev/null +++ b/src/html/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 @@ -0,0 +1 @@ +1a07e7c1dedc6e73592f3688b5e9cf48 \ No newline at end of file diff --git a/src/html/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.png b/src/html/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.png new file mode 100644 index 0000000..7e57ec4 Binary files /dev/null and b/src/html/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.png differ diff --git a/src/html/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.map b/src/html/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.map new file mode 100644 index 0000000..f4507d3 --- /dev/null +++ b/src/html/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 b/src/html/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 new file mode 100644 index 0000000..dd26c03 --- /dev/null +++ b/src/html/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 @@ -0,0 +1 @@ +32fa20e26e588a1a19fecdc7a0c92c64 \ No newline at end of file diff --git a/src/html/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.png b/src/html/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.png new file mode 100644 index 0000000..5babdec Binary files /dev/null and b/src/html/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.png differ diff --git a/src/html/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.map b/src/html/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.map new file mode 100644 index 0000000..9fcd358 --- /dev/null +++ b/src/html/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.map @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/html/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 b/src/html/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 new file mode 100644 index 0000000..ae50f8f --- /dev/null +++ b/src/html/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 @@ -0,0 +1 @@ +ee4ea75ff85c72171fb47ff2b9c75830 \ No newline at end of file diff --git a/src/html/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.png b/src/html/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.png new file mode 100644 index 0000000..f8d6437 Binary files /dev/null and b/src/html/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.png differ diff --git a/src/html/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.map b/src/html/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.map new file mode 100644 index 0000000..918609a --- /dev/null +++ b/src/html/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.map @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/html/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 b/src/html/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 new file mode 100644 index 0000000..9c5f4bd --- /dev/null +++ b/src/html/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 @@ -0,0 +1 @@ +6caab8d22b361ca022406ed10b074f6c \ No newline at end of file diff --git a/src/html/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.png b/src/html/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.png new file mode 100644 index 0000000..5e7b2a3 Binary files /dev/null and b/src/html/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.png differ diff --git a/src/html/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.map b/src/html/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.map new file mode 100644 index 0000000..df1943a --- /dev/null +++ b/src/html/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 b/src/html/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 new file mode 100644 index 0000000..3dd6a4b --- /dev/null +++ b/src/html/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 @@ -0,0 +1 @@ +c72f6216cba96542a0d4752a5951ea67 \ No newline at end of file diff --git a/src/html/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.png b/src/html/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.png new file mode 100644 index 0000000..4c521d1 Binary files /dev/null and b/src/html/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.png differ diff --git a/src/html/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.map b/src/html/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.map new file mode 100644 index 0000000..0e5c7fa --- /dev/null +++ b/src/html/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 b/src/html/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 new file mode 100644 index 0000000..4f8cdbc --- /dev/null +++ b/src/html/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 @@ -0,0 +1 @@ +a7490b41cf997e1c6119cc288898190b \ No newline at end of file diff --git a/src/html/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.png b/src/html/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.png new file mode 100644 index 0000000..5e591fa Binary files /dev/null and b/src/html/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.png differ diff --git a/src/html/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.map b/src/html/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.map new file mode 100644 index 0000000..0814954 --- /dev/null +++ b/src/html/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 b/src/html/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 new file mode 100644 index 0000000..6c2c153 --- /dev/null +++ b/src/html/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 @@ -0,0 +1 @@ +d272c236310c51c29d75473a278ae47e \ No newline at end of file diff --git a/src/html/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.png b/src/html/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.png new file mode 100644 index 0000000..d2e20a9 Binary files /dev/null and b/src/html/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.png differ diff --git a/src/html/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.map b/src/html/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.map new file mode 100644 index 0000000..77abd42 --- /dev/null +++ b/src/html/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 b/src/html/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 new file mode 100644 index 0000000..b88fc9d --- /dev/null +++ b/src/html/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 @@ -0,0 +1 @@ +4b2a5eb7b595d6d1f558131bc2567467 \ No newline at end of file diff --git a/src/html/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.png b/src/html/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.png new file mode 100644 index 0000000..a1ec2cd Binary files /dev/null and b/src/html/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.png differ diff --git a/src/html/cmdline_8h_source.html b/src/html/cmdline_8h_source.html new file mode 100644 index 0000000..279713e --- /dev/null +++ b/src/html/cmdline_8h_source.html @@ -0,0 +1,155 @@ + + + + + + + +My Project: cmdline.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
cmdline.h
+
+
+Go to the documentation of this file.
1 
8 #ifndef CMDLINE_H
9 #define CMDLINE_H
10 
11 /* If we use autoconf. */
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #include <stdio.h> /* for FILE */
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif /* __cplusplus */
21 
22 #ifndef CMDLINE_PARSER_PACKAGE
23 
24 #define CMDLINE_PARSER_PACKAGE PACKAGE
25 #endif
26 
27 #ifndef CMDLINE_PARSER_VERSION
28 
29 #define CMDLINE_PARSER_VERSION VERSION
30 #endif
31 
34 {
35  const char *help_help;
36  const char *version_help;
37  char * outfile_arg;
38  char * outfile_orig;
39  const char *outfile_help;
40  int gtf_flag;
41  const char *gtf_help;
43  const char *tabular_help;
45  const char *best_only_help;
47  const char *best_region_help;
48  char * pars_arg;
49  char * pars_orig;
50  const char *pars_help;
52  const char *stop_early_help;
55  const char *num_samples_help;
56  float cutoff_arg;
57  char * cutoff_orig;
58  const char *cutoff_help;
59  char * debug_file_arg;
60  char * debug_file_orig;
61  const char *debug_file_help;
62  int eps_flag;
63  const char *eps_help;
65  char * eps_cutoff_orig;
66  const char *eps_cutoff_help;
67  char * eps_dir_arg;
68  char * eps_dir_orig;
69  const char *eps_dir_help;
70  char * limit_arg;
71  char * limit_orig;
72  const char *limit_help;
73  int blosum_arg;
74  char * blosum_orig;
75  const char *blosum_help;
77  unsigned int help_given ;
78  unsigned int version_given ;
79  unsigned int outfile_given ;
80  unsigned int gtf_given ;
81  unsigned int tabular_given ;
82  unsigned int best_only_given ;
83  unsigned int best_region_given ;
84  unsigned int pars_given ;
85  unsigned int stop_early_given ;
86  unsigned int num_samples_given ;
87  unsigned int cutoff_given ;
88  unsigned int debug_file_given ;
89  unsigned int eps_given ;
90  unsigned int eps_cutoff_given ;
91  unsigned int eps_dir_given ;
92  unsigned int limit_given ;
93  unsigned int blosum_given ;
95  char **inputs ;
96  unsigned inputs_num ;
97 } ;
98 
101 {
102  int override;
107 } ;
108 
110 extern const char *gengetopt_args_info_purpose;
112 extern const char *gengetopt_args_info_usage;
114 extern const char *gengetopt_args_info_help[];
115 
123 int cmdline_parser (int argc, char * const *argv,
124  struct gengetopt_args_info *args_info);
125 
137 int cmdline_parser2 (int argc, char * const *argv,
138  struct gengetopt_args_info *args_info,
139  int override, int initialize, int check_required);
140 
149 int cmdline_parser_ext (int argc, char * const *argv,
150  struct gengetopt_args_info *args_info,
151  struct cmdline_parser_params *params);
152 
159 int cmdline_parser_dump(FILE *outfile,
160  struct gengetopt_args_info *args_info);
161 
169 int cmdline_parser_file_save(const char *filename,
170  struct gengetopt_args_info *args_info);
171 
175 void cmdline_parser_print_help(void);
180 
187 
194 
200 void cmdline_parser_init (struct gengetopt_args_info *args_info);
206 void cmdline_parser_free (struct gengetopt_args_info *args_info);
207 
215 int cmdline_parser_required (struct gengetopt_args_info *args_info,
216  const char *prog_name);
217 
218 
219 #ifdef __cplusplus
220 }
221 #endif /* __cplusplus */
222 #endif /* CMDLINE_H */
const char * pars_help
String with parameters help description.
Definition: cmdline.h:50
+
int best_only_flag
Print only best hit per alignment (default=off).
Definition: cmdline.h:44
+
int initialize
whether to initialize the option structure gengetopt_args_info (default 1)
Definition: cmdline.h:103
+
Where the command line options are stored.
Definition: cmdline.h:33
+
char * cutoff_orig
p-value cutoff original value given at command line.
Definition: cmdline.h:57
+
int num_samples_arg
Number of samples.
Definition: cmdline.h:53
+
const char * debug_file_help
Debug file help description.
Definition: cmdline.h:61
+
char * debug_file_arg
Debug file.
Definition: cmdline.h:59
+
unsigned int help_given
Whether help was given.
Definition: cmdline.h:77
+
unsigned int debug_file_given
Whether debug-file was given.
Definition: cmdline.h:88
+
FILE * outfile
Definition: postscript.c:15
+
const char * gengetopt_args_info_help[]
all the lines making the help output
Definition: cmdline.c:30
+
int cmdline_parser2(int argc, char *const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
Definition: cmdline.c:368
+
const char * best_region_help
Print all best non-overlapping hits per alignment help description.
Definition: cmdline.h:47
+
unsigned int eps_dir_given
Whether eps-dir was given.
Definition: cmdline.h:91
+
const char * gengetopt_args_info_usage
the usage string of the program
Definition: cmdline.c:26
+
int cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
Definition: cmdline.c:311
+
int stop_early_flag
Don&#39;t calculate p-values if below cutoff (default=off).
Definition: cmdline.h:51
+
unsigned int eps_given
Whether eps was given.
Definition: cmdline.h:89
+
char * pars_arg
String with parameters.
Definition: cmdline.h:48
+
const char * eps_help
Postscript output help description.
Definition: cmdline.h:63
+
char * limit_orig
limit to species original value given at command line.
Definition: cmdline.h:71
+
unsigned int cutoff_given
Whether cutoff was given.
Definition: cmdline.h:87
+
int cmdline_parser(int argc, char *const *argv, struct gengetopt_args_info *args_info)
Definition: cmdline.c:352
+
unsigned int pars_given
Whether pars was given.
Definition: cmdline.h:84
+
int tabular_flag
Tab delimited output (default=off).
Definition: cmdline.h:42
+
char * pars_orig
String with parameters original value given at command line.
Definition: cmdline.h:49
+
int best_region_flag
Print all best non-overlapping hits per alignment (default=off).
Definition: cmdline.h:46
+
int gtf_flag
GTF output (default=off).
Definition: cmdline.h:40
+
unsigned int outfile_given
Whether outfile was given.
Definition: cmdline.h:79
+
const char * stop_early_help
Don&#39;t calculate p-values if below cutoff help description.
Definition: cmdline.h:52
+
const char * limit_help
limit to species help description.
Definition: cmdline.h:72
+
The additional parameters to pass to parser functions.
Definition: cmdline.h:100
+
const char * gengetopt_args_info_purpose
the purpose string of the program
Definition: cmdline.c:24
+
float cutoff_arg
p-value cutoff.
Definition: cmdline.h:56
+
char * num_samples_orig
Number of samples original value given at command line.
Definition: cmdline.h:54
+
const char * gtf_help
GTF output help description.
Definition: cmdline.h:41
+
char * eps_dir_arg
Postscript directory.
Definition: cmdline.h:67
+
char * eps_cutoff_orig
Postscript output p-value cutoff original value given at command line.
Definition: cmdline.h:65
+
int cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
Definition: cmdline.c:260
+
const char * cutoff_help
p-value cutoff help description.
Definition: cmdline.h:58
+
void cmdline_parser_print_version(void)
Definition: cmdline.c:145
+
const char * num_samples_help
Number of samples help description.
Definition: cmdline.h:55
+
unsigned int eps_cutoff_given
Whether eps-cutoff was given.
Definition: cmdline.h:90
+
unsigned int stop_early_given
Whether stop-early was given.
Definition: cmdline.h:85
+
int cmdline_parser_ext(int argc, char *const *argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params)
Definition: cmdline.c:358
+
void cmdline_parser_init(struct gengetopt_args_info *args_info)
Definition: cmdline.c:175
+
unsigned int blosum_given
Whether blosum was given.
Definition: cmdline.h:93
+
unsigned int best_only_given
Whether best-only was given.
Definition: cmdline.h:82
+
int blosum_arg
BLOSUM matrix version.
Definition: cmdline.h:73
+
const char * version_help
Print version and exit help description.
Definition: cmdline.h:36
+
unsigned int gtf_given
Whether gtf was given.
Definition: cmdline.h:80
+
void cmdline_parser_params_init(struct cmdline_parser_params *params)
Definition: cmdline.c:186
+
const char * blosum_help
BLOSUM matrix version help description.
Definition: cmdline.h:75
+
const char * outfile_help
Output filename help description.
Definition: cmdline.h:39
+
const char * tabular_help
Tab delimited output help description.
Definition: cmdline.h:43
+
void cmdline_parser_print_help(void)
Definition: cmdline.c:166
+
unsigned inputs_num
unamed options number
Definition: cmdline.h:96
+
const char * help_help
Print help and exit help description.
Definition: cmdline.h:35
+
char * limit_arg
limit to species.
Definition: cmdline.h:70
+
float eps_cutoff_arg
Postscript output p-value cutoff.
Definition: cmdline.h:64
+
int print_errors
whether getopt_long should print an error message for a bad option (default 1)
Definition: cmdline.h:106
+
char * outfile_arg
Output filename.
Definition: cmdline.h:37
+
const char * eps_cutoff_help
Postscript output p-value cutoff help description.
Definition: cmdline.h:66
+
int check_ambiguity
whether to check for options already specified in the option structure gengetopt_args_info (default 0...
Definition: cmdline.h:105
+
unsigned int tabular_given
Whether tabular was given.
Definition: cmdline.h:81
+
unsigned int num_samples_given
Whether num-samples was given.
Definition: cmdline.h:86
+
int check_required
whether to check that all required options were provided (default 1)
Definition: cmdline.h:104
+
const char * eps_dir_help
Postscript directory help description.
Definition: cmdline.h:69
+
unsigned int limit_given
Whether limit was given.
Definition: cmdline.h:92
+
char * outfile_orig
Output filename original value given at command line.
Definition: cmdline.h:38
+
char * eps_dir_orig
Postscript directory original value given at command line.
Definition: cmdline.h:68
+
char ** inputs
unamed options (options without names)
Definition: cmdline.h:95
+
void cmdline_parser_free(struct gengetopt_args_info *args_info)
Definition: cmdline.c:331
+
char * debug_file_orig
Debug file original value given at command line.
Definition: cmdline.h:60
+
struct cmdline_parser_params * cmdline_parser_params_create(void)
Definition: cmdline.c:199
+
int cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name)
Definition: cmdline.c:385
+
const char * best_only_help
Print only best hit per alignment help description.
Definition: cmdline.h:45
+
int eps_flag
Postscript output (default=off).
Definition: cmdline.h:62
+
unsigned int version_given
Whether version was given.
Definition: cmdline.h:78
+
unsigned int best_region_given
Whether best-region was given.
Definition: cmdline.h:83
+
char * blosum_orig
BLOSUM matrix version original value given at command line.
Definition: cmdline.h:74
+
+ + + + diff --git a/src/html/code_8c.html b/src/html/code_8c.html new file mode 100644 index 0000000..57a2dce --- /dev/null +++ b/src/html/code_8c.html @@ -0,0 +1,233 @@ + + + + + + + +My Project: code.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
code.c File Reference
+
+
+
#include <stdlib.h>
+#include <string.h>
+#include "code.h"
+
+Include dependency graph for code.c:
+
+
+ + + +
+
+ + + + + + + + + +

+Functions

char * translateSeq (char *seq)
 
int * encodeSeq (char *seq)
 
int encodeAA (char aa)
 
char decodeAA (int encodedAA)
 
+ + + + + + + +

+Variables

int transcode [4][4][4]
 
int BLOSUM62 [24][24]
 
int BLOSUM90 [24][24]
 
+

Function Documentation

+ +

◆ decodeAA()

+ +
+
+ + + + + + + + +
char decodeAA (int encodedAA)
+
+ +
+
+ +

◆ encodeAA()

+ +
+
+ + + + + + + + +
int encodeAA (char aa)
+
+ +
+
+ +

◆ encodeSeq()

+ +
+
+ + + + + + + + +
int* encodeSeq (char * seq)
+
+ +
+
+ +

◆ translateSeq()

+ +
+
+ + + + + + + + +
char* translateSeq (char * seq)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+

Variable Documentation

+ +

◆ BLOSUM62

+ +
+
+ + + + +
int BLOSUM62[24][24]
+
+Initial value:
={{ 4,-1,-2,-2, 0,-1,-1, 0,-2,-1,-1,-1,-1,-2,-1, 1, 0,-3,-2, 0,-2,-1, 0,-4},
{-1, 5, 0,-2,-3, 1, 0,-2, 0,-3,-2, 2,-1,-3,-2,-1,-1,-3,-2,-3,-1, 0,-1,-4},
{-2, 0, 6, 1,-3, 0, 0, 0, 1,-3,-3, 0,-2,-3,-2, 1, 0,-4,-2,-3, 3, 0,-1,-4},
{-2,-2, 1, 6,-3, 0, 2,-1,-1,-3,-4,-1,-3,-3,-1, 0,-1,-4,-3,-3, 4, 1,-1,-4},
{ 0,-3,-3,-3, 9,-3,-4,-3,-3,-1,-1,-3,-1,-2,-3,-1,-1,-2,-2,-1,-3,-3,-2,-4},
{-1, 1, 0, 0,-3, 5, 2,-2, 0,-3,-2, 1, 0,-3,-1, 0,-1,-2,-1,-2, 0, 3,-1,-4},
{-1, 0, 0, 2,-4, 2, 5,-2, 0,-3,-3, 1,-2,-3,-1, 0,-1,-3,-2,-2, 1, 4,-1,-4},
{ 0,-2, 0,-1,-3,-2,-2, 6,-2,-4,-4,-2,-3,-3,-2, 0,-2,-2,-3,-3,-1,-2,-1,-4},
{-2, 0, 1,-1,-3, 0, 0,-2, 8,-3,-3,-1,-2,-1,-2,-1,-2,-2, 2,-3, 0, 0,-1,-4},
{-1,-3,-3,-3,-1,-3,-3,-4,-3, 4, 2,-3, 1, 0,-3,-2,-1,-3,-1, 3,-3,-3,-1,-4},
{-1,-2,-3,-4,-1,-2,-3,-4,-3, 2, 4,-2, 2, 0,-3,-2,-1,-2,-1, 1,-4,-3,-1,-4},
{-1, 2, 0,-1,-3, 1, 1,-2,-1,-3,-2, 5,-1,-3,-1, 0,-1,-3,-2,-2, 0, 1,-1,-4},
{-1,-1,-2,-3,-1, 0,-2,-3,-2, 1, 2,-1, 5, 0,-2,-1,-1,-1,-1, 1,-3,-1,-1,-4},
{-2,-3,-3,-3,-2,-3,-3,-3,-1, 0, 0,-3, 0, 6,-4,-2,-2, 1, 3,-1,-3,-3,-1,-4},
{-1,-2,-2,-1,-3,-1,-1,-2,-2,-3,-3,-1,-2,-4, 7,-1,-1,-4,-3,-2,-2,-1,-2,-4},
{ 1,-1, 1, 0,-1, 0, 0, 0,-1,-2,-2, 0,-1,-2,-1, 4, 1,-3,-2,-2, 0, 0, 0,-4},
{ 0,-1, 0,-1,-1,-1,-1,-2,-2,-1,-1,-1,-1,-2,-1, 1, 5,-2,-2, 0,-1,-1, 0,-4},
{-3,-3,-4,-4,-2,-2,-3,-2,-2,-3,-2,-3,-1, 1,-4,-3,-2, 11, 2,-3,-4,-3,-2,-4},
{-2,-2,-2,-3,-2,-1,-2,-3, 2,-1,-1,-2,-1, 3,-3,-2,-2, 2, 7,-1,-3,-2,-1,-4},
{ 0,-3,-3,-3,-1,-2,-2,-3,-3, 3, 1,-2, 1,-1,-2,-2, 0,-3,-1, 4,-3,-2,-1,-4},
{-2,-1, 3, 4,-3, 0, 1,-1, 0,-3,-4, 0,-3,-3,-2, 0,-1,-4,-3,-3, 4, 1,-1,-4},
{-1, 0, 0, 1,-3, 3, 4,-2, 0,-3,-3, 1,-1,-3,-1, 0,-1,-3,-2,-2, 1, 4,-1,-4},
{ 0,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2, 0, 0,-2,-1,-1,-1,-1,-1,-4},
{-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, 1}}
+
+
+ +

◆ BLOSUM90

+ +
+
+ + + + +
int BLOSUM90[24][24]
+
+Initial value:
={{ 5,-2,-2,-3,-1,-1,-1, 0,-2,-2,-2,-1,-2,-3,-1, 1, 0,-4,-3,-1,-2,-1,-1,-6},
{-2, 6,-1,-3,-5, 1,-1,-3, 0,-4,-3, 2,-2,-4,-3,-1,-2,-4,-3,-3,-2, 0,-2,-6},
{-2,-1, 7, 1,-4, 0,-1,-1, 0,-4,-4, 0,-3,-4,-3, 0, 0,-5,-3,-4, 4,-1,-2,-6},
{-3,-3, 1, 7,-5,-1, 1,-2,-2,-5,-5,-1,-4,-5,-3,-1,-2,-6,-4,-5, 4, 0,-2,-6},
{-1,-5,-4,-5, 9,-4,-6,-4,-5,-2,-2,-4,-2,-3,-4,-2,-2,-4,-4,-2,-4,-5,-3,-6},
{-1, 1, 0,-1,-4, 7, 2,-3, 1,-4,-3, 1, 0,-4,-2,-1,-1,-3,-3,-3,-1, 4,-1,-6},
{-1,-1,-1, 1,-6, 2, 6,-3,-1,-4,-4, 0,-3,-5,-2,-1,-1,-5,-4,-3, 0, 4,-2,-6},
{ 0,-3,-1,-2,-4,-3,-3, 6,-3,-5,-5,-2,-4,-5,-3,-1,-3,-4,-5,-5,-2,-3,-2,-6},
{-2, 0, 0,-2,-5, 1,-1,-3, 8,-4,-4,-1,-3,-2,-3,-2,-2,-3, 1,-4,-1, 0,-2,-6},
{-2,-4,-4,-5,-2,-4,-4,-5,-4, 5, 1,-4, 1,-1,-4,-3,-1,-4,-2, 3,-5,-4,-2,-6},
{-2,-3,-4,-5,-2,-3,-4,-5,-4, 1, 5,-3, 2, 0,-4,-3,-2,-3,-2, 0,-5,-4,-2,-6},
{-1, 2, 0,-1,-4, 1, 0,-2,-1,-4,-3, 6,-2,-4,-2,-1,-1,-5,-3,-3,-1, 1,-1,-6},
{-2,-2,-3,-4,-2, 0,-3,-4,-3, 1, 2,-2, 7,-1,-3,-2,-1,-2,-2, 0,-4,-2,-1,-6},
{-3,-4,-4,-5,-3,-4,-5,-5,-2,-1, 0,-4,-1, 7,-4,-3,-3, 0, 3,-2,-4,-4,-2,-6},
{-1,-3,-3,-3,-4,-2,-2,-3,-3,-4,-4,-2,-3,-4, 8,-2,-2,-5,-4,-3,-3,-2,-2,-6},
{ 1,-1, 0,-1,-2,-1,-1,-1,-2,-3,-3,-1,-2,-3,-2, 5, 1,-4,-3,-2, 0,-1,-1,-6},
{ 0,-2, 0,-2,-2,-1,-1,-3,-2,-1,-2,-1,-1,-3,-2, 1, 6,-4,-2,-1,-1,-1,-1,-6},
{-4,-4,-5,-6,-4,-3,-5,-4,-3,-4,-3,-5,-2, 0,-5,-4,-4, 11, 2,-3,-6,-4,-3,-6},
{-3,-3,-3,-4,-4,-3,-4,-5, 1,-2,-2,-3,-2, 3,-4,-3,-2, 2, 8,-3,-4,-3,-2,-6},
{-1,-3,-4,-5,-2,-3,-3,-5,-4, 3, 0,-3, 0,-2,-3,-2,-1,-3,-3, 5,-4,-3,-2,-6},
{-2,-2, 4, 4,-4,-1, 0,-2,-1,-5,-5,-1,-4,-4,-3, 0,-1,-6,-4,-4, 4, 0,-2,-6},
{-1, 0,-1, 0,-5, 4, 4,-3, 0,-4,-4, 1,-2,-4,-2,-1,-1,-4,-3,-3, 0, 4,-1,-6},
{-1,-2,-2,-2,-3,-1,-2,-2,-2,-2,-2,-1,-1,-2,-2,-1,-1,-3,-2,-2,-2,-1,-2,-6},
{-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, 1},
}
+
+
+ +

◆ transcode

+ +
+
+ + + + +
int transcode[4][4][4]
+
+Initial value:
={{{ 11, 2 , 11, 2 },{ 16, 16, 16, 16},{ 1 , 15, 1 , 15},{ 9 , 9 , 12, 9 }},
{{ 5 , 8 , 5 , 8 },{ 14, 14, 14, 14},{ 1 , 1 , 1 , 1 },{ 10, 10, 10, 10 }},
{{ 6 , 3 , 6 , 3 },{ 0 , 0 , 0 , 0 },{ 7 , 7 , 7 , 7 },{ 19, 19, 19, 19}},
{{ -1, 18, -1, 18},{ 15, 15, 15, 15},{ -1, 4 , 17, 4 },{ 10, 13, 10, 13}}}
+
+
+
+ + + + diff --git a/src/html/code_8c__incl.map b/src/html/code_8c__incl.map new file mode 100644 index 0000000..1529277 --- /dev/null +++ b/src/html/code_8c__incl.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/code_8c__incl.md5 b/src/html/code_8c__incl.md5 new file mode 100644 index 0000000..26e9abd --- /dev/null +++ b/src/html/code_8c__incl.md5 @@ -0,0 +1 @@ +e417fdf92bf493f37237e416ed73fb82 \ No newline at end of file diff --git a/src/html/code_8c__incl.png b/src/html/code_8c__incl.png new file mode 100644 index 0000000..1a6a089 Binary files /dev/null and b/src/html/code_8c__incl.png differ diff --git a/src/html/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.map b/src/html/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.map new file mode 100644 index 0000000..fbc70b0 --- /dev/null +++ b/src/html/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 b/src/html/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 new file mode 100644 index 0000000..42a24c6 --- /dev/null +++ b/src/html/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 @@ -0,0 +1 @@ +a2d29ed604b593088932173e561f1e63 \ No newline at end of file diff --git a/src/html/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.png b/src/html/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.png new file mode 100644 index 0000000..587aaca Binary files /dev/null and b/src/html/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.png differ diff --git a/src/html/code_8h.html b/src/html/code_8h.html new file mode 100644 index 0000000..8fcbd35 --- /dev/null +++ b/src/html/code_8h.html @@ -0,0 +1,185 @@ + + + + + + + +My Project: code.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
code.h File Reference
+
+
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + + + + + + +
+
+

Go to the source code of this file.

+ + + + + + + + + + +

+Functions

int * encodeSeq (char *seq)
 
int encodeAA (char aa)
 
char decodeAA (int encodedAA)
 
char * translateSeq (char *seq)
 
+

Function Documentation

+ +

◆ decodeAA()

+ +
+
+ + + + + + + + +
char decodeAA (int encodedAA)
+
+ +
+
+ +

◆ encodeAA()

+ +
+
+ + + + + + + + +
int encodeAA (char aa)
+
+ +
+
+ +

◆ encodeSeq()

+ +
+
+ + + + + + + + +
int* encodeSeq (char * seq)
+
+ +
+
+ +

◆ translateSeq()

+ +
+
+ + + + + + + + +
char* translateSeq (char * seq)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+
+ + + + diff --git a/src/html/code_8h__dep__incl.map b/src/html/code_8h__dep__incl.map new file mode 100644 index 0000000..332af9f --- /dev/null +++ b/src/html/code_8h__dep__incl.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/html/code_8h__dep__incl.md5 b/src/html/code_8h__dep__incl.md5 new file mode 100644 index 0000000..83e007a --- /dev/null +++ b/src/html/code_8h__dep__incl.md5 @@ -0,0 +1 @@ +a3f827b430cacc229a19a08a539cfb9c \ No newline at end of file diff --git a/src/html/code_8h__dep__incl.png b/src/html/code_8h__dep__incl.png new file mode 100644 index 0000000..5adb0ff Binary files /dev/null and b/src/html/code_8h__dep__incl.png differ diff --git a/src/html/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.map b/src/html/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.map new file mode 100644 index 0000000..fbc70b0 --- /dev/null +++ b/src/html/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 b/src/html/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 new file mode 100644 index 0000000..42a24c6 --- /dev/null +++ b/src/html/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 @@ -0,0 +1 @@ +a2d29ed604b593088932173e561f1e63 \ No newline at end of file diff --git a/src/html/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.png b/src/html/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.png new file mode 100644 index 0000000..587aaca Binary files /dev/null and b/src/html/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.png differ diff --git a/src/html/code_8h_source.html b/src/html/code_8h_source.html new file mode 100644 index 0000000..996295c --- /dev/null +++ b/src/html/code_8h_source.html @@ -0,0 +1,77 @@ + + + + + + + +My Project: code.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
code.h
+
+
+Go to the documentation of this file.
1 /* Copyright 2009, Stefan Washietl
2 
3  This file is part of RNAcode.
4 
5  RNAcode is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  RNAcode is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with RNAcode. If not, see <http://www.gnu.org/licenses/>. */
17 
18 
19 #ifndef _CODE_H_
20 #define _CODE_H_
21 
22 int* encodeSeq(char* seq);
23 
24 int encodeAA(char aa);
25 
26 char decodeAA(int encodedAA);
27 
28 char* translateSeq(char* seq);
29 
30 #endif
char * translateSeq(char *seq)
Definition: code.c:103
+
char decodeAA(int encodedAA)
Definition: code.c:236
+
int encodeAA(char aa)
Definition: code.c:193
+
int * encodeSeq(char *seq)
Definition: code.c:140
+
+ + + + diff --git a/src/html/deprecated.html b/src/html/deprecated.html new file mode 100644 index 0000000..5ffe325 --- /dev/null +++ b/src/html/deprecated.html @@ -0,0 +1,77 @@ + + + + + + + +My Project: Deprecated List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+
+
Deprecated List
+
+
+
+
Member cmdline_parser2 (int argc, char *const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
+
use cmdline_parser_ext() instead
+
+
+ + + + diff --git a/src/html/doc.png b/src/html/doc.png new file mode 100644 index 0000000..17edabf Binary files /dev/null and b/src/html/doc.png differ diff --git a/src/html/doxygen.css b/src/html/doxygen.css new file mode 100644 index 0000000..4f1ab91 --- /dev/null +++ b/src/html/doxygen.css @@ -0,0 +1,1596 @@ +/* The standard CSS for doxygen 1.8.13 */ + +body, table, div, p, dl { + font: 400 14px/22px Roboto,sans-serif; +} + +p.reference, p.definition { + font: 400 14px/22px Roboto,sans-serif; +} + +/* @group Heading Levels */ + +h1.groupheader { + font-size: 150%; +} + +.title { + font: 400 14px/28px Roboto,sans-serif; + font-size: 150%; + font-weight: bold; + margin: 10px 2px; +} + +h2.groupheader { + border-bottom: 1px solid #879ECB; + color: #354C7B; + font-size: 150%; + font-weight: normal; + margin-top: 1.75em; + padding-top: 8px; + padding-bottom: 4px; + width: 100%; +} + +h3.groupheader { + font-size: 100%; +} + +h1, h2, h3, h4, h5, h6 { + -webkit-transition: text-shadow 0.5s linear; + -moz-transition: text-shadow 0.5s linear; + -ms-transition: text-shadow 0.5s linear; + -o-transition: text-shadow 0.5s linear; + transition: text-shadow 0.5s linear; + margin-right: 15px; +} + +h1.glow, h2.glow, h3.glow, h4.glow, h5.glow, h6.glow { + text-shadow: 0 0 15px cyan; +} + +dt { + font-weight: bold; +} + +div.multicol { + -moz-column-gap: 1em; + -webkit-column-gap: 1em; + -moz-column-count: 3; + -webkit-column-count: 3; +} + +p.startli, p.startdd { + margin-top: 2px; +} + +p.starttd { + margin-top: 0px; +} + +p.endli { + margin-bottom: 0px; +} + +p.enddd { + margin-bottom: 4px; +} + +p.endtd { + margin-bottom: 2px; +} + +/* @end */ + +caption { + font-weight: bold; +} + +span.legend { + font-size: 70%; + text-align: center; +} + +h3.version { + font-size: 90%; + text-align: center; +} + +div.qindex, div.navtab{ + background-color: #EBEFF6; + border: 1px solid #A3B4D7; + text-align: center; +} + +div.qindex, div.navpath { + width: 100%; + line-height: 140%; +} + +div.navtab { + margin-right: 15px; +} + +/* @group Link Styling */ + +a { + color: #3D578C; + font-weight: normal; + text-decoration: none; +} + +.contents a:visited { + color: #4665A2; +} + +a:hover { + text-decoration: underline; +} + +a.qindex { + font-weight: bold; +} + +a.qindexHL { + font-weight: bold; + background-color: #9CAFD4; + color: #ffffff; + border: 1px double #869DCA; +} + +.contents a.qindexHL:visited { + color: #ffffff; +} + +a.el { + font-weight: bold; +} + +a.elRef { +} + +a.code, a.code:visited, a.line, a.line:visited { + color: #4665A2; +} + +a.codeRef, a.codeRef:visited, a.lineRef, a.lineRef:visited { + color: #4665A2; +} + +/* @end */ + +dl.el { + margin-left: -1cm; +} + +pre.fragment { + border: 1px solid #C4CFE5; + background-color: #FBFCFD; + padding: 4px 6px; + margin: 4px 8px 4px 2px; + overflow: auto; + word-wrap: break-word; + font-size: 9pt; + line-height: 125%; + font-family: monospace, fixed; + font-size: 105%; +} + +div.fragment { + padding: 0px; + margin: 4px 8px 4px 2px; + background-color: #FBFCFD; + border: 1px solid #C4CFE5; +} + +div.line { + font-family: monospace, fixed; + font-size: 13px; + min-height: 13px; + line-height: 1.0; + text-wrap: unrestricted; + white-space: -moz-pre-wrap; /* Moz */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: -o-pre-wrap; /* Opera 7 */ + white-space: pre-wrap; /* CSS3 */ + word-wrap: break-word; /* IE 5.5+ */ + text-indent: -53px; + padding-left: 53px; + padding-bottom: 0px; + margin: 0px; + -webkit-transition-property: background-color, box-shadow; + -webkit-transition-duration: 0.5s; + -moz-transition-property: background-color, box-shadow; + -moz-transition-duration: 0.5s; + -ms-transition-property: background-color, box-shadow; + -ms-transition-duration: 0.5s; + -o-transition-property: background-color, box-shadow; + -o-transition-duration: 0.5s; + transition-property: background-color, box-shadow; + transition-duration: 0.5s; +} + +div.line:after { + content:"\000A"; + white-space: pre; +} + +div.line.glow { + background-color: cyan; + box-shadow: 0 0 10px cyan; +} + + +span.lineno { + padding-right: 4px; + text-align: right; + border-right: 2px solid #0F0; + background-color: #E8E8E8; + white-space: pre; +} +span.lineno a { + background-color: #D8D8D8; +} + +span.lineno a:hover { + background-color: #C8C8C8; +} + +.lineno { + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +div.ah, span.ah { + background-color: black; + font-weight: bold; + color: #ffffff; + margin-bottom: 3px; + margin-top: 3px; + padding: 0.2em; + border: solid thin #333; + border-radius: 0.5em; + -webkit-border-radius: .5em; + -moz-border-radius: .5em; + box-shadow: 2px 2px 3px #999; + -webkit-box-shadow: 2px 2px 3px #999; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px; + background-image: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#000),color-stop(0.3, #444)); + background-image: -moz-linear-gradient(center top, #eee 0%, #444 40%, #000 110%); +} + +div.classindex ul { + list-style: none; + padding-left: 0; +} + +div.classindex span.ai { + display: inline-block; +} + +div.groupHeader { + margin-left: 16px; + margin-top: 12px; + font-weight: bold; +} + +div.groupText { + margin-left: 16px; + font-style: italic; +} + +body { + background-color: white; + color: black; + margin: 0; +} + +div.contents { + margin-top: 10px; + margin-left: 12px; + margin-right: 8px; +} + +td.indexkey { + background-color: #EBEFF6; + font-weight: bold; + border: 1px solid #C4CFE5; + margin: 2px 0px 2px 0; + padding: 2px 10px; + white-space: nowrap; + vertical-align: top; +} + +td.indexvalue { + background-color: #EBEFF6; + border: 1px solid #C4CFE5; + padding: 2px 10px; + margin: 2px 0px; +} + +tr.memlist { + background-color: #EEF1F7; +} + +p.formulaDsp { + text-align: center; +} + +img.formulaDsp { + +} + +img.formulaInl { + vertical-align: middle; +} + +div.center { + text-align: center; + margin-top: 0px; + margin-bottom: 0px; + padding: 0px; +} + +div.center img { + border: 0px; +} + +address.footer { + text-align: right; + padding-right: 12px; +} + +img.footer { + border: 0px; + vertical-align: middle; +} + +/* @group Code Colorization */ + +span.keyword { + color: #008000 +} + +span.keywordtype { + color: #604020 +} + +span.keywordflow { + color: #e08000 +} + +span.comment { + color: #800000 +} + +span.preprocessor { + color: #806020 +} + +span.stringliteral { + color: #002080 +} + +span.charliteral { + color: #008080 +} + +span.vhdldigit { + color: #ff00ff +} + +span.vhdlchar { + color: #000000 +} + +span.vhdlkeyword { + color: #700070 +} + +span.vhdllogic { + color: #ff0000 +} + +blockquote { + background-color: #F7F8FB; + border-left: 2px solid #9CAFD4; + margin: 0 24px 0 4px; + padding: 0 12px 0 16px; +} + +/* @end */ + +/* +.search { + color: #003399; + font-weight: bold; +} + +form.search { + margin-bottom: 0px; + margin-top: 0px; +} + +input.search { + font-size: 75%; + color: #000080; + font-weight: normal; + background-color: #e8eef2; +} +*/ + +td.tiny { + font-size: 75%; +} + +.dirtab { + padding: 4px; + border-collapse: collapse; + border: 1px solid #A3B4D7; +} + +th.dirtab { + background: #EBEFF6; + font-weight: bold; +} + +hr { + height: 0px; + border: none; + border-top: 1px solid #4A6AAA; +} + +hr.footer { + height: 1px; +} + +/* @group Member Descriptions */ + +table.memberdecls { + border-spacing: 0px; + padding: 0px; +} + +.memberdecls td, .fieldtable tr { + -webkit-transition-property: background-color, box-shadow; + -webkit-transition-duration: 0.5s; + -moz-transition-property: background-color, box-shadow; + -moz-transition-duration: 0.5s; + -ms-transition-property: background-color, box-shadow; + -ms-transition-duration: 0.5s; + -o-transition-property: background-color, box-shadow; + -o-transition-duration: 0.5s; + transition-property: background-color, box-shadow; + transition-duration: 0.5s; +} + +.memberdecls td.glow, .fieldtable tr.glow { + background-color: cyan; + box-shadow: 0 0 15px cyan; +} + +.mdescLeft, .mdescRight, +.memItemLeft, .memItemRight, +.memTemplItemLeft, .memTemplItemRight, .memTemplParams { + background-color: #F9FAFC; + border: none; + margin: 4px; + padding: 1px 0 0 8px; +} + +.mdescLeft, .mdescRight { + padding: 0px 8px 4px 8px; + color: #555; +} + +.memSeparator { + border-bottom: 1px solid #DEE4F0; + line-height: 1px; + margin: 0px; + padding: 0px; +} + +.memItemLeft, .memTemplItemLeft { + white-space: nowrap; +} + +.memItemRight { + width: 100%; +} + +.memTemplParams { + color: #4665A2; + white-space: nowrap; + font-size: 80%; +} + +/* @end */ + +/* @group Member Details */ + +/* Styles for detailed member documentation */ + +.memtitle { + padding: 8px; + border-top: 1px solid #A8B8D9; + border-left: 1px solid #A8B8D9; + border-right: 1px solid #A8B8D9; + border-top-right-radius: 4px; + border-top-left-radius: 4px; + margin-bottom: -1px; + background-image: url('nav_f.png'); + background-repeat: repeat-x; + background-color: #E2E8F2; + line-height: 1.25; + font-weight: 300; + float:left; +} + +.permalink +{ + font-size: 65%; + display: inline-block; + vertical-align: middle; +} + +.memtemplate { + font-size: 80%; + color: #4665A2; + font-weight: normal; + margin-left: 9px; +} + +.memnav { + background-color: #EBEFF6; + border: 1px solid #A3B4D7; + text-align: center; + margin: 2px; + margin-right: 15px; + padding: 2px; +} + +.mempage { + width: 100%; +} + +.memitem { + padding: 0; + margin-bottom: 10px; + margin-right: 5px; + -webkit-transition: box-shadow 0.5s linear; + -moz-transition: box-shadow 0.5s linear; + -ms-transition: box-shadow 0.5s linear; + -o-transition: box-shadow 0.5s linear; + transition: box-shadow 0.5s linear; + display: table !important; + width: 100%; +} + +.memitem.glow { + box-shadow: 0 0 15px cyan; +} + +.memname { + font-weight: 400; + margin-left: 6px; +} + +.memname td { + vertical-align: bottom; +} + +.memproto, dl.reflist dt { + border-top: 1px solid #A8B8D9; + border-left: 1px solid #A8B8D9; + border-right: 1px solid #A8B8D9; + padding: 6px 0px 6px 0px; + color: #253555; + font-weight: bold; + text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); + background-color: #DFE5F1; + /* opera specific markup */ + box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + border-top-right-radius: 4px; + /* firefox specific markup */ + -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; + -moz-border-radius-topright: 4px; + /* webkit specific markup */ + -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + -webkit-border-top-right-radius: 4px; + +} + +.overload { + font-family: "courier new",courier,monospace; + font-size: 65%; +} + +.memdoc, dl.reflist dd { + border-bottom: 1px solid #A8B8D9; + border-left: 1px solid #A8B8D9; + border-right: 1px solid #A8B8D9; + padding: 6px 10px 2px 10px; + background-color: #FBFCFD; + border-top-width: 0; + background-image:url('nav_g.png'); + background-repeat:repeat-x; + background-color: #FFFFFF; + /* opera specific markup */ + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; + box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + /* firefox specific markup */ + -moz-border-radius-bottomleft: 4px; + -moz-border-radius-bottomright: 4px; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; + /* webkit specific markup */ + -webkit-border-bottom-left-radius: 4px; + -webkit-border-bottom-right-radius: 4px; + -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); +} + +dl.reflist dt { + padding: 5px; +} + +dl.reflist dd { + margin: 0px 0px 10px 0px; + padding: 5px; +} + +.paramkey { + text-align: right; +} + +.paramtype { + white-space: nowrap; +} + +.paramname { + color: #602020; + white-space: nowrap; +} +.paramname em { + font-style: normal; +} +.paramname code { + line-height: 14px; +} + +.params, .retval, .exception, .tparams { + margin-left: 0px; + padding-left: 0px; +} + +.params .paramname, .retval .paramname { + font-weight: bold; + vertical-align: top; +} + +.params .paramtype { + font-style: italic; + vertical-align: top; +} + +.params .paramdir { + font-family: "courier new",courier,monospace; + vertical-align: top; +} + +table.mlabels { + border-spacing: 0px; +} + +td.mlabels-left { + width: 100%; + padding: 0px; +} + +td.mlabels-right { + vertical-align: bottom; + padding: 0px; + white-space: nowrap; +} + +span.mlabels { + margin-left: 8px; +} + +span.mlabel { + background-color: #728DC1; + border-top:1px solid #5373B4; + border-left:1px solid #5373B4; + border-right:1px solid #C4CFE5; + border-bottom:1px solid #C4CFE5; + text-shadow: none; + color: white; + margin-right: 4px; + padding: 2px 3px; + border-radius: 3px; + font-size: 7pt; + white-space: nowrap; + vertical-align: middle; +} + + + +/* @end */ + +/* these are for tree view inside a (index) page */ + +div.directory { + margin: 10px 0px; + border-top: 1px solid #9CAFD4; + border-bottom: 1px solid #9CAFD4; + width: 100%; +} + +.directory table { + border-collapse:collapse; +} + +.directory td { + margin: 0px; + padding: 0px; + vertical-align: top; +} + +.directory td.entry { + white-space: nowrap; + padding-right: 6px; + padding-top: 3px; +} + +.directory td.entry a { + outline:none; +} + +.directory td.entry a img { + border: none; +} + +.directory td.desc { + width: 100%; + padding-left: 6px; + padding-right: 6px; + padding-top: 3px; + border-left: 1px solid rgba(0,0,0,0.05); +} + +.directory tr.even { + padding-left: 6px; + background-color: #F7F8FB; +} + +.directory img { + vertical-align: -30%; +} + +.directory .levels { + white-space: nowrap; + width: 100%; + text-align: right; + font-size: 9pt; +} + +.directory .levels span { + cursor: pointer; + padding-left: 2px; + padding-right: 2px; + color: #3D578C; +} + +.arrow { + color: #9CAFD4; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + cursor: pointer; + font-size: 80%; + display: inline-block; + width: 16px; + height: 22px; +} + +.icon { + font-family: Arial, Helvetica; + font-weight: bold; + font-size: 12px; + height: 14px; + width: 16px; + display: inline-block; + background-color: #728DC1; + color: white; + text-align: center; + border-radius: 4px; + margin-left: 2px; + margin-right: 2px; +} + +.icona { + width: 24px; + height: 22px; + display: inline-block; +} + +.iconfopen { + width: 24px; + height: 18px; + margin-bottom: 4px; + background-image:url('folderopen.png'); + background-position: 0px -4px; + background-repeat: repeat-y; + vertical-align:top; + display: inline-block; +} + +.iconfclosed { + width: 24px; + height: 18px; + margin-bottom: 4px; + background-image:url('folderclosed.png'); + background-position: 0px -4px; + background-repeat: repeat-y; + vertical-align:top; + display: inline-block; +} + +.icondoc { + width: 24px; + height: 18px; + margin-bottom: 4px; + background-image:url('doc.png'); + background-position: 0px -4px; + background-repeat: repeat-y; + vertical-align:top; + display: inline-block; +} + +table.directory { + font: 400 14px Roboto,sans-serif; +} + +/* @end */ + +div.dynheader { + margin-top: 8px; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +address { + font-style: normal; + color: #2A3D61; +} + +table.doxtable caption { + caption-side: top; +} + +table.doxtable { + border-collapse:collapse; + margin-top: 4px; + margin-bottom: 4px; +} + +table.doxtable td, table.doxtable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +table.doxtable th { + background-color: #374F7F; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; +} + +table.fieldtable { + /*width: 100%;*/ + margin-bottom: 10px; + border: 1px solid #A8B8D9; + border-spacing: 0px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + border-radius: 4px; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px; + -webkit-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.15); + box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.15); +} + +.fieldtable td, .fieldtable th { + padding: 3px 7px 2px; +} + +.fieldtable td.fieldtype, .fieldtable td.fieldname { + white-space: nowrap; + border-right: 1px solid #A8B8D9; + border-bottom: 1px solid #A8B8D9; + vertical-align: top; +} + +.fieldtable td.fieldname { + padding-top: 3px; +} + +.fieldtable td.fielddoc { + border-bottom: 1px solid #A8B8D9; + /*width: 100%;*/ +} + +.fieldtable td.fielddoc p:first-child { + margin-top: 0px; +} + +.fieldtable td.fielddoc p:last-child { + margin-bottom: 2px; +} + +.fieldtable tr:last-child td { + border-bottom: none; +} + +.fieldtable th { + background-image:url('nav_f.png'); + background-repeat:repeat-x; + background-color: #E2E8F2; + font-size: 90%; + color: #253555; + padding-bottom: 4px; + padding-top: 5px; + text-align:left; + font-weight: 400; + -moz-border-radius-topleft: 4px; + -moz-border-radius-topright: 4px; + -webkit-border-top-left-radius: 4px; + -webkit-border-top-right-radius: 4px; + border-top-left-radius: 4px; + border-top-right-radius: 4px; + border-bottom: 1px solid #A8B8D9; +} + + +.tabsearch { + top: 0px; + left: 10px; + height: 36px; + background-image: url('tab_b.png'); + z-index: 101; + overflow: hidden; + font-size: 13px; +} + +.navpath ul +{ + font-size: 11px; + background-image:url('tab_b.png'); + background-repeat:repeat-x; + background-position: 0 -5px; + height:30px; + line-height:30px; + color:#8AA0CC; + border:solid 1px #C2CDE4; + overflow:hidden; + margin:0px; + padding:0px; +} + +.navpath li +{ + list-style-type:none; + float:left; + padding-left:10px; + padding-right:15px; + background-image:url('bc_s.png'); + background-repeat:no-repeat; + background-position:right; + color:#364D7C; +} + +.navpath li.navelem a +{ + height:32px; + display:block; + text-decoration: none; + outline: none; + color: #283A5D; + font-family: 'Lucida Grande',Geneva,Helvetica,Arial,sans-serif; + text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); + text-decoration: none; +} + +.navpath li.navelem a:hover +{ + color:#6884BD; +} + +.navpath li.footer +{ + list-style-type:none; + float:right; + padding-left:10px; + padding-right:15px; + background-image:none; + background-repeat:no-repeat; + background-position:right; + color:#364D7C; + font-size: 8pt; +} + + +div.summary +{ + float: right; + font-size: 8pt; + padding-right: 5px; + width: 50%; + text-align: right; +} + +div.summary a +{ + white-space: nowrap; +} + +table.classindex +{ + margin: 10px; + white-space: nowrap; + margin-left: 3%; + margin-right: 3%; + width: 94%; + border: 0; + border-spacing: 0; + padding: 0; +} + +div.ingroups +{ + font-size: 8pt; + width: 50%; + text-align: left; +} + +div.ingroups a +{ + white-space: nowrap; +} + +div.header +{ + background-image:url('nav_h.png'); + background-repeat:repeat-x; + background-color: #F9FAFC; + margin: 0px; + border-bottom: 1px solid #C4CFE5; +} + +div.headertitle +{ + padding: 5px 5px 5px 10px; +} + +dl +{ + padding: 0 0 0 10px; +} + +/* dl.note, dl.warning, dl.attention, dl.pre, dl.post, dl.invariant, dl.deprecated, dl.todo, dl.test, dl.bug */ +dl.section +{ + margin-left: 0px; + padding-left: 0px; +} + +dl.note +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #D0C000; +} + +dl.warning, dl.attention +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #FF0000; +} + +dl.pre, dl.post, dl.invariant +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #00D000; +} + +dl.deprecated +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #505050; +} + +dl.todo +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #00C0E0; +} + +dl.test +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #3030E0; +} + +dl.bug +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #C08050; +} + +dl.section dd { + margin-bottom: 6px; +} + + +#projectlogo +{ + text-align: center; + vertical-align: bottom; + border-collapse: separate; +} + +#projectlogo img +{ + border: 0px none; +} + +#projectalign +{ + vertical-align: middle; +} + +#projectname +{ + font: 300% Tahoma, Arial,sans-serif; + margin: 0px; + padding: 2px 0px; +} + +#projectbrief +{ + font: 120% Tahoma, Arial,sans-serif; + margin: 0px; + padding: 0px; +} + +#projectnumber +{ + font: 50% Tahoma, Arial,sans-serif; + margin: 0px; + padding: 0px; +} + +#titlearea +{ + padding: 0px; + margin: 0px; + width: 100%; + border-bottom: 1px solid #5373B4; +} + +.image +{ + text-align: center; +} + +.dotgraph +{ + text-align: center; +} + +.mscgraph +{ + text-align: center; +} + +.plantumlgraph +{ + text-align: center; +} + +.diagraph +{ + text-align: center; +} + +.caption +{ + font-weight: bold; +} + +div.zoom +{ + border: 1px solid #90A5CE; +} + +dl.citelist { + margin-bottom:50px; +} + +dl.citelist dt { + color:#334975; + float:left; + font-weight:bold; + margin-right:10px; + padding:5px; +} + +dl.citelist dd { + margin:2px 0; + padding:5px 0; +} + +div.toc { + padding: 14px 25px; + background-color: #F4F6FA; + border: 1px solid #D8DFEE; + border-radius: 7px 7px 7px 7px; + float: right; + height: auto; + margin: 0 8px 10px 10px; + width: 200px; +} + +div.toc li { + background: url("bdwn.png") no-repeat scroll 0 5px transparent; + font: 10px/1.2 Verdana,DejaVu Sans,Geneva,sans-serif; + margin-top: 5px; + padding-left: 10px; + padding-top: 2px; +} + +div.toc h3 { + font: bold 12px/1.2 Arial,FreeSans,sans-serif; + color: #4665A2; + border-bottom: 0 none; + margin: 0; +} + +div.toc ul { + list-style: none outside none; + border: medium none; + padding: 0px; +} + +div.toc li.level1 { + margin-left: 0px; +} + +div.toc li.level2 { + margin-left: 15px; +} + +div.toc li.level3 { + margin-left: 30px; +} + +div.toc li.level4 { + margin-left: 45px; +} + +.inherit_header { + font-weight: bold; + color: gray; + cursor: pointer; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.inherit_header td { + padding: 6px 0px 2px 5px; +} + +.inherit { + display: none; +} + +tr.heading h2 { + margin-top: 12px; + margin-bottom: 4px; +} + +/* tooltip related style info */ + +.ttc { + position: absolute; + display: none; +} + +#powerTip { + cursor: default; + white-space: nowrap; + background-color: white; + border: 1px solid gray; + border-radius: 4px 4px 4px 4px; + box-shadow: 1px 1px 7px gray; + display: none; + font-size: smaller; + max-width: 80%; + opacity: 0.9; + padding: 1ex 1em 1em; + position: absolute; + z-index: 2147483647; +} + +#powerTip div.ttdoc { + color: grey; + font-style: italic; +} + +#powerTip div.ttname a { + font-weight: bold; +} + +#powerTip div.ttname { + font-weight: bold; +} + +#powerTip div.ttdeci { + color: #006318; +} + +#powerTip div { + margin: 0px; + padding: 0px; + font: 12px/16px Roboto,sans-serif; +} + +#powerTip:before, #powerTip:after { + content: ""; + position: absolute; + margin: 0px; +} + +#powerTip.n:after, #powerTip.n:before, +#powerTip.s:after, #powerTip.s:before, +#powerTip.w:after, #powerTip.w:before, +#powerTip.e:after, #powerTip.e:before, +#powerTip.ne:after, #powerTip.ne:before, +#powerTip.se:after, #powerTip.se:before, +#powerTip.nw:after, #powerTip.nw:before, +#powerTip.sw:after, #powerTip.sw:before { + border: solid transparent; + content: " "; + height: 0; + width: 0; + position: absolute; +} + +#powerTip.n:after, #powerTip.s:after, +#powerTip.w:after, #powerTip.e:after, +#powerTip.nw:after, #powerTip.ne:after, +#powerTip.sw:after, #powerTip.se:after { + border-color: rgba(255, 255, 255, 0); +} + +#powerTip.n:before, #powerTip.s:before, +#powerTip.w:before, #powerTip.e:before, +#powerTip.nw:before, #powerTip.ne:before, +#powerTip.sw:before, #powerTip.se:before { + border-color: rgba(128, 128, 128, 0); +} + +#powerTip.n:after, #powerTip.n:before, +#powerTip.ne:after, #powerTip.ne:before, +#powerTip.nw:after, #powerTip.nw:before { + top: 100%; +} + +#powerTip.n:after, #powerTip.ne:after, #powerTip.nw:after { + border-top-color: #ffffff; + border-width: 10px; + margin: 0px -10px; +} +#powerTip.n:before { + border-top-color: #808080; + border-width: 11px; + margin: 0px -11px; +} +#powerTip.n:after, #powerTip.n:before { + left: 50%; +} + +#powerTip.nw:after, #powerTip.nw:before { + right: 14px; +} + +#powerTip.ne:after, #powerTip.ne:before { + left: 14px; +} + +#powerTip.s:after, #powerTip.s:before, +#powerTip.se:after, #powerTip.se:before, +#powerTip.sw:after, #powerTip.sw:before { + bottom: 100%; +} + +#powerTip.s:after, #powerTip.se:after, #powerTip.sw:after { + border-bottom-color: #ffffff; + border-width: 10px; + margin: 0px -10px; +} + +#powerTip.s:before, #powerTip.se:before, #powerTip.sw:before { + border-bottom-color: #808080; + border-width: 11px; + margin: 0px -11px; +} + +#powerTip.s:after, #powerTip.s:before { + left: 50%; +} + +#powerTip.sw:after, #powerTip.sw:before { + right: 14px; +} + +#powerTip.se:after, #powerTip.se:before { + left: 14px; +} + +#powerTip.e:after, #powerTip.e:before { + left: 100%; +} +#powerTip.e:after { + border-left-color: #ffffff; + border-width: 10px; + top: 50%; + margin-top: -10px; +} +#powerTip.e:before { + border-left-color: #808080; + border-width: 11px; + top: 50%; + margin-top: -11px; +} + +#powerTip.w:after, #powerTip.w:before { + right: 100%; +} +#powerTip.w:after { + border-right-color: #ffffff; + border-width: 10px; + top: 50%; + margin-top: -10px; +} +#powerTip.w:before { + border-right-color: #808080; + border-width: 11px; + top: 50%; + margin-top: -11px; +} + +@media print +{ + #top { display: none; } + #side-nav { display: none; } + #nav-path { display: none; } + body { overflow:visible; } + h1, h2, h3, h4, h5, h6 { page-break-after: avoid; } + .summary { display: none; } + .memitem { page-break-inside: avoid; } + #doc-content + { + margin-left:0 !important; + height:auto !important; + width:auto !important; + overflow:inherit; + display:inline; + } +} + +/* @group Markdown */ + +/* +table.markdownTable { + border-collapse:collapse; + margin-top: 4px; + margin-bottom: 4px; +} + +table.markdownTable td, table.markdownTable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +table.markdownTableHead tr { +} + +table.markdownTableBodyLeft td, table.markdownTable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +th.markdownTableHeadLeft th.markdownTableHeadRight th.markdownTableHeadCenter th.markdownTableHeadNone { + background-color: #374F7F; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; +} + +th.markdownTableHeadLeft { + text-align: left +} + +th.markdownTableHeadRight { + text-align: right +} + +th.markdownTableHeadCenter { + text-align: center +} +*/ + +table.markdownTable { + border-collapse:collapse; + margin-top: 4px; + margin-bottom: 4px; +} + +table.markdownTable td, table.markdownTable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +table.markdownTable tr { +} + +th.markdownTableHeadLeft, th.markdownTableHeadRight, th.markdownTableHeadCenter, th.markdownTableHeadNone { + background-color: #374F7F; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; +} + +th.markdownTableHeadLeft, td.markdownTableBodyLeft { + text-align: left +} + +th.markdownTableHeadRight, td.markdownTableBodyRight { + text-align: right +} + +th.markdownTableHeadCenter, td.markdownTableBodyCenter { + text-align: center +} + + +/* @end */ diff --git a/src/html/doxygen.png b/src/html/doxygen.png new file mode 100644 index 0000000..3ff17d8 Binary files /dev/null and b/src/html/doxygen.png differ diff --git a/src/html/dynsections.js b/src/html/dynsections.js new file mode 100644 index 0000000..85e1836 --- /dev/null +++ b/src/html/dynsections.js @@ -0,0 +1,97 @@ +function toggleVisibility(linkObj) +{ + var base = $(linkObj).attr('id'); + var summary = $('#'+base+'-summary'); + var content = $('#'+base+'-content'); + var trigger = $('#'+base+'-trigger'); + var src=$(trigger).attr('src'); + if (content.is(':visible')===true) { + content.hide(); + summary.show(); + $(linkObj).addClass('closed').removeClass('opened'); + $(trigger).attr('src',src.substring(0,src.length-8)+'closed.png'); + } else { + content.show(); + summary.hide(); + $(linkObj).removeClass('closed').addClass('opened'); + $(trigger).attr('src',src.substring(0,src.length-10)+'open.png'); + } + return false; +} + +function updateStripes() +{ + $('table.directory tr'). + removeClass('even').filter(':visible:even').addClass('even'); +} + +function toggleLevel(level) +{ + $('table.directory tr').each(function() { + var l = this.id.split('_').length-1; + var i = $('#img'+this.id.substring(3)); + var a = $('#arr'+this.id.substring(3)); + if (l + + + + + + +My Project: extreme_fit.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
extreme_fit.c File Reference
+
+
+
#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include "extreme_fit.h"
+#include "lm.h"
+
+Include dependency graph for extreme_fit.c:
+
+
+ + + +
+
+ + + + + + + +

+Functions

void Lawless416 (double *x, int *y, int n, double lambda, double *ret_f, double *ret_df)
 
void Lawless422 (double *x, int *y, int n, int z, double c, double lambda, double *ret_f, double *ret_df)
 
int EVDMaxLikelyFit (double *x, int *c, int n, double *ret_mu, double *ret_lambda)
 
+

Function Documentation

+ +

◆ EVDMaxLikelyFit()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int EVDMaxLikelyFit (double * x,
int * c,
int n,
double * ret_mu,
double * ret_lambda 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ Lawless416()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void Lawless416 (double * x,
int * y,
int n,
double lambda,
double * ret_f,
double * ret_df 
)
+
+ +
+
+ +

◆ Lawless422()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void Lawless422 (double * x,
int * y,
int n,
int z,
double c,
double lambda,
double * ret_f,
double * ret_df 
)
+
+ +
+
+
+ + + + diff --git a/src/html/extreme__fit_8c__incl.map b/src/html/extreme__fit_8c__incl.map new file mode 100644 index 0000000..ec32ad8 --- /dev/null +++ b/src/html/extreme__fit_8c__incl.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/extreme__fit_8c__incl.md5 b/src/html/extreme__fit_8c__incl.md5 new file mode 100644 index 0000000..e932276 --- /dev/null +++ b/src/html/extreme__fit_8c__incl.md5 @@ -0,0 +1 @@ +e49057e0185f68ea5bdc09dab23a1e7d \ No newline at end of file diff --git a/src/html/extreme__fit_8c__incl.png b/src/html/extreme__fit_8c__incl.png new file mode 100644 index 0000000..e3a3580 Binary files /dev/null and b/src/html/extreme__fit_8c__incl.png differ diff --git a/src/html/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.map b/src/html/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.map new file mode 100644 index 0000000..716402b --- /dev/null +++ b/src/html/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 b/src/html/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 new file mode 100644 index 0000000..2510a9b --- /dev/null +++ b/src/html/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 @@ -0,0 +1 @@ +1e52339befe919c4980ca24827890d74 \ No newline at end of file diff --git a/src/html/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.png b/src/html/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.png new file mode 100644 index 0000000..587dba9 Binary files /dev/null and b/src/html/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.png differ diff --git a/src/html/extreme__fit_8h.html b/src/html/extreme__fit_8h.html new file mode 100644 index 0000000..0c4ed8f --- /dev/null +++ b/src/html/extreme__fit_8h.html @@ -0,0 +1,148 @@ + + + + + + + +My Project: extreme_fit.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
extreme_fit.h File Reference
+
+
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + + +
+
+

Go to the source code of this file.

+ + + + +

+Functions

int EVDMaxLikelyFit (double *x, int *c, int n, double *ret_mu, double *ret_lambda)
 
+

Function Documentation

+ +

◆ EVDMaxLikelyFit()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int EVDMaxLikelyFit (double * x,
int * c,
int n,
double * ret_mu,
double * ret_lambda 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+
+ + + + diff --git a/src/html/extreme__fit_8h__dep__incl.map b/src/html/extreme__fit_8h__dep__incl.map new file mode 100644 index 0000000..fa0203c --- /dev/null +++ b/src/html/extreme__fit_8h__dep__incl.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/extreme__fit_8h__dep__incl.md5 b/src/html/extreme__fit_8h__dep__incl.md5 new file mode 100644 index 0000000..2c04e9f --- /dev/null +++ b/src/html/extreme__fit_8h__dep__incl.md5 @@ -0,0 +1 @@ +60b886df855cec2cb7abed42ea8a583d \ No newline at end of file diff --git a/src/html/extreme__fit_8h__dep__incl.png b/src/html/extreme__fit_8h__dep__incl.png new file mode 100644 index 0000000..dc0ab01 Binary files /dev/null and b/src/html/extreme__fit_8h__dep__incl.png differ diff --git a/src/html/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.map b/src/html/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.map new file mode 100644 index 0000000..716402b --- /dev/null +++ b/src/html/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 b/src/html/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 new file mode 100644 index 0000000..2510a9b --- /dev/null +++ b/src/html/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 @@ -0,0 +1 @@ +1e52339befe919c4980ca24827890d74 \ No newline at end of file diff --git a/src/html/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.png b/src/html/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.png new file mode 100644 index 0000000..587dba9 Binary files /dev/null and b/src/html/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.png differ diff --git a/src/html/extreme__fit_8h_source.html b/src/html/extreme__fit_8h_source.html new file mode 100644 index 0000000..2c0554c --- /dev/null +++ b/src/html/extreme__fit_8h_source.html @@ -0,0 +1,74 @@ + + + + + + + +My Project: extreme_fit.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
extreme_fit.h
+
+
+Go to the documentation of this file.
1 /* Copyright 2009, Stefan Washietl
2 
3  This file is part of RNAcode.
4 
5  RNAcode is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  RNAcode is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with RNAcode. If not, see <http://www.gnu.org/licenses/>. */
17 
18 
19 int EVDMaxLikelyFit(double *x, int *c, int n, double *ret_mu, double *ret_lambda);
int EVDMaxLikelyFit(double *x, int *c, int n, double *ret_mu, double *ret_lambda)
Definition: extreme_fit.c:158
+
+ + + + diff --git a/src/html/files.html b/src/html/files.html new file mode 100644 index 0000000..e7af2a9 --- /dev/null +++ b/src/html/files.html @@ -0,0 +1,103 @@ + + + + + + + +My Project: File List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
File List
+
+
+
Here is a list of all files with brief descriptions:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
 cmdline.c
 cmdline.hThe header file for the command line option parser generated by GNU Gengetopt version 2.22.1 http://www.gnu.org/software/gengetopt. DO NOT modify this file, since it can be overwritten
 code.c
 code.h
 extreme_fit.c
 extreme_fit.h
 getopt.c
 getopt.h
 misc.c
 misc.h
 postscript.c
 postscript.h
 RNAcode.c
 RNAcode.h
 rnaz_utils.c
 rnaz_utils.h
 score.c
 score.h
 treeML.c
 treeML.h
 treeSimulate.c
 treeSimulate.h
 utils.c
 utils.h
 weight.c
 weight.h
+
+
+ + + + diff --git a/src/html/folderclosed.png b/src/html/folderclosed.png new file mode 100644 index 0000000..bb8ab35 Binary files /dev/null and b/src/html/folderclosed.png differ diff --git a/src/html/folderopen.png b/src/html/folderopen.png new file mode 100644 index 0000000..d6c7f67 Binary files /dev/null and b/src/html/folderopen.png differ diff --git a/src/html/functions.html b/src/html/functions.html new file mode 100644 index 0000000..cbaa881 --- /dev/null +++ b/src/html/functions.html @@ -0,0 +1,501 @@ + + + + + + + +My Project: Class Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all class members with links to the classes they belong to:
+ +

- b -

+ + +

- c -

+ + +

- d -

+ + +

- e -

+ + +

- f -

+ + +

- g -

+ + +

- h -

+ + +

- i -

+ + +

- k -

+ + +

- l -

+ + +

- m -

+ + +

- n -

+ + +

- o -

+ + +

- p -

+ + +

- s -

+ + +

- t -

+ + +

- v -

+ + +

- w -

+ + +

- z -

+
+ + + + diff --git a/src/html/functions_vars.html b/src/html/functions_vars.html new file mode 100644 index 0000000..beb1ed9 --- /dev/null +++ b/src/html/functions_vars.html @@ -0,0 +1,501 @@ + + + + + + + +My Project: Class Members - Variables + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- b -

+ + +

- c -

+ + +

- d -

+ + +

- e -

+ + +

- f -

+ + +

- g -

+ + +

- h -

+ + +

- i -

+ + +

- k -

+ + +

- l -

+ + +

- m -

+ + +

- n -

+ + +

- o -

+ + +

- p -

+ + +

- s -

+ + +

- t -

+ + +

- v -

+ + +

- w -

+ + +

- z -

+
+ + + + diff --git a/src/html/getopt_8c.html b/src/html/getopt_8c.html new file mode 100644 index 0000000..c225b10 --- /dev/null +++ b/src/html/getopt_8c.html @@ -0,0 +1,739 @@ + + + + + + + +My Project: getopt.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
getopt.c File Reference
+
+
+
#include <stdio.h>
+#include "getopt.h"
+#include <strings.h>
+
+Include dependency graph for getopt.c:
+
+
+ + + +
+
+ + + + + + + + + + + + + +

+Macros

#define _NO_PROTO
 
#define const
 
#define GETOPT_INTERFACE_VERSION   2
 
#define _(msgid)   (msgid)
 
#define SWAP_FLAGS(ch1, ch2)
 
#define NONOPTION_P   (argv[optind][0] != '-' || argv[optind][1] == '\0')
 
+ + + +

+Enumerations

enum  { REQUIRE_ORDER, +PERMUTE, +RETURN_IN_ORDER + }
 
+ + + + + + + + + + + + + +

+Functions

char * getenv ()
 
static char * my_index (char *str, int chr) const
 
static void exchange (char **argv)
 
static const char * _getopt_initialize (int argc, char *const *argv, const char *optstring)
 
int _getopt_internal (int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only)
 
int getopt (int argc, char *const *argv, const char *optstring)
 
+ + + + + + + + + + + + + + + + + + + + + +

+Variables

char * optarg
 
int optind = 1
 
int __getopt_initialized
 
static char * nextchar
 
int opterr = 1
 
int optopt = '?'
 
static enum { ... }  ordering
 
static char * posixly_correct
 
static int first_nonopt
 
static int last_nonopt
 
+

Macro Definition Documentation

+ +

◆ _

+ +
+
+ + + + + + + + +
#define _( msgid)   (msgid)
+
+ +
+
+ +

◆ _NO_PROTO

+ +
+
+ + + + +
#define _NO_PROTO
+
+ +
+
+ +

◆ const

+ +
+
+ + + + +
#define const
+
+ +
+
+ +

◆ GETOPT_INTERFACE_VERSION

+ +
+
+ + + + +
#define GETOPT_INTERFACE_VERSION   2
+
+ +
+
+ +

◆ NONOPTION_P

+ +
+
+ + + + +
#define NONOPTION_P   (argv[optind][0] != '-' || argv[optind][1] == '\0')
+
+ +
+
+ +

◆ SWAP_FLAGS

+ +
+
+ + + + + + + + + + + + + + + + + + +
#define SWAP_FLAGS( ch1,
 ch2 
)
+
+ +
+
+

Enumeration Type Documentation

+ +

◆ anonymous enum

+ +
+
+ + + + +
anonymous enum
+
+ + + + +
Enumerator
REQUIRE_ORDER 
PERMUTE 
RETURN_IN_ORDER 
+ +
+
+

Function Documentation

+ +

◆ _getopt_initialize()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
static const char* _getopt_initialize (int argc,
char *constargv,
const char * optstring 
)
+
+static
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ _getopt_internal()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int _getopt_internal (int argc,
char *constargv,
const char * optstring,
const struct optionlongopts,
int * longind,
int long_only 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + +
+ +
+
+ +

◆ exchange()

+ +
+
+ + + + + +
+ + + + + + + + +
static void exchange (char ** argv)
+
+static
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ getenv()

+ +
+
+ + + + + + + +
char* getenv ()
+
+ +
+
+ +

◆ getopt()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int getopt (int argc,
char *constargv,
const char * optstring 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ my_index()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
static char* my_index (char * str,
int chr 
) const
+
+static
+
+ +
+
+

Variable Documentation

+ +

◆ __getopt_initialized

+ +
+
+ + + + +
int __getopt_initialized
+
+ +
+
+ +

◆ first_nonopt

+ +
+
+ + + + + +
+ + + + +
int first_nonopt
+
+static
+
+ +
+
+ +

◆ last_nonopt

+ +
+
+ + + + + +
+ + + + +
int last_nonopt
+
+static
+
+ +
+
+ +

◆ nextchar

+ +
+
+ + + + + +
+ + + + +
char* nextchar
+
+static
+
+ +
+
+ +

◆ optarg

+ +
+
+ + + + +
char* optarg
+
+ +
+
+ +

◆ opterr

+ +
+
+ + + + +
int opterr = 1
+
+ +
+
+ +

◆ optind

+ +
+
+ + + + +
int optind = 1
+
+ +
+
+ +

◆ optopt

+ +
+
+ + + + +
int optopt = '?'
+
+ +
+
+ +

◆ ordering

+ +
+
+ + + + +
enum { ... } ordering
+
+ +
+
+ +

◆ posixly_correct

+ +
+
+ + + + + +
+ + + + +
char* posixly_correct
+
+static
+
+ +
+
+
+ + + + diff --git a/src/html/getopt_8c__incl.map b/src/html/getopt_8c__incl.map new file mode 100644 index 0000000..4cefeea --- /dev/null +++ b/src/html/getopt_8c__incl.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/getopt_8c__incl.md5 b/src/html/getopt_8c__incl.md5 new file mode 100644 index 0000000..59baf54 --- /dev/null +++ b/src/html/getopt_8c__incl.md5 @@ -0,0 +1 @@ +5eae473d319f8371fdda2900d599e284 \ No newline at end of file diff --git a/src/html/getopt_8c__incl.png b/src/html/getopt_8c__incl.png new file mode 100644 index 0000000..b75d2d7 Binary files /dev/null and b/src/html/getopt_8c__incl.png differ diff --git a/src/html/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.map b/src/html/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.map new file mode 100644 index 0000000..4079b46 --- /dev/null +++ b/src/html/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.map @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/html/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.md5 b/src/html/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.md5 new file mode 100644 index 0000000..b1d3512 --- /dev/null +++ b/src/html/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.md5 @@ -0,0 +1 @@ +9ae2517cbc6c91162cd98975348db0b5 \ No newline at end of file diff --git a/src/html/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.png b/src/html/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.png new file mode 100644 index 0000000..f9d39c6 Binary files /dev/null and b/src/html/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.png differ diff --git a/src/html/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.map b/src/html/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.map new file mode 100644 index 0000000..caf386e --- /dev/null +++ b/src/html/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.md5 b/src/html/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.md5 new file mode 100644 index 0000000..0544eb8 --- /dev/null +++ b/src/html/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.md5 @@ -0,0 +1 @@ +b9b4bcb6f1e32ec21b4ade1038ab5cbe \ No newline at end of file diff --git a/src/html/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.png b/src/html/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.png new file mode 100644 index 0000000..7096337 Binary files /dev/null and b/src/html/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.png differ diff --git a/src/html/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.map b/src/html/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.map new file mode 100644 index 0000000..37991ea --- /dev/null +++ b/src/html/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.map @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/html/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.md5 b/src/html/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.md5 new file mode 100644 index 0000000..5728080 --- /dev/null +++ b/src/html/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.md5 @@ -0,0 +1 @@ +f9e44401d723587acf52d2def332ec44 \ No newline at end of file diff --git a/src/html/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.png b/src/html/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.png new file mode 100644 index 0000000..5bef848 Binary files /dev/null and b/src/html/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.png differ diff --git a/src/html/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.map b/src/html/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.map new file mode 100644 index 0000000..bb64224 --- /dev/null +++ b/src/html/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.md5 b/src/html/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.md5 new file mode 100644 index 0000000..6a9a5d4 --- /dev/null +++ b/src/html/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.md5 @@ -0,0 +1 @@ +27d4e8a5d49eac1b4d74aa2f322bbb78 \ No newline at end of file diff --git a/src/html/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.png b/src/html/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.png new file mode 100644 index 0000000..35d47b7 Binary files /dev/null and b/src/html/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.png differ diff --git a/src/html/getopt_8h.html b/src/html/getopt_8h.html new file mode 100644 index 0000000..faf746b --- /dev/null +++ b/src/html/getopt_8h.html @@ -0,0 +1,311 @@ + + + + + + + +My Project: getopt.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
getopt.h File Reference
+
+
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + +
+
+

Go to the source code of this file.

+ + + + +

+Classes

struct  option
 
+ + + + + + + + + +

+Macros

#define _GETOPT_H   1
 
#define no_argument   0
 
#define required_argument   1
 
#define optional_argument   2
 
+ + + + + + + + + +

+Functions

int getopt ()
 
int getopt_long ()
 
int getopt_long_only ()
 
int _getopt_internal ()
 
+ + + + + + + + + +

+Variables

char * optarg
 
int optind
 
int opterr
 
int optopt
 
+

Macro Definition Documentation

+ +

◆ _GETOPT_H

+ +
+
+ + + + +
#define _GETOPT_H   1
+
+ +
+
+ +

◆ no_argument

+ +
+
+ + + + +
#define no_argument   0
+
+ +
+
+ +

◆ optional_argument

+ +
+
+ + + + +
#define optional_argument   2
+
+ +
+
+ +

◆ required_argument

+ +
+
+ + + + +
#define required_argument   1
+
+ +
+
+

Function Documentation

+ +

◆ _getopt_internal()

+ +
+
+ + + + + + + +
int _getopt_internal ()
+
+ +
+
+ +

◆ getopt()

+ +
+
+ + + + + + + +
int getopt ()
+
+ +
+
+ +

◆ getopt_long()

+ +
+
+ + + + + + + +
int getopt_long ()
+
+ +
+
+ +

◆ getopt_long_only()

+ +
+
+ + + + + + + +
int getopt_long_only ()
+
+ +
+
+

Variable Documentation

+ +

◆ optarg

+ +
+
+ + + + +
char* optarg
+
+ +
+
+ +

◆ opterr

+ +
+
+ + + + +
int opterr
+
+ +
+
+ +

◆ optind

+ +
+
+ + + + +
int optind
+
+ +
+
+ +

◆ optopt

+ +
+
+ + + + +
int optopt
+
+ +
+
+
+ + + + diff --git a/src/html/getopt_8h__dep__incl.map b/src/html/getopt_8h__dep__incl.map new file mode 100644 index 0000000..07401c1 --- /dev/null +++ b/src/html/getopt_8h__dep__incl.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/getopt_8h__dep__incl.md5 b/src/html/getopt_8h__dep__incl.md5 new file mode 100644 index 0000000..a288f28 --- /dev/null +++ b/src/html/getopt_8h__dep__incl.md5 @@ -0,0 +1 @@ +6dfab0ee594cd012c3ecc76861cd7fbc \ No newline at end of file diff --git a/src/html/getopt_8h__dep__incl.png b/src/html/getopt_8h__dep__incl.png new file mode 100644 index 0000000..765547e Binary files /dev/null and b/src/html/getopt_8h__dep__incl.png differ diff --git a/src/html/getopt_8h_source.html b/src/html/getopt_8h_source.html new file mode 100644 index 0000000..6c91d54 --- /dev/null +++ b/src/html/getopt_8h_source.html @@ -0,0 +1,86 @@ + + + + + + + +My Project: getopt.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
getopt.h
+
+
+Go to the documentation of this file.
1 /* Declarations for getopt.
2  Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc.
3  This file is part of the GNU C Library.
4 
5  The GNU C Library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public License as
7  published by the Free Software Foundation; either version 2 of the
8  License, or (at your option) any later version.
9 
10  The GNU C Library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public
16  License along with the GNU C Library; see the file COPYING.LIB. If not,
17  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  Boston, MA 02111-1307, USA. */
19 
20 #ifndef _GETOPT_H
21 
22 #ifndef __need_getopt
23 # define _GETOPT_H 1
24 #endif
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /* For communication from `getopt' to the caller.
31  When `getopt' finds an option that takes an argument,
32  the argument value is returned here.
33  Also, when `ordering' is RETURN_IN_ORDER,
34  each non-option ARGV-element is returned here. */
35 
36 extern char *optarg;
37 
38 /* Index in ARGV of the next element to be scanned.
39  This is used for communication to and from the caller
40  and for communication between successive calls to `getopt'.
41 
42  On entry to `getopt', zero means this is the first call; initialize.
43 
44  When `getopt' returns -1, this is the index of the first of the
45  non-option elements that the caller should itself scan.
46 
47  Otherwise, `optind' communicates from one call to the next
48  how much of ARGV has been scanned so far. */
49 
50 extern int optind;
51 
52 /* Callers store zero here to inhibit the error message `getopt' prints
53  for unrecognized options. */
54 
55 extern int opterr;
56 
57 /* Set to an option character which was unrecognized. */
58 
59 extern int optopt;
60 
61 #ifndef __need_getopt
62 /* Describe the long-named options requested by the application.
63  The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
64  of `struct option' terminated by an element containing a name which is
65  zero.
66 
67  The field `has_arg' is:
68  no_argument (or 0) if the option does not take an argument,
69  required_argument (or 1) if the option requires an argument,
70  optional_argument (or 2) if the option takes an optional argument.
71 
72  If the field `flag' is not NULL, it points to a variable that is set
73  to the value given in the field `val' when the option is found, but
74  left unchanged if the option is not found.
75 
76  To have a long-named option do something other than set an `int' to
77  a compiled-in constant, such as set a value from `optarg', set the
78  option's `flag' field to zero and its `val' field to a nonzero
79  value (the equivalent single-letter option character, if there is
80  one). For long options that have a zero `flag' field, `getopt'
81  returns the contents of the `val' field. */
82 
83 struct option
84 {
85 # if defined __STDC__ && __STDC__
86  const char *name;
87 # else
88  char *name;
89 # endif
90  /* has_arg can't be an enum because some compilers complain about
91  type mismatches in all the code that assumes it is an int. */
92  int has_arg;
93  int *flag;
94  int val;
95 };
96 
97 /* Names for the values of the `has_arg' field of `struct option'. */
98 
99 # define no_argument 0
100 # define required_argument 1
101 # define optional_argument 2
102 #endif /* need getopt */
103 
104 
105 /* Get definitions and prototypes for functions to process the
106  arguments in ARGV (ARGC of them, minus the program name) for
107  options given in OPTS.
108 
109  Return the option character from OPTS just read. Return -1 when
110  there are no more options. For unrecognized options, or options
111  missing arguments, `optopt' is set to the option letter, and '?' is
112  returned.
113 
114  The OPTS string is a list of characters which are recognized option
115  letters, optionally followed by colons, specifying that that letter
116  takes an argument, to be placed in `optarg'.
117 
118  If a letter in OPTS is followed by two colons, its argument is
119  optional. This behavior is specific to the GNU `getopt'.
120 
121  The argument `--' causes premature termination of argument
122  scanning, explicitly telling `getopt' that there are no more
123  options.
124 
125  If OPTS begins with `--', then non-option arguments are treated as
126  arguments to the option '\0'. This behavior is specific to the GNU
127  `getopt'. */
128 
129 #if defined __STDC__ && __STDC__
130 # ifdef __GNU_LIBRARY__
131 /* Many other libraries have conflicting prototypes for getopt, with
132  differences in the consts, in stdlib.h. To avoid compilation
133  errors, only prototype getopt for the GNU C library. */
134 extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
135 # else /* not __GNU_LIBRARY__ */
136 extern int getopt ();
137 # endif /* __GNU_LIBRARY__ */
138 
139 # ifndef __need_getopt
140 extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
141  const struct option *__longopts, int *__longind);
142 extern int getopt_long_only (int __argc, char *const *__argv,
143  const char *__shortopts,
144  const struct option *__longopts, int *__longind);
145 
146 /* Internal only. Users should not call this directly. */
147 extern int _getopt_internal (int __argc, char *const *__argv,
148  const char *__shortopts,
149  const struct option *__longopts, int *__longind,
150  int __long_only);
151 # endif
152 #else /* not __STDC__ */
153 extern int getopt ();
154 # ifndef __need_getopt
155 extern int getopt_long ();
156 extern int getopt_long_only ();
157 
158 extern int _getopt_internal ();
159 # endif
160 #endif /* __STDC__ */
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 /* Make sure we later can get all the definitions and declarations. */
167 #undef __need_getopt
168 
169 #endif /* getopt.h */
int getopt_long()
+
int val
Definition: getopt.h:94
+
char * name
Definition: getopt.h:88
+
Definition: getopt.h:83
+
int optopt
Definition: getopt.c:153
+
int getopt_long_only()
+
char * optarg
Definition: getopt.c:112
+
int optind
Definition: getopt.c:127
+
int * flag
Definition: getopt.h:93
+
int opterr
Definition: getopt.c:147
+
int has_arg
Definition: getopt.h:92
+
int _getopt_internal()
+
int getopt()
+
+ + + + diff --git a/src/html/globals.html b/src/html/globals.html new file mode 100644 index 0000000..fbc8aae --- /dev/null +++ b/src/html/globals.html @@ -0,0 +1,92 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- _ -

+
+ + + + diff --git a/src/html/globals_a.html b/src/html/globals_a.html new file mode 100644 index 0000000..c7ea9de --- /dev/null +++ b/src/html/globals_a.html @@ -0,0 +1,99 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- a -

+
+ + + + diff --git a/src/html/globals_b.html b/src/html/globals_b.html new file mode 100644 index 0000000..aa891b8 --- /dev/null +++ b/src/html/globals_b.html @@ -0,0 +1,98 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- b -

+
+ + + + diff --git a/src/html/globals_c.html b/src/html/globals_c.html new file mode 100644 index 0000000..cfc3e1f --- /dev/null +++ b/src/html/globals_c.html @@ -0,0 +1,213 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- c -

+
+ + + + diff --git a/src/html/globals_d.html b/src/html/globals_d.html new file mode 100644 index 0000000..aa0ee08 --- /dev/null +++ b/src/html/globals_d.html @@ -0,0 +1,77 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- d -

+
+ + + + diff --git a/src/html/globals_defs.html b/src/html/globals_defs.html new file mode 100644 index 0000000..caa6008 --- /dev/null +++ b/src/html/globals_defs.html @@ -0,0 +1,138 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+ + + + diff --git a/src/html/globals_e.html b/src/html/globals_e.html new file mode 100644 index 0000000..e14fe14 --- /dev/null +++ b/src/html/globals_e.html @@ -0,0 +1,99 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- e -

+
+ + + + diff --git a/src/html/globals_enum.html b/src/html/globals_enum.html new file mode 100644 index 0000000..6acbf1d --- /dev/null +++ b/src/html/globals_enum.html @@ -0,0 +1,77 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+ + + + diff --git a/src/html/globals_eval.html b/src/html/globals_eval.html new file mode 100644 index 0000000..adb14d4 --- /dev/null +++ b/src/html/globals_eval.html @@ -0,0 +1,104 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+ + + + diff --git a/src/html/globals_f.html b/src/html/globals_f.html new file mode 100644 index 0000000..dfdce9f --- /dev/null +++ b/src/html/globals_f.html @@ -0,0 +1,128 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- f -

+
+ + + + diff --git a/src/html/globals_func.html b/src/html/globals_func.html new file mode 100644 index 0000000..3d10058 --- /dev/null +++ b/src/html/globals_func.html @@ -0,0 +1,80 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- _ -

+
+ + + + diff --git a/src/html/globals_func_a.html b/src/html/globals_func_a.html new file mode 100644 index 0000000..7f27f21 --- /dev/null +++ b/src/html/globals_func_a.html @@ -0,0 +1,81 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- a -

+
+ + + + diff --git a/src/html/globals_func_b.html b/src/html/globals_func_b.html new file mode 100644 index 0000000..86527d9 --- /dev/null +++ b/src/html/globals_func_b.html @@ -0,0 +1,81 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- b -

+
+ + + + diff --git a/src/html/globals_func_c.html b/src/html/globals_func_c.html new file mode 100644 index 0000000..93dc89b --- /dev/null +++ b/src/html/globals_func_c.html @@ -0,0 +1,183 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- c -

+
+ + + + diff --git a/src/html/globals_func_d.html b/src/html/globals_func_d.html new file mode 100644 index 0000000..c717ced --- /dev/null +++ b/src/html/globals_func_d.html @@ -0,0 +1,77 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- d -

+
+ + + + diff --git a/src/html/globals_func_e.html b/src/html/globals_func_e.html new file mode 100644 index 0000000..1501af9 --- /dev/null +++ b/src/html/globals_func_e.html @@ -0,0 +1,96 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- e -

+
+ + + + diff --git a/src/html/globals_func_f.html b/src/html/globals_func_f.html new file mode 100644 index 0000000..15d34b3 --- /dev/null +++ b/src/html/globals_func_f.html @@ -0,0 +1,119 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- f -

+
+ + + + diff --git a/src/html/globals_func_g.html b/src/html/globals_func_g.html new file mode 100644 index 0000000..7cef960 --- /dev/null +++ b/src/html/globals_func_g.html @@ -0,0 +1,145 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- g -

+
+ + + + diff --git a/src/html/globals_func_h.html b/src/html/globals_func_h.html new file mode 100644 index 0000000..2afc829 --- /dev/null +++ b/src/html/globals_func_h.html @@ -0,0 +1,85 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- h -

+
+ + + + diff --git a/src/html/globals_func_i.html b/src/html/globals_func_i.html new file mode 100644 index 0000000..2c9b0f8 --- /dev/null +++ b/src/html/globals_func_i.html @@ -0,0 +1,84 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- i -

+
+ + + + diff --git a/src/html/globals_func_l.html b/src/html/globals_func_l.html new file mode 100644 index 0000000..8e23236 --- /dev/null +++ b/src/html/globals_func_l.html @@ -0,0 +1,83 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- l -

+
+ + + + diff --git a/src/html/globals_func_m.html b/src/html/globals_func_m.html new file mode 100644 index 0000000..379ead2 --- /dev/null +++ b/src/html/globals_func_m.html @@ -0,0 +1,87 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- m -

+
+ + + + diff --git a/src/html/globals_func_n.html b/src/html/globals_func_n.html new file mode 100644 index 0000000..3694d4d --- /dev/null +++ b/src/html/globals_func_n.html @@ -0,0 +1,77 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- n -

+
+ + + + diff --git a/src/html/globals_func_p.html b/src/html/globals_func_p.html new file mode 100644 index 0000000..b145a19 --- /dev/null +++ b/src/html/globals_func_p.html @@ -0,0 +1,108 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- p -

+
+ + + + diff --git a/src/html/globals_func_r.html b/src/html/globals_func_r.html new file mode 100644 index 0000000..a5ce25a --- /dev/null +++ b/src/html/globals_func_r.html @@ -0,0 +1,97 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- r -

+
+ + + + diff --git a/src/html/globals_func_s.html b/src/html/globals_func_s.html new file mode 100644 index 0000000..6c00a10 --- /dev/null +++ b/src/html/globals_func_s.html @@ -0,0 +1,123 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- s -

+
+ + + + diff --git a/src/html/globals_func_t.html b/src/html/globals_func_t.html new file mode 100644 index 0000000..168087d --- /dev/null +++ b/src/html/globals_func_t.html @@ -0,0 +1,89 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- t -

+
+ + + + diff --git a/src/html/globals_func_u.html b/src/html/globals_func_u.html new file mode 100644 index 0000000..cfc85bc --- /dev/null +++ b/src/html/globals_func_u.html @@ -0,0 +1,88 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- u -

+
+ + + + diff --git a/src/html/globals_func_v.html b/src/html/globals_func_v.html new file mode 100644 index 0000000..10a5bfc --- /dev/null +++ b/src/html/globals_func_v.html @@ -0,0 +1,77 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- v -

+
+ + + + diff --git a/src/html/globals_func_w.html b/src/html/globals_func_w.html new file mode 100644 index 0000000..cf806ed --- /dev/null +++ b/src/html/globals_func_w.html @@ -0,0 +1,80 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- w -

+
+ + + + diff --git a/src/html/globals_func_x.html b/src/html/globals_func_x.html new file mode 100644 index 0000000..a226470 --- /dev/null +++ b/src/html/globals_func_x.html @@ -0,0 +1,77 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- x -

+
+ + + + diff --git a/src/html/globals_g.html b/src/html/globals_g.html new file mode 100644 index 0000000..e5577df --- /dev/null +++ b/src/html/globals_g.html @@ -0,0 +1,163 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- g -

+
+ + + + diff --git a/src/html/globals_h.html b/src/html/globals_h.html new file mode 100644 index 0000000..0ebfecb --- /dev/null +++ b/src/html/globals_h.html @@ -0,0 +1,89 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- h -

+
+ + + + diff --git a/src/html/globals_i.html b/src/html/globals_i.html new file mode 100644 index 0000000..04cbae6 --- /dev/null +++ b/src/html/globals_i.html @@ -0,0 +1,93 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- i -

+
+ + + + diff --git a/src/html/globals_l.html b/src/html/globals_l.html new file mode 100644 index 0000000..3a42b7f --- /dev/null +++ b/src/html/globals_l.html @@ -0,0 +1,92 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- l -

+
+ + + + diff --git a/src/html/globals_m.html b/src/html/globals_m.html new file mode 100644 index 0000000..2337571 --- /dev/null +++ b/src/html/globals_m.html @@ -0,0 +1,125 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- m -

+
+ + + + diff --git a/src/html/globals_n.html b/src/html/globals_n.html new file mode 100644 index 0000000..b721e73 --- /dev/null +++ b/src/html/globals_n.html @@ -0,0 +1,110 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- n -

+
+ + + + diff --git a/src/html/globals_o.html b/src/html/globals_o.html new file mode 100644 index 0000000..eb020af --- /dev/null +++ b/src/html/globals_o.html @@ -0,0 +1,98 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- o -

+
+ + + + diff --git a/src/html/globals_p.html b/src/html/globals_p.html new file mode 100644 index 0000000..89c11b2 --- /dev/null +++ b/src/html/globals_p.html @@ -0,0 +1,138 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- p -

+
+ + + + diff --git a/src/html/globals_r.html b/src/html/globals_r.html new file mode 100644 index 0000000..e601eb8 --- /dev/null +++ b/src/html/globals_r.html @@ -0,0 +1,112 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- r -

+
+ + + + diff --git a/src/html/globals_s.html b/src/html/globals_s.html new file mode 100644 index 0000000..0017f70 --- /dev/null +++ b/src/html/globals_s.html @@ -0,0 +1,152 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- s -

+
+ + + + diff --git a/src/html/globals_t.html b/src/html/globals_t.html new file mode 100644 index 0000000..f90ca2a --- /dev/null +++ b/src/html/globals_t.html @@ -0,0 +1,100 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- t -

+
+ + + + diff --git a/src/html/globals_type.html b/src/html/globals_type.html new file mode 100644 index 0000000..502436d --- /dev/null +++ b/src/html/globals_type.html @@ -0,0 +1,83 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+ + + + diff --git a/src/html/globals_u.html b/src/html/globals_u.html new file mode 100644 index 0000000..bf245b9 --- /dev/null +++ b/src/html/globals_u.html @@ -0,0 +1,97 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- u -

+
+ + + + diff --git a/src/html/globals_v.html b/src/html/globals_v.html new file mode 100644 index 0000000..90de96c --- /dev/null +++ b/src/html/globals_v.html @@ -0,0 +1,77 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- v -

+
+ + + + diff --git a/src/html/globals_vars.html b/src/html/globals_vars.html new file mode 100644 index 0000000..1a8696c --- /dev/null +++ b/src/html/globals_vars.html @@ -0,0 +1,346 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+  + +

- _ -

+ + +

- b -

+ + +

- c -

+ + +

- e -

+ + +

- f -

+ + +

- g -

+ + +

- h -

+ + +

- i -

+ + +

- l -

+ + +

- m -

+ + +

- n -

+ + +

- o -

+ + +

- p -

+ + +

- r -

+ + +

- s -

+ + +

- t -

+ + +

- u -

+ + +

- x -

+
+ + + + diff --git a/src/html/globals_w.html b/src/html/globals_w.html new file mode 100644 index 0000000..e92bc62 --- /dev/null +++ b/src/html/globals_w.html @@ -0,0 +1,80 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- w -

+
+ + + + diff --git a/src/html/globals_x.html b/src/html/globals_x.html new file mode 100644 index 0000000..41e86d8 --- /dev/null +++ b/src/html/globals_x.html @@ -0,0 +1,81 @@ + + + + + + + +My Project: File Members + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
Here is a list of all file members with links to the files they belong to:
+ +

- x -

+
+ + + + diff --git a/src/html/graph_legend.html b/src/html/graph_legend.html new file mode 100644 index 0000000..1625d6c --- /dev/null +++ b/src/html/graph_legend.html @@ -0,0 +1,102 @@ + + + + + + + +My Project: Graph Legend + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
Graph Legend
+
+
+

This page explains how to interpret the graphs that are generated by doxygen.

+

Consider the following example:

/*! Invisible class because of truncation */
class Invisible { };
/*! Truncated class, inheritance relation is hidden */
class Truncated : public Invisible { };
/* Class not documented with doxygen comments */
class Undocumented { };
/*! Class that is inherited using public inheritance */
class PublicBase : public Truncated { };
/*! A template class */
template<class T> class Templ { };
/*! Class that is inherited using protected inheritance */
class ProtectedBase { };
/*! Class that is inherited using private inheritance */
class PrivateBase { };
/*! Class that is used by the Inherited class */
class Used { };
/*! Super class that inherits a number of other classes */
class Inherited : public PublicBase,
protected ProtectedBase,
private PrivateBase,
public Undocumented,
public Templ<int>
{
private:
Used *m_usedClass;
};

This will result in the following graph:

+
+ +
+

The boxes in the above graph have the following meaning:

+
    +
  • +A filled gray box represents the struct or class for which the graph is generated.
  • +
  • +A box with a black border denotes a documented struct or class.
  • +
  • +A box with a gray border denotes an undocumented struct or class.
  • +
  • +A box with a red border denotes a documented struct or class forwhich not all inheritance/containment relations are shown. A graph is truncated if it does not fit within the specified boundaries.
  • +
+

The arrows have the following meaning:

+
    +
  • +A dark blue arrow is used to visualize a public inheritance relation between two classes.
  • +
  • +A dark green arrow is used for protected inheritance.
  • +
  • +A dark red arrow is used for private inheritance.
  • +
  • +A purple dashed arrow is used if a class is contained or used by another class. The arrow is labelled with the variable(s) through which the pointed class or struct is accessible.
  • +
  • +A yellow dashed arrow denotes a relation between a template instance and the template class it was instantiated from. The arrow is labelled with the template parameters of the instance.
  • +
+
+ + + + diff --git a/src/html/graph_legend.md5 b/src/html/graph_legend.md5 new file mode 100644 index 0000000..a06ed05 --- /dev/null +++ b/src/html/graph_legend.md5 @@ -0,0 +1 @@ +387ff8eb65306fa251338d3c9bd7bfff \ No newline at end of file diff --git a/src/html/graph_legend.png b/src/html/graph_legend.png new file mode 100644 index 0000000..81788d8 Binary files /dev/null and b/src/html/graph_legend.png differ diff --git a/src/html/index.html b/src/html/index.html new file mode 100644 index 0000000..04e75a5 --- /dev/null +++ b/src/html/index.html @@ -0,0 +1,73 @@ + + + + + + + +My Project: Main Page + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
My Project Documentation
+
+
+
+ + + + diff --git a/src/html/jquery.js b/src/html/jquery.js new file mode 100644 index 0000000..f5343ed --- /dev/null +++ b/src/html/jquery.js @@ -0,0 +1,87 @@ +/*! + * jQuery JavaScript Library v1.7.1 + * http://jquery.com/ + * + * Copyright 2011, John Resig + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * Includes Sizzle.js + * http://sizzlejs.com/ + * Copyright 2011, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * + * Date: Mon Nov 21 21:11:03 2011 -0500 + */ +(function(bb,L){var av=bb.document,bu=bb.navigator,bl=bb.location;var b=(function(){var bF=function(b0,b1){return new bF.fn.init(b0,b1,bD)},bU=bb.jQuery,bH=bb.$,bD,bY=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,bM=/\S/,bI=/^\s+/,bE=/\s+$/,bA=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,bN=/^[\],:{}\s]*$/,bW=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,bP=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,bJ=/(?:^|:|,)(?:\s*\[)+/g,by=/(webkit)[ \/]([\w.]+)/,bR=/(opera)(?:.*version)?[ \/]([\w.]+)/,bQ=/(msie) ([\w.]+)/,bS=/(mozilla)(?:.*? rv:([\w.]+))?/,bB=/-([a-z]|[0-9])/ig,bZ=/^-ms-/,bT=function(b0,b1){return(b1+"").toUpperCase()},bX=bu.userAgent,bV,bC,e,bL=Object.prototype.toString,bG=Object.prototype.hasOwnProperty,bz=Array.prototype.push,bK=Array.prototype.slice,bO=String.prototype.trim,bv=Array.prototype.indexOf,bx={};bF.fn=bF.prototype={constructor:bF,init:function(b0,b4,b3){var b2,b5,b1,b6;if(!b0){return this}if(b0.nodeType){this.context=this[0]=b0;this.length=1;return this}if(b0==="body"&&!b4&&av.body){this.context=av;this[0]=av.body;this.selector=b0;this.length=1;return this}if(typeof b0==="string"){if(b0.charAt(0)==="<"&&b0.charAt(b0.length-1)===">"&&b0.length>=3){b2=[null,b0,null]}else{b2=bY.exec(b0)}if(b2&&(b2[1]||!b4)){if(b2[1]){b4=b4 instanceof bF?b4[0]:b4;b6=(b4?b4.ownerDocument||b4:av);b1=bA.exec(b0);if(b1){if(bF.isPlainObject(b4)){b0=[av.createElement(b1[1])];bF.fn.attr.call(b0,b4,true)}else{b0=[b6.createElement(b1[1])]}}else{b1=bF.buildFragment([b2[1]],[b6]);b0=(b1.cacheable?bF.clone(b1.fragment):b1.fragment).childNodes}return bF.merge(this,b0)}else{b5=av.getElementById(b2[2]);if(b5&&b5.parentNode){if(b5.id!==b2[2]){return b3.find(b0)}this.length=1;this[0]=b5}this.context=av;this.selector=b0;return this}}else{if(!b4||b4.jquery){return(b4||b3).find(b0)}else{return this.constructor(b4).find(b0)}}}else{if(bF.isFunction(b0)){return b3.ready(b0)}}if(b0.selector!==L){this.selector=b0.selector;this.context=b0.context}return bF.makeArray(b0,this)},selector:"",jquery:"1.7.1",length:0,size:function(){return this.length},toArray:function(){return bK.call(this,0)},get:function(b0){return b0==null?this.toArray():(b0<0?this[this.length+b0]:this[b0])},pushStack:function(b1,b3,b0){var b2=this.constructor();if(bF.isArray(b1)){bz.apply(b2,b1)}else{bF.merge(b2,b1)}b2.prevObject=this;b2.context=this.context;if(b3==="find"){b2.selector=this.selector+(this.selector?" ":"")+b0}else{if(b3){b2.selector=this.selector+"."+b3+"("+b0+")"}}return b2},each:function(b1,b0){return bF.each(this,b1,b0)},ready:function(b0){bF.bindReady();bC.add(b0);return this},eq:function(b0){b0=+b0;return b0===-1?this.slice(b0):this.slice(b0,b0+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(bK.apply(this,arguments),"slice",bK.call(arguments).join(","))},map:function(b0){return this.pushStack(bF.map(this,function(b2,b1){return b0.call(b2,b1,b2)}))},end:function(){return this.prevObject||this.constructor(null)},push:bz,sort:[].sort,splice:[].splice};bF.fn.init.prototype=bF.fn;bF.extend=bF.fn.extend=function(){var b9,b2,b0,b1,b6,b7,b5=arguments[0]||{},b4=1,b3=arguments.length,b8=false;if(typeof b5==="boolean"){b8=b5;b5=arguments[1]||{};b4=2}if(typeof b5!=="object"&&!bF.isFunction(b5)){b5={}}if(b3===b4){b5=this;--b4}for(;b40){return}bC.fireWith(av,[bF]);if(bF.fn.trigger){bF(av).trigger("ready").off("ready")}}},bindReady:function(){if(bC){return}bC=bF.Callbacks("once memory");if(av.readyState==="complete"){return setTimeout(bF.ready,1)}if(av.addEventListener){av.addEventListener("DOMContentLoaded",e,false);bb.addEventListener("load",bF.ready,false)}else{if(av.attachEvent){av.attachEvent("onreadystatechange",e);bb.attachEvent("onload",bF.ready);var b0=false;try{b0=bb.frameElement==null}catch(b1){}if(av.documentElement.doScroll&&b0){bw()}}}},isFunction:function(b0){return bF.type(b0)==="function"},isArray:Array.isArray||function(b0){return bF.type(b0)==="array"},isWindow:function(b0){return b0&&typeof b0==="object"&&"setInterval" in b0},isNumeric:function(b0){return !isNaN(parseFloat(b0))&&isFinite(b0)},type:function(b0){return b0==null?String(b0):bx[bL.call(b0)]||"object"},isPlainObject:function(b2){if(!b2||bF.type(b2)!=="object"||b2.nodeType||bF.isWindow(b2)){return false}try{if(b2.constructor&&!bG.call(b2,"constructor")&&!bG.call(b2.constructor.prototype,"isPrototypeOf")){return false}}catch(b1){return false}var b0;for(b0 in b2){}return b0===L||bG.call(b2,b0)},isEmptyObject:function(b1){for(var b0 in b1){return false}return true},error:function(b0){throw new Error(b0)},parseJSON:function(b0){if(typeof b0!=="string"||!b0){return null}b0=bF.trim(b0);if(bb.JSON&&bb.JSON.parse){return bb.JSON.parse(b0)}if(bN.test(b0.replace(bW,"@").replace(bP,"]").replace(bJ,""))){return(new Function("return "+b0))()}bF.error("Invalid JSON: "+b0)},parseXML:function(b2){var b0,b1;try{if(bb.DOMParser){b1=new DOMParser();b0=b1.parseFromString(b2,"text/xml")}else{b0=new ActiveXObject("Microsoft.XMLDOM");b0.async="false";b0.loadXML(b2)}}catch(b3){b0=L}if(!b0||!b0.documentElement||b0.getElementsByTagName("parsererror").length){bF.error("Invalid XML: "+b2)}return b0},noop:function(){},globalEval:function(b0){if(b0&&bM.test(b0)){(bb.execScript||function(b1){bb["eval"].call(bb,b1)})(b0)}},camelCase:function(b0){return b0.replace(bZ,"ms-").replace(bB,bT)},nodeName:function(b1,b0){return b1.nodeName&&b1.nodeName.toUpperCase()===b0.toUpperCase()},each:function(b3,b6,b2){var b1,b4=0,b5=b3.length,b0=b5===L||bF.isFunction(b3);if(b2){if(b0){for(b1 in b3){if(b6.apply(b3[b1],b2)===false){break}}}else{for(;b40&&b0[0]&&b0[b1-1])||b1===0||bF.isArray(b0));if(b3){for(;b21?aJ.call(arguments,0):bG;if(!(--bw)){bC.resolveWith(bC,bx)}}}function bz(bF){return function(bG){bB[bF]=arguments.length>1?aJ.call(arguments,0):bG;bC.notifyWith(bE,bB)}}if(e>1){for(;bv
a";bI=bv.getElementsByTagName("*");bF=bv.getElementsByTagName("a")[0];if(!bI||!bI.length||!bF){return{}}bG=av.createElement("select");bx=bG.appendChild(av.createElement("option"));bE=bv.getElementsByTagName("input")[0];bJ={leadingWhitespace:(bv.firstChild.nodeType===3),tbody:!bv.getElementsByTagName("tbody").length,htmlSerialize:!!bv.getElementsByTagName("link").length,style:/top/.test(bF.getAttribute("style")),hrefNormalized:(bF.getAttribute("href")==="/a"),opacity:/^0.55/.test(bF.style.opacity),cssFloat:!!bF.style.cssFloat,checkOn:(bE.value==="on"),optSelected:bx.selected,getSetAttribute:bv.className!=="t",enctype:!!av.createElement("form").enctype,html5Clone:av.createElement("nav").cloneNode(true).outerHTML!=="<:nav>",submitBubbles:true,changeBubbles:true,focusinBubbles:false,deleteExpando:true,noCloneEvent:true,inlineBlockNeedsLayout:false,shrinkWrapBlocks:false,reliableMarginRight:true};bE.checked=true;bJ.noCloneChecked=bE.cloneNode(true).checked;bG.disabled=true;bJ.optDisabled=!bx.disabled;try{delete bv.test}catch(bC){bJ.deleteExpando=false}if(!bv.addEventListener&&bv.attachEvent&&bv.fireEvent){bv.attachEvent("onclick",function(){bJ.noCloneEvent=false});bv.cloneNode(true).fireEvent("onclick")}bE=av.createElement("input");bE.value="t";bE.setAttribute("type","radio");bJ.radioValue=bE.value==="t";bE.setAttribute("checked","checked");bv.appendChild(bE);bD=av.createDocumentFragment();bD.appendChild(bv.lastChild);bJ.checkClone=bD.cloneNode(true).cloneNode(true).lastChild.checked;bJ.appendChecked=bE.checked;bD.removeChild(bE);bD.appendChild(bv);bv.innerHTML="";if(bb.getComputedStyle){bA=av.createElement("div");bA.style.width="0";bA.style.marginRight="0";bv.style.width="2px";bv.appendChild(bA);bJ.reliableMarginRight=(parseInt((bb.getComputedStyle(bA,null)||{marginRight:0}).marginRight,10)||0)===0}if(bv.attachEvent){for(by in {submit:1,change:1,focusin:1}){bB="on"+by;bw=(bB in bv);if(!bw){bv.setAttribute(bB,"return;");bw=(typeof bv[bB]==="function")}bJ[by+"Bubbles"]=bw}}bD.removeChild(bv);bD=bG=bx=bA=bv=bE=null;b(function(){var bM,bU,bV,bT,bN,bO,bL,bS,bR,e,bP,bQ=av.getElementsByTagName("body")[0];if(!bQ){return}bL=1;bS="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;";bR="visibility:hidden;border:0;";e="style='"+bS+"border:5px solid #000;padding:0;'";bP="
";bM=av.createElement("div");bM.style.cssText=bR+"width:0;height:0;position:static;top:0;margin-top:"+bL+"px";bQ.insertBefore(bM,bQ.firstChild);bv=av.createElement("div");bM.appendChild(bv);bv.innerHTML="
t
";bz=bv.getElementsByTagName("td");bw=(bz[0].offsetHeight===0);bz[0].style.display="";bz[1].style.display="none";bJ.reliableHiddenOffsets=bw&&(bz[0].offsetHeight===0);bv.innerHTML="";bv.style.width=bv.style.paddingLeft="1px";b.boxModel=bJ.boxModel=bv.offsetWidth===2;if(typeof bv.style.zoom!=="undefined"){bv.style.display="inline";bv.style.zoom=1;bJ.inlineBlockNeedsLayout=(bv.offsetWidth===2);bv.style.display="";bv.innerHTML="
";bJ.shrinkWrapBlocks=(bv.offsetWidth!==2)}bv.style.cssText=bS+bR;bv.innerHTML=bP;bU=bv.firstChild;bV=bU.firstChild;bN=bU.nextSibling.firstChild.firstChild;bO={doesNotAddBorder:(bV.offsetTop!==5),doesAddBorderForTableAndCells:(bN.offsetTop===5)};bV.style.position="fixed";bV.style.top="20px";bO.fixedPosition=(bV.offsetTop===20||bV.offsetTop===15);bV.style.position=bV.style.top="";bU.style.overflow="hidden";bU.style.position="relative";bO.subtractsBorderForOverflowNotVisible=(bV.offsetTop===-5);bO.doesNotIncludeMarginInBodyOffset=(bQ.offsetTop!==bL);bQ.removeChild(bM);bv=bM=null;b.extend(bJ,bO)});return bJ})();var aS=/^(?:\{.*\}|\[.*\])$/,aA=/([A-Z])/g;b.extend({cache:{},uuid:0,expando:"jQuery"+(b.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:true,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:true},hasData:function(e){e=e.nodeType?b.cache[e[b.expando]]:e[b.expando];return !!e&&!S(e)},data:function(bx,bv,bz,by){if(!b.acceptData(bx)){return}var bG,bA,bD,bE=b.expando,bC=typeof bv==="string",bF=bx.nodeType,e=bF?b.cache:bx,bw=bF?bx[bE]:bx[bE]&&bE,bB=bv==="events";if((!bw||!e[bw]||(!bB&&!by&&!e[bw].data))&&bC&&bz===L){return}if(!bw){if(bF){bx[bE]=bw=++b.uuid}else{bw=bE}}if(!e[bw]){e[bw]={};if(!bF){e[bw].toJSON=b.noop}}if(typeof bv==="object"||typeof bv==="function"){if(by){e[bw]=b.extend(e[bw],bv)}else{e[bw].data=b.extend(e[bw].data,bv)}}bG=bA=e[bw];if(!by){if(!bA.data){bA.data={}}bA=bA.data}if(bz!==L){bA[b.camelCase(bv)]=bz}if(bB&&!bA[bv]){return bG.events}if(bC){bD=bA[bv];if(bD==null){bD=bA[b.camelCase(bv)]}}else{bD=bA}return bD},removeData:function(bx,bv,by){if(!b.acceptData(bx)){return}var bB,bA,bz,bC=b.expando,bD=bx.nodeType,e=bD?b.cache:bx,bw=bD?bx[bC]:bC;if(!e[bw]){return}if(bv){bB=by?e[bw]:e[bw].data;if(bB){if(!b.isArray(bv)){if(bv in bB){bv=[bv]}else{bv=b.camelCase(bv);if(bv in bB){bv=[bv]}else{bv=bv.split(" ")}}}for(bA=0,bz=bv.length;bA-1){return true}}return false},val:function(bx){var e,bv,by,bw=this[0];if(!arguments.length){if(bw){e=b.valHooks[bw.nodeName.toLowerCase()]||b.valHooks[bw.type];if(e&&"get" in e&&(bv=e.get(bw,"value"))!==L){return bv}bv=bw.value;return typeof bv==="string"?bv.replace(aU,""):bv==null?"":bv}return}by=b.isFunction(bx);return this.each(function(bA){var bz=b(this),bB;if(this.nodeType!==1){return}if(by){bB=bx.call(this,bA,bz.val())}else{bB=bx}if(bB==null){bB=""}else{if(typeof bB==="number"){bB+=""}else{if(b.isArray(bB)){bB=b.map(bB,function(bC){return bC==null?"":bC+""})}}}e=b.valHooks[this.nodeName.toLowerCase()]||b.valHooks[this.type];if(!e||!("set" in e)||e.set(this,bB,"value")===L){this.value=bB}})}});b.extend({valHooks:{option:{get:function(e){var bv=e.attributes.value;return !bv||bv.specified?e.value:e.text}},select:{get:function(e){var bA,bv,bz,bx,by=e.selectedIndex,bB=[],bC=e.options,bw=e.type==="select-one";if(by<0){return null}bv=bw?by:0;bz=bw?by+1:bC.length;for(;bv=0});if(!e.length){bv.selectedIndex=-1}return e}}},attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},attr:function(bA,bx,bB,bz){var bw,e,by,bv=bA.nodeType;if(!bA||bv===3||bv===8||bv===2){return}if(bz&&bx in b.attrFn){return b(bA)[bx](bB)}if(typeof bA.getAttribute==="undefined"){return b.prop(bA,bx,bB)}by=bv!==1||!b.isXMLDoc(bA);if(by){bx=bx.toLowerCase();e=b.attrHooks[bx]||(ao.test(bx)?aY:be)}if(bB!==L){if(bB===null){b.removeAttr(bA,bx);return}else{if(e&&"set" in e&&by&&(bw=e.set(bA,bB,bx))!==L){return bw}else{bA.setAttribute(bx,""+bB);return bB}}}else{if(e&&"get" in e&&by&&(bw=e.get(bA,bx))!==null){return bw}else{bw=bA.getAttribute(bx);return bw===null?L:bw}}},removeAttr:function(bx,bz){var by,bA,bv,e,bw=0;if(bz&&bx.nodeType===1){bA=bz.toLowerCase().split(af);e=bA.length;for(;bw=0)}}})});var bd=/^(?:textarea|input|select)$/i,n=/^([^\.]*)?(?:\.(.+))?$/,J=/\bhover(\.\S+)?\b/,aO=/^key/,bf=/^(?:mouse|contextmenu)|click/,T=/^(?:focusinfocus|focusoutblur)$/,U=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,Y=function(e){var bv=U.exec(e);if(bv){bv[1]=(bv[1]||"").toLowerCase();bv[3]=bv[3]&&new RegExp("(?:^|\\s)"+bv[3]+"(?:\\s|$)")}return bv},j=function(bw,e){var bv=bw.attributes||{};return((!e[1]||bw.nodeName.toLowerCase()===e[1])&&(!e[2]||(bv.id||{}).value===e[2])&&(!e[3]||e[3].test((bv["class"]||{}).value)))},bt=function(e){return b.event.special.hover?e:e.replace(J,"mouseenter$1 mouseleave$1")};b.event={add:function(bx,bC,bJ,bA,by){var bD,bB,bK,bI,bH,bF,e,bG,bv,bz,bw,bE;if(bx.nodeType===3||bx.nodeType===8||!bC||!bJ||!(bD=b._data(bx))){return}if(bJ.handler){bv=bJ;bJ=bv.handler}if(!bJ.guid){bJ.guid=b.guid++}bK=bD.events;if(!bK){bD.events=bK={}}bB=bD.handle;if(!bB){bD.handle=bB=function(bL){return typeof b!=="undefined"&&(!bL||b.event.triggered!==bL.type)?b.event.dispatch.apply(bB.elem,arguments):L};bB.elem=bx}bC=b.trim(bt(bC)).split(" ");for(bI=0;bI=0){bG=bG.slice(0,-1);bw=true}if(bG.indexOf(".")>=0){bx=bG.split(".");bG=bx.shift();bx.sort()}if((!bA||b.event.customEvent[bG])&&!b.event.global[bG]){return}bv=typeof bv==="object"?bv[b.expando]?bv:new b.Event(bG,bv):new b.Event(bG);bv.type=bG;bv.isTrigger=true;bv.exclusive=bw;bv.namespace=bx.join(".");bv.namespace_re=bv.namespace?new RegExp("(^|\\.)"+bx.join("\\.(?:.*\\.)?")+"(\\.|$)"):null;by=bG.indexOf(":")<0?"on"+bG:"";if(!bA){e=b.cache;for(bC in e){if(e[bC].events&&e[bC].events[bG]){b.event.trigger(bv,bD,e[bC].handle.elem,true)}}return}bv.result=L;if(!bv.target){bv.target=bA}bD=bD!=null?b.makeArray(bD):[];bD.unshift(bv);bF=b.event.special[bG]||{};if(bF.trigger&&bF.trigger.apply(bA,bD)===false){return}bB=[[bA,bF.bindType||bG]];if(!bJ&&!bF.noBubble&&!b.isWindow(bA)){bI=bF.delegateType||bG;bH=T.test(bI+bG)?bA:bA.parentNode;bz=null;for(;bH;bH=bH.parentNode){bB.push([bH,bI]);bz=bH}if(bz&&bz===bA.ownerDocument){bB.push([bz.defaultView||bz.parentWindow||bb,bI])}}for(bC=0;bCbA){bH.push({elem:this,matches:bz.slice(bA)})}for(bC=0;bC0?this.on(e,null,bx,bw):this.trigger(e)};if(b.attrFn){b.attrFn[e]=true}if(aO.test(e)){b.event.fixHooks[e]=b.event.keyHooks}if(bf.test(e)){b.event.fixHooks[e]=b.event.mouseHooks}}); +/*! + * Sizzle CSS Selector Engine + * Copyright 2011, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * More information: http://sizzlejs.com/ + */ +(function(){var bH=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,bC="sizcache"+(Math.random()+"").replace(".",""),bI=0,bL=Object.prototype.toString,bB=false,bA=true,bK=/\\/g,bO=/\r\n/g,bQ=/\W/;[0,0].sort(function(){bA=false;return 0});var by=function(bV,e,bY,bZ){bY=bY||[];e=e||av;var b1=e;if(e.nodeType!==1&&e.nodeType!==9){return[]}if(!bV||typeof bV!=="string"){return bY}var bS,b3,b6,bR,b2,b5,b4,bX,bU=true,bT=by.isXML(e),bW=[],b0=bV;do{bH.exec("");bS=bH.exec(b0);if(bS){b0=bS[3];bW.push(bS[1]);if(bS[2]){bR=bS[3];break}}}while(bS);if(bW.length>1&&bD.exec(bV)){if(bW.length===2&&bE.relative[bW[0]]){b3=bM(bW[0]+bW[1],e,bZ)}else{b3=bE.relative[bW[0]]?[e]:by(bW.shift(),e);while(bW.length){bV=bW.shift();if(bE.relative[bV]){bV+=bW.shift()}b3=bM(bV,b3,bZ)}}}else{if(!bZ&&bW.length>1&&e.nodeType===9&&!bT&&bE.match.ID.test(bW[0])&&!bE.match.ID.test(bW[bW.length-1])){b2=by.find(bW.shift(),e,bT);e=b2.expr?by.filter(b2.expr,b2.set)[0]:b2.set[0]}if(e){b2=bZ?{expr:bW.pop(),set:bF(bZ)}:by.find(bW.pop(),bW.length===1&&(bW[0]==="~"||bW[0]==="+")&&e.parentNode?e.parentNode:e,bT);b3=b2.expr?by.filter(b2.expr,b2.set):b2.set;if(bW.length>0){b6=bF(b3)}else{bU=false}while(bW.length){b5=bW.pop();b4=b5;if(!bE.relative[b5]){b5=""}else{b4=bW.pop()}if(b4==null){b4=e}bE.relative[b5](b6,b4,bT)}}else{b6=bW=[]}}if(!b6){b6=b3}if(!b6){by.error(b5||bV)}if(bL.call(b6)==="[object Array]"){if(!bU){bY.push.apply(bY,b6)}else{if(e&&e.nodeType===1){for(bX=0;b6[bX]!=null;bX++){if(b6[bX]&&(b6[bX]===true||b6[bX].nodeType===1&&by.contains(e,b6[bX]))){bY.push(b3[bX])}}}else{for(bX=0;b6[bX]!=null;bX++){if(b6[bX]&&b6[bX].nodeType===1){bY.push(b3[bX])}}}}}else{bF(b6,bY)}if(bR){by(bR,b1,bY,bZ);by.uniqueSort(bY)}return bY};by.uniqueSort=function(bR){if(bJ){bB=bA;bR.sort(bJ);if(bB){for(var e=1;e0};by.find=function(bX,e,bY){var bW,bS,bU,bT,bV,bR;if(!bX){return[]}for(bS=0,bU=bE.order.length;bS":function(bW,bR){var bV,bU=typeof bR==="string",bS=0,e=bW.length;if(bU&&!bQ.test(bR)){bR=bR.toLowerCase();for(;bS=0)){if(!bS){e.push(bV)}}else{if(bS){bR[bU]=false}}}}return false},ID:function(e){return e[1].replace(bK,"")},TAG:function(bR,e){return bR[1].replace(bK,"").toLowerCase()},CHILD:function(e){if(e[1]==="nth"){if(!e[2]){by.error(e[0])}e[2]=e[2].replace(/^\+|\s*/g,"");var bR=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(e[2]==="even"&&"2n"||e[2]==="odd"&&"2n+1"||!/\D/.test(e[2])&&"0n+"+e[2]||e[2]);e[2]=(bR[1]+(bR[2]||1))-0;e[3]=bR[3]-0}else{if(e[2]){by.error(e[0])}}e[0]=bI++;return e},ATTR:function(bU,bR,bS,e,bV,bW){var bT=bU[1]=bU[1].replace(bK,"");if(!bW&&bE.attrMap[bT]){bU[1]=bE.attrMap[bT]}bU[4]=(bU[4]||bU[5]||"").replace(bK,"");if(bU[2]==="~="){bU[4]=" "+bU[4]+" "}return bU},PSEUDO:function(bU,bR,bS,e,bV){if(bU[1]==="not"){if((bH.exec(bU[3])||"").length>1||/^\w/.test(bU[3])){bU[3]=by(bU[3],null,null,bR)}else{var bT=by.filter(bU[3],bR,bS,true^bV);if(!bS){e.push.apply(e,bT)}return false}}else{if(bE.match.POS.test(bU[0])||bE.match.CHILD.test(bU[0])){return true}}return bU},POS:function(e){e.unshift(true);return e}},filters:{enabled:function(e){return e.disabled===false&&e.type!=="hidden"},disabled:function(e){return e.disabled===true},checked:function(e){return e.checked===true},selected:function(e){if(e.parentNode){e.parentNode.selectedIndex}return e.selected===true},parent:function(e){return !!e.firstChild},empty:function(e){return !e.firstChild},has:function(bS,bR,e){return !!by(e[3],bS).length},header:function(e){return(/h\d/i).test(e.nodeName)},text:function(bS){var e=bS.getAttribute("type"),bR=bS.type;return bS.nodeName.toLowerCase()==="input"&&"text"===bR&&(e===bR||e===null)},radio:function(e){return e.nodeName.toLowerCase()==="input"&&"radio"===e.type},checkbox:function(e){return e.nodeName.toLowerCase()==="input"&&"checkbox"===e.type},file:function(e){return e.nodeName.toLowerCase()==="input"&&"file"===e.type},password:function(e){return e.nodeName.toLowerCase()==="input"&&"password"===e.type},submit:function(bR){var e=bR.nodeName.toLowerCase();return(e==="input"||e==="button")&&"submit"===bR.type},image:function(e){return e.nodeName.toLowerCase()==="input"&&"image"===e.type},reset:function(bR){var e=bR.nodeName.toLowerCase();return(e==="input"||e==="button")&&"reset"===bR.type},button:function(bR){var e=bR.nodeName.toLowerCase();return e==="input"&&"button"===bR.type||e==="button"},input:function(e){return(/input|select|textarea|button/i).test(e.nodeName)},focus:function(e){return e===e.ownerDocument.activeElement}},setFilters:{first:function(bR,e){return e===0},last:function(bS,bR,e,bT){return bR===bT.length-1},even:function(bR,e){return e%2===0},odd:function(bR,e){return e%2===1},lt:function(bS,bR,e){return bRe[3]-0},nth:function(bS,bR,e){return e[3]-0===bR},eq:function(bS,bR,e){return e[3]-0===bR}},filter:{PSEUDO:function(bS,bX,bW,bY){var e=bX[1],bR=bE.filters[e];if(bR){return bR(bS,bW,bX,bY)}else{if(e==="contains"){return(bS.textContent||bS.innerText||bw([bS])||"").indexOf(bX[3])>=0}else{if(e==="not"){var bT=bX[3];for(var bV=0,bU=bT.length;bV=0)}}},ID:function(bR,e){return bR.nodeType===1&&bR.getAttribute("id")===e},TAG:function(bR,e){return(e==="*"&&bR.nodeType===1)||!!bR.nodeName&&bR.nodeName.toLowerCase()===e},CLASS:function(bR,e){return(" "+(bR.className||bR.getAttribute("class"))+" ").indexOf(e)>-1},ATTR:function(bV,bT){var bS=bT[1],e=by.attr?by.attr(bV,bS):bE.attrHandle[bS]?bE.attrHandle[bS](bV):bV[bS]!=null?bV[bS]:bV.getAttribute(bS),bW=e+"",bU=bT[2],bR=bT[4];return e==null?bU==="!=":!bU&&by.attr?e!=null:bU==="="?bW===bR:bU==="*="?bW.indexOf(bR)>=0:bU==="~="?(" "+bW+" ").indexOf(bR)>=0:!bR?bW&&e!==false:bU==="!="?bW!==bR:bU==="^="?bW.indexOf(bR)===0:bU==="$="?bW.substr(bW.length-bR.length)===bR:bU==="|="?bW===bR||bW.substr(0,bR.length+1)===bR+"-":false},POS:function(bU,bR,bS,bV){var e=bR[2],bT=bE.setFilters[e];if(bT){return bT(bU,bS,bR,bV)}}}};var bD=bE.match.POS,bx=function(bR,e){return"\\"+(e-0+1)};for(var bz in bE.match){bE.match[bz]=new RegExp(bE.match[bz].source+(/(?![^\[]*\])(?![^\(]*\))/.source));bE.leftMatch[bz]=new RegExp(/(^(?:.|\r|\n)*?)/.source+bE.match[bz].source.replace(/\\(\d+)/g,bx))}var bF=function(bR,e){bR=Array.prototype.slice.call(bR,0);if(e){e.push.apply(e,bR);return e}return bR};try{Array.prototype.slice.call(av.documentElement.childNodes,0)[0].nodeType}catch(bP){bF=function(bU,bT){var bS=0,bR=bT||[];if(bL.call(bU)==="[object Array]"){Array.prototype.push.apply(bR,bU)}else{if(typeof bU.length==="number"){for(var e=bU.length;bS";e.insertBefore(bR,e.firstChild);if(av.getElementById(bS)){bE.find.ID=function(bU,bV,bW){if(typeof bV.getElementById!=="undefined"&&!bW){var bT=bV.getElementById(bU[1]);return bT?bT.id===bU[1]||typeof bT.getAttributeNode!=="undefined"&&bT.getAttributeNode("id").nodeValue===bU[1]?[bT]:L:[]}};bE.filter.ID=function(bV,bT){var bU=typeof bV.getAttributeNode!=="undefined"&&bV.getAttributeNode("id");return bV.nodeType===1&&bU&&bU.nodeValue===bT}}e.removeChild(bR);e=bR=null})();(function(){var e=av.createElement("div");e.appendChild(av.createComment(""));if(e.getElementsByTagName("*").length>0){bE.find.TAG=function(bR,bV){var bU=bV.getElementsByTagName(bR[1]);if(bR[1]==="*"){var bT=[];for(var bS=0;bU[bS];bS++){if(bU[bS].nodeType===1){bT.push(bU[bS])}}bU=bT}return bU}}e.innerHTML="";if(e.firstChild&&typeof e.firstChild.getAttribute!=="undefined"&&e.firstChild.getAttribute("href")!=="#"){bE.attrHandle.href=function(bR){return bR.getAttribute("href",2)}}e=null})();if(av.querySelectorAll){(function(){var e=by,bT=av.createElement("div"),bS="__sizzle__";bT.innerHTML="

";if(bT.querySelectorAll&&bT.querySelectorAll(".TEST").length===0){return}by=function(b4,bV,bZ,b3){bV=bV||av;if(!b3&&!by.isXML(bV)){var b2=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b4);if(b2&&(bV.nodeType===1||bV.nodeType===9)){if(b2[1]){return bF(bV.getElementsByTagName(b4),bZ)}else{if(b2[2]&&bE.find.CLASS&&bV.getElementsByClassName){return bF(bV.getElementsByClassName(b2[2]),bZ)}}}if(bV.nodeType===9){if(b4==="body"&&bV.body){return bF([bV.body],bZ)}else{if(b2&&b2[3]){var bY=bV.getElementById(b2[3]);if(bY&&bY.parentNode){if(bY.id===b2[3]){return bF([bY],bZ)}}else{return bF([],bZ)}}}try{return bF(bV.querySelectorAll(b4),bZ)}catch(b0){}}else{if(bV.nodeType===1&&bV.nodeName.toLowerCase()!=="object"){var bW=bV,bX=bV.getAttribute("id"),bU=bX||bS,b6=bV.parentNode,b5=/^\s*[+~]/.test(b4);if(!bX){bV.setAttribute("id",bU)}else{bU=bU.replace(/'/g,"\\$&")}if(b5&&b6){bV=bV.parentNode}try{if(!b5||b6){return bF(bV.querySelectorAll("[id='"+bU+"'] "+b4),bZ)}}catch(b1){}finally{if(!bX){bW.removeAttribute("id")}}}}}return e(b4,bV,bZ,b3)};for(var bR in e){by[bR]=e[bR]}bT=null})()}(function(){var e=av.documentElement,bS=e.matchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.msMatchesSelector;if(bS){var bU=!bS.call(av.createElement("div"),"div"),bR=false;try{bS.call(av.documentElement,"[test!='']:sizzle")}catch(bT){bR=true}by.matchesSelector=function(bW,bY){bY=bY.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!by.isXML(bW)){try{if(bR||!bE.match.PSEUDO.test(bY)&&!/!=/.test(bY)){var bV=bS.call(bW,bY);if(bV||!bU||bW.document&&bW.document.nodeType!==11){return bV}}}catch(bX){}}return by(bY,null,null,[bW]).length>0}}})();(function(){var e=av.createElement("div");e.innerHTML="
";if(!e.getElementsByClassName||e.getElementsByClassName("e").length===0){return}e.lastChild.className="e";if(e.getElementsByClassName("e").length===1){return}bE.order.splice(1,0,"CLASS");bE.find.CLASS=function(bR,bS,bT){if(typeof bS.getElementsByClassName!=="undefined"&&!bT){return bS.getElementsByClassName(bR[1])}};e=null})();function bv(bR,bW,bV,bZ,bX,bY){for(var bT=0,bS=bZ.length;bT0){bU=e;break}}}e=e[bR]}bZ[bT]=bU}}}if(av.documentElement.contains){by.contains=function(bR,e){return bR!==e&&(bR.contains?bR.contains(e):true)}}else{if(av.documentElement.compareDocumentPosition){by.contains=function(bR,e){return !!(bR.compareDocumentPosition(e)&16)}}else{by.contains=function(){return false}}}by.isXML=function(e){var bR=(e?e.ownerDocument||e:0).documentElement;return bR?bR.nodeName!=="HTML":false};var bM=function(bS,e,bW){var bV,bX=[],bU="",bY=e.nodeType?[e]:e;while((bV=bE.match.PSEUDO.exec(bS))){bU+=bV[0];bS=bS.replace(bE.match.PSEUDO,"")}bS=bE.relative[bS]?bS+"*":bS;for(var bT=0,bR=bY.length;bT0){for(bB=bA;bB=0:b.filter(e,this).length>0:this.filter(e).length>0)},closest:function(by,bx){var bv=[],bw,e,bz=this[0];if(b.isArray(by)){var bB=1;while(bz&&bz.ownerDocument&&bz!==bx){for(bw=0;bw-1:b.find.matchesSelector(bz,by)){bv.push(bz);break}else{bz=bz.parentNode;if(!bz||!bz.ownerDocument||bz===bx||bz.nodeType===11){break}}}}bv=bv.length>1?b.unique(bv):bv;return this.pushStack(bv,"closest",by)},index:function(e){if(!e){return(this[0]&&this[0].parentNode)?this.prevAll().length:-1}if(typeof e==="string"){return b.inArray(this[0],b(e))}return b.inArray(e.jquery?e[0]:e,this)},add:function(e,bv){var bx=typeof e==="string"?b(e,bv):b.makeArray(e&&e.nodeType?[e]:e),bw=b.merge(this.get(),bx);return this.pushStack(C(bx[0])||C(bw[0])?bw:b.unique(bw))},andSelf:function(){return this.add(this.prevObject)}});function C(e){return !e||!e.parentNode||e.parentNode.nodeType===11}b.each({parent:function(bv){var e=bv.parentNode;return e&&e.nodeType!==11?e:null},parents:function(e){return b.dir(e,"parentNode")},parentsUntil:function(bv,e,bw){return b.dir(bv,"parentNode",bw)},next:function(e){return b.nth(e,2,"nextSibling")},prev:function(e){return b.nth(e,2,"previousSibling")},nextAll:function(e){return b.dir(e,"nextSibling")},prevAll:function(e){return b.dir(e,"previousSibling")},nextUntil:function(bv,e,bw){return b.dir(bv,"nextSibling",bw)},prevUntil:function(bv,e,bw){return b.dir(bv,"previousSibling",bw)},siblings:function(e){return b.sibling(e.parentNode.firstChild,e)},children:function(e){return b.sibling(e.firstChild)},contents:function(e){return b.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:b.makeArray(e.childNodes)}},function(e,bv){b.fn[e]=function(by,bw){var bx=b.map(this,bv,by);if(!ab.test(e)){bw=by}if(bw&&typeof bw==="string"){bx=b.filter(bw,bx)}bx=this.length>1&&!ay[e]?b.unique(bx):bx;if((this.length>1||a9.test(bw))&&aq.test(e)){bx=bx.reverse()}return this.pushStack(bx,e,P.call(arguments).join(","))}});b.extend({filter:function(bw,e,bv){if(bv){bw=":not("+bw+")"}return e.length===1?b.find.matchesSelector(e[0],bw)?[e[0]]:[]:b.find.matches(bw,e)},dir:function(bw,bv,by){var e=[],bx=bw[bv];while(bx&&bx.nodeType!==9&&(by===L||bx.nodeType!==1||!b(bx).is(by))){if(bx.nodeType===1){e.push(bx)}bx=bx[bv]}return e},nth:function(by,e,bw,bx){e=e||1;var bv=0;for(;by;by=by[bw]){if(by.nodeType===1&&++bv===e){break}}return by},sibling:function(bw,bv){var e=[];for(;bw;bw=bw.nextSibling){if(bw.nodeType===1&&bw!==bv){e.push(bw)}}return e}});function aG(bx,bw,e){bw=bw||0;if(b.isFunction(bw)){return b.grep(bx,function(bz,by){var bA=!!bw.call(bz,by,bz);return bA===e})}else{if(bw.nodeType){return b.grep(bx,function(bz,by){return(bz===bw)===e})}else{if(typeof bw==="string"){var bv=b.grep(bx,function(by){return by.nodeType===1});if(bp.test(bw)){return b.filter(bw,bv,!e)}else{bw=b.filter(bw,bv)}}}}return b.grep(bx,function(bz,by){return(b.inArray(bz,bw)>=0)===e})}function a(e){var bw=aR.split("|"),bv=e.createDocumentFragment();if(bv.createElement){while(bw.length){bv.createElement(bw.pop())}}return bv}var aR="abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",ag=/ jQuery\d+="(?:\d+|null)"/g,ar=/^\s+/,R=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,d=/<([\w:]+)/,w=/",""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]},ac=a(av);ax.optgroup=ax.option;ax.tbody=ax.tfoot=ax.colgroup=ax.caption=ax.thead;ax.th=ax.td;if(!b.support.htmlSerialize){ax._default=[1,"div
","
"]}b.fn.extend({text:function(e){if(b.isFunction(e)){return this.each(function(bw){var bv=b(this);bv.text(e.call(this,bw,bv.text()))})}if(typeof e!=="object"&&e!==L){return this.empty().append((this[0]&&this[0].ownerDocument||av).createTextNode(e))}return b.text(this)},wrapAll:function(e){if(b.isFunction(e)){return this.each(function(bw){b(this).wrapAll(e.call(this,bw))})}if(this[0]){var bv=b(e,this[0].ownerDocument).eq(0).clone(true);if(this[0].parentNode){bv.insertBefore(this[0])}bv.map(function(){var bw=this;while(bw.firstChild&&bw.firstChild.nodeType===1){bw=bw.firstChild}return bw}).append(this)}return this},wrapInner:function(e){if(b.isFunction(e)){return this.each(function(bv){b(this).wrapInner(e.call(this,bv))})}return this.each(function(){var bv=b(this),bw=bv.contents();if(bw.length){bw.wrapAll(e)}else{bv.append(e)}})},wrap:function(e){var bv=b.isFunction(e);return this.each(function(bw){b(this).wrapAll(bv?e.call(this,bw):e)})},unwrap:function(){return this.parent().each(function(){if(!b.nodeName(this,"body")){b(this).replaceWith(this.childNodes)}}).end()},append:function(){return this.domManip(arguments,true,function(e){if(this.nodeType===1){this.appendChild(e)}})},prepend:function(){return this.domManip(arguments,true,function(e){if(this.nodeType===1){this.insertBefore(e,this.firstChild)}})},before:function(){if(this[0]&&this[0].parentNode){return this.domManip(arguments,false,function(bv){this.parentNode.insertBefore(bv,this)})}else{if(arguments.length){var e=b.clean(arguments);e.push.apply(e,this.toArray());return this.pushStack(e,"before",arguments)}}},after:function(){if(this[0]&&this[0].parentNode){return this.domManip(arguments,false,function(bv){this.parentNode.insertBefore(bv,this.nextSibling)})}else{if(arguments.length){var e=this.pushStack(this,"after",arguments);e.push.apply(e,b.clean(arguments));return e}}},remove:function(e,bx){for(var bv=0,bw;(bw=this[bv])!=null;bv++){if(!e||b.filter(e,[bw]).length){if(!bx&&bw.nodeType===1){b.cleanData(bw.getElementsByTagName("*"));b.cleanData([bw])}if(bw.parentNode){bw.parentNode.removeChild(bw)}}}return this},empty:function(){for(var e=0,bv;(bv=this[e])!=null;e++){if(bv.nodeType===1){b.cleanData(bv.getElementsByTagName("*"))}while(bv.firstChild){bv.removeChild(bv.firstChild)}}return this},clone:function(bv,e){bv=bv==null?false:bv;e=e==null?bv:e;return this.map(function(){return b.clone(this,bv,e)})},html:function(bx){if(bx===L){return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(ag,""):null}else{if(typeof bx==="string"&&!ae.test(bx)&&(b.support.leadingWhitespace||!ar.test(bx))&&!ax[(d.exec(bx)||["",""])[1].toLowerCase()]){bx=bx.replace(R,"<$1>");try{for(var bw=0,bv=this.length;bw1&&bw0?this.clone(true):this).get();b(bC[bA])[bv](by);bz=bz.concat(by)}return this.pushStack(bz,e,bC.selector)}}});function bg(e){if(typeof e.getElementsByTagName!=="undefined"){return e.getElementsByTagName("*")}else{if(typeof e.querySelectorAll!=="undefined"){return e.querySelectorAll("*")}else{return[]}}}function az(e){if(e.type==="checkbox"||e.type==="radio"){e.defaultChecked=e.checked}}function E(e){var bv=(e.nodeName||"").toLowerCase();if(bv==="input"){az(e)}else{if(bv!=="script"&&typeof e.getElementsByTagName!=="undefined"){b.grep(e.getElementsByTagName("input"),az)}}}function al(e){var bv=av.createElement("div");ac.appendChild(bv);bv.innerHTML=e.outerHTML;return bv.firstChild}b.extend({clone:function(by,bA,bw){var e,bv,bx,bz=b.support.html5Clone||!ah.test("<"+by.nodeName)?by.cloneNode(true):al(by);if((!b.support.noCloneEvent||!b.support.noCloneChecked)&&(by.nodeType===1||by.nodeType===11)&&!b.isXMLDoc(by)){ai(by,bz);e=bg(by);bv=bg(bz);for(bx=0;e[bx];++bx){if(bv[bx]){ai(e[bx],bv[bx])}}}if(bA){t(by,bz);if(bw){e=bg(by);bv=bg(bz);for(bx=0;e[bx];++bx){t(e[bx],bv[bx])}}}e=bv=null;return bz},clean:function(bw,by,bH,bA){var bF;by=by||av;if(typeof by.createElement==="undefined"){by=by.ownerDocument||by[0]&&by[0].ownerDocument||av}var bI=[],bB;for(var bE=0,bz;(bz=bw[bE])!=null;bE++){if(typeof bz==="number"){bz+=""}if(!bz){continue}if(typeof bz==="string"){if(!W.test(bz)){bz=by.createTextNode(bz)}else{bz=bz.replace(R,"<$1>");var bK=(d.exec(bz)||["",""])[1].toLowerCase(),bx=ax[bK]||ax._default,bD=bx[0],bv=by.createElement("div");if(by===av){ac.appendChild(bv)}else{a(by).appendChild(bv)}bv.innerHTML=bx[1]+bz+bx[2];while(bD--){bv=bv.lastChild}if(!b.support.tbody){var e=w.test(bz),bC=bK==="table"&&!e?bv.firstChild&&bv.firstChild.childNodes:bx[1]===""&&!e?bv.childNodes:[];for(bB=bC.length-1;bB>=0;--bB){if(b.nodeName(bC[bB],"tbody")&&!bC[bB].childNodes.length){bC[bB].parentNode.removeChild(bC[bB])}}}if(!b.support.leadingWhitespace&&ar.test(bz)){bv.insertBefore(by.createTextNode(ar.exec(bz)[0]),bv.firstChild)}bz=bv.childNodes}}var bG;if(!b.support.appendChecked){if(bz[0]&&typeof(bG=bz.length)==="number"){for(bB=0;bB=0){return bx+"px"}}else{return bx}}}});if(!b.support.opacity){b.cssHooks.opacity={get:function(bv,e){return au.test((e&&bv.currentStyle?bv.currentStyle.filter:bv.style.filter)||"")?(parseFloat(RegExp.$1)/100)+"":e?"1":""},set:function(by,bz){var bx=by.style,bv=by.currentStyle,e=b.isNumeric(bz)?"alpha(opacity="+bz*100+")":"",bw=bv&&bv.filter||bx.filter||"";bx.zoom=1;if(bz>=1&&b.trim(bw.replace(ak,""))===""){bx.removeAttribute("filter");if(bv&&!bv.filter){return}}bx.filter=ak.test(bw)?bw.replace(ak,e):bw+" "+e}}}b(function(){if(!b.support.reliableMarginRight){b.cssHooks.marginRight={get:function(bw,bv){var e;b.swap(bw,{display:"inline-block"},function(){if(bv){e=Z(bw,"margin-right","marginRight")}else{e=bw.style.marginRight}});return e}}}});if(av.defaultView&&av.defaultView.getComputedStyle){aI=function(by,bw){var bv,bx,e;bw=bw.replace(z,"-$1").toLowerCase();if((bx=by.ownerDocument.defaultView)&&(e=bx.getComputedStyle(by,null))){bv=e.getPropertyValue(bw);if(bv===""&&!b.contains(by.ownerDocument.documentElement,by)){bv=b.style(by,bw)}}return bv}}if(av.documentElement.currentStyle){aX=function(bz,bw){var bA,e,by,bv=bz.currentStyle&&bz.currentStyle[bw],bx=bz.style;if(bv===null&&bx&&(by=bx[bw])){bv=by}if(!bc.test(bv)&&bn.test(bv)){bA=bx.left;e=bz.runtimeStyle&&bz.runtimeStyle.left;if(e){bz.runtimeStyle.left=bz.currentStyle.left}bx.left=bw==="fontSize"?"1em":(bv||0);bv=bx.pixelLeft+"px";bx.left=bA;if(e){bz.runtimeStyle.left=e}}return bv===""?"auto":bv}}Z=aI||aX;function p(by,bw,bv){var bA=bw==="width"?by.offsetWidth:by.offsetHeight,bz=bw==="width"?an:a1,bx=0,e=bz.length;if(bA>0){if(bv!=="border"){for(;bx)<[^<]*)*<\/script>/gi,q=/^(?:select|textarea)/i,h=/\s+/,br=/([?&])_=[^&]*/,K=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,A=b.fn.load,aa={},r={},aE,s,aV=["*/"]+["*"];try{aE=bl.href}catch(aw){aE=av.createElement("a");aE.href="";aE=aE.href}s=K.exec(aE.toLowerCase())||[];function f(e){return function(by,bA){if(typeof by!=="string"){bA=by;by="*"}if(b.isFunction(bA)){var bx=by.toLowerCase().split(h),bw=0,bz=bx.length,bv,bB,bC;for(;bw=0){var e=bw.slice(by,bw.length);bw=bw.slice(0,by)}var bx="GET";if(bz){if(b.isFunction(bz)){bA=bz;bz=L}else{if(typeof bz==="object"){bz=b.param(bz,b.ajaxSettings.traditional);bx="POST"}}}var bv=this;b.ajax({url:bw,type:bx,dataType:"html",data:bz,complete:function(bC,bB,bD){bD=bC.responseText;if(bC.isResolved()){bC.done(function(bE){bD=bE});bv.html(e?b("
").append(bD.replace(a6,"")).find(e):bD)}if(bA){bv.each(bA,[bD,bB,bC])}}});return this},serialize:function(){return b.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?b.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||q.test(this.nodeName)||aZ.test(this.type))}).map(function(e,bv){var bw=b(this).val();return bw==null?null:b.isArray(bw)?b.map(bw,function(by,bx){return{name:bv.name,value:by.replace(bs,"\r\n")}}):{name:bv.name,value:bw.replace(bs,"\r\n")}}).get()}});b.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(e,bv){b.fn[bv]=function(bw){return this.on(bv,bw)}});b.each(["get","post"],function(e,bv){b[bv]=function(bw,by,bz,bx){if(b.isFunction(by)){bx=bx||bz;bz=by;by=L}return b.ajax({type:bv,url:bw,data:by,success:bz,dataType:bx})}});b.extend({getScript:function(e,bv){return b.get(e,L,bv,"script")},getJSON:function(e,bv,bw){return b.get(e,bv,bw,"json")},ajaxSetup:function(bv,e){if(e){am(bv,b.ajaxSettings)}else{e=bv;bv=b.ajaxSettings}am(bv,e);return bv},ajaxSettings:{url:aE,isLocal:aM.test(s[1]),global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":aV},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":bb.String,"text html":true,"text json":b.parseJSON,"text xml":b.parseXML},flatOptions:{context:true,url:true}},ajaxPrefilter:f(aa),ajaxTransport:f(r),ajax:function(bz,bx){if(typeof bz==="object"){bx=bz;bz=L}bx=bx||{};var bD=b.ajaxSetup({},bx),bS=bD.context||bD,bG=bS!==bD&&(bS.nodeType||bS instanceof b)?b(bS):b.event,bR=b.Deferred(),bN=b.Callbacks("once memory"),bB=bD.statusCode||{},bC,bH={},bO={},bQ,by,bL,bE,bI,bA=0,bw,bK,bJ={readyState:0,setRequestHeader:function(bT,bU){if(!bA){var e=bT.toLowerCase();bT=bO[e]=bO[e]||bT;bH[bT]=bU}return this},getAllResponseHeaders:function(){return bA===2?bQ:null},getResponseHeader:function(bT){var e;if(bA===2){if(!by){by={};while((e=aD.exec(bQ))){by[e[1].toLowerCase()]=e[2]}}e=by[bT.toLowerCase()]}return e===L?null:e},overrideMimeType:function(e){if(!bA){bD.mimeType=e}return this},abort:function(e){e=e||"abort";if(bL){bL.abort(e)}bF(0,e);return this}};function bF(bZ,bU,b0,bW){if(bA===2){return}bA=2;if(bE){clearTimeout(bE)}bL=L;bQ=bW||"";bJ.readyState=bZ>0?4:0;var bT,b4,b3,bX=bU,bY=b0?bj(bD,bJ,b0):L,bV,b2;if(bZ>=200&&bZ<300||bZ===304){if(bD.ifModified){if((bV=bJ.getResponseHeader("Last-Modified"))){b.lastModified[bC]=bV}if((b2=bJ.getResponseHeader("Etag"))){b.etag[bC]=b2}}if(bZ===304){bX="notmodified";bT=true}else{try{b4=G(bD,bY);bX="success";bT=true}catch(b1){bX="parsererror";b3=b1}}}else{b3=bX;if(!bX||bZ){bX="error";if(bZ<0){bZ=0}}}bJ.status=bZ;bJ.statusText=""+(bU||bX);if(bT){bR.resolveWith(bS,[b4,bX,bJ])}else{bR.rejectWith(bS,[bJ,bX,b3])}bJ.statusCode(bB);bB=L;if(bw){bG.trigger("ajax"+(bT?"Success":"Error"),[bJ,bD,bT?b4:b3])}bN.fireWith(bS,[bJ,bX]);if(bw){bG.trigger("ajaxComplete",[bJ,bD]);if(!(--b.active)){b.event.trigger("ajaxStop")}}}bR.promise(bJ);bJ.success=bJ.done;bJ.error=bJ.fail;bJ.complete=bN.add;bJ.statusCode=function(bT){if(bT){var e;if(bA<2){for(e in bT){bB[e]=[bB[e],bT[e]]}}else{e=bT[bJ.status];bJ.then(e,e)}}return this};bD.url=((bz||bD.url)+"").replace(bq,"").replace(c,s[1]+"//");bD.dataTypes=b.trim(bD.dataType||"*").toLowerCase().split(h);if(bD.crossDomain==null){bI=K.exec(bD.url.toLowerCase());bD.crossDomain=!!(bI&&(bI[1]!=s[1]||bI[2]!=s[2]||(bI[3]||(bI[1]==="http:"?80:443))!=(s[3]||(s[1]==="http:"?80:443))))}if(bD.data&&bD.processData&&typeof bD.data!=="string"){bD.data=b.param(bD.data,bD.traditional)}aW(aa,bD,bx,bJ);if(bA===2){return false}bw=bD.global;bD.type=bD.type.toUpperCase();bD.hasContent=!aQ.test(bD.type);if(bw&&b.active++===0){b.event.trigger("ajaxStart")}if(!bD.hasContent){if(bD.data){bD.url+=(M.test(bD.url)?"&":"?")+bD.data;delete bD.data}bC=bD.url;if(bD.cache===false){var bv=b.now(),bP=bD.url.replace(br,"$1_="+bv);bD.url=bP+((bP===bD.url)?(M.test(bD.url)?"&":"?")+"_="+bv:"")}}if(bD.data&&bD.hasContent&&bD.contentType!==false||bx.contentType){bJ.setRequestHeader("Content-Type",bD.contentType)}if(bD.ifModified){bC=bC||bD.url;if(b.lastModified[bC]){bJ.setRequestHeader("If-Modified-Since",b.lastModified[bC])}if(b.etag[bC]){bJ.setRequestHeader("If-None-Match",b.etag[bC])}}bJ.setRequestHeader("Accept",bD.dataTypes[0]&&bD.accepts[bD.dataTypes[0]]?bD.accepts[bD.dataTypes[0]]+(bD.dataTypes[0]!=="*"?", "+aV+"; q=0.01":""):bD.accepts["*"]);for(bK in bD.headers){bJ.setRequestHeader(bK,bD.headers[bK])}if(bD.beforeSend&&(bD.beforeSend.call(bS,bJ,bD)===false||bA===2)){bJ.abort();return false}for(bK in {success:1,error:1,complete:1}){bJ[bK](bD[bK])}bL=aW(r,bD,bx,bJ);if(!bL){bF(-1,"No Transport")}else{bJ.readyState=1;if(bw){bG.trigger("ajaxSend",[bJ,bD])}if(bD.async&&bD.timeout>0){bE=setTimeout(function(){bJ.abort("timeout")},bD.timeout)}try{bA=1;bL.send(bH,bF)}catch(bM){if(bA<2){bF(-1,bM)}else{throw bM}}}return bJ},param:function(e,bw){var bv=[],by=function(bz,bA){bA=b.isFunction(bA)?bA():bA;bv[bv.length]=encodeURIComponent(bz)+"="+encodeURIComponent(bA)};if(bw===L){bw=b.ajaxSettings.traditional}if(b.isArray(e)||(e.jquery&&!b.isPlainObject(e))){b.each(e,function(){by(this.name,this.value)})}else{for(var bx in e){v(bx,e[bx],bw,by)}}return bv.join("&").replace(k,"+")}});function v(bw,by,bv,bx){if(b.isArray(by)){b.each(by,function(bA,bz){if(bv||ap.test(bw)){bx(bw,bz)}else{v(bw+"["+(typeof bz==="object"||b.isArray(bz)?bA:"")+"]",bz,bv,bx)}})}else{if(!bv&&by!=null&&typeof by==="object"){for(var e in by){v(bw+"["+e+"]",by[e],bv,bx)}}else{bx(bw,by)}}}b.extend({active:0,lastModified:{},etag:{}});function bj(bD,bC,bz){var bv=bD.contents,bB=bD.dataTypes,bw=bD.responseFields,by,bA,bx,e;for(bA in bw){if(bA in bz){bC[bw[bA]]=bz[bA]}}while(bB[0]==="*"){bB.shift();if(by===L){by=bD.mimeType||bC.getResponseHeader("content-type")}}if(by){for(bA in bv){if(bv[bA]&&bv[bA].test(by)){bB.unshift(bA);break}}}if(bB[0] in bz){bx=bB[0]}else{for(bA in bz){if(!bB[0]||bD.converters[bA+" "+bB[0]]){bx=bA;break}if(!e){e=bA}}bx=bx||e}if(bx){if(bx!==bB[0]){bB.unshift(bx)}return bz[bx]}}function G(bH,bz){if(bH.dataFilter){bz=bH.dataFilter(bz,bH.dataType)}var bD=bH.dataTypes,bG={},bA,bE,bw=bD.length,bB,bC=bD[0],bx,by,bF,bv,e;for(bA=1;bA=bw.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();bw.animatedProperties[this.prop]=true;for(bA in bw.animatedProperties){if(bw.animatedProperties[bA]!==true){e=false}}if(e){if(bw.overflow!=null&&!b.support.shrinkWrapBlocks){b.each(["","X","Y"],function(bC,bD){bz.style["overflow"+bD]=bw.overflow[bC]})}if(bw.hide){b(bz).hide()}if(bw.hide||bw.show){for(bA in bw.animatedProperties){b.style(bz,bA,bw.orig[bA]);b.removeData(bz,"fxshow"+bA,true);b.removeData(bz,"toggle"+bA,true)}}bv=bw.complete;if(bv){bw.complete=false;bv.call(bz)}}return false}else{if(bw.duration==Infinity){this.now=bx}else{bB=bx-this.startTime;this.state=bB/bw.duration;this.pos=b.easing[bw.animatedProperties[this.prop]](this.state,bB,0,1,bw.duration);this.now=this.start+((this.end-this.start)*this.pos)}this.update()}return true}};b.extend(b.fx,{tick:function(){var bw,bv=b.timers,e=0;for(;e").appendTo(e),bw=bv.css("display");bv.remove();if(bw==="none"||bw===""){if(!a8){a8=av.createElement("iframe");a8.frameBorder=a8.width=a8.height=0}e.appendChild(a8);if(!m||!a8.createElement){m=(a8.contentWindow||a8.contentDocument).document;m.write((av.compatMode==="CSS1Compat"?"":"")+"");m.close()}bv=m.createElement(bx);m.body.appendChild(bv);bw=b.css(bv,"display");e.removeChild(a8)}Q[bx]=bw}return Q[bx]}var V=/^t(?:able|d|h)$/i,ad=/^(?:body|html)$/i;if("getBoundingClientRect" in av.documentElement){b.fn.offset=function(bI){var by=this[0],bB;if(bI){return this.each(function(e){b.offset.setOffset(this,bI,e)})}if(!by||!by.ownerDocument){return null}if(by===by.ownerDocument.body){return b.offset.bodyOffset(by)}try{bB=by.getBoundingClientRect()}catch(bF){}var bH=by.ownerDocument,bw=bH.documentElement;if(!bB||!b.contains(bw,by)){return bB?{top:bB.top,left:bB.left}:{top:0,left:0}}var bC=bH.body,bD=aK(bH),bA=bw.clientTop||bC.clientTop||0,bE=bw.clientLeft||bC.clientLeft||0,bv=bD.pageYOffset||b.support.boxModel&&bw.scrollTop||bC.scrollTop,bz=bD.pageXOffset||b.support.boxModel&&bw.scrollLeft||bC.scrollLeft,bG=bB.top+bv-bA,bx=bB.left+bz-bE;return{top:bG,left:bx}}}else{b.fn.offset=function(bF){var bz=this[0];if(bF){return this.each(function(bG){b.offset.setOffset(this,bF,bG)})}if(!bz||!bz.ownerDocument){return null}if(bz===bz.ownerDocument.body){return b.offset.bodyOffset(bz)}var bC,bw=bz.offsetParent,bv=bz,bE=bz.ownerDocument,bx=bE.documentElement,bA=bE.body,bB=bE.defaultView,e=bB?bB.getComputedStyle(bz,null):bz.currentStyle,bD=bz.offsetTop,by=bz.offsetLeft;while((bz=bz.parentNode)&&bz!==bA&&bz!==bx){if(b.support.fixedPosition&&e.position==="fixed"){break}bC=bB?bB.getComputedStyle(bz,null):bz.currentStyle;bD-=bz.scrollTop;by-=bz.scrollLeft;if(bz===bw){bD+=bz.offsetTop;by+=bz.offsetLeft;if(b.support.doesNotAddBorder&&!(b.support.doesAddBorderForTableAndCells&&V.test(bz.nodeName))){bD+=parseFloat(bC.borderTopWidth)||0;by+=parseFloat(bC.borderLeftWidth)||0}bv=bw;bw=bz.offsetParent}if(b.support.subtractsBorderForOverflowNotVisible&&bC.overflow!=="visible"){bD+=parseFloat(bC.borderTopWidth)||0;by+=parseFloat(bC.borderLeftWidth)||0}e=bC}if(e.position==="relative"||e.position==="static"){bD+=bA.offsetTop;by+=bA.offsetLeft}if(b.support.fixedPosition&&e.position==="fixed"){bD+=Math.max(bx.scrollTop,bA.scrollTop);by+=Math.max(bx.scrollLeft,bA.scrollLeft)}return{top:bD,left:by}}}b.offset={bodyOffset:function(e){var bw=e.offsetTop,bv=e.offsetLeft;if(b.support.doesNotIncludeMarginInBodyOffset){bw+=parseFloat(b.css(e,"marginTop"))||0;bv+=parseFloat(b.css(e,"marginLeft"))||0}return{top:bw,left:bv}},setOffset:function(bx,bG,bA){var bB=b.css(bx,"position");if(bB==="static"){bx.style.position="relative"}var bz=b(bx),bv=bz.offset(),e=b.css(bx,"top"),bE=b.css(bx,"left"),bF=(bB==="absolute"||bB==="fixed")&&b.inArray("auto",[e,bE])>-1,bD={},bC={},bw,by;if(bF){bC=bz.position();bw=bC.top;by=bC.left}else{bw=parseFloat(e)||0;by=parseFloat(bE)||0}if(b.isFunction(bG)){bG=bG.call(bx,bA,bv)}if(bG.top!=null){bD.top=(bG.top-bv.top)+bw}if(bG.left!=null){bD.left=(bG.left-bv.left)+by}if("using" in bG){bG.using.call(bx,bD)}else{bz.css(bD)}}};b.fn.extend({position:function(){if(!this[0]){return null}var bw=this[0],bv=this.offsetParent(),bx=this.offset(),e=ad.test(bv[0].nodeName)?{top:0,left:0}:bv.offset();bx.top-=parseFloat(b.css(bw,"marginTop"))||0;bx.left-=parseFloat(b.css(bw,"marginLeft"))||0;e.top+=parseFloat(b.css(bv[0],"borderTopWidth"))||0;e.left+=parseFloat(b.css(bv[0],"borderLeftWidth"))||0;return{top:bx.top-e.top,left:bx.left-e.left}},offsetParent:function(){return this.map(function(){var e=this.offsetParent||av.body;while(e&&(!ad.test(e.nodeName)&&b.css(e,"position")==="static")){e=e.offsetParent}return e})}});b.each(["Left","Top"],function(bv,e){var bw="scroll"+e;b.fn[bw]=function(bz){var bx,by;if(bz===L){bx=this[0];if(!bx){return null}by=aK(bx);return by?("pageXOffset" in by)?by[bv?"pageYOffset":"pageXOffset"]:b.support.boxModel&&by.document.documentElement[bw]||by.document.body[bw]:bx[bw]}return this.each(function(){by=aK(this);if(by){by.scrollTo(!bv?bz:b(by).scrollLeft(),bv?bz:b(by).scrollTop())}else{this[bw]=bz}})}});function aK(e){return b.isWindow(e)?e:e.nodeType===9?e.defaultView||e.parentWindow:false}b.each(["Height","Width"],function(bv,e){var bw=e.toLowerCase();b.fn["inner"+e]=function(){var bx=this[0];return bx?bx.style?parseFloat(b.css(bx,bw,"padding")):this[bw]():null};b.fn["outer"+e]=function(by){var bx=this[0];return bx?bx.style?parseFloat(b.css(bx,bw,by?"margin":"border")):this[bw]():null};b.fn[bw]=function(bz){var bA=this[0];if(!bA){return bz==null?null:this}if(b.isFunction(bz)){return this.each(function(bE){var bD=b(this);bD[bw](bz.call(this,bE,bD[bw]()))})}if(b.isWindow(bA)){var bB=bA.document.documentElement["client"+e],bx=bA.document.body;return bA.document.compatMode==="CSS1Compat"&&bB||bx&&bx["client"+e]||bB}else{if(bA.nodeType===9){return Math.max(bA.documentElement["client"+e],bA.body["scroll"+e],bA.documentElement["scroll"+e],bA.body["offset"+e],bA.documentElement["offset"+e])}else{if(bz===L){var bC=b.css(bA,bw),by=parseFloat(bC);return b.isNumeric(by)?by:bC}else{return this.css(bw,typeof bz==="string"?bz:bz+"px")}}}}});bb.jQuery=bb.$=b;if(typeof define==="function"&&define.amd&&define.amd.jQuery){define("jquery",[],function(){return b})}})(window);/*! + * jQuery UI 1.8.18 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI + */ +(function(a,d){a.ui=a.ui||{};if(a.ui.version){return}a.extend(a.ui,{version:"1.8.18",keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}});a.fn.extend({propAttr:a.fn.prop||a.fn.attr,_focus:a.fn.focus,focus:function(e,f){return typeof e==="number"?this.each(function(){var g=this;setTimeout(function(){a(g).focus();if(f){f.call(g)}},e)}):this._focus.apply(this,arguments)},scrollParent:function(){var e;if((a.browser.msie&&(/(static|relative)/).test(this.css("position")))||(/absolute/).test(this.css("position"))){e=this.parents().filter(function(){return(/(relative|absolute|fixed)/).test(a.curCSS(this,"position",1))&&(/(auto|scroll)/).test(a.curCSS(this,"overflow",1)+a.curCSS(this,"overflow-y",1)+a.curCSS(this,"overflow-x",1))}).eq(0)}else{e=this.parents().filter(function(){return(/(auto|scroll)/).test(a.curCSS(this,"overflow",1)+a.curCSS(this,"overflow-y",1)+a.curCSS(this,"overflow-x",1))}).eq(0)}return(/fixed/).test(this.css("position"))||!e.length?a(document):e},zIndex:function(h){if(h!==d){return this.css("zIndex",h)}if(this.length){var f=a(this[0]),e,g;while(f.length&&f[0]!==document){e=f.css("position");if(e==="absolute"||e==="relative"||e==="fixed"){g=parseInt(f.css("zIndex"),10);if(!isNaN(g)&&g!==0){return g}}f=f.parent()}}return 0},disableSelection:function(){return this.bind((a.support.selectstart?"selectstart":"mousedown")+".ui-disableSelection",function(e){e.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}});a.each(["Width","Height"],function(g,e){var f=e==="Width"?["Left","Right"]:["Top","Bottom"],h=e.toLowerCase(),k={innerWidth:a.fn.innerWidth,innerHeight:a.fn.innerHeight,outerWidth:a.fn.outerWidth,outerHeight:a.fn.outerHeight};function j(m,l,i,n){a.each(f,function(){l-=parseFloat(a.curCSS(m,"padding"+this,true))||0;if(i){l-=parseFloat(a.curCSS(m,"border"+this+"Width",true))||0}if(n){l-=parseFloat(a.curCSS(m,"margin"+this,true))||0}});return l}a.fn["inner"+e]=function(i){if(i===d){return k["inner"+e].call(this)}return this.each(function(){a(this).css(h,j(this,i)+"px")})};a.fn["outer"+e]=function(i,l){if(typeof i!=="number"){return k["outer"+e].call(this,i)}return this.each(function(){a(this).css(h,j(this,i,true,l)+"px")})}});function c(g,e){var j=g.nodeName.toLowerCase();if("area"===j){var i=g.parentNode,h=i.name,f;if(!g.href||!h||i.nodeName.toLowerCase()!=="map"){return false}f=a("img[usemap=#"+h+"]")[0];return !!f&&b(f)}return(/input|select|textarea|button|object/.test(j)?!g.disabled:"a"==j?g.href||e:e)&&b(g)}function b(e){return !a(e).parents().andSelf().filter(function(){return a.curCSS(this,"visibility")==="hidden"||a.expr.filters.hidden(this)}).length}a.extend(a.expr[":"],{data:function(g,f,e){return !!a.data(g,e[3])},focusable:function(e){return c(e,!isNaN(a.attr(e,"tabindex")))},tabbable:function(g){var e=a.attr(g,"tabindex"),f=isNaN(e);return(f||e>=0)&&c(g,!f)}});a(function(){var e=document.body,f=e.appendChild(f=document.createElement("div"));f.offsetHeight;a.extend(f.style,{minHeight:"100px",height:"auto",padding:0,borderWidth:0});a.support.minHeight=f.offsetHeight===100;a.support.selectstart="onselectstart" in f;e.removeChild(f).style.display="none"});a.extend(a.ui,{plugin:{add:function(f,g,j){var h=a.ui[f].prototype;for(var e in j){h.plugins[e]=h.plugins[e]||[];h.plugins[e].push([g,j[e]])}},call:function(e,g,f){var j=e.plugins[g];if(!j||!e.element[0].parentNode){return}for(var h=0;h0){return true}h[e]=1;g=(h[e]>0);h[e]=0;return g},isOverAxis:function(f,e,g){return(f>e)&&(f<(e+g))},isOver:function(j,f,i,h,e,g){return a.ui.isOverAxis(j,i,e)&&a.ui.isOverAxis(f,h,g)}})})(jQuery);/*! + * jQuery UI Widget 1.8.18 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Widget + */ +(function(b,d){if(b.cleanData){var c=b.cleanData;b.cleanData=function(f){for(var g=0,h;(h=f[g])!=null;g++){try{b(h).triggerHandler("remove")}catch(j){}}c(f)}}else{var a=b.fn.remove;b.fn.remove=function(e,f){return this.each(function(){if(!f){if(!e||b.filter(e,[this]).length){b("*",this).add([this]).each(function(){try{b(this).triggerHandler("remove")}catch(g){}})}}return a.call(b(this),e,f)})}}b.widget=function(f,h,e){var g=f.split(".")[0],j;f=f.split(".")[1];j=g+"-"+f;if(!e){e=h;h=b.Widget}b.expr[":"][j]=function(k){return !!b.data(k,f)};b[g]=b[g]||{};b[g][f]=function(k,l){if(arguments.length){this._createWidget(k,l)}};var i=new h();i.options=b.extend(true,{},i.options);b[g][f].prototype=b.extend(true,i,{namespace:g,widgetName:f,widgetEventPrefix:b[g][f].prototype.widgetEventPrefix||f,widgetBaseClass:j},e);b.widget.bridge(f,b[g][f])};b.widget.bridge=function(f,e){b.fn[f]=function(i){var g=typeof i==="string",h=Array.prototype.slice.call(arguments,1),j=this;i=!g&&h.length?b.extend.apply(null,[true,i].concat(h)):i;if(g&&i.charAt(0)==="_"){return j}if(g){this.each(function(){var k=b.data(this,f),l=k&&b.isFunction(k[i])?k[i].apply(k,h):k;if(l!==k&&l!==d){j=l;return false}})}else{this.each(function(){var k=b.data(this,f);if(k){k.option(i||{})._init()}else{b.data(this,f,new e(i,this))}})}return j}};b.Widget=function(e,f){if(arguments.length){this._createWidget(e,f)}};b.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",options:{disabled:false},_createWidget:function(f,g){b.data(g,this.widgetName,this);this.element=b(g);this.options=b.extend(true,{},this.options,this._getCreateOptions(),f);var e=this;this.element.bind("remove."+this.widgetName,function(){e.destroy()});this._create();this._trigger("create");this._init()},_getCreateOptions:function(){return b.metadata&&b.metadata.get(this.element[0])[this.widgetName]},_create:function(){},_init:function(){},destroy:function(){this.element.unbind("."+this.widgetName).removeData(this.widgetName);this.widget().unbind("."+this.widgetName).removeAttr("aria-disabled").removeClass(this.widgetBaseClass+"-disabled ui-state-disabled")},widget:function(){return this.element},option:function(f,g){var e=f;if(arguments.length===0){return b.extend({},this.options)}if(typeof f==="string"){if(g===d){return this.options[f]}e={};e[f]=g}this._setOptions(e);return this},_setOptions:function(f){var e=this;b.each(f,function(g,h){e._setOption(g,h)});return this},_setOption:function(e,f){this.options[e]=f;if(e==="disabled"){this.widget()[f?"addClass":"removeClass"](this.widgetBaseClass+"-disabled ui-state-disabled").attr("aria-disabled",f)}return this},enable:function(){return this._setOption("disabled",false)},disable:function(){return this._setOption("disabled",true)},_trigger:function(e,f,g){var j,i,h=this.options[e];g=g||{};f=b.Event(f);f.type=(e===this.widgetEventPrefix?e:this.widgetEventPrefix+e).toLowerCase();f.target=this.element[0];i=f.originalEvent;if(i){for(j in i){if(!(j in f)){f[j]=i[j]}}}this.element.trigger(f,g);return !(b.isFunction(h)&&h.call(this.element[0],f,g)===false||f.isDefaultPrevented())}}})(jQuery);/*! + * jQuery UI Mouse 1.8.18 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Mouse + * + * Depends: + * jquery.ui.widget.js + */ +(function(b,c){var a=false;b(document).mouseup(function(d){a=false});b.widget("ui.mouse",{options:{cancel:":input,option",distance:1,delay:0},_mouseInit:function(){var d=this;this.element.bind("mousedown."+this.widgetName,function(e){return d._mouseDown(e)}).bind("click."+this.widgetName,function(e){if(true===b.data(e.target,d.widgetName+".preventClickEvent")){b.removeData(e.target,d.widgetName+".preventClickEvent");e.stopImmediatePropagation();return false}});this.started=false},_mouseDestroy:function(){this.element.unbind("."+this.widgetName)},_mouseDown:function(f){if(a){return}(this._mouseStarted&&this._mouseUp(f));this._mouseDownEvent=f;var e=this,g=(f.which==1),d=(typeof this.options.cancel=="string"&&f.target.nodeName?b(f.target).closest(this.options.cancel).length:false);if(!g||d||!this._mouseCapture(f)){return true}this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet){this._mouseDelayTimer=setTimeout(function(){e.mouseDelayMet=true},this.options.delay)}if(this._mouseDistanceMet(f)&&this._mouseDelayMet(f)){this._mouseStarted=(this._mouseStart(f)!==false);if(!this._mouseStarted){f.preventDefault();return true}}if(true===b.data(f.target,this.widgetName+".preventClickEvent")){b.removeData(f.target,this.widgetName+".preventClickEvent")}this._mouseMoveDelegate=function(h){return e._mouseMove(h)};this._mouseUpDelegate=function(h){return e._mouseUp(h)};b(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);f.preventDefault();a=true;return true},_mouseMove:function(d){if(b.browser.msie&&!(document.documentMode>=9)&&!d.button){return this._mouseUp(d)}if(this._mouseStarted){this._mouseDrag(d);return d.preventDefault()}if(this._mouseDistanceMet(d)&&this._mouseDelayMet(d)){this._mouseStarted=(this._mouseStart(this._mouseDownEvent,d)!==false);(this._mouseStarted?this._mouseDrag(d):this._mouseUp(d))}return !this._mouseStarted},_mouseUp:function(d){b(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;if(d.target==this._mouseDownEvent.target){b.data(d.target,this.widgetName+".preventClickEvent",true)}this._mouseStop(d)}return false},_mouseDistanceMet:function(d){return(Math.max(Math.abs(this._mouseDownEvent.pageX-d.pageX),Math.abs(this._mouseDownEvent.pageY-d.pageY))>=this.options.distance)},_mouseDelayMet:function(d){return this.mouseDelayMet},_mouseStart:function(d){},_mouseDrag:function(d){},_mouseStop:function(d){},_mouseCapture:function(d){return true}})})(jQuery);(function(c,d){c.widget("ui.resizable",c.ui.mouse,{widgetEventPrefix:"resize",options:{alsoResize:false,animate:false,animateDuration:"slow",animateEasing:"swing",aspectRatio:false,autoHide:false,containment:false,ghost:false,grid:false,handles:"e,s,se",helper:false,maxHeight:null,maxWidth:null,minHeight:10,minWidth:10,zIndex:1000},_create:function(){var f=this,k=this.options;this.element.addClass("ui-resizable");c.extend(this,{_aspectRatio:!!(k.aspectRatio),aspectRatio:k.aspectRatio,originalElement:this.element,_proportionallyResizeElements:[],_helper:k.helper||k.ghost||k.animate?k.helper||"ui-resizable-helper":null});if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)){this.element.wrap(c('
').css({position:this.element.css("position"),width:this.element.outerWidth(),height:this.element.outerHeight(),top:this.element.css("top"),left:this.element.css("left")}));this.element=this.element.parent().data("resizable",this.element.data("resizable"));this.elementIsWrapper=true;this.element.css({marginLeft:this.originalElement.css("marginLeft"),marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom")});this.originalElement.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0});this.originalResizeStyle=this.originalElement.css("resize");this.originalElement.css("resize","none");this._proportionallyResizeElements.push(this.originalElement.css({position:"static",zoom:1,display:"block"}));this.originalElement.css({margin:this.originalElement.css("margin")});this._proportionallyResize()}this.handles=k.handles||(!c(".ui-resizable-handle",this.element).length?"e,s,se":{n:".ui-resizable-n",e:".ui-resizable-e",s:".ui-resizable-s",w:".ui-resizable-w",se:".ui-resizable-se",sw:".ui-resizable-sw",ne:".ui-resizable-ne",nw:".ui-resizable-nw"});if(this.handles.constructor==String){if(this.handles=="all"){this.handles="n,e,s,w,se,sw,ne,nw"}var l=this.handles.split(",");this.handles={};for(var g=0;g
');if(/sw|se|ne|nw/.test(j)){h.css({zIndex:++k.zIndex})}if("se"==j){h.addClass("ui-icon ui-icon-gripsmall-diagonal-se")}this.handles[j]=".ui-resizable-"+j;this.element.append(h)}}this._renderAxis=function(q){q=q||this.element;for(var n in this.handles){if(this.handles[n].constructor==String){this.handles[n]=c(this.handles[n],this.element).show()}if(this.elementIsWrapper&&this.originalElement[0].nodeName.match(/textarea|input|select|button/i)){var o=c(this.handles[n],this.element),p=0;p=/sw|ne|nw|se|n|s/.test(n)?o.outerHeight():o.outerWidth();var m=["padding",/ne|nw|n/.test(n)?"Top":/se|sw|s/.test(n)?"Bottom":/^e$/.test(n)?"Right":"Left"].join("");q.css(m,p);this._proportionallyResize()}if(!c(this.handles[n]).length){continue}}};this._renderAxis(this.element);this._handles=c(".ui-resizable-handle",this.element).disableSelection();this._handles.mouseover(function(){if(!f.resizing){if(this.className){var i=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i)}f.axis=i&&i[1]?i[1]:"se"}});if(k.autoHide){this._handles.hide();c(this.element).addClass("ui-resizable-autohide").hover(function(){if(k.disabled){return}c(this).removeClass("ui-resizable-autohide");f._handles.show()},function(){if(k.disabled){return}if(!f.resizing){c(this).addClass("ui-resizable-autohide");f._handles.hide()}})}this._mouseInit()},destroy:function(){this._mouseDestroy();var e=function(g){c(g).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing").removeData("resizable").unbind(".resizable").find(".ui-resizable-handle").remove()};if(this.elementIsWrapper){e(this.element);var f=this.element;f.after(this.originalElement.css({position:f.css("position"),width:f.outerWidth(),height:f.outerHeight(),top:f.css("top"),left:f.css("left")})).remove()}this.originalElement.css("resize",this.originalResizeStyle);e(this.originalElement);return this},_mouseCapture:function(f){var g=false;for(var e in this.handles){if(c(this.handles[e])[0]==f.target){g=true}}return !this.options.disabled&&g},_mouseStart:function(g){var j=this.options,f=this.element.position(),e=this.element;this.resizing=true;this.documentScroll={top:c(document).scrollTop(),left:c(document).scrollLeft()};if(e.is(".ui-draggable")||(/absolute/).test(e.css("position"))){e.css({position:"absolute",top:f.top,left:f.left})}this._renderProxy();var k=b(this.helper.css("left")),h=b(this.helper.css("top"));if(j.containment){k+=c(j.containment).scrollLeft()||0;h+=c(j.containment).scrollTop()||0}this.offset=this.helper.offset();this.position={left:k,top:h};this.size=this._helper?{width:e.outerWidth(),height:e.outerHeight()}:{width:e.width(),height:e.height()};this.originalSize=this._helper?{width:e.outerWidth(),height:e.outerHeight()}:{width:e.width(),height:e.height()};this.originalPosition={left:k,top:h};this.sizeDiff={width:e.outerWidth()-e.width(),height:e.outerHeight()-e.height()};this.originalMousePosition={left:g.pageX,top:g.pageY};this.aspectRatio=(typeof j.aspectRatio=="number")?j.aspectRatio:((this.originalSize.width/this.originalSize.height)||1);var i=c(".ui-resizable-"+this.axis).css("cursor");c("body").css("cursor",i=="auto"?this.axis+"-resize":i);e.addClass("ui-resizable-resizing");this._propagate("start",g);return true},_mouseDrag:function(e){var h=this.helper,g=this.options,m={},q=this,j=this.originalMousePosition,n=this.axis;var r=(e.pageX-j.left)||0,p=(e.pageY-j.top)||0;var i=this._change[n];if(!i){return false}var l=i.apply(this,[e,r,p]),k=c.browser.msie&&c.browser.version<7,f=this.sizeDiff;this._updateVirtualBoundaries(e.shiftKey);if(this._aspectRatio||e.shiftKey){l=this._updateRatio(l,e)}l=this._respectSize(l,e);this._propagate("resize",e);h.css({top:this.position.top+"px",left:this.position.left+"px",width:this.size.width+"px",height:this.size.height+"px"});if(!this._helper&&this._proportionallyResizeElements.length){this._proportionallyResize()}this._updateCache(l);this._trigger("resize",e,this.ui());return false},_mouseStop:function(h){this.resizing=false;var i=this.options,m=this;if(this._helper){var g=this._proportionallyResizeElements,e=g.length&&(/textarea/i).test(g[0].nodeName),f=e&&c.ui.hasScroll(g[0],"left")?0:m.sizeDiff.height,k=e?0:m.sizeDiff.width;var n={width:(m.helper.width()-k),height:(m.helper.height()-f)},j=(parseInt(m.element.css("left"),10)+(m.position.left-m.originalPosition.left))||null,l=(parseInt(m.element.css("top"),10)+(m.position.top-m.originalPosition.top))||null;if(!i.animate){this.element.css(c.extend(n,{top:l,left:j}))}m.helper.height(m.size.height);m.helper.width(m.size.width);if(this._helper&&!i.animate){this._proportionallyResize()}}c("body").css("cursor","auto");this.element.removeClass("ui-resizable-resizing");this._propagate("stop",h);if(this._helper){this.helper.remove()}return false},_updateVirtualBoundaries:function(g){var j=this.options,i,h,f,k,e;e={minWidth:a(j.minWidth)?j.minWidth:0,maxWidth:a(j.maxWidth)?j.maxWidth:Infinity,minHeight:a(j.minHeight)?j.minHeight:0,maxHeight:a(j.maxHeight)?j.maxHeight:Infinity};if(this._aspectRatio||g){i=e.minHeight*this.aspectRatio;f=e.minWidth/this.aspectRatio;h=e.maxHeight*this.aspectRatio;k=e.maxWidth/this.aspectRatio;if(i>e.minWidth){e.minWidth=i}if(f>e.minHeight){e.minHeight=f}if(hl.width),s=a(l.height)&&i.minHeight&&(i.minHeight>l.height);if(h){l.width=i.minWidth}if(s){l.height=i.minHeight}if(t){l.width=i.maxWidth}if(m){l.height=i.maxHeight}var f=this.originalPosition.left+this.originalSize.width,p=this.position.top+this.size.height;var k=/sw|nw|w/.test(q),e=/nw|ne|n/.test(q);if(h&&k){l.left=f-i.minWidth}if(t&&k){l.left=f-i.maxWidth}if(s&&e){l.top=p-i.minHeight}if(m&&e){l.top=p-i.maxHeight}var n=!l.width&&!l.height;if(n&&!l.left&&l.top){l.top=null}else{if(n&&!l.top&&l.left){l.left=null}}return l},_proportionallyResize:function(){var k=this.options;if(!this._proportionallyResizeElements.length){return}var g=this.helper||this.element;for(var f=0;f');var e=c.browser.msie&&c.browser.version<7,g=(e?1:0),h=(e?2:-1);this.helper.addClass(this._helper).css({width:this.element.outerWidth()+h,height:this.element.outerHeight()+h,position:"absolute",left:this.elementOffset.left-g+"px",top:this.elementOffset.top-g+"px",zIndex:++i.zIndex});this.helper.appendTo("body").disableSelection()}else{this.helper=this.element}},_change:{e:function(g,f,e){return{width:this.originalSize.width+f}},w:function(h,f,e){var j=this.options,g=this.originalSize,i=this.originalPosition;return{left:i.left+f,width:g.width-f}},n:function(h,f,e){var j=this.options,g=this.originalSize,i=this.originalPosition;return{top:i.top+e,height:g.height-e}},s:function(g,f,e){return{height:this.originalSize.height+e}},se:function(g,f,e){return c.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[g,f,e]))},sw:function(g,f,e){return c.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[g,f,e]))},ne:function(g,f,e){return c.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[g,f,e]))},nw:function(g,f,e){return c.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[g,f,e]))}},_propagate:function(f,e){c.ui.plugin.call(this,f,[e,this.ui()]);(f!="resize"&&this._trigger(f,e,this.ui()))},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}});c.extend(c.ui.resizable,{version:"1.8.18"});c.ui.plugin.add("resizable","alsoResize",{start:function(f,g){var e=c(this).data("resizable"),i=e.options;var h=function(j){c(j).each(function(){var k=c(this);k.data("resizable-alsoresize",{width:parseInt(k.width(),10),height:parseInt(k.height(),10),left:parseInt(k.css("left"),10),top:parseInt(k.css("top"),10)})})};if(typeof(i.alsoResize)=="object"&&!i.alsoResize.parentNode){if(i.alsoResize.length){i.alsoResize=i.alsoResize[0];h(i.alsoResize)}else{c.each(i.alsoResize,function(j){h(j)})}}else{h(i.alsoResize)}},resize:function(g,i){var f=c(this).data("resizable"),j=f.options,h=f.originalSize,l=f.originalPosition;var k={height:(f.size.height-h.height)||0,width:(f.size.width-h.width)||0,top:(f.position.top-l.top)||0,left:(f.position.left-l.left)||0},e=function(m,n){c(m).each(function(){var q=c(this),r=c(this).data("resizable-alsoresize"),p={},o=n&&n.length?n:q.parents(i.originalElement[0]).length?["width","height"]:["width","height","top","left"];c.each(o,function(s,u){var t=(r[u]||0)+(k[u]||0);if(t&&t>=0){p[u]=t||null}});q.css(p)})};if(typeof(j.alsoResize)=="object"&&!j.alsoResize.nodeType){c.each(j.alsoResize,function(m,n){e(m,n)})}else{e(j.alsoResize)}},stop:function(e,f){c(this).removeData("resizable-alsoresize")}});c.ui.plugin.add("resizable","animate",{stop:function(i,n){var p=c(this).data("resizable"),j=p.options;var h=p._proportionallyResizeElements,e=h.length&&(/textarea/i).test(h[0].nodeName),f=e&&c.ui.hasScroll(h[0],"left")?0:p.sizeDiff.height,l=e?0:p.sizeDiff.width;var g={width:(p.size.width-l),height:(p.size.height-f)},k=(parseInt(p.element.css("left"),10)+(p.position.left-p.originalPosition.left))||null,m=(parseInt(p.element.css("top"),10)+(p.position.top-p.originalPosition.top))||null;p.element.animate(c.extend(g,m&&k?{top:m,left:k}:{}),{duration:j.animateDuration,easing:j.animateEasing,step:function(){var o={width:parseInt(p.element.css("width"),10),height:parseInt(p.element.css("height"),10),top:parseInt(p.element.css("top"),10),left:parseInt(p.element.css("left"),10)};if(h&&h.length){c(h[0]).css({width:o.width,height:o.height})}p._updateCache(o);p._propagate("resize",i)}})}});c.ui.plugin.add("resizable","containment",{start:function(f,r){var t=c(this).data("resizable"),j=t.options,l=t.element;var g=j.containment,k=(g instanceof c)?g.get(0):(/parent/.test(g))?l.parent().get(0):g;if(!k){return}t.containerElement=c(k);if(/document/.test(g)||g==document){t.containerOffset={left:0,top:0};t.containerPosition={left:0,top:0};t.parentData={element:c(document),left:0,top:0,width:c(document).width(),height:c(document).height()||document.body.parentNode.scrollHeight}}else{var n=c(k),i=[];c(["Top","Right","Left","Bottom"]).each(function(p,o){i[p]=b(n.css("padding"+o))});t.containerOffset=n.offset();t.containerPosition=n.position();t.containerSize={height:(n.innerHeight()-i[3]),width:(n.innerWidth()-i[1])};var q=t.containerOffset,e=t.containerSize.height,m=t.containerSize.width,h=(c.ui.hasScroll(k,"left")?k.scrollWidth:m),s=(c.ui.hasScroll(k)?k.scrollHeight:e);t.parentData={element:k,left:q.left,top:q.top,width:h,height:s}}},resize:function(g,q){var t=c(this).data("resizable"),i=t.options,f=t.containerSize,p=t.containerOffset,m=t.size,n=t.position,r=t._aspectRatio||g.shiftKey,e={top:0,left:0},h=t.containerElement;if(h[0]!=document&&(/static/).test(h.css("position"))){e=p}if(n.left<(t._helper?p.left:0)){t.size.width=t.size.width+(t._helper?(t.position.left-p.left):(t.position.left-e.left));if(r){t.size.height=t.size.width/i.aspectRatio}t.position.left=i.helper?p.left:0}if(n.top<(t._helper?p.top:0)){t.size.height=t.size.height+(t._helper?(t.position.top-p.top):t.position.top);if(r){t.size.width=t.size.height*i.aspectRatio}t.position.top=t._helper?p.top:0}t.offset.left=t.parentData.left+t.position.left;t.offset.top=t.parentData.top+t.position.top;var l=Math.abs((t._helper?t.offset.left-e.left:(t.offset.left-e.left))+t.sizeDiff.width),s=Math.abs((t._helper?t.offset.top-e.top:(t.offset.top-p.top))+t.sizeDiff.height);var k=t.containerElement.get(0)==t.element.parent().get(0),j=/relative|absolute/.test(t.containerElement.css("position"));if(k&&j){l-=t.parentData.left}if(l+t.size.width>=t.parentData.width){t.size.width=t.parentData.width-l;if(r){t.size.height=t.size.width/t.aspectRatio}}if(s+t.size.height>=t.parentData.height){t.size.height=t.parentData.height-s;if(r){t.size.width=t.size.height*t.aspectRatio}}},stop:function(f,n){var q=c(this).data("resizable"),g=q.options,l=q.position,m=q.containerOffset,e=q.containerPosition,i=q.containerElement;var j=c(q.helper),r=j.offset(),p=j.outerWidth()-q.sizeDiff.width,k=j.outerHeight()-q.sizeDiff.height;if(q._helper&&!g.animate&&(/relative/).test(i.css("position"))){c(this).css({left:r.left-e.left-m.left,width:p,height:k})}if(q._helper&&!g.animate&&(/static/).test(i.css("position"))){c(this).css({left:r.left-e.left-m.left,width:p,height:k})}}});c.ui.plugin.add("resizable","ghost",{start:function(g,h){var e=c(this).data("resizable"),i=e.options,f=e.size;e.ghost=e.originalElement.clone();e.ghost.css({opacity:0.25,display:"block",position:"relative",height:f.height,width:f.width,margin:0,left:0,top:0}).addClass("ui-resizable-ghost").addClass(typeof i.ghost=="string"?i.ghost:"");e.ghost.appendTo(e.helper)},resize:function(f,g){var e=c(this).data("resizable"),h=e.options;if(e.ghost){e.ghost.css({position:"relative",height:e.size.height,width:e.size.width})}},stop:function(f,g){var e=c(this).data("resizable"),h=e.options;if(e.ghost&&e.helper){e.helper.get(0).removeChild(e.ghost.get(0))}}});c.ui.plugin.add("resizable","grid",{resize:function(e,m){var p=c(this).data("resizable"),h=p.options,k=p.size,i=p.originalSize,j=p.originalPosition,n=p.axis,l=h._aspectRatio||e.shiftKey;h.grid=typeof h.grid=="number"?[h.grid,h.grid]:h.grid;var g=Math.round((k.width-i.width)/(h.grid[0]||1))*(h.grid[0]||1),f=Math.round((k.height-i.height)/(h.grid[1]||1))*(h.grid[1]||1);if(/^(se|s|e)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f}else{if(/^(ne)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f;p.position.top=j.top-f}else{if(/^(sw)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f;p.position.left=j.left-g}else{p.size.width=i.width+g;p.size.height=i.height+f;p.position.top=j.top-f;p.position.left=j.left-g}}}}});var b=function(e){return parseInt(e,10)||0};var a=function(e){return !isNaN(parseInt(e,10))}})(jQuery);/*! + * jQuery hashchange event - v1.3 - 7/21/2010 + * http://benalman.com/projects/jquery-hashchange-plugin/ + * + * Copyright (c) 2010 "Cowboy" Ben Alman + * Dual licensed under the MIT and GPL licenses. + * http://benalman.com/about/license/ + */ +(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$(' + + + +
+ +
+
misc.c File Reference
+
+
+
#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include "RNAcode.h"
+#include "misc.h"
+#include "postscript.h"
+
+Include dependency graph for misc.c:
+
+
+ + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

float **** allocateSk (int N, int L)
 
void copySk (float ****from, float ****to, int N, int L)
 
int compareScores (const void *a, const void *b)
 
int compareLocation (const void *a, const void *b)
 
void reintroduceGaps (const struct aln *origAln[], struct aln *sampledAln[])
 
void sortAln (const struct aln *origAln[], struct aln *sampledAln[])
 
void getBlock (int i, const char *seq_0, const char *seq_k, const int *map_0, const int *map_k, char *block_0, char *block_k, int *z)
 
int pos2col (const char *seq, int pos)
 
int getSeqLength (char *seq)
 
void freeResults (segmentStats results[])
 
int hDist (int a1, int a2, int a3, int b1, int b2, int b3)
 
float avg (float *data, int N)
 
float stddev (float *data, int N)
 
void copyAln (struct aln *src[], struct aln *dest[])
 
void printAlnClustal (FILE *out, const struct aln *AS[])
 
void printResults (FILE *outfile, int outputFormat, const struct aln *inputAln[], segmentStats results[])
 
int extendRegion (const struct aln *alignment[], int pos, int direction)
 
+ + + + + +

+Variables

parameters pars
 
long int hitCounter
 
+

Function Documentation

+ +

◆ allocateSk()

+ +
+
+ + + + + + + + + + + + + + + + + + +
float**** allocateSk (int N,
int L 
)
+
+ +
+
+ +

◆ avg()

+ +
+
+ + + + + + + + + + + + + + + + + + +
float avg (float * data,
int N 
)
+
+ +
+
+ +

◆ compareLocation()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int compareLocation (const void * a,
const void * b 
)
+
+ +
+
+ +

◆ compareScores()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int compareScores (const void * a,
const void * b 
)
+
+ +
+
+ +

◆ copyAln()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void copyAln (struct alnsrc[],
struct alndest[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ copySk()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void copySk (float **** from,
float **** to,
int N,
int L 
)
+
+ +
+
+ +

◆ extendRegion()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int extendRegion (const struct alnalignment[],
int pos,
int direction 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ freeResults()

+ +
+
+ + + + + + + + +
void freeResults (segmentStats results[])
+
+ +
+
+ +

◆ getBlock()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void getBlock (int i,
const char * seq_0,
const char * seq_k,
const int * map_0,
const int * map_k,
char * block_0,
char * block_k,
int * z 
)
+
+ +
+
+ +

◆ getSeqLength()

+ +
+
+ + + + + + + + +
int getSeqLength (char * seq)
+
+ +
+
+ +

◆ hDist()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int hDist (int a1,
int a2,
int a3,
int b1,
int b2,
int b3 
)
+
+ +
+
+ +

◆ pos2col()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int pos2col (const char * seq,
int pos 
)
+
+ +
+
+ +

◆ printAlnClustal()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void printAlnClustal (FILE * out,
const struct alnAS[] 
)
+
+ +
+
+ +

◆ printResults()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void printResults (FILE * outfile,
int outputFormat,
const struct alninputAln[],
segmentStats results[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ reintroduceGaps()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void reintroduceGaps (const struct alnorigAln[],
struct alnsampledAln[] 
)
+
+ +
+
+ +

◆ sortAln()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void sortAln (const struct alnorigAln[],
struct alnsampledAln[] 
)
+
+ +
+
+ +

◆ stddev()

+ +
+
+ + + + + + + + + + + + + + + + + + +
float stddev (float * data,
int N 
)
+
+ +
+
+

Variable Documentation

+ +

◆ hitCounter

+ +
+
+ + + + +
long int hitCounter
+
+ +
+
+ +

◆ pars

+ +
+
+ + + + +
parameters pars
+
+ +
+
+ + + + + diff --git a/src/html/misc_8c__incl.map b/src/html/misc_8c__incl.map new file mode 100644 index 0000000..6b9e17d --- /dev/null +++ b/src/html/misc_8c__incl.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/html/misc_8c__incl.md5 b/src/html/misc_8c__incl.md5 new file mode 100644 index 0000000..c1ece31 --- /dev/null +++ b/src/html/misc_8c__incl.md5 @@ -0,0 +1 @@ +3833e65ae407dab1dbddc36229fa4afd \ No newline at end of file diff --git a/src/html/misc_8c__incl.png b/src/html/misc_8c__incl.png new file mode 100644 index 0000000..3987c1f Binary files /dev/null and b/src/html/misc_8c__incl.png differ diff --git a/src/html/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.map b/src/html/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.map new file mode 100644 index 0000000..7c94d8d --- /dev/null +++ b/src/html/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 b/src/html/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 new file mode 100644 index 0000000..b222b9b --- /dev/null +++ b/src/html/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 @@ -0,0 +1 @@ +53827c3e01767867abef7f66c41397f9 \ No newline at end of file diff --git a/src/html/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.png b/src/html/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.png new file mode 100644 index 0000000..365c6d8 Binary files /dev/null and b/src/html/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.png differ diff --git a/src/html/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.map b/src/html/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.map new file mode 100644 index 0000000..fd04901 --- /dev/null +++ b/src/html/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.map @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/html/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.md5 b/src/html/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.md5 new file mode 100644 index 0000000..071f7f3 --- /dev/null +++ b/src/html/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.md5 @@ -0,0 +1 @@ +dd8c5415863f43fd96134f3c6566757d \ No newline at end of file diff --git a/src/html/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.png b/src/html/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.png new file mode 100644 index 0000000..c3fe520 Binary files /dev/null and b/src/html/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.png differ diff --git a/src/html/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.map b/src/html/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.map new file mode 100644 index 0000000..86157a4 --- /dev/null +++ b/src/html/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 b/src/html/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 new file mode 100644 index 0000000..dd6d85b --- /dev/null +++ b/src/html/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 @@ -0,0 +1 @@ +1d7a193848ef1a7e900dd15c97762b57 \ No newline at end of file diff --git a/src/html/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.png b/src/html/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.png new file mode 100644 index 0000000..9245137 Binary files /dev/null and b/src/html/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.png differ diff --git a/src/html/misc_8h.html b/src/html/misc_8h.html new file mode 100644 index 0000000..9e467d9 --- /dev/null +++ b/src/html/misc_8h.html @@ -0,0 +1,725 @@ + + + + + + + +My Project: misc.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
misc.h File Reference
+
+
+
#include "score.h"
+#include "code.h"
+#include "rnaz_utils.h"
+
+Include dependency graph for misc.h:
+
+
+ + + + + + +
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + + + +
+
+

Go to the source code of this file.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

float **** allocateSk (int N, int L)
 
void copySk (float ****from, float ****to, int N, int L)
 
int compareScores (const void *a, const void *b)
 
void reintroduceGaps (const struct aln *origAln[], struct aln *sampledAln[])
 
void sortAln (const struct aln *origAln[], struct aln *sampledAln[])
 
void freeResults (segmentStats results[])
 
void getBlock (int i, const char *seq_0, const char *seq_k, const int *map_0, const int *map_k, char *block_0, char *block_k, int *z)
 
int pos2col (const char *seq, int pos)
 
int getSeqLength (char *seq)
 
int hDist (int a1, int a2, int a3, int b1, int b2, int b3)
 
float avg (float *data, int N)
 
float stddev (float *data, int N)
 
float gaussian (const float sigma)
 
void copyAln (struct aln *src[], struct aln *dest[])
 
void printAlnClustal (FILE *out, const struct aln *AS[])
 
void printResults (FILE *outfile, int outputFormat, const struct aln *AS[], segmentStats results[])
 
int extendRegion (const struct aln *alignment[], int pos, int direction)
 
+

Function Documentation

+ +

◆ allocateSk()

+ +
+
+ + + + + + + + + + + + + + + + + + +
float**** allocateSk (int N,
int L 
)
+
+ +
+
+ +

◆ avg()

+ +
+
+ + + + + + + + + + + + + + + + + + +
float avg (float * data,
int N 
)
+
+ +
+
+ +

◆ compareScores()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int compareScores (const void * a,
const void * b 
)
+
+ +
+
+ +

◆ copyAln()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void copyAln (struct alnsrc[],
struct alndest[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ copySk()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void copySk (float **** from,
float **** to,
int N,
int L 
)
+
+ +
+
+ +

◆ extendRegion()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int extendRegion (const struct alnalignment[],
int pos,
int direction 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ freeResults()

+ +
+
+ + + + + + + + +
void freeResults (segmentStats results[])
+
+ +
+
+ +

◆ gaussian()

+ +
+
+ + + + + + + + +
float gaussian (const float sigma)
+
+ +
+
+ +

◆ getBlock()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void getBlock (int i,
const char * seq_0,
const char * seq_k,
const int * map_0,
const int * map_k,
char * block_0,
char * block_k,
int * z 
)
+
+ +
+
+ +

◆ getSeqLength()

+ +
+
+ + + + + + + + +
int getSeqLength (char * seq)
+
+ +
+
+ +

◆ hDist()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int hDist (int a1,
int a2,
int a3,
int b1,
int b2,
int b3 
)
+
+ +
+
+ +

◆ pos2col()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int pos2col (const char * seq,
int pos 
)
+
+ +
+
+ +

◆ printAlnClustal()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void printAlnClustal (FILE * out,
const struct alnAS[] 
)
+
+ +
+
+ +

◆ printResults()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void printResults (FILE * outfile,
int outputFormat,
const struct alnAS[],
segmentStats results[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ reintroduceGaps()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void reintroduceGaps (const struct alnorigAln[],
struct alnsampledAln[] 
)
+
+ +
+
+ +

◆ sortAln()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void sortAln (const struct alnorigAln[],
struct alnsampledAln[] 
)
+
+ +
+
+ +

◆ stddev()

+ +
+
+ + + + + + + + + + + + + + + + + + +
float stddev (float * data,
int N 
)
+
+ +
+
+
+ + + + diff --git a/src/html/misc_8h__dep__incl.map b/src/html/misc_8h__dep__incl.map new file mode 100644 index 0000000..1025671 --- /dev/null +++ b/src/html/misc_8h__dep__incl.map @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/html/misc_8h__dep__incl.md5 b/src/html/misc_8h__dep__incl.md5 new file mode 100644 index 0000000..56548e0 --- /dev/null +++ b/src/html/misc_8h__dep__incl.md5 @@ -0,0 +1 @@ +b4df8f0b105f1bc426e5f6392493da15 \ No newline at end of file diff --git a/src/html/misc_8h__dep__incl.png b/src/html/misc_8h__dep__incl.png new file mode 100644 index 0000000..a3a4681 Binary files /dev/null and b/src/html/misc_8h__dep__incl.png differ diff --git a/src/html/misc_8h__incl.map b/src/html/misc_8h__incl.map new file mode 100644 index 0000000..995dbf4 --- /dev/null +++ b/src/html/misc_8h__incl.map @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/html/misc_8h__incl.md5 b/src/html/misc_8h__incl.md5 new file mode 100644 index 0000000..e677c56 --- /dev/null +++ b/src/html/misc_8h__incl.md5 @@ -0,0 +1 @@ +92e28c6527f13c3efabddf31a20d4d9f \ No newline at end of file diff --git a/src/html/misc_8h__incl.png b/src/html/misc_8h__incl.png new file mode 100644 index 0000000..2269888 Binary files /dev/null and b/src/html/misc_8h__incl.png differ diff --git a/src/html/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.map b/src/html/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.map new file mode 100644 index 0000000..7c94d8d --- /dev/null +++ b/src/html/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 b/src/html/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 new file mode 100644 index 0000000..188e3e0 --- /dev/null +++ b/src/html/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 @@ -0,0 +1 @@ +7662643a3b60c13f75a1ff3424095d5e \ No newline at end of file diff --git a/src/html/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.png b/src/html/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.png new file mode 100644 index 0000000..365c6d8 Binary files /dev/null and b/src/html/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.png differ diff --git a/src/html/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.map b/src/html/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.map new file mode 100644 index 0000000..86157a4 --- /dev/null +++ b/src/html/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 b/src/html/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 new file mode 100644 index 0000000..901216b --- /dev/null +++ b/src/html/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 @@ -0,0 +1 @@ +9213db80cd9a75a6c00638521eb4344c \ No newline at end of file diff --git a/src/html/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.png b/src/html/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.png new file mode 100644 index 0000000..9245137 Binary files /dev/null and b/src/html/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.png differ diff --git a/src/html/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.map b/src/html/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.map new file mode 100644 index 0000000..fd04901 --- /dev/null +++ b/src/html/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.map @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/html/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.md5 b/src/html/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.md5 new file mode 100644 index 0000000..071f7f3 --- /dev/null +++ b/src/html/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.md5 @@ -0,0 +1 @@ +dd8c5415863f43fd96134f3c6566757d \ No newline at end of file diff --git a/src/html/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.png b/src/html/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.png new file mode 100644 index 0000000..c3fe520 Binary files /dev/null and b/src/html/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.png differ diff --git a/src/html/misc_8h_source.html b/src/html/misc_8h_source.html new file mode 100644 index 0000000..a770fbc --- /dev/null +++ b/src/html/misc_8h_source.html @@ -0,0 +1,96 @@ + + + + + + + +My Project: misc.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
misc.h
+
+
+Go to the documentation of this file.
1 /* Copyright 2009, Stefan Washietl
2 
3  This file is part of RNAcode.
4 
5  RNAcode is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  RNAcode is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with RNAcode. If not, see <http://www.gnu.org/licenses/>. */
17 
18 #ifndef _MISC_H_
19 #define _MISC_H_
20 
21 #include "score.h"
22 #include "code.h"
23 #include "rnaz_utils.h"
24 
25 float**** allocateSk(int N, int L);
26 void copySk(float**** from, float**** to, int N, int L);
27 
28 int compareScores(const void * a, const void * b);
29 
30 void reintroduceGaps(const struct aln* origAln[], struct aln* sampledAln[]);
31 
32 void sortAln(const struct aln* origAln[], struct aln* sampledAln[]);
33 
34 void freeResults(segmentStats results[]);
35 
36 //void getBlock(const char* seq_0, const char* seq_k, int i, char* block_0, char* block_k, int* z );
37 void getBlock(int i, const char* seq_0, const char* seq_k, const int* map_0, const int* map_k, char* block_0, char* block_k, int* z );
38 
39 int pos2col(const char* seq, int pos);
40 
41 int getSeqLength(char *seq);
42 
43 int hDist(int a1, int a2, int a3, int b1, int b2, int b3);
44 
45 float avg(float* data, int N);
46 
47 float stddev(float* data, int N);
48 
49 float gaussian (const float sigma);
50 
51 void copyAln(struct aln *src[],struct aln *dest[]);
52 
53 void printAlnClustal(FILE *out, const struct aln* AS[]);
54 
55 void printResults(FILE* outfile, int outputFormat, const struct aln* AS[], segmentStats results[]);
56 
57 int extendRegion(const struct aln* alignment[], int pos, int direction);
58 
59 #endif
void printAlnClustal(FILE *out, const struct aln *AS[])
Definition: misc.c:377
+
int hDist(int a1, int a2, int a3, int b1, int b2, int b3)
Definition: misc.c:303
+
Definition: rnaz_utils.h:12
+
int extendRegion(const struct aln *alignment[], int pos, int direction)
Definition: misc.c:555
+
void copySk(float ****from, float ****to, int N, int L)
Definition: misc.c:57
+
void getBlock(int i, const char *seq_0, const char *seq_k, const int *map_0, const int *map_k, char *block_0, char *block_k, int *z)
Definition: misc.c:186
+
void printResults(FILE *outfile, int outputFormat, const struct aln *AS[], segmentStats results[])
Definition: misc.c:392
+
FILE * outfile
Definition: postscript.c:15
+
float **** allocateSk(int N, int L)
Definition: misc.c:33
+
int compareScores(const void *a, const void *b)
Definition: misc.c:84
+ +
Definition: score.h:48
+
float stddev(float *data, int N)
Definition: misc.c:332
+
void reintroduceGaps(const struct aln *origAln[], struct aln *sampledAln[])
Definition: misc.c:127
+
float avg(float *data, int N)
Definition: misc.c:316
+
float gaussian(const float sigma)
+ +
void sortAln(const struct aln *origAln[], struct aln *sampledAln[])
Definition: misc.c:150
+ +
int getSeqLength(char *seq)
Definition: misc.c:272
+
void copyAln(struct aln *src[], struct aln *dest[])
Definition: misc.c:355
+
int pos2col(const char *seq, int pos)
Definition: misc.c:250
+
void freeResults(segmentStats results[])
Definition: misc.c:292
+
+ + + + diff --git a/src/html/nav_f.png b/src/html/nav_f.png new file mode 100644 index 0000000..72a58a5 Binary files /dev/null and b/src/html/nav_f.png differ diff --git a/src/html/nav_g.png b/src/html/nav_g.png new file mode 100644 index 0000000..2093a23 Binary files /dev/null and b/src/html/nav_g.png differ diff --git a/src/html/nav_h.png b/src/html/nav_h.png new file mode 100644 index 0000000..33389b1 Binary files /dev/null and b/src/html/nav_h.png differ diff --git a/src/html/open.png b/src/html/open.png new file mode 100644 index 0000000..30f75c7 Binary files /dev/null and b/src/html/open.png differ diff --git a/src/html/pages.html b/src/html/pages.html new file mode 100644 index 0000000..ba094bc --- /dev/null +++ b/src/html/pages.html @@ -0,0 +1,78 @@ + + + + + + + +My Project: Related Pages + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
Related Pages
+
+
+
Here is a list of all related documentation pages:
+ + +
 Deprecated List
+
+
+ + + + diff --git a/src/html/postscript_8c.html b/src/html/postscript_8c.html new file mode 100644 index 0000000..f7d0bd2 --- /dev/null +++ b/src/html/postscript_8c.html @@ -0,0 +1,656 @@ + + + + + + + +My Project: postscript.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
postscript.c File Reference
+
+
+
#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "score.h"
+#include "code.h"
+#include "misc.h"
+#include "postscript.h"
+
+Include dependency graph for postscript.c:
+
+
+ + + + + + + + +
+
+ + + + + + + +

+Functions

void setParameters ()
 
int colorAln (const char *filename, const struct aln *alignment[], segmentStats region)
 
void colorHSS (const char *filename, const struct aln *alignment[], backtrackData *bt, const char *label, int b, int i)
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Variables

float fontWidth
 
float fontHeight
 
float imageHeight
 
float imageWidth
 
float tmpColumns
 
int length
 
int maxName
 
int maxNum
 
int currPos
 
int columnWidth
 
float lineStep
 
float blockStep
 
float consStep
 
float ssStep
 
float rulerStep
 
float nameStep
 
float numberStep
 
float maxConsBar
 
float startY
 
float namesX
 
float seqsX
 
float currY
 
FILE * outfile
 
float **** Sk_native
 
float **** Sk_native_rev
 
+

Function Documentation

+ +

◆ colorAln()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int colorAln (const char * filename,
const struct alnalignment[],
segmentStats region 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ colorHSS()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void colorHSS (const char * filename,
const struct alnalignment[],
backtrackDatabt,
const char * label,
int b,
int i 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + +
+ +
+
+ +

◆ setParameters()

+ +
+
+ + + + + + + +
void setParameters ()
+
+ +
+
+

Variable Documentation

+ +

◆ blockStep

+ +
+
+ + + + +
float blockStep
+
+ +
+
+ +

◆ columnWidth

+ +
+
+ + + + +
int columnWidth
+
+ +
+
+ +

◆ consStep

+ +
+
+ + + + +
float consStep
+
+ +
+
+ +

◆ currPos

+ +
+
+ + + + +
int currPos
+
+ +
+
+ +

◆ currY

+ +
+
+ + + + +
float currY
+
+ +
+
+ +

◆ fontHeight

+ +
+
+ + + + +
float fontHeight
+
+ +
+
+ +

◆ fontWidth

+ +
+
+ + + + +
float fontWidth
+
+ +
+
+ +

◆ imageHeight

+ +
+
+ + + + +
float imageHeight
+
+ +
+
+ +

◆ imageWidth

+ +
+
+ + + + +
float imageWidth
+
+ +
+
+ +

◆ length

+ +
+
+ + + + +
int length
+
+ +
+
+ +

◆ lineStep

+ +
+
+ + + + +
float lineStep
+
+ +
+
+ +

◆ maxConsBar

+ +
+
+ + + + +
float maxConsBar
+
+ +
+
+ +

◆ maxName

+ +
+
+ + + + +
int maxName
+
+ +
+
+ +

◆ maxNum

+ +
+
+ + + + +
int maxNum
+
+ +
+
+ +

◆ nameStep

+ +
+
+ + + + +
float nameStep
+
+ +
+
+ +

◆ namesX

+ +
+
+ + + + +
float namesX
+
+ +
+
+ +

◆ numberStep

+ +
+
+ + + + +
float numberStep
+
+ +
+
+ +

◆ outfile

+ +
+
+ + + + +
FILE* outfile
+
+ +
+
+ +

◆ rulerStep

+ +
+
+ + + + +
float rulerStep
+
+ +
+
+ +

◆ seqsX

+ +
+
+ + + + +
float seqsX
+
+ +
+
+ +

◆ Sk_native

+ +
+
+ + + + +
float**** Sk_native
+
+ +
+
+ +

◆ Sk_native_rev

+ +
+
+ + + + +
float**** Sk_native_rev
+
+ +
+
+ +

◆ ssStep

+ +
+
+ + + + +
float ssStep
+
+ +
+
+ +

◆ startY

+ +
+
+ + + + +
float startY
+
+ +
+
+ +

◆ tmpColumns

+ +
+
+ + + + +
float tmpColumns
+
+ +
+
+
+ + + + diff --git a/src/html/postscript_8c__incl.map b/src/html/postscript_8c__incl.map new file mode 100644 index 0000000..f999e46 --- /dev/null +++ b/src/html/postscript_8c__incl.map @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/html/postscript_8c__incl.md5 b/src/html/postscript_8c__incl.md5 new file mode 100644 index 0000000..7685b1c --- /dev/null +++ b/src/html/postscript_8c__incl.md5 @@ -0,0 +1 @@ +faf149df38bb002077a3940e5dc71054 \ No newline at end of file diff --git a/src/html/postscript_8c__incl.png b/src/html/postscript_8c__incl.png new file mode 100644 index 0000000..019733f Binary files /dev/null and b/src/html/postscript_8c__incl.png differ diff --git a/src/html/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.map b/src/html/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.map new file mode 100644 index 0000000..894acd1 --- /dev/null +++ b/src/html/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.map @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/html/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 b/src/html/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 new file mode 100644 index 0000000..4ccfb0d --- /dev/null +++ b/src/html/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 @@ -0,0 +1 @@ +dc4cd78c5be886941f02c5d92ac26303 \ No newline at end of file diff --git a/src/html/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.png b/src/html/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.png new file mode 100644 index 0000000..bfe25dc Binary files /dev/null and b/src/html/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.png differ diff --git a/src/html/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.map b/src/html/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.map new file mode 100644 index 0000000..fb77039 --- /dev/null +++ b/src/html/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.map @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/html/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 b/src/html/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 new file mode 100644 index 0000000..8f8943c --- /dev/null +++ b/src/html/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 @@ -0,0 +1 @@ +64543466fd3c413aa942f172642148a0 \ No newline at end of file diff --git a/src/html/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.png b/src/html/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.png new file mode 100644 index 0000000..87c3991 Binary files /dev/null and b/src/html/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.png differ diff --git a/src/html/postscript_8h.html b/src/html/postscript_8h.html new file mode 100644 index 0000000..b6f3a92 --- /dev/null +++ b/src/html/postscript_8h.html @@ -0,0 +1,253 @@ + + + + + + + +My Project: postscript.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
postscript.h File Reference
+
+
+
#include "rnaz_utils.h"
+#include "code.h"
+
+Include dependency graph for postscript.h:
+
+
+ + + + +
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + + +
+
+

Go to the source code of this file.

+ + + + + + + + +

+Functions

int colorAln (const char *filename, const struct aln *alignment[], segmentStats region)
 
void colorHSS (const char *filename, const struct aln *alignment[], backtrackData *bt, const char *label, int b, int i)
 
void setParameters ()
 
+

Function Documentation

+ +

◆ colorAln()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int colorAln (const char * filename,
const struct alnalignment[],
segmentStats region 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ colorHSS()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void colorHSS (const char * filename,
const struct alnalignment[],
backtrackDatabt,
const char * label,
int b,
int i 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + +
+ +
+
+ +

◆ setParameters()

+ +
+
+ + + + + + + +
void setParameters ()
+
+ +
+
+
+ + + + diff --git a/src/html/postscript_8h__dep__incl.map b/src/html/postscript_8h__dep__incl.map new file mode 100644 index 0000000..25abb82 --- /dev/null +++ b/src/html/postscript_8h__dep__incl.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/postscript_8h__dep__incl.md5 b/src/html/postscript_8h__dep__incl.md5 new file mode 100644 index 0000000..729a1c9 --- /dev/null +++ b/src/html/postscript_8h__dep__incl.md5 @@ -0,0 +1 @@ +c523aaa10bd3724609800fe50f0aed34 \ No newline at end of file diff --git a/src/html/postscript_8h__dep__incl.png b/src/html/postscript_8h__dep__incl.png new file mode 100644 index 0000000..1f1c2f8 Binary files /dev/null and b/src/html/postscript_8h__dep__incl.png differ diff --git a/src/html/postscript_8h__incl.map b/src/html/postscript_8h__incl.map new file mode 100644 index 0000000..2cf2d2e --- /dev/null +++ b/src/html/postscript_8h__incl.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/postscript_8h__incl.md5 b/src/html/postscript_8h__incl.md5 new file mode 100644 index 0000000..fde89a5 --- /dev/null +++ b/src/html/postscript_8h__incl.md5 @@ -0,0 +1 @@ +a51d415ace1d6d3c4ed490eabe117fa9 \ No newline at end of file diff --git a/src/html/postscript_8h__incl.png b/src/html/postscript_8h__incl.png new file mode 100644 index 0000000..7e4287c Binary files /dev/null and b/src/html/postscript_8h__incl.png differ diff --git a/src/html/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.map b/src/html/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.map new file mode 100644 index 0000000..894acd1 --- /dev/null +++ b/src/html/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.map @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/html/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 b/src/html/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 new file mode 100644 index 0000000..4ccfb0d --- /dev/null +++ b/src/html/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 @@ -0,0 +1 @@ +dc4cd78c5be886941f02c5d92ac26303 \ No newline at end of file diff --git a/src/html/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.png b/src/html/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.png new file mode 100644 index 0000000..bfe25dc Binary files /dev/null and b/src/html/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.png differ diff --git a/src/html/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.map b/src/html/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.map new file mode 100644 index 0000000..fb77039 --- /dev/null +++ b/src/html/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.map @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/html/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 b/src/html/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 new file mode 100644 index 0000000..8f8943c --- /dev/null +++ b/src/html/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 @@ -0,0 +1 @@ +64543466fd3c413aa942f172642148a0 \ No newline at end of file diff --git a/src/html/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.png b/src/html/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.png new file mode 100644 index 0000000..87c3991 Binary files /dev/null and b/src/html/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.png differ diff --git a/src/html/postscript_8h_source.html b/src/html/postscript_8h_source.html new file mode 100644 index 0000000..a89729d --- /dev/null +++ b/src/html/postscript_8h_source.html @@ -0,0 +1,81 @@ + + + + + + + +My Project: postscript.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
postscript.h
+
+
+Go to the documentation of this file.
1 #ifndef _POSTSCRIPT_H_
2 #define _POSTSCRIPT_H_
3 
4 #include "rnaz_utils.h"
5 #include "code.h"
6 
7 int colorAln(const char *filename, const struct aln *alignment[],segmentStats region);
8 
9 void colorHSS(const char *filename, const struct aln *alignment[], backtrackData *bt, const char* label, int b, int i);
10 
11 void setParameters();
12 
13 
14 #endif
Definition: rnaz_utils.h:12
+ +
Definition: score.h:48
+
Definition: score.h:67
+
void colorHSS(const char *filename, const struct aln *alignment[], backtrackData *bt, const char *label, int b, int i)
Definition: postscript.c:338
+ +
void setParameters()
Definition: postscript.c:19
+
int colorAln(const char *filename, const struct aln *alignment[], segmentStats region)
Definition: postscript.c:37
+
+ + + + diff --git a/src/html/rnaz__utils_8c.html b/src/html/rnaz__utils_8c.html new file mode 100644 index 0000000..0aed3fa --- /dev/null +++ b/src/html/rnaz__utils_8c.html @@ -0,0 +1,721 @@ + + + + + + + +My Project: rnaz_utils.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
rnaz_utils.c File Reference
+
+
+
#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <string.h>
+#include "fold.h"
+#include "fold_vars.h"
+#include "utils.h"
+#include "pair_mat.h"
+#include "alifold.h"
+#include "rnaz_utils.h"
+
+Include dependency graph for rnaz_utils.c:
+
+
+ + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

int read_clustal (FILE *clust, struct aln *alignedSeqs[])
 
int read_maf (FILE *clust, struct aln *alignedSeqs[])
 
char * consensus (const struct aln *AS[])
 
double meanPairID (const struct aln *AS[])
 
void revAln (struct aln *AS[])
 
void sliceAln (const struct aln *sourceAln[], struct aln *destAln[], int from, int to)
 
void freeAln (struct aln *AS[])
 
struct alncreateAlnEntry (char *name, char *seq, int start, int length, int fullLength, char strand)
 
void freeAlnEntry (struct aln *entry)
 
void printAln (const struct aln *AS[])
 
int checkFormat (FILE *file)
 
char ** splitFields (char *string)
 
char ** splitLines (char *string)
 
void freeFields (char **fields)
 
double combPerPair (struct aln *AS[], char *structure)
 
int encodeBase (char base)
 
void printAlnMAF (FILE *out, const struct aln *AS[], int printU)
 
void pruneAln (char *species, struct aln *alignment[])
 
char ** splitString (char *string, char *separators)
 
+

Function Documentation

+ +

◆ checkFormat()

+ +
+
+ + + + + + + + +
int checkFormat (FILE * file)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + +
+ +
+
+ +

◆ combPerPair()

+ +
+
+ + + + + + + + + + + + + + + + + + +
double combPerPair (struct alnAS[],
char * structure 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ consensus()

+ +
+
+ + + + + + + + +
char* consensus (const struct alnAS[])
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ createAlnEntry()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
struct aln* createAlnEntry (char * name,
char * seq,
int start,
int length,
int fullLength,
char strand 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ encodeBase()

+ +
+
+ + + + + + + + +
int encodeBase (char base)
+
+ +
+
+ +

◆ freeAln()

+ +
+
+ + + + + + + + +
void freeAln (struct alnAS[])
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ freeAlnEntry()

+ +
+
+ + + + + + + + +
void freeAlnEntry (struct alnentry)
+
+ +
+
+ +

◆ freeFields()

+ +
+
+ + + + + + + + +
void freeFields (char ** fields)
+
+ +
+
+ +

◆ meanPairID()

+ +
+
+ + + + + + + + +
double meanPairID (const struct alnAS[])
+
+ +
+
+ +

◆ printAln()

+ +
+
+ + + + + + + + +
void printAln (const struct alnAS[])
+
+ +
+
+ +

◆ printAlnMAF()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void printAlnMAF (FILE * out,
const struct alnAS[],
int printU 
)
+
+ +
+
+ +

◆ pruneAln()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void pruneAln (char * species,
struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ read_clustal()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int read_clustal (FILE * clust,
struct alnalignedSeqs[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + +
+ +
+
+ +

◆ read_maf()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int read_maf (FILE * clust,
struct alnalignedSeqs[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + +
+ +
+
+ +

◆ revAln()

+ +
+
+ + + + + + + + +
void revAln (struct alnAS[])
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ sliceAln()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void sliceAln (const struct alnsourceAln[],
struct alndestAln[],
int from,
int to 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ splitFields()

+ +
+
+ + + + + + + + +
char** splitFields (char * string)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ splitLines()

+ +
+
+ + + + + + + + +
char** splitLines (char * string)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ splitString()

+ +
+
+ + + + + + + + + + + + + + + + + + +
char** splitString (char * string,
char * separators 
)
+
+ +
+
+
+ + + + diff --git a/src/html/rnaz__utils_8c__incl.map b/src/html/rnaz__utils_8c__incl.map new file mode 100644 index 0000000..d89622f --- /dev/null +++ b/src/html/rnaz__utils_8c__incl.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/rnaz__utils_8c__incl.md5 b/src/html/rnaz__utils_8c__incl.md5 new file mode 100644 index 0000000..3e7c1c5 --- /dev/null +++ b/src/html/rnaz__utils_8c__incl.md5 @@ -0,0 +1 @@ +d60f6ef7016103a095863b7185277875 \ No newline at end of file diff --git a/src/html/rnaz__utils_8c__incl.png b/src/html/rnaz__utils_8c__incl.png new file mode 100644 index 0000000..9a0fd89 Binary files /dev/null and b/src/html/rnaz__utils_8c__incl.png differ diff --git a/src/html/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.map b/src/html/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.map new file mode 100644 index 0000000..8e639ee --- /dev/null +++ b/src/html/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.md5 b/src/html/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.md5 new file mode 100644 index 0000000..e4fcea9 --- /dev/null +++ b/src/html/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.md5 @@ -0,0 +1 @@ +f06bd77d3b2dcb6d17c91d269b78b7bc \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.png b/src/html/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.png new file mode 100644 index 0000000..b73a40d Binary files /dev/null and b/src/html/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.map b/src/html/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.map new file mode 100644 index 0000000..2c27d94 --- /dev/null +++ b/src/html/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 b/src/html/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 new file mode 100644 index 0000000..e1e9d6a --- /dev/null +++ b/src/html/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 @@ -0,0 +1 @@ +a08c482a6e1453c79d2c89e9d112f47b \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.png b/src/html/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.png new file mode 100644 index 0000000..9732de2 Binary files /dev/null and b/src/html/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.map b/src/html/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.map new file mode 100644 index 0000000..572d666 --- /dev/null +++ b/src/html/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/html/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 b/src/html/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 new file mode 100644 index 0000000..517a3e6 --- /dev/null +++ b/src/html/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 @@ -0,0 +1 @@ +5b8746c7701876181046388dd2e687c8 \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.png b/src/html/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.png new file mode 100644 index 0000000..1090b76 Binary files /dev/null and b/src/html/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.map b/src/html/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.map new file mode 100644 index 0000000..f5fae46 --- /dev/null +++ b/src/html/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 b/src/html/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 new file mode 100644 index 0000000..809fb0c --- /dev/null +++ b/src/html/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 @@ -0,0 +1 @@ +79d5120754575180eed856b9f69c0569 \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.png b/src/html/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.png new file mode 100644 index 0000000..103b6a5 Binary files /dev/null and b/src/html/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.map b/src/html/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.map new file mode 100644 index 0000000..63cd2a8 --- /dev/null +++ b/src/html/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.map @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/html/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 b/src/html/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 new file mode 100644 index 0000000..106d336 --- /dev/null +++ b/src/html/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 @@ -0,0 +1 @@ +7543e72c0bde716d6bc6f8b7335fc6de \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.png b/src/html/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.png new file mode 100644 index 0000000..67bfbba Binary files /dev/null and b/src/html/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.map b/src/html/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.map new file mode 100644 index 0000000..13fe8b5 --- /dev/null +++ b/src/html/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 b/src/html/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 new file mode 100644 index 0000000..be1fcca --- /dev/null +++ b/src/html/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 @@ -0,0 +1 @@ +8fa734e6341fdb1cfded9a2d9011d4cb \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.png b/src/html/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.png new file mode 100644 index 0000000..90fd641 Binary files /dev/null and b/src/html/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.map b/src/html/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.map new file mode 100644 index 0000000..18ed09d --- /dev/null +++ b/src/html/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 b/src/html/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 new file mode 100644 index 0000000..f24c4fa --- /dev/null +++ b/src/html/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 @@ -0,0 +1 @@ +32c2906f255b41eb37e1a3a92be8c736 \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.png b/src/html/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.png new file mode 100644 index 0000000..b3a1fb2 Binary files /dev/null and b/src/html/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.map b/src/html/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.map new file mode 100644 index 0000000..923f22d --- /dev/null +++ b/src/html/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 b/src/html/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 new file mode 100644 index 0000000..81f61e9 --- /dev/null +++ b/src/html/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 @@ -0,0 +1 @@ +edcfde7831a865e533b4531f0bce91e4 \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.png b/src/html/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.png new file mode 100644 index 0000000..5b1d6ba Binary files /dev/null and b/src/html/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.map b/src/html/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.map new file mode 100644 index 0000000..3cea926 --- /dev/null +++ b/src/html/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.md5 b/src/html/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.md5 new file mode 100644 index 0000000..83aaff6 --- /dev/null +++ b/src/html/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.md5 @@ -0,0 +1 @@ +14ff103af9ed02977cdf16c781ce95d2 \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.png b/src/html/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.png new file mode 100644 index 0000000..d614380 Binary files /dev/null and b/src/html/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.map b/src/html/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.map new file mode 100644 index 0000000..ffd6768 --- /dev/null +++ b/src/html/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.md5 b/src/html/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.md5 new file mode 100644 index 0000000..2787c9a --- /dev/null +++ b/src/html/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.md5 @@ -0,0 +1 @@ +2c7168991dd0d0e8b93022272f00accb \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.png b/src/html/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.png new file mode 100644 index 0000000..6589acf Binary files /dev/null and b/src/html/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.map b/src/html/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.map new file mode 100644 index 0000000..7e1b85d --- /dev/null +++ b/src/html/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.map @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/html/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 b/src/html/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 new file mode 100644 index 0000000..0714238 --- /dev/null +++ b/src/html/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 @@ -0,0 +1 @@ +f8da47ba604b0609ef857eec3d102064 \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.png b/src/html/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.png new file mode 100644 index 0000000..72e6094 Binary files /dev/null and b/src/html/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.png differ diff --git a/src/html/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.map b/src/html/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.map new file mode 100644 index 0000000..b418b91 --- /dev/null +++ b/src/html/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.md5 b/src/html/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.md5 new file mode 100644 index 0000000..e5b339d --- /dev/null +++ b/src/html/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.md5 @@ -0,0 +1 @@ +d8b4c9d287104031efadec6e725674a1 \ No newline at end of file diff --git a/src/html/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.png b/src/html/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.png new file mode 100644 index 0000000..71d8d4d Binary files /dev/null and b/src/html/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.png differ diff --git a/src/html/rnaz__utils_8h.html b/src/html/rnaz__utils_8h.html new file mode 100644 index 0000000..baabfff --- /dev/null +++ b/src/html/rnaz__utils_8h.html @@ -0,0 +1,821 @@ + + + + + + + +My Project: rnaz_utils.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
rnaz_utils.h File Reference
+
+
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + + + + + + + + + + +
+
+

Go to the source code of this file.

+ + + + +

+Classes

struct  aln
 
+ + + + + + + +

+Macros

#define PRIVATE   static
 
#define MAX_NUM_NAMES   500
 
#define MIN2(A, B)   ((A) < (B) ? (A) : (B))
 
+ + + +

+Enumerations

enum  alnFormat { UNKNOWN =0, +CLUSTAL =1, +MAF =2 + }
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

int read_clustal (FILE *clust, struct aln *alignedSeqs[])
 
int read_maf (FILE *clust, struct aln *alignedSeqs[])
 
char * consensus (const struct aln *AS[])
 
double meanPairID (const struct aln *AS[])
 
void revAln (struct aln *AS[])
 
double combPerPair (struct aln *AS[], char *structure)
 
int encodeBase (char base)
 
void sliceAln (const struct aln *sourceAln[], struct aln *destAln[], int from, int to)
 
void freeAln (struct aln *AS[])
 
struct alncreateAlnEntry (char *name, char *seq, int start, int length, int fullLength, char strand)
 
void freeAlnEntry (struct aln *entry)
 
void printAln (const struct aln *AS[])
 
int checkFormat (FILE *file)
 
char ** splitFields (char *string)
 
void freeFields (char **fields)
 
char ** splitLines (char *string)
 
void printAlnMAF (FILE *out, const struct aln *AS[], int printU)
 
void pruneAln (char *species, struct aln *AS[])
 
char ** splitString (char *string, char *separators)
 
+

Macro Definition Documentation

+ +

◆ MAX_NUM_NAMES

+ +
+
+ + + + +
#define MAX_NUM_NAMES   500
+
+ +
+
+ +

◆ MIN2

+ +
+
+ + + + + + + + + + + + + + + + + + +
#define MIN2( A,
 
)   ((A) < (B) ? (A) : (B))
+
+ +
+
+ +

◆ PRIVATE

+ +
+
+ + + + +
#define PRIVATE   static
+
+ +
+
+

Enumeration Type Documentation

+ +

◆ alnFormat

+ +
+
+ + + + +
enum alnFormat
+
+ + + + +
Enumerator
UNKNOWN 
CLUSTAL 
MAF 
+ +
+
+

Function Documentation

+ +

◆ checkFormat()

+ +
+
+ + + + + + + + +
int checkFormat (FILE * file)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + +
+ +
+
+ +

◆ combPerPair()

+ +
+
+ + + + + + + + + + + + + + + + + + +
double combPerPair (struct alnAS[],
char * structure 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ consensus()

+ +
+
+ + + + + + + + +
char* consensus (const struct alnAS[])
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ createAlnEntry()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
struct aln* createAlnEntry (char * name,
char * seq,
int start,
int length,
int fullLength,
char strand 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ encodeBase()

+ +
+
+ + + + + + + + +
int encodeBase (char base)
+
+ +
+
+ +

◆ freeAln()

+ +
+
+ + + + + + + + +
void freeAln (struct alnAS[])
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ freeAlnEntry()

+ +
+
+ + + + + + + + +
void freeAlnEntry (struct alnentry)
+
+ +
+
+ +

◆ freeFields()

+ +
+
+ + + + + + + + +
void freeFields (char ** fields)
+
+ +
+
+ +

◆ meanPairID()

+ +
+
+ + + + + + + + +
double meanPairID (const struct alnAS[])
+
+ +
+
+ +

◆ printAln()

+ +
+
+ + + + + + + + +
void printAln (const struct alnAS[])
+
+ +
+
+ +

◆ printAlnMAF()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void printAlnMAF (FILE * out,
const struct alnAS[],
int printU 
)
+
+ +
+
+ +

◆ pruneAln()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void pruneAln (char * species,
struct alnAS[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ read_clustal()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int read_clustal (FILE * clust,
struct alnalignedSeqs[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + +
+ +
+
+ +

◆ read_maf()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int read_maf (FILE * clust,
struct alnalignedSeqs[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + +
+ +
+
+ +

◆ revAln()

+ +
+
+ + + + + + + + +
void revAln (struct alnAS[])
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ sliceAln()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void sliceAln (const struct alnsourceAln[],
struct alndestAln[],
int from,
int to 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ splitFields()

+ +
+
+ + + + + + + + +
char** splitFields (char * string)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ splitLines()

+ +
+
+ + + + + + + + +
char** splitLines (char * string)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ splitString()

+ +
+
+ + + + + + + + + + + + + + + + + + +
char** splitString (char * string,
char * separators 
)
+
+ +
+
+
+ + + + diff --git a/src/html/rnaz__utils_8h__dep__incl.map b/src/html/rnaz__utils_8h__dep__incl.map new file mode 100644 index 0000000..8a89096 --- /dev/null +++ b/src/html/rnaz__utils_8h__dep__incl.map @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/html/rnaz__utils_8h__dep__incl.md5 b/src/html/rnaz__utils_8h__dep__incl.md5 new file mode 100644 index 0000000..10b3253 --- /dev/null +++ b/src/html/rnaz__utils_8h__dep__incl.md5 @@ -0,0 +1 @@ +bf10bf51219c988cde76e47194968799 \ No newline at end of file diff --git a/src/html/rnaz__utils_8h__dep__incl.png b/src/html/rnaz__utils_8h__dep__incl.png new file mode 100644 index 0000000..198d847 Binary files /dev/null and b/src/html/rnaz__utils_8h__dep__incl.png differ diff --git a/src/html/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.map b/src/html/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.map new file mode 100644 index 0000000..2c27d94 --- /dev/null +++ b/src/html/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 b/src/html/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 new file mode 100644 index 0000000..e1e9d6a --- /dev/null +++ b/src/html/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 @@ -0,0 +1 @@ +a08c482a6e1453c79d2c89e9d112f47b \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.png b/src/html/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.png new file mode 100644 index 0000000..9732de2 Binary files /dev/null and b/src/html/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.map b/src/html/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.map new file mode 100644 index 0000000..572d666 --- /dev/null +++ b/src/html/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/html/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 b/src/html/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 new file mode 100644 index 0000000..517a3e6 --- /dev/null +++ b/src/html/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 @@ -0,0 +1 @@ +5b8746c7701876181046388dd2e687c8 \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.png b/src/html/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.png new file mode 100644 index 0000000..1090b76 Binary files /dev/null and b/src/html/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.map b/src/html/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.map new file mode 100644 index 0000000..f5fae46 --- /dev/null +++ b/src/html/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 b/src/html/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 new file mode 100644 index 0000000..809fb0c --- /dev/null +++ b/src/html/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 @@ -0,0 +1 @@ +79d5120754575180eed856b9f69c0569 \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.png b/src/html/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.png new file mode 100644 index 0000000..103b6a5 Binary files /dev/null and b/src/html/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.map b/src/html/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.map new file mode 100644 index 0000000..8e639ee --- /dev/null +++ b/src/html/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.md5 b/src/html/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.md5 new file mode 100644 index 0000000..e4fcea9 --- /dev/null +++ b/src/html/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.md5 @@ -0,0 +1 @@ +f06bd77d3b2dcb6d17c91d269b78b7bc \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.png b/src/html/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.png new file mode 100644 index 0000000..b73a40d Binary files /dev/null and b/src/html/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.map b/src/html/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.map new file mode 100644 index 0000000..63cd2a8 --- /dev/null +++ b/src/html/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.map @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/html/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 b/src/html/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 new file mode 100644 index 0000000..106d336 --- /dev/null +++ b/src/html/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 @@ -0,0 +1 @@ +7543e72c0bde716d6bc6f8b7335fc6de \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.png b/src/html/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.png new file mode 100644 index 0000000..67bfbba Binary files /dev/null and b/src/html/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.map b/src/html/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.map new file mode 100644 index 0000000..13fe8b5 --- /dev/null +++ b/src/html/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 b/src/html/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 new file mode 100644 index 0000000..be1fcca --- /dev/null +++ b/src/html/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 @@ -0,0 +1 @@ +8fa734e6341fdb1cfded9a2d9011d4cb \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.png b/src/html/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.png new file mode 100644 index 0000000..90fd641 Binary files /dev/null and b/src/html/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.map b/src/html/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.map new file mode 100644 index 0000000..18ed09d --- /dev/null +++ b/src/html/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 b/src/html/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 new file mode 100644 index 0000000..f24c4fa --- /dev/null +++ b/src/html/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 @@ -0,0 +1 @@ +32c2906f255b41eb37e1a3a92be8c736 \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.png b/src/html/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.png new file mode 100644 index 0000000..b3a1fb2 Binary files /dev/null and b/src/html/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.map b/src/html/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.map new file mode 100644 index 0000000..923f22d --- /dev/null +++ b/src/html/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 b/src/html/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 new file mode 100644 index 0000000..81f61e9 --- /dev/null +++ b/src/html/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 @@ -0,0 +1 @@ +edcfde7831a865e533b4531f0bce91e4 \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.png b/src/html/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.png new file mode 100644 index 0000000..5b1d6ba Binary files /dev/null and b/src/html/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.map b/src/html/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.map new file mode 100644 index 0000000..3cea926 --- /dev/null +++ b/src/html/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.md5 b/src/html/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.md5 new file mode 100644 index 0000000..83aaff6 --- /dev/null +++ b/src/html/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.md5 @@ -0,0 +1 @@ +14ff103af9ed02977cdf16c781ce95d2 \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.png b/src/html/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.png new file mode 100644 index 0000000..d614380 Binary files /dev/null and b/src/html/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.map b/src/html/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.map new file mode 100644 index 0000000..ffd6768 --- /dev/null +++ b/src/html/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.md5 b/src/html/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.md5 new file mode 100644 index 0000000..2787c9a --- /dev/null +++ b/src/html/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.md5 @@ -0,0 +1 @@ +2c7168991dd0d0e8b93022272f00accb \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.png b/src/html/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.png new file mode 100644 index 0000000..6589acf Binary files /dev/null and b/src/html/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.map b/src/html/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.map new file mode 100644 index 0000000..7e1b85d --- /dev/null +++ b/src/html/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.map @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/html/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 b/src/html/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 new file mode 100644 index 0000000..0714238 --- /dev/null +++ b/src/html/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 @@ -0,0 +1 @@ +f8da47ba604b0609ef857eec3d102064 \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.png b/src/html/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.png new file mode 100644 index 0000000..72e6094 Binary files /dev/null and b/src/html/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.map b/src/html/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.map new file mode 100644 index 0000000..b418b91 --- /dev/null +++ b/src/html/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.md5 b/src/html/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.md5 new file mode 100644 index 0000000..e5b339d --- /dev/null +++ b/src/html/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.md5 @@ -0,0 +1 @@ +d8b4c9d287104031efadec6e725674a1 \ No newline at end of file diff --git a/src/html/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.png b/src/html/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.png new file mode 100644 index 0000000..71d8d4d Binary files /dev/null and b/src/html/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.png differ diff --git a/src/html/rnaz__utils_8h_source.html b/src/html/rnaz__utils_8h_source.html new file mode 100644 index 0000000..22cbba2 --- /dev/null +++ b/src/html/rnaz__utils_8h_source.html @@ -0,0 +1,104 @@ + + + + + + + +My Project: rnaz_utils.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
rnaz_utils.h
+
+
+Go to the documentation of this file.
1 #ifndef _RNAZ_UTILS_H_
2 #define _RNAZ_UTILS_H_
3 
4 
5 
6 #define PRIVATE static
7 #define MAX_NUM_NAMES 500
8 #define MIN2(A, B) ((A) < (B) ? (A) : (B))
9 
10 enum alnFormat {UNKNOWN=0, CLUSTAL=1, MAF=2};
11 
12 struct aln {
13  char *name;
14  char *seq;
15  char *fullSeq; /* Remembers full sequence when gaps are stripped in seq*/
16  int start;
17  int length;
19  char strand;
20 };
21 
22 
23 int read_clustal(FILE *clust, struct aln *alignedSeqs[]);
24 int read_maf(FILE *clust, struct aln *alignedSeqs[]);
25 
26 
27 char *consensus(const struct aln *AS[]);
28 
29 double meanPairID(const struct aln *AS[]);
30 
31 void revAln(struct aln *AS[]);
32 
33 double combPerPair(struct aln *AS[],char* structure);
34 
35 int encodeBase(char base);
36 
37 void sliceAln(const struct aln *sourceAln[], struct aln *destAln[],
38  int from, int to);
39 
40 void freeAln(struct aln *AS[]);
41 
42 
43 struct aln* createAlnEntry(char* name, char* seq, int start, int length, int fullLength, char strand);
44 void freeAlnEntry(struct aln* entry);
45 void printAln(const struct aln* AS[]);
46 
47 int checkFormat(FILE *file);
48 
49 char** splitFields(char* string);
50 void freeFields(char** fields);
51 
52 char** splitLines(char* string);
53 
54 void printAlnMAF(FILE *out, const struct aln* AS[],int printU);
55 
56 void pruneAln(char *species, struct aln* AS[]);
57 
58 char** splitString(char* string, char* separators);
59 
60 #endif
Definition: rnaz_utils.h:10
+
char strand
Definition: rnaz_utils.h:19
+
alnFormat
Definition: rnaz_utils.h:10
+
double combPerPair(struct aln *AS[], char *structure)
Definition: rnaz_utils.c:610
+
char * seq
Definition: rnaz_utils.h:14
+
int start
Definition: rnaz_utils.h:16
+
Definition: rnaz_utils.h:12
+
char * consensus(const struct aln *AS[])
Definition: rnaz_utils.c:249
+
void freeAlnEntry(struct aln *entry)
Definition: rnaz_utils.c:413
+
void printAln(const struct aln *AS[])
Definition: rnaz_utils.c:423
+
void freeFields(char **fields)
Definition: rnaz_utils.c:601
+
int read_clustal(FILE *clust, struct aln *alignedSeqs[])
Definition: rnaz_utils.c:44
+
Definition: rnaz_utils.h:10
+
char ** splitString(char *string, char *separators)
Definition: rnaz_utils.c:754
+
int read_maf(FILE *clust, struct aln *alignedSeqs[])
Definition: rnaz_utils.c:132
+
int encodeBase(char base)
Definition: rnaz_utils.c:676
+
int length
Definition: rnaz_utils.h:17
+
int fullLength
Definition: rnaz_utils.h:18
+
void printAlnMAF(FILE *out, const struct aln *AS[], int printU)
Definition: rnaz_utils.c:691
+
Definition: rnaz_utils.h:10
+
void pruneAln(char *species, struct aln *AS[])
Definition: rnaz_utils.c:724
+
int checkFormat(FILE *file)
Definition: rnaz_utils.c:430
+
struct aln * createAlnEntry(char *name, char *seq, int start, int length, int fullLength, char strand)
Definition: rnaz_utils.c:398
+
void revAln(struct aln *AS[])
Definition: rnaz_utils.c:316
+
char ** splitLines(char *string)
Definition: rnaz_utils.c:565
+
void freeAln(struct aln *AS[])
Definition: rnaz_utils.c:388
+
char * fullSeq
Definition: rnaz_utils.h:15
+
double meanPairID(const struct aln *AS[])
Definition: rnaz_utils.c:280
+
char ** splitFields(char *string)
Definition: rnaz_utils.c:480
+
void sliceAln(const struct aln *sourceAln[], struct aln *destAln[], int from, int to)
Definition: rnaz_utils.c:362
+
char * name
Definition: rnaz_utils.h:13
+
+ + + + diff --git a/src/html/score_8c.html b/src/html/score_8c.html new file mode 100644 index 0000000..bc2d78e --- /dev/null +++ b/src/html/score_8c.html @@ -0,0 +1,949 @@ + + + + + + + +My Project: score.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
score.c File Reference
+
+
+
#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "score.h"
+#include "RNAcode.h"
+#include "code.h"
+#include "misc.h"
+#include "extreme_fit.h"
+
+Include dependency graph for score.c:
+
+
+ + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

int ** getScoringMatrix ()
 
void freeScoringMatrix (int **matrix)
 
void calculateBG (bgModel *model)
 
float probHKY (int i, int j, float d, float freqs[4], float kappa)
 
void countFreqsMono (const struct aln *alignment[], float freqs[])
 
bgModelgetModels (TTree *tree, struct aln *alignment[], float kappa)
 
void freeModels (bgModel *models, int N)
 
float calculateSigma (char *block_0, char *block_k, int k, bgModel *models)
 
void getPairwiseScoreMatrix (bgModel *models, const struct aln *alignment[])
 
backtrackDatabacktrack (int opt_b, int opt_i, float ****SSk, const struct aln *alignment[])
 
float ** getMultipleScoreMatrix (float ****Sk, bgModel *models, const struct aln *alignment[])
 
segmentStatsgetHSS (float **S, const struct aln **inputAln, char strand)
 
int getExtremeValuePars (TTree *tree, const struct aln *alignment[], int sampleN, float maxNativeScore, float *parMu, float *parLambda)
 
segmentStatsscoreAln (const struct aln *inputAln[], TTree *tree, float kappa, int backtrack)
 
void freeS (float **S, const struct aln *alignment[])
 
void freeSk (float ****S, const struct aln *alignment[])
 
+ + + + + + + + + + + + + + + + + + + +

+Variables

parameters pars
 
int transcode [4][4][4]
 
int BLOSUM62 [24][24]
 
int BLOSUM90 [24][24]
 
bgModelmodels
 
bgModelmodelsRev
 
float **** Sk
 
float **** Sk_native
 
float **** Sk_native_rev
 
+

Function Documentation

+ +

◆ backtrack()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
backtrackData* backtrack (int opt_b,
int opt_i,
float **** SSk,
const struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ calculateBG()

+ +
+
+ + + + + + + + +
void calculateBG (bgModelmodel)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ calculateSigma()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
float calculateSigma (char * block_0,
char * block_k,
int k,
bgModelmodels 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ countFreqsMono()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void countFreqsMono (const struct alnalignment[],
float freqs[] 
)
+
+ +
+
+ +

◆ freeModels()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void freeModels (bgModelmodels,
int N 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ freeS()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void freeS (float ** S,
const struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ freeScoringMatrix()

+ +
+
+ + + + + + + + +
void freeScoringMatrix (int ** matrix)
+
+ +
+
+ +

◆ freeSk()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void freeSk (float **** S,
const struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ getExtremeValuePars()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int getExtremeValuePars (TTree * tree,
const struct alnalignment[],
int sampleN,
float maxNativeScore,
float * parMu,
float * parLambda 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ getHSS()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
segmentStats* getHSS (float ** S,
const struct aln ** inputAln,
char strand 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ getModels()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
bgModel* getModels (TTree * tree,
struct alnalignment[],
float kappa 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + +
+ +
+
+ +

◆ getMultipleScoreMatrix()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
float** getMultipleScoreMatrix (float **** Sk,
bgModelmodels,
const struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ getPairwiseScoreMatrix()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void getPairwiseScoreMatrix (bgModelmodels,
const struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + +
+ +
+
+ +

◆ getScoringMatrix()

+ +
+
+ + + + + + + +
int** getScoringMatrix ()
+
+ +
+
+ +

◆ probHKY()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
float probHKY (int i,
int j,
float d,
float freqs[4],
float kappa 
)
+
+ +
+
+ +

◆ scoreAln()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
segmentStats* scoreAln (const struct alninputAln[],
TTree * tree,
float kappa,
int backtrack 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ +
+
+

Variable Documentation

+ +

◆ BLOSUM62

+ +
+
+ + + + +
int BLOSUM62[24][24]
+
+ +
+
+ +

◆ BLOSUM90

+ +
+
+ + + + +
int BLOSUM90[24][24]
+
+ +
+
+ +

◆ models

+ +
+
+ + + + +
bgModel* models
+
+ +
+
+ +

◆ modelsRev

+ +
+
+ + + + +
bgModel* modelsRev
+
+ +
+
+ +

◆ pars

+ +
+
+ + + + +
parameters pars
+
+ +
+
+ +

◆ Sk

+ +
+
+ + + + +
float**** Sk
+
+ +
+
+ +

◆ Sk_native

+ +
+
+ + + + +
float**** Sk_native
+
+ +
+
+ +

◆ Sk_native_rev

+ +
+
+ + + + +
float**** Sk_native_rev
+
+ +
+
+ +

◆ transcode

+ +
+
+ + + + +
int transcode[4][4][4]
+
+ +
+
+
+ + + + diff --git a/src/html/score_8c__incl.map b/src/html/score_8c__incl.map new file mode 100644 index 0000000..542afe5 --- /dev/null +++ b/src/html/score_8c__incl.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/html/score_8c__incl.md5 b/src/html/score_8c__incl.md5 new file mode 100644 index 0000000..cdbe6eb --- /dev/null +++ b/src/html/score_8c__incl.md5 @@ -0,0 +1 @@ +db26bc62c26747bc45567aa74bb4c2d9 \ No newline at end of file diff --git a/src/html/score_8c__incl.png b/src/html/score_8c__incl.png new file mode 100644 index 0000000..3d646ae Binary files /dev/null and b/src/html/score_8c__incl.png differ diff --git a/src/html/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.map b/src/html/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.map new file mode 100644 index 0000000..335865d --- /dev/null +++ b/src/html/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.md5 b/src/html/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.md5 new file mode 100644 index 0000000..1aef05f --- /dev/null +++ b/src/html/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.md5 @@ -0,0 +1 @@ +b0dbfad53370be4fe31a140fc565aa3e \ No newline at end of file diff --git a/src/html/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.png b/src/html/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.png new file mode 100644 index 0000000..a922986 Binary files /dev/null and b/src/html/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.png differ diff --git a/src/html/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.map b/src/html/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.map new file mode 100644 index 0000000..c369b04 --- /dev/null +++ b/src/html/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.map @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/html/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.md5 b/src/html/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.md5 new file mode 100644 index 0000000..5e27e76 --- /dev/null +++ b/src/html/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.md5 @@ -0,0 +1 @@ +b2c355c331f6d8494bddbbc0d4547eb7 \ No newline at end of file diff --git a/src/html/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.png b/src/html/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.png new file mode 100644 index 0000000..a0ed7ff Binary files /dev/null and b/src/html/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.png differ diff --git a/src/html/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.map b/src/html/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.map new file mode 100644 index 0000000..75770a3 --- /dev/null +++ b/src/html/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 b/src/html/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 new file mode 100644 index 0000000..230d050 --- /dev/null +++ b/src/html/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 @@ -0,0 +1 @@ +1e833f63e5b9558d8ae4176a9d505fad \ No newline at end of file diff --git a/src/html/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.png b/src/html/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.png new file mode 100644 index 0000000..95fb8ea Binary files /dev/null and b/src/html/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.png differ diff --git a/src/html/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.map b/src/html/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.map new file mode 100644 index 0000000..5d616b7 --- /dev/null +++ b/src/html/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 b/src/html/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 new file mode 100644 index 0000000..15f0f4e --- /dev/null +++ b/src/html/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 @@ -0,0 +1 @@ +c613bce57e028d21678447dbb2452fa6 \ No newline at end of file diff --git a/src/html/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.png b/src/html/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.png new file mode 100644 index 0000000..e624145 Binary files /dev/null and b/src/html/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.png differ diff --git a/src/html/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.map b/src/html/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.map new file mode 100644 index 0000000..afb219d --- /dev/null +++ b/src/html/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.map @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/html/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 b/src/html/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 new file mode 100644 index 0000000..372129b --- /dev/null +++ b/src/html/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 @@ -0,0 +1 @@ +e8e927179fac8fc59519969100382fc8 \ No newline at end of file diff --git a/src/html/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.png b/src/html/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.png new file mode 100644 index 0000000..e2856aa Binary files /dev/null and b/src/html/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.png differ diff --git a/src/html/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.map b/src/html/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.map new file mode 100644 index 0000000..cade18f --- /dev/null +++ b/src/html/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 b/src/html/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 new file mode 100644 index 0000000..fd371f3 --- /dev/null +++ b/src/html/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 @@ -0,0 +1 @@ +90663cc500c2c99e0f2296d513580b04 \ No newline at end of file diff --git a/src/html/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.png b/src/html/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.png new file mode 100644 index 0000000..c3f8700 Binary files /dev/null and b/src/html/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.png differ diff --git a/src/html/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.map b/src/html/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.map new file mode 100644 index 0000000..7434abe --- /dev/null +++ b/src/html/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.map @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/html/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 b/src/html/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 new file mode 100644 index 0000000..f010fee --- /dev/null +++ b/src/html/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 @@ -0,0 +1 @@ +8420faaaded2f2eaf952013c6167190d \ No newline at end of file diff --git a/src/html/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.png b/src/html/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.png new file mode 100644 index 0000000..4e62955 Binary files /dev/null and b/src/html/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.png differ diff --git a/src/html/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.map b/src/html/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.map new file mode 100644 index 0000000..f1390db --- /dev/null +++ b/src/html/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.md5 b/src/html/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.md5 new file mode 100644 index 0000000..6ca74dd --- /dev/null +++ b/src/html/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.md5 @@ -0,0 +1 @@ +088c937012d966549c3f064868dbd058 \ No newline at end of file diff --git a/src/html/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.png b/src/html/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.png new file mode 100644 index 0000000..cabf837 Binary files /dev/null and b/src/html/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.png differ diff --git a/src/html/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.map b/src/html/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.map new file mode 100644 index 0000000..8a5cd64 --- /dev/null +++ b/src/html/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.md5 b/src/html/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.md5 new file mode 100644 index 0000000..b9e3187 --- /dev/null +++ b/src/html/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.md5 @@ -0,0 +1 @@ +0ac26f363676010365da287828f68ad2 \ No newline at end of file diff --git a/src/html/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.png b/src/html/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.png new file mode 100644 index 0000000..239e892 Binary files /dev/null and b/src/html/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.png differ diff --git a/src/html/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.map b/src/html/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.map new file mode 100644 index 0000000..60fb436 --- /dev/null +++ b/src/html/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/html/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 b/src/html/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 new file mode 100644 index 0000000..9d366f8 --- /dev/null +++ b/src/html/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 @@ -0,0 +1 @@ +95e05c0153803944b9ed3a8c6f08329b \ No newline at end of file diff --git a/src/html/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.png b/src/html/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.png new file mode 100644 index 0000000..6f7bd93 Binary files /dev/null and b/src/html/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.png differ diff --git a/src/html/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.map b/src/html/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.map new file mode 100644 index 0000000..1aa7bd0 --- /dev/null +++ b/src/html/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 b/src/html/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 new file mode 100644 index 0000000..d8fedee --- /dev/null +++ b/src/html/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 @@ -0,0 +1 @@ +ba5da6b806a7bfcd644573203bfee9d5 \ No newline at end of file diff --git a/src/html/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.png b/src/html/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.png new file mode 100644 index 0000000..657b221 Binary files /dev/null and b/src/html/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.png differ diff --git a/src/html/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.map b/src/html/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.map new file mode 100644 index 0000000..dba9a8d --- /dev/null +++ b/src/html/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.md5 b/src/html/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.md5 new file mode 100644 index 0000000..d8e0f8a --- /dev/null +++ b/src/html/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.md5 @@ -0,0 +1 @@ +a511b0908e92b222d3ebc6b266b102b8 \ No newline at end of file diff --git a/src/html/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.png b/src/html/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.png new file mode 100644 index 0000000..7f91a18 Binary files /dev/null and b/src/html/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.png differ diff --git a/src/html/score_8h.html b/src/html/score_8h.html new file mode 100644 index 0000000..2a6bc6b --- /dev/null +++ b/src/html/score_8h.html @@ -0,0 +1,1106 @@ + + + + + + + +My Project: score.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
score.h File Reference
+
+
+
#include "rnaz_utils.h"
+#include "tree.h"
+#include "treeSimulate.h"
+
+Include dependency graph for score.h:
+
+
+ + + + +
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + + + + +
+
+

Go to the source code of this file.

+ + + + + + + + +

+Classes

struct  _bgModel
 
struct  _segmentStats
 
struct  _backtrackData
 
+ + + + + + + + + + + +

+Macros

#define UNDEF   -9.0
 
#define MINUS_INF   -99.0
 
#define MAX(x, y)   (((x)>(y)) ? (x) : (y))
 
#define MAX3(x, y, z)   (MAX( (MAX((x),(y))) ,(z)))
 
#define CMP(x, y)   (((x) > (y) ? ((x)-(y)) : ((y)-(x))) < 0.00001)
 
+ + + + + + + +

+Typedefs

typedef struct _bgModel bgModel
 
typedef struct _segmentStats segmentStats
 
typedef struct _backtrackData backtrackData
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

float probHKY (int i, int j, float d, float freqs[4], float kappa)
 
int ** getScoringMatrix ()
 
void freeScoringMatrix (int **matrix)
 
void calculateBG (bgModel *models)
 
void stripGaps (struct aln *AS[])
 
void countFreqsMono (const struct aln *alignment[], float freqs[])
 
float * sumOfPairScore (bgModel *models, const struct aln *alignment[], int from, int to)
 
float * getCumSum (float *scores, int N)
 
bgModelgetModelMatrix (TTree *tree, struct aln *alignment[], float kappa)
 
void freeModelMatrix (bgModel *models, int N)
 
int getExtremeValuePars (TTree *tree, const struct aln *alignment[], int sampleN, float maxNativeScore, float *parMu, float *parLambda)
 
segmentStatsgetHSS (float **S, const struct aln **inputAln, char strand)
 
void getPairwiseScoreMatrix (bgModel *models, const struct aln *alignment[])
 
float ** getMultipleScoreMatrix (float ****Sk, bgModel *models, const struct aln *alignment[])
 
backtrackDatabacktrack (int opt_b, int opt_i, float ****SSk, const struct aln *alignment[])
 
void freeSk (float ****S, const struct aln *alignment[])
 
void freeS (float **S, const struct aln *alignment[])
 
segmentStatsscoreAln (const struct aln *alignment[], TTree *tree, float kappa, int backtrack)
 
bgModelgetModels (TTree *tree, struct aln *alignment[], float kappa)
 
+ + + + + +

+Variables

int ntMap [256]
 
int transcode [4][4][4]
 
+

Macro Definition Documentation

+ +

◆ CMP

+ +
+
+ + + + + + + + + + + + + + + + + + +
#define CMP( x,
 
)   (((x) > (y) ? ((x)-(y)) : ((y)-(x))) < 0.00001)
+
+ +
+
+ +

◆ MAX

+ +
+
+ + + + + + + + + + + + + + + + + + +
#define MAX( x,
 
)   (((x)>(y)) ? (x) : (y))
+
+ +
+
+ +

◆ MAX3

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
#define MAX3( x,
 y,
 
)   (MAX( (MAX((x),(y))) ,(z)))
+
+ +
+
+ +

◆ MINUS_INF

+ +
+
+ + + + +
#define MINUS_INF   -99.0
+
+ +
+
+ +

◆ UNDEF

+ +
+
+ + + + +
#define UNDEF   -9.0
+
+ +
+
+

Typedef Documentation

+ +

◆ backtrackData

+ +
+
+ + + + +
typedef struct _backtrackData backtrackData
+
+ +
+
+ +

◆ bgModel

+ +
+
+ + + + +
typedef struct _bgModel bgModel
+
+ +
+
+ +

◆ segmentStats

+ +
+
+ + + + +
typedef struct _segmentStats segmentStats
+
+ +
+
+

Function Documentation

+ +

◆ backtrack()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
backtrackData* backtrack (int opt_b,
int opt_i,
float **** SSk,
const struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ calculateBG()

+ +
+
+ + + + + + + + +
void calculateBG (bgModelmodels)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ countFreqsMono()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void countFreqsMono (const struct alnalignment[],
float freqs[] 
)
+
+ +
+
+ +

◆ freeModelMatrix()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void freeModelMatrix (bgModelmodels,
int N 
)
+
+ +
+
+ +

◆ freeS()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void freeS (float ** S,
const struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ freeScoringMatrix()

+ +
+
+ + + + + + + + +
void freeScoringMatrix (int ** matrix)
+
+ +
+
+ +

◆ freeSk()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void freeSk (float **** S,
const struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ getCumSum()

+ +
+
+ + + + + + + + + + + + + + + + + + +
float* getCumSum (float * scores,
int N 
)
+
+ +
+
+ +

◆ getExtremeValuePars()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int getExtremeValuePars (TTree * tree,
const struct alnalignment[],
int sampleN,
float maxNativeScore,
float * parMu,
float * parLambda 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ getHSS()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
segmentStats* getHSS (float ** S,
const struct aln ** inputAln,
char strand 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ getModelMatrix()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
bgModel* getModelMatrix (TTree * tree,
struct alnalignment[],
float kappa 
)
+
+ +
+
+ +

◆ getModels()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
bgModel* getModels (TTree * tree,
struct alnalignment[],
float kappa 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + +
+ +
+
+ +

◆ getMultipleScoreMatrix()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
float** getMultipleScoreMatrix (float **** Sk,
bgModelmodels,
const struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ getPairwiseScoreMatrix()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void getPairwiseScoreMatrix (bgModelmodels,
const struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + +
+ +
+
+ +

◆ getScoringMatrix()

+ +
+
+ + + + + + + +
int** getScoringMatrix ()
+
+ +
+
+ +

◆ probHKY()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
float probHKY (int i,
int j,
float d,
float freqs[4],
float kappa 
)
+
+ +
+
+ +

◆ scoreAln()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
segmentStats* scoreAln (const struct alnalignment[],
TTree * tree,
float kappa,
int backtrack 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +

◆ stripGaps()

+ +
+
+ + + + + + + + +
void stripGaps (struct alnAS[])
+
+ +
+
+ +

◆ sumOfPairScore()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
float* sumOfPairScore (bgModelmodels,
const struct alnalignment[],
int from,
int to 
)
+
+ +
+
+

Variable Documentation

+ +

◆ ntMap

+ +
+
+ + + + +
int ntMap[256]
+
+ +
+
+ +

◆ transcode

+ +
+
+ + + + +
int transcode[4][4][4]
+
+ +
+
+
+ + + + diff --git a/src/html/score_8h__dep__incl.map b/src/html/score_8h__dep__incl.map new file mode 100644 index 0000000..b460e60 --- /dev/null +++ b/src/html/score_8h__dep__incl.map @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/html/score_8h__dep__incl.md5 b/src/html/score_8h__dep__incl.md5 new file mode 100644 index 0000000..4bca051 --- /dev/null +++ b/src/html/score_8h__dep__incl.md5 @@ -0,0 +1 @@ +0a47e91a8272cb65c599fe794cdbc42e \ No newline at end of file diff --git a/src/html/score_8h__dep__incl.png b/src/html/score_8h__dep__incl.png new file mode 100644 index 0000000..7d7d86c Binary files /dev/null and b/src/html/score_8h__dep__incl.png differ diff --git a/src/html/score_8h__incl.map b/src/html/score_8h__incl.map new file mode 100644 index 0000000..409a8dc --- /dev/null +++ b/src/html/score_8h__incl.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/score_8h__incl.md5 b/src/html/score_8h__incl.md5 new file mode 100644 index 0000000..3bc004d --- /dev/null +++ b/src/html/score_8h__incl.md5 @@ -0,0 +1 @@ +2edf22a40c1c1566dbf3e914d5910aa9 \ No newline at end of file diff --git a/src/html/score_8h__incl.png b/src/html/score_8h__incl.png new file mode 100644 index 0000000..0081bbd Binary files /dev/null and b/src/html/score_8h__incl.png differ diff --git a/src/html/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.map b/src/html/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.map new file mode 100644 index 0000000..335865d --- /dev/null +++ b/src/html/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.md5 b/src/html/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.md5 new file mode 100644 index 0000000..1aef05f --- /dev/null +++ b/src/html/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.md5 @@ -0,0 +1 @@ +b0dbfad53370be4fe31a140fc565aa3e \ No newline at end of file diff --git a/src/html/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.png b/src/html/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.png new file mode 100644 index 0000000..a922986 Binary files /dev/null and b/src/html/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.png differ diff --git a/src/html/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.map b/src/html/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.map new file mode 100644 index 0000000..5d616b7 --- /dev/null +++ b/src/html/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 b/src/html/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 new file mode 100644 index 0000000..078effa --- /dev/null +++ b/src/html/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 @@ -0,0 +1 @@ +edebf846c17a1eb7ce86e40a6ef90e04 \ No newline at end of file diff --git a/src/html/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.png b/src/html/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.png new file mode 100644 index 0000000..e624145 Binary files /dev/null and b/src/html/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.png differ diff --git a/src/html/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.map b/src/html/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.map new file mode 100644 index 0000000..afb219d --- /dev/null +++ b/src/html/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.map @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/html/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 b/src/html/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 new file mode 100644 index 0000000..49502ed --- /dev/null +++ b/src/html/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 @@ -0,0 +1 @@ +33e319100d2e0eb505f86b8b2726f129 \ No newline at end of file diff --git a/src/html/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.png b/src/html/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.png new file mode 100644 index 0000000..e2856aa Binary files /dev/null and b/src/html/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.png differ diff --git a/src/html/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.map b/src/html/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.map new file mode 100644 index 0000000..dba9a8d --- /dev/null +++ b/src/html/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.md5 b/src/html/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.md5 new file mode 100644 index 0000000..d8e0f8a --- /dev/null +++ b/src/html/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.md5 @@ -0,0 +1 @@ +a511b0908e92b222d3ebc6b266b102b8 \ No newline at end of file diff --git a/src/html/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.png b/src/html/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.png new file mode 100644 index 0000000..7f91a18 Binary files /dev/null and b/src/html/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.png differ diff --git a/src/html/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.map b/src/html/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.map new file mode 100644 index 0000000..cade18f --- /dev/null +++ b/src/html/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 b/src/html/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 new file mode 100644 index 0000000..bdae8d4 --- /dev/null +++ b/src/html/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 @@ -0,0 +1 @@ +1053041849e6da4c0e1b9e7f6869ccc4 \ No newline at end of file diff --git a/src/html/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.png b/src/html/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.png new file mode 100644 index 0000000..c3f8700 Binary files /dev/null and b/src/html/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.png differ diff --git a/src/html/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.map b/src/html/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.map new file mode 100644 index 0000000..7434abe --- /dev/null +++ b/src/html/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.map @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/html/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 b/src/html/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 new file mode 100644 index 0000000..db4a537 --- /dev/null +++ b/src/html/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 @@ -0,0 +1 @@ +ea128b7c68edebe35c8aace7615ccfdc \ No newline at end of file diff --git a/src/html/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.png b/src/html/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.png new file mode 100644 index 0000000..4e62955 Binary files /dev/null and b/src/html/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.png differ diff --git a/src/html/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.map b/src/html/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.map new file mode 100644 index 0000000..8a5cd64 --- /dev/null +++ b/src/html/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.md5 b/src/html/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.md5 new file mode 100644 index 0000000..6b5adf4 --- /dev/null +++ b/src/html/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.md5 @@ -0,0 +1 @@ +4117afee27d5f055bd5a172a74f45ae5 \ No newline at end of file diff --git a/src/html/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.png b/src/html/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.png new file mode 100644 index 0000000..239e892 Binary files /dev/null and b/src/html/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.png differ diff --git a/src/html/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.map b/src/html/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.map new file mode 100644 index 0000000..60fb436 --- /dev/null +++ b/src/html/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/html/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 b/src/html/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 new file mode 100644 index 0000000..d68e9b8 --- /dev/null +++ b/src/html/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 @@ -0,0 +1 @@ +8f06da0d355c7bdffd82106492d8a560 \ No newline at end of file diff --git a/src/html/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.png b/src/html/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.png new file mode 100644 index 0000000..6f7bd93 Binary files /dev/null and b/src/html/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.png differ diff --git a/src/html/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.map b/src/html/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.map new file mode 100644 index 0000000..c369b04 --- /dev/null +++ b/src/html/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.map @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/html/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.md5 b/src/html/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.md5 new file mode 100644 index 0000000..9fca719 --- /dev/null +++ b/src/html/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.md5 @@ -0,0 +1 @@ +a89a13c6895fea190d18306f2a460455 \ No newline at end of file diff --git a/src/html/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.png b/src/html/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.png new file mode 100644 index 0000000..a0ed7ff Binary files /dev/null and b/src/html/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.png differ diff --git a/src/html/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.map b/src/html/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.map new file mode 100644 index 0000000..1aa7bd0 --- /dev/null +++ b/src/html/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 b/src/html/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 new file mode 100644 index 0000000..e4454b8 --- /dev/null +++ b/src/html/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 @@ -0,0 +1 @@ +928b2517e1aec737b097571c3c36597a \ No newline at end of file diff --git a/src/html/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.png b/src/html/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.png new file mode 100644 index 0000000..657b221 Binary files /dev/null and b/src/html/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.png differ diff --git a/src/html/score_8h_source.html b/src/html/score_8h_source.html new file mode 100644 index 0000000..91a6269 --- /dev/null +++ b/src/html/score_8h_source.html @@ -0,0 +1,125 @@ + + + + + + + +My Project: score.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
score.h
+
+
+Go to the documentation of this file.
1 /* Copyright 2009, Stefan Washietl
2 
3  This file is part of RNAcode.
4 
5  RNAcode is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  RNAcode is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with RNAcode. If not, see <http://www.gnu.org/licenses/>. */
17 
18 #ifndef _SCORE_H_
19 #define _SCORE_H_
20 
21 #include "rnaz_utils.h"
22 #include "tree.h"
23 #include "treeSimulate.h"
24 
25 #define UNDEF -9.0
26 #define MINUS_INF -99.0
27 
28 #define MAX(x,y) (((x)>(y)) ? (x) : (y))
29 #define MAX3(x,y,z) (MAX( (MAX((x),(y))) ,(z)))
30 #define CMP(x,y) (((x) > (y) ? ((x)-(y)) : ((y)-(x))) < 0.00001)
31 
32 typedef struct _bgModel bgModel;
33 
34 struct _bgModel {
35 
36  float scores[4];
37  float probs[4];
38  float kappa;
39  float dist;
40  float freqs[4];
41  int** matrix;
42  float weight;
43 
44 };
45 
46 typedef struct _segmentStats segmentStats;
47 
48 struct _segmentStats {
49 
50  int start; /* Relative start position (nt) */
51  int end;
52  int startGenomic; /* Absolute genomic start/end position when MAF is given */
53  int endGenomic;
54  int startSite; /* Relative start/end in amino acids */
55  int endSite;
56  int strand; /* Strand '+' or '-' */
57  int frame; /* Frame 1,2,3 */
58  char *name;
59  float score;
60  float pvalue;
61  int hide;
62 
63 };
64 
66 
68  float* scores;
69  int* z;
70  int* states;
71  int *transitions; // 0 stay the same, 1 ... Omega, 2 ... Delta;
72 };
73 
74 
75 
76 
77 
78 /* Values set in main() */
79 int ntMap[256];
80 
81 extern int transcode[4][4][4];
82 
83 float probHKY(int i, int j, float d, float freqs[4], float kappa);
84 
85 int** getScoringMatrix();
86 
87 void freeScoringMatrix(int** matrix);
88 
90 
91 void stripGaps(struct aln* AS[]);
92 
93 void countFreqsMono(const struct aln *alignment[], float freqs[]);
94 
95 float* sumOfPairScore(bgModel* models, const struct aln *alignment[],int from, int to);
96 
97 float* getCumSum(float* scores, int N);
98 
99 bgModel* getModelMatrix(TTree* tree, struct aln *alignment[], float kappa);
100 
101 void freeModelMatrix(bgModel* models, int N);
102 
103 int getExtremeValuePars(TTree* tree, const struct aln *alignment[],
104  int sampleN, float maxNativeScore, float* parMu, float* parLambda);
105 
106 segmentStats* getHSS(float** S, const struct aln** inputAln, char strand);
107 
108 void getPairwiseScoreMatrix(bgModel* models, const struct aln *alignment[]);
109 float** getMultipleScoreMatrix(float**** Sk, bgModel* models, const struct aln *alignment[]);
110 
111 backtrackData* backtrack(int opt_b, int opt_i, float**** SSk , const struct aln *alignment[]);
112 
113 void freeSk (float**** S, const struct aln *alignment[]);
114 void freeS (float** S, const struct aln *alignment[]);
115 
116 segmentStats* scoreAln(const struct aln *alignment[], TTree* tree, float kappa, int backtrack);
117 
118 bgModel* getModels(TTree* tree, struct aln *alignment[], float kappa);
119 
120 
121 #endif
int startSite
Definition: score.h:54
+
bgModel * getModelMatrix(TTree *tree, struct aln *alignment[], float kappa)
+
void calculateBG(bgModel *models)
Definition: score.c:105
+
float probs[4]
Definition: score.h:37
+
Definition: rnaz_utils.h:12
+
float dist
Definition: score.h:39
+
int hide
Definition: score.h:61
+
segmentStats * getHSS(float **S, const struct aln **inputAln, char strand)
Definition: score.c:862
+
float scores[4]
Definition: score.h:36
+
float score
Definition: score.h:59
+
void freeScoringMatrix(int **matrix)
Definition: score.c:83
+
float pvalue
Definition: score.h:60
+
void countFreqsMono(const struct aln *alignment[], float freqs[])
Definition: score.c:253
+
int ** matrix
Definition: score.h:41
+
char * name
Definition: score.h:58
+
int endGenomic
Definition: score.h:53
+
segmentStats * scoreAln(const struct aln *alignment[], TTree *tree, float kappa, int backtrack)
Definition: score.c:1065
+
float weight
Definition: score.h:42
+ +
Definition: score.h:48
+
int end
Definition: score.h:51
+
Definition: score.h:34
+
float probHKY(int i, int j, float d, float freqs[4], float kappa)
Definition: score.c:202
+
Definition: score.h:67
+
int frame
Definition: score.h:57
+
int ntMap[256]
Definition: score.h:79
+
int * states
Definition: score.h:70
+
float **** Sk
Definition: RNAcode.c:42
+
int ** getScoringMatrix()
Definition: score.c:48
+
int strand
Definition: score.h:56
+
void freeS(float **S, const struct aln *alignment[])
Definition: score.c:1148
+
bgModel * getModels(TTree *tree, struct aln *alignment[], float kappa)
Definition: score.c:289
+ +
float kappa
Definition: score.h:38
+
void freeModelMatrix(bgModel *models, int N)
+
int transcode[4][4][4]
Definition: code.c:26
+
float * sumOfPairScore(bgModel *models, const struct aln *alignment[], int from, int to)
+
float * getCumSum(float *scores, int N)
+
float ** getMultipleScoreMatrix(float ****Sk, bgModel *models, const struct aln *alignment[])
Definition: score.c:809
+
int getExtremeValuePars(TTree *tree, const struct aln *alignment[], int sampleN, float maxNativeScore, float *parMu, float *parLambda)
Definition: score.c:974
+
void getPairwiseScoreMatrix(bgModel *models, const struct aln *alignment[])
Definition: score.c:439
+
int * transitions
Definition: score.h:71
+
backtrackData * backtrack(int opt_b, int opt_i, float ****SSk, const struct aln *alignment[])
Definition: score.c:556
+
int start
Definition: score.h:50
+
float freqs[4]
Definition: score.h:40
+
void stripGaps(struct aln *AS[])
+
bgModel * models
Definition: RNAcode.c:41
+
void freeSk(float ****S, const struct aln *alignment[])
Definition: score.c:1162
+
int startGenomic
Definition: score.h:52
+
float * scores
Definition: score.h:68
+
int endSite
Definition: score.h:55
+
int * z
Definition: score.h:69
+
+ + + + diff --git a/src/html/search/all_0.html b/src/html/search/all_0.html new file mode 100644 index 0000000..f25360b --- /dev/null +++ b/src/html/search/all_0.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_0.js b/src/html/search/all_0.js new file mode 100644 index 0000000..9732406 --- /dev/null +++ b/src/html/search/all_0.js @@ -0,0 +1,13 @@ +var searchData= +[ + ['_5f',['_',['../getopt_8c.html#a86a239addea586602343007a370bf8ad',1,'getopt.c']]], + ['_5f_5fgetopt_5finitialized',['__getopt_initialized',['../getopt_8c.html#a28286be757527aeb1db951b5da9aeec1',1,'getopt.c']]], + ['_5fbacktrackdata',['_backtrackData',['../struct__backtrackData.html',1,'']]], + ['_5fbgmodel',['_bgModel',['../struct__bgModel.html',1,'']]], + ['_5fgetopt_5fh',['_GETOPT_H',['../getopt_8h.html#aaafc27a0389aa87797164b227566342d',1,'getopt.h']]], + ['_5fgetopt_5finitialize',['_getopt_initialize',['../getopt_8c.html#a17475cbc1ffae0c12af2e0a3319d197f',1,'getopt.c']]], + ['_5fgetopt_5finternal',['_getopt_internal',['../getopt_8c.html#a0df92a0ae8fe1fd43268c738f548674f',1,'_getopt_internal(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only): getopt.c'],['../getopt_8h.html#a60428225710059ca135c6b2a8941855f',1,'_getopt_internal(): getopt.h']]], + ['_5fno_5fproto',['_NO_PROTO',['../getopt_8c.html#a9bcd7db9771ff03b7e5a9fec9c489861',1,'getopt.c']]], + ['_5fparameters',['_parameters',['../struct__parameters.html',1,'']]], + ['_5fsegmentstats',['_segmentStats',['../struct__segmentStats.html',1,'']]] +]; diff --git a/src/html/search/all_1.html b/src/html/search/all_1.html new file mode 100644 index 0000000..b13f0f7 --- /dev/null +++ b/src/html/search/all_1.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_1.js b/src/html/search/all_1.js new file mode 100644 index 0000000..75240fb --- /dev/null +++ b/src/html/search/all_1.js @@ -0,0 +1,12 @@ +var searchData= +[ + ['allocatesk',['allocateSk',['../misc_8c.html#ab8906f987e8caa1c304422e2105784db',1,'allocateSk(int N, int L): misc.c'],['../misc_8h.html#ab8906f987e8caa1c304422e2105784db',1,'allocateSk(int N, int L): misc.c']]], + ['aln',['aln',['../structaln.html',1,'']]], + ['alnformat',['alnFormat',['../rnaz__utils_8h.html#ad849a5b1ae21b9dd57228a7cc706a189',1,'rnaz_utils.h']]], + ['arg_5fflag',['ARG_FLAG',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1afd135f03243c33991ef507f4410718f7',1,'cmdline.c']]], + ['arg_5ffloat',['ARG_FLOAT',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1a5875de3e892eb32ed41e4d60ef7d99ca',1,'cmdline.c']]], + ['arg_5fint',['ARG_INT',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1a58393752406d163205fa18f450909993',1,'cmdline.c']]], + ['arg_5fno',['ARG_NO',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1a67dd250fb3e23862523b667407868ada',1,'cmdline.c']]], + ['arg_5fstring',['ARG_STRING',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1a1e0904ee5e3baf2aa4070ab0718a3afa',1,'cmdline.c']]], + ['avg',['avg',['../misc_8c.html#a29db63ab5182ac2f88eb37329c092126',1,'avg(float *data, int N): misc.c'],['../misc_8h.html#a29db63ab5182ac2f88eb37329c092126',1,'avg(float *data, int N): misc.c']]] +]; diff --git a/src/html/search/all_10.html b/src/html/search/all_10.html new file mode 100644 index 0000000..d1345a1 --- /dev/null +++ b/src/html/search/all_10.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_10.js b/src/html/search/all_10.js new file mode 100644 index 0000000..04dafb9 --- /dev/null +++ b/src/html/search/all_10.js @@ -0,0 +1,18 @@ +var searchData= +[ + ['random_5fstring',['random_string',['../utils_8c.html#ab4ae5a543569ad8c331564963ea50f68',1,'random_string(int l, const char symbols[]): utils.c'],['../utils_8h.html#a1b95eac365a021572e1c37e5993a89be',1,'random_string(int l, const char symbols[]): utils.c']]], + ['rcsid',['rcsid',['../utils_8c.html#af1b3bff1622925d03c9cd14c5f1a51bf',1,'utils.c']]], + ['read_5fclustal',['read_clustal',['../rnaz__utils_8c.html#ad571d9ad5858c8e2d834225efec51163',1,'read_clustal(FILE *clust, struct aln *alignedSeqs[]): rnaz_utils.c'],['../rnaz__utils_8h.html#ad571d9ad5858c8e2d834225efec51163',1,'read_clustal(FILE *clust, struct aln *alignedSeqs[]): rnaz_utils.c']]], + ['read_5fcommandline',['read_commandline',['../RNAcode_8c.html#ae36ab4408b3aaada4218ac5f60ea6027',1,'read_commandline(int argc, char *argv[]): RNAcode.c'],['../RNAcode_8h.html#ae36ab4408b3aaada4218ac5f60ea6027',1,'read_commandline(int argc, char *argv[]): RNAcode.c']]], + ['read_5fmaf',['read_maf',['../rnaz__utils_8c.html#a2207280ef510cc5d737b0b04bcfba476',1,'read_maf(FILE *clust, struct aln *alignedSeqs[]): rnaz_utils.c'],['../rnaz__utils_8h.html#a2207280ef510cc5d737b0b04bcfba476',1,'read_maf(FILE *clust, struct aln *alignedSeqs[]): rnaz_utils.c']]], + ['reintroducegaps',['reintroduceGaps',['../misc_8c.html#a8eed68ed1197df02c8b9a49264efc717',1,'reintroduceGaps(const struct aln *origAln[], struct aln *sampledAln[]): misc.c'],['../misc_8h.html#a8eed68ed1197df02c8b9a49264efc717',1,'reintroduceGaps(const struct aln *origAln[], struct aln *sampledAln[]): misc.c']]], + ['require_5forder',['REQUIRE_ORDER',['../getopt_8c.html#a06fc87d81c62e9abb8790b6e5713c55ba0e73a0691c110b1442d8364d1d12eccc',1,'getopt.c']]], + ['required_5fargument',['required_argument',['../getopt_8h.html#a6ece8d8dfa8378778f7290fdaba5b8bc',1,'getopt.h']]], + ['return_5fin_5forder',['RETURN_IN_ORDER',['../getopt_8c.html#a06fc87d81c62e9abb8790b6e5713c55ba3c56550bfafe809d9214b863b69c31c5',1,'getopt.c']]], + ['revaln',['revAln',['../rnaz__utils_8c.html#a9c0adcc1f46e9fceab51c54bd25475e2',1,'revAln(struct aln *AS[]): rnaz_utils.c'],['../rnaz__utils_8h.html#a9c0adcc1f46e9fceab51c54bd25475e2',1,'revAln(struct aln *AS[]): rnaz_utils.c']]], + ['rnacode_2ec',['RNAcode.c',['../RNAcode_8c.html',1,'']]], + ['rnacode_2eh',['RNAcode.h',['../RNAcode_8h.html',1,'']]], + ['rnaz_5futils_2ec',['rnaz_utils.c',['../rnaz__utils_8c.html',1,'']]], + ['rnaz_5futils_2eh',['rnaz_utils.h',['../rnaz__utils_8h.html',1,'']]], + ['rulerstep',['rulerStep',['../postscript_8c.html#adbb97a02a7e2f5bc69940fc230062839',1,'postscript.c']]] +]; diff --git a/src/html/search/all_11.html b/src/html/search/all_11.html new file mode 100644 index 0000000..2be8b71 --- /dev/null +++ b/src/html/search/all_11.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_11.js b/src/html/search/all_11.js new file mode 100644 index 0000000..318ba27 --- /dev/null +++ b/src/html/search/all_11.js @@ -0,0 +1,41 @@ +var searchData= +[ + ['samplen',['sampleN',['../struct__parameters.html#a40706f4d64be0c9ee5cb411cee949416',1,'_parameters']]], + ['score',['score',['../struct__segmentStats.html#aea28293c9c59198e9f14542d99ac1484',1,'_segmentStats']]], + ['score_2ec',['score.c',['../score_8c.html',1,'']]], + ['score_2eh',['score.h',['../score_8h.html',1,'']]], + ['scorealn',['scoreAln',['../score_8c.html#a098269687ae30d844d2c6b58793f2d2c',1,'scoreAln(const struct aln *inputAln[], TTree *tree, float kappa, int backtrack): score.c'],['../score_8h.html#af667df05b60aeb3ec0bd6bd423e268db',1,'scoreAln(const struct aln *alignment[], TTree *tree, float kappa, int backtrack): score.c']]], + ['scores',['scores',['../struct__bgModel.html#af4fae6328e121d42a0a8fb3dd882c549',1,'_bgModel::scores()'],['../struct__backtrackData.html#af803a69e3c75e33c0ba7df036642c44d',1,'_backtrackData::scores()']]], + ['segmentstats',['segmentStats',['../score_8h.html#a5b7f5df9506ff8c871dc49e4bf9f22af',1,'score.h']]], + ['seq',['seq',['../structaln.html#aee1fbffa2c18c0b3d6016b8fe409eeae',1,'aln']]], + ['seqsx',['seqsX',['../postscript_8c.html#a69294d581be62ee920a2ef6622500cbd',1,'postscript.c']]], + ['setparameters',['setParameters',['../postscript_8c.html#a1d6c94586a33965dd4277c7fe62de430',1,'setParameters(): postscript.c'],['../postscript_8h.html#a1d6c94586a33965dd4277c7fe62de430',1,'setParameters(): postscript.c']]], + ['simulatetree',['simulateTree',['../treeSimulate_8c.html#a2a10fb3293a345ad28201efc8f452348',1,'simulateTree(TTree *tree, float freqs[], float kap, int L): treeSimulate.c'],['../treeSimulate_8h.html#a2a10fb3293a345ad28201efc8f452348',1,'simulateTree(TTree *tree, float freqs[], float kap, int L): treeSimulate.c']]], + ['sk',['Sk',['../RNAcode_8c.html#a1662932a5f2814e67dfbbd95ab925073',1,'Sk(): RNAcode.c'],['../score_8c.html#a1662932a5f2814e67dfbbd95ab925073',1,'Sk(): RNAcode.c']]], + ['sk_5fnative',['Sk_native',['../postscript_8c.html#a189ec0118947b93b0df1359ab643d3ce',1,'Sk_native(): postscript.c'],['../RNAcode_8c.html#a189ec0118947b93b0df1359ab643d3ce',1,'Sk_native(): RNAcode.c'],['../score_8c.html#a189ec0118947b93b0df1359ab643d3ce',1,'Sk_native(): postscript.c']]], + ['sk_5fnative_5frev',['Sk_native_rev',['../postscript_8c.html#a720f3e09e87f08ee95fd84af1c9c575e',1,'Sk_native_rev(): postscript.c'],['../RNAcode_8c.html#a720f3e09e87f08ee95fd84af1c9c575e',1,'Sk_native_rev(): RNAcode.c'],['../score_8c.html#a720f3e09e87f08ee95fd84af1c9c575e',1,'Sk_native_rev(): postscript.c']]], + ['slicealn',['sliceAln',['../rnaz__utils_8c.html#a43cebeec9c40c9be2970b4ed266e7065',1,'sliceAln(const struct aln *sourceAln[], struct aln *destAln[], int from, int to): rnaz_utils.c'],['../rnaz__utils_8h.html#a43cebeec9c40c9be2970b4ed266e7065',1,'sliceAln(const struct aln *sourceAln[], struct aln *destAln[], int from, int to): rnaz_utils.c']]], + ['sortaln',['sortAln',['../misc_8c.html#a5753372a1a3c3974fc6be9a6030a67bf',1,'sortAln(const struct aln *origAln[], struct aln *sampledAln[]): misc.c'],['../misc_8h.html#a5753372a1a3c3974fc6be9a6030a67bf',1,'sortAln(const struct aln *origAln[], struct aln *sampledAln[]): misc.c']]], + ['space',['space',['../utils_8c.html#a5dac704be118855d7c4dd3aa3bc31fc3',1,'space(unsigned int size): utils.c'],['../utils_8c.html#a38098f2a039377364b35c84560792ecb',1,'space(unsigned size): utils.c'],['../utils_8h.html#ad7e1e137b3bf1f7108933d302a7f0177',1,'space(unsigned size): utils.c']]], + ['splitfields',['splitFields',['../rnaz__utils_8c.html#a174b786ba35d783d0937a545d2d4071b',1,'splitFields(char *string): rnaz_utils.c'],['../rnaz__utils_8h.html#a174b786ba35d783d0937a545d2d4071b',1,'splitFields(char *string): rnaz_utils.c']]], + ['splitlines',['splitLines',['../rnaz__utils_8c.html#ad897a202b424203bee4a1746872aa095',1,'splitLines(char *string): rnaz_utils.c'],['../rnaz__utils_8h.html#ad897a202b424203bee4a1746872aa095',1,'splitLines(char *string): rnaz_utils.c']]], + ['splitstring',['splitString',['../rnaz__utils_8c.html#a7d5f1b4f24c9a156013547278b473278',1,'splitString(char *string, char *separators): rnaz_utils.c'],['../rnaz__utils_8h.html#a7d5f1b4f24c9a156013547278b473278',1,'splitString(char *string, char *separators): rnaz_utils.c']]], + ['ssstep',['ssStep',['../postscript_8c.html#a0fa03894e3a7c9aa3690c217af65c7c3',1,'postscript.c']]], + ['start',['start',['../structaln.html#a1cde67bfa55bc9e8f2d98f9e53a4ba12',1,'aln::start()'],['../struct__segmentStats.html#acbd4b0e7ceaa05b6506aab77d2bf1090',1,'_segmentStats::start()']]], + ['startgenomic',['startGenomic',['../struct__segmentStats.html#a95a69dcd9686db97033daded2f42878b',1,'_segmentStats']]], + ['startsite',['startSite',['../struct__segmentStats.html#a403f946ddab65393861d93fbb81f0d5a',1,'_segmentStats']]], + ['starty',['startY',['../postscript_8c.html#aa3dfc2d68f6a44a7941b7e6f2940ecac',1,'postscript.c']]], + ['states',['states',['../struct__backtrackData.html#a5dc8d2471b3ad228bfba4b4a4638ac85',1,'_backtrackData']]], + ['stddev',['stddev',['../misc_8c.html#ac9b591bdb26f6a8b8ee56aee3e809c65',1,'stddev(float *data, int N): misc.c'],['../misc_8h.html#ac9b591bdb26f6a8b8ee56aee3e809c65',1,'stddev(float *data, int N): misc.c']]], + ['stop_5fearly_5fflag',['stop_early_flag',['../structgengetopt__args__info.html#aa4b8393ab6c37bca14cb1b291b5871df',1,'gengetopt_args_info']]], + ['stop_5fearly_5fgiven',['stop_early_given',['../structgengetopt__args__info.html#a69729e2dba0de954d98a56a1b3d8d1c1',1,'gengetopt_args_info']]], + ['stop_5fearly_5fhelp',['stop_early_help',['../structgengetopt__args__info.html#aefd3bdbabef305d8e53741dc229e7cb0',1,'gengetopt_args_info']]], + ['stopearly',['stopEarly',['../struct__parameters.html#ad170b87fd49f42a1ca464c93e36fa0e3',1,'_parameters']]], + ['stoppenalty_5f0',['stopPenalty_0',['../struct__parameters.html#a35c6c83856e4256be0fb543410014f1e',1,'_parameters']]], + ['stoppenalty_5fk',['stopPenalty_k',['../struct__parameters.html#ae26af9c558d90b735b7ed5c2bb8bbb1b',1,'_parameters']]], + ['strand',['strand',['../structaln.html#aa3a2e698a569a230e9e14e14d3afe653',1,'aln::strand()'],['../struct__segmentStats.html#a84cfdd51d1e7fe9555f887c3658e9ced',1,'_segmentStats::strand()']]], + ['string2tree',['string2tree',['../treeSimulate_8c.html#af77eeafe78dc6291a2c5a0f9e0dea164',1,'string2tree(char *treeString): treeSimulate.c'],['../treeSimulate_8h.html#af77eeafe78dc6291a2c5a0f9e0dea164',1,'string2tree(char *treeString): treeSimulate.c']]], + ['stripgaps',['stripGaps',['../score_8h.html#a50f4b7f86944e31e967a5d2e7d045c01',1,'score.h']]], + ['sumofpairscore',['sumOfPairScore',['../score_8h.html#ab64745553f4c76c089d6dc44f76f639b',1,'score.h']]], + ['swap_5fflags',['SWAP_FLAGS',['../getopt_8c.html#a6e06e56c5fa96faaf47f3b231e015e35',1,'getopt.c']]] +]; diff --git a/src/html/search/all_12.html b/src/html/search/all_12.html new file mode 100644 index 0000000..13c5263 --- /dev/null +++ b/src/html/search/all_12.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_12.js b/src/html/search/all_12.js new file mode 100644 index 0000000..529c75f --- /dev/null +++ b/src/html/search/all_12.js @@ -0,0 +1,18 @@ +var searchData= +[ + ['tabular_5fflag',['tabular_flag',['../structgengetopt__args__info.html#aa01935a1796974d3347aff6062718afc',1,'gengetopt_args_info']]], + ['tabular_5fgiven',['tabular_given',['../structgengetopt__args__info.html#a3b5a200c98e9f33b1dfa0adf5fbaf69d',1,'gengetopt_args_info']]], + ['tabular_5fhelp',['tabular_help',['../structgengetopt__args__info.html#a923b9288287e40df1b3f21bfe288f123',1,'gengetopt_args_info']]], + ['time_5fstamp',['time_stamp',['../utils_8c.html#ade7ba8b8ed6a11e4c6f20e9e603e8799',1,'time_stamp(void): utils.c'],['../utils_8h.html#a7afeb906cb36e9d77379eabc6907ac46',1,'time_stamp(void): utils.c']]], + ['tmpcolumns',['tmpColumns',['../postscript_8c.html#a7e166443fa8165daca1829477a3678c1',1,'postscript.c']]], + ['transcode',['transcode',['../code_8c.html#a119a7eb0ecd417f83e41f4325ce522c8',1,'transcode(): code.c'],['../score_8c.html#a119a7eb0ecd417f83e41f4325ce522c8',1,'transcode(): code.c'],['../score_8h.html#a119a7eb0ecd417f83e41f4325ce522c8',1,'transcode(): code.c']]], + ['transitions',['transitions',['../struct__backtrackData.html#ac559f1f5976ad99432828f9f9ea7f218',1,'_backtrackData']]], + ['translateseq',['translateSeq',['../code_8c.html#a8d64bc3ec5de4db181efd7ff565ff894',1,'translateSeq(char *seq): code.c'],['../code_8h.html#a8d64bc3ec5de4db181efd7ff565ff894',1,'translateSeq(char *seq): code.c']]], + ['tree2aln',['tree2aln',['../treeSimulate_8c.html#a3de1638db8b0f14df05b49f41bae2da6',1,'tree2aln(TTree *tree, struct aln *alignment[]): treeSimulate.c'],['../treeSimulate_8h.html#a3de1638db8b0f14df05b49f41bae2da6',1,'tree2aln(TTree *tree, struct aln *alignment[]): treeSimulate.c']]], + ['treeml',['treeML',['../treeML_8c.html#a252122923da9d542436a6ce49c15c819',1,'treeML(const struct aln *alignment[], char **treeString, float *kappa): treeML.c'],['../treeML_8h.html#a252122923da9d542436a6ce49c15c819',1,'treeML(const struct aln *alignment[], char **treeString, float *kappa): treeML.c']]], + ['treeml_2ec',['treeML.c',['../treeML_8c.html',1,'']]], + ['treeml_2eh',['treeML.h',['../treeML_8h.html',1,'']]], + ['treesimulate_2ec',['treeSimulate.c',['../treeSimulate_8c.html',1,'']]], + ['treesimulate_2eh',['treeSimulate.h',['../treeSimulate_8h.html',1,'']]], + ['tstv',['tstv',['../treeSimulate_8c.html#a489eb68465b539564550251550697a47',1,'treeSimulate.c']]] +]; diff --git a/src/html/search/all_13.html b/src/html/search/all_13.html new file mode 100644 index 0000000..b4a8bca --- /dev/null +++ b/src/html/search/all_13.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_13.js b/src/html/search/all_13.js new file mode 100644 index 0000000..e878e1c --- /dev/null +++ b/src/html/search/all_13.js @@ -0,0 +1,12 @@ +var searchData= +[ + ['undef',['UNDEF',['../score_8h.html#abde25a67f4046530ae1c572cefeb5869',1,'score.h']]], + ['unknown',['UNKNOWN',['../rnaz__utils_8h.html#ad849a5b1ae21b9dd57228a7cc706a189a6ce26a62afab55d7606ad4e92428b30c',1,'rnaz_utils.h']]], + ['unpack_5fstructure',['unpack_structure',['../utils_8c.html#aeda5e0295cdcacc9da2ae479db08396c',1,'unpack_structure(const char *packed): utils.c'],['../utils_8h.html#a071c6921efe1eb974f115ee6fefa3c39',1,'unpack_structure(const char *packed): utils.c']]], + ['update_5farg',['update_arg',['../cmdline_8c.html#a21d8824d410efa489c4921011c1c0765',1,'cmdline.c']]], + ['urn',['urn',['../utils_8c.html#ab838605c6654ebdddc4ad19280855a25',1,'urn(void): utils.c'],['../utils_8h.html#aaa328491c84996e445d027fde9800f2e',1,'urn(void): utils.c']]], + ['usage',['usage',['../RNAcode_8c.html#ae8605e2b78cd4a81b6c6b5c30cb7366a',1,'usage(void): RNAcode.c'],['../RNAcode_8h.html#ae8605e2b78cd4a81b6c6b5c30cb7366a',1,'usage(void): RNAcode.c']]], + ['userfreqs',['userFreqs',['../treeSimulate_8c.html#a2d2500b39f829187e7542d576b71a547',1,'treeSimulate.c']]], + ['utils_2ec',['utils.c',['../utils_8c.html',1,'']]], + ['utils_2eh',['utils.h',['../utils_8h.html',1,'']]] +]; diff --git a/src/html/search/all_14.html b/src/html/search/all_14.html new file mode 100644 index 0000000..fb4d0ec --- /dev/null +++ b/src/html/search/all_14.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_14.js b/src/html/search/all_14.js new file mode 100644 index 0000000..7295691 --- /dev/null +++ b/src/html/search/all_14.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['val',['val',['../structoption.html#a13bd155ec3b405d29c41ab8d0793be11',1,'option']]], + ['version',['version',['../RNAcode_8c.html#af986bd0575ec9b913dfab4b8422509ae',1,'version(void): RNAcode.c'],['../RNAcode_8h.html#af986bd0575ec9b913dfab4b8422509ae',1,'version(void): RNAcode.c']]], + ['version_5fgiven',['version_given',['../structgengetopt__args__info.html#ad4953a2130b2f8b94a3a687014f278e1',1,'gengetopt_args_info']]], + ['version_5fhelp',['version_help',['../structgengetopt__args__info.html#adef454ea6f3ff4114ae5009e58360cfc',1,'gengetopt_args_info']]] +]; diff --git a/src/html/search/all_15.html b/src/html/search/all_15.html new file mode 100644 index 0000000..8afe9a0 --- /dev/null +++ b/src/html/search/all_15.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_15.js b/src/html/search/all_15.js new file mode 100644 index 0000000..76f2b97 --- /dev/null +++ b/src/html/search/all_15.js @@ -0,0 +1,8 @@ +var searchData= +[ + ['weight',['weight',['../struct__bgModel.html#a00821dd196f2cf6dbccbfa8400a15752',1,'_bgModel']]], + ['weight_2ec',['weight.c',['../weight_8c.html',1,'']]], + ['weight_2eh',['weight.h',['../weight_8h.html',1,'']]], + ['weights',['weights',['../weight_8c.html#a0c41284822a5ce5bfea7cd745ac71edc',1,'weights(float **D, int N): weight.c'],['../weight_8h.html#a2d3bb1f6e0b7a4b2c564e8843f51e385',1,'weights(float **D, int N): weight.c']]], + ['write_5finto_5ffile',['write_into_file',['../cmdline_8c.html#a332041b3060103618ef6b767ab32d0dd',1,'cmdline.c']]] +]; diff --git a/src/html/search/all_16.html b/src/html/search/all_16.html new file mode 100644 index 0000000..e511edb --- /dev/null +++ b/src/html/search/all_16.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_16.js b/src/html/search/all_16.js new file mode 100644 index 0000000..5b70a44 --- /dev/null +++ b/src/html/search/all_16.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['xrealloc',['xrealloc',['../utils_8c.html#a9037ada838835b1b9db41581a021b0c8',1,'xrealloc(void *p, unsigned size): utils.c'],['../utils_8h.html#a9037ada838835b1b9db41581a021b0c8',1,'xrealloc(void *p, unsigned size): utils.c']]], + ['xsubi',['xsubi',['../utils_8c.html#a082c5a4e1e1e662b3452b3eb021291fb',1,'xsubi(): utils.c'],['../utils_8h.html#af9a866c8417afda7368bbac939ab3c47',1,'xsubi(): utils.c']]] +]; diff --git a/src/html/search/all_17.html b/src/html/search/all_17.html new file mode 100644 index 0000000..5ca9efd --- /dev/null +++ b/src/html/search/all_17.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_17.js b/src/html/search/all_17.js new file mode 100644 index 0000000..d4604c1 --- /dev/null +++ b/src/html/search/all_17.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['z',['z',['../struct__backtrackData.html#a72e1450e2610bee1d867d8428f33a2cc',1,'_backtrackData']]] +]; diff --git a/src/html/search/all_2.html b/src/html/search/all_2.html new file mode 100644 index 0000000..9543c57 --- /dev/null +++ b/src/html/search/all_2.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_2.js b/src/html/search/all_2.js new file mode 100644 index 0000000..f1568c0 --- /dev/null +++ b/src/html/search/all_2.js @@ -0,0 +1,23 @@ +var searchData= +[ + ['backtrack',['backtrack',['../score_8c.html#a0557015d88daf987d0730792a31493ad',1,'backtrack(int opt_b, int opt_i, float ****SSk, const struct aln *alignment[]): score.c'],['../score_8h.html#a0557015d88daf987d0730792a31493ad',1,'backtrack(int opt_b, int opt_i, float ****SSk, const struct aln *alignment[]): score.c']]], + ['backtrackdata',['backtrackData',['../score_8h.html#a0751e1c4932f95e3e60c73409408a97f',1,'score.h']]], + ['best_5fonly_5fflag',['best_only_flag',['../structgengetopt__args__info.html#ab0275ce8469b8fa0415ec84a692aba90',1,'gengetopt_args_info']]], + ['best_5fonly_5fgiven',['best_only_given',['../structgengetopt__args__info.html#a6c48b4d066a85f4a580a6a64dbdb176e',1,'gengetopt_args_info']]], + ['best_5fonly_5fhelp',['best_only_help',['../structgengetopt__args__info.html#a4f31622f59d764e13fe3ef9d3d0cc579',1,'gengetopt_args_info']]], + ['best_5fregion_5fflag',['best_region_flag',['../structgengetopt__args__info.html#a4ee2d5172359ee7a6b7fd042fae11817',1,'gengetopt_args_info']]], + ['best_5fregion_5fgiven',['best_region_given',['../structgengetopt__args__info.html#afd4b6f3efee5f421948359ec5eea335c',1,'gengetopt_args_info']]], + ['best_5fregion_5fhelp',['best_region_help',['../structgengetopt__args__info.html#a8943d1adc6dc6a89790adb4ce383943e',1,'gengetopt_args_info']]], + ['bestonly',['bestOnly',['../struct__parameters.html#acdebd1fac8029bad117f9ba82bef93d5',1,'_parameters']]], + ['bestregion',['bestRegion',['../struct__parameters.html#ad8bdd1fcbd46e8fb6842e5ab77b9c8fe',1,'_parameters']]], + ['bgmodel',['bgModel',['../score_8h.html#aec88546fa977a827f3312b2c12738421',1,'score.h']]], + ['blockstep',['blockStep',['../postscript_8c.html#a2d6e8a7836bfad8586715c3bb775cbb4',1,'postscript.c']]], + ['blosum',['blosum',['../struct__parameters.html#a3857ab2091fd5bbda92463952163163f',1,'_parameters']]], + ['blosum62',['BLOSUM62',['../code_8c.html#a528f2f941a2c7a8de187c946e438d107',1,'BLOSUM62(): code.c'],['../score_8c.html#a528f2f941a2c7a8de187c946e438d107',1,'BLOSUM62(): code.c']]], + ['blosum90',['BLOSUM90',['../code_8c.html#addcd68ee32c359359fcb55b5bfd8a62f',1,'BLOSUM90(): code.c'],['../score_8c.html#addcd68ee32c359359fcb55b5bfd8a62f',1,'BLOSUM90(): code.c']]], + ['blosum_5farg',['blosum_arg',['../structgengetopt__args__info.html#a7d3c9030b97320380911d603e2130e0d',1,'gengetopt_args_info']]], + ['blosum_5fgiven',['blosum_given',['../structgengetopt__args__info.html#a5c4114dd20295edf631f04e637214386',1,'gengetopt_args_info']]], + ['blosum_5fhelp',['blosum_help',['../structgengetopt__args__info.html#a6527f32b39a7c09ee3daffe899887075',1,'gengetopt_args_info']]], + ['blosum_5forig',['blosum_orig',['../structgengetopt__args__info.html#a93a262b5d97dda58b75849a1318e2918',1,'gengetopt_args_info']]], + ['bp_5fdistance',['bp_distance',['../utils_8c.html#ad3b3262478312877d19d74950030de73',1,'bp_distance(const char *str1, const char *str2): utils.c'],['../utils_8h.html#a6ebbcd29a754f0e4f1a66d1fd84184db',1,'bp_distance(const char *str1, const char *str2): utils.c']]] +]; diff --git a/src/html/search/all_3.html b/src/html/search/all_3.html new file mode 100644 index 0000000..03405c0 --- /dev/null +++ b/src/html/search/all_3.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_3.js b/src/html/search/all_3.js new file mode 100644 index 0000000..9c89228 --- /dev/null +++ b/src/html/search/all_3.js @@ -0,0 +1,54 @@ +var searchData= +[ + ['calculatebg',['calculateBG',['../score_8c.html#afa0b54f696bdcdf5395fb5e5185bd129',1,'calculateBG(bgModel *model): score.c'],['../score_8h.html#a853a7de0874087a99e452ed917b3fdfa',1,'calculateBG(bgModel *models): score.c']]], + ['calculatesigma',['calculateSigma',['../score_8c.html#aa7ac5e027c4335c220657e63d95b18ec',1,'score.c']]], + ['check_5fambiguity',['check_ambiguity',['../structcmdline__parser__params.html#a6e4442704fc40b0b655f7cc602f13ec4',1,'cmdline_parser_params']]], + ['check_5frequired',['check_required',['../structcmdline__parser__params.html#a44ff439d7e9e36799e59173af74829c6',1,'cmdline_parser_params']]], + ['checkformat',['checkFormat',['../rnaz__utils_8c.html#a7e802ce86090ca9375d5e39ebacc1470',1,'checkFormat(FILE *file): rnaz_utils.c'],['../rnaz__utils_8h.html#a7e802ce86090ca9375d5e39ebacc1470',1,'checkFormat(FILE *file): rnaz_utils.c']]], + ['clear_5fargs',['clear_args',['../cmdline_8c.html#a4d7018864f814395754ea4127ce4d37b',1,'cmdline.c']]], + ['clear_5fgiven',['clear_given',['../cmdline_8c.html#a48968b912c47767e9f057f5bc11634cb',1,'cmdline.c']]], + ['clustal',['CLUSTAL',['../rnaz__utils_8h.html#ad849a5b1ae21b9dd57228a7cc706a189a0c9e4d1c84d67fc10b7d54da4aad56ca',1,'rnaz_utils.h']]], + ['cmdline_2ec',['cmdline.c',['../cmdline_8c.html',1,'']]], + ['cmdline_2eh',['cmdline.h',['../cmdline_8h.html',1,'']]], + ['cmdline_5fparser',['cmdline_parser',['../cmdline_8c.html#a96f1044799c552f3ee139f9b1387b363',1,'cmdline_parser(int argc, char *const *argv, struct gengetopt_args_info *args_info): cmdline.c'],['../cmdline_8h.html#a96f1044799c552f3ee139f9b1387b363',1,'cmdline_parser(int argc, char *const *argv, struct gengetopt_args_info *args_info): cmdline.c']]], + ['cmdline_5fparser2',['cmdline_parser2',['../cmdline_8c.html#a08e3536edc64ec5ee7c2df546c6e9dd7',1,'cmdline_parser2(int argc, char *const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required): cmdline.c'],['../cmdline_8h.html#a08e3536edc64ec5ee7c2df546c6e9dd7',1,'cmdline_parser2(int argc, char *const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required): cmdline.c']]], + ['cmdline_5fparser_5farg_5ftype',['cmdline_parser_arg_type',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1',1,'cmdline.c']]], + ['cmdline_5fparser_5fdump',['cmdline_parser_dump',['../cmdline_8c.html#a1f73418092a6e6eb3706aa0de2785e11',1,'cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info): cmdline.c'],['../cmdline_8h.html#a1f73418092a6e6eb3706aa0de2785e11',1,'cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info): cmdline.c']]], + ['cmdline_5fparser_5fext',['cmdline_parser_ext',['../cmdline_8c.html#a77e461b5bdfd4a36c59a96bfb1813e38',1,'cmdline_parser_ext(int argc, char *const *argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params): cmdline.c'],['../cmdline_8h.html#a77e461b5bdfd4a36c59a96bfb1813e38',1,'cmdline_parser_ext(int argc, char *const *argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params): cmdline.c']]], + ['cmdline_5fparser_5ffile_5fsave',['cmdline_parser_file_save',['../cmdline_8c.html#a5f3e9412f88f1058a31ac28ad2ea2818',1,'cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info): cmdline.c'],['../cmdline_8h.html#a5f3e9412f88f1058a31ac28ad2ea2818',1,'cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info): cmdline.c']]], + ['cmdline_5fparser_5ffree',['cmdline_parser_free',['../cmdline_8c.html#af1b97c4e92b88f736e350b3902266ba4',1,'cmdline_parser_free(struct gengetopt_args_info *args_info): cmdline.c'],['../cmdline_8h.html#af1b97c4e92b88f736e350b3902266ba4',1,'cmdline_parser_free(struct gengetopt_args_info *args_info): cmdline.c']]], + ['cmdline_5fparser_5finit',['cmdline_parser_init',['../cmdline_8c.html#aca62b50d03d0d082968eeb1940f98650',1,'cmdline_parser_init(struct gengetopt_args_info *args_info): cmdline.c'],['../cmdline_8h.html#aca62b50d03d0d082968eeb1940f98650',1,'cmdline_parser_init(struct gengetopt_args_info *args_info): cmdline.c']]], + ['cmdline_5fparser_5finternal',['cmdline_parser_internal',['../cmdline_8c.html#aaba43e1bb216c68c96e982c600c906a7',1,'cmdline.c']]], + ['cmdline_5fparser_5fpackage',['CMDLINE_PARSER_PACKAGE',['../cmdline_8h.html#aeb847973552c32bcbe5f14973a0a8a32',1,'cmdline.h']]], + ['cmdline_5fparser_5fparams',['cmdline_parser_params',['../structcmdline__parser__params.html',1,'']]], + ['cmdline_5fparser_5fparams_5fcreate',['cmdline_parser_params_create',['../cmdline_8c.html#afd778af110fe0ee1ea5eac7aa9939d92',1,'cmdline_parser_params_create(void): cmdline.c'],['../cmdline_8h.html#afd778af110fe0ee1ea5eac7aa9939d92',1,'cmdline_parser_params_create(void): cmdline.c']]], + ['cmdline_5fparser_5fparams_5finit',['cmdline_parser_params_init',['../cmdline_8c.html#af72b814611cffc706b2135ccdfe7e997',1,'cmdline_parser_params_init(struct cmdline_parser_params *params): cmdline.c'],['../cmdline_8h.html#af72b814611cffc706b2135ccdfe7e997',1,'cmdline_parser_params_init(struct cmdline_parser_params *params): cmdline.c']]], + ['cmdline_5fparser_5fprint_5fhelp',['cmdline_parser_print_help',['../cmdline_8c.html#ad4f7db2fa4002379eb30e5206f3b7492',1,'cmdline_parser_print_help(void): cmdline.c'],['../cmdline_8h.html#ad4f7db2fa4002379eb30e5206f3b7492',1,'cmdline_parser_print_help(void): cmdline.c']]], + ['cmdline_5fparser_5fprint_5fversion',['cmdline_parser_print_version',['../cmdline_8c.html#a96f27bf35ce0ab8eea7a1f6e6b59a5e2',1,'cmdline_parser_print_version(void): cmdline.c'],['../cmdline_8h.html#a96f27bf35ce0ab8eea7a1f6e6b59a5e2',1,'cmdline_parser_print_version(void): cmdline.c']]], + ['cmdline_5fparser_5frelease',['cmdline_parser_release',['../cmdline_8c.html#ace6fb8241473bb89c5a575774eb4ba2a',1,'cmdline.c']]], + ['cmdline_5fparser_5frequired',['cmdline_parser_required',['../cmdline_8c.html#a83651e5be280d60aed58fdb72456a030',1,'cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name): cmdline.c'],['../cmdline_8h.html#a83651e5be280d60aed58fdb72456a030',1,'cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name): cmdline.c']]], + ['cmdline_5fparser_5fversion',['CMDLINE_PARSER_VERSION',['../cmdline_8h.html#a1eeca7dc254bf6867ba9635f45771471',1,'cmdline.h']]], + ['cmp',['CMP',['../score_8h.html#afb073915b50e7112cfed534aff6524cf',1,'score.h']]], + ['code_2ec',['code.c',['../code_8c.html',1,'']]], + ['code_2eh',['code.h',['../code_8h.html',1,'']]], + ['coloraln',['colorAln',['../postscript_8c.html#ac7d6bf70e040d36788b6eacace4cb312',1,'colorAln(const char *filename, const struct aln *alignment[], segmentStats region): postscript.c'],['../postscript_8h.html#ac7d6bf70e040d36788b6eacace4cb312',1,'colorAln(const char *filename, const struct aln *alignment[], segmentStats region): postscript.c']]], + ['colorhss',['colorHSS',['../postscript_8c.html#a88d8c5c3031b8ee553b4bfc437e4b73e',1,'colorHSS(const char *filename, const struct aln *alignment[], backtrackData *bt, const char *label, int b, int i): postscript.c'],['../postscript_8h.html#a88d8c5c3031b8ee553b4bfc437e4b73e',1,'colorHSS(const char *filename, const struct aln *alignment[], backtrackData *bt, const char *label, int b, int i): postscript.c']]], + ['columnwidth',['columnWidth',['../postscript_8c.html#acb1a982424fe4ce17865ade904f6afbb',1,'postscript.c']]], + ['combperpair',['combPerPair',['../rnaz__utils_8c.html#aa5d9fd87f6384e8d19af13f1365b503b',1,'combPerPair(struct aln *AS[], char *structure): rnaz_utils.c'],['../rnaz__utils_8h.html#aa5d9fd87f6384e8d19af13f1365b503b',1,'combPerPair(struct aln *AS[], char *structure): rnaz_utils.c']]], + ['comparelocation',['compareLocation',['../misc_8c.html#a08c97f6ebbb296bfe2d0f74e7a3a8af8',1,'misc.c']]], + ['comparescores',['compareScores',['../misc_8c.html#a3003bc209fbd623b0ebf8d55c3f76454',1,'compareScores(const void *a, const void *b): misc.c'],['../misc_8h.html#a3003bc209fbd623b0ebf8d55c3f76454',1,'compareScores(const void *a, const void *b): misc.c']]], + ['consensus',['consensus',['../rnaz__utils_8c.html#aa870f4f41dc7bf4808af716a34482ac5',1,'consensus(const struct aln *AS[]): rnaz_utils.c'],['../rnaz__utils_8h.html#aa870f4f41dc7bf4808af716a34482ac5',1,'consensus(const struct aln *AS[]): rnaz_utils.c']]], + ['consstep',['consStep',['../postscript_8c.html#a6290c97dafee311a97e747d02251da9d',1,'postscript.c']]], + ['const',['const',['../getopt_8c.html#a2c212835823e3c54a8ab6d95c652660e',1,'getopt.c']]], + ['copyaln',['copyAln',['../misc_8c.html#a0da1742a6a7f546827bee85fbdf53592',1,'copyAln(struct aln *src[], struct aln *dest[]): misc.c'],['../misc_8h.html#a0da1742a6a7f546827bee85fbdf53592',1,'copyAln(struct aln *src[], struct aln *dest[]): misc.c']]], + ['copysk',['copySk',['../misc_8c.html#a540d653adf9134e345a0be15556bef9f',1,'copySk(float ****from, float ****to, int N, int L): misc.c'],['../misc_8h.html#a540d653adf9134e345a0be15556bef9f',1,'copySk(float ****from, float ****to, int N, int L): misc.c']]], + ['countfreqsmono',['countFreqsMono',['../score_8c.html#a73aae058cfc643479adf77c5ffc48a45',1,'countFreqsMono(const struct aln *alignment[], float freqs[]): score.c'],['../score_8h.html#a73aae058cfc643479adf77c5ffc48a45',1,'countFreqsMono(const struct aln *alignment[], float freqs[]): score.c']]], + ['createalnentry',['createAlnEntry',['../rnaz__utils_8c.html#ab3af11f3fc09669574f682072f795865',1,'createAlnEntry(char *name, char *seq, int start, int length, int fullLength, char strand): rnaz_utils.c'],['../rnaz__utils_8h.html#ab3af11f3fc09669574f682072f795865',1,'createAlnEntry(char *name, char *seq, int start, int length, int fullLength, char strand): rnaz_utils.c']]], + ['currpos',['currPos',['../postscript_8c.html#aee13643f97e046b7492876910b23b59d',1,'postscript.c']]], + ['curry',['currY',['../postscript_8c.html#a6cd3947c7e694dc9a6516a4efce1c73d',1,'postscript.c']]], + ['cutoff',['cutoff',['../struct__parameters.html#a6e3ed4fee9836ba83e10f42a0b9d89b2',1,'_parameters']]], + ['cutoff_5farg',['cutoff_arg',['../structgengetopt__args__info.html#a79efa24e1a3d614f474d323f147edf10',1,'gengetopt_args_info']]], + ['cutoff_5fgiven',['cutoff_given',['../structgengetopt__args__info.html#ace7446eaaaffb4c8be5ee2d157933ac1',1,'gengetopt_args_info']]], + ['cutoff_5fhelp',['cutoff_help',['../structgengetopt__args__info.html#a46f7d71837544abf13c5972fc5e528b3',1,'gengetopt_args_info']]], + ['cutoff_5forig',['cutoff_orig',['../structgengetopt__args__info.html#ac1cc7e0fbe8552f19e4760b827349622',1,'gengetopt_args_info']]] +]; diff --git a/src/html/search/all_4.html b/src/html/search/all_4.html new file mode 100644 index 0000000..8e1f4b9 --- /dev/null +++ b/src/html/search/all_4.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_4.js b/src/html/search/all_4.js new file mode 100644 index 0000000..b10fcb9 --- /dev/null +++ b/src/html/search/all_4.js @@ -0,0 +1,13 @@ +var searchData= +[ + ['debug_5ffile_5farg',['debug_file_arg',['../structgengetopt__args__info.html#a648135bce096c7f592d4a6cc6d2b4d20',1,'gengetopt_args_info']]], + ['debug_5ffile_5fgiven',['debug_file_given',['../structgengetopt__args__info.html#a87bd42cd11567d4e27859cc0569752d6',1,'gengetopt_args_info']]], + ['debug_5ffile_5fhelp',['debug_file_help',['../structgengetopt__args__info.html#af5d881c802b02a6f85b5e4b957de85e9',1,'gengetopt_args_info']]], + ['debug_5ffile_5forig',['debug_file_orig',['../structgengetopt__args__info.html#a2b22e7ebbc50b2b054e9be56785fb2de',1,'gengetopt_args_info']]], + ['debugfile',['debugFile',['../struct__parameters.html#ab616c6d418c255985ac50a9311d8c26a',1,'_parameters']]], + ['debugfilename',['debugFileName',['../struct__parameters.html#a82681df81d7bc113bc6fad0b5328a95d',1,'_parameters']]], + ['decodeaa',['decodeAA',['../code_8c.html#a124646f7d65dd512584b8fbab1fcc7a4',1,'decodeAA(int encodedAA): code.c'],['../code_8h.html#a124646f7d65dd512584b8fbab1fcc7a4',1,'decodeAA(int encodedAA): code.c']]], + ['delta',['Delta',['../struct__parameters.html#a9a5b85aa0c04d7e22e824e315b14e4cd',1,'_parameters']]], + ['deprecated_20list',['Deprecated List',['../deprecated.html',1,'']]], + ['dist',['dist',['../struct__bgModel.html#a3757c1ef6b0176dfdeb6046365bf8524',1,'_bgModel']]] +]; diff --git a/src/html/search/all_5.html b/src/html/search/all_5.html new file mode 100644 index 0000000..89a879e --- /dev/null +++ b/src/html/search/all_5.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_5.js b/src/html/search/all_5.js new file mode 100644 index 0000000..b8e778a --- /dev/null +++ b/src/html/search/all_5.js @@ -0,0 +1,26 @@ +var searchData= +[ + ['encodeaa',['encodeAA',['../code_8c.html#a617a88955038003d70de0d9113b505eb',1,'encodeAA(char aa): code.c'],['../code_8h.html#a617a88955038003d70de0d9113b505eb',1,'encodeAA(char aa): code.c']]], + ['encodebase',['encodeBase',['../rnaz__utils_8c.html#a48ca69cad11fcf2c4d962b73ff4388ee',1,'encodeBase(char base): rnaz_utils.c'],['../rnaz__utils_8h.html#a48ca69cad11fcf2c4d962b73ff4388ee',1,'encodeBase(char base): rnaz_utils.c']]], + ['encodeseq',['encodeSeq',['../code_8c.html#a011bbc41b53a2519b2bb46214b7a1fcc',1,'encodeSeq(char *seq): code.c'],['../code_8h.html#a011bbc41b53a2519b2bb46214b7a1fcc',1,'encodeSeq(char *seq): code.c']]], + ['end',['end',['../struct__segmentStats.html#a4d3d7af903f88c69e687d259590b00a3',1,'_segmentStats']]], + ['endgenomic',['endGenomic',['../struct__segmentStats.html#acf8d8441557c049db6d84d96ed7f7ca3',1,'_segmentStats']]], + ['endsite',['endSite',['../struct__segmentStats.html#af419d597e7393b0e78078eaa842ded6c',1,'_segmentStats']]], + ['eps_5fcutoff_5farg',['eps_cutoff_arg',['../structgengetopt__args__info.html#a7d5c15c092764baac13552613fda575f',1,'gengetopt_args_info']]], + ['eps_5fcutoff_5fgiven',['eps_cutoff_given',['../structgengetopt__args__info.html#a60b5aec84888abe557256b1909b01a01',1,'gengetopt_args_info']]], + ['eps_5fcutoff_5fhelp',['eps_cutoff_help',['../structgengetopt__args__info.html#a32790cf21a0f8e8623371d12deb4b337',1,'gengetopt_args_info']]], + ['eps_5fcutoff_5forig',['eps_cutoff_orig',['../structgengetopt__args__info.html#ad2f45ed857ac6e6d8b1a371d85b65e25',1,'gengetopt_args_info']]], + ['eps_5fdir_5farg',['eps_dir_arg',['../structgengetopt__args__info.html#a29434f1b1030755c24dde59d8c157de5',1,'gengetopt_args_info']]], + ['eps_5fdir_5fgiven',['eps_dir_given',['../structgengetopt__args__info.html#a33c0504245a49e483924248119b400a6',1,'gengetopt_args_info']]], + ['eps_5fdir_5fhelp',['eps_dir_help',['../structgengetopt__args__info.html#a1c676a66f0cf100d49679440032ae4ab',1,'gengetopt_args_info']]], + ['eps_5fdir_5forig',['eps_dir_orig',['../structgengetopt__args__info.html#a7474b0d19ed3f9c13ebc88e6cf652c65',1,'gengetopt_args_info']]], + ['eps_5fflag',['eps_flag',['../structgengetopt__args__info.html#a4c97eb3971c8f9222073e63484872bf0',1,'gengetopt_args_info']]], + ['eps_5fgiven',['eps_given',['../structgengetopt__args__info.html#a9d52e7e979f21f9278bcb39005164a44',1,'gengetopt_args_info']]], + ['eps_5fhelp',['eps_help',['../structgengetopt__args__info.html#aa87d33b8ebe4fa33c6c4b7454c3e7e55',1,'gengetopt_args_info']]], + ['equalfreqs',['equalFreqs',['../treeSimulate_8c.html#a85ef69963901475137a5babcaf4233b3',1,'treeSimulate.c']]], + ['evdmaxlikelyfit',['EVDMaxLikelyFit',['../extreme__fit_8c.html#a51c7409c6447353e0bd3b7c48d982984',1,'EVDMaxLikelyFit(double *x, int *c, int n, double *ret_mu, double *ret_lambda): extreme_fit.c'],['../extreme__fit_8h.html#a51c7409c6447353e0bd3b7c48d982984',1,'EVDMaxLikelyFit(double *x, int *c, int n, double *ret_mu, double *ret_lambda): extreme_fit.c']]], + ['exchange',['exchange',['../getopt_8c.html#a4621659dd6377e52ac50a0869625bb6e',1,'getopt.c']]], + ['extendregion',['extendRegion',['../misc_8c.html#a6017c986a43a1bba1569a8efb1b3aedb',1,'extendRegion(const struct aln *alignment[], int pos, int direction): misc.c'],['../misc_8h.html#a6017c986a43a1bba1569a8efb1b3aedb',1,'extendRegion(const struct aln *alignment[], int pos, int direction): misc.c']]], + ['extreme_5ffit_2ec',['extreme_fit.c',['../extreme__fit_8c.html',1,'']]], + ['extreme_5ffit_2eh',['extreme_fit.h',['../extreme__fit_8h.html',1,'']]] +]; diff --git a/src/html/search/all_6.html b/src/html/search/all_6.html new file mode 100644 index 0000000..6afac06 --- /dev/null +++ b/src/html/search/all_6.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_6.js b/src/html/search/all_6.js new file mode 100644 index 0000000..04af0fc --- /dev/null +++ b/src/html/search/all_6.js @@ -0,0 +1,23 @@ +var searchData= +[ + ['filecopy',['filecopy',['../utils_8c.html#ae3ef8f02d94a4aeaa2050fb210acd3b0',1,'filecopy(FILE *from, FILE *to): utils.c'],['../utils_8h.html#ab213334ce977b6d21611cdea6b80c3bf',1,'filecopy(FILE *from, FILE *to): utils.c']]], + ['first_5fnonopt',['first_nonopt',['../getopt_8c.html#a7b0f4f3bfbee147113f282427ce933ed',1,'getopt.c']]], + ['flag',['flag',['../structoption.html#ab366eea5fe7be25c1928328ba715e353',1,'option']]], + ['fontheight',['fontHeight',['../postscript_8c.html#a8fc5219f9ead102b3596111331374b2f',1,'postscript.c']]], + ['fontwidth',['fontWidth',['../postscript_8c.html#a05a25f17ddf6ed395c481d783d1af2b4',1,'postscript.c']]], + ['frame',['frame',['../struct__segmentStats.html#aaa79b059634ee49ceb65150735dae1dd',1,'_segmentStats']]], + ['free_5fstring_5ffield',['free_string_field',['../cmdline_8c.html#a3a3cc8b020811185cb0a4b96e1ff5a40',1,'cmdline.c']]], + ['freealn',['freeAln',['../rnaz__utils_8c.html#ace5cb65b010161f9eb138717b4592673',1,'freeAln(struct aln *AS[]): rnaz_utils.c'],['../rnaz__utils_8h.html#ace5cb65b010161f9eb138717b4592673',1,'freeAln(struct aln *AS[]): rnaz_utils.c']]], + ['freealnentry',['freeAlnEntry',['../rnaz__utils_8c.html#ac38565a99389ebf0aed62a623d893299',1,'freeAlnEntry(struct aln *entry): rnaz_utils.c'],['../rnaz__utils_8h.html#ac38565a99389ebf0aed62a623d893299',1,'freeAlnEntry(struct aln *entry): rnaz_utils.c']]], + ['freefields',['freeFields',['../rnaz__utils_8c.html#a5afeb493cf63c3077bc7ccc2df25208d',1,'freeFields(char **fields): rnaz_utils.c'],['../rnaz__utils_8h.html#a5afeb493cf63c3077bc7ccc2df25208d',1,'freeFields(char **fields): rnaz_utils.c']]], + ['freemodelmatrix',['freeModelMatrix',['../score_8h.html#a5c86ff30dfac4ac88d64ac6db1c6c559',1,'score.h']]], + ['freemodels',['freeModels',['../RNAcode_8c.html#a303c139a77497eb1282c6d2a4d415c1c',1,'freeModels(bgModel *models, int N): score.c'],['../score_8c.html#a303c139a77497eb1282c6d2a4d415c1c',1,'freeModels(bgModel *models, int N): score.c']]], + ['freeresults',['freeResults',['../misc_8c.html#a71b140f8ccd1190776a6cc04f42f7b0d',1,'freeResults(segmentStats results[]): misc.c'],['../misc_8h.html#a71b140f8ccd1190776a6cc04f42f7b0d',1,'freeResults(segmentStats results[]): misc.c']]], + ['frees',['freeS',['../score_8c.html#ab2954f5929699167062e554323b3ec08',1,'freeS(float **S, const struct aln *alignment[]): score.c'],['../score_8h.html#ab2954f5929699167062e554323b3ec08',1,'freeS(float **S, const struct aln *alignment[]): score.c']]], + ['freescoringmatrix',['freeScoringMatrix',['../score_8c.html#a92e464aeb840be0a3082485f30bd094b',1,'freeScoringMatrix(int **matrix): score.c'],['../score_8h.html#a92e464aeb840be0a3082485f30bd094b',1,'freeScoringMatrix(int **matrix): score.c']]], + ['freeseqgentree',['freeSeqgenTree',['../treeSimulate_8c.html#a0f4d088716aa0dbcb5485641a0be7096',1,'freeSeqgenTree(TTree *tree): treeSimulate.c'],['../treeSimulate_8h.html#a0f4d088716aa0dbcb5485641a0be7096',1,'freeSeqgenTree(TTree *tree): treeSimulate.c']]], + ['freesk',['freeSk',['../score_8c.html#a39c41782e70b3f6d743e3287c015d573',1,'freeSk(float ****S, const struct aln *alignment[]): score.c'],['../score_8h.html#a39c41782e70b3f6d743e3287c015d573',1,'freeSk(float ****S, const struct aln *alignment[]): score.c']]], + ['freqs',['freqs',['../struct__bgModel.html#a906bda936ba864ba209eecff5f1ab721',1,'_bgModel']]], + ['fulllength',['fullLength',['../structaln.html#a483afd3cef94d6713429e91b3ea2f9a9',1,'aln']]], + ['fullseq',['fullSeq',['../structaln.html#ad86e38ddd090ff01a1665db42fe80775',1,'aln']]] +]; diff --git a/src/html/search/all_7.html b/src/html/search/all_7.html new file mode 100644 index 0000000..de19107 --- /dev/null +++ b/src/html/search/all_7.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_7.js b/src/html/search/all_7.js new file mode 100644 index 0000000..f35c69c --- /dev/null +++ b/src/html/search/all_7.js @@ -0,0 +1,34 @@ +var searchData= +[ + ['gaussian',['gaussian',['../misc_8h.html#af625860d4b3644771a9b58a316518d00',1,'misc.h']]], + ['gengetopt_5fargs_5finfo',['gengetopt_args_info',['../structgengetopt__args__info.html',1,'']]], + ['gengetopt_5fargs_5finfo_5fdescription',['gengetopt_args_info_description',['../cmdline_8c.html#accad6107ca685f6eba555f6ce63d355d',1,'cmdline.c']]], + ['gengetopt_5fargs_5finfo_5fhelp',['gengetopt_args_info_help',['../cmdline_8c.html#a6af7a6b7fb37c0abaa916ee1cfa0a41f',1,'gengetopt_args_info_help(): cmdline.c'],['../cmdline_8h.html#a6af7a6b7fb37c0abaa916ee1cfa0a41f',1,'gengetopt_args_info_help(): cmdline.c']]], + ['gengetopt_5fargs_5finfo_5fpurpose',['gengetopt_args_info_purpose',['../cmdline_8c.html#a610c3307abce5a8fd304b86b018ae60b',1,'gengetopt_args_info_purpose(): cmdline.c'],['../cmdline_8h.html#a610c3307abce5a8fd304b86b018ae60b',1,'gengetopt_args_info_purpose(): cmdline.c']]], + ['gengetopt_5fargs_5finfo_5fusage',['gengetopt_args_info_usage',['../cmdline_8c.html#a9f397a306f363bfdebb611e86acf36d5',1,'gengetopt_args_info_usage(): cmdline.c'],['../cmdline_8h.html#a9f397a306f363bfdebb611e86acf36d5',1,'gengetopt_args_info_usage(): cmdline.c']]], + ['gengetopt_5fstrdup',['gengetopt_strdup',['../cmdline_8c.html#a0ec9efd6eb3e6e939fcaaadd8b4c6a9f',1,'cmdline.c']]], + ['get_5fline',['get_line',['../utils_8c.html#a39d4415a69dcce7a8301d38829101d50',1,'get_line(FILE *fp): utils.c'],['../utils_8h.html#a90fb7a370255e405c5384c4332bce847',1,'get_line(const FILE *fp): utils.h']]], + ['get_5fseq_5flocal',['Get_Seq_local',['../treeML_8c.html#a8a90f2586451905454dd568da9a0f759',1,'treeML.c']]], + ['getblock',['getBlock',['../misc_8c.html#a9fe543fe19ab3ff4ae9def519e1f0ac1',1,'getBlock(int i, const char *seq_0, const char *seq_k, const int *map_0, const int *map_k, char *block_0, char *block_k, int *z): misc.c'],['../misc_8h.html#a9fe543fe19ab3ff4ae9def519e1f0ac1',1,'getBlock(int i, const char *seq_0, const char *seq_k, const int *map_0, const int *map_k, char *block_0, char *block_k, int *z): misc.c']]], + ['getcumsum',['getCumSum',['../score_8h.html#ae5aac97ccd98fa3231294f3677204992',1,'score.h']]], + ['getdistancematrix',['getDistanceMatrix',['../treeSimulate_8c.html#a684681e84edaa63e768ec7ad1ff4884f',1,'getDistanceMatrix(TTree *tree, struct aln *alignment[]): treeSimulate.c'],['../treeSimulate_8h.html#a684681e84edaa63e768ec7ad1ff4884f',1,'getDistanceMatrix(TTree *tree, struct aln *alignment[]): treeSimulate.c']]], + ['getenv',['getenv',['../getopt_8c.html#aee28fd8a0e40b6d958f7d20348e45368',1,'getopt.c']]], + ['getextremevaluepars',['getExtremeValuePars',['../score_8c.html#aa313efebb5f1c1c987e98178c1668452',1,'getExtremeValuePars(TTree *tree, const struct aln *alignment[], int sampleN, float maxNativeScore, float *parMu, float *parLambda): score.c'],['../score_8h.html#aa313efebb5f1c1c987e98178c1668452',1,'getExtremeValuePars(TTree *tree, const struct aln *alignment[], int sampleN, float maxNativeScore, float *parMu, float *parLambda): score.c']]], + ['gethss',['getHSS',['../score_8c.html#a93045a86d8c050d38eed9c213ced83c7',1,'getHSS(float **S, const struct aln **inputAln, char strand): score.c'],['../score_8h.html#a93045a86d8c050d38eed9c213ced83c7',1,'getHSS(float **S, const struct aln **inputAln, char strand): score.c']]], + ['getlca',['getLCA',['../treeSimulate_8c.html#a3d5dbc026864385b3c931c928110b32a',1,'getLCA(TTree *tree, TNode *nodeA, TNode *nodeB): treeSimulate.c'],['../treeSimulate_8h.html#a3d5dbc026864385b3c931c928110b32a',1,'getLCA(TTree *tree, TNode *nodeA, TNode *nodeB): treeSimulate.c']]], + ['getmodelmatrix',['getModelMatrix',['../score_8h.html#a909825ebbd6f4923c4e425186001f095',1,'score.h']]], + ['getmodels',['getModels',['../score_8c.html#ad5c373a610e54d23a1cb8500d2634e9b',1,'getModels(TTree *tree, struct aln *alignment[], float kappa): score.c'],['../score_8h.html#ad5c373a610e54d23a1cb8500d2634e9b',1,'getModels(TTree *tree, struct aln *alignment[], float kappa): score.c']]], + ['getmultiplescorematrix',['getMultipleScoreMatrix',['../score_8c.html#af6b84950cd47402f4580d56eb22854fd',1,'getMultipleScoreMatrix(float ****Sk, bgModel *models, const struct aln *alignment[]): score.c'],['../score_8h.html#af6b84950cd47402f4580d56eb22854fd',1,'getMultipleScoreMatrix(float ****Sk, bgModel *models, const struct aln *alignment[]): score.c']]], + ['getopt',['getopt',['../getopt_8c.html#a1b2ada39ab92162c6ec9c67c8093fa2e',1,'getopt(int argc, char *const *argv, const char *optstring): getopt.c'],['../getopt_8h.html#a6c5b232cca42dab05f40b47f69715f8b',1,'getopt(): getopt.h']]], + ['getopt_2ec',['getopt.c',['../getopt_8c.html',1,'']]], + ['getopt_2eh',['getopt.h',['../getopt_8h.html',1,'']]], + ['getopt_5finterface_5fversion',['GETOPT_INTERFACE_VERSION',['../getopt_8c.html#a5325c715897861c318d3ae312ac452cc',1,'getopt.c']]], + ['getopt_5flong',['getopt_long',['../getopt_8h.html#a8616b8a74ae6c01a7ad95ad2876226ec',1,'getopt.h']]], + ['getopt_5flong_5fonly',['getopt_long_only',['../getopt_8h.html#ac07930413317507d5c51c19b3ac6ed20',1,'getopt.h']]], + ['getpairwisescorematrix',['getPairwiseScoreMatrix',['../score_8c.html#a6589227c4b47c35cca34ecc18c7f9634',1,'getPairwiseScoreMatrix(bgModel *models, const struct aln *alignment[]): score.c'],['../score_8h.html#a6589227c4b47c35cca34ecc18c7f9634',1,'getPairwiseScoreMatrix(bgModel *models, const struct aln *alignment[]): score.c']]], + ['getscoringmatrix',['getScoringMatrix',['../score_8c.html#a5deb0fecb3a13330879241f24575ac6c',1,'getScoringMatrix(): score.c'],['../score_8h.html#a5deb0fecb3a13330879241f24575ac6c',1,'getScoringMatrix(): score.c']]], + ['getseqlength',['getSeqLength',['../misc_8c.html#a935b3901ff2b656c44257b4606ceab6c',1,'getSeqLength(char *seq): misc.c'],['../misc_8h.html#a935b3901ff2b656c44257b4606ceab6c',1,'getSeqLength(char *seq): misc.c']]], + ['gtf_5fflag',['gtf_flag',['../structgengetopt__args__info.html#a3cc76992b00eb5f69d49ecabfa65de28',1,'gengetopt_args_info']]], + ['gtf_5fgiven',['gtf_given',['../structgengetopt__args__info.html#a0e6e111149cf2a4bc171c80ee4055f8e',1,'gengetopt_args_info']]], + ['gtf_5fhelp',['gtf_help',['../structgengetopt__args__info.html#a7eb6417bded13cc26a47a1ee53bcb8dc',1,'gengetopt_args_info']]] +]; diff --git a/src/html/search/all_8.html b/src/html/search/all_8.html new file mode 100644 index 0000000..11e27cd --- /dev/null +++ b/src/html/search/all_8.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_8.js b/src/html/search/all_8.js new file mode 100644 index 0000000..f07721e --- /dev/null +++ b/src/html/search/all_8.js @@ -0,0 +1,11 @@ +var searchData= +[ + ['hamming',['hamming',['../utils_8c.html#aad87a2700e9dcc28f48007ba3927f80e',1,'hamming(const char *s1, const char *s2): utils.c'],['../utils_8h.html#ad9dc7bfc9aa664dc6698f17ce07fc7e7',1,'hamming(const char *s1, const char *s2): utils.c']]], + ['has_5farg',['has_arg',['../structoption.html#a90d7ee9a51eea5c002682dbd0af149e4',1,'option']]], + ['hdist',['hDist',['../misc_8c.html#a62dbd6f5f78b8829c91c5e373b897f67',1,'hDist(int a1, int a2, int a3, int b1, int b2, int b3): misc.c'],['../misc_8h.html#a62dbd6f5f78b8829c91c5e373b897f67',1,'hDist(int a1, int a2, int a3, int b1, int b2, int b3): misc.c']]], + ['help',['help',['../RNAcode_8c.html#a0bed8474bd33a912769360766f6b10d4',1,'help(void): RNAcode.c'],['../RNAcode_8h.html#a0bed8474bd33a912769360766f6b10d4',1,'help(void): RNAcode.c']]], + ['help_5fgiven',['help_given',['../structgengetopt__args__info.html#ab9fd677f890731fd7d6f6c62e6dfc99c',1,'gengetopt_args_info']]], + ['help_5fhelp',['help_help',['../structgengetopt__args__info.html#afb4efa68a6f43a4d112e9b96ffe89101',1,'gengetopt_args_info']]], + ['hide',['hide',['../struct__segmentStats.html#a7db5f703ed1ff2f2105f756cb79eaecf',1,'_segmentStats']]], + ['hitcounter',['hitCounter',['../misc_8c.html#a8c5872fcd4604b525d509ffd6afc5631',1,'hitCounter(): RNAcode.c'],['../RNAcode_8c.html#a8c5872fcd4604b525d509ffd6afc5631',1,'hitCounter(): RNAcode.c']]] +]; diff --git a/src/html/search/all_9.html b/src/html/search/all_9.html new file mode 100644 index 0000000..f8abbbe --- /dev/null +++ b/src/html/search/all_9.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_9.js b/src/html/search/all_9.js new file mode 100644 index 0000000..f854620 --- /dev/null +++ b/src/html/search/all_9.js @@ -0,0 +1,14 @@ +var searchData= +[ + ['imageheight',['imageHeight',['../postscript_8c.html#a97b51530ccb867cc13f911e57be3a559',1,'postscript.c']]], + ['imagewidth',['imageWidth',['../postscript_8c.html#a056677386b85246c5b6f9de91327868c',1,'postscript.c']]], + ['init_5fargs_5finfo',['init_args_info',['../cmdline_8c.html#a4dcfd361cdaac143739a02102296fedd',1,'cmdline.c']]], + ['init_5frand',['init_rand',['../utils_8c.html#ade17b35078a34c6d26b09148c6f81f4d',1,'init_rand(void): utils.c'],['../utils_8h.html#a8aaa6d9be6f803f496d9b97375c371f3',1,'init_rand(void): utils.c']]], + ['initialize',['initialize',['../structcmdline__parser__params.html#a97ed8a6eabd39291ae7d73f273e12c11',1,'cmdline_parser_params']]], + ['inputfile',['inputFile',['../struct__parameters.html#a37a15ced629242ecdf8a8ccf9f49d81b',1,'_parameters']]], + ['inputfilename',['inputFileName',['../struct__parameters.html#a1b9b47e6f58186d767de1d34d956b516',1,'_parameters']]], + ['inputs',['inputs',['../structgengetopt__args__info.html#a9604690019dd09b318302dae6868726c',1,'gengetopt_args_info']]], + ['inputs_5fnum',['inputs_num',['../structgengetopt__args__info.html#a3d69c180d5ac0b1124fd9a6fe680706c',1,'gengetopt_args_info']]], + ['int_5furn',['int_urn',['../utils_8c.html#af0a9bc3a6894eea7895d5cdf825bccd6',1,'int_urn(int from, int to): utils.c'],['../utils_8h.html#a68ff0849d44f62fe491800378a5ffcb4',1,'int_urn(int from, int to): utils.c']]], + ['isnucmodel',['isNucModel',['../treeSimulate_8c.html#a72e05eb4637bf2f93aa05f211b1a57b2',1,'treeSimulate.c']]] +]; diff --git a/src/html/search/all_a.html b/src/html/search/all_a.html new file mode 100644 index 0000000..9601fce --- /dev/null +++ b/src/html/search/all_a.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_a.js b/src/html/search/all_a.js new file mode 100644 index 0000000..f8a6e15 --- /dev/null +++ b/src/html/search/all_a.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['kappa',['kappa',['../struct__bgModel.html#a251b8c86d6c01c5f1813c37df31c3096',1,'_bgModel']]] +]; diff --git a/src/html/search/all_b.html b/src/html/search/all_b.html new file mode 100644 index 0000000..0814e4e --- /dev/null +++ b/src/html/search/all_b.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_b.js b/src/html/search/all_b.js new file mode 100644 index 0000000..e83f622 --- /dev/null +++ b/src/html/search/all_b.js @@ -0,0 +1,14 @@ +var searchData= +[ + ['last_5fnonopt',['last_nonopt',['../getopt_8c.html#a580f2c2acf35dad51ca18b427212bf15',1,'getopt.c']]], + ['lawless416',['Lawless416',['../extreme__fit_8c.html#ac7d28c2cfa789de3864ed5d07ef800ec',1,'extreme_fit.c']]], + ['lawless422',['Lawless422',['../extreme__fit_8c.html#a05c76c8801e372734c3888b165c28f86',1,'extreme_fit.c']]], + ['length',['length',['../structaln.html#ad03a776f899ce00d63827146906ab6b4',1,'aln::length()'],['../postscript_8c.html#a9f59b34b1f25fe00023291b678246bcc',1,'length(): postscript.c']]], + ['limit',['limit',['../struct__parameters.html#ab9f7cf2359b590f2476fff80a85aff43',1,'_parameters']]], + ['limit_5farg',['limit_arg',['../structgengetopt__args__info.html#afe75799aec30a1011e3f65a93538eb88',1,'gengetopt_args_info']]], + ['limit_5fgiven',['limit_given',['../structgengetopt__args__info.html#a1058bb49a05830b377b2335d9ae1c7c9',1,'gengetopt_args_info']]], + ['limit_5fhelp',['limit_help',['../structgengetopt__args__info.html#ac54bb7e91539b98c4d0756254880b4ee',1,'gengetopt_args_info']]], + ['limit_5forig',['limit_orig',['../structgengetopt__args__info.html#a77bc7cac390e1901106ad9c70e04b9aa',1,'gengetopt_args_info']]], + ['linestep',['lineStep',['../postscript_8c.html#a47c6c3302e0a9d686ba540869d4f3688',1,'postscript.c']]], + ['linsys',['linsys',['../weight_8c.html#a938fd9f0d302e85abaed502179b51275',1,'linsys(float **a, float *b, int N): weight.c'],['../weight_8h.html#a938fd9f0d302e85abaed502179b51275',1,'linsys(float **a, float *b, int N): weight.c']]] +]; diff --git a/src/html/search/all_c.html b/src/html/search/all_c.html new file mode 100644 index 0000000..da08c38 --- /dev/null +++ b/src/html/search/all_c.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_c.js b/src/html/search/all_c.js new file mode 100644 index 0000000..8ddeb3a --- /dev/null +++ b/src/html/search/all_c.js @@ -0,0 +1,22 @@ +var searchData= +[ + ['maf',['MAF',['../rnaz__utils_8h.html#ad849a5b1ae21b9dd57228a7cc706a189a2d41a0476d221862995d2a0a02f6b3b3',1,'rnaz_utils.h']]], + ['main',['main',['../RNAcode_8c.html#a0ddf1224851353fc92bfbff6f499fa97',1,'RNAcode.c']]], + ['make_5fpair_5ftable',['make_pair_table',['../utils_8c.html#a84f42ca126d57c91364fde04b622b014',1,'make_pair_table(const char *structure): utils.c'],['../utils_8h.html#a89c32307ee50a0026f4a3131fac0845a',1,'make_pair_table(const char *structure): utils.c']]], + ['matrix',['matrix',['../struct__bgModel.html#a6843a94f9717bd58819c3fbffe9fbe56',1,'_bgModel']]], + ['max',['MAX',['../score_8h.html#aacc3ee1a7f283f8ef65cea31f4436a95',1,'score.h']]], + ['max3',['MAX3',['../score_8h.html#a7751a16322c502dc5d35d620b69277af',1,'score.h']]], + ['max_5fnum_5fnames',['MAX_NUM_NAMES',['../rnaz__utils_8h.html#a9b65dc832210814414fe462bbafba8b8',1,'rnaz_utils.h']]], + ['maxconsbar',['maxConsBar',['../postscript_8c.html#a0c4c0a1f79429ea034c156318b576175',1,'postscript.c']]], + ['maxname',['maxName',['../postscript_8c.html#a04c4ce9dea57def69ca277c748f1ec4a',1,'postscript.c']]], + ['maxnum',['maxNum',['../postscript_8c.html#af4b91d5ea883f66de1f385aee64a0d5f',1,'postscript.c']]], + ['meanpairid',['meanPairID',['../rnaz__utils_8c.html#a802470f11cb32abaa510b2c67f098235',1,'meanPairID(const struct aln *AS[]): rnaz_utils.c'],['../rnaz__utils_8h.html#a802470f11cb32abaa510b2c67f098235',1,'meanPairID(const struct aln *AS[]): rnaz_utils.c']]], + ['min2',['MIN2',['../rnaz__utils_8h.html#ae0b9cd0ce090bd69b951aa73e8fa4f7d',1,'rnaz_utils.h']]], + ['minus_5finf',['MINUS_INF',['../score_8h.html#aa48b28e62c168ecef26792b023bedb09',1,'score.h']]], + ['misc_2ec',['misc.c',['../misc_8c.html',1,'']]], + ['misc_2eh',['misc.h',['../misc_8h.html',1,'']]], + ['model',['model',['../treeSimulate_8c.html#a027a1f1731d22465c926ce57be2364c3',1,'treeSimulate.c']]], + ['models',['models',['../RNAcode_8c.html#a2351b02aa48f9f78d350b4b19408d38f',1,'models(): RNAcode.c'],['../score_8c.html#a2351b02aa48f9f78d350b4b19408d38f',1,'models(): RNAcode.c']]], + ['modelsrev',['modelsRev',['../RNAcode_8c.html#aa758f546869f82fa894aeeab59fc8a4f',1,'modelsRev(): RNAcode.c'],['../score_8c.html#a63827dfbc95488762e66ea061bc89afd',1,'modelsRev(): RNAcode.c']]], + ['my_5findex',['my_index',['../getopt_8c.html#ae0ac978b7775f69496c0f127ffdada9d',1,'getopt.c']]] +]; diff --git a/src/html/search/all_d.html b/src/html/search/all_d.html new file mode 100644 index 0000000..9986c9c --- /dev/null +++ b/src/html/search/all_d.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_d.js b/src/html/search/all_d.js new file mode 100644 index 0000000..a5c17f0 --- /dev/null +++ b/src/html/search/all_d.js @@ -0,0 +1,20 @@ +var searchData= +[ + ['name',['name',['../structoption.html#a92c850a23c7828c1dba453bf8d15e1f0',1,'option::name()'],['../structaln.html#af655f033b20fc2f4361576240cac2c0f',1,'aln::name()'],['../struct__segmentStats.html#aea84cdd90979dc3c173424166ef8d532',1,'_segmentStats::name()']]], + ['namestep',['nameStep',['../postscript_8c.html#a7b9ed0953c4c3a72b4763f3913467d83',1,'postscript.c']]], + ['namesx',['namesX',['../postscript_8c.html#ab9e364a4cf29b5aad82e7ec316ac09e9',1,'postscript.c']]], + ['nextchar',['nextchar',['../getopt_8c.html#a47a40a4c365dae45f94751ad32aab530',1,'getopt.c']]], + ['no_5fargument',['no_argument',['../getopt_8h.html#a3bc1d5f667b5b4ca4b4abb685dc874ce',1,'getopt.h']]], + ['nonoption_5fp',['NONOPTION_P',['../getopt_8c.html#a71ceb8911d64b39b402041ba5ea8453c',1,'getopt.c']]], + ['nrerror',['nrerror',['../utils_8c.html#a93e5a2447f559f7930054555a4252ccd',1,'nrerror(const char message[]): utils.c'],['../utils_8h.html#a127ce946e56b5a5773781cabe68e38c5',1,'nrerror(const char message[]): utils.c']]], + ['ntmap',['ntMap',['../score_8h.html#a5eb739b80c0e44d631e8cd4b317ea39e',1,'score.h']]], + ['nucfreq',['nucFreq',['../treeSimulate_8c.html#a720f633590f8f9d192891d52735cfcce',1,'treeSimulate.c']]], + ['num_5fsamples_5farg',['num_samples_arg',['../structgengetopt__args__info.html#ac62c13305dd12c4d426aeb82b6e4561b',1,'gengetopt_args_info']]], + ['num_5fsamples_5fgiven',['num_samples_given',['../structgengetopt__args__info.html#a26d6c50dc3b78c9194509a8399d62888',1,'gengetopt_args_info']]], + ['num_5fsamples_5fhelp',['num_samples_help',['../structgengetopt__args__info.html#a1c4039a0fea549c7db4b2c62482179f8',1,'gengetopt_args_info']]], + ['num_5fsamples_5forig',['num_samples_orig',['../structgengetopt__args__info.html#a043409e12989cdbf8cd34fa47f8c6a4c',1,'gengetopt_args_info']]], + ['numberstep',['numberStep',['../postscript_8c.html#ab2e008e977e58c17747a69818f653584',1,'postscript.c']]], + ['numsites',['numSites',['../treeSimulate_8c.html#a13ffae79c3c34f8e30570d5baf7641b0',1,'treeSimulate.c']]], + ['numstates',['numStates',['../treeSimulate_8c.html#a39cc268c324972ce5653c35bdc8aa80f',1,'treeSimulate.c']]], + ['numtaxa',['numTaxa',['../treeSimulate_8c.html#a3893608bdd239b0b3b47338282608791',1,'treeSimulate.c']]] +]; diff --git a/src/html/search/all_e.html b/src/html/search/all_e.html new file mode 100644 index 0000000..9fa42bb --- /dev/null +++ b/src/html/search/all_e.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_e.js b/src/html/search/all_e.js new file mode 100644 index 0000000..6657749 --- /dev/null +++ b/src/html/search/all_e.js @@ -0,0 +1,19 @@ +var searchData= +[ + ['omega',['omega',['../struct__parameters.html#a8f69e384c5cc468de9c3c527bd9a3722',1,'_parameters::omega()'],['../struct__parameters.html#ab9173ba4e45a417ed8e7317699b5c77c',1,'_parameters::Omega()']]], + ['optarg',['optarg',['../getopt_8c.html#adb50a0eab9fed92fc3bfc7dfa4f2c410',1,'optarg(): getopt.c'],['../getopt_8h.html#adb50a0eab9fed92fc3bfc7dfa4f2c410',1,'optarg(): getopt.c']]], + ['opterr',['opterr',['../getopt_8c.html#ae30f05ee1e2e5652f174a35c7875d25e',1,'opterr(): getopt.c'],['../getopt_8h.html#ae30f05ee1e2e5652f174a35c7875d25e',1,'opterr(): getopt.c']]], + ['optind',['optind',['../getopt_8c.html#ad5e1c16213bbee2d5e8cc363309f418c',1,'optind(): getopt.c'],['../getopt_8h.html#ad5e1c16213bbee2d5e8cc363309f418c',1,'optind(): getopt.c']]], + ['option',['option',['../structoption.html',1,'']]], + ['optional_5fargument',['optional_argument',['../getopt_8h.html#acca06c0a947656bd8b395bf1084ffb72',1,'getopt.h']]], + ['optopt',['optopt',['../getopt_8c.html#a475b8db98445da73e5f62a1ef6324b95',1,'optopt(): getopt.c'],['../getopt_8h.html#a475b8db98445da73e5f62a1ef6324b95',1,'optopt(): getopt.c']]], + ['ordering',['ordering',['../getopt_8c.html#a67a84cf4dacaa8337be68345f8b9a8cc',1,'getopt.c']]], + ['outfile',['outfile',['../postscript_8c.html#ae581849c67336453bd5b81e6518019a9',1,'postscript.c']]], + ['outfile_5farg',['outfile_arg',['../structgengetopt__args__info.html#ab9e3d63af39beb195c0ce4b30628475b',1,'gengetopt_args_info']]], + ['outfile_5fgiven',['outfile_given',['../structgengetopt__args__info.html#af6f058929187956cb68a0192b866f942',1,'gengetopt_args_info']]], + ['outfile_5fhelp',['outfile_help',['../structgengetopt__args__info.html#ae7d54ef8556b73161c14a77b20fe321f',1,'gengetopt_args_info']]], + ['outfile_5forig',['outfile_orig',['../structgengetopt__args__info.html#a39782404c00e6f9107f8fdcae948222f',1,'gengetopt_args_info']]], + ['outputfile',['outputFile',['../struct__parameters.html#a683e0de09c9d45e219db06753f89bc7e',1,'_parameters']]], + ['outputformat',['outputFormat',['../struct__parameters.html#a37dadb0f3fa7deca9cdc43797cc0ff5b',1,'_parameters']]], + ['override',['override',['../structcmdline__parser__params.html#ad3ff9d69146e69a47506782197b5675c',1,'cmdline_parser_params']]] +]; diff --git a/src/html/search/all_f.html b/src/html/search/all_f.html new file mode 100644 index 0000000..6ecfc0e --- /dev/null +++ b/src/html/search/all_f.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/all_f.js b/src/html/search/all_f.js new file mode 100644 index 0000000..e04d2d7 --- /dev/null +++ b/src/html/search/all_f.js @@ -0,0 +1,35 @@ +var searchData= +[ + ['p',['P',['../treeSimulate_8c.html#aed2d481a3756e5431b6d0e26b1d4b246',1,'treeSimulate.c']]], + ['pack_5fstructure',['pack_structure',['../utils_8c.html#aa3a18376e73375f7ccb0abc90d162a02',1,'pack_structure(const char *struc): utils.c'],['../utils_8h.html#ac6dfa5e22928c087c6e09ff0054a7ced',1,'pack_structure(const char *struc): utils.c']]], + ['package_5fname',['package_name',['../cmdline_8c.html#a08f16a026de44b77c5e7be490fb9e32b',1,'cmdline.c']]], + ['parameters',['parameters',['../RNAcode_8h.html#ac21aeabbefffddb27496994611a09dcd',1,'RNAcode.h']]], + ['pars',['pars',['../misc_8c.html#a8dea3b88a171ed8de9f8f98079e7561a',1,'pars(): RNAcode.c'],['../RNAcode_8c.html#a8dea3b88a171ed8de9f8f98079e7561a',1,'pars(): RNAcode.c'],['../score_8c.html#a8dea3b88a171ed8de9f8f98079e7561a',1,'pars(): RNAcode.c']]], + ['pars_5farg',['pars_arg',['../structgengetopt__args__info.html#a965c61281e9339738647ff5e44604d8b',1,'gengetopt_args_info']]], + ['pars_5fgiven',['pars_given',['../structgengetopt__args__info.html#abaf16e517f88e5ad41e06e0584045074',1,'gengetopt_args_info']]], + ['pars_5fhelp',['pars_help',['../structgengetopt__args__info.html#aacd28fcc4238ef2516cca7526df79533',1,'gengetopt_args_info']]], + ['pars_5forig',['pars_orig',['../structgengetopt__args__info.html#a2c6837447e74b77af713002cdb58949b',1,'gengetopt_args_info']]], + ['permute',['PERMUTE',['../getopt_8c.html#a06fc87d81c62e9abb8790b6e5713c55bacfdde4b47c27f4efbd832e1ac7f8a8fc',1,'getopt.c']]], + ['phyml',['PHYML',['../treeML_8h.html#a881b73a915d74c35b5bdae930066e817',1,'treeML.h']]], + ['pos2col',['pos2col',['../misc_8c.html#af49091737065e3ea21101edf17533dcf',1,'pos2col(const char *seq, int pos): misc.c'],['../misc_8h.html#af49091737065e3ea21101edf17533dcf',1,'pos2col(const char *seq, int pos): misc.c']]], + ['posixly_5fcorrect',['posixly_correct',['../getopt_8c.html#ad0ccb64bbd4defe7a57dbad2045ddd14',1,'getopt.c']]], + ['postscript',['postscript',['../struct__parameters.html#a7080180324a5b3081e85eb308d2d530c',1,'_parameters']]], + ['postscript_2ec',['postscript.c',['../postscript_8c.html',1,'']]], + ['postscript_2eh',['postscript.h',['../postscript_8h.html',1,'']]], + ['postscript_5fcutoff',['postscript_cutoff',['../struct__parameters.html#a796cc87fce657443f51845fd1098f0df',1,'_parameters']]], + ['postscriptdir',['postscriptDir',['../struct__parameters.html#a6c33be73b16d623ca8e5af964d248424',1,'_parameters']]], + ['print_5ferrors',['print_errors',['../structcmdline__parser__params.html#a3236f066777488e8502abe05ccd24455',1,'cmdline_parser_params']]], + ['print_5fhelp_5fcommon',['print_help_common',['../cmdline_8c.html#ad600bb9026825a295ea57df22bdf7eca',1,'cmdline.c']]], + ['printaln',['printAln',['../rnaz__utils_8c.html#ad1830dc656474e2da129e5322927ee15',1,'printAln(const struct aln *AS[]): rnaz_utils.c'],['../rnaz__utils_8h.html#ad1830dc656474e2da129e5322927ee15',1,'printAln(const struct aln *AS[]): rnaz_utils.c']]], + ['printalnclustal',['printAlnClustal',['../misc_8c.html#a622e2235405d5fce48465d284271642c',1,'printAlnClustal(FILE *out, const struct aln *AS[]): misc.c'],['../misc_8h.html#a622e2235405d5fce48465d284271642c',1,'printAlnClustal(FILE *out, const struct aln *AS[]): misc.c']]], + ['printalnmaf',['printAlnMAF',['../rnaz__utils_8c.html#a7dc7886bc41a49ff0a19e67451026d81',1,'printAlnMAF(FILE *out, const struct aln *AS[], int printU): rnaz_utils.c'],['../rnaz__utils_8h.html#a7dc7886bc41a49ff0a19e67451026d81',1,'printAlnMAF(FILE *out, const struct aln *AS[], int printU): rnaz_utils.c']]], + ['printifabove',['printIfAbove',['../struct__parameters.html#aa9034282619631f32acd19230990ea6e',1,'_parameters']]], + ['printifbelow',['printIfBelow',['../struct__parameters.html#ad73fc37c8e5f6964149f12899200472b',1,'_parameters']]], + ['printresults',['printResults',['../misc_8c.html#a326b72f1de05ef655a3188af0af23aee',1,'printResults(FILE *outfile, int outputFormat, const struct aln *inputAln[], segmentStats results[]): misc.c'],['../misc_8h.html#a92f776363f89ffb2864dc72fa7c8471f',1,'printResults(FILE *outfile, int outputFormat, const struct aln *AS[], segmentStats results[]): misc.c']]], + ['private',['PRIVATE',['../rnaz__utils_8h.html#a5e151c615eda34903514212f05a5ccf8',1,'PRIVATE(): rnaz_utils.h'],['../utils_8c.html#a5e151c615eda34903514212f05a5ccf8',1,'PRIVATE(): utils.c']]], + ['probhky',['probHKY',['../score_8c.html#a10a41c7b92952d470f0f8d2af7bd2c1b',1,'probHKY(int i, int j, float d, float freqs[4], float kappa): score.c'],['../score_8h.html#a10a41c7b92952d470f0f8d2af7bd2c1b',1,'probHKY(int i, int j, float d, float freqs[4], float kappa): score.c']]], + ['probs',['probs',['../struct__bgModel.html#ac106ea61c120d4a60f38c98a97254f49',1,'_bgModel']]], + ['prunealn',['pruneAln',['../rnaz__utils_8c.html#a121bcc17b926e5be6edd36caea0a8985',1,'pruneAln(char *species, struct aln *alignment[]): rnaz_utils.c'],['../rnaz__utils_8h.html#a4dbf87f40603a4c37ccb6e312f7ee4fb',1,'pruneAln(char *species, struct aln *AS[]): rnaz_utils.c']]], + ['public',['PUBLIC',['../utils_8c.html#ad17d551e31d1828c68acf40684849b7e',1,'utils.c']]], + ['pvalue',['pvalue',['../struct__segmentStats.html#a36c8958e60d5f733eb6b3bc0e178ad61',1,'_segmentStats']]] +]; diff --git a/src/html/search/classes_0.html b/src/html/search/classes_0.html new file mode 100644 index 0000000..1c3e406 --- /dev/null +++ b/src/html/search/classes_0.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/classes_0.js b/src/html/search/classes_0.js new file mode 100644 index 0000000..6a7c396 --- /dev/null +++ b/src/html/search/classes_0.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['_5fbacktrackdata',['_backtrackData',['../struct__backtrackData.html',1,'']]], + ['_5fbgmodel',['_bgModel',['../struct__bgModel.html',1,'']]], + ['_5fparameters',['_parameters',['../struct__parameters.html',1,'']]], + ['_5fsegmentstats',['_segmentStats',['../struct__segmentStats.html',1,'']]] +]; diff --git a/src/html/search/classes_1.html b/src/html/search/classes_1.html new file mode 100644 index 0000000..a8e7069 --- /dev/null +++ b/src/html/search/classes_1.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/classes_1.js b/src/html/search/classes_1.js new file mode 100644 index 0000000..1d8e48d --- /dev/null +++ b/src/html/search/classes_1.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['aln',['aln',['../structaln.html',1,'']]] +]; diff --git a/src/html/search/classes_2.html b/src/html/search/classes_2.html new file mode 100644 index 0000000..5c09c96 --- /dev/null +++ b/src/html/search/classes_2.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/classes_2.js b/src/html/search/classes_2.js new file mode 100644 index 0000000..8a5b2ad --- /dev/null +++ b/src/html/search/classes_2.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['cmdline_5fparser_5fparams',['cmdline_parser_params',['../structcmdline__parser__params.html',1,'']]] +]; diff --git a/src/html/search/classes_3.html b/src/html/search/classes_3.html new file mode 100644 index 0000000..5faaeba --- /dev/null +++ b/src/html/search/classes_3.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/classes_3.js b/src/html/search/classes_3.js new file mode 100644 index 0000000..0589714 --- /dev/null +++ b/src/html/search/classes_3.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['gengetopt_5fargs_5finfo',['gengetopt_args_info',['../structgengetopt__args__info.html',1,'']]] +]; diff --git a/src/html/search/classes_4.html b/src/html/search/classes_4.html new file mode 100644 index 0000000..b3f11bc --- /dev/null +++ b/src/html/search/classes_4.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/classes_4.js b/src/html/search/classes_4.js new file mode 100644 index 0000000..5a57c93 --- /dev/null +++ b/src/html/search/classes_4.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['option',['option',['../structoption.html',1,'']]] +]; diff --git a/src/html/search/close.png b/src/html/search/close.png new file mode 100644 index 0000000..9342d3d Binary files /dev/null and b/src/html/search/close.png differ diff --git a/src/html/search/defines_0.html b/src/html/search/defines_0.html new file mode 100644 index 0000000..5b25204 --- /dev/null +++ b/src/html/search/defines_0.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/defines_0.js b/src/html/search/defines_0.js new file mode 100644 index 0000000..046221f --- /dev/null +++ b/src/html/search/defines_0.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['_5f',['_',['../getopt_8c.html#a86a239addea586602343007a370bf8ad',1,'getopt.c']]], + ['_5fgetopt_5fh',['_GETOPT_H',['../getopt_8h.html#aaafc27a0389aa87797164b227566342d',1,'getopt.h']]], + ['_5fno_5fproto',['_NO_PROTO',['../getopt_8c.html#a9bcd7db9771ff03b7e5a9fec9c489861',1,'getopt.c']]] +]; diff --git a/src/html/search/defines_1.html b/src/html/search/defines_1.html new file mode 100644 index 0000000..91488cb --- /dev/null +++ b/src/html/search/defines_1.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/defines_1.js b/src/html/search/defines_1.js new file mode 100644 index 0000000..55d4ca9 --- /dev/null +++ b/src/html/search/defines_1.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['cmdline_5fparser_5fpackage',['CMDLINE_PARSER_PACKAGE',['../cmdline_8h.html#aeb847973552c32bcbe5f14973a0a8a32',1,'cmdline.h']]], + ['cmdline_5fparser_5fversion',['CMDLINE_PARSER_VERSION',['../cmdline_8h.html#a1eeca7dc254bf6867ba9635f45771471',1,'cmdline.h']]], + ['cmp',['CMP',['../score_8h.html#afb073915b50e7112cfed534aff6524cf',1,'score.h']]], + ['const',['const',['../getopt_8c.html#a2c212835823e3c54a8ab6d95c652660e',1,'getopt.c']]] +]; diff --git a/src/html/search/defines_2.html b/src/html/search/defines_2.html new file mode 100644 index 0000000..8655993 --- /dev/null +++ b/src/html/search/defines_2.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/defines_2.js b/src/html/search/defines_2.js new file mode 100644 index 0000000..2a6daff --- /dev/null +++ b/src/html/search/defines_2.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['getopt_5finterface_5fversion',['GETOPT_INTERFACE_VERSION',['../getopt_8c.html#a5325c715897861c318d3ae312ac452cc',1,'getopt.c']]] +]; diff --git a/src/html/search/defines_3.html b/src/html/search/defines_3.html new file mode 100644 index 0000000..a55d3ff --- /dev/null +++ b/src/html/search/defines_3.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/defines_3.js b/src/html/search/defines_3.js new file mode 100644 index 0000000..d34f7a3 --- /dev/null +++ b/src/html/search/defines_3.js @@ -0,0 +1,8 @@ +var searchData= +[ + ['max',['MAX',['../score_8h.html#aacc3ee1a7f283f8ef65cea31f4436a95',1,'score.h']]], + ['max3',['MAX3',['../score_8h.html#a7751a16322c502dc5d35d620b69277af',1,'score.h']]], + ['max_5fnum_5fnames',['MAX_NUM_NAMES',['../rnaz__utils_8h.html#a9b65dc832210814414fe462bbafba8b8',1,'rnaz_utils.h']]], + ['min2',['MIN2',['../rnaz__utils_8h.html#ae0b9cd0ce090bd69b951aa73e8fa4f7d',1,'rnaz_utils.h']]], + ['minus_5finf',['MINUS_INF',['../score_8h.html#aa48b28e62c168ecef26792b023bedb09',1,'score.h']]] +]; diff --git a/src/html/search/defines_4.html b/src/html/search/defines_4.html new file mode 100644 index 0000000..54da39a --- /dev/null +++ b/src/html/search/defines_4.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/defines_4.js b/src/html/search/defines_4.js new file mode 100644 index 0000000..21a966c --- /dev/null +++ b/src/html/search/defines_4.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['no_5fargument',['no_argument',['../getopt_8h.html#a3bc1d5f667b5b4ca4b4abb685dc874ce',1,'getopt.h']]], + ['nonoption_5fp',['NONOPTION_P',['../getopt_8c.html#a71ceb8911d64b39b402041ba5ea8453c',1,'getopt.c']]] +]; diff --git a/src/html/search/defines_5.html b/src/html/search/defines_5.html new file mode 100644 index 0000000..dd7bfdc --- /dev/null +++ b/src/html/search/defines_5.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/defines_5.js b/src/html/search/defines_5.js new file mode 100644 index 0000000..035d583 --- /dev/null +++ b/src/html/search/defines_5.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['optional_5fargument',['optional_argument',['../getopt_8h.html#acca06c0a947656bd8b395bf1084ffb72',1,'getopt.h']]] +]; diff --git a/src/html/search/defines_6.html b/src/html/search/defines_6.html new file mode 100644 index 0000000..58d00e9 --- /dev/null +++ b/src/html/search/defines_6.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/defines_6.js b/src/html/search/defines_6.js new file mode 100644 index 0000000..3acad51 --- /dev/null +++ b/src/html/search/defines_6.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['phyml',['PHYML',['../treeML_8h.html#a881b73a915d74c35b5bdae930066e817',1,'treeML.h']]], + ['private',['PRIVATE',['../rnaz__utils_8h.html#a5e151c615eda34903514212f05a5ccf8',1,'PRIVATE(): rnaz_utils.h'],['../utils_8c.html#a5e151c615eda34903514212f05a5ccf8',1,'PRIVATE(): utils.c']]], + ['public',['PUBLIC',['../utils_8c.html#ad17d551e31d1828c68acf40684849b7e',1,'utils.c']]] +]; diff --git a/src/html/search/defines_7.html b/src/html/search/defines_7.html new file mode 100644 index 0000000..275e1b3 --- /dev/null +++ b/src/html/search/defines_7.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/defines_7.js b/src/html/search/defines_7.js new file mode 100644 index 0000000..a58096c --- /dev/null +++ b/src/html/search/defines_7.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['required_5fargument',['required_argument',['../getopt_8h.html#a6ece8d8dfa8378778f7290fdaba5b8bc',1,'getopt.h']]] +]; diff --git a/src/html/search/defines_8.html b/src/html/search/defines_8.html new file mode 100644 index 0000000..de651d9 --- /dev/null +++ b/src/html/search/defines_8.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/defines_8.js b/src/html/search/defines_8.js new file mode 100644 index 0000000..e6f1b0c --- /dev/null +++ b/src/html/search/defines_8.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['swap_5fflags',['SWAP_FLAGS',['../getopt_8c.html#a6e06e56c5fa96faaf47f3b231e015e35',1,'getopt.c']]] +]; diff --git a/src/html/search/defines_9.html b/src/html/search/defines_9.html new file mode 100644 index 0000000..a93bb53 --- /dev/null +++ b/src/html/search/defines_9.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/defines_9.js b/src/html/search/defines_9.js new file mode 100644 index 0000000..a764b89 --- /dev/null +++ b/src/html/search/defines_9.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['undef',['UNDEF',['../score_8h.html#abde25a67f4046530ae1c572cefeb5869',1,'score.h']]] +]; diff --git a/src/html/search/enums_0.html b/src/html/search/enums_0.html new file mode 100644 index 0000000..ee343ac --- /dev/null +++ b/src/html/search/enums_0.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/enums_0.js b/src/html/search/enums_0.js new file mode 100644 index 0000000..f4a6198 --- /dev/null +++ b/src/html/search/enums_0.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['alnformat',['alnFormat',['../rnaz__utils_8h.html#ad849a5b1ae21b9dd57228a7cc706a189',1,'rnaz_utils.h']]] +]; diff --git a/src/html/search/enums_1.html b/src/html/search/enums_1.html new file mode 100644 index 0000000..3fd210a --- /dev/null +++ b/src/html/search/enums_1.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/enums_1.js b/src/html/search/enums_1.js new file mode 100644 index 0000000..2474e32 --- /dev/null +++ b/src/html/search/enums_1.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['cmdline_5fparser_5farg_5ftype',['cmdline_parser_arg_type',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1',1,'cmdline.c']]] +]; diff --git a/src/html/search/enumvalues_0.html b/src/html/search/enumvalues_0.html new file mode 100644 index 0000000..9387b6a --- /dev/null +++ b/src/html/search/enumvalues_0.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/enumvalues_0.js b/src/html/search/enumvalues_0.js new file mode 100644 index 0000000..fe796dc --- /dev/null +++ b/src/html/search/enumvalues_0.js @@ -0,0 +1,8 @@ +var searchData= +[ + ['arg_5fflag',['ARG_FLAG',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1afd135f03243c33991ef507f4410718f7',1,'cmdline.c']]], + ['arg_5ffloat',['ARG_FLOAT',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1a5875de3e892eb32ed41e4d60ef7d99ca',1,'cmdline.c']]], + ['arg_5fint',['ARG_INT',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1a58393752406d163205fa18f450909993',1,'cmdline.c']]], + ['arg_5fno',['ARG_NO',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1a67dd250fb3e23862523b667407868ada',1,'cmdline.c']]], + ['arg_5fstring',['ARG_STRING',['../cmdline_8c.html#a88e31a859f36efa57ad64e6ae13332a1a1e0904ee5e3baf2aa4070ab0718a3afa',1,'cmdline.c']]] +]; diff --git a/src/html/search/enumvalues_1.html b/src/html/search/enumvalues_1.html new file mode 100644 index 0000000..f622aba --- /dev/null +++ b/src/html/search/enumvalues_1.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/enumvalues_1.js b/src/html/search/enumvalues_1.js new file mode 100644 index 0000000..67e2faa --- /dev/null +++ b/src/html/search/enumvalues_1.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['clustal',['CLUSTAL',['../rnaz__utils_8h.html#ad849a5b1ae21b9dd57228a7cc706a189a0c9e4d1c84d67fc10b7d54da4aad56ca',1,'rnaz_utils.h']]] +]; diff --git a/src/html/search/enumvalues_2.html b/src/html/search/enumvalues_2.html new file mode 100644 index 0000000..d499078 --- /dev/null +++ b/src/html/search/enumvalues_2.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/enumvalues_2.js b/src/html/search/enumvalues_2.js new file mode 100644 index 0000000..ef5f45d --- /dev/null +++ b/src/html/search/enumvalues_2.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['maf',['MAF',['../rnaz__utils_8h.html#ad849a5b1ae21b9dd57228a7cc706a189a2d41a0476d221862995d2a0a02f6b3b3',1,'rnaz_utils.h']]] +]; diff --git a/src/html/search/enumvalues_3.html b/src/html/search/enumvalues_3.html new file mode 100644 index 0000000..b4fc3ee --- /dev/null +++ b/src/html/search/enumvalues_3.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/enumvalues_3.js b/src/html/search/enumvalues_3.js new file mode 100644 index 0000000..b204357 --- /dev/null +++ b/src/html/search/enumvalues_3.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['permute',['PERMUTE',['../getopt_8c.html#a06fc87d81c62e9abb8790b6e5713c55bacfdde4b47c27f4efbd832e1ac7f8a8fc',1,'getopt.c']]] +]; diff --git a/src/html/search/enumvalues_4.html b/src/html/search/enumvalues_4.html new file mode 100644 index 0000000..d6f69ac --- /dev/null +++ b/src/html/search/enumvalues_4.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/enumvalues_4.js b/src/html/search/enumvalues_4.js new file mode 100644 index 0000000..3c477d1 --- /dev/null +++ b/src/html/search/enumvalues_4.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['require_5forder',['REQUIRE_ORDER',['../getopt_8c.html#a06fc87d81c62e9abb8790b6e5713c55ba0e73a0691c110b1442d8364d1d12eccc',1,'getopt.c']]], + ['return_5fin_5forder',['RETURN_IN_ORDER',['../getopt_8c.html#a06fc87d81c62e9abb8790b6e5713c55ba3c56550bfafe809d9214b863b69c31c5',1,'getopt.c']]] +]; diff --git a/src/html/search/enumvalues_5.html b/src/html/search/enumvalues_5.html new file mode 100644 index 0000000..43a28d1 --- /dev/null +++ b/src/html/search/enumvalues_5.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/enumvalues_5.js b/src/html/search/enumvalues_5.js new file mode 100644 index 0000000..77b60d1 --- /dev/null +++ b/src/html/search/enumvalues_5.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['unknown',['UNKNOWN',['../rnaz__utils_8h.html#ad849a5b1ae21b9dd57228a7cc706a189a6ce26a62afab55d7606ad4e92428b30c',1,'rnaz_utils.h']]] +]; diff --git a/src/html/search/files_0.html b/src/html/search/files_0.html new file mode 100644 index 0000000..4f272b8 --- /dev/null +++ b/src/html/search/files_0.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/files_0.js b/src/html/search/files_0.js new file mode 100644 index 0000000..78cc890 --- /dev/null +++ b/src/html/search/files_0.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['cmdline_2ec',['cmdline.c',['../cmdline_8c.html',1,'']]], + ['cmdline_2eh',['cmdline.h',['../cmdline_8h.html',1,'']]], + ['code_2ec',['code.c',['../code_8c.html',1,'']]], + ['code_2eh',['code.h',['../code_8h.html',1,'']]] +]; diff --git a/src/html/search/files_1.html b/src/html/search/files_1.html new file mode 100644 index 0000000..dcce422 --- /dev/null +++ b/src/html/search/files_1.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/files_1.js b/src/html/search/files_1.js new file mode 100644 index 0000000..0ff19a6 --- /dev/null +++ b/src/html/search/files_1.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['extreme_5ffit_2ec',['extreme_fit.c',['../extreme__fit_8c.html',1,'']]], + ['extreme_5ffit_2eh',['extreme_fit.h',['../extreme__fit_8h.html',1,'']]] +]; diff --git a/src/html/search/files_2.html b/src/html/search/files_2.html new file mode 100644 index 0000000..d5c6c3b --- /dev/null +++ b/src/html/search/files_2.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/files_2.js b/src/html/search/files_2.js new file mode 100644 index 0000000..7aadfb4 --- /dev/null +++ b/src/html/search/files_2.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['getopt_2ec',['getopt.c',['../getopt_8c.html',1,'']]], + ['getopt_2eh',['getopt.h',['../getopt_8h.html',1,'']]] +]; diff --git a/src/html/search/files_3.html b/src/html/search/files_3.html new file mode 100644 index 0000000..d5a9528 --- /dev/null +++ b/src/html/search/files_3.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/files_3.js b/src/html/search/files_3.js new file mode 100644 index 0000000..3dc9ed3 --- /dev/null +++ b/src/html/search/files_3.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['misc_2ec',['misc.c',['../misc_8c.html',1,'']]], + ['misc_2eh',['misc.h',['../misc_8h.html',1,'']]] +]; diff --git a/src/html/search/files_4.html b/src/html/search/files_4.html new file mode 100644 index 0000000..7b4c42a --- /dev/null +++ b/src/html/search/files_4.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/files_4.js b/src/html/search/files_4.js new file mode 100644 index 0000000..3afe7bd --- /dev/null +++ b/src/html/search/files_4.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['postscript_2ec',['postscript.c',['../postscript_8c.html',1,'']]], + ['postscript_2eh',['postscript.h',['../postscript_8h.html',1,'']]] +]; diff --git a/src/html/search/files_5.html b/src/html/search/files_5.html new file mode 100644 index 0000000..1f77bb1 --- /dev/null +++ b/src/html/search/files_5.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/files_5.js b/src/html/search/files_5.js new file mode 100644 index 0000000..12e6d56 --- /dev/null +++ b/src/html/search/files_5.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['rnacode_2ec',['RNAcode.c',['../RNAcode_8c.html',1,'']]], + ['rnacode_2eh',['RNAcode.h',['../RNAcode_8h.html',1,'']]], + ['rnaz_5futils_2ec',['rnaz_utils.c',['../rnaz__utils_8c.html',1,'']]], + ['rnaz_5futils_2eh',['rnaz_utils.h',['../rnaz__utils_8h.html',1,'']]] +]; diff --git a/src/html/search/files_6.html b/src/html/search/files_6.html new file mode 100644 index 0000000..7573254 --- /dev/null +++ b/src/html/search/files_6.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/files_6.js b/src/html/search/files_6.js new file mode 100644 index 0000000..86bd729 --- /dev/null +++ b/src/html/search/files_6.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['score_2ec',['score.c',['../score_8c.html',1,'']]], + ['score_2eh',['score.h',['../score_8h.html',1,'']]] +]; diff --git a/src/html/search/files_7.html b/src/html/search/files_7.html new file mode 100644 index 0000000..214b329 --- /dev/null +++ b/src/html/search/files_7.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/files_7.js b/src/html/search/files_7.js new file mode 100644 index 0000000..c556735 --- /dev/null +++ b/src/html/search/files_7.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['treeml_2ec',['treeML.c',['../treeML_8c.html',1,'']]], + ['treeml_2eh',['treeML.h',['../treeML_8h.html',1,'']]], + ['treesimulate_2ec',['treeSimulate.c',['../treeSimulate_8c.html',1,'']]], + ['treesimulate_2eh',['treeSimulate.h',['../treeSimulate_8h.html',1,'']]] +]; diff --git a/src/html/search/files_8.html b/src/html/search/files_8.html new file mode 100644 index 0000000..6720c7c --- /dev/null +++ b/src/html/search/files_8.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/files_8.js b/src/html/search/files_8.js new file mode 100644 index 0000000..d9598c3 --- /dev/null +++ b/src/html/search/files_8.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['utils_2ec',['utils.c',['../utils_8c.html',1,'']]], + ['utils_2eh',['utils.h',['../utils_8h.html',1,'']]] +]; diff --git a/src/html/search/files_9.html b/src/html/search/files_9.html new file mode 100644 index 0000000..fc95877 --- /dev/null +++ b/src/html/search/files_9.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/files_9.js b/src/html/search/files_9.js new file mode 100644 index 0000000..96b1830 --- /dev/null +++ b/src/html/search/files_9.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['weight_2ec',['weight.c',['../weight_8c.html',1,'']]], + ['weight_2eh',['weight.h',['../weight_8h.html',1,'']]] +]; diff --git a/src/html/search/functions_0.html b/src/html/search/functions_0.html new file mode 100644 index 0000000..4e6d87d --- /dev/null +++ b/src/html/search/functions_0.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_0.js b/src/html/search/functions_0.js new file mode 100644 index 0000000..396d575 --- /dev/null +++ b/src/html/search/functions_0.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['_5fgetopt_5finitialize',['_getopt_initialize',['../getopt_8c.html#a17475cbc1ffae0c12af2e0a3319d197f',1,'getopt.c']]], + ['_5fgetopt_5finternal',['_getopt_internal',['../getopt_8c.html#a0df92a0ae8fe1fd43268c738f548674f',1,'_getopt_internal(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only): getopt.c'],['../getopt_8h.html#a60428225710059ca135c6b2a8941855f',1,'_getopt_internal(): getopt.h']]] +]; diff --git a/src/html/search/functions_1.html b/src/html/search/functions_1.html new file mode 100644 index 0000000..b343e2d --- /dev/null +++ b/src/html/search/functions_1.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_1.js b/src/html/search/functions_1.js new file mode 100644 index 0000000..0d2a53e --- /dev/null +++ b/src/html/search/functions_1.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['allocatesk',['allocateSk',['../misc_8c.html#ab8906f987e8caa1c304422e2105784db',1,'allocateSk(int N, int L): misc.c'],['../misc_8h.html#ab8906f987e8caa1c304422e2105784db',1,'allocateSk(int N, int L): misc.c']]], + ['avg',['avg',['../misc_8c.html#a29db63ab5182ac2f88eb37329c092126',1,'avg(float *data, int N): misc.c'],['../misc_8h.html#a29db63ab5182ac2f88eb37329c092126',1,'avg(float *data, int N): misc.c']]] +]; diff --git a/src/html/search/functions_10.html b/src/html/search/functions_10.html new file mode 100644 index 0000000..72bc1ea --- /dev/null +++ b/src/html/search/functions_10.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_10.js b/src/html/search/functions_10.js new file mode 100644 index 0000000..6d8f587 --- /dev/null +++ b/src/html/search/functions_10.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['time_5fstamp',['time_stamp',['../utils_8c.html#ade7ba8b8ed6a11e4c6f20e9e603e8799',1,'time_stamp(void): utils.c'],['../utils_8h.html#a7afeb906cb36e9d77379eabc6907ac46',1,'time_stamp(void): utils.c']]], + ['translateseq',['translateSeq',['../code_8c.html#a8d64bc3ec5de4db181efd7ff565ff894',1,'translateSeq(char *seq): code.c'],['../code_8h.html#a8d64bc3ec5de4db181efd7ff565ff894',1,'translateSeq(char *seq): code.c']]], + ['tree2aln',['tree2aln',['../treeSimulate_8c.html#a3de1638db8b0f14df05b49f41bae2da6',1,'tree2aln(TTree *tree, struct aln *alignment[]): treeSimulate.c'],['../treeSimulate_8h.html#a3de1638db8b0f14df05b49f41bae2da6',1,'tree2aln(TTree *tree, struct aln *alignment[]): treeSimulate.c']]], + ['treeml',['treeML',['../treeML_8c.html#a252122923da9d542436a6ce49c15c819',1,'treeML(const struct aln *alignment[], char **treeString, float *kappa): treeML.c'],['../treeML_8h.html#a252122923da9d542436a6ce49c15c819',1,'treeML(const struct aln *alignment[], char **treeString, float *kappa): treeML.c']]] +]; diff --git a/src/html/search/functions_11.html b/src/html/search/functions_11.html new file mode 100644 index 0000000..6948a61 --- /dev/null +++ b/src/html/search/functions_11.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_11.js b/src/html/search/functions_11.js new file mode 100644 index 0000000..c5ea15a --- /dev/null +++ b/src/html/search/functions_11.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['unpack_5fstructure',['unpack_structure',['../utils_8c.html#aeda5e0295cdcacc9da2ae479db08396c',1,'unpack_structure(const char *packed): utils.c'],['../utils_8h.html#a071c6921efe1eb974f115ee6fefa3c39',1,'unpack_structure(const char *packed): utils.c']]], + ['update_5farg',['update_arg',['../cmdline_8c.html#a21d8824d410efa489c4921011c1c0765',1,'cmdline.c']]], + ['urn',['urn',['../utils_8c.html#ab838605c6654ebdddc4ad19280855a25',1,'urn(void): utils.c'],['../utils_8h.html#aaa328491c84996e445d027fde9800f2e',1,'urn(void): utils.c']]], + ['usage',['usage',['../RNAcode_8c.html#ae8605e2b78cd4a81b6c6b5c30cb7366a',1,'usage(void): RNAcode.c'],['../RNAcode_8h.html#ae8605e2b78cd4a81b6c6b5c30cb7366a',1,'usage(void): RNAcode.c']]] +]; diff --git a/src/html/search/functions_12.html b/src/html/search/functions_12.html new file mode 100644 index 0000000..3df8489 --- /dev/null +++ b/src/html/search/functions_12.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_12.js b/src/html/search/functions_12.js new file mode 100644 index 0000000..47ca79f --- /dev/null +++ b/src/html/search/functions_12.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['version',['version',['../RNAcode_8c.html#af986bd0575ec9b913dfab4b8422509ae',1,'version(void): RNAcode.c'],['../RNAcode_8h.html#af986bd0575ec9b913dfab4b8422509ae',1,'version(void): RNAcode.c']]] +]; diff --git a/src/html/search/functions_13.html b/src/html/search/functions_13.html new file mode 100644 index 0000000..febf8e0 --- /dev/null +++ b/src/html/search/functions_13.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_13.js b/src/html/search/functions_13.js new file mode 100644 index 0000000..ce8306c --- /dev/null +++ b/src/html/search/functions_13.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['weights',['weights',['../weight_8c.html#a0c41284822a5ce5bfea7cd745ac71edc',1,'weights(float **D, int N): weight.c'],['../weight_8h.html#a2d3bb1f6e0b7a4b2c564e8843f51e385',1,'weights(float **D, int N): weight.c']]], + ['write_5finto_5ffile',['write_into_file',['../cmdline_8c.html#a332041b3060103618ef6b767ab32d0dd',1,'cmdline.c']]] +]; diff --git a/src/html/search/functions_14.html b/src/html/search/functions_14.html new file mode 100644 index 0000000..4c814f5 --- /dev/null +++ b/src/html/search/functions_14.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_14.js b/src/html/search/functions_14.js new file mode 100644 index 0000000..8e4ab69 --- /dev/null +++ b/src/html/search/functions_14.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['xrealloc',['xrealloc',['../utils_8c.html#a9037ada838835b1b9db41581a021b0c8',1,'xrealloc(void *p, unsigned size): utils.c'],['../utils_8h.html#a9037ada838835b1b9db41581a021b0c8',1,'xrealloc(void *p, unsigned size): utils.c']]] +]; diff --git a/src/html/search/functions_2.html b/src/html/search/functions_2.html new file mode 100644 index 0000000..ecce2f3 --- /dev/null +++ b/src/html/search/functions_2.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_2.js b/src/html/search/functions_2.js new file mode 100644 index 0000000..141a761 --- /dev/null +++ b/src/html/search/functions_2.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['backtrack',['backtrack',['../score_8c.html#a0557015d88daf987d0730792a31493ad',1,'backtrack(int opt_b, int opt_i, float ****SSk, const struct aln *alignment[]): score.c'],['../score_8h.html#a0557015d88daf987d0730792a31493ad',1,'backtrack(int opt_b, int opt_i, float ****SSk, const struct aln *alignment[]): score.c']]], + ['bp_5fdistance',['bp_distance',['../utils_8c.html#ad3b3262478312877d19d74950030de73',1,'bp_distance(const char *str1, const char *str2): utils.c'],['../utils_8h.html#a6ebbcd29a754f0e4f1a66d1fd84184db',1,'bp_distance(const char *str1, const char *str2): utils.c']]] +]; diff --git a/src/html/search/functions_3.html b/src/html/search/functions_3.html new file mode 100644 index 0000000..15f06ab --- /dev/null +++ b/src/html/search/functions_3.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_3.js b/src/html/search/functions_3.js new file mode 100644 index 0000000..100672d --- /dev/null +++ b/src/html/search/functions_3.js @@ -0,0 +1,32 @@ +var searchData= +[ + ['calculatebg',['calculateBG',['../score_8c.html#afa0b54f696bdcdf5395fb5e5185bd129',1,'calculateBG(bgModel *model): score.c'],['../score_8h.html#a853a7de0874087a99e452ed917b3fdfa',1,'calculateBG(bgModel *models): score.c']]], + ['calculatesigma',['calculateSigma',['../score_8c.html#aa7ac5e027c4335c220657e63d95b18ec',1,'score.c']]], + ['checkformat',['checkFormat',['../rnaz__utils_8c.html#a7e802ce86090ca9375d5e39ebacc1470',1,'checkFormat(FILE *file): rnaz_utils.c'],['../rnaz__utils_8h.html#a7e802ce86090ca9375d5e39ebacc1470',1,'checkFormat(FILE *file): rnaz_utils.c']]], + ['clear_5fargs',['clear_args',['../cmdline_8c.html#a4d7018864f814395754ea4127ce4d37b',1,'cmdline.c']]], + ['clear_5fgiven',['clear_given',['../cmdline_8c.html#a48968b912c47767e9f057f5bc11634cb',1,'cmdline.c']]], + ['cmdline_5fparser',['cmdline_parser',['../cmdline_8c.html#a96f1044799c552f3ee139f9b1387b363',1,'cmdline_parser(int argc, char *const *argv, struct gengetopt_args_info *args_info): cmdline.c'],['../cmdline_8h.html#a96f1044799c552f3ee139f9b1387b363',1,'cmdline_parser(int argc, char *const *argv, struct gengetopt_args_info *args_info): cmdline.c']]], + ['cmdline_5fparser2',['cmdline_parser2',['../cmdline_8c.html#a08e3536edc64ec5ee7c2df546c6e9dd7',1,'cmdline_parser2(int argc, char *const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required): cmdline.c'],['../cmdline_8h.html#a08e3536edc64ec5ee7c2df546c6e9dd7',1,'cmdline_parser2(int argc, char *const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required): cmdline.c']]], + ['cmdline_5fparser_5fdump',['cmdline_parser_dump',['../cmdline_8c.html#a1f73418092a6e6eb3706aa0de2785e11',1,'cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info): cmdline.c'],['../cmdline_8h.html#a1f73418092a6e6eb3706aa0de2785e11',1,'cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info): cmdline.c']]], + ['cmdline_5fparser_5fext',['cmdline_parser_ext',['../cmdline_8c.html#a77e461b5bdfd4a36c59a96bfb1813e38',1,'cmdline_parser_ext(int argc, char *const *argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params): cmdline.c'],['../cmdline_8h.html#a77e461b5bdfd4a36c59a96bfb1813e38',1,'cmdline_parser_ext(int argc, char *const *argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params): cmdline.c']]], + ['cmdline_5fparser_5ffile_5fsave',['cmdline_parser_file_save',['../cmdline_8c.html#a5f3e9412f88f1058a31ac28ad2ea2818',1,'cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info): cmdline.c'],['../cmdline_8h.html#a5f3e9412f88f1058a31ac28ad2ea2818',1,'cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info): cmdline.c']]], + ['cmdline_5fparser_5ffree',['cmdline_parser_free',['../cmdline_8c.html#af1b97c4e92b88f736e350b3902266ba4',1,'cmdline_parser_free(struct gengetopt_args_info *args_info): cmdline.c'],['../cmdline_8h.html#af1b97c4e92b88f736e350b3902266ba4',1,'cmdline_parser_free(struct gengetopt_args_info *args_info): cmdline.c']]], + ['cmdline_5fparser_5finit',['cmdline_parser_init',['../cmdline_8c.html#aca62b50d03d0d082968eeb1940f98650',1,'cmdline_parser_init(struct gengetopt_args_info *args_info): cmdline.c'],['../cmdline_8h.html#aca62b50d03d0d082968eeb1940f98650',1,'cmdline_parser_init(struct gengetopt_args_info *args_info): cmdline.c']]], + ['cmdline_5fparser_5finternal',['cmdline_parser_internal',['../cmdline_8c.html#aaba43e1bb216c68c96e982c600c906a7',1,'cmdline.c']]], + ['cmdline_5fparser_5fparams_5fcreate',['cmdline_parser_params_create',['../cmdline_8c.html#afd778af110fe0ee1ea5eac7aa9939d92',1,'cmdline_parser_params_create(void): cmdline.c'],['../cmdline_8h.html#afd778af110fe0ee1ea5eac7aa9939d92',1,'cmdline_parser_params_create(void): cmdline.c']]], + ['cmdline_5fparser_5fparams_5finit',['cmdline_parser_params_init',['../cmdline_8c.html#af72b814611cffc706b2135ccdfe7e997',1,'cmdline_parser_params_init(struct cmdline_parser_params *params): cmdline.c'],['../cmdline_8h.html#af72b814611cffc706b2135ccdfe7e997',1,'cmdline_parser_params_init(struct cmdline_parser_params *params): cmdline.c']]], + ['cmdline_5fparser_5fprint_5fhelp',['cmdline_parser_print_help',['../cmdline_8c.html#ad4f7db2fa4002379eb30e5206f3b7492',1,'cmdline_parser_print_help(void): cmdline.c'],['../cmdline_8h.html#ad4f7db2fa4002379eb30e5206f3b7492',1,'cmdline_parser_print_help(void): cmdline.c']]], + ['cmdline_5fparser_5fprint_5fversion',['cmdline_parser_print_version',['../cmdline_8c.html#a96f27bf35ce0ab8eea7a1f6e6b59a5e2',1,'cmdline_parser_print_version(void): cmdline.c'],['../cmdline_8h.html#a96f27bf35ce0ab8eea7a1f6e6b59a5e2',1,'cmdline_parser_print_version(void): cmdline.c']]], + ['cmdline_5fparser_5frelease',['cmdline_parser_release',['../cmdline_8c.html#ace6fb8241473bb89c5a575774eb4ba2a',1,'cmdline.c']]], + ['cmdline_5fparser_5frequired',['cmdline_parser_required',['../cmdline_8c.html#a83651e5be280d60aed58fdb72456a030',1,'cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name): cmdline.c'],['../cmdline_8h.html#a83651e5be280d60aed58fdb72456a030',1,'cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name): cmdline.c']]], + ['coloraln',['colorAln',['../postscript_8c.html#ac7d6bf70e040d36788b6eacace4cb312',1,'colorAln(const char *filename, const struct aln *alignment[], segmentStats region): postscript.c'],['../postscript_8h.html#ac7d6bf70e040d36788b6eacace4cb312',1,'colorAln(const char *filename, const struct aln *alignment[], segmentStats region): postscript.c']]], + ['colorhss',['colorHSS',['../postscript_8c.html#a88d8c5c3031b8ee553b4bfc437e4b73e',1,'colorHSS(const char *filename, const struct aln *alignment[], backtrackData *bt, const char *label, int b, int i): postscript.c'],['../postscript_8h.html#a88d8c5c3031b8ee553b4bfc437e4b73e',1,'colorHSS(const char *filename, const struct aln *alignment[], backtrackData *bt, const char *label, int b, int i): postscript.c']]], + ['combperpair',['combPerPair',['../rnaz__utils_8c.html#aa5d9fd87f6384e8d19af13f1365b503b',1,'combPerPair(struct aln *AS[], char *structure): rnaz_utils.c'],['../rnaz__utils_8h.html#aa5d9fd87f6384e8d19af13f1365b503b',1,'combPerPair(struct aln *AS[], char *structure): rnaz_utils.c']]], + ['comparelocation',['compareLocation',['../misc_8c.html#a08c97f6ebbb296bfe2d0f74e7a3a8af8',1,'misc.c']]], + ['comparescores',['compareScores',['../misc_8c.html#a3003bc209fbd623b0ebf8d55c3f76454',1,'compareScores(const void *a, const void *b): misc.c'],['../misc_8h.html#a3003bc209fbd623b0ebf8d55c3f76454',1,'compareScores(const void *a, const void *b): misc.c']]], + ['consensus',['consensus',['../rnaz__utils_8c.html#aa870f4f41dc7bf4808af716a34482ac5',1,'consensus(const struct aln *AS[]): rnaz_utils.c'],['../rnaz__utils_8h.html#aa870f4f41dc7bf4808af716a34482ac5',1,'consensus(const struct aln *AS[]): rnaz_utils.c']]], + ['copyaln',['copyAln',['../misc_8c.html#a0da1742a6a7f546827bee85fbdf53592',1,'copyAln(struct aln *src[], struct aln *dest[]): misc.c'],['../misc_8h.html#a0da1742a6a7f546827bee85fbdf53592',1,'copyAln(struct aln *src[], struct aln *dest[]): misc.c']]], + ['copysk',['copySk',['../misc_8c.html#a540d653adf9134e345a0be15556bef9f',1,'copySk(float ****from, float ****to, int N, int L): misc.c'],['../misc_8h.html#a540d653adf9134e345a0be15556bef9f',1,'copySk(float ****from, float ****to, int N, int L): misc.c']]], + ['countfreqsmono',['countFreqsMono',['../score_8c.html#a73aae058cfc643479adf77c5ffc48a45',1,'countFreqsMono(const struct aln *alignment[], float freqs[]): score.c'],['../score_8h.html#a73aae058cfc643479adf77c5ffc48a45',1,'countFreqsMono(const struct aln *alignment[], float freqs[]): score.c']]], + ['createalnentry',['createAlnEntry',['../rnaz__utils_8c.html#ab3af11f3fc09669574f682072f795865',1,'createAlnEntry(char *name, char *seq, int start, int length, int fullLength, char strand): rnaz_utils.c'],['../rnaz__utils_8h.html#ab3af11f3fc09669574f682072f795865',1,'createAlnEntry(char *name, char *seq, int start, int length, int fullLength, char strand): rnaz_utils.c']]] +]; diff --git a/src/html/search/functions_4.html b/src/html/search/functions_4.html new file mode 100644 index 0000000..8985ff2 --- /dev/null +++ b/src/html/search/functions_4.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_4.js b/src/html/search/functions_4.js new file mode 100644 index 0000000..8535b4a --- /dev/null +++ b/src/html/search/functions_4.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['decodeaa',['decodeAA',['../code_8c.html#a124646f7d65dd512584b8fbab1fcc7a4',1,'decodeAA(int encodedAA): code.c'],['../code_8h.html#a124646f7d65dd512584b8fbab1fcc7a4',1,'decodeAA(int encodedAA): code.c']]] +]; diff --git a/src/html/search/functions_5.html b/src/html/search/functions_5.html new file mode 100644 index 0000000..0314918 --- /dev/null +++ b/src/html/search/functions_5.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_5.js b/src/html/search/functions_5.js new file mode 100644 index 0000000..277db2a --- /dev/null +++ b/src/html/search/functions_5.js @@ -0,0 +1,9 @@ +var searchData= +[ + ['encodeaa',['encodeAA',['../code_8c.html#a617a88955038003d70de0d9113b505eb',1,'encodeAA(char aa): code.c'],['../code_8h.html#a617a88955038003d70de0d9113b505eb',1,'encodeAA(char aa): code.c']]], + ['encodebase',['encodeBase',['../rnaz__utils_8c.html#a48ca69cad11fcf2c4d962b73ff4388ee',1,'encodeBase(char base): rnaz_utils.c'],['../rnaz__utils_8h.html#a48ca69cad11fcf2c4d962b73ff4388ee',1,'encodeBase(char base): rnaz_utils.c']]], + ['encodeseq',['encodeSeq',['../code_8c.html#a011bbc41b53a2519b2bb46214b7a1fcc',1,'encodeSeq(char *seq): code.c'],['../code_8h.html#a011bbc41b53a2519b2bb46214b7a1fcc',1,'encodeSeq(char *seq): code.c']]], + ['evdmaxlikelyfit',['EVDMaxLikelyFit',['../extreme__fit_8c.html#a51c7409c6447353e0bd3b7c48d982984',1,'EVDMaxLikelyFit(double *x, int *c, int n, double *ret_mu, double *ret_lambda): extreme_fit.c'],['../extreme__fit_8h.html#a51c7409c6447353e0bd3b7c48d982984',1,'EVDMaxLikelyFit(double *x, int *c, int n, double *ret_mu, double *ret_lambda): extreme_fit.c']]], + ['exchange',['exchange',['../getopt_8c.html#a4621659dd6377e52ac50a0869625bb6e',1,'getopt.c']]], + ['extendregion',['extendRegion',['../misc_8c.html#a6017c986a43a1bba1569a8efb1b3aedb',1,'extendRegion(const struct aln *alignment[], int pos, int direction): misc.c'],['../misc_8h.html#a6017c986a43a1bba1569a8efb1b3aedb',1,'extendRegion(const struct aln *alignment[], int pos, int direction): misc.c']]] +]; diff --git a/src/html/search/functions_6.html b/src/html/search/functions_6.html new file mode 100644 index 0000000..c506123 --- /dev/null +++ b/src/html/search/functions_6.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_6.js b/src/html/search/functions_6.js new file mode 100644 index 0000000..a667f28 --- /dev/null +++ b/src/html/search/functions_6.js @@ -0,0 +1,15 @@ +var searchData= +[ + ['filecopy',['filecopy',['../utils_8c.html#ae3ef8f02d94a4aeaa2050fb210acd3b0',1,'filecopy(FILE *from, FILE *to): utils.c'],['../utils_8h.html#ab213334ce977b6d21611cdea6b80c3bf',1,'filecopy(FILE *from, FILE *to): utils.c']]], + ['free_5fstring_5ffield',['free_string_field',['../cmdline_8c.html#a3a3cc8b020811185cb0a4b96e1ff5a40',1,'cmdline.c']]], + ['freealn',['freeAln',['../rnaz__utils_8c.html#ace5cb65b010161f9eb138717b4592673',1,'freeAln(struct aln *AS[]): rnaz_utils.c'],['../rnaz__utils_8h.html#ace5cb65b010161f9eb138717b4592673',1,'freeAln(struct aln *AS[]): rnaz_utils.c']]], + ['freealnentry',['freeAlnEntry',['../rnaz__utils_8c.html#ac38565a99389ebf0aed62a623d893299',1,'freeAlnEntry(struct aln *entry): rnaz_utils.c'],['../rnaz__utils_8h.html#ac38565a99389ebf0aed62a623d893299',1,'freeAlnEntry(struct aln *entry): rnaz_utils.c']]], + ['freefields',['freeFields',['../rnaz__utils_8c.html#a5afeb493cf63c3077bc7ccc2df25208d',1,'freeFields(char **fields): rnaz_utils.c'],['../rnaz__utils_8h.html#a5afeb493cf63c3077bc7ccc2df25208d',1,'freeFields(char **fields): rnaz_utils.c']]], + ['freemodelmatrix',['freeModelMatrix',['../score_8h.html#a5c86ff30dfac4ac88d64ac6db1c6c559',1,'score.h']]], + ['freemodels',['freeModels',['../RNAcode_8c.html#a303c139a77497eb1282c6d2a4d415c1c',1,'freeModels(bgModel *models, int N): score.c'],['../score_8c.html#a303c139a77497eb1282c6d2a4d415c1c',1,'freeModels(bgModel *models, int N): score.c']]], + ['freeresults',['freeResults',['../misc_8c.html#a71b140f8ccd1190776a6cc04f42f7b0d',1,'freeResults(segmentStats results[]): misc.c'],['../misc_8h.html#a71b140f8ccd1190776a6cc04f42f7b0d',1,'freeResults(segmentStats results[]): misc.c']]], + ['frees',['freeS',['../score_8c.html#ab2954f5929699167062e554323b3ec08',1,'freeS(float **S, const struct aln *alignment[]): score.c'],['../score_8h.html#ab2954f5929699167062e554323b3ec08',1,'freeS(float **S, const struct aln *alignment[]): score.c']]], + ['freescoringmatrix',['freeScoringMatrix',['../score_8c.html#a92e464aeb840be0a3082485f30bd094b',1,'freeScoringMatrix(int **matrix): score.c'],['../score_8h.html#a92e464aeb840be0a3082485f30bd094b',1,'freeScoringMatrix(int **matrix): score.c']]], + ['freeseqgentree',['freeSeqgenTree',['../treeSimulate_8c.html#a0f4d088716aa0dbcb5485641a0be7096',1,'freeSeqgenTree(TTree *tree): treeSimulate.c'],['../treeSimulate_8h.html#a0f4d088716aa0dbcb5485641a0be7096',1,'freeSeqgenTree(TTree *tree): treeSimulate.c']]], + ['freesk',['freeSk',['../score_8c.html#a39c41782e70b3f6d743e3287c015d573',1,'freeSk(float ****S, const struct aln *alignment[]): score.c'],['../score_8h.html#a39c41782e70b3f6d743e3287c015d573',1,'freeSk(float ****S, const struct aln *alignment[]): score.c']]] +]; diff --git a/src/html/search/functions_7.html b/src/html/search/functions_7.html new file mode 100644 index 0000000..83a7b84 --- /dev/null +++ b/src/html/search/functions_7.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_7.js b/src/html/search/functions_7.js new file mode 100644 index 0000000..d4d125f --- /dev/null +++ b/src/html/search/functions_7.js @@ -0,0 +1,23 @@ +var searchData= +[ + ['gaussian',['gaussian',['../misc_8h.html#af625860d4b3644771a9b58a316518d00',1,'misc.h']]], + ['gengetopt_5fstrdup',['gengetopt_strdup',['../cmdline_8c.html#a0ec9efd6eb3e6e939fcaaadd8b4c6a9f',1,'cmdline.c']]], + ['get_5fline',['get_line',['../utils_8c.html#a39d4415a69dcce7a8301d38829101d50',1,'get_line(FILE *fp): utils.c'],['../utils_8h.html#a90fb7a370255e405c5384c4332bce847',1,'get_line(const FILE *fp): utils.h']]], + ['get_5fseq_5flocal',['Get_Seq_local',['../treeML_8c.html#a8a90f2586451905454dd568da9a0f759',1,'treeML.c']]], + ['getblock',['getBlock',['../misc_8c.html#a9fe543fe19ab3ff4ae9def519e1f0ac1',1,'getBlock(int i, const char *seq_0, const char *seq_k, const int *map_0, const int *map_k, char *block_0, char *block_k, int *z): misc.c'],['../misc_8h.html#a9fe543fe19ab3ff4ae9def519e1f0ac1',1,'getBlock(int i, const char *seq_0, const char *seq_k, const int *map_0, const int *map_k, char *block_0, char *block_k, int *z): misc.c']]], + ['getcumsum',['getCumSum',['../score_8h.html#ae5aac97ccd98fa3231294f3677204992',1,'score.h']]], + ['getdistancematrix',['getDistanceMatrix',['../treeSimulate_8c.html#a684681e84edaa63e768ec7ad1ff4884f',1,'getDistanceMatrix(TTree *tree, struct aln *alignment[]): treeSimulate.c'],['../treeSimulate_8h.html#a684681e84edaa63e768ec7ad1ff4884f',1,'getDistanceMatrix(TTree *tree, struct aln *alignment[]): treeSimulate.c']]], + ['getenv',['getenv',['../getopt_8c.html#aee28fd8a0e40b6d958f7d20348e45368',1,'getopt.c']]], + ['getextremevaluepars',['getExtremeValuePars',['../score_8c.html#aa313efebb5f1c1c987e98178c1668452',1,'getExtremeValuePars(TTree *tree, const struct aln *alignment[], int sampleN, float maxNativeScore, float *parMu, float *parLambda): score.c'],['../score_8h.html#aa313efebb5f1c1c987e98178c1668452',1,'getExtremeValuePars(TTree *tree, const struct aln *alignment[], int sampleN, float maxNativeScore, float *parMu, float *parLambda): score.c']]], + ['gethss',['getHSS',['../score_8c.html#a93045a86d8c050d38eed9c213ced83c7',1,'getHSS(float **S, const struct aln **inputAln, char strand): score.c'],['../score_8h.html#a93045a86d8c050d38eed9c213ced83c7',1,'getHSS(float **S, const struct aln **inputAln, char strand): score.c']]], + ['getlca',['getLCA',['../treeSimulate_8c.html#a3d5dbc026864385b3c931c928110b32a',1,'getLCA(TTree *tree, TNode *nodeA, TNode *nodeB): treeSimulate.c'],['../treeSimulate_8h.html#a3d5dbc026864385b3c931c928110b32a',1,'getLCA(TTree *tree, TNode *nodeA, TNode *nodeB): treeSimulate.c']]], + ['getmodelmatrix',['getModelMatrix',['../score_8h.html#a909825ebbd6f4923c4e425186001f095',1,'score.h']]], + ['getmodels',['getModels',['../score_8c.html#ad5c373a610e54d23a1cb8500d2634e9b',1,'getModels(TTree *tree, struct aln *alignment[], float kappa): score.c'],['../score_8h.html#ad5c373a610e54d23a1cb8500d2634e9b',1,'getModels(TTree *tree, struct aln *alignment[], float kappa): score.c']]], + ['getmultiplescorematrix',['getMultipleScoreMatrix',['../score_8c.html#af6b84950cd47402f4580d56eb22854fd',1,'getMultipleScoreMatrix(float ****Sk, bgModel *models, const struct aln *alignment[]): score.c'],['../score_8h.html#af6b84950cd47402f4580d56eb22854fd',1,'getMultipleScoreMatrix(float ****Sk, bgModel *models, const struct aln *alignment[]): score.c']]], + ['getopt',['getopt',['../getopt_8c.html#a1b2ada39ab92162c6ec9c67c8093fa2e',1,'getopt(int argc, char *const *argv, const char *optstring): getopt.c'],['../getopt_8h.html#a6c5b232cca42dab05f40b47f69715f8b',1,'getopt(): getopt.h']]], + ['getopt_5flong',['getopt_long',['../getopt_8h.html#a8616b8a74ae6c01a7ad95ad2876226ec',1,'getopt.h']]], + ['getopt_5flong_5fonly',['getopt_long_only',['../getopt_8h.html#ac07930413317507d5c51c19b3ac6ed20',1,'getopt.h']]], + ['getpairwisescorematrix',['getPairwiseScoreMatrix',['../score_8c.html#a6589227c4b47c35cca34ecc18c7f9634',1,'getPairwiseScoreMatrix(bgModel *models, const struct aln *alignment[]): score.c'],['../score_8h.html#a6589227c4b47c35cca34ecc18c7f9634',1,'getPairwiseScoreMatrix(bgModel *models, const struct aln *alignment[]): score.c']]], + ['getscoringmatrix',['getScoringMatrix',['../score_8c.html#a5deb0fecb3a13330879241f24575ac6c',1,'getScoringMatrix(): score.c'],['../score_8h.html#a5deb0fecb3a13330879241f24575ac6c',1,'getScoringMatrix(): score.c']]], + ['getseqlength',['getSeqLength',['../misc_8c.html#a935b3901ff2b656c44257b4606ceab6c',1,'getSeqLength(char *seq): misc.c'],['../misc_8h.html#a935b3901ff2b656c44257b4606ceab6c',1,'getSeqLength(char *seq): misc.c']]] +]; diff --git a/src/html/search/functions_8.html b/src/html/search/functions_8.html new file mode 100644 index 0000000..b55f0e6 --- /dev/null +++ b/src/html/search/functions_8.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_8.js b/src/html/search/functions_8.js new file mode 100644 index 0000000..252761a --- /dev/null +++ b/src/html/search/functions_8.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['hamming',['hamming',['../utils_8c.html#aad87a2700e9dcc28f48007ba3927f80e',1,'hamming(const char *s1, const char *s2): utils.c'],['../utils_8h.html#ad9dc7bfc9aa664dc6698f17ce07fc7e7',1,'hamming(const char *s1, const char *s2): utils.c']]], + ['hdist',['hDist',['../misc_8c.html#a62dbd6f5f78b8829c91c5e373b897f67',1,'hDist(int a1, int a2, int a3, int b1, int b2, int b3): misc.c'],['../misc_8h.html#a62dbd6f5f78b8829c91c5e373b897f67',1,'hDist(int a1, int a2, int a3, int b1, int b2, int b3): misc.c']]], + ['help',['help',['../RNAcode_8c.html#a0bed8474bd33a912769360766f6b10d4',1,'help(void): RNAcode.c'],['../RNAcode_8h.html#a0bed8474bd33a912769360766f6b10d4',1,'help(void): RNAcode.c']]] +]; diff --git a/src/html/search/functions_9.html b/src/html/search/functions_9.html new file mode 100644 index 0000000..c73f07b --- /dev/null +++ b/src/html/search/functions_9.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_9.js b/src/html/search/functions_9.js new file mode 100644 index 0000000..d57cb3e --- /dev/null +++ b/src/html/search/functions_9.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['init_5fargs_5finfo',['init_args_info',['../cmdline_8c.html#a4dcfd361cdaac143739a02102296fedd',1,'cmdline.c']]], + ['init_5frand',['init_rand',['../utils_8c.html#ade17b35078a34c6d26b09148c6f81f4d',1,'init_rand(void): utils.c'],['../utils_8h.html#a8aaa6d9be6f803f496d9b97375c371f3',1,'init_rand(void): utils.c']]], + ['int_5furn',['int_urn',['../utils_8c.html#af0a9bc3a6894eea7895d5cdf825bccd6',1,'int_urn(int from, int to): utils.c'],['../utils_8h.html#a68ff0849d44f62fe491800378a5ffcb4',1,'int_urn(int from, int to): utils.c']]] +]; diff --git a/src/html/search/functions_a.html b/src/html/search/functions_a.html new file mode 100644 index 0000000..f10ad63 --- /dev/null +++ b/src/html/search/functions_a.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_a.js b/src/html/search/functions_a.js new file mode 100644 index 0000000..27ed2fb --- /dev/null +++ b/src/html/search/functions_a.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['lawless416',['Lawless416',['../extreme__fit_8c.html#ac7d28c2cfa789de3864ed5d07ef800ec',1,'extreme_fit.c']]], + ['lawless422',['Lawless422',['../extreme__fit_8c.html#a05c76c8801e372734c3888b165c28f86',1,'extreme_fit.c']]], + ['linsys',['linsys',['../weight_8c.html#a938fd9f0d302e85abaed502179b51275',1,'linsys(float **a, float *b, int N): weight.c'],['../weight_8h.html#a938fd9f0d302e85abaed502179b51275',1,'linsys(float **a, float *b, int N): weight.c']]] +]; diff --git a/src/html/search/functions_b.html b/src/html/search/functions_b.html new file mode 100644 index 0000000..172ea1b --- /dev/null +++ b/src/html/search/functions_b.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_b.js b/src/html/search/functions_b.js new file mode 100644 index 0000000..2ff8d23 --- /dev/null +++ b/src/html/search/functions_b.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['main',['main',['../RNAcode_8c.html#a0ddf1224851353fc92bfbff6f499fa97',1,'RNAcode.c']]], + ['make_5fpair_5ftable',['make_pair_table',['../utils_8c.html#a84f42ca126d57c91364fde04b622b014',1,'make_pair_table(const char *structure): utils.c'],['../utils_8h.html#a89c32307ee50a0026f4a3131fac0845a',1,'make_pair_table(const char *structure): utils.c']]], + ['meanpairid',['meanPairID',['../rnaz__utils_8c.html#a802470f11cb32abaa510b2c67f098235',1,'meanPairID(const struct aln *AS[]): rnaz_utils.c'],['../rnaz__utils_8h.html#a802470f11cb32abaa510b2c67f098235',1,'meanPairID(const struct aln *AS[]): rnaz_utils.c']]], + ['my_5findex',['my_index',['../getopt_8c.html#ae0ac978b7775f69496c0f127ffdada9d',1,'getopt.c']]] +]; diff --git a/src/html/search/functions_c.html b/src/html/search/functions_c.html new file mode 100644 index 0000000..99492ba --- /dev/null +++ b/src/html/search/functions_c.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_c.js b/src/html/search/functions_c.js new file mode 100644 index 0000000..ef8062d --- /dev/null +++ b/src/html/search/functions_c.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['nrerror',['nrerror',['../utils_8c.html#a93e5a2447f559f7930054555a4252ccd',1,'nrerror(const char message[]): utils.c'],['../utils_8h.html#a127ce946e56b5a5773781cabe68e38c5',1,'nrerror(const char message[]): utils.c']]] +]; diff --git a/src/html/search/functions_d.html b/src/html/search/functions_d.html new file mode 100644 index 0000000..5be9ecc --- /dev/null +++ b/src/html/search/functions_d.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_d.js b/src/html/search/functions_d.js new file mode 100644 index 0000000..9e60943 --- /dev/null +++ b/src/html/search/functions_d.js @@ -0,0 +1,12 @@ +var searchData= +[ + ['pack_5fstructure',['pack_structure',['../utils_8c.html#aa3a18376e73375f7ccb0abc90d162a02',1,'pack_structure(const char *struc): utils.c'],['../utils_8h.html#ac6dfa5e22928c087c6e09ff0054a7ced',1,'pack_structure(const char *struc): utils.c']]], + ['pos2col',['pos2col',['../misc_8c.html#af49091737065e3ea21101edf17533dcf',1,'pos2col(const char *seq, int pos): misc.c'],['../misc_8h.html#af49091737065e3ea21101edf17533dcf',1,'pos2col(const char *seq, int pos): misc.c']]], + ['print_5fhelp_5fcommon',['print_help_common',['../cmdline_8c.html#ad600bb9026825a295ea57df22bdf7eca',1,'cmdline.c']]], + ['printaln',['printAln',['../rnaz__utils_8c.html#ad1830dc656474e2da129e5322927ee15',1,'printAln(const struct aln *AS[]): rnaz_utils.c'],['../rnaz__utils_8h.html#ad1830dc656474e2da129e5322927ee15',1,'printAln(const struct aln *AS[]): rnaz_utils.c']]], + ['printalnclustal',['printAlnClustal',['../misc_8c.html#a622e2235405d5fce48465d284271642c',1,'printAlnClustal(FILE *out, const struct aln *AS[]): misc.c'],['../misc_8h.html#a622e2235405d5fce48465d284271642c',1,'printAlnClustal(FILE *out, const struct aln *AS[]): misc.c']]], + ['printalnmaf',['printAlnMAF',['../rnaz__utils_8c.html#a7dc7886bc41a49ff0a19e67451026d81',1,'printAlnMAF(FILE *out, const struct aln *AS[], int printU): rnaz_utils.c'],['../rnaz__utils_8h.html#a7dc7886bc41a49ff0a19e67451026d81',1,'printAlnMAF(FILE *out, const struct aln *AS[], int printU): rnaz_utils.c']]], + ['printresults',['printResults',['../misc_8c.html#a326b72f1de05ef655a3188af0af23aee',1,'printResults(FILE *outfile, int outputFormat, const struct aln *inputAln[], segmentStats results[]): misc.c'],['../misc_8h.html#a92f776363f89ffb2864dc72fa7c8471f',1,'printResults(FILE *outfile, int outputFormat, const struct aln *AS[], segmentStats results[]): misc.c']]], + ['probhky',['probHKY',['../score_8c.html#a10a41c7b92952d470f0f8d2af7bd2c1b',1,'probHKY(int i, int j, float d, float freqs[4], float kappa): score.c'],['../score_8h.html#a10a41c7b92952d470f0f8d2af7bd2c1b',1,'probHKY(int i, int j, float d, float freqs[4], float kappa): score.c']]], + ['prunealn',['pruneAln',['../rnaz__utils_8c.html#a121bcc17b926e5be6edd36caea0a8985',1,'pruneAln(char *species, struct aln *alignment[]): rnaz_utils.c'],['../rnaz__utils_8h.html#a4dbf87f40603a4c37ccb6e312f7ee4fb',1,'pruneAln(char *species, struct aln *AS[]): rnaz_utils.c']]] +]; diff --git a/src/html/search/functions_e.html b/src/html/search/functions_e.html new file mode 100644 index 0000000..e256cb6 --- /dev/null +++ b/src/html/search/functions_e.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_e.js b/src/html/search/functions_e.js new file mode 100644 index 0000000..9f0da0c --- /dev/null +++ b/src/html/search/functions_e.js @@ -0,0 +1,9 @@ +var searchData= +[ + ['random_5fstring',['random_string',['../utils_8c.html#ab4ae5a543569ad8c331564963ea50f68',1,'random_string(int l, const char symbols[]): utils.c'],['../utils_8h.html#a1b95eac365a021572e1c37e5993a89be',1,'random_string(int l, const char symbols[]): utils.c']]], + ['read_5fclustal',['read_clustal',['../rnaz__utils_8c.html#ad571d9ad5858c8e2d834225efec51163',1,'read_clustal(FILE *clust, struct aln *alignedSeqs[]): rnaz_utils.c'],['../rnaz__utils_8h.html#ad571d9ad5858c8e2d834225efec51163',1,'read_clustal(FILE *clust, struct aln *alignedSeqs[]): rnaz_utils.c']]], + ['read_5fcommandline',['read_commandline',['../RNAcode_8c.html#ae36ab4408b3aaada4218ac5f60ea6027',1,'read_commandline(int argc, char *argv[]): RNAcode.c'],['../RNAcode_8h.html#ae36ab4408b3aaada4218ac5f60ea6027',1,'read_commandline(int argc, char *argv[]): RNAcode.c']]], + ['read_5fmaf',['read_maf',['../rnaz__utils_8c.html#a2207280ef510cc5d737b0b04bcfba476',1,'read_maf(FILE *clust, struct aln *alignedSeqs[]): rnaz_utils.c'],['../rnaz__utils_8h.html#a2207280ef510cc5d737b0b04bcfba476',1,'read_maf(FILE *clust, struct aln *alignedSeqs[]): rnaz_utils.c']]], + ['reintroducegaps',['reintroduceGaps',['../misc_8c.html#a8eed68ed1197df02c8b9a49264efc717',1,'reintroduceGaps(const struct aln *origAln[], struct aln *sampledAln[]): misc.c'],['../misc_8h.html#a8eed68ed1197df02c8b9a49264efc717',1,'reintroduceGaps(const struct aln *origAln[], struct aln *sampledAln[]): misc.c']]], + ['revaln',['revAln',['../rnaz__utils_8c.html#a9c0adcc1f46e9fceab51c54bd25475e2',1,'revAln(struct aln *AS[]): rnaz_utils.c'],['../rnaz__utils_8h.html#a9c0adcc1f46e9fceab51c54bd25475e2',1,'revAln(struct aln *AS[]): rnaz_utils.c']]] +]; diff --git a/src/html/search/functions_f.html b/src/html/search/functions_f.html new file mode 100644 index 0000000..424126c --- /dev/null +++ b/src/html/search/functions_f.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/functions_f.js b/src/html/search/functions_f.js new file mode 100644 index 0000000..596b4cc --- /dev/null +++ b/src/html/search/functions_f.js @@ -0,0 +1,16 @@ +var searchData= +[ + ['scorealn',['scoreAln',['../score_8c.html#a098269687ae30d844d2c6b58793f2d2c',1,'scoreAln(const struct aln *inputAln[], TTree *tree, float kappa, int backtrack): score.c'],['../score_8h.html#af667df05b60aeb3ec0bd6bd423e268db',1,'scoreAln(const struct aln *alignment[], TTree *tree, float kappa, int backtrack): score.c']]], + ['setparameters',['setParameters',['../postscript_8c.html#a1d6c94586a33965dd4277c7fe62de430',1,'setParameters(): postscript.c'],['../postscript_8h.html#a1d6c94586a33965dd4277c7fe62de430',1,'setParameters(): postscript.c']]], + ['simulatetree',['simulateTree',['../treeSimulate_8c.html#a2a10fb3293a345ad28201efc8f452348',1,'simulateTree(TTree *tree, float freqs[], float kap, int L): treeSimulate.c'],['../treeSimulate_8h.html#a2a10fb3293a345ad28201efc8f452348',1,'simulateTree(TTree *tree, float freqs[], float kap, int L): treeSimulate.c']]], + ['slicealn',['sliceAln',['../rnaz__utils_8c.html#a43cebeec9c40c9be2970b4ed266e7065',1,'sliceAln(const struct aln *sourceAln[], struct aln *destAln[], int from, int to): rnaz_utils.c'],['../rnaz__utils_8h.html#a43cebeec9c40c9be2970b4ed266e7065',1,'sliceAln(const struct aln *sourceAln[], struct aln *destAln[], int from, int to): rnaz_utils.c']]], + ['sortaln',['sortAln',['../misc_8c.html#a5753372a1a3c3974fc6be9a6030a67bf',1,'sortAln(const struct aln *origAln[], struct aln *sampledAln[]): misc.c'],['../misc_8h.html#a5753372a1a3c3974fc6be9a6030a67bf',1,'sortAln(const struct aln *origAln[], struct aln *sampledAln[]): misc.c']]], + ['space',['space',['../utils_8c.html#a5dac704be118855d7c4dd3aa3bc31fc3',1,'space(unsigned int size): utils.c'],['../utils_8c.html#a38098f2a039377364b35c84560792ecb',1,'space(unsigned size): utils.c'],['../utils_8h.html#ad7e1e137b3bf1f7108933d302a7f0177',1,'space(unsigned size): utils.c']]], + ['splitfields',['splitFields',['../rnaz__utils_8c.html#a174b786ba35d783d0937a545d2d4071b',1,'splitFields(char *string): rnaz_utils.c'],['../rnaz__utils_8h.html#a174b786ba35d783d0937a545d2d4071b',1,'splitFields(char *string): rnaz_utils.c']]], + ['splitlines',['splitLines',['../rnaz__utils_8c.html#ad897a202b424203bee4a1746872aa095',1,'splitLines(char *string): rnaz_utils.c'],['../rnaz__utils_8h.html#ad897a202b424203bee4a1746872aa095',1,'splitLines(char *string): rnaz_utils.c']]], + ['splitstring',['splitString',['../rnaz__utils_8c.html#a7d5f1b4f24c9a156013547278b473278',1,'splitString(char *string, char *separators): rnaz_utils.c'],['../rnaz__utils_8h.html#a7d5f1b4f24c9a156013547278b473278',1,'splitString(char *string, char *separators): rnaz_utils.c']]], + ['stddev',['stddev',['../misc_8c.html#ac9b591bdb26f6a8b8ee56aee3e809c65',1,'stddev(float *data, int N): misc.c'],['../misc_8h.html#ac9b591bdb26f6a8b8ee56aee3e809c65',1,'stddev(float *data, int N): misc.c']]], + ['string2tree',['string2tree',['../treeSimulate_8c.html#af77eeafe78dc6291a2c5a0f9e0dea164',1,'string2tree(char *treeString): treeSimulate.c'],['../treeSimulate_8h.html#af77eeafe78dc6291a2c5a0f9e0dea164',1,'string2tree(char *treeString): treeSimulate.c']]], + ['stripgaps',['stripGaps',['../score_8h.html#a50f4b7f86944e31e967a5d2e7d045c01',1,'score.h']]], + ['sumofpairscore',['sumOfPairScore',['../score_8h.html#ab64745553f4c76c089d6dc44f76f639b',1,'score.h']]] +]; diff --git a/src/html/search/mag_sel.png b/src/html/search/mag_sel.png new file mode 100644 index 0000000..81f6040 Binary files /dev/null and b/src/html/search/mag_sel.png differ diff --git a/src/html/search/nomatches.html b/src/html/search/nomatches.html new file mode 100644 index 0000000..b1ded27 --- /dev/null +++ b/src/html/search/nomatches.html @@ -0,0 +1,12 @@ + + + + + + + +
+
No Matches
+
+ + diff --git a/src/html/search/pages_0.html b/src/html/search/pages_0.html new file mode 100644 index 0000000..4955b9e --- /dev/null +++ b/src/html/search/pages_0.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/pages_0.js b/src/html/search/pages_0.js new file mode 100644 index 0000000..038da54 --- /dev/null +++ b/src/html/search/pages_0.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['deprecated_20list',['Deprecated List',['../deprecated.html',1,'']]] +]; diff --git a/src/html/search/search.css b/src/html/search/search.css new file mode 100644 index 0000000..3cf9df9 --- /dev/null +++ b/src/html/search/search.css @@ -0,0 +1,271 @@ +/*---------------- Search Box */ + +#FSearchBox { + float: left; +} + +#MSearchBox { + white-space : nowrap; + float: none; + margin-top: 8px; + right: 0px; + width: 170px; + height: 24px; + z-index: 102; +} + +#MSearchBox .left +{ + display:block; + position:absolute; + left:10px; + width:20px; + height:19px; + background:url('search_l.png') no-repeat; + background-position:right; +} + +#MSearchSelect { + display:block; + position:absolute; + width:20px; + height:19px; +} + +.left #MSearchSelect { + left:4px; +} + +.right #MSearchSelect { + right:5px; +} + +#MSearchField { + display:block; + position:absolute; + height:19px; + background:url('search_m.png') repeat-x; + border:none; + width:115px; + margin-left:20px; + padding-left:4px; + color: #909090; + outline: none; + font: 9pt Arial, Verdana, sans-serif; + -webkit-border-radius: 0px; +} + +#FSearchBox #MSearchField { + margin-left:15px; +} + +#MSearchBox .right { + display:block; + position:absolute; + right:10px; + top:8px; + width:20px; + height:19px; + background:url('search_r.png') no-repeat; + background-position:left; +} + +#MSearchClose { + display: none; + position: absolute; + top: 4px; + background : none; + border: none; + margin: 0px 4px 0px 0px; + padding: 0px 0px; + outline: none; +} + +.left #MSearchClose { + left: 6px; +} + +.right #MSearchClose { + right: 2px; +} + +.MSearchBoxActive #MSearchField { + color: #000000; +} + +/*---------------- Search filter selection */ + +#MSearchSelectWindow { + display: none; + position: absolute; + left: 0; top: 0; + border: 1px solid #90A5CE; + background-color: #F9FAFC; + z-index: 10001; + padding-top: 4px; + padding-bottom: 4px; + -moz-border-radius: 4px; + -webkit-border-top-left-radius: 4px; + -webkit-border-top-right-radius: 4px; + -webkit-border-bottom-left-radius: 4px; + -webkit-border-bottom-right-radius: 4px; + -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); +} + +.SelectItem { + font: 8pt Arial, Verdana, sans-serif; + padding-left: 2px; + padding-right: 12px; + border: 0px; +} + +span.SelectionMark { + margin-right: 4px; + font-family: monospace; + outline-style: none; + text-decoration: none; +} + +a.SelectItem { + display: block; + outline-style: none; + color: #000000; + text-decoration: none; + padding-left: 6px; + padding-right: 12px; +} + +a.SelectItem:focus, +a.SelectItem:active { + color: #000000; + outline-style: none; + text-decoration: none; +} + +a.SelectItem:hover { + color: #FFFFFF; + background-color: #3D578C; + outline-style: none; + text-decoration: none; + cursor: pointer; + display: block; +} + +/*---------------- Search results window */ + +iframe#MSearchResults { + width: 60ex; + height: 15em; +} + +#MSearchResultsWindow { + display: none; + position: absolute; + left: 0; top: 0; + border: 1px solid #000; + background-color: #EEF1F7; + z-index:10000; +} + +/* ----------------------------------- */ + + +#SRIndex { + clear:both; + padding-bottom: 15px; +} + +.SREntry { + font-size: 10pt; + padding-left: 1ex; +} + +.SRPage .SREntry { + font-size: 8pt; + padding: 1px 5px; +} + +body.SRPage { + margin: 5px 2px; +} + +.SRChildren { + padding-left: 3ex; padding-bottom: .5em +} + +.SRPage .SRChildren { + display: none; +} + +.SRSymbol { + font-weight: bold; + color: #425E97; + font-family: Arial, Verdana, sans-serif; + text-decoration: none; + outline: none; +} + +a.SRScope { + display: block; + color: #425E97; + font-family: Arial, Verdana, sans-serif; + text-decoration: none; + outline: none; +} + +a.SRSymbol:focus, a.SRSymbol:active, +a.SRScope:focus, a.SRScope:active { + text-decoration: underline; +} + +span.SRScope { + padding-left: 4px; +} + +.SRPage .SRStatus { + padding: 2px 5px; + font-size: 8pt; + font-style: italic; +} + +.SRResult { + display: none; +} + +DIV.searchresults { + margin-left: 10px; + margin-right: 10px; +} + +/*---------------- External search page results */ + +.searchresult { + background-color: #F0F3F8; +} + +.pages b { + color: white; + padding: 5px 5px 3px 5px; + background-image: url("../tab_a.png"); + background-repeat: repeat-x; + text-shadow: 0 1px 1px #000000; +} + +.pages { + line-height: 17px; + margin-left: 4px; + text-decoration: none; +} + +.hl { + font-weight: bold; +} + +#searchresults { + margin-bottom: 20px; +} + +.searchpages { + margin-top: 10px; +} + diff --git a/src/html/search/search.js b/src/html/search/search.js new file mode 100644 index 0000000..dedce3b --- /dev/null +++ b/src/html/search/search.js @@ -0,0 +1,791 @@ +function convertToId(search) +{ + var result = ''; + for (i=0;i do a search + { + this.Search(); + } + } + + this.OnSearchSelectKey = function(evt) + { + var e = (evt) ? evt : window.event; // for IE + if (e.keyCode==40 && this.searchIndex0) // Up + { + this.searchIndex--; + this.OnSelectItem(this.searchIndex); + } + else if (e.keyCode==13 || e.keyCode==27) + { + this.OnSelectItem(this.searchIndex); + this.CloseSelectionWindow(); + this.DOMSearchField().focus(); + } + return false; + } + + // --------- Actions + + // Closes the results window. + this.CloseResultsWindow = function() + { + this.DOMPopupSearchResultsWindow().style.display = 'none'; + this.DOMSearchClose().style.display = 'none'; + this.Activate(false); + } + + this.CloseSelectionWindow = function() + { + this.DOMSearchSelectWindow().style.display = 'none'; + } + + // Performs a search. + this.Search = function() + { + this.keyTimeout = 0; + + // strip leading whitespace + var searchValue = this.DOMSearchField().value.replace(/^ +/, ""); + + var code = searchValue.toLowerCase().charCodeAt(0); + var idxChar = searchValue.substr(0, 1).toLowerCase(); + if ( 0xD800 <= code && code <= 0xDBFF && searchValue > 1) // surrogate pair + { + idxChar = searchValue.substr(0, 2); + } + + var resultsPage; + var resultsPageWithSearch; + var hasResultsPage; + + var idx = indexSectionsWithContent[this.searchIndex].indexOf(idxChar); + if (idx!=-1) + { + var hexCode=idx.toString(16); + resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html'; + resultsPageWithSearch = resultsPage+'?'+escape(searchValue); + hasResultsPage = true; + } + else // nothing available for this search term + { + resultsPage = this.resultsPath + '/nomatches.html'; + resultsPageWithSearch = resultsPage; + hasResultsPage = false; + } + + window.frames.MSearchResults.location = resultsPageWithSearch; + var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow(); + + if (domPopupSearchResultsWindow.style.display!='block') + { + var domSearchBox = this.DOMSearchBox(); + this.DOMSearchClose().style.display = 'inline'; + if (this.insideFrame) + { + var domPopupSearchResults = this.DOMPopupSearchResults(); + domPopupSearchResultsWindow.style.position = 'relative'; + domPopupSearchResultsWindow.style.display = 'block'; + var width = document.body.clientWidth - 8; // the -8 is for IE :-( + domPopupSearchResultsWindow.style.width = width + 'px'; + domPopupSearchResults.style.width = width + 'px'; + } + else + { + var domPopupSearchResults = this.DOMPopupSearchResults(); + var left = getXPos(domSearchBox) + 150; // domSearchBox.offsetWidth; + var top = getYPos(domSearchBox) + 20; // domSearchBox.offsetHeight + 1; + domPopupSearchResultsWindow.style.display = 'block'; + left -= domPopupSearchResults.offsetWidth; + domPopupSearchResultsWindow.style.top = top + 'px'; + domPopupSearchResultsWindow.style.left = left + 'px'; + } + } + + this.lastSearchValue = searchValue; + this.lastResultsPage = resultsPage; + } + + // -------- Activation Functions + + // Activates or deactivates the search panel, resetting things to + // their default values if necessary. + this.Activate = function(isActive) + { + if (isActive || // open it + this.DOMPopupSearchResultsWindow().style.display == 'block' + ) + { + this.DOMSearchBox().className = 'MSearchBoxActive'; + + var searchField = this.DOMSearchField(); + + if (searchField.value == this.searchLabel) // clear "Search" term upon entry + { + searchField.value = ''; + this.searchActive = true; + } + } + else if (!isActive) // directly remove the panel + { + this.DOMSearchBox().className = 'MSearchBoxInactive'; + this.DOMSearchField().value = this.searchLabel; + this.searchActive = false; + this.lastSearchValue = '' + this.lastResultsPage = ''; + } + } +} + +// ----------------------------------------------------------------------- + +// The class that handles everything on the search results page. +function SearchResults(name) +{ + // The number of matches from the last run of . + this.lastMatchCount = 0; + this.lastKey = 0; + this.repeatOn = false; + + // Toggles the visibility of the passed element ID. + this.FindChildElement = function(id) + { + var parentElement = document.getElementById(id); + var element = parentElement.firstChild; + + while (element && element!=parentElement) + { + if (element.nodeName == 'DIV' && element.className == 'SRChildren') + { + return element; + } + + if (element.nodeName == 'DIV' && element.hasChildNodes()) + { + element = element.firstChild; + } + else if (element.nextSibling) + { + element = element.nextSibling; + } + else + { + do + { + element = element.parentNode; + } + while (element && element!=parentElement && !element.nextSibling); + + if (element && element!=parentElement) + { + element = element.nextSibling; + } + } + } + } + + this.Toggle = function(id) + { + var element = this.FindChildElement(id); + if (element) + { + if (element.style.display == 'block') + { + element.style.display = 'none'; + } + else + { + element.style.display = 'block'; + } + } + } + + // Searches for the passed string. If there is no parameter, + // it takes it from the URL query. + // + // Always returns true, since other documents may try to call it + // and that may or may not be possible. + this.Search = function(search) + { + if (!search) // get search word from URL + { + search = window.location.search; + search = search.substring(1); // Remove the leading '?' + search = unescape(search); + } + + search = search.replace(/^ +/, ""); // strip leading spaces + search = search.replace(/ +$/, ""); // strip trailing spaces + search = search.toLowerCase(); + search = convertToId(search); + + var resultRows = document.getElementsByTagName("div"); + var matches = 0; + + var i = 0; + while (i < resultRows.length) + { + var row = resultRows.item(i); + if (row.className == "SRResult") + { + var rowMatchName = row.id.toLowerCase(); + rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); // strip 'sr123_' + + if (search.length<=rowMatchName.length && + rowMatchName.substr(0, search.length)==search) + { + row.style.display = 'block'; + matches++; + } + else + { + row.style.display = 'none'; + } + } + i++; + } + document.getElementById("Searching").style.display='none'; + if (matches == 0) // no results + { + document.getElementById("NoMatches").style.display='block'; + } + else // at least one result + { + document.getElementById("NoMatches").style.display='none'; + } + this.lastMatchCount = matches; + return true; + } + + // return the first item with index index or higher that is visible + this.NavNext = function(index) + { + var focusItem; + while (1) + { + var focusName = 'Item'+index; + focusItem = document.getElementById(focusName); + if (focusItem && focusItem.parentNode.parentNode.style.display=='block') + { + break; + } + else if (!focusItem) // last element + { + break; + } + focusItem=null; + index++; + } + return focusItem; + } + + this.NavPrev = function(index) + { + var focusItem; + while (1) + { + var focusName = 'Item'+index; + focusItem = document.getElementById(focusName); + if (focusItem && focusItem.parentNode.parentNode.style.display=='block') + { + break; + } + else if (!focusItem) // last element + { + break; + } + focusItem=null; + index--; + } + return focusItem; + } + + this.ProcessKeys = function(e) + { + if (e.type == "keydown") + { + this.repeatOn = false; + this.lastKey = e.keyCode; + } + else if (e.type == "keypress") + { + if (!this.repeatOn) + { + if (this.lastKey) this.repeatOn = true; + return false; // ignore first keypress after keydown + } + } + else if (e.type == "keyup") + { + this.lastKey = 0; + this.repeatOn = false; + } + return this.lastKey!=0; + } + + this.Nav = function(evt,itemIndex) + { + var e = (evt) ? evt : window.event; // for IE + if (e.keyCode==13) return true; + if (!this.ProcessKeys(e)) return false; + + if (this.lastKey==38) // Up + { + var newIndex = itemIndex-1; + var focusItem = this.NavPrev(newIndex); + if (focusItem) + { + var child = this.FindChildElement(focusItem.parentNode.parentNode.id); + if (child && child.style.display == 'block') // children visible + { + var n=0; + var tmpElem; + while (1) // search for last child + { + tmpElem = document.getElementById('Item'+newIndex+'_c'+n); + if (tmpElem) + { + focusItem = tmpElem; + } + else // found it! + { + break; + } + n++; + } + } + } + if (focusItem) + { + focusItem.focus(); + } + else // return focus to search field + { + parent.document.getElementById("MSearchField").focus(); + } + } + else if (this.lastKey==40) // Down + { + var newIndex = itemIndex+1; + var focusItem; + var item = document.getElementById('Item'+itemIndex); + var elem = this.FindChildElement(item.parentNode.parentNode.id); + if (elem && elem.style.display == 'block') // children visible + { + focusItem = document.getElementById('Item'+itemIndex+'_c0'); + } + if (!focusItem) focusItem = this.NavNext(newIndex); + if (focusItem) focusItem.focus(); + } + else if (this.lastKey==39) // Right + { + var item = document.getElementById('Item'+itemIndex); + var elem = this.FindChildElement(item.parentNode.parentNode.id); + if (elem) elem.style.display = 'block'; + } + else if (this.lastKey==37) // Left + { + var item = document.getElementById('Item'+itemIndex); + var elem = this.FindChildElement(item.parentNode.parentNode.id); + if (elem) elem.style.display = 'none'; + } + else if (this.lastKey==27) // Escape + { + parent.searchBox.CloseResultsWindow(); + parent.document.getElementById("MSearchField").focus(); + } + else if (this.lastKey==13) // Enter + { + return true; + } + return false; + } + + this.NavChild = function(evt,itemIndex,childIndex) + { + var e = (evt) ? evt : window.event; // for IE + if (e.keyCode==13) return true; + if (!this.ProcessKeys(e)) return false; + + if (this.lastKey==38) // Up + { + if (childIndex>0) + { + var newIndex = childIndex-1; + document.getElementById('Item'+itemIndex+'_c'+newIndex).focus(); + } + else // already at first child, jump to parent + { + document.getElementById('Item'+itemIndex).focus(); + } + } + else if (this.lastKey==40) // Down + { + var newIndex = childIndex+1; + var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex); + if (!elem) // last child, jump to parent next parent + { + elem = this.NavNext(itemIndex+1); + } + if (elem) + { + elem.focus(); + } + } + else if (this.lastKey==27) // Escape + { + parent.searchBox.CloseResultsWindow(); + parent.document.getElementById("MSearchField").focus(); + } + else if (this.lastKey==13) // Enter + { + return true; + } + return false; + } +} + +function setKeyActions(elem,action) +{ + elem.setAttribute('onkeydown',action); + elem.setAttribute('onkeypress',action); + elem.setAttribute('onkeyup',action); +} + +function setClassAttr(elem,attr) +{ + elem.setAttribute('class',attr); + elem.setAttribute('className',attr); +} + +function createResults() +{ + var results = document.getElementById("SRResults"); + for (var e=0; e + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/typedefs_0.js b/src/html/search/typedefs_0.js new file mode 100644 index 0000000..87c92a1 --- /dev/null +++ b/src/html/search/typedefs_0.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['backtrackdata',['backtrackData',['../score_8h.html#a0751e1c4932f95e3e60c73409408a97f',1,'score.h']]], + ['bgmodel',['bgModel',['../score_8h.html#aec88546fa977a827f3312b2c12738421',1,'score.h']]] +]; diff --git a/src/html/search/typedefs_1.html b/src/html/search/typedefs_1.html new file mode 100644 index 0000000..b77c533 --- /dev/null +++ b/src/html/search/typedefs_1.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/typedefs_1.js b/src/html/search/typedefs_1.js new file mode 100644 index 0000000..ab461aa --- /dev/null +++ b/src/html/search/typedefs_1.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['parameters',['parameters',['../RNAcode_8h.html#ac21aeabbefffddb27496994611a09dcd',1,'RNAcode.h']]] +]; diff --git a/src/html/search/typedefs_2.html b/src/html/search/typedefs_2.html new file mode 100644 index 0000000..076311d --- /dev/null +++ b/src/html/search/typedefs_2.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/typedefs_2.js b/src/html/search/typedefs_2.js new file mode 100644 index 0000000..e68927c --- /dev/null +++ b/src/html/search/typedefs_2.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['segmentstats',['segmentStats',['../score_8h.html#a5b7f5df9506ff8c871dc49e4bf9f22af',1,'score.h']]] +]; diff --git a/src/html/search/variables_0.html b/src/html/search/variables_0.html new file mode 100644 index 0000000..74ce807 --- /dev/null +++ b/src/html/search/variables_0.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_0.js b/src/html/search/variables_0.js new file mode 100644 index 0000000..d612693 --- /dev/null +++ b/src/html/search/variables_0.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['_5f_5fgetopt_5finitialized',['__getopt_initialized',['../getopt_8c.html#a28286be757527aeb1db951b5da9aeec1',1,'getopt.c']]] +]; diff --git a/src/html/search/variables_1.html b/src/html/search/variables_1.html new file mode 100644 index 0000000..84237b6 --- /dev/null +++ b/src/html/search/variables_1.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_1.js b/src/html/search/variables_1.js new file mode 100644 index 0000000..18027f8 --- /dev/null +++ b/src/html/search/variables_1.js @@ -0,0 +1,19 @@ +var searchData= +[ + ['best_5fonly_5fflag',['best_only_flag',['../structgengetopt__args__info.html#ab0275ce8469b8fa0415ec84a692aba90',1,'gengetopt_args_info']]], + ['best_5fonly_5fgiven',['best_only_given',['../structgengetopt__args__info.html#a6c48b4d066a85f4a580a6a64dbdb176e',1,'gengetopt_args_info']]], + ['best_5fonly_5fhelp',['best_only_help',['../structgengetopt__args__info.html#a4f31622f59d764e13fe3ef9d3d0cc579',1,'gengetopt_args_info']]], + ['best_5fregion_5fflag',['best_region_flag',['../structgengetopt__args__info.html#a4ee2d5172359ee7a6b7fd042fae11817',1,'gengetopt_args_info']]], + ['best_5fregion_5fgiven',['best_region_given',['../structgengetopt__args__info.html#afd4b6f3efee5f421948359ec5eea335c',1,'gengetopt_args_info']]], + ['best_5fregion_5fhelp',['best_region_help',['../structgengetopt__args__info.html#a8943d1adc6dc6a89790adb4ce383943e',1,'gengetopt_args_info']]], + ['bestonly',['bestOnly',['../struct__parameters.html#acdebd1fac8029bad117f9ba82bef93d5',1,'_parameters']]], + ['bestregion',['bestRegion',['../struct__parameters.html#ad8bdd1fcbd46e8fb6842e5ab77b9c8fe',1,'_parameters']]], + ['blockstep',['blockStep',['../postscript_8c.html#a2d6e8a7836bfad8586715c3bb775cbb4',1,'postscript.c']]], + ['blosum',['blosum',['../struct__parameters.html#a3857ab2091fd5bbda92463952163163f',1,'_parameters']]], + ['blosum62',['BLOSUM62',['../code_8c.html#a528f2f941a2c7a8de187c946e438d107',1,'BLOSUM62(): code.c'],['../score_8c.html#a528f2f941a2c7a8de187c946e438d107',1,'BLOSUM62(): code.c']]], + ['blosum90',['BLOSUM90',['../code_8c.html#addcd68ee32c359359fcb55b5bfd8a62f',1,'BLOSUM90(): code.c'],['../score_8c.html#addcd68ee32c359359fcb55b5bfd8a62f',1,'BLOSUM90(): code.c']]], + ['blosum_5farg',['blosum_arg',['../structgengetopt__args__info.html#a7d3c9030b97320380911d603e2130e0d',1,'gengetopt_args_info']]], + ['blosum_5fgiven',['blosum_given',['../structgengetopt__args__info.html#a5c4114dd20295edf631f04e637214386',1,'gengetopt_args_info']]], + ['blosum_5fhelp',['blosum_help',['../structgengetopt__args__info.html#a6527f32b39a7c09ee3daffe899887075',1,'gengetopt_args_info']]], + ['blosum_5forig',['blosum_orig',['../structgengetopt__args__info.html#a93a262b5d97dda58b75849a1318e2918',1,'gengetopt_args_info']]] +]; diff --git a/src/html/search/variables_10.html b/src/html/search/variables_10.html new file mode 100644 index 0000000..548ac84 --- /dev/null +++ b/src/html/search/variables_10.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_10.js b/src/html/search/variables_10.js new file mode 100644 index 0000000..9b0044c --- /dev/null +++ b/src/html/search/variables_10.js @@ -0,0 +1,24 @@ +var searchData= +[ + ['samplen',['sampleN',['../struct__parameters.html#a40706f4d64be0c9ee5cb411cee949416',1,'_parameters']]], + ['score',['score',['../struct__segmentStats.html#aea28293c9c59198e9f14542d99ac1484',1,'_segmentStats']]], + ['scores',['scores',['../struct__bgModel.html#af4fae6328e121d42a0a8fb3dd882c549',1,'_bgModel::scores()'],['../struct__backtrackData.html#af803a69e3c75e33c0ba7df036642c44d',1,'_backtrackData::scores()']]], + ['seq',['seq',['../structaln.html#aee1fbffa2c18c0b3d6016b8fe409eeae',1,'aln']]], + ['seqsx',['seqsX',['../postscript_8c.html#a69294d581be62ee920a2ef6622500cbd',1,'postscript.c']]], + ['sk',['Sk',['../RNAcode_8c.html#a1662932a5f2814e67dfbbd95ab925073',1,'Sk(): RNAcode.c'],['../score_8c.html#a1662932a5f2814e67dfbbd95ab925073',1,'Sk(): RNAcode.c']]], + ['sk_5fnative',['Sk_native',['../postscript_8c.html#a189ec0118947b93b0df1359ab643d3ce',1,'Sk_native(): postscript.c'],['../RNAcode_8c.html#a189ec0118947b93b0df1359ab643d3ce',1,'Sk_native(): RNAcode.c'],['../score_8c.html#a189ec0118947b93b0df1359ab643d3ce',1,'Sk_native(): postscript.c']]], + ['sk_5fnative_5frev',['Sk_native_rev',['../postscript_8c.html#a720f3e09e87f08ee95fd84af1c9c575e',1,'Sk_native_rev(): postscript.c'],['../RNAcode_8c.html#a720f3e09e87f08ee95fd84af1c9c575e',1,'Sk_native_rev(): RNAcode.c'],['../score_8c.html#a720f3e09e87f08ee95fd84af1c9c575e',1,'Sk_native_rev(): postscript.c']]], + ['ssstep',['ssStep',['../postscript_8c.html#a0fa03894e3a7c9aa3690c217af65c7c3',1,'postscript.c']]], + ['start',['start',['../structaln.html#a1cde67bfa55bc9e8f2d98f9e53a4ba12',1,'aln::start()'],['../struct__segmentStats.html#acbd4b0e7ceaa05b6506aab77d2bf1090',1,'_segmentStats::start()']]], + ['startgenomic',['startGenomic',['../struct__segmentStats.html#a95a69dcd9686db97033daded2f42878b',1,'_segmentStats']]], + ['startsite',['startSite',['../struct__segmentStats.html#a403f946ddab65393861d93fbb81f0d5a',1,'_segmentStats']]], + ['starty',['startY',['../postscript_8c.html#aa3dfc2d68f6a44a7941b7e6f2940ecac',1,'postscript.c']]], + ['states',['states',['../struct__backtrackData.html#a5dc8d2471b3ad228bfba4b4a4638ac85',1,'_backtrackData']]], + ['stop_5fearly_5fflag',['stop_early_flag',['../structgengetopt__args__info.html#aa4b8393ab6c37bca14cb1b291b5871df',1,'gengetopt_args_info']]], + ['stop_5fearly_5fgiven',['stop_early_given',['../structgengetopt__args__info.html#a69729e2dba0de954d98a56a1b3d8d1c1',1,'gengetopt_args_info']]], + ['stop_5fearly_5fhelp',['stop_early_help',['../structgengetopt__args__info.html#aefd3bdbabef305d8e53741dc229e7cb0',1,'gengetopt_args_info']]], + ['stopearly',['stopEarly',['../struct__parameters.html#ad170b87fd49f42a1ca464c93e36fa0e3',1,'_parameters']]], + ['stoppenalty_5f0',['stopPenalty_0',['../struct__parameters.html#a35c6c83856e4256be0fb543410014f1e',1,'_parameters']]], + ['stoppenalty_5fk',['stopPenalty_k',['../struct__parameters.html#ae26af9c558d90b735b7ed5c2bb8bbb1b',1,'_parameters']]], + ['strand',['strand',['../structaln.html#aa3a2e698a569a230e9e14e14d3afe653',1,'aln::strand()'],['../struct__segmentStats.html#a84cfdd51d1e7fe9555f887c3658e9ced',1,'_segmentStats::strand()']]] +]; diff --git a/src/html/search/variables_11.html b/src/html/search/variables_11.html new file mode 100644 index 0000000..d5be914 --- /dev/null +++ b/src/html/search/variables_11.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_11.js b/src/html/search/variables_11.js new file mode 100644 index 0000000..56efa9e --- /dev/null +++ b/src/html/search/variables_11.js @@ -0,0 +1,10 @@ +var searchData= +[ + ['tabular_5fflag',['tabular_flag',['../structgengetopt__args__info.html#aa01935a1796974d3347aff6062718afc',1,'gengetopt_args_info']]], + ['tabular_5fgiven',['tabular_given',['../structgengetopt__args__info.html#a3b5a200c98e9f33b1dfa0adf5fbaf69d',1,'gengetopt_args_info']]], + ['tabular_5fhelp',['tabular_help',['../structgengetopt__args__info.html#a923b9288287e40df1b3f21bfe288f123',1,'gengetopt_args_info']]], + ['tmpcolumns',['tmpColumns',['../postscript_8c.html#a7e166443fa8165daca1829477a3678c1',1,'postscript.c']]], + ['transcode',['transcode',['../code_8c.html#a119a7eb0ecd417f83e41f4325ce522c8',1,'transcode(): code.c'],['../score_8c.html#a119a7eb0ecd417f83e41f4325ce522c8',1,'transcode(): code.c'],['../score_8h.html#a119a7eb0ecd417f83e41f4325ce522c8',1,'transcode(): code.c']]], + ['transitions',['transitions',['../struct__backtrackData.html#ac559f1f5976ad99432828f9f9ea7f218',1,'_backtrackData']]], + ['tstv',['tstv',['../treeSimulate_8c.html#a489eb68465b539564550251550697a47',1,'treeSimulate.c']]] +]; diff --git a/src/html/search/variables_12.html b/src/html/search/variables_12.html new file mode 100644 index 0000000..b62e1ee --- /dev/null +++ b/src/html/search/variables_12.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_12.js b/src/html/search/variables_12.js new file mode 100644 index 0000000..8fa7127 --- /dev/null +++ b/src/html/search/variables_12.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['userfreqs',['userFreqs',['../treeSimulate_8c.html#a2d2500b39f829187e7542d576b71a547',1,'treeSimulate.c']]] +]; diff --git a/src/html/search/variables_13.html b/src/html/search/variables_13.html new file mode 100644 index 0000000..15437be --- /dev/null +++ b/src/html/search/variables_13.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_13.js b/src/html/search/variables_13.js new file mode 100644 index 0000000..1b671a5 --- /dev/null +++ b/src/html/search/variables_13.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['val',['val',['../structoption.html#a13bd155ec3b405d29c41ab8d0793be11',1,'option']]], + ['version_5fgiven',['version_given',['../structgengetopt__args__info.html#ad4953a2130b2f8b94a3a687014f278e1',1,'gengetopt_args_info']]], + ['version_5fhelp',['version_help',['../structgengetopt__args__info.html#adef454ea6f3ff4114ae5009e58360cfc',1,'gengetopt_args_info']]] +]; diff --git a/src/html/search/variables_14.html b/src/html/search/variables_14.html new file mode 100644 index 0000000..3745fec --- /dev/null +++ b/src/html/search/variables_14.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_14.js b/src/html/search/variables_14.js new file mode 100644 index 0000000..600f20c --- /dev/null +++ b/src/html/search/variables_14.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['weight',['weight',['../struct__bgModel.html#a00821dd196f2cf6dbccbfa8400a15752',1,'_bgModel']]] +]; diff --git a/src/html/search/variables_15.html b/src/html/search/variables_15.html new file mode 100644 index 0000000..7432fd7 --- /dev/null +++ b/src/html/search/variables_15.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_15.js b/src/html/search/variables_15.js new file mode 100644 index 0000000..d2730d6 --- /dev/null +++ b/src/html/search/variables_15.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['xsubi',['xsubi',['../utils_8c.html#a082c5a4e1e1e662b3452b3eb021291fb',1,'xsubi(): utils.c'],['../utils_8h.html#af9a866c8417afda7368bbac939ab3c47',1,'xsubi(): utils.c']]] +]; diff --git a/src/html/search/variables_16.html b/src/html/search/variables_16.html new file mode 100644 index 0000000..737584f --- /dev/null +++ b/src/html/search/variables_16.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_16.js b/src/html/search/variables_16.js new file mode 100644 index 0000000..d4604c1 --- /dev/null +++ b/src/html/search/variables_16.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['z',['z',['../struct__backtrackData.html#a72e1450e2610bee1d867d8428f33a2cc',1,'_backtrackData']]] +]; diff --git a/src/html/search/variables_2.html b/src/html/search/variables_2.html new file mode 100644 index 0000000..5c9de1a --- /dev/null +++ b/src/html/search/variables_2.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_2.js b/src/html/search/variables_2.js new file mode 100644 index 0000000..f04a589 --- /dev/null +++ b/src/html/search/variables_2.js @@ -0,0 +1,14 @@ +var searchData= +[ + ['check_5fambiguity',['check_ambiguity',['../structcmdline__parser__params.html#a6e4442704fc40b0b655f7cc602f13ec4',1,'cmdline_parser_params']]], + ['check_5frequired',['check_required',['../structcmdline__parser__params.html#a44ff439d7e9e36799e59173af74829c6',1,'cmdline_parser_params']]], + ['columnwidth',['columnWidth',['../postscript_8c.html#acb1a982424fe4ce17865ade904f6afbb',1,'postscript.c']]], + ['consstep',['consStep',['../postscript_8c.html#a6290c97dafee311a97e747d02251da9d',1,'postscript.c']]], + ['currpos',['currPos',['../postscript_8c.html#aee13643f97e046b7492876910b23b59d',1,'postscript.c']]], + ['curry',['currY',['../postscript_8c.html#a6cd3947c7e694dc9a6516a4efce1c73d',1,'postscript.c']]], + ['cutoff',['cutoff',['../struct__parameters.html#a6e3ed4fee9836ba83e10f42a0b9d89b2',1,'_parameters']]], + ['cutoff_5farg',['cutoff_arg',['../structgengetopt__args__info.html#a79efa24e1a3d614f474d323f147edf10',1,'gengetopt_args_info']]], + ['cutoff_5fgiven',['cutoff_given',['../structgengetopt__args__info.html#ace7446eaaaffb4c8be5ee2d157933ac1',1,'gengetopt_args_info']]], + ['cutoff_5fhelp',['cutoff_help',['../structgengetopt__args__info.html#a46f7d71837544abf13c5972fc5e528b3',1,'gengetopt_args_info']]], + ['cutoff_5forig',['cutoff_orig',['../structgengetopt__args__info.html#ac1cc7e0fbe8552f19e4760b827349622',1,'gengetopt_args_info']]] +]; diff --git a/src/html/search/variables_3.html b/src/html/search/variables_3.html new file mode 100644 index 0000000..f95e34c --- /dev/null +++ b/src/html/search/variables_3.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_3.js b/src/html/search/variables_3.js new file mode 100644 index 0000000..69c5e05 --- /dev/null +++ b/src/html/search/variables_3.js @@ -0,0 +1,11 @@ +var searchData= +[ + ['debug_5ffile_5farg',['debug_file_arg',['../structgengetopt__args__info.html#a648135bce096c7f592d4a6cc6d2b4d20',1,'gengetopt_args_info']]], + ['debug_5ffile_5fgiven',['debug_file_given',['../structgengetopt__args__info.html#a87bd42cd11567d4e27859cc0569752d6',1,'gengetopt_args_info']]], + ['debug_5ffile_5fhelp',['debug_file_help',['../structgengetopt__args__info.html#af5d881c802b02a6f85b5e4b957de85e9',1,'gengetopt_args_info']]], + ['debug_5ffile_5forig',['debug_file_orig',['../structgengetopt__args__info.html#a2b22e7ebbc50b2b054e9be56785fb2de',1,'gengetopt_args_info']]], + ['debugfile',['debugFile',['../struct__parameters.html#ab616c6d418c255985ac50a9311d8c26a',1,'_parameters']]], + ['debugfilename',['debugFileName',['../struct__parameters.html#a82681df81d7bc113bc6fad0b5328a95d',1,'_parameters']]], + ['delta',['Delta',['../struct__parameters.html#a9a5b85aa0c04d7e22e824e315b14e4cd',1,'_parameters']]], + ['dist',['dist',['../struct__bgModel.html#a3757c1ef6b0176dfdeb6046365bf8524',1,'_bgModel']]] +]; diff --git a/src/html/search/variables_4.html b/src/html/search/variables_4.html new file mode 100644 index 0000000..d7db285 --- /dev/null +++ b/src/html/search/variables_4.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_4.js b/src/html/search/variables_4.js new file mode 100644 index 0000000..7e9d5db --- /dev/null +++ b/src/html/search/variables_4.js @@ -0,0 +1,18 @@ +var searchData= +[ + ['end',['end',['../struct__segmentStats.html#a4d3d7af903f88c69e687d259590b00a3',1,'_segmentStats']]], + ['endgenomic',['endGenomic',['../struct__segmentStats.html#acf8d8441557c049db6d84d96ed7f7ca3',1,'_segmentStats']]], + ['endsite',['endSite',['../struct__segmentStats.html#af419d597e7393b0e78078eaa842ded6c',1,'_segmentStats']]], + ['eps_5fcutoff_5farg',['eps_cutoff_arg',['../structgengetopt__args__info.html#a7d5c15c092764baac13552613fda575f',1,'gengetopt_args_info']]], + ['eps_5fcutoff_5fgiven',['eps_cutoff_given',['../structgengetopt__args__info.html#a60b5aec84888abe557256b1909b01a01',1,'gengetopt_args_info']]], + ['eps_5fcutoff_5fhelp',['eps_cutoff_help',['../structgengetopt__args__info.html#a32790cf21a0f8e8623371d12deb4b337',1,'gengetopt_args_info']]], + ['eps_5fcutoff_5forig',['eps_cutoff_orig',['../structgengetopt__args__info.html#ad2f45ed857ac6e6d8b1a371d85b65e25',1,'gengetopt_args_info']]], + ['eps_5fdir_5farg',['eps_dir_arg',['../structgengetopt__args__info.html#a29434f1b1030755c24dde59d8c157de5',1,'gengetopt_args_info']]], + ['eps_5fdir_5fgiven',['eps_dir_given',['../structgengetopt__args__info.html#a33c0504245a49e483924248119b400a6',1,'gengetopt_args_info']]], + ['eps_5fdir_5fhelp',['eps_dir_help',['../structgengetopt__args__info.html#a1c676a66f0cf100d49679440032ae4ab',1,'gengetopt_args_info']]], + ['eps_5fdir_5forig',['eps_dir_orig',['../structgengetopt__args__info.html#a7474b0d19ed3f9c13ebc88e6cf652c65',1,'gengetopt_args_info']]], + ['eps_5fflag',['eps_flag',['../structgengetopt__args__info.html#a4c97eb3971c8f9222073e63484872bf0',1,'gengetopt_args_info']]], + ['eps_5fgiven',['eps_given',['../structgengetopt__args__info.html#a9d52e7e979f21f9278bcb39005164a44',1,'gengetopt_args_info']]], + ['eps_5fhelp',['eps_help',['../structgengetopt__args__info.html#aa87d33b8ebe4fa33c6c4b7454c3e7e55',1,'gengetopt_args_info']]], + ['equalfreqs',['equalFreqs',['../treeSimulate_8c.html#a85ef69963901475137a5babcaf4233b3',1,'treeSimulate.c']]] +]; diff --git a/src/html/search/variables_5.html b/src/html/search/variables_5.html new file mode 100644 index 0000000..7bbceeb --- /dev/null +++ b/src/html/search/variables_5.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_5.js b/src/html/search/variables_5.js new file mode 100644 index 0000000..74a4c04 --- /dev/null +++ b/src/html/search/variables_5.js @@ -0,0 +1,11 @@ +var searchData= +[ + ['first_5fnonopt',['first_nonopt',['../getopt_8c.html#a7b0f4f3bfbee147113f282427ce933ed',1,'getopt.c']]], + ['flag',['flag',['../structoption.html#ab366eea5fe7be25c1928328ba715e353',1,'option']]], + ['fontheight',['fontHeight',['../postscript_8c.html#a8fc5219f9ead102b3596111331374b2f',1,'postscript.c']]], + ['fontwidth',['fontWidth',['../postscript_8c.html#a05a25f17ddf6ed395c481d783d1af2b4',1,'postscript.c']]], + ['frame',['frame',['../struct__segmentStats.html#aaa79b059634ee49ceb65150735dae1dd',1,'_segmentStats']]], + ['freqs',['freqs',['../struct__bgModel.html#a906bda936ba864ba209eecff5f1ab721',1,'_bgModel']]], + ['fulllength',['fullLength',['../structaln.html#a483afd3cef94d6713429e91b3ea2f9a9',1,'aln']]], + ['fullseq',['fullSeq',['../structaln.html#ad86e38ddd090ff01a1665db42fe80775',1,'aln']]] +]; diff --git a/src/html/search/variables_6.html b/src/html/search/variables_6.html new file mode 100644 index 0000000..4eb162d --- /dev/null +++ b/src/html/search/variables_6.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_6.js b/src/html/search/variables_6.js new file mode 100644 index 0000000..104f197 --- /dev/null +++ b/src/html/search/variables_6.js @@ -0,0 +1,10 @@ +var searchData= +[ + ['gengetopt_5fargs_5finfo_5fdescription',['gengetopt_args_info_description',['../cmdline_8c.html#accad6107ca685f6eba555f6ce63d355d',1,'cmdline.c']]], + ['gengetopt_5fargs_5finfo_5fhelp',['gengetopt_args_info_help',['../cmdline_8c.html#a6af7a6b7fb37c0abaa916ee1cfa0a41f',1,'gengetopt_args_info_help(): cmdline.c'],['../cmdline_8h.html#a6af7a6b7fb37c0abaa916ee1cfa0a41f',1,'gengetopt_args_info_help(): cmdline.c']]], + ['gengetopt_5fargs_5finfo_5fpurpose',['gengetopt_args_info_purpose',['../cmdline_8c.html#a610c3307abce5a8fd304b86b018ae60b',1,'gengetopt_args_info_purpose(): cmdline.c'],['../cmdline_8h.html#a610c3307abce5a8fd304b86b018ae60b',1,'gengetopt_args_info_purpose(): cmdline.c']]], + ['gengetopt_5fargs_5finfo_5fusage',['gengetopt_args_info_usage',['../cmdline_8c.html#a9f397a306f363bfdebb611e86acf36d5',1,'gengetopt_args_info_usage(): cmdline.c'],['../cmdline_8h.html#a9f397a306f363bfdebb611e86acf36d5',1,'gengetopt_args_info_usage(): cmdline.c']]], + ['gtf_5fflag',['gtf_flag',['../structgengetopt__args__info.html#a3cc76992b00eb5f69d49ecabfa65de28',1,'gengetopt_args_info']]], + ['gtf_5fgiven',['gtf_given',['../structgengetopt__args__info.html#a0e6e111149cf2a4bc171c80ee4055f8e',1,'gengetopt_args_info']]], + ['gtf_5fhelp',['gtf_help',['../structgengetopt__args__info.html#a7eb6417bded13cc26a47a1ee53bcb8dc',1,'gengetopt_args_info']]] +]; diff --git a/src/html/search/variables_7.html b/src/html/search/variables_7.html new file mode 100644 index 0000000..0408829 --- /dev/null +++ b/src/html/search/variables_7.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_7.js b/src/html/search/variables_7.js new file mode 100644 index 0000000..fa55117 --- /dev/null +++ b/src/html/search/variables_7.js @@ -0,0 +1,8 @@ +var searchData= +[ + ['has_5farg',['has_arg',['../structoption.html#a90d7ee9a51eea5c002682dbd0af149e4',1,'option']]], + ['help_5fgiven',['help_given',['../structgengetopt__args__info.html#ab9fd677f890731fd7d6f6c62e6dfc99c',1,'gengetopt_args_info']]], + ['help_5fhelp',['help_help',['../structgengetopt__args__info.html#afb4efa68a6f43a4d112e9b96ffe89101',1,'gengetopt_args_info']]], + ['hide',['hide',['../struct__segmentStats.html#a7db5f703ed1ff2f2105f756cb79eaecf',1,'_segmentStats']]], + ['hitcounter',['hitCounter',['../misc_8c.html#a8c5872fcd4604b525d509ffd6afc5631',1,'hitCounter(): RNAcode.c'],['../RNAcode_8c.html#a8c5872fcd4604b525d509ffd6afc5631',1,'hitCounter(): RNAcode.c']]] +]; diff --git a/src/html/search/variables_8.html b/src/html/search/variables_8.html new file mode 100644 index 0000000..d54d096 --- /dev/null +++ b/src/html/search/variables_8.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_8.js b/src/html/search/variables_8.js new file mode 100644 index 0000000..9dc09b5 --- /dev/null +++ b/src/html/search/variables_8.js @@ -0,0 +1,11 @@ +var searchData= +[ + ['imageheight',['imageHeight',['../postscript_8c.html#a97b51530ccb867cc13f911e57be3a559',1,'postscript.c']]], + ['imagewidth',['imageWidth',['../postscript_8c.html#a056677386b85246c5b6f9de91327868c',1,'postscript.c']]], + ['initialize',['initialize',['../structcmdline__parser__params.html#a97ed8a6eabd39291ae7d73f273e12c11',1,'cmdline_parser_params']]], + ['inputfile',['inputFile',['../struct__parameters.html#a37a15ced629242ecdf8a8ccf9f49d81b',1,'_parameters']]], + ['inputfilename',['inputFileName',['../struct__parameters.html#a1b9b47e6f58186d767de1d34d956b516',1,'_parameters']]], + ['inputs',['inputs',['../structgengetopt__args__info.html#a9604690019dd09b318302dae6868726c',1,'gengetopt_args_info']]], + ['inputs_5fnum',['inputs_num',['../structgengetopt__args__info.html#a3d69c180d5ac0b1124fd9a6fe680706c',1,'gengetopt_args_info']]], + ['isnucmodel',['isNucModel',['../treeSimulate_8c.html#a72e05eb4637bf2f93aa05f211b1a57b2',1,'treeSimulate.c']]] +]; diff --git a/src/html/search/variables_9.html b/src/html/search/variables_9.html new file mode 100644 index 0000000..234dc60 --- /dev/null +++ b/src/html/search/variables_9.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_9.js b/src/html/search/variables_9.js new file mode 100644 index 0000000..f8a6e15 --- /dev/null +++ b/src/html/search/variables_9.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['kappa',['kappa',['../struct__bgModel.html#a251b8c86d6c01c5f1813c37df31c3096',1,'_bgModel']]] +]; diff --git a/src/html/search/variables_a.html b/src/html/search/variables_a.html new file mode 100644 index 0000000..0892488 --- /dev/null +++ b/src/html/search/variables_a.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_a.js b/src/html/search/variables_a.js new file mode 100644 index 0000000..dbd700c --- /dev/null +++ b/src/html/search/variables_a.js @@ -0,0 +1,11 @@ +var searchData= +[ + ['last_5fnonopt',['last_nonopt',['../getopt_8c.html#a580f2c2acf35dad51ca18b427212bf15',1,'getopt.c']]], + ['length',['length',['../structaln.html#ad03a776f899ce00d63827146906ab6b4',1,'aln::length()'],['../postscript_8c.html#a9f59b34b1f25fe00023291b678246bcc',1,'length(): postscript.c']]], + ['limit',['limit',['../struct__parameters.html#ab9f7cf2359b590f2476fff80a85aff43',1,'_parameters']]], + ['limit_5farg',['limit_arg',['../structgengetopt__args__info.html#afe75799aec30a1011e3f65a93538eb88',1,'gengetopt_args_info']]], + ['limit_5fgiven',['limit_given',['../structgengetopt__args__info.html#a1058bb49a05830b377b2335d9ae1c7c9',1,'gengetopt_args_info']]], + ['limit_5fhelp',['limit_help',['../structgengetopt__args__info.html#ac54bb7e91539b98c4d0756254880b4ee',1,'gengetopt_args_info']]], + ['limit_5forig',['limit_orig',['../structgengetopt__args__info.html#a77bc7cac390e1901106ad9c70e04b9aa',1,'gengetopt_args_info']]], + ['linestep',['lineStep',['../postscript_8c.html#a47c6c3302e0a9d686ba540869d4f3688',1,'postscript.c']]] +]; diff --git a/src/html/search/variables_b.html b/src/html/search/variables_b.html new file mode 100644 index 0000000..ea46965 --- /dev/null +++ b/src/html/search/variables_b.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_b.js b/src/html/search/variables_b.js new file mode 100644 index 0000000..a412209 --- /dev/null +++ b/src/html/search/variables_b.js @@ -0,0 +1,10 @@ +var searchData= +[ + ['matrix',['matrix',['../struct__bgModel.html#a6843a94f9717bd58819c3fbffe9fbe56',1,'_bgModel']]], + ['maxconsbar',['maxConsBar',['../postscript_8c.html#a0c4c0a1f79429ea034c156318b576175',1,'postscript.c']]], + ['maxname',['maxName',['../postscript_8c.html#a04c4ce9dea57def69ca277c748f1ec4a',1,'postscript.c']]], + ['maxnum',['maxNum',['../postscript_8c.html#af4b91d5ea883f66de1f385aee64a0d5f',1,'postscript.c']]], + ['model',['model',['../treeSimulate_8c.html#a027a1f1731d22465c926ce57be2364c3',1,'treeSimulate.c']]], + ['models',['models',['../RNAcode_8c.html#a2351b02aa48f9f78d350b4b19408d38f',1,'models(): RNAcode.c'],['../score_8c.html#a2351b02aa48f9f78d350b4b19408d38f',1,'models(): RNAcode.c']]], + ['modelsrev',['modelsRev',['../RNAcode_8c.html#aa758f546869f82fa894aeeab59fc8a4f',1,'modelsRev(): RNAcode.c'],['../score_8c.html#a63827dfbc95488762e66ea061bc89afd',1,'modelsRev(): RNAcode.c']]] +]; diff --git a/src/html/search/variables_c.html b/src/html/search/variables_c.html new file mode 100644 index 0000000..94bf1a6 --- /dev/null +++ b/src/html/search/variables_c.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_c.js b/src/html/search/variables_c.js new file mode 100644 index 0000000..4e62255 --- /dev/null +++ b/src/html/search/variables_c.js @@ -0,0 +1,17 @@ +var searchData= +[ + ['name',['name',['../structoption.html#a92c850a23c7828c1dba453bf8d15e1f0',1,'option::name()'],['../structaln.html#af655f033b20fc2f4361576240cac2c0f',1,'aln::name()'],['../struct__segmentStats.html#aea84cdd90979dc3c173424166ef8d532',1,'_segmentStats::name()']]], + ['namestep',['nameStep',['../postscript_8c.html#a7b9ed0953c4c3a72b4763f3913467d83',1,'postscript.c']]], + ['namesx',['namesX',['../postscript_8c.html#ab9e364a4cf29b5aad82e7ec316ac09e9',1,'postscript.c']]], + ['nextchar',['nextchar',['../getopt_8c.html#a47a40a4c365dae45f94751ad32aab530',1,'getopt.c']]], + ['ntmap',['ntMap',['../score_8h.html#a5eb739b80c0e44d631e8cd4b317ea39e',1,'score.h']]], + ['nucfreq',['nucFreq',['../treeSimulate_8c.html#a720f633590f8f9d192891d52735cfcce',1,'treeSimulate.c']]], + ['num_5fsamples_5farg',['num_samples_arg',['../structgengetopt__args__info.html#ac62c13305dd12c4d426aeb82b6e4561b',1,'gengetopt_args_info']]], + ['num_5fsamples_5fgiven',['num_samples_given',['../structgengetopt__args__info.html#a26d6c50dc3b78c9194509a8399d62888',1,'gengetopt_args_info']]], + ['num_5fsamples_5fhelp',['num_samples_help',['../structgengetopt__args__info.html#a1c4039a0fea549c7db4b2c62482179f8',1,'gengetopt_args_info']]], + ['num_5fsamples_5forig',['num_samples_orig',['../structgengetopt__args__info.html#a043409e12989cdbf8cd34fa47f8c6a4c',1,'gengetopt_args_info']]], + ['numberstep',['numberStep',['../postscript_8c.html#ab2e008e977e58c17747a69818f653584',1,'postscript.c']]], + ['numsites',['numSites',['../treeSimulate_8c.html#a13ffae79c3c34f8e30570d5baf7641b0',1,'treeSimulate.c']]], + ['numstates',['numStates',['../treeSimulate_8c.html#a39cc268c324972ce5653c35bdc8aa80f',1,'treeSimulate.c']]], + ['numtaxa',['numTaxa',['../treeSimulate_8c.html#a3893608bdd239b0b3b47338282608791',1,'treeSimulate.c']]] +]; diff --git a/src/html/search/variables_d.html b/src/html/search/variables_d.html new file mode 100644 index 0000000..b9381e9 --- /dev/null +++ b/src/html/search/variables_d.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_d.js b/src/html/search/variables_d.js new file mode 100644 index 0000000..c8977b3 --- /dev/null +++ b/src/html/search/variables_d.js @@ -0,0 +1,17 @@ +var searchData= +[ + ['omega',['omega',['../struct__parameters.html#a8f69e384c5cc468de9c3c527bd9a3722',1,'_parameters::omega()'],['../struct__parameters.html#ab9173ba4e45a417ed8e7317699b5c77c',1,'_parameters::Omega()']]], + ['optarg',['optarg',['../getopt_8c.html#adb50a0eab9fed92fc3bfc7dfa4f2c410',1,'optarg(): getopt.c'],['../getopt_8h.html#adb50a0eab9fed92fc3bfc7dfa4f2c410',1,'optarg(): getopt.c']]], + ['opterr',['opterr',['../getopt_8c.html#ae30f05ee1e2e5652f174a35c7875d25e',1,'opterr(): getopt.c'],['../getopt_8h.html#ae30f05ee1e2e5652f174a35c7875d25e',1,'opterr(): getopt.c']]], + ['optind',['optind',['../getopt_8c.html#ad5e1c16213bbee2d5e8cc363309f418c',1,'optind(): getopt.c'],['../getopt_8h.html#ad5e1c16213bbee2d5e8cc363309f418c',1,'optind(): getopt.c']]], + ['optopt',['optopt',['../getopt_8c.html#a475b8db98445da73e5f62a1ef6324b95',1,'optopt(): getopt.c'],['../getopt_8h.html#a475b8db98445da73e5f62a1ef6324b95',1,'optopt(): getopt.c']]], + ['ordering',['ordering',['../getopt_8c.html#a67a84cf4dacaa8337be68345f8b9a8cc',1,'getopt.c']]], + ['outfile',['outfile',['../postscript_8c.html#ae581849c67336453bd5b81e6518019a9',1,'postscript.c']]], + ['outfile_5farg',['outfile_arg',['../structgengetopt__args__info.html#ab9e3d63af39beb195c0ce4b30628475b',1,'gengetopt_args_info']]], + ['outfile_5fgiven',['outfile_given',['../structgengetopt__args__info.html#af6f058929187956cb68a0192b866f942',1,'gengetopt_args_info']]], + ['outfile_5fhelp',['outfile_help',['../structgengetopt__args__info.html#ae7d54ef8556b73161c14a77b20fe321f',1,'gengetopt_args_info']]], + ['outfile_5forig',['outfile_orig',['../structgengetopt__args__info.html#a39782404c00e6f9107f8fdcae948222f',1,'gengetopt_args_info']]], + ['outputfile',['outputFile',['../struct__parameters.html#a683e0de09c9d45e219db06753f89bc7e',1,'_parameters']]], + ['outputformat',['outputFormat',['../struct__parameters.html#a37dadb0f3fa7deca9cdc43797cc0ff5b',1,'_parameters']]], + ['override',['override',['../structcmdline__parser__params.html#ad3ff9d69146e69a47506782197b5675c',1,'cmdline_parser_params']]] +]; diff --git a/src/html/search/variables_e.html b/src/html/search/variables_e.html new file mode 100644 index 0000000..375ad70 --- /dev/null +++ b/src/html/search/variables_e.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_e.js b/src/html/search/variables_e.js new file mode 100644 index 0000000..42c98b3 --- /dev/null +++ b/src/html/search/variables_e.js @@ -0,0 +1,19 @@ +var searchData= +[ + ['p',['P',['../treeSimulate_8c.html#aed2d481a3756e5431b6d0e26b1d4b246',1,'treeSimulate.c']]], + ['package_5fname',['package_name',['../cmdline_8c.html#a08f16a026de44b77c5e7be490fb9e32b',1,'cmdline.c']]], + ['pars',['pars',['../misc_8c.html#a8dea3b88a171ed8de9f8f98079e7561a',1,'pars(): RNAcode.c'],['../RNAcode_8c.html#a8dea3b88a171ed8de9f8f98079e7561a',1,'pars(): RNAcode.c'],['../score_8c.html#a8dea3b88a171ed8de9f8f98079e7561a',1,'pars(): RNAcode.c']]], + ['pars_5farg',['pars_arg',['../structgengetopt__args__info.html#a965c61281e9339738647ff5e44604d8b',1,'gengetopt_args_info']]], + ['pars_5fgiven',['pars_given',['../structgengetopt__args__info.html#abaf16e517f88e5ad41e06e0584045074',1,'gengetopt_args_info']]], + ['pars_5fhelp',['pars_help',['../structgengetopt__args__info.html#aacd28fcc4238ef2516cca7526df79533',1,'gengetopt_args_info']]], + ['pars_5forig',['pars_orig',['../structgengetopt__args__info.html#a2c6837447e74b77af713002cdb58949b',1,'gengetopt_args_info']]], + ['posixly_5fcorrect',['posixly_correct',['../getopt_8c.html#ad0ccb64bbd4defe7a57dbad2045ddd14',1,'getopt.c']]], + ['postscript',['postscript',['../struct__parameters.html#a7080180324a5b3081e85eb308d2d530c',1,'_parameters']]], + ['postscript_5fcutoff',['postscript_cutoff',['../struct__parameters.html#a796cc87fce657443f51845fd1098f0df',1,'_parameters']]], + ['postscriptdir',['postscriptDir',['../struct__parameters.html#a6c33be73b16d623ca8e5af964d248424',1,'_parameters']]], + ['print_5ferrors',['print_errors',['../structcmdline__parser__params.html#a3236f066777488e8502abe05ccd24455',1,'cmdline_parser_params']]], + ['printifabove',['printIfAbove',['../struct__parameters.html#aa9034282619631f32acd19230990ea6e',1,'_parameters']]], + ['printifbelow',['printIfBelow',['../struct__parameters.html#ad73fc37c8e5f6964149f12899200472b',1,'_parameters']]], + ['probs',['probs',['../struct__bgModel.html#ac106ea61c120d4a60f38c98a97254f49',1,'_bgModel']]], + ['pvalue',['pvalue',['../struct__segmentStats.html#a36c8958e60d5f733eb6b3bc0e178ad61',1,'_segmentStats']]] +]; diff --git a/src/html/search/variables_f.html b/src/html/search/variables_f.html new file mode 100644 index 0000000..d371418 --- /dev/null +++ b/src/html/search/variables_f.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/src/html/search/variables_f.js b/src/html/search/variables_f.js new file mode 100644 index 0000000..0fe960d --- /dev/null +++ b/src/html/search/variables_f.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['rcsid',['rcsid',['../utils_8c.html#af1b3bff1622925d03c9cd14c5f1a51bf',1,'utils.c']]], + ['rulerstep',['rulerStep',['../postscript_8c.html#adbb97a02a7e2f5bc69940fc230062839',1,'postscript.c']]] +]; diff --git a/src/html/splitbar.png b/src/html/splitbar.png new file mode 100644 index 0000000..fe895f2 Binary files /dev/null and b/src/html/splitbar.png differ diff --git a/src/html/struct__backtrackData-members.html b/src/html/struct__backtrackData-members.html new file mode 100644 index 0000000..741411c --- /dev/null +++ b/src/html/struct__backtrackData-members.html @@ -0,0 +1,80 @@ + + + + + + + +My Project: Member List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+
+
_backtrackData Member List
+
+
+ +

This is the complete list of members for _backtrackData, including all inherited members.

+ + + + + +
scores_backtrackData
states_backtrackData
transitions_backtrackData
z_backtrackData
+ + + + diff --git a/src/html/struct__backtrackData.html b/src/html/struct__backtrackData.html new file mode 100644 index 0000000..a529b89 --- /dev/null +++ b/src/html/struct__backtrackData.html @@ -0,0 +1,150 @@ + + + + + + + +My Project: _backtrackData Struct Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
_backtrackData Struct Reference
+
+
+ +

#include <score.h>

+ + + + + + + + + + +

+Public Attributes

float * scores
 
int * z
 
int * states
 
int * transitions
 
+

Member Data Documentation

+ +

◆ scores

+ +
+
+ + + + +
float* _backtrackData::scores
+
+ +
+
+ +

◆ states

+ +
+
+ + + + +
int* _backtrackData::states
+
+ +
+
+ +

◆ transitions

+ +
+
+ + + + +
int* _backtrackData::transitions
+
+ +
+
+ +

◆ z

+ +
+
+ + + + +
int* _backtrackData::z
+
+ +
+
+
The documentation for this struct was generated from the following file: +
+ + + + diff --git a/src/html/struct__bgModel-members.html b/src/html/struct__bgModel-members.html new file mode 100644 index 0000000..ffe09f3 --- /dev/null +++ b/src/html/struct__bgModel-members.html @@ -0,0 +1,83 @@ + + + + + + + +My Project: Member List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+
+
_bgModel Member List
+
+
+ +

This is the complete list of members for _bgModel, including all inherited members.

+ + + + + + + + +
dist_bgModel
freqs_bgModel
kappa_bgModel
matrix_bgModel
probs_bgModel
scores_bgModel
weight_bgModel
+ + + + diff --git a/src/html/struct__bgModel.html b/src/html/struct__bgModel.html new file mode 100644 index 0000000..a69487b --- /dev/null +++ b/src/html/struct__bgModel.html @@ -0,0 +1,198 @@ + + + + + + + +My Project: _bgModel Struct Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
_bgModel Struct Reference
+
+
+ +

#include <score.h>

+ + + + + + + + + + + + + + + + +

+Public Attributes

float scores [4]
 
float probs [4]
 
float kappa
 
float dist
 
float freqs [4]
 
int ** matrix
 
float weight
 
+

Member Data Documentation

+ +

◆ dist

+ +
+
+ + + + +
float _bgModel::dist
+
+ +
+
+ +

◆ freqs

+ +
+
+ + + + +
float _bgModel::freqs[4]
+
+ +
+
+ +

◆ kappa

+ +
+
+ + + + +
float _bgModel::kappa
+
+ +
+
+ +

◆ matrix

+ +
+
+ + + + +
int** _bgModel::matrix
+
+ +
+
+ +

◆ probs

+ +
+
+ + + + +
float _bgModel::probs[4]
+
+ +
+
+ +

◆ scores

+ +
+
+ + + + +
float _bgModel::scores[4]
+
+ +
+
+ +

◆ weight

+ +
+
+ + + + +
float _bgModel::weight
+
+ +
+
+
The documentation for this struct was generated from the following file: +
+ + + + diff --git a/src/html/struct__parameters-members.html b/src/html/struct__parameters-members.html new file mode 100644 index 0000000..54542e0 --- /dev/null +++ b/src/html/struct__parameters-members.html @@ -0,0 +1,99 @@ + + + + + + + +My Project: Member List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+
+
_parameters Member List
+
+ + + + + diff --git a/src/html/struct__parameters.html b/src/html/struct__parameters.html new file mode 100644 index 0000000..451d5bc --- /dev/null +++ b/src/html/struct__parameters.html @@ -0,0 +1,454 @@ + + + + + + + +My Project: _parameters Struct Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
_parameters Struct Reference
+
+
+ +

#include <RNAcode.h>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Public Attributes

float omega
 
float Omega
 
float Delta
 
float stopPenalty_0
 
float stopPenalty_k
 
FILE * inputFile
 
FILE * outputFile
 
FILE * debugFile
 
int sampleN
 
char limit [10000]
 
float cutoff
 
int outputFormat
 
int stopEarly
 
int bestOnly
 
int bestRegion
 
int blosum
 
char debugFileName [1024]
 
char inputFileName [1024]
 
float printIfBelow
 
float printIfAbove
 
int postscript
 
float postscript_cutoff
 
char postscriptDir [1024]
 
+

Member Data Documentation

+ +

◆ bestOnly

+ +
+
+ + + + +
int _parameters::bestOnly
+
+ +
+
+ +

◆ bestRegion

+ +
+
+ + + + +
int _parameters::bestRegion
+
+ +
+
+ +

◆ blosum

+ +
+
+ + + + +
int _parameters::blosum
+
+ +
+
+ +

◆ cutoff

+ +
+
+ + + + +
float _parameters::cutoff
+
+ +
+
+ +

◆ debugFile

+ +
+
+ + + + +
FILE* _parameters::debugFile
+
+ +
+
+ +

◆ debugFileName

+ +
+
+ + + + +
char _parameters::debugFileName[1024]
+
+ +
+
+ +

◆ Delta

+ +
+
+ + + + +
float _parameters::Delta
+
+ +
+
+ +

◆ inputFile

+ +
+
+ + + + +
FILE* _parameters::inputFile
+
+ +
+
+ +

◆ inputFileName

+ +
+
+ + + + +
char _parameters::inputFileName[1024]
+
+ +
+
+ +

◆ limit

+ +
+
+ + + + +
char _parameters::limit[10000]
+
+ +
+
+ +

◆ omega

+ +
+
+ + + + +
float _parameters::omega
+
+ +
+
+ +

◆ Omega

+ +
+
+ + + + +
float _parameters::Omega
+
+ +
+
+ +

◆ outputFile

+ +
+
+ + + + +
FILE* _parameters::outputFile
+
+ +
+
+ +

◆ outputFormat

+ +
+
+ + + + +
int _parameters::outputFormat
+
+ +
+
+ +

◆ postscript

+ +
+
+ + + + +
int _parameters::postscript
+
+ +
+
+ +

◆ postscript_cutoff

+ +
+
+ + + + +
float _parameters::postscript_cutoff
+
+ +
+
+ +

◆ postscriptDir

+ +
+
+ + + + +
char _parameters::postscriptDir[1024]
+
+ +
+
+ +

◆ printIfAbove

+ +
+
+ + + + +
float _parameters::printIfAbove
+
+ +
+
+ +

◆ printIfBelow

+ +
+
+ + + + +
float _parameters::printIfBelow
+
+ +
+
+ +

◆ sampleN

+ +
+
+ + + + +
int _parameters::sampleN
+
+ +
+
+ +

◆ stopEarly

+ +
+
+ + + + +
int _parameters::stopEarly
+
+ +
+
+ +

◆ stopPenalty_0

+ +
+
+ + + + +
float _parameters::stopPenalty_0
+
+ +
+
+ +

◆ stopPenalty_k

+ +
+
+ + + + +
float _parameters::stopPenalty_k
+
+ +
+
+
The documentation for this struct was generated from the following file: +
+ + + + diff --git a/src/html/struct__segmentStats-members.html b/src/html/struct__segmentStats-members.html new file mode 100644 index 0000000..904e343 --- /dev/null +++ b/src/html/struct__segmentStats-members.html @@ -0,0 +1,88 @@ + + + + + + + +My Project: Member List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+
+
_segmentStats Member List
+
+ + + + + diff --git a/src/html/struct__segmentStats.html b/src/html/struct__segmentStats.html new file mode 100644 index 0000000..c1f62b4 --- /dev/null +++ b/src/html/struct__segmentStats.html @@ -0,0 +1,278 @@ + + + + + + + +My Project: _segmentStats Struct Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
_segmentStats Struct Reference
+
+
+ +

#include <score.h>

+ + + + + + + + + + + + + + + + + + + + + + + + + + +

+Public Attributes

int start
 
int end
 
int startGenomic
 
int endGenomic
 
int startSite
 
int endSite
 
int strand
 
int frame
 
char * name
 
float score
 
float pvalue
 
int hide
 
+

Member Data Documentation

+ +

◆ end

+ +
+
+ + + + +
int _segmentStats::end
+
+ +
+
+ +

◆ endGenomic

+ +
+
+ + + + +
int _segmentStats::endGenomic
+
+ +
+
+ +

◆ endSite

+ +
+
+ + + + +
int _segmentStats::endSite
+
+ +
+
+ +

◆ frame

+ +
+
+ + + + +
int _segmentStats::frame
+
+ +
+
+ +

◆ hide

+ +
+
+ + + + +
int _segmentStats::hide
+
+ +
+
+ +

◆ name

+ +
+
+ + + + +
char* _segmentStats::name
+
+ +
+
+ +

◆ pvalue

+ +
+
+ + + + +
float _segmentStats::pvalue
+
+ +
+
+ +

◆ score

+ +
+
+ + + + +
float _segmentStats::score
+
+ +
+
+ +

◆ start

+ +
+
+ + + + +
int _segmentStats::start
+
+ +
+
+ +

◆ startGenomic

+ +
+
+ + + + +
int _segmentStats::startGenomic
+
+ +
+
+ +

◆ startSite

+ +
+
+ + + + +
int _segmentStats::startSite
+
+ +
+
+ +

◆ strand

+ +
+
+ + + + +
int _segmentStats::strand
+
+ +
+
+
The documentation for this struct was generated from the following file: +
+ + + + diff --git a/src/html/structaln-members.html b/src/html/structaln-members.html new file mode 100644 index 0000000..f993108 --- /dev/null +++ b/src/html/structaln-members.html @@ -0,0 +1,83 @@ + + + + + + + +My Project: Member List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+
+
aln Member List
+
+
+ +

This is the complete list of members for aln, including all inherited members.

+ + + + + + + + +
fullLengthaln
fullSeqaln
lengthaln
namealn
seqaln
startaln
strandaln
+ + + + diff --git a/src/html/structaln.html b/src/html/structaln.html new file mode 100644 index 0000000..6a635fa --- /dev/null +++ b/src/html/structaln.html @@ -0,0 +1,198 @@ + + + + + + + +My Project: aln Struct Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
aln Struct Reference
+
+
+ +

#include <rnaz_utils.h>

+ + + + + + + + + + + + + + + + +

+Public Attributes

char * name
 
char * seq
 
char * fullSeq
 
int start
 
int length
 
int fullLength
 
char strand
 
+

Member Data Documentation

+ +

◆ fullLength

+ +
+
+ + + + +
int aln::fullLength
+
+ +
+
+ +

◆ fullSeq

+ +
+
+ + + + +
char* aln::fullSeq
+
+ +
+
+ +

◆ length

+ +
+
+ + + + +
int aln::length
+
+ +
+
+ +

◆ name

+ +
+
+ + + + +
char* aln::name
+
+ +
+
+ +

◆ seq

+ +
+
+ + + + +
char* aln::seq
+
+ +
+
+ +

◆ start

+ +
+
+ + + + +
int aln::start
+
+ +
+
+ +

◆ strand

+ +
+
+ + + + +
char aln::strand
+
+ +
+
+
The documentation for this struct was generated from the following file: +
+ + + + diff --git a/src/html/structcmdline__parser__params-members.html b/src/html/structcmdline__parser__params-members.html new file mode 100644 index 0000000..cceedad --- /dev/null +++ b/src/html/structcmdline__parser__params-members.html @@ -0,0 +1,81 @@ + + + + + + + +My Project: Member List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+
+
cmdline_parser_params Member List
+
+ + + + + diff --git a/src/html/structcmdline__parser__params.html b/src/html/structcmdline__parser__params.html new file mode 100644 index 0000000..e15d03b --- /dev/null +++ b/src/html/structcmdline__parser__params.html @@ -0,0 +1,186 @@ + + + + + + + +My Project: cmdline_parser_params Struct Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
cmdline_parser_params Struct Reference
+
+
+ +

The additional parameters to pass to parser functions. + More...

+ +

#include <cmdline.h>

+ + + + + + + + + + + + + + + + + +

+Public Attributes

int override
 whether to override possibly already present options (default 0) More...
 
int initialize
 whether to initialize the option structure gengetopt_args_info (default 1) More...
 
int check_required
 whether to check that all required options were provided (default 1) More...
 
int check_ambiguity
 whether to check for options already specified in the option structure gengetopt_args_info (default 0) More...
 
int print_errors
 whether getopt_long should print an error message for a bad option (default 1) More...
 
+

Detailed Description

+

The additional parameters to pass to parser functions.

+

Member Data Documentation

+ +

◆ check_ambiguity

+ +
+
+ + + + +
int cmdline_parser_params::check_ambiguity
+
+ +

whether to check for options already specified in the option structure gengetopt_args_info (default 0)

+ +
+
+ +

◆ check_required

+ +
+
+ + + + +
int cmdline_parser_params::check_required
+
+ +

whether to check that all required options were provided (default 1)

+ +
+
+ +

◆ initialize

+ +
+
+ + + + +
int cmdline_parser_params::initialize
+
+ +

whether to initialize the option structure gengetopt_args_info (default 1)

+ +
+
+ +

◆ override

+ +
+
+ + + + +
int cmdline_parser_params::override
+
+ +

whether to override possibly already present options (default 0)

+ +
+
+ +

◆ print_errors

+ +
+
+ + + + +
int cmdline_parser_params::print_errors
+
+ +

whether getopt_long should print an error message for a bad option (default 1)

+ +
+
+
The documentation for this struct was generated from the following file: +
+ + + + diff --git a/src/html/structgengetopt__args__info-members.html b/src/html/structgengetopt__args__info-members.html new file mode 100644 index 0000000..59b69d6 --- /dev/null +++ b/src/html/structgengetopt__args__info-members.html @@ -0,0 +1,136 @@ + + + + + + + +My Project: Member List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+
+
gengetopt_args_info Member List
+
+
+ +

This is the complete list of members for gengetopt_args_info, including all inherited members.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
best_only_flaggengetopt_args_info
best_only_givengengetopt_args_info
best_only_helpgengetopt_args_info
best_region_flaggengetopt_args_info
best_region_givengengetopt_args_info
best_region_helpgengetopt_args_info
blosum_arggengetopt_args_info
blosum_givengengetopt_args_info
blosum_helpgengetopt_args_info
blosum_origgengetopt_args_info
cutoff_arggengetopt_args_info
cutoff_givengengetopt_args_info
cutoff_helpgengetopt_args_info
cutoff_origgengetopt_args_info
debug_file_arggengetopt_args_info
debug_file_givengengetopt_args_info
debug_file_helpgengetopt_args_info
debug_file_origgengetopt_args_info
eps_cutoff_arggengetopt_args_info
eps_cutoff_givengengetopt_args_info
eps_cutoff_helpgengetopt_args_info
eps_cutoff_origgengetopt_args_info
eps_dir_arggengetopt_args_info
eps_dir_givengengetopt_args_info
eps_dir_helpgengetopt_args_info
eps_dir_origgengetopt_args_info
eps_flaggengetopt_args_info
eps_givengengetopt_args_info
eps_helpgengetopt_args_info
gtf_flaggengetopt_args_info
gtf_givengengetopt_args_info
gtf_helpgengetopt_args_info
help_givengengetopt_args_info
help_helpgengetopt_args_info
inputsgengetopt_args_info
inputs_numgengetopt_args_info
limit_arggengetopt_args_info
limit_givengengetopt_args_info
limit_helpgengetopt_args_info
limit_origgengetopt_args_info
num_samples_arggengetopt_args_info
num_samples_givengengetopt_args_info
num_samples_helpgengetopt_args_info
num_samples_origgengetopt_args_info
outfile_arggengetopt_args_info
outfile_givengengetopt_args_info
outfile_helpgengetopt_args_info
outfile_origgengetopt_args_info
pars_arggengetopt_args_info
pars_givengengetopt_args_info
pars_helpgengetopt_args_info
pars_origgengetopt_args_info
stop_early_flaggengetopt_args_info
stop_early_givengengetopt_args_info
stop_early_helpgengetopt_args_info
tabular_flaggengetopt_args_info
tabular_givengengetopt_args_info
tabular_helpgengetopt_args_info
version_givengengetopt_args_info
version_helpgengetopt_args_info
+ + + + diff --git a/src/html/structgengetopt__args__info.html b/src/html/structgengetopt__args__info.html new file mode 100644 index 0000000..89d04b9 --- /dev/null +++ b/src/html/structgengetopt__args__info.html @@ -0,0 +1,1231 @@ + + + + + + + +My Project: gengetopt_args_info Struct Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
gengetopt_args_info Struct Reference
+
+
+ +

Where the command line options are stored. + More...

+ +

#include <cmdline.h>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Public Attributes

const char * help_help
 Print help and exit help description. More...
 
const char * version_help
 Print version and exit help description. More...
 
char * outfile_arg
 Output filename. More...
 
char * outfile_orig
 Output filename original value given at command line. More...
 
const char * outfile_help
 Output filename help description. More...
 
int gtf_flag
 GTF output (default=off). More...
 
const char * gtf_help
 GTF output help description. More...
 
int tabular_flag
 Tab delimited output (default=off). More...
 
const char * tabular_help
 Tab delimited output help description. More...
 
int best_only_flag
 Print only best hit per alignment (default=off). More...
 
const char * best_only_help
 Print only best hit per alignment help description. More...
 
int best_region_flag
 Print all best non-overlapping hits per alignment (default=off). More...
 
const char * best_region_help
 Print all best non-overlapping hits per alignment help description. More...
 
char * pars_arg
 String with parameters. More...
 
char * pars_orig
 String with parameters original value given at command line. More...
 
const char * pars_help
 String with parameters help description. More...
 
int stop_early_flag
 Don't calculate p-values if below cutoff (default=off). More...
 
const char * stop_early_help
 Don't calculate p-values if below cutoff help description. More...
 
int num_samples_arg
 Number of samples. More...
 
char * num_samples_orig
 Number of samples original value given at command line. More...
 
const char * num_samples_help
 Number of samples help description. More...
 
float cutoff_arg
 p-value cutoff. More...
 
char * cutoff_orig
 p-value cutoff original value given at command line. More...
 
const char * cutoff_help
 p-value cutoff help description. More...
 
char * debug_file_arg
 Debug file. More...
 
char * debug_file_orig
 Debug file original value given at command line. More...
 
const char * debug_file_help
 Debug file help description. More...
 
int eps_flag
 Postscript output (default=off). More...
 
const char * eps_help
 Postscript output help description. More...
 
float eps_cutoff_arg
 Postscript output p-value cutoff. More...
 
char * eps_cutoff_orig
 Postscript output p-value cutoff original value given at command line. More...
 
const char * eps_cutoff_help
 Postscript output p-value cutoff help description. More...
 
char * eps_dir_arg
 Postscript directory. More...
 
char * eps_dir_orig
 Postscript directory original value given at command line. More...
 
const char * eps_dir_help
 Postscript directory help description. More...
 
char * limit_arg
 limit to species. More...
 
char * limit_orig
 limit to species original value given at command line. More...
 
const char * limit_help
 limit to species help description. More...
 
int blosum_arg
 BLOSUM matrix version. More...
 
char * blosum_orig
 BLOSUM matrix version original value given at command line. More...
 
const char * blosum_help
 BLOSUM matrix version help description. More...
 
unsigned int help_given
 Whether help was given. More...
 
unsigned int version_given
 Whether version was given. More...
 
unsigned int outfile_given
 Whether outfile was given. More...
 
unsigned int gtf_given
 Whether gtf was given. More...
 
unsigned int tabular_given
 Whether tabular was given. More...
 
unsigned int best_only_given
 Whether best-only was given. More...
 
unsigned int best_region_given
 Whether best-region was given. More...
 
unsigned int pars_given
 Whether pars was given. More...
 
unsigned int stop_early_given
 Whether stop-early was given. More...
 
unsigned int num_samples_given
 Whether num-samples was given. More...
 
unsigned int cutoff_given
 Whether cutoff was given. More...
 
unsigned int debug_file_given
 Whether debug-file was given. More...
 
unsigned int eps_given
 Whether eps was given. More...
 
unsigned int eps_cutoff_given
 Whether eps-cutoff was given. More...
 
unsigned int eps_dir_given
 Whether eps-dir was given. More...
 
unsigned int limit_given
 Whether limit was given. More...
 
unsigned int blosum_given
 Whether blosum was given. More...
 
char ** inputs
 unamed options (options without names) More...
 
unsigned inputs_num
 unamed options number More...
 
+

Detailed Description

+

Where the command line options are stored.

+

Member Data Documentation

+ +

◆ best_only_flag

+ +
+
+ + + + +
int gengetopt_args_info::best_only_flag
+
+ +

Print only best hit per alignment (default=off).

+ +
+
+ +

◆ best_only_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::best_only_given
+
+ +

Whether best-only was given.

+ +
+
+ +

◆ best_only_help

+ +
+
+ + + + +
const char* gengetopt_args_info::best_only_help
+
+ +

Print only best hit per alignment help description.

+ +
+
+ +

◆ best_region_flag

+ +
+
+ + + + +
int gengetopt_args_info::best_region_flag
+
+ +

Print all best non-overlapping hits per alignment (default=off).

+ +
+
+ +

◆ best_region_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::best_region_given
+
+ +

Whether best-region was given.

+ +
+
+ +

◆ best_region_help

+ +
+
+ + + + +
const char* gengetopt_args_info::best_region_help
+
+ +

Print all best non-overlapping hits per alignment help description.

+ +
+
+ +

◆ blosum_arg

+ +
+
+ + + + +
int gengetopt_args_info::blosum_arg
+
+ +

BLOSUM matrix version.

+ +
+
+ +

◆ blosum_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::blosum_given
+
+ +

Whether blosum was given.

+ +
+
+ +

◆ blosum_help

+ +
+
+ + + + +
const char* gengetopt_args_info::blosum_help
+
+ +

BLOSUM matrix version help description.

+ +
+
+ +

◆ blosum_orig

+ +
+
+ + + + +
char* gengetopt_args_info::blosum_orig
+
+ +

BLOSUM matrix version original value given at command line.

+ +
+
+ +

◆ cutoff_arg

+ +
+
+ + + + +
float gengetopt_args_info::cutoff_arg
+
+ +

p-value cutoff.

+ +
+
+ +

◆ cutoff_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::cutoff_given
+
+ +

Whether cutoff was given.

+ +
+
+ +

◆ cutoff_help

+ +
+
+ + + + +
const char* gengetopt_args_info::cutoff_help
+
+ +

p-value cutoff help description.

+ +
+
+ +

◆ cutoff_orig

+ +
+
+ + + + +
char* gengetopt_args_info::cutoff_orig
+
+ +

p-value cutoff original value given at command line.

+ +
+
+ +

◆ debug_file_arg

+ +
+
+ + + + +
char* gengetopt_args_info::debug_file_arg
+
+ +

Debug file.

+ +
+
+ +

◆ debug_file_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::debug_file_given
+
+ +

Whether debug-file was given.

+ +
+
+ +

◆ debug_file_help

+ +
+
+ + + + +
const char* gengetopt_args_info::debug_file_help
+
+ +

Debug file help description.

+ +
+
+ +

◆ debug_file_orig

+ +
+
+ + + + +
char* gengetopt_args_info::debug_file_orig
+
+ +

Debug file original value given at command line.

+ +
+
+ +

◆ eps_cutoff_arg

+ +
+
+ + + + +
float gengetopt_args_info::eps_cutoff_arg
+
+ +

Postscript output p-value cutoff.

+ +
+
+ +

◆ eps_cutoff_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::eps_cutoff_given
+
+ +

Whether eps-cutoff was given.

+ +
+
+ +

◆ eps_cutoff_help

+ +
+
+ + + + +
const char* gengetopt_args_info::eps_cutoff_help
+
+ +

Postscript output p-value cutoff help description.

+ +
+
+ +

◆ eps_cutoff_orig

+ +
+
+ + + + +
char* gengetopt_args_info::eps_cutoff_orig
+
+ +

Postscript output p-value cutoff original value given at command line.

+ +
+
+ +

◆ eps_dir_arg

+ +
+
+ + + + +
char* gengetopt_args_info::eps_dir_arg
+
+ +

Postscript directory.

+ +
+
+ +

◆ eps_dir_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::eps_dir_given
+
+ +

Whether eps-dir was given.

+ +
+
+ +

◆ eps_dir_help

+ +
+
+ + + + +
const char* gengetopt_args_info::eps_dir_help
+
+ +

Postscript directory help description.

+ +
+
+ +

◆ eps_dir_orig

+ +
+
+ + + + +
char* gengetopt_args_info::eps_dir_orig
+
+ +

Postscript directory original value given at command line.

+ +
+
+ +

◆ eps_flag

+ +
+
+ + + + +
int gengetopt_args_info::eps_flag
+
+ +

Postscript output (default=off).

+ +
+
+ +

◆ eps_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::eps_given
+
+ +

Whether eps was given.

+ +
+
+ +

◆ eps_help

+ +
+
+ + + + +
const char* gengetopt_args_info::eps_help
+
+ +

Postscript output help description.

+ +
+
+ +

◆ gtf_flag

+ +
+
+ + + + +
int gengetopt_args_info::gtf_flag
+
+ +

GTF output (default=off).

+ +
+
+ +

◆ gtf_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::gtf_given
+
+ +

Whether gtf was given.

+ +
+
+ +

◆ gtf_help

+ +
+
+ + + + +
const char* gengetopt_args_info::gtf_help
+
+ +

GTF output help description.

+ +
+
+ +

◆ help_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::help_given
+
+ +

Whether help was given.

+ +
+
+ +

◆ help_help

+ +
+
+ + + + +
const char* gengetopt_args_info::help_help
+
+ +

Print help and exit help description.

+ +
+
+ +

◆ inputs

+ +
+
+ + + + +
char** gengetopt_args_info::inputs
+
+ +

unamed options (options without names)

+ +
+
+ +

◆ inputs_num

+ +
+
+ + + + +
unsigned gengetopt_args_info::inputs_num
+
+ +

unamed options number

+ +
+
+ +

◆ limit_arg

+ +
+
+ + + + +
char* gengetopt_args_info::limit_arg
+
+ +

limit to species.

+ +
+
+ +

◆ limit_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::limit_given
+
+ +

Whether limit was given.

+ +
+
+ +

◆ limit_help

+ +
+
+ + + + +
const char* gengetopt_args_info::limit_help
+
+ +

limit to species help description.

+ +
+
+ +

◆ limit_orig

+ +
+
+ + + + +
char* gengetopt_args_info::limit_orig
+
+ +

limit to species original value given at command line.

+ +
+
+ +

◆ num_samples_arg

+ +
+
+ + + + +
int gengetopt_args_info::num_samples_arg
+
+ +

Number of samples.

+ +
+
+ +

◆ num_samples_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::num_samples_given
+
+ +

Whether num-samples was given.

+ +
+
+ +

◆ num_samples_help

+ +
+
+ + + + +
const char* gengetopt_args_info::num_samples_help
+
+ +

Number of samples help description.

+ +
+
+ +

◆ num_samples_orig

+ +
+
+ + + + +
char* gengetopt_args_info::num_samples_orig
+
+ +

Number of samples original value given at command line.

+ +
+
+ +

◆ outfile_arg

+ +
+
+ + + + +
char* gengetopt_args_info::outfile_arg
+
+ +

Output filename.

+ +
+
+ +

◆ outfile_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::outfile_given
+
+ +

Whether outfile was given.

+ +
+
+ +

◆ outfile_help

+ +
+
+ + + + +
const char* gengetopt_args_info::outfile_help
+
+ +

Output filename help description.

+ +
+
+ +

◆ outfile_orig

+ +
+
+ + + + +
char* gengetopt_args_info::outfile_orig
+
+ +

Output filename original value given at command line.

+ +
+
+ +

◆ pars_arg

+ +
+
+ + + + +
char* gengetopt_args_info::pars_arg
+
+ +

String with parameters.

+ +
+
+ +

◆ pars_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::pars_given
+
+ +

Whether pars was given.

+ +
+
+ +

◆ pars_help

+ +
+
+ + + + +
const char* gengetopt_args_info::pars_help
+
+ +

String with parameters help description.

+ +
+
+ +

◆ pars_orig

+ +
+
+ + + + +
char* gengetopt_args_info::pars_orig
+
+ +

String with parameters original value given at command line.

+ +
+
+ +

◆ stop_early_flag

+ +
+
+ + + + +
int gengetopt_args_info::stop_early_flag
+
+ +

Don't calculate p-values if below cutoff (default=off).

+ +
+
+ +

◆ stop_early_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::stop_early_given
+
+ +

Whether stop-early was given.

+ +
+
+ +

◆ stop_early_help

+ +
+
+ + + + +
const char* gengetopt_args_info::stop_early_help
+
+ +

Don't calculate p-values if below cutoff help description.

+ +
+
+ +

◆ tabular_flag

+ +
+
+ + + + +
int gengetopt_args_info::tabular_flag
+
+ +

Tab delimited output (default=off).

+ +
+
+ +

◆ tabular_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::tabular_given
+
+ +

Whether tabular was given.

+ +
+
+ +

◆ tabular_help

+ +
+
+ + + + +
const char* gengetopt_args_info::tabular_help
+
+ +

Tab delimited output help description.

+ +
+
+ +

◆ version_given

+ +
+
+ + + + +
unsigned int gengetopt_args_info::version_given
+
+ +

Whether version was given.

+ +
+
+ +

◆ version_help

+ +
+
+ + + + +
const char* gengetopt_args_info::version_help
+
+ +

Print version and exit help description.

+ +
+
+
The documentation for this struct was generated from the following file: +
+ + + + diff --git a/src/html/structoption-members.html b/src/html/structoption-members.html new file mode 100644 index 0000000..333d72e --- /dev/null +++ b/src/html/structoption-members.html @@ -0,0 +1,80 @@ + + + + + + + +My Project: Member List + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+
+
option Member List
+
+
+ +

This is the complete list of members for option, including all inherited members.

+ + + + + +
flagoption
has_argoption
nameoption
valoption
+ + + + diff --git a/src/html/structoption.html b/src/html/structoption.html new file mode 100644 index 0000000..f67c3bf --- /dev/null +++ b/src/html/structoption.html @@ -0,0 +1,150 @@ + + + + + + + +My Project: option Struct Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
option Struct Reference
+
+
+ +

#include <getopt.h>

+ + + + + + + + + + +

+Public Attributes

char * name
 
int has_arg
 
int * flag
 
int val
 
+

Member Data Documentation

+ +

◆ flag

+ +
+
+ + + + +
int* option::flag
+
+ +
+
+ +

◆ has_arg

+ +
+
+ + + + +
int option::has_arg
+
+ +
+
+ +

◆ name

+ +
+
+ + + + +
char* option::name
+
+ +
+
+ +

◆ val

+ +
+
+ + + + +
int option::val
+
+ +
+
+
The documentation for this struct was generated from the following file: +
+ + + + diff --git a/src/html/sync_off.png b/src/html/sync_off.png new file mode 100644 index 0000000..3b443fc Binary files /dev/null and b/src/html/sync_off.png differ diff --git a/src/html/sync_on.png b/src/html/sync_on.png new file mode 100644 index 0000000..e08320f Binary files /dev/null and b/src/html/sync_on.png differ diff --git a/src/html/tab_a.png b/src/html/tab_a.png new file mode 100644 index 0000000..3b725c4 Binary files /dev/null and b/src/html/tab_a.png differ diff --git a/src/html/tab_b.png b/src/html/tab_b.png new file mode 100644 index 0000000..e2b4a86 Binary files /dev/null and b/src/html/tab_b.png differ diff --git a/src/html/tab_h.png b/src/html/tab_h.png new file mode 100644 index 0000000..fd5cb70 Binary files /dev/null and b/src/html/tab_h.png differ diff --git a/src/html/tab_s.png b/src/html/tab_s.png new file mode 100644 index 0000000..ab478c9 Binary files /dev/null and b/src/html/tab_s.png differ diff --git a/src/html/tabs.css b/src/html/tabs.css new file mode 100644 index 0000000..bbde11e --- /dev/null +++ b/src/html/tabs.css @@ -0,0 +1 @@ +.sm{position:relative;z-index:9999}.sm,.sm ul,.sm li{display:block;list-style:none;margin:0;padding:0;line-height:normal;direction:ltr;text-align:left;-webkit-tap-highlight-color:transparent}.sm-rtl,.sm-rtl ul,.sm-rtl li{direction:rtl;text-align:right}.sm>li>h1,.sm>li>h2,.sm>li>h3,.sm>li>h4,.sm>li>h5,.sm>li>h6{margin:0;padding:0}.sm ul{display:none}.sm li,.sm a{position:relative}.sm a{display:block}.sm a.disabled{cursor:not-allowed}.sm:after{content:"\00a0";display:block;height:0;font:0px/0 serif;clear:both;visibility:hidden;overflow:hidden}.sm,.sm *,.sm *:before,.sm *:after{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}.sm-dox{background-image:url("tab_b.png")}.sm-dox a,.sm-dox a:focus,.sm-dox a:hover,.sm-dox a:active{padding:0px 12px;padding-right:43px;font-family:"Lucida Grande","Geneva","Helvetica",Arial,sans-serif;font-size:13px;font-weight:bold;line-height:36px;text-decoration:none;text-shadow:0px 1px 1px rgba(255,255,255,0.9);color:#283A5D;outline:none}.sm-dox a:hover{background-image:url("tab_a.png");background-repeat:repeat-x;color:#fff;text-shadow:0px 1px 1px #000}.sm-dox a.current{color:#D23600}.sm-dox a.disabled{color:#bbb}.sm-dox a span.sub-arrow{position:absolute;top:50%;margin-top:-14px;left:auto;right:3px;width:28px;height:28px;overflow:hidden;font:bold 12px/28px monospace !important;text-align:center;text-shadow:none;background:rgba(255,255,255,0.5);border-radius:5px}.sm-dox a.highlighted span.sub-arrow:before{display:block;content:'-'}.sm-dox>li:first-child>a,.sm-dox>li:first-child>:not(ul) a{border-radius:5px 5px 0 0}.sm-dox>li:last-child>a,.sm-dox>li:last-child>*:not(ul) a,.sm-dox>li:last-child>ul,.sm-dox>li:last-child>ul>li:last-child>a,.sm-dox>li:last-child>ul>li:last-child>*:not(ul) a,.sm-dox>li:last-child>ul>li:last-child>ul,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul{border-radius:0 0 5px 5px}.sm-dox>li:last-child>a.highlighted,.sm-dox>li:last-child>*:not(ul) a.highlighted,.sm-dox>li:last-child>ul>li:last-child>a.highlighted,.sm-dox>li:last-child>ul>li:last-child>*:not(ul) a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a.highlighted{border-radius:0}.sm-dox ul{background:rgba(162,162,162,0.1)}.sm-dox ul a,.sm-dox ul a:focus,.sm-dox ul a:hover,.sm-dox ul a:active{font-size:12px;border-left:8px solid transparent;line-height:36px;text-shadow:none;background-color:white;background-image:none}.sm-dox ul a:hover{background-image:url("tab_a.png");background-repeat:repeat-x;color:#fff;text-shadow:0px 1px 1px #000}.sm-dox ul ul a,.sm-dox ul ul a:hover,.sm-dox ul ul a:focus,.sm-dox ul ul a:active{border-left:16px solid transparent}.sm-dox ul ul ul a,.sm-dox ul ul ul a:hover,.sm-dox ul ul ul a:focus,.sm-dox ul ul ul a:active{border-left:24px solid transparent}.sm-dox ul ul ul ul a,.sm-dox ul ul ul ul a:hover,.sm-dox ul ul ul ul a:focus,.sm-dox ul ul ul ul a:active{border-left:32px solid transparent}.sm-dox ul ul ul ul ul a,.sm-dox ul ul ul ul ul a:hover,.sm-dox ul ul ul ul ul a:focus,.sm-dox ul ul ul ul ul a:active{border-left:40px solid transparent}@media (min-width: 768px){.sm-dox ul{position:absolute;width:12em}.sm-dox li{float:left}.sm-dox.sm-rtl li{float:right}.sm-dox ul li,.sm-dox.sm-rtl ul li,.sm-dox.sm-vertical li{float:none}.sm-dox a{white-space:nowrap}.sm-dox ul a,.sm-dox.sm-vertical a{white-space:normal}.sm-dox .sm-nowrap>li>a,.sm-dox .sm-nowrap>li>:not(ul) a{white-space:nowrap}.sm-dox{padding:0 10px;background-image:url("tab_b.png");line-height:36px}.sm-dox a span.sub-arrow{top:50%;margin-top:-2px;right:12px;width:0;height:0;border-width:4px;border-style:solid dashed dashed dashed;border-color:#283A5D transparent transparent transparent;background:transparent;border-radius:0}.sm-dox a,.sm-dox a:focus,.sm-dox a:active,.sm-dox a:hover,.sm-dox a.highlighted{padding:0px 12px;background-image:url("tab_s.png");background-repeat:no-repeat;background-position:right;border-radius:0 !important}.sm-dox a:hover{background-image:url("tab_a.png");background-repeat:repeat-x;color:#fff;text-shadow:0px 1px 1px #000}.sm-dox a:hover span.sub-arrow{border-color:#fff transparent transparent transparent}.sm-dox a.has-submenu{padding-right:24px}.sm-dox li{border-top:0}.sm-dox>li>ul:before,.sm-dox>li>ul:after{content:'';position:absolute;top:-18px;left:30px;width:0;height:0;overflow:hidden;border-width:9px;border-style:dashed dashed solid dashed;border-color:transparent transparent #bbb transparent}.sm-dox>li>ul:after{top:-16px;left:31px;border-width:8px;border-color:transparent transparent #fff transparent}.sm-dox ul{border:1px solid #bbb;padding:5px 0;background:#fff;border-radius:5px !important;box-shadow:0 5px 9px rgba(0,0,0,0.2)}.sm-dox ul a span.sub-arrow{right:8px;top:50%;margin-top:-5px;border-width:5px;border-color:transparent transparent transparent #555;border-style:dashed dashed dashed solid}.sm-dox ul a,.sm-dox ul a:hover,.sm-dox ul a:focus,.sm-dox ul a:active,.sm-dox ul a.highlighted{color:#555;background-image:none;border:0 !important;color:#555;background-image:none}.sm-dox ul a:hover{background-image:url("tab_a.png");background-repeat:repeat-x;color:#fff;text-shadow:0px 1px 1px #000}.sm-dox ul a:hover span.sub-arrow{border-color:transparent transparent transparent #fff}.sm-dox span.scroll-up,.sm-dox span.scroll-down{position:absolute;display:none;visibility:hidden;overflow:hidden;background:#fff;height:36px}.sm-dox span.scroll-up:hover,.sm-dox span.scroll-down:hover{background:#eee}.sm-dox span.scroll-up:hover span.scroll-up-arrow,.sm-dox span.scroll-up:hover span.scroll-down-arrow{border-color:transparent transparent #D23600 transparent}.sm-dox span.scroll-down:hover span.scroll-down-arrow{border-color:#D23600 transparent transparent transparent}.sm-dox span.scroll-up-arrow,.sm-dox span.scroll-down-arrow{position:absolute;top:0;left:50%;margin-left:-6px;width:0;height:0;overflow:hidden;border-width:6px;border-style:dashed dashed solid dashed;border-color:transparent transparent #555 transparent}.sm-dox span.scroll-down-arrow{top:8px;border-style:solid dashed dashed dashed;border-color:#555 transparent transparent transparent}.sm-dox.sm-rtl a.has-submenu{padding-right:12px;padding-left:24px}.sm-dox.sm-rtl a span.sub-arrow{right:auto;left:12px}.sm-dox.sm-rtl.sm-vertical a.has-submenu{padding:10px 20px}.sm-dox.sm-rtl.sm-vertical a span.sub-arrow{right:auto;left:8px;border-style:dashed solid dashed dashed;border-color:transparent #555 transparent transparent}.sm-dox.sm-rtl>li>ul:before{left:auto;right:30px}.sm-dox.sm-rtl>li>ul:after{left:auto;right:31px}.sm-dox.sm-rtl ul a.has-submenu{padding:10px 20px !important}.sm-dox.sm-rtl ul a span.sub-arrow{right:auto;left:8px;border-style:dashed solid dashed dashed;border-color:transparent #555 transparent transparent}.sm-dox.sm-vertical{padding:10px 0;border-radius:5px}.sm-dox.sm-vertical a{padding:10px 20px}.sm-dox.sm-vertical a:hover,.sm-dox.sm-vertical a:focus,.sm-dox.sm-vertical a:active,.sm-dox.sm-vertical a.highlighted{background:#fff}.sm-dox.sm-vertical a.disabled{background-image:url("tab_b.png")}.sm-dox.sm-vertical a span.sub-arrow{right:8px;top:50%;margin-top:-5px;border-width:5px;border-style:dashed dashed dashed solid;border-color:transparent transparent transparent #555}.sm-dox.sm-vertical>li>ul:before,.sm-dox.sm-vertical>li>ul:after{display:none}.sm-dox.sm-vertical ul a{padding:10px 20px}.sm-dox.sm-vertical ul a:hover,.sm-dox.sm-vertical ul a:focus,.sm-dox.sm-vertical ul a:active,.sm-dox.sm-vertical ul a.highlighted{background:#eee}.sm-dox.sm-vertical ul a.disabled{background:#fff}} diff --git a/src/html/treeML_8c.html b/src/html/treeML_8c.html new file mode 100644 index 0000000..56ce292 --- /dev/null +++ b/src/html/treeML_8c.html @@ -0,0 +1,181 @@ + + + + + + + +My Project: treeML.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
treeML.c File Reference
+
+
+
#include "spr.h"
+#include "utilities.h"
+#include "lk.h"
+#include "optimiz.h"
+#include "bionj.h"
+#include "models.h"
+#include "free.h"
+#include "options.h"
+#include "simu.h"
+#include "eigen.h"
+#include "pars.h"
+#include "alrt.h"
+#include "rnaz_utils.h"
+
+Include dependency graph for treeML.c:
+
+
+ + + +
+
+ + + + + +

+Functions

seq ** Get_Seq_local (seq **, option *io, int rw)
 
int treeML (const struct aln *alignment[], char **treeString, float *kappa)
 
+

Function Documentation

+ +

◆ Get_Seq_local()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
seq ** Get_Seq_local (seq ** data,
optionio,
int rw 
)
+
+ +
+
+ +

◆ treeML()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int treeML (const struct alnalignment[],
char ** treeString,
float * kappa 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+
+ + + + diff --git a/src/html/treeML_8c__incl.map b/src/html/treeML_8c__incl.map new file mode 100644 index 0000000..5b00480 --- /dev/null +++ b/src/html/treeML_8c__incl.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/treeML_8c__incl.md5 b/src/html/treeML_8c__incl.md5 new file mode 100644 index 0000000..c379efc --- /dev/null +++ b/src/html/treeML_8c__incl.md5 @@ -0,0 +1 @@ +406949e81fec25d83ef94dbe0cfb07f6 \ No newline at end of file diff --git a/src/html/treeML_8c__incl.png b/src/html/treeML_8c__incl.png new file mode 100644 index 0000000..585d469 Binary files /dev/null and b/src/html/treeML_8c__incl.png differ diff --git a/src/html/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.map b/src/html/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.map new file mode 100644 index 0000000..1d60508 --- /dev/null +++ b/src/html/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.md5 b/src/html/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.md5 new file mode 100644 index 0000000..76b573f --- /dev/null +++ b/src/html/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.md5 @@ -0,0 +1 @@ +15dc8b3e94383d66735cddb9e7cce38e \ No newline at end of file diff --git a/src/html/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.png b/src/html/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.png new file mode 100644 index 0000000..23c2244 Binary files /dev/null and b/src/html/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.png differ diff --git a/src/html/treeML_8h.html b/src/html/treeML_8h.html new file mode 100644 index 0000000..3e66239 --- /dev/null +++ b/src/html/treeML_8h.html @@ -0,0 +1,155 @@ + + + + + + + +My Project: treeML.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
treeML.h File Reference
+
+
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + +
+
+

Go to the source code of this file.

+ + + + +

+Macros

#define PHYML
 
+ + + +

+Functions

int treeML (const struct aln *alignment[], char **treeString, float *kappa)
 
+

Macro Definition Documentation

+ +

◆ PHYML

+ +
+
+ + + + +
#define PHYML
+
+ +
+
+

Function Documentation

+ +

◆ treeML()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int treeML (const struct alnalignment[],
char ** treeString,
float * kappa 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+
+ + + + diff --git a/src/html/treeML_8h__dep__incl.map b/src/html/treeML_8h__dep__incl.map new file mode 100644 index 0000000..abaa389 --- /dev/null +++ b/src/html/treeML_8h__dep__incl.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/treeML_8h__dep__incl.md5 b/src/html/treeML_8h__dep__incl.md5 new file mode 100644 index 0000000..060c7fd --- /dev/null +++ b/src/html/treeML_8h__dep__incl.md5 @@ -0,0 +1 @@ +952582e25e3fe635c6473fde82b2b5b6 \ No newline at end of file diff --git a/src/html/treeML_8h__dep__incl.png b/src/html/treeML_8h__dep__incl.png new file mode 100644 index 0000000..472b151 Binary files /dev/null and b/src/html/treeML_8h__dep__incl.png differ diff --git a/src/html/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.map b/src/html/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.map new file mode 100644 index 0000000..1d60508 --- /dev/null +++ b/src/html/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.md5 b/src/html/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.md5 new file mode 100644 index 0000000..737bbf1 --- /dev/null +++ b/src/html/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.md5 @@ -0,0 +1 @@ +a5e92936d3d3488197ea07558188f1c8 \ No newline at end of file diff --git a/src/html/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.png b/src/html/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.png new file mode 100644 index 0000000..23c2244 Binary files /dev/null and b/src/html/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.png differ diff --git a/src/html/treeML_8h_source.html b/src/html/treeML_8h_source.html new file mode 100644 index 0000000..d22d34d --- /dev/null +++ b/src/html/treeML_8h_source.html @@ -0,0 +1,75 @@ + + + + + + + +My Project: treeML.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
treeML.h
+
+
+Go to the documentation of this file.
1 #define PHYML
2 
3 int treeML(const struct aln *alignment[], char** treeString, float* kappa);
4 
Definition: rnaz_utils.h:12
+
int treeML(const struct aln *alignment[], char **treeString, float *kappa)
Definition: treeML.c:35
+
+ + + + diff --git a/src/html/treeSimulate_8c.html b/src/html/treeSimulate_8c.html new file mode 100644 index 0000000..f42c701 --- /dev/null +++ b/src/html/treeSimulate_8c.html @@ -0,0 +1,465 @@ + + + + + + + +My Project: treeSimulate.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
treeSimulate.c File Reference
+
+
+
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <time.h>
+#include <math.h>
+#include "rnaz_utils.h"
+#include "treeSimulate.h"
+#include "global.h"
+#include "treefile.h"
+#include "evolve.h"
+#include "model.h"
+#include "nucmodels.h"
+#include "aamodels.h"
+#include "progress.h"
+#include "twister.h"
+
+Include dependency graph for treeSimulate.c:
+
+
+ + + + +
+
+ + + + + + + + + + + + + +

+Functions

void simulateTree (TTree *tree, float freqs[], float kap, int L)
 
TTree * string2tree (char *treeString)
 
float ** getDistanceMatrix (TTree *tree, struct aln *alignment[])
 
TNode * getLCA (TTree *tree, TNode *nodeA, TNode *nodeB)
 
void tree2aln (TTree *tree, struct aln *alignment[])
 
void freeSeqgenTree (TTree *tree)
 
+ + + + + + + + + + + + + + + + + + + + + +

+Variables

int model
 
int numStates
 
int isNucModel
 
int userFreqs
 
int equalFreqs
 
int numSites
 
double tstv
 
double nucFreq [NUM_NUC]
 
int numTaxa
 
char * P
 
+

Function Documentation

+ +

◆ freeSeqgenTree()

+ +
+
+ + + + + + + + +
void freeSeqgenTree (TTree * tree)
+
+ +
+
+ +

◆ getDistanceMatrix()

+ +
+
+ + + + + + + + + + + + + + + + + + +
float** getDistanceMatrix (TTree * tree,
struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ getLCA()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
TNode* getLCA (TTree * tree,
TNode * nodeA,
TNode * nodeB 
)
+
+ +
+
+ +

◆ simulateTree()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void simulateTree (TTree * tree,
float freqs[],
float kap,
int L 
)
+
+ +
+
+ +

◆ string2tree()

+ +
+
+ + + + + + + + +
TTree* string2tree (char * treeString)
+
+ +
+
+ +

◆ tree2aln()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void tree2aln (TTree * tree,
struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+

Variable Documentation

+ +

◆ equalFreqs

+ +
+
+ + + + +
int equalFreqs
+
+ +
+
+ +

◆ isNucModel

+ +
+
+ + + + +
int isNucModel
+
+ +
+
+ +

◆ model

+ +
+
+ + + + +
int model
+
+ +
+
+ +

◆ nucFreq

+ +
+
+ + + + +
double nucFreq[NUM_NUC]
+
+ +
+
+ +

◆ numSites

+ +
+
+ + + + +
int numSites
+
+ +
+
+ +

◆ numStates

+ +
+
+ + + + +
int numStates
+
+ +
+
+ +

◆ numTaxa

+ +
+
+ + + + +
int numTaxa
+
+ +
+
+ +

◆ P

+ +
+
+ + + + +
char* P
+
+ +
+
+ +

◆ tstv

+ +
+
+ + + + +
double tstv
+
+ +
+
+ +

◆ userFreqs

+ +
+
+ + + + +
int userFreqs
+
+ +
+
+
+ + + + diff --git a/src/html/treeSimulate_8c__incl.map b/src/html/treeSimulate_8c__incl.map new file mode 100644 index 0000000..4c95d82 --- /dev/null +++ b/src/html/treeSimulate_8c__incl.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/treeSimulate_8c__incl.md5 b/src/html/treeSimulate_8c__incl.md5 new file mode 100644 index 0000000..1c48588 --- /dev/null +++ b/src/html/treeSimulate_8c__incl.md5 @@ -0,0 +1 @@ +8dad9262c7e3fdd1bf52d590031ed43f \ No newline at end of file diff --git a/src/html/treeSimulate_8c__incl.png b/src/html/treeSimulate_8c__incl.png new file mode 100644 index 0000000..a1d2775 Binary files /dev/null and b/src/html/treeSimulate_8c__incl.png differ diff --git a/src/html/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.map b/src/html/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.map new file mode 100644 index 0000000..4d44f38 --- /dev/null +++ b/src/html/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 b/src/html/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 new file mode 100644 index 0000000..087795d --- /dev/null +++ b/src/html/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 @@ -0,0 +1 @@ +c2d527f8aea235549b8fc232c42aa7da \ No newline at end of file diff --git a/src/html/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.png b/src/html/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.png new file mode 100644 index 0000000..15bd9a8 Binary files /dev/null and b/src/html/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.png differ diff --git a/src/html/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.map b/src/html/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.map new file mode 100644 index 0000000..4ad3eb5 --- /dev/null +++ b/src/html/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 b/src/html/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 new file mode 100644 index 0000000..74ee293 --- /dev/null +++ b/src/html/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 @@ -0,0 +1 @@ +93579460f47ba389c4c7dd2bd01daf54 \ No newline at end of file diff --git a/src/html/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.png b/src/html/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.png new file mode 100644 index 0000000..134dac3 Binary files /dev/null and b/src/html/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.png differ diff --git a/src/html/treeSimulate_8h.html b/src/html/treeSimulate_8h.html new file mode 100644 index 0000000..968437a --- /dev/null +++ b/src/html/treeSimulate_8h.html @@ -0,0 +1,301 @@ + + + + + + + +My Project: treeSimulate.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
treeSimulate.h File Reference
+
+
+
#include "tree.h"
+#include "rnaz_utils.h"
+
+Include dependency graph for treeSimulate.h:
+
+
+ + + +
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + + + + + + +
+
+

Go to the source code of this file.

+ + + + + + + + + + + + + + +

+Functions

TNode * getLCA (TTree *tree, TNode *nodeA, TNode *nodeB)
 
void tree2aln (TTree *tree, struct aln *alignment[])
 
TTree * string2tree (char *treeString)
 
void simulateTree (TTree *tree, float freqs[], float kap, int L)
 
float ** getDistanceMatrix (TTree *tree, struct aln *alignment[])
 
void freeSeqgenTree (TTree *tree)
 
+

Function Documentation

+ +

◆ freeSeqgenTree()

+ +
+
+ + + + + + + + +
void freeSeqgenTree (TTree * tree)
+
+ +
+
+ +

◆ getDistanceMatrix()

+ +
+
+ + + + + + + + + + + + + + + + + + +
float** getDistanceMatrix (TTree * tree,
struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ getLCA()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
TNode* getLCA (TTree * tree,
TNode * nodeA,
TNode * nodeB 
)
+
+ +
+
+ +

◆ simulateTree()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void simulateTree (TTree * tree,
float freqs[],
float kap,
int L 
)
+
+ +
+
+ +

◆ string2tree()

+ +
+
+ + + + + + + + +
TTree* string2tree (char * treeString)
+
+ +
+
+ +

◆ tree2aln()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void tree2aln (TTree * tree,
struct alnalignment[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+
+ + + + diff --git a/src/html/treeSimulate_8h__dep__incl.map b/src/html/treeSimulate_8h__dep__incl.map new file mode 100644 index 0000000..cb8588d --- /dev/null +++ b/src/html/treeSimulate_8h__dep__incl.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/html/treeSimulate_8h__dep__incl.md5 b/src/html/treeSimulate_8h__dep__incl.md5 new file mode 100644 index 0000000..dce2c7c --- /dev/null +++ b/src/html/treeSimulate_8h__dep__incl.md5 @@ -0,0 +1 @@ +4a6598860fac584d25f9d575f7b65f10 \ No newline at end of file diff --git a/src/html/treeSimulate_8h__dep__incl.png b/src/html/treeSimulate_8h__dep__incl.png new file mode 100644 index 0000000..05bcebd Binary files /dev/null and b/src/html/treeSimulate_8h__dep__incl.png differ diff --git a/src/html/treeSimulate_8h__incl.map b/src/html/treeSimulate_8h__incl.map new file mode 100644 index 0000000..f378bef --- /dev/null +++ b/src/html/treeSimulate_8h__incl.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/treeSimulate_8h__incl.md5 b/src/html/treeSimulate_8h__incl.md5 new file mode 100644 index 0000000..e566149 --- /dev/null +++ b/src/html/treeSimulate_8h__incl.md5 @@ -0,0 +1 @@ +08694433639c676d45e56a45f4471c57 \ No newline at end of file diff --git a/src/html/treeSimulate_8h__incl.png b/src/html/treeSimulate_8h__incl.png new file mode 100644 index 0000000..8f01632 Binary files /dev/null and b/src/html/treeSimulate_8h__incl.png differ diff --git a/src/html/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.map b/src/html/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.map new file mode 100644 index 0000000..4d44f38 --- /dev/null +++ b/src/html/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 b/src/html/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 new file mode 100644 index 0000000..087795d --- /dev/null +++ b/src/html/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 @@ -0,0 +1 @@ +c2d527f8aea235549b8fc232c42aa7da \ No newline at end of file diff --git a/src/html/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.png b/src/html/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.png new file mode 100644 index 0000000..15bd9a8 Binary files /dev/null and b/src/html/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.png differ diff --git a/src/html/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.map b/src/html/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.map new file mode 100644 index 0000000..4ad3eb5 --- /dev/null +++ b/src/html/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 b/src/html/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 new file mode 100644 index 0000000..74ee293 --- /dev/null +++ b/src/html/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 @@ -0,0 +1 @@ +93579460f47ba389c4c7dd2bd01daf54 \ No newline at end of file diff --git a/src/html/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.png b/src/html/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.png new file mode 100644 index 0000000..134dac3 Binary files /dev/null and b/src/html/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.png differ diff --git a/src/html/treeSimulate_8h_source.html b/src/html/treeSimulate_8h_source.html new file mode 100644 index 0000000..6d46dc7 --- /dev/null +++ b/src/html/treeSimulate_8h_source.html @@ -0,0 +1,81 @@ + + + + + + + +My Project: treeSimulate.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
treeSimulate.h
+
+
+Go to the documentation of this file.
1 /* Copyright 2009, Stefan Washietl
2 
3  This file is part of RNAcode.
4 
5  RNAcode is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  RNAcode is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with RNAcode. If not, see <http://www.gnu.org/licenses/>. */
17 
18 #include "tree.h"
19 #include "rnaz_utils.h"
20 
21 TNode* getLCA(TTree* tree, TNode* nodeA, TNode* nodeB);
22 void tree2aln(TTree* tree, struct aln *alignment[]);
23 TTree* string2tree(char* treeString);
24 
25 void simulateTree(TTree* tree, float freqs[], float kap, int L);
26 
27 float** getDistanceMatrix(TTree* tree, struct aln *alignment[]);
28 
29 void freeSeqgenTree(TTree* tree);
Definition: rnaz_utils.h:12
+
TNode * getLCA(TTree *tree, TNode *nodeA, TNode *nodeB)
Definition: treeSimulate.c:196
+
void freeSeqgenTree(TTree *tree)
Definition: treeSimulate.c:288
+ +
float ** getDistanceMatrix(TTree *tree, struct aln *alignment[])
Definition: treeSimulate.c:118
+
TTree * string2tree(char *treeString)
Definition: treeSimulate.c:100
+
void tree2aln(TTree *tree, struct aln *alignment[])
Definition: treeSimulate.c:254
+
void simulateTree(TTree *tree, float freqs[], float kap, int L)
Definition: treeSimulate.c:52
+
+ + + + diff --git a/src/html/utils_8c.html b/src/html/utils_8c.html new file mode 100644 index 0000000..464d7ba --- /dev/null +++ b/src/html/utils_8c.html @@ -0,0 +1,635 @@ + + + + + + + +My Project: utils.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
utils.c File Reference
+
+
+
#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <time.h>
+#include <string.h>
+#include "../config.h"
+
+Include dependency graph for utils.c:
+
+
+ + +
+
+ + + + + +

+Macros

#define PRIVATE   static
 
#define PUBLIC
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

PUBLIC void * space (unsigned int size)
 
PUBLIC void nrerror (const char message[])
 
PUBLIC double urn (void)
 
PUBLIC int int_urn (int from, int to)
 
PUBLIC void filecopy (FILE *from, FILE *to)
 
PUBLIC char * time_stamp (void)
 
PUBLIC char * random_string (int l, const char symbols[])
 
PUBLIC int hamming (const char *s1, const char *s2)
 
PUBLIC char * get_line (FILE *fp)
 
PUBLIC void * space (unsigned size)
 
void * xrealloc (void *p, unsigned size)
 
PUBLIC void init_rand (void)
 
PUBLIC char * pack_structure (const char *struc)
 
PUBLIC char * unpack_structure (const char *packed)
 
PUBLIC short * make_pair_table (const char *structure)
 
PUBLIC int bp_distance (const char *str1, const char *str2)
 
+ + + + + +

+Variables

static char rcsid [] = "$Id: utils.c,v 1.2 2007-07-22 20:58:48 wash Exp $"
 
PUBLIC unsigned short xsubi [3]
 
+

Macro Definition Documentation

+ +

◆ PRIVATE

+ +
+
+ + + + +
#define PRIVATE   static
+
+ +
+
+ +

◆ PUBLIC

+ +
+
+ + + + +
#define PUBLIC
+
+ +
+
+

Function Documentation

+ +

◆ bp_distance()

+ +
+
+ + + + + + + + + + + + + + + + + + +
PUBLIC int bp_distance (const char * str1,
const char * str2 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ filecopy()

+ +
+
+ + + + + + + + + + + + + + + + + + +
PUBLIC void filecopy (FILE * from,
FILE * to 
)
+
+ +
+
+ +

◆ get_line()

+ +
+
+ + + + + + + + +
PUBLIC char * get_line (FILE * fp)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ hamming()

+ +
+
+ + + + + + + + + + + + + + + + + + +
PUBLIC int hamming (const char * s1,
const char * s2 
)
+
+ +
+
+ +

◆ init_rand()

+ +
+
+ + + + + + + + +
PUBLIC void init_rand (void )
+
+ +
+
+ +

◆ int_urn()

+ +
+
+ + + + + + + + + + + + + + + + + + +
PUBLIC int int_urn (int from,
int to 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ make_pair_table()

+ +
+
+ + + + + + + + +
PUBLIC short* make_pair_table (const char * structure)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ nrerror()

+ +
+
+ + + + + + + + +
PUBLIC void nrerror (const char message[])
+
+ +
+
+ +

◆ pack_structure()

+ +
+
+ + + + + + + + +
PUBLIC char* pack_structure (const char * struc)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ random_string()

+ +
+
+ + + + + + + + + + + + + + + + + + +
PUBLIC char * random_string (int l,
const char symbols[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ space() [1/2]

+ +
+
+ + + + + + + + +
PUBLIC void* space (unsigned int size)
+
+ +
+
+ +

◆ space() [2/2]

+ +
+
+ + + + + + + + +
PUBLIC void* space (unsigned size)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ time_stamp()

+ +
+
+ + + + + + + + +
PUBLIC char * time_stamp (void )
+
+ +
+
+ +

◆ unpack_structure()

+ +
+
+ + + + + + + + +
PUBLIC char* unpack_structure (const char * packed)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ urn()

+ +
+
+ + + + + + + + +
PUBLIC double urn (void )
+
+ +
+
+ +

◆ xrealloc()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void* xrealloc (void * p,
unsigned size 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+

Variable Documentation

+ +

◆ rcsid

+ +
+
+ + + + + +
+ + + + +
char rcsid[] = "$Id: utils.c,v 1.2 2007-07-22 20:58:48 wash Exp $"
+
+static
+
+ +
+
+ +

◆ xsubi

+ +
+
+ + + + +
PUBLIC unsigned short xsubi[3]
+
+ +
+
+
+ + + + diff --git a/src/html/utils_8c__incl.map b/src/html/utils_8c__incl.map new file mode 100644 index 0000000..179259e --- /dev/null +++ b/src/html/utils_8c__incl.map @@ -0,0 +1,2 @@ + + diff --git a/src/html/utils_8c__incl.md5 b/src/html/utils_8c__incl.md5 new file mode 100644 index 0000000..0be0a76 --- /dev/null +++ b/src/html/utils_8c__incl.md5 @@ -0,0 +1 @@ +70f58bd3c904142a566f63b24fab7fd0 \ No newline at end of file diff --git a/src/html/utils_8c__incl.png b/src/html/utils_8c__incl.png new file mode 100644 index 0000000..5577082 Binary files /dev/null and b/src/html/utils_8c__incl.png differ diff --git a/src/html/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.map b/src/html/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.map new file mode 100644 index 0000000..22b4a3e --- /dev/null +++ b/src/html/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.md5 b/src/html/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.md5 new file mode 100644 index 0000000..2b50060 --- /dev/null +++ b/src/html/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.md5 @@ -0,0 +1 @@ +ed266e6b0e4684dc388aa79423d364e8 \ No newline at end of file diff --git a/src/html/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.png b/src/html/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.png new file mode 100644 index 0000000..80c59b3 Binary files /dev/null and b/src/html/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.png differ diff --git a/src/html/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.map b/src/html/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.map new file mode 100644 index 0000000..7bd4f9c --- /dev/null +++ b/src/html/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.md5 b/src/html/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.md5 new file mode 100644 index 0000000..9b18282 --- /dev/null +++ b/src/html/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.md5 @@ -0,0 +1 @@ +fa2d508578d37f7fdef3988b6fc2d281 \ No newline at end of file diff --git a/src/html/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.png b/src/html/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.png new file mode 100644 index 0000000..4712989 Binary files /dev/null and b/src/html/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.png differ diff --git a/src/html/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.map b/src/html/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.map new file mode 100644 index 0000000..2ad98a4 --- /dev/null +++ b/src/html/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.md5 b/src/html/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.md5 new file mode 100644 index 0000000..d93b2a6 --- /dev/null +++ b/src/html/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.md5 @@ -0,0 +1 @@ +aff00add955748d4c5f9b98e99e5325f \ No newline at end of file diff --git a/src/html/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.png b/src/html/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.png new file mode 100644 index 0000000..0c6d3d4 Binary files /dev/null and b/src/html/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.png differ diff --git a/src/html/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.map b/src/html/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.map new file mode 100644 index 0000000..d4ca0e7 --- /dev/null +++ b/src/html/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 b/src/html/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 new file mode 100644 index 0000000..e590cd2 --- /dev/null +++ b/src/html/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 @@ -0,0 +1 @@ +b83ef1f8d3d9210611c7a7530761b02d \ No newline at end of file diff --git a/src/html/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.png b/src/html/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.png new file mode 100644 index 0000000..2aa6dc7 Binary files /dev/null and b/src/html/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.png differ diff --git a/src/html/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.map b/src/html/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.map new file mode 100644 index 0000000..26d687f --- /dev/null +++ b/src/html/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.md5 b/src/html/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.md5 new file mode 100644 index 0000000..6729391 --- /dev/null +++ b/src/html/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.md5 @@ -0,0 +1 @@ +cf2bf11dec6c3a9a367d4bf9362fa05f \ No newline at end of file diff --git a/src/html/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.png b/src/html/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.png new file mode 100644 index 0000000..e5b402e Binary files /dev/null and b/src/html/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.png differ diff --git a/src/html/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.map b/src/html/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.map new file mode 100644 index 0000000..3b9c5c7 --- /dev/null +++ b/src/html/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.md5 b/src/html/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.md5 new file mode 100644 index 0000000..78bf645 --- /dev/null +++ b/src/html/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.md5 @@ -0,0 +1 @@ +f98df3ac1b0ec24b97e221683fedccd9 \ No newline at end of file diff --git a/src/html/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.png b/src/html/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.png new file mode 100644 index 0000000..bfd825f Binary files /dev/null and b/src/html/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.png differ diff --git a/src/html/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.map b/src/html/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.map new file mode 100644 index 0000000..e2cedda --- /dev/null +++ b/src/html/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.md5 b/src/html/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.md5 new file mode 100644 index 0000000..d4e1db2 --- /dev/null +++ b/src/html/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.md5 @@ -0,0 +1 @@ +fcf192ec79881f5c7647ab5901fee52a \ No newline at end of file diff --git a/src/html/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.png b/src/html/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.png new file mode 100644 index 0000000..6def82d Binary files /dev/null and b/src/html/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.png differ diff --git a/src/html/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.map b/src/html/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.map new file mode 100644 index 0000000..587c71c --- /dev/null +++ b/src/html/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.md5 b/src/html/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.md5 new file mode 100644 index 0000000..bc8b6db --- /dev/null +++ b/src/html/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.md5 @@ -0,0 +1 @@ +6ff7813d10aefff0217c9cb09bd36ae9 \ No newline at end of file diff --git a/src/html/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.png b/src/html/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.png new file mode 100644 index 0000000..c65cb91 Binary files /dev/null and b/src/html/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.png differ diff --git a/src/html/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.map b/src/html/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.map new file mode 100644 index 0000000..08635f6 --- /dev/null +++ b/src/html/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.md5 b/src/html/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.md5 new file mode 100644 index 0000000..3b8fe51 --- /dev/null +++ b/src/html/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.md5 @@ -0,0 +1 @@ +b23f5ce9ca605d0f033a2d1562eae0bd \ No newline at end of file diff --git a/src/html/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.png b/src/html/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.png new file mode 100644 index 0000000..7037824 Binary files /dev/null and b/src/html/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.png differ diff --git a/src/html/utils_8h.html b/src/html/utils_8h.html new file mode 100644 index 0000000..23f4caf --- /dev/null +++ b/src/html/utils_8h.html @@ -0,0 +1,542 @@ + + + + + + + +My Project: utils.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
utils.h File Reference
+
+
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + + + +
+
+

Go to the source code of this file.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

void * space (unsigned size)
 
void * xrealloc (void *p, unsigned size)
 
void nrerror (const char message[])
 
void init_rand (void)
 
double urn (void)
 
int int_urn (int from, int to)
 
void filecopy (FILE *from, FILE *to)
 
char * time_stamp (void)
 
char * random_string (int l, const char symbols[])
 
int hamming (const char *s1, const char *s2)
 
char * get_line (const FILE *fp)
 
char * pack_structure (const char *struc)
 
char * unpack_structure (const char *packed)
 
short * make_pair_table (const char *structure)
 
int bp_distance (const char *str1, const char *str2)
 
+ + + +

+Variables

unsigned short xsubi [3]
 
+

Function Documentation

+ +

◆ bp_distance()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int bp_distance (const char * str1,
const char * str2 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + + +
+ +
+
+ +

◆ filecopy()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void filecopy (FILE * from,
FILE * to 
)
+
+ +
+
+ +

◆ get_line()

+ +
+
+ + + + + + + + +
char* get_line (const FILE * fp)
+
+ +
+
+ +

◆ hamming()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int hamming (const char * s1,
const char * s2 
)
+
+ +
+
+ +

◆ init_rand()

+ +
+
+ + + + + + + + +
void init_rand (void )
+
+ +
+
+ +

◆ int_urn()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int int_urn (int from,
int to 
)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ make_pair_table()

+ +
+
+ + + + + + + + +
short* make_pair_table (const char * structure)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ nrerror()

+ +
+
+ + + + + + + + +
void nrerror (const char message[])
+
+ +
+
+ +

◆ pack_structure()

+ +
+
+ + + + + + + + +
char* pack_structure (const char * struc)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ random_string()

+ +
+
+ + + + + + + + + + + + + + + + + + +
char* random_string (int l,
const char symbols[] 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+ +

◆ space()

+ +
+
+ + + + + + + + +
void* space (unsigned size)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ time_stamp()

+ +
+
+ + + + + + + + +
char* time_stamp (void )
+
+ +
+
+ +

◆ unpack_structure()

+ +
+
+ + + + + + + + +
char* unpack_structure (const char * packed)
+
+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+ +

◆ urn()

+ +
+
+ + + + + + + + +
double urn (void )
+
+ +
+
+ +

◆ xrealloc()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void* xrealloc (void * p,
unsigned size 
)
+
+
+Here is the call graph for this function:
+
+
+ + + + +
+ +
+
+

Variable Documentation

+ +

◆ xsubi

+ +
+
+ + + + +
unsigned short xsubi[3]
+
+ +
+
+
+ + + + diff --git a/src/html/utils_8h__dep__incl.map b/src/html/utils_8h__dep__incl.map new file mode 100644 index 0000000..49b2533 --- /dev/null +++ b/src/html/utils_8h__dep__incl.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/utils_8h__dep__incl.md5 b/src/html/utils_8h__dep__incl.md5 new file mode 100644 index 0000000..e791bb1 --- /dev/null +++ b/src/html/utils_8h__dep__incl.md5 @@ -0,0 +1 @@ +bec8f5714483d75d96d87ee67172c81b \ No newline at end of file diff --git a/src/html/utils_8h__dep__incl.png b/src/html/utils_8h__dep__incl.png new file mode 100644 index 0000000..7472d13 Binary files /dev/null and b/src/html/utils_8h__dep__incl.png differ diff --git a/src/html/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.map b/src/html/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.map new file mode 100644 index 0000000..587c71c --- /dev/null +++ b/src/html/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.md5 b/src/html/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.md5 new file mode 100644 index 0000000..af610b6 --- /dev/null +++ b/src/html/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.md5 @@ -0,0 +1 @@ +d0a4b461928505f9a07aaa2b6a550b57 \ No newline at end of file diff --git a/src/html/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.png b/src/html/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.png new file mode 100644 index 0000000..c65cb91 Binary files /dev/null and b/src/html/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.png differ diff --git a/src/html/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.map b/src/html/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.map new file mode 100644 index 0000000..3b9c5c7 --- /dev/null +++ b/src/html/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.md5 b/src/html/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.md5 new file mode 100644 index 0000000..f9c2c51 --- /dev/null +++ b/src/html/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.md5 @@ -0,0 +1 @@ +7b6d435ade82fb87007370bf850ab8ed \ No newline at end of file diff --git a/src/html/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.png b/src/html/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.png new file mode 100644 index 0000000..bfd825f Binary files /dev/null and b/src/html/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.png differ diff --git a/src/html/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.map b/src/html/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.map new file mode 100644 index 0000000..08635f6 --- /dev/null +++ b/src/html/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.md5 b/src/html/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.md5 new file mode 100644 index 0000000..ff1a059 --- /dev/null +++ b/src/html/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.md5 @@ -0,0 +1 @@ +9c915bb977e3dde30222385499a1dd06 \ No newline at end of file diff --git a/src/html/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.png b/src/html/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.png new file mode 100644 index 0000000..7037824 Binary files /dev/null and b/src/html/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.png differ diff --git a/src/html/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.map b/src/html/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.map new file mode 100644 index 0000000..e2cedda --- /dev/null +++ b/src/html/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/src/html/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.md5 b/src/html/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.md5 new file mode 100644 index 0000000..d4e1db2 --- /dev/null +++ b/src/html/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.md5 @@ -0,0 +1 @@ +fcf192ec79881f5c7647ab5901fee52a \ No newline at end of file diff --git a/src/html/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.png b/src/html/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.png new file mode 100644 index 0000000..6def82d Binary files /dev/null and b/src/html/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.png differ diff --git a/src/html/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.map b/src/html/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.map new file mode 100644 index 0000000..2ad98a4 --- /dev/null +++ b/src/html/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.md5 b/src/html/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.md5 new file mode 100644 index 0000000..c62647e --- /dev/null +++ b/src/html/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.md5 @@ -0,0 +1 @@ +b03260d913931b0bab47a33ede8a8bd5 \ No newline at end of file diff --git a/src/html/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.png b/src/html/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.png new file mode 100644 index 0000000..0c6d3d4 Binary files /dev/null and b/src/html/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.png differ diff --git a/src/html/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.map b/src/html/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.map new file mode 100644 index 0000000..d4ca0e7 --- /dev/null +++ b/src/html/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 b/src/html/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 new file mode 100644 index 0000000..77edaa4 --- /dev/null +++ b/src/html/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 @@ -0,0 +1 @@ +08ee1b88aa4ee0949ce8b8cd2d5be449 \ No newline at end of file diff --git a/src/html/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.png b/src/html/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.png new file mode 100644 index 0000000..2aa6dc7 Binary files /dev/null and b/src/html/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.png differ diff --git a/src/html/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.map b/src/html/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.map new file mode 100644 index 0000000..26d687f --- /dev/null +++ b/src/html/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.map @@ -0,0 +1,4 @@ + + + + diff --git a/src/html/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.md5 b/src/html/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.md5 new file mode 100644 index 0000000..d1bd578 --- /dev/null +++ b/src/html/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.md5 @@ -0,0 +1 @@ +5462f5b2d96414230dbd82afae1b2a04 \ No newline at end of file diff --git a/src/html/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.png b/src/html/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.png new file mode 100644 index 0000000..e5b402e Binary files /dev/null and b/src/html/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.png differ diff --git a/src/html/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.map b/src/html/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.map new file mode 100644 index 0000000..22b4a3e --- /dev/null +++ b/src/html/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.md5 b/src/html/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.md5 new file mode 100644 index 0000000..18450b5 --- /dev/null +++ b/src/html/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.md5 @@ -0,0 +1 @@ +99372c716a3d8126407f07ddb7ad1800 \ No newline at end of file diff --git a/src/html/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.png b/src/html/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.png new file mode 100644 index 0000000..80c59b3 Binary files /dev/null and b/src/html/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.png differ diff --git a/src/html/utils_8h_source.html b/src/html/utils_8h_source.html new file mode 100644 index 0000000..94aee11 --- /dev/null +++ b/src/html/utils_8h_source.html @@ -0,0 +1,89 @@ + + + + + + + +My Project: utils.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
utils.h
+
+
+Go to the documentation of this file.
1 /* Header file for utils.c */
2 #ifdef HAVE_CONFIG_H
3 #include <config.h>
4 #endif
5 #ifdef WITH_DMALLOC
6 /* use dmalloc library to check for memory management bugs */
7 #include "dmalloc.h"
8 #define space(S) calloc(1,(S))
9 #else
10 extern /*@only@*/ /*@notnull@*/
11 void *space(unsigned size) /*@ensures MaxSet(result) == (size-1);@*/;
12  /* allocate space safely */
13 extern /*@only@*/ /*@notnull@*/
14 void *xrealloc(/*@null@*/ /*@only@*/ /*@out@*/ /*@returned@*/ void *p, unsigned size) /*@modifies *p @*/ /*@ensures MaxSet(result) == (size-1) @*/;
15 #endif
16 
17 extern /*@exits@*/ void nrerror(const char message[]); /* die with error message */
18 extern void init_rand(void); /* make random number seeds */
19 extern unsigned short xsubi[3]; /* current 48bit random number */
20 extern double urn(void); /* random number from [0..1] */
21 extern int int_urn(int from, int to); /* random integer */
22 extern void filecopy(FILE *from, FILE *to); /* inefficient `cp' */
23 extern /*@observer@*/ char *time_stamp(void); /* current date in a string */
24 extern /*@only@*/ /*@notnull@*/ char *random_string(int l, const char symbols[]);
25 /* random string of length l using characters from symbols[] */
26 extern int hamming(const char *s1, const char *s2);
27 /* calculate hamming distance */
28 extern /*@only@*/ /*@null@*/ char *get_line(const FILE *fp); /* read one (arbitrary length) line from fp */
29 
30 
31 extern char *pack_structure(const char *struc);
32 /* pack secondary secondary structure, 5:1 compression using base 3 encoding */
33 extern char *unpack_structure(const char *packed);
34 /* unpack sec structure packed with pack_structure() */
35 extern short *make_pair_table(const char *structure);
36 /* returns a newly allocated table, such that: table[i]=j if (i.j) pair or
37  0 if i is unpaired, table[0] contains the length of the structure. */
38 
39 extern int bp_distance(const char *str1, const char *str2);
40 /* dist = {number of base pairs in one structure but not in the other}
41  same as edit distance with open-pair close-pair as move-set */
void * space(unsigned size)
Definition: utils.c:41
+
char * time_stamp(void)
Definition: utils.c:134
+
char * unpack_structure(const char *packed)
Definition: utils.c:227
+
int int_urn(int from, int to)
Definition: utils.c:118
+
void filecopy(FILE *from, FILE *to)
Definition: utils.c:125
+
char * random_string(int l, const char symbols[])
Definition: utils.c:144
+
char * pack_structure(const char *struc)
Definition: utils.c:193
+
int bp_distance(const char *str1, const char *str2)
Definition: utils.c:301
+
void nrerror(const char message[])
Definition: utils.c:82
+
void * xrealloc(void *p, unsigned size)
Definition: utils.c:63
+
char * get_line(const FILE *fp)
+
short * make_pair_table(const char *structure)
Definition: utils.c:258
+
double urn(void)
Definition: utils.c:103
+
void init_rand(void)
Definition: utils.c:89
+
unsigned short xsubi[3]
Definition: utils.c:37
+
int hamming(const char *s1, const char *s2)
Definition: utils.c:162
+
+ + + + diff --git a/src/html/weight_8c.html b/src/html/weight_8c.html new file mode 100644 index 0000000..a663322 --- /dev/null +++ b/src/html/weight_8c.html @@ -0,0 +1,168 @@ + + + + + + + +My Project: weight.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
weight.c File Reference
+
+
+
#include <stdio.h>
+#include <strings.h>
+#include <malloc.h>
+#include <math.h>
+
+Include dependency graph for weight.c:
+
+
+ + +
+
+ + + + + +

+Functions

float * weights (float **D, int N)
 
int linsys (float **a, float *b, int N)
 
+

Function Documentation

+ +

◆ linsys()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int linsys (float ** a,
float * b,
int N 
)
+
+ +
+
+ +

◆ weights()

+ +
+
+ + + + + + + + + + + + + + + + + + +
float* weights (float ** D,
int N 
)
+
+

working arrays

+

call Gauss elimination

+

normalize

+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+
+ + + + diff --git a/src/html/weight_8c__incl.map b/src/html/weight_8c__incl.map new file mode 100644 index 0000000..185cf50 --- /dev/null +++ b/src/html/weight_8c__incl.map @@ -0,0 +1,2 @@ + + diff --git a/src/html/weight_8c__incl.md5 b/src/html/weight_8c__incl.md5 new file mode 100644 index 0000000..cd23efc --- /dev/null +++ b/src/html/weight_8c__incl.md5 @@ -0,0 +1 @@ +d75bb4ff4dc51bc14659ce03ec6fe56f \ No newline at end of file diff --git a/src/html/weight_8c__incl.png b/src/html/weight_8c__incl.png new file mode 100644 index 0000000..3e8e0c8 Binary files /dev/null and b/src/html/weight_8c__incl.png differ diff --git a/src/html/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.map b/src/html/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.map new file mode 100644 index 0000000..df86e25 --- /dev/null +++ b/src/html/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.md5 b/src/html/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.md5 new file mode 100644 index 0000000..0ed4483 --- /dev/null +++ b/src/html/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.md5 @@ -0,0 +1 @@ +d95dbde49ae84e9183d2b4a377b1978d \ No newline at end of file diff --git a/src/html/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.png b/src/html/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.png new file mode 100644 index 0000000..f2cb1aa Binary files /dev/null and b/src/html/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.png differ diff --git a/src/html/weight_8h.html b/src/html/weight_8h.html new file mode 100644 index 0000000..9000f4a --- /dev/null +++ b/src/html/weight_8h.html @@ -0,0 +1,159 @@ + + + + + + + +My Project: weight.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ +
+
+ +
+
weight.h File Reference
+
+
+ +

Go to the source code of this file.

+ + + + + + +

+Functions

int linsys (float **a, float *b, int N)
 
double * weights (float **D, int N)
 
+

Function Documentation

+ +

◆ linsys()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int linsys (float ** a,
float * b,
int N 
)
+
+ +
+
+ +

◆ weights()

+ +
+
+ + + + + + + + + + + + + + + + + + +
double* weights (float ** D,
int N 
)
+
+

working arrays

+

call Gauss elimination

+

normalize

+
+Here is the call graph for this function:
+
+
+ + + +
+ +
+
+
+ + + + diff --git a/src/html/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.map b/src/html/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.map new file mode 100644 index 0000000..df86e25 --- /dev/null +++ b/src/html/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.map @@ -0,0 +1,3 @@ + + + diff --git a/src/html/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.md5 b/src/html/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.md5 new file mode 100644 index 0000000..0ed4483 --- /dev/null +++ b/src/html/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.md5 @@ -0,0 +1 @@ +d95dbde49ae84e9183d2b4a377b1978d \ No newline at end of file diff --git a/src/html/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.png b/src/html/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.png new file mode 100644 index 0000000..f2cb1aa Binary files /dev/null and b/src/html/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.png differ diff --git a/src/html/weight_8h_source.html b/src/html/weight_8h_source.html new file mode 100644 index 0000000..01e7cdb --- /dev/null +++ b/src/html/weight_8h_source.html @@ -0,0 +1,75 @@ + + + + + + + +My Project: weight.h Source File + + + + + + + + + +
+
+ + + + + + +
+
My Project +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
weight.h
+
+
+Go to the documentation of this file.
1 #ifndef _WEIGHT_H_
2 #define _WEIGHT_H_
3 
4 int linsys(float **a, float *b, int N );
5 double *weights(float **D, int N);
6 
7 #endif
double * weights(float **D, int N)
Definition: weight.c:6
+
int linsys(float **a, float *b, int N)
Definition: weight.c:72
+
+ + + + diff --git a/src/latex/Makefile b/src/latex/Makefile new file mode 100644 index 0000000..8cc3866 --- /dev/null +++ b/src/latex/Makefile @@ -0,0 +1,21 @@ +all: refman.pdf + +pdf: refman.pdf + +refman.pdf: clean refman.tex + pdflatex refman + makeindex refman.idx + pdflatex refman + latex_count=8 ; \ + while egrep -s 'Rerun (LaTeX|to get cross-references right)' refman.log && [ $$latex_count -gt 0 ] ;\ + do \ + echo "Rerunning latex...." ;\ + pdflatex refman ;\ + latex_count=`expr $$latex_count - 1` ;\ + done + makeindex refman.idx + pdflatex refman + + +clean: + rm -f *.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log *.out *.brf *.blg *.bbl refman.pdf diff --git a/src/latex/RNAcode_8c.tex b/src/latex/RNAcode_8c.tex new file mode 100644 index 0000000..78b2a5a --- /dev/null +++ b/src/latex/RNAcode_8c.tex @@ -0,0 +1,184 @@ +\hypertarget{RNAcode_8c}{}\section{R\+N\+Acode.\+c File Reference} +\label{RNAcode_8c}\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +{\ttfamily \#include $<$time.\+h$>$}\newline +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include $<$stdlib.\+h$>$}\newline +{\ttfamily \#include $<$string.\+h$>$}\newline +{\ttfamily \#include $<$ctype.\+h$>$}\newline +{\ttfamily \#include $<$math.\+h$>$}\newline +{\ttfamily \#include \char`\"{}R\+N\+Acode.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}rnaz\+\_\+utils.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}tree\+M\+L.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}cmdline.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}code.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}score.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}tree.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}tree\+Simulate.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}extreme\+\_\+fit.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}postscript.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}misc.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}utils.\+h\char`\"{}}\newline +Include dependency graph for R\+N\+Acode.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{RNAcode_8c__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +void \hyperlink{RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c}{free\+Models} (\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models}, int N) +\item +int \hyperlink{RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97}{main} (int argc, char $\ast$argv\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a}{usage} (void) +\item +void \hyperlink{RNAcode_8c_a0bed8474bd33a912769360766f6b10d4}{help} (void) +\item +void \hyperlink{RNAcode_8c_af986bd0575ec9b913dfab4b8422509ae}{version} (void) +\item +void \hyperlink{RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027}{read\+\_\+commandline} (int argc, char $\ast$argv\mbox{[}$\,$\mbox{]}) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +\hyperlink{RNAcode_8h_ac21aeabbefffddb27496994611a09dcd}{parameters} \hyperlink{RNAcode_8c_a8dea3b88a171ed8de9f8f98079e7561a}{pars} +\item +\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$ \hyperlink{RNAcode_8c_a2351b02aa48f9f78d350b4b19408d38f}{models} +\item +\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$ \hyperlink{RNAcode_8c_aa758f546869f82fa894aeeab59fc8a4f}{models\+Rev} +\item +float $\ast$$\ast$$\ast$$\ast$ \hyperlink{RNAcode_8c_a1662932a5f2814e67dfbbd95ab925073}{Sk} +\item +float $\ast$$\ast$$\ast$$\ast$ \hyperlink{RNAcode_8c_a189ec0118947b93b0df1359ab643d3ce}{Sk\+\_\+native} +\item +float $\ast$$\ast$$\ast$$\ast$ \hyperlink{RNAcode_8c_a720f3e09e87f08ee95fd84af1c9c575e}{Sk\+\_\+native\+\_\+rev} +\item +long int \hyperlink{RNAcode_8c_a8c5872fcd4604b525d509ffd6afc5631}{hit\+Counter} +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c}\label{RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!free\+Models@{free\+Models}} +\index{free\+Models@{free\+Models}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{free\+Models()}{freeModels()}} +{\footnotesize\ttfamily void free\+Models (\begin{DoxyParamCaption}\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{models, }\item[{int}]{N }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=274pt]{RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{RNAcode_8c_a0bed8474bd33a912769360766f6b10d4}\label{RNAcode_8c_a0bed8474bd33a912769360766f6b10d4}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!help@{help}} +\index{help@{help}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{help()}{help()}} +{\footnotesize\ttfamily void help (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=258pt]{RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97}\label{RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!main@{main}} +\index{main@{main}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{main()}{main()}} +{\footnotesize\ttfamily int main (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$}]{argv\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[height=550pt]{RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027}\label{RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!read\+\_\+commandline@{read\+\_\+commandline}} +\index{read\+\_\+commandline@{read\+\_\+commandline}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{read\+\_\+commandline()}{read\_commandline()}} +{\footnotesize\ttfamily void read\+\_\+commandline (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$}]{argv\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a}\label{RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!usage@{usage}} +\index{usage@{usage}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{usage()}{usage()}} +{\footnotesize\ttfamily void usage (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=337pt]{RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{RNAcode_8c_af986bd0575ec9b913dfab4b8422509ae}\label{RNAcode_8c_af986bd0575ec9b913dfab4b8422509ae}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!version@{version}} +\index{version@{version}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{version()}{version()}} +{\footnotesize\ttfamily void version (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{RNAcode_8c_a8c5872fcd4604b525d509ffd6afc5631}\label{RNAcode_8c_a8c5872fcd4604b525d509ffd6afc5631}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!hit\+Counter@{hit\+Counter}} +\index{hit\+Counter@{hit\+Counter}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{hit\+Counter}{hitCounter}} +{\footnotesize\ttfamily long int hit\+Counter} + +\mbox{\Hypertarget{RNAcode_8c_a2351b02aa48f9f78d350b4b19408d38f}\label{RNAcode_8c_a2351b02aa48f9f78d350b4b19408d38f}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!models@{models}} +\index{models@{models}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{models}{models}} +{\footnotesize\ttfamily \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model}$\ast$ models} + +\mbox{\Hypertarget{RNAcode_8c_aa758f546869f82fa894aeeab59fc8a4f}\label{RNAcode_8c_aa758f546869f82fa894aeeab59fc8a4f}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!models\+Rev@{models\+Rev}} +\index{models\+Rev@{models\+Rev}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{models\+Rev}{modelsRev}} +{\footnotesize\ttfamily \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$ models\+Rev} + +\mbox{\Hypertarget{RNAcode_8c_a8dea3b88a171ed8de9f8f98079e7561a}\label{RNAcode_8c_a8dea3b88a171ed8de9f8f98079e7561a}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!pars@{pars}} +\index{pars@{pars}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{pars}{pars}} +{\footnotesize\ttfamily \hyperlink{RNAcode_8h_ac21aeabbefffddb27496994611a09dcd}{parameters} pars} + +\mbox{\Hypertarget{RNAcode_8c_a1662932a5f2814e67dfbbd95ab925073}\label{RNAcode_8c_a1662932a5f2814e67dfbbd95ab925073}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!Sk@{Sk}} +\index{Sk@{Sk}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{Sk}{Sk}} +{\footnotesize\ttfamily float$\ast$$\ast$$\ast$$\ast$ Sk} + +\mbox{\Hypertarget{RNAcode_8c_a189ec0118947b93b0df1359ab643d3ce}\label{RNAcode_8c_a189ec0118947b93b0df1359ab643d3ce}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!Sk\+\_\+native@{Sk\+\_\+native}} +\index{Sk\+\_\+native@{Sk\+\_\+native}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{Sk\+\_\+native}{Sk\_native}} +{\footnotesize\ttfamily float$\ast$$\ast$$\ast$$\ast$ Sk\+\_\+native} + +\mbox{\Hypertarget{RNAcode_8c_a720f3e09e87f08ee95fd84af1c9c575e}\label{RNAcode_8c_a720f3e09e87f08ee95fd84af1c9c575e}} +\index{R\+N\+Acode.\+c@{R\+N\+Acode.\+c}!Sk\+\_\+native\+\_\+rev@{Sk\+\_\+native\+\_\+rev}} +\index{Sk\+\_\+native\+\_\+rev@{Sk\+\_\+native\+\_\+rev}!R\+N\+Acode.\+c@{R\+N\+Acode.\+c}} +\subsubsection{\texorpdfstring{Sk\+\_\+native\+\_\+rev}{Sk\_native\_rev}} +{\footnotesize\ttfamily float$\ast$$\ast$$\ast$$\ast$ Sk\+\_\+native\+\_\+rev} + diff --git a/src/latex/RNAcode_8c__incl.md5 b/src/latex/RNAcode_8c__incl.md5 new file mode 100644 index 0000000..b85434f --- /dev/null +++ b/src/latex/RNAcode_8c__incl.md5 @@ -0,0 +1 @@ +0bb30de58620df4f3a4aa11f28beb1ee \ No newline at end of file diff --git a/src/latex/RNAcode_8c__incl.pdf b/src/latex/RNAcode_8c__incl.pdf new file mode 100644 index 0000000..b90aa68 Binary files /dev/null and b/src/latex/RNAcode_8c__incl.pdf differ diff --git a/src/latex/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 b/src/latex/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 new file mode 100644 index 0000000..d4438c8 --- /dev/null +++ b/src/latex/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 @@ -0,0 +1 @@ +e22c27e265a64022a79600dc5e880355 \ No newline at end of file diff --git a/src/latex/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.pdf b/src/latex/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.pdf new file mode 100644 index 0000000..4901876 Binary files /dev/null and b/src/latex/RNAcode_8c_a0bed8474bd33a912769360766f6b10d4_cgraph.pdf differ diff --git a/src/latex/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.md5 b/src/latex/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.md5 new file mode 100644 index 0000000..ea6b462 --- /dev/null +++ b/src/latex/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.md5 @@ -0,0 +1 @@ +f329bfb7b97a6fe43bb195f2a63eeb34 \ No newline at end of file diff --git a/src/latex/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.pdf b/src/latex/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.pdf new file mode 100644 index 0000000..97d6201 Binary files /dev/null and b/src/latex/RNAcode_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.pdf differ diff --git a/src/latex/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 b/src/latex/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 new file mode 100644 index 0000000..b02ae00 --- /dev/null +++ b/src/latex/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 @@ -0,0 +1 @@ +1ed039c6d019e84398270f3e0b76415d \ No newline at end of file diff --git a/src/latex/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.pdf b/src/latex/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.pdf new file mode 100644 index 0000000..ffa9455 Binary files /dev/null and b/src/latex/RNAcode_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.pdf differ diff --git a/src/latex/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 b/src/latex/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 new file mode 100644 index 0000000..025250b --- /dev/null +++ b/src/latex/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 @@ -0,0 +1 @@ +fa09640974220e8cfffab1344cc9c587 \ No newline at end of file diff --git a/src/latex/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.pdf b/src/latex/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.pdf new file mode 100644 index 0000000..4224f1e Binary files /dev/null and b/src/latex/RNAcode_8c_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.pdf differ diff --git a/src/latex/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 b/src/latex/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 new file mode 100644 index 0000000..c06103f --- /dev/null +++ b/src/latex/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 @@ -0,0 +1 @@ +69e4e1ebff7e8088a116d69dba8c81b6 \ No newline at end of file diff --git a/src/latex/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.pdf b/src/latex/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.pdf new file mode 100644 index 0000000..ea4e93a Binary files /dev/null and b/src/latex/RNAcode_8c_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.pdf differ diff --git a/src/latex/RNAcode_8h.tex b/src/latex/RNAcode_8h.tex new file mode 100644 index 0000000..0b2968d --- /dev/null +++ b/src/latex/RNAcode_8h.tex @@ -0,0 +1,91 @@ +\hypertarget{RNAcode_8h}{}\section{R\+N\+Acode.\+h File Reference} +\label{RNAcode_8h}\index{R\+N\+Acode.\+h@{R\+N\+Acode.\+h}} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=280pt]{RNAcode_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Classes} +\begin{DoxyCompactItemize} +\item +struct \hyperlink{struct__parameters}{\+\_\+parameters} +\end{DoxyCompactItemize} +\subsection*{Typedefs} +\begin{DoxyCompactItemize} +\item +typedef struct \hyperlink{struct__parameters}{\+\_\+parameters} \hyperlink{RNAcode_8h_ac21aeabbefffddb27496994611a09dcd}{parameters} +\end{DoxyCompactItemize} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +void \hyperlink{RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a}{usage} (void) +\item +void \hyperlink{RNAcode_8h_a0bed8474bd33a912769360766f6b10d4}{help} (void) +\item +void \hyperlink{RNAcode_8h_af986bd0575ec9b913dfab4b8422509ae}{version} (void) +\item +void \hyperlink{RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027}{read\+\_\+commandline} (int argc, char $\ast$argv\mbox{[}$\,$\mbox{]}) +\end{DoxyCompactItemize} + + +\subsection{Typedef Documentation} +\mbox{\Hypertarget{RNAcode_8h_ac21aeabbefffddb27496994611a09dcd}\label{RNAcode_8h_ac21aeabbefffddb27496994611a09dcd}} +\index{R\+N\+Acode.\+h@{R\+N\+Acode.\+h}!parameters@{parameters}} +\index{parameters@{parameters}!R\+N\+Acode.\+h@{R\+N\+Acode.\+h}} +\subsubsection{\texorpdfstring{parameters}{parameters}} +{\footnotesize\ttfamily typedef struct \hyperlink{struct__parameters}{\+\_\+parameters} \hyperlink{RNAcode_8h_ac21aeabbefffddb27496994611a09dcd}{parameters}} + + + +\subsection{Function Documentation} +\mbox{\Hypertarget{RNAcode_8h_a0bed8474bd33a912769360766f6b10d4}\label{RNAcode_8h_a0bed8474bd33a912769360766f6b10d4}} +\index{R\+N\+Acode.\+h@{R\+N\+Acode.\+h}!help@{help}} +\index{help@{help}!R\+N\+Acode.\+h@{R\+N\+Acode.\+h}} +\subsubsection{\texorpdfstring{help()}{help()}} +{\footnotesize\ttfamily void help (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=258pt]{RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027}\label{RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027}} +\index{R\+N\+Acode.\+h@{R\+N\+Acode.\+h}!read\+\_\+commandline@{read\+\_\+commandline}} +\index{read\+\_\+commandline@{read\+\_\+commandline}!R\+N\+Acode.\+h@{R\+N\+Acode.\+h}} +\subsubsection{\texorpdfstring{read\+\_\+commandline()}{read\_commandline()}} +{\footnotesize\ttfamily void read\+\_\+commandline (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$}]{argv\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a}\label{RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a}} +\index{R\+N\+Acode.\+h@{R\+N\+Acode.\+h}!usage@{usage}} +\index{usage@{usage}!R\+N\+Acode.\+h@{R\+N\+Acode.\+h}} +\subsubsection{\texorpdfstring{usage()}{usage()}} +{\footnotesize\ttfamily void usage (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=337pt]{RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{RNAcode_8h_af986bd0575ec9b913dfab4b8422509ae}\label{RNAcode_8h_af986bd0575ec9b913dfab4b8422509ae}} +\index{R\+N\+Acode.\+h@{R\+N\+Acode.\+h}!version@{version}} +\index{version@{version}!R\+N\+Acode.\+h@{R\+N\+Acode.\+h}} +\subsubsection{\texorpdfstring{version()}{version()}} +{\footnotesize\ttfamily void version (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + diff --git a/src/latex/RNAcode_8h__dep__incl.md5 b/src/latex/RNAcode_8h__dep__incl.md5 new file mode 100644 index 0000000..535a02d --- /dev/null +++ b/src/latex/RNAcode_8h__dep__incl.md5 @@ -0,0 +1 @@ +e68b84c401881ad261c34773815a9158 \ No newline at end of file diff --git a/src/latex/RNAcode_8h__dep__incl.pdf b/src/latex/RNAcode_8h__dep__incl.pdf new file mode 100644 index 0000000..2e042c9 Binary files /dev/null and b/src/latex/RNAcode_8h__dep__incl.pdf differ diff --git a/src/latex/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 b/src/latex/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 new file mode 100644 index 0000000..4a19580 --- /dev/null +++ b/src/latex/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.md5 @@ -0,0 +1 @@ +b42e6856b380c5ef270fdc47ceb5af46 \ No newline at end of file diff --git a/src/latex/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.pdf b/src/latex/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.pdf new file mode 100644 index 0000000..4901876 Binary files /dev/null and b/src/latex/RNAcode_8h_a0bed8474bd33a912769360766f6b10d4_cgraph.pdf differ diff --git a/src/latex/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 b/src/latex/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 new file mode 100644 index 0000000..b63f4a5 --- /dev/null +++ b/src/latex/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.md5 @@ -0,0 +1 @@ +f30f11f6636c2c3572cb99fba0546208 \ No newline at end of file diff --git a/src/latex/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.pdf b/src/latex/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.pdf new file mode 100644 index 0000000..4224f1e Binary files /dev/null and b/src/latex/RNAcode_8h_ae36ab4408b3aaada4218ac5f60ea6027_cgraph.pdf differ diff --git a/src/latex/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 b/src/latex/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 new file mode 100644 index 0000000..a4abf12 --- /dev/null +++ b/src/latex/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.md5 @@ -0,0 +1 @@ +88cd4cc37d168a573e38dd26ea28f70b \ No newline at end of file diff --git a/src/latex/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.pdf b/src/latex/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.pdf new file mode 100644 index 0000000..ea4e93a Binary files /dev/null and b/src/latex/RNAcode_8h_ae8605e2b78cd4a81b6c6b5c30cb7366a_cgraph.pdf differ diff --git a/src/latex/annotated.tex b/src/latex/annotated.tex new file mode 100644 index 0000000..22e496c --- /dev/null +++ b/src/latex/annotated.tex @@ -0,0 +1,11 @@ +\section{Class List} +Here are the classes, structs, unions and interfaces with brief descriptions\+:\begin{DoxyCompactList} +\item\contentsline{section}{\hyperlink{struct__backtrackData}{\+\_\+backtrack\+Data} }{\pageref{struct__backtrackData}}{} +\item\contentsline{section}{\hyperlink{struct__bgModel}{\+\_\+bg\+Model} }{\pageref{struct__bgModel}}{} +\item\contentsline{section}{\hyperlink{struct__parameters}{\+\_\+parameters} }{\pageref{struct__parameters}}{} +\item\contentsline{section}{\hyperlink{struct__segmentStats}{\+\_\+segment\+Stats} }{\pageref{struct__segmentStats}}{} +\item\contentsline{section}{\hyperlink{structaln}{aln} }{\pageref{structaln}}{} +\item\contentsline{section}{\hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} \\*The additional parameters to pass to parser functions }{\pageref{structcmdline__parser__params}}{} +\item\contentsline{section}{\hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} \\*Where the command line options are stored }{\pageref{structgengetopt__args__info}}{} +\item\contentsline{section}{\hyperlink{structoption}{option} }{\pageref{structoption}}{} +\end{DoxyCompactList} diff --git a/src/latex/cmdline_8c.tex b/src/latex/cmdline_8c.tex new file mode 100644 index 0000000..4765c1f --- /dev/null +++ b/src/latex/cmdline_8c.tex @@ -0,0 +1,574 @@ +\hypertarget{cmdline_8c}{}\section{cmdline.\+c File Reference} +\label{cmdline_8c}\index{cmdline.\+c@{cmdline.\+c}} +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include $<$stdlib.\+h$>$}\newline +{\ttfamily \#include $<$string.\+h$>$}\newline +{\ttfamily \#include \char`\"{}getopt.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}cmdline.\+h\char`\"{}}\newline +Include dependency graph for cmdline.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8c__incl} +\end{center} +\end{figure} +\subsection*{Enumerations} +\begin{DoxyCompactItemize} +\item +enum \hyperlink{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1}{cmdline\+\_\+parser\+\_\+arg\+\_\+type} \{ \newline +\hyperlink{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a67dd250fb3e23862523b667407868ada}{A\+R\+G\+\_\+\+NO}, +\hyperlink{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1afd135f03243c33991ef507f4410718f7}{A\+R\+G\+\_\+\+F\+L\+AG}, +\hyperlink{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a1e0904ee5e3baf2aa4070ab0718a3afa}{A\+R\+G\+\_\+\+S\+T\+R\+I\+NG}, +\hyperlink{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a58393752406d163205fa18f450909993}{A\+R\+G\+\_\+\+I\+NT}, +\newline +\hyperlink{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a5875de3e892eb32ed41e4d60ef7d99ca}{A\+R\+G\+\_\+\+F\+L\+O\+AT} + \} +\end{DoxyCompactItemize} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +static void \hyperlink{cmdline_8c_a48968b912c47767e9f057f5bc11634cb}{clear\+\_\+given} (struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +static void \hyperlink{cmdline_8c_a4d7018864f814395754ea4127ce4d37b}{clear\+\_\+args} (struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +static int \hyperlink{cmdline_8c_aaba43e1bb216c68c96e982c600c906a7}{cmdline\+\_\+parser\+\_\+internal} (int argc, char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$argv, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info, struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$params, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$additional\+\_\+error) +\item +static char $\ast$ \hyperlink{cmdline_8c_a0ec9efd6eb3e6e939fcaaadd8b4c6a9f}{gengetopt\+\_\+strdup} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$s) +\begin{DoxyCompactList}\small\item\em replacement of strdup, which is not standard \end{DoxyCompactList}\item +static void \hyperlink{cmdline_8c_a4dcfd361cdaac143739a02102296fedd}{init\+\_\+args\+\_\+info} (struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +void \hyperlink{cmdline_8c_a96f27bf35ce0ab8eea7a1f6e6b59a5e2}{cmdline\+\_\+parser\+\_\+print\+\_\+version} (void) +\item +static void \hyperlink{cmdline_8c_ad600bb9026825a295ea57df22bdf7eca}{print\+\_\+help\+\_\+common} (void) +\item +void \hyperlink{cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492}{cmdline\+\_\+parser\+\_\+print\+\_\+help} (void) +\item +void \hyperlink{cmdline_8c_aca62b50d03d0d082968eeb1940f98650}{cmdline\+\_\+parser\+\_\+init} (struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +void \hyperlink{cmdline_8c_af72b814611cffc706b2135ccdfe7e997}{cmdline\+\_\+parser\+\_\+params\+\_\+init} (struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$params) +\item +struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$ \hyperlink{cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92}{cmdline\+\_\+parser\+\_\+params\+\_\+create} (void) +\item +static void \hyperlink{cmdline_8c_a3a3cc8b020811185cb0a4b96e1ff5a40}{free\+\_\+string\+\_\+field} (char $\ast$$\ast$s) +\item +static void \hyperlink{cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a}{cmdline\+\_\+parser\+\_\+release} (struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +static void \hyperlink{cmdline_8c_a332041b3060103618ef6b767ab32d0dd}{write\+\_\+into\+\_\+file} (F\+I\+LE $\ast$\hyperlink{postscript_8c_ae581849c67336453bd5b81e6518019a9}{outfile}, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$opt, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$arg, char $\ast$values\mbox{[}$\,$\mbox{]}) +\item +int \hyperlink{cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11}{cmdline\+\_\+parser\+\_\+dump} (F\+I\+LE $\ast$\hyperlink{postscript_8c_ae581849c67336453bd5b81e6518019a9}{outfile}, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +int \hyperlink{cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818}{cmdline\+\_\+parser\+\_\+file\+\_\+save} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$filename, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +void \hyperlink{cmdline_8c_af1b97c4e92b88f736e350b3902266ba4}{cmdline\+\_\+parser\+\_\+free} (struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +int \hyperlink{cmdline_8c_a96f1044799c552f3ee139f9b1387b363}{cmdline\+\_\+parser} (int argc, char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$argv, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +int \hyperlink{cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38}{cmdline\+\_\+parser\+\_\+ext} (int argc, char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$argv, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info, struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$params) +\item +int \hyperlink{cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7}{cmdline\+\_\+parser2} (int argc, char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$argv, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info, int override, int initialize, int check\+\_\+required) +\item +int \hyperlink{cmdline_8c_a83651e5be280d60aed58fdb72456a030}{cmdline\+\_\+parser\+\_\+required} (struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$prog\+\_\+name) +\item +static int \hyperlink{cmdline_8c_a21d8824d410efa489c4921011c1c0765}{update\+\_\+arg} (void $\ast$field, char $\ast$$\ast$orig\+\_\+field, unsigned int $\ast$field\+\_\+given, unsigned int $\ast$prev\+\_\+given, char $\ast$value, char $\ast$possible\+\_\+values\mbox{[}$\,$\mbox{]}, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$default\+\_\+value, \hyperlink{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1}{cmdline\+\_\+parser\+\_\+arg\+\_\+type} arg\+\_\+type, int check\+\_\+ambiguity, int override, int no\+\_\+free, int multiple\+\_\+option, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$long\+\_\+opt, char short\+\_\+opt, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$additional\+\_\+error) +\begin{DoxyCompactList}\small\item\em updates an option \end{DoxyCompactList}\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{cmdline_8c_a610c3307abce5a8fd304b86b018ae60b}{gengetopt\+\_\+args\+\_\+info\+\_\+purpose} = \char`\"{}\char`\"{} +\begin{DoxyCompactList}\small\item\em the purpose string of the program \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{cmdline_8c_a9f397a306f363bfdebb611e86acf36d5}{gengetopt\+\_\+args\+\_\+info\+\_\+usage} = \char`\"{}Usage\+: \char`\"{} C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+P\+A\+C\+K\+A\+GE \char`\"{} \mbox{[}O\+P\+T\+I\+O\+NS\mbox{]}... \mbox{[}F\+I\+L\+ES\mbox{]}...\char`\"{} +\begin{DoxyCompactList}\small\item\em the usage string of the program \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{cmdline_8c_accad6107ca685f6eba555f6ce63d355d}{gengetopt\+\_\+args\+\_\+info\+\_\+description} = \char`\"{}\char`\"{} +\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{cmdline_8c_a6af7a6b7fb37c0abaa916ee1cfa0a41f}{gengetopt\+\_\+args\+\_\+info\+\_\+help} \mbox{[}$\,$\mbox{]} +\begin{DoxyCompactList}\small\item\em all the lines making the help output \end{DoxyCompactList}\item +static char $\ast$ \hyperlink{cmdline_8c_a08f16a026de44b77c5e7be490fb9e32b}{package\+\_\+name} = 0 +\end{DoxyCompactItemize} + + +\subsection{Enumeration Type Documentation} +\mbox{\Hypertarget{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1}\label{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+arg\+\_\+type@{cmdline\+\_\+parser\+\_\+arg\+\_\+type}} +\index{cmdline\+\_\+parser\+\_\+arg\+\_\+type@{cmdline\+\_\+parser\+\_\+arg\+\_\+type}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+arg\+\_\+type}{cmdline\_parser\_arg\_type}} +{\footnotesize\ttfamily enum \hyperlink{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1}{cmdline\+\_\+parser\+\_\+arg\+\_\+type}} + +\begin{DoxyEnumFields}{Enumerator} +\raisebox{\heightof{T}}[0pt][0pt]{\index{A\+R\+G\+\_\+\+NO@{A\+R\+G\+\_\+\+NO}!cmdline.\+c@{cmdline.\+c}}\index{cmdline.\+c@{cmdline.\+c}!A\+R\+G\+\_\+\+NO@{A\+R\+G\+\_\+\+NO}}}\mbox{\Hypertarget{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a67dd250fb3e23862523b667407868ada}\label{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a67dd250fb3e23862523b667407868ada}} +A\+R\+G\+\_\+\+NO&\\ +\hline + +\raisebox{\heightof{T}}[0pt][0pt]{\index{A\+R\+G\+\_\+\+F\+L\+AG@{A\+R\+G\+\_\+\+F\+L\+AG}!cmdline.\+c@{cmdline.\+c}}\index{cmdline.\+c@{cmdline.\+c}!A\+R\+G\+\_\+\+F\+L\+AG@{A\+R\+G\+\_\+\+F\+L\+AG}}}\mbox{\Hypertarget{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1afd135f03243c33991ef507f4410718f7}\label{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1afd135f03243c33991ef507f4410718f7}} +A\+R\+G\+\_\+\+F\+L\+AG&\\ +\hline + +\raisebox{\heightof{T}}[0pt][0pt]{\index{A\+R\+G\+\_\+\+S\+T\+R\+I\+NG@{A\+R\+G\+\_\+\+S\+T\+R\+I\+NG}!cmdline.\+c@{cmdline.\+c}}\index{cmdline.\+c@{cmdline.\+c}!A\+R\+G\+\_\+\+S\+T\+R\+I\+NG@{A\+R\+G\+\_\+\+S\+T\+R\+I\+NG}}}\mbox{\Hypertarget{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a1e0904ee5e3baf2aa4070ab0718a3afa}\label{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a1e0904ee5e3baf2aa4070ab0718a3afa}} +A\+R\+G\+\_\+\+S\+T\+R\+I\+NG&\\ +\hline + +\raisebox{\heightof{T}}[0pt][0pt]{\index{A\+R\+G\+\_\+\+I\+NT@{A\+R\+G\+\_\+\+I\+NT}!cmdline.\+c@{cmdline.\+c}}\index{cmdline.\+c@{cmdline.\+c}!A\+R\+G\+\_\+\+I\+NT@{A\+R\+G\+\_\+\+I\+NT}}}\mbox{\Hypertarget{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a58393752406d163205fa18f450909993}\label{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a58393752406d163205fa18f450909993}} +A\+R\+G\+\_\+\+I\+NT&\\ +\hline + +\raisebox{\heightof{T}}[0pt][0pt]{\index{A\+R\+G\+\_\+\+F\+L\+O\+AT@{A\+R\+G\+\_\+\+F\+L\+O\+AT}!cmdline.\+c@{cmdline.\+c}}\index{cmdline.\+c@{cmdline.\+c}!A\+R\+G\+\_\+\+F\+L\+O\+AT@{A\+R\+G\+\_\+\+F\+L\+O\+AT}}}\mbox{\Hypertarget{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a5875de3e892eb32ed41e4d60ef7d99ca}\label{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1a5875de3e892eb32ed41e4d60ef7d99ca}} +A\+R\+G\+\_\+\+F\+L\+O\+AT&\\ +\hline + +\end{DoxyEnumFields} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{cmdline_8c_a4d7018864f814395754ea4127ce4d37b}\label{cmdline_8c_a4d7018864f814395754ea4127ce4d37b}} +\index{cmdline.\+c@{cmdline.\+c}!clear\+\_\+args@{clear\+\_\+args}} +\index{clear\+\_\+args@{clear\+\_\+args}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{clear\+\_\+args()}{clear\_args()}} +{\footnotesize\ttfamily static void clear\+\_\+args (\begin{DoxyParamCaption}\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + +\mbox{\Hypertarget{cmdline_8c_a48968b912c47767e9f057f5bc11634cb}\label{cmdline_8c_a48968b912c47767e9f057f5bc11634cb}} +\index{cmdline.\+c@{cmdline.\+c}!clear\+\_\+given@{clear\+\_\+given}} +\index{clear\+\_\+given@{clear\+\_\+given}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{clear\+\_\+given()}{clear\_given()}} +{\footnotesize\ttfamily static void clear\+\_\+given (\begin{DoxyParamCaption}\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + +\mbox{\Hypertarget{cmdline_8c_a96f1044799c552f3ee139f9b1387b363}\label{cmdline_8c_a96f1044799c552f3ee139f9b1387b363}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser@{cmdline\+\_\+parser}} +\index{cmdline\+\_\+parser@{cmdline\+\_\+parser}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser()}{cmdline\_parser()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$}]{argv, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})} + +The command line parser +\begin{DoxyParams}{Parameters} +{\em argc} & the number of command line options \\ +\hline +{\em argv} & the command line options \\ +\hline +{\em args\+\_\+info} & the structure where option information will be stored \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} +0 if everything went fine, N\+ON 0 if an error took place +\end{DoxyReturn} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7}\label{cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser2@{cmdline\+\_\+parser2}} +\index{cmdline\+\_\+parser2@{cmdline\+\_\+parser2}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser2()}{cmdline\_parser2()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser2 (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$}]{argv, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info, }\item[{int}]{override, }\item[{int}]{initialize, }\item[{int}]{check\+\_\+required }\end{DoxyParamCaption})} + +The command line parser (version with additional parameters -\/ deprecated) +\begin{DoxyParams}{Parameters} +{\em argc} & the number of command line options \\ +\hline +{\em argv} & the command line options \\ +\hline +{\em args\+\_\+info} & the structure where option information will be stored \\ +\hline +{\em override} & whether to override possibly already present options \\ +\hline +{\em initialize} & whether to initialize the option structure my\+\_\+args\+\_\+info \\ +\hline +{\em check\+\_\+required} & whether to check that all required options were provided \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} +0 if everything went fine, N\+ON 0 if an error took place +\end{DoxyReturn} +\begin{DoxyRefDesc}{Deprecated} +\item[\hyperlink{deprecated__deprecated000001}{Deprecated}]use \hyperlink{cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38}{cmdline\+\_\+parser\+\_\+ext()} instead \end{DoxyRefDesc} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11}\label{cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+dump@{cmdline\+\_\+parser\+\_\+dump}} +\index{cmdline\+\_\+parser\+\_\+dump@{cmdline\+\_\+parser\+\_\+dump}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+dump()}{cmdline\_parser\_dump()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+dump (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{outfile, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})} + +Save the contents of the option struct into an already open F\+I\+LE stream. +\begin{DoxyParams}{Parameters} +{\em outfile} & the stream where to dump options \\ +\hline +{\em args\+\_\+info} & the option struct to dump \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} +0 if everything went fine, N\+ON 0 if an error took place +\end{DoxyReturn} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=305pt]{cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38}\label{cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+ext@{cmdline\+\_\+parser\+\_\+ext}} +\index{cmdline\+\_\+parser\+\_\+ext@{cmdline\+\_\+parser\+\_\+ext}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+ext()}{cmdline\_parser\_ext()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+ext (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$}]{argv, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info, }\item[{struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$}]{params }\end{DoxyParamCaption})} + +The command line parser (version with additional parameters) +\begin{DoxyParams}{Parameters} +{\em argc} & the number of command line options \\ +\hline +{\em argv} & the command line options \\ +\hline +{\em args\+\_\+info} & the structure where option information will be stored \\ +\hline +{\em params} & additional parameters for the parser \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} +0 if everything went fine, N\+ON 0 if an error took place +\end{DoxyReturn} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818}\label{cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+file\+\_\+save@{cmdline\+\_\+parser\+\_\+file\+\_\+save}} +\index{cmdline\+\_\+parser\+\_\+file\+\_\+save@{cmdline\+\_\+parser\+\_\+file\+\_\+save}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+file\+\_\+save()}{cmdline\_parser\_file\_save()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+file\+\_\+save (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{filename, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})} + +Save the contents of the option struct into a (text) file. This file can be read by the config file parser (if generated by gengetopt) +\begin{DoxyParams}{Parameters} +{\em filename} & the file where to save \\ +\hline +{\em args\+\_\+info} & the option struct to save \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} +0 if everything went fine, N\+ON 0 if an error took place +\end{DoxyReturn} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_af1b97c4e92b88f736e350b3902266ba4}\label{cmdline_8c_af1b97c4e92b88f736e350b3902266ba4}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+free@{cmdline\+\_\+parser\+\_\+free}} +\index{cmdline\+\_\+parser\+\_\+free@{cmdline\+\_\+parser\+\_\+free}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+free()}{cmdline\_parser\_free()}} +{\footnotesize\ttfamily void cmdline\+\_\+parser\+\_\+free (\begin{DoxyParamCaption}\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})} + +Deallocates the string fields of the \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} structure (but does not deallocate the structure itself) +\begin{DoxyParams}{Parameters} +{\em args\+\_\+info} & the structure to deallocate \\ +\hline +\end{DoxyParams} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_aca62b50d03d0d082968eeb1940f98650}\label{cmdline_8c_aca62b50d03d0d082968eeb1940f98650}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+init@{cmdline\+\_\+parser\+\_\+init}} +\index{cmdline\+\_\+parser\+\_\+init@{cmdline\+\_\+parser\+\_\+init}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+init()}{cmdline\_parser\_init()}} +{\footnotesize\ttfamily void cmdline\+\_\+parser\+\_\+init (\begin{DoxyParamCaption}\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})} + +Initializes the passed \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} structure\textquotesingle{}s fields (also set default values for options that have a default) +\begin{DoxyParams}{Parameters} +{\em args\+\_\+info} & the structure to initialize \\ +\hline +\end{DoxyParams} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=291pt]{cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_aaba43e1bb216c68c96e982c600c906a7}\label{cmdline_8c_aaba43e1bb216c68c96e982c600c906a7}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+internal@{cmdline\+\_\+parser\+\_\+internal}} +\index{cmdline\+\_\+parser\+\_\+internal@{cmdline\+\_\+parser\+\_\+internal}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+internal()}{cmdline\_parser\_internal()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+internal (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$}]{argv, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info, }\item[{struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$}]{params, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{additional\+\_\+error }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92}\label{cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+params\+\_\+create@{cmdline\+\_\+parser\+\_\+params\+\_\+create}} +\index{cmdline\+\_\+parser\+\_\+params\+\_\+create@{cmdline\+\_\+parser\+\_\+params\+\_\+create}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+params\+\_\+create()}{cmdline\_parser\_params\_create()}} +{\footnotesize\ttfamily struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params}$\ast$ cmdline\+\_\+parser\+\_\+params\+\_\+create (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +Allocates dynamically a \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} structure and initializes all its fields to their default values \begin{DoxyReturn}{Returns} +the created and initialized \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} structure +\end{DoxyReturn} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_af72b814611cffc706b2135ccdfe7e997}\label{cmdline_8c_af72b814611cffc706b2135ccdfe7e997}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+params\+\_\+init@{cmdline\+\_\+parser\+\_\+params\+\_\+init}} +\index{cmdline\+\_\+parser\+\_\+params\+\_\+init@{cmdline\+\_\+parser\+\_\+params\+\_\+init}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+params\+\_\+init()}{cmdline\_parser\_params\_init()}} +{\footnotesize\ttfamily void cmdline\+\_\+parser\+\_\+params\+\_\+init (\begin{DoxyParamCaption}\item[{struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$}]{params }\end{DoxyParamCaption})} + +Initializes all the fields a \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} structure to their default values +\begin{DoxyParams}{Parameters} +{\em params} & the structure to initialize \\ +\hline +\end{DoxyParams} +\mbox{\Hypertarget{cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492}\label{cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+print\+\_\+help@{cmdline\+\_\+parser\+\_\+print\+\_\+help}} +\index{cmdline\+\_\+parser\+\_\+print\+\_\+help@{cmdline\+\_\+parser\+\_\+print\+\_\+help}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+print\+\_\+help()}{cmdline\_parser\_print\_help()}} +{\footnotesize\ttfamily void cmdline\+\_\+parser\+\_\+print\+\_\+help (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +Print the help Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_a96f27bf35ce0ab8eea7a1f6e6b59a5e2}\label{cmdline_8c_a96f27bf35ce0ab8eea7a1f6e6b59a5e2}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+print\+\_\+version@{cmdline\+\_\+parser\+\_\+print\+\_\+version}} +\index{cmdline\+\_\+parser\+\_\+print\+\_\+version@{cmdline\+\_\+parser\+\_\+print\+\_\+version}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+print\+\_\+version()}{cmdline\_parser\_print\_version()}} +{\footnotesize\ttfamily void cmdline\+\_\+parser\+\_\+print\+\_\+version (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +Print the version \mbox{\Hypertarget{cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a}\label{cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+release@{cmdline\+\_\+parser\+\_\+release}} +\index{cmdline\+\_\+parser\+\_\+release@{cmdline\+\_\+parser\+\_\+release}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+release()}{cmdline\_parser\_release()}} +{\footnotesize\ttfamily static void cmdline\+\_\+parser\+\_\+release (\begin{DoxyParamCaption}\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=321pt]{cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_a83651e5be280d60aed58fdb72456a030}\label{cmdline_8c_a83651e5be280d60aed58fdb72456a030}} +\index{cmdline.\+c@{cmdline.\+c}!cmdline\+\_\+parser\+\_\+required@{cmdline\+\_\+parser\+\_\+required}} +\index{cmdline\+\_\+parser\+\_\+required@{cmdline\+\_\+parser\+\_\+required}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+required()}{cmdline\_parser\_required()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+required (\begin{DoxyParamCaption}\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{prog\+\_\+name }\end{DoxyParamCaption})} + +Checks that all the required options were specified +\begin{DoxyParams}{Parameters} +{\em args\+\_\+info} & the structure to check \\ +\hline +{\em prog\+\_\+name} & the name of the program that will be used to print possible errors \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} + +\end{DoxyReturn} +\mbox{\Hypertarget{cmdline_8c_a3a3cc8b020811185cb0a4b96e1ff5a40}\label{cmdline_8c_a3a3cc8b020811185cb0a4b96e1ff5a40}} +\index{cmdline.\+c@{cmdline.\+c}!free\+\_\+string\+\_\+field@{free\+\_\+string\+\_\+field}} +\index{free\+\_\+string\+\_\+field@{free\+\_\+string\+\_\+field}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{free\+\_\+string\+\_\+field()}{free\_string\_field()}} +{\footnotesize\ttfamily static void free\+\_\+string\+\_\+field (\begin{DoxyParamCaption}\item[{char $\ast$$\ast$}]{s }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + +\mbox{\Hypertarget{cmdline_8c_a0ec9efd6eb3e6e939fcaaadd8b4c6a9f}\label{cmdline_8c_a0ec9efd6eb3e6e939fcaaadd8b4c6a9f}} +\index{cmdline.\+c@{cmdline.\+c}!gengetopt\+\_\+strdup@{gengetopt\+\_\+strdup}} +\index{gengetopt\+\_\+strdup@{gengetopt\+\_\+strdup}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{gengetopt\+\_\+strdup()}{gengetopt\_strdup()}} +{\footnotesize\ttfamily char $\ast$ gengetopt\+\_\+strdup (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{s }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + + + +replacement of strdup, which is not standard + +\mbox{\Hypertarget{cmdline_8c_a4dcfd361cdaac143739a02102296fedd}\label{cmdline_8c_a4dcfd361cdaac143739a02102296fedd}} +\index{cmdline.\+c@{cmdline.\+c}!init\+\_\+args\+\_\+info@{init\+\_\+args\+\_\+info}} +\index{init\+\_\+args\+\_\+info@{init\+\_\+args\+\_\+info}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{init\+\_\+args\+\_\+info()}{init\_args\_info()}} +{\footnotesize\ttfamily static void init\+\_\+args\+\_\+info (\begin{DoxyParamCaption}\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + +\mbox{\Hypertarget{cmdline_8c_ad600bb9026825a295ea57df22bdf7eca}\label{cmdline_8c_ad600bb9026825a295ea57df22bdf7eca}} +\index{cmdline.\+c@{cmdline.\+c}!print\+\_\+help\+\_\+common@{print\+\_\+help\+\_\+common}} +\index{print\+\_\+help\+\_\+common@{print\+\_\+help\+\_\+common}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{print\+\_\+help\+\_\+common()}{print\_help\_common()}} +{\footnotesize\ttfamily static void print\+\_\+help\+\_\+common (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=324pt]{cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_a21d8824d410efa489c4921011c1c0765}\label{cmdline_8c_a21d8824d410efa489c4921011c1c0765}} +\index{cmdline.\+c@{cmdline.\+c}!update\+\_\+arg@{update\+\_\+arg}} +\index{update\+\_\+arg@{update\+\_\+arg}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{update\+\_\+arg()}{update\_arg()}} +{\footnotesize\ttfamily static int update\+\_\+arg (\begin{DoxyParamCaption}\item[{void $\ast$}]{field, }\item[{char $\ast$$\ast$}]{orig\+\_\+field, }\item[{unsigned int $\ast$}]{field\+\_\+given, }\item[{unsigned int $\ast$}]{prev\+\_\+given, }\item[{char $\ast$}]{value, }\item[{char $\ast$}]{possible\+\_\+values\mbox{[}$\,$\mbox{]}, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{default\+\_\+value, }\item[{\hyperlink{cmdline_8c_a88e31a859f36efa57ad64e6ae13332a1}{cmdline\+\_\+parser\+\_\+arg\+\_\+type}}]{arg\+\_\+type, }\item[{int}]{check\+\_\+ambiguity, }\item[{int}]{override, }\item[{int}]{no\+\_\+free, }\item[{int}]{multiple\+\_\+option, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{long\+\_\+opt, }\item[{char}]{short\+\_\+opt, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{additional\+\_\+error }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + + + +updates an option + + +\begin{DoxyParams}{Parameters} +{\em field} & the generic pointer to the field to update \\ +\hline +{\em orig\+\_\+field} & the pointer to the orig field \\ +\hline +{\em field\+\_\+given} & the pointer to the number of occurrence of this option \\ +\hline +{\em prev\+\_\+given} & the pointer to the number of occurrence already seen \\ +\hline +{\em value} & the argument for this option (if null no arg was specified) \\ +\hline +{\em possible\+\_\+values} & the possible values for this option (if specified) \\ +\hline +{\em default\+\_\+value} & the default value (in case the option only accepts fixed values) \\ +\hline +{\em arg\+\_\+type} & the type of this option \\ +\hline +{\em check\+\_\+ambiguity} & \\ +\hline +\end{DoxyParams} +\begin{DoxySeeAlso}{See also} +\hyperlink{structcmdline__parser__params_a6e4442704fc40b0b655f7cc602f13ec4}{cmdline\+\_\+parser\+\_\+params.\+check\+\_\+ambiguity} +\end{DoxySeeAlso} + +\begin{DoxyParams}{Parameters} +{\em override} & \\ +\hline +\end{DoxyParams} +\begin{DoxySeeAlso}{See also} +\hyperlink{structcmdline__parser__params_ad3ff9d69146e69a47506782197b5675c}{cmdline\+\_\+parser\+\_\+params.\+override} +\end{DoxySeeAlso} + +\begin{DoxyParams}{Parameters} +{\em no\+\_\+free} & whether to free a possible previous value \\ +\hline +{\em multiple\+\_\+option} & whether this is a multiple option \\ +\hline +{\em long\+\_\+opt} & the corresponding long option \\ +\hline +{\em short\+\_\+opt} & the corresponding short option (or \textquotesingle{}-\/\textquotesingle{} if none) \\ +\hline +{\em additional\+\_\+error} & possible further error specification \\ +\hline +\end{DoxyParams} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=273pt]{cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8c_a332041b3060103618ef6b767ab32d0dd}\label{cmdline_8c_a332041b3060103618ef6b767ab32d0dd}} +\index{cmdline.\+c@{cmdline.\+c}!write\+\_\+into\+\_\+file@{write\+\_\+into\+\_\+file}} +\index{write\+\_\+into\+\_\+file@{write\+\_\+into\+\_\+file}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{write\+\_\+into\+\_\+file()}{write\_into\_file()}} +{\footnotesize\ttfamily static void write\+\_\+into\+\_\+file (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{outfile, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{opt, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{arg, }\item[{char $\ast$}]{values\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{cmdline_8c_accad6107ca685f6eba555f6ce63d355d}\label{cmdline_8c_accad6107ca685f6eba555f6ce63d355d}} +\index{cmdline.\+c@{cmdline.\+c}!gengetopt\+\_\+args\+\_\+info\+\_\+description@{gengetopt\+\_\+args\+\_\+info\+\_\+description}} +\index{gengetopt\+\_\+args\+\_\+info\+\_\+description@{gengetopt\+\_\+args\+\_\+info\+\_\+description}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{gengetopt\+\_\+args\+\_\+info\+\_\+description}{gengetopt\_args\_info\_description}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+\_\+description = \char`\"{}\char`\"{}} + +\mbox{\Hypertarget{cmdline_8c_a6af7a6b7fb37c0abaa916ee1cfa0a41f}\label{cmdline_8c_a6af7a6b7fb37c0abaa916ee1cfa0a41f}} +\index{cmdline.\+c@{cmdline.\+c}!gengetopt\+\_\+args\+\_\+info\+\_\+help@{gengetopt\+\_\+args\+\_\+info\+\_\+help}} +\index{gengetopt\+\_\+args\+\_\+info\+\_\+help@{gengetopt\+\_\+args\+\_\+info\+\_\+help}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{gengetopt\+\_\+args\+\_\+info\+\_\+help}{gengetopt\_args\_info\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+\_\+help\mbox{[}$\,$\mbox{]}} + +{\bfseries Initial value\+:} +\begin{DoxyCode} += \{ + \textcolor{stringliteral}{" -h, --help Print help and exit"}, + \textcolor{stringliteral}{" -V, --version Print version and exit"}, + \textcolor{stringliteral}{" -o, --outfile=STRING Output filename"}, + \textcolor{stringliteral}{" -g, --gtf GTF output (default=off)"}, + \textcolor{stringliteral}{" -t, --tabular Tab delimited output (default=off)"}, + \textcolor{stringliteral}{" -b, --best-only Print only best hit per alignment (default=off)"}, + \textcolor{stringliteral}{" -r, --best-region Print all best non-overlapping hits per alignment \(\backslash\)n + (default=off)"}, + \textcolor{stringliteral}{" -c, --pars=STRING String with parameters"}, + \textcolor{stringliteral}{" -s, --stop-early Don't calculate p-values if below cutoff \(\backslash\)n + (default=off)"}, + \textcolor{stringliteral}{" -n, --num-samples=INT Number of samples"}, + \textcolor{stringliteral}{" -p, --cutoff=FLOAT p-value cutoff"}, + \textcolor{stringliteral}{" -z, --debug-file=STRING Debug file"}, + \textcolor{stringliteral}{" -e, --eps Postscript output (default=off)"}, + \textcolor{stringliteral}{" -i, --eps-cutoff=FLOAT Postscript output p-value cutoff"}, + \textcolor{stringliteral}{" -d, --eps-dir=STRING Postscript directory"}, + \textcolor{stringliteral}{" -l, --limit=STRING limit to species"}, + \textcolor{stringliteral}{" -m, --blosum=INT BLOSUM matrix version"}, + 0 +\} +\end{DoxyCode} + + +all the lines making the help output + +\mbox{\Hypertarget{cmdline_8c_a610c3307abce5a8fd304b86b018ae60b}\label{cmdline_8c_a610c3307abce5a8fd304b86b018ae60b}} +\index{cmdline.\+c@{cmdline.\+c}!gengetopt\+\_\+args\+\_\+info\+\_\+purpose@{gengetopt\+\_\+args\+\_\+info\+\_\+purpose}} +\index{gengetopt\+\_\+args\+\_\+info\+\_\+purpose@{gengetopt\+\_\+args\+\_\+info\+\_\+purpose}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{gengetopt\+\_\+args\+\_\+info\+\_\+purpose}{gengetopt\_args\_info\_purpose}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+\_\+purpose = \char`\"{}\char`\"{}} + + + +the purpose string of the program + +\mbox{\Hypertarget{cmdline_8c_a9f397a306f363bfdebb611e86acf36d5}\label{cmdline_8c_a9f397a306f363bfdebb611e86acf36d5}} +\index{cmdline.\+c@{cmdline.\+c}!gengetopt\+\_\+args\+\_\+info\+\_\+usage@{gengetopt\+\_\+args\+\_\+info\+\_\+usage}} +\index{gengetopt\+\_\+args\+\_\+info\+\_\+usage@{gengetopt\+\_\+args\+\_\+info\+\_\+usage}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{gengetopt\+\_\+args\+\_\+info\+\_\+usage}{gengetopt\_args\_info\_usage}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+\_\+usage = \char`\"{}Usage\+: \char`\"{} C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+P\+A\+C\+K\+A\+GE \char`\"{} \mbox{[}O\+P\+T\+I\+O\+NS\mbox{]}... \mbox{[}F\+I\+L\+ES\mbox{]}...\char`\"{}} + + + +the usage string of the program + +\mbox{\Hypertarget{cmdline_8c_a08f16a026de44b77c5e7be490fb9e32b}\label{cmdline_8c_a08f16a026de44b77c5e7be490fb9e32b}} +\index{cmdline.\+c@{cmdline.\+c}!package\+\_\+name@{package\+\_\+name}} +\index{package\+\_\+name@{package\+\_\+name}!cmdline.\+c@{cmdline.\+c}} +\subsubsection{\texorpdfstring{package\+\_\+name}{package\_name}} +{\footnotesize\ttfamily char$\ast$ package\+\_\+name = 0\hspace{0.3cm}{\ttfamily [static]}} + diff --git a/src/latex/cmdline_8c__incl.md5 b/src/latex/cmdline_8c__incl.md5 new file mode 100644 index 0000000..481facb --- /dev/null +++ b/src/latex/cmdline_8c__incl.md5 @@ -0,0 +1 @@ +9ce83b31d8b4fff3b37fe4f95c769a3d \ No newline at end of file diff --git a/src/latex/cmdline_8c__incl.pdf b/src/latex/cmdline_8c__incl.pdf new file mode 100644 index 0000000..75b30ce Binary files /dev/null and b/src/latex/cmdline_8c__incl.pdf differ diff --git a/src/latex/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 b/src/latex/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 new file mode 100644 index 0000000..85f74a8 --- /dev/null +++ b/src/latex/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 @@ -0,0 +1 @@ +06d3d5d5cbc61a2675e6e51898dd5710 \ No newline at end of file diff --git a/src/latex/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.pdf b/src/latex/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.pdf new file mode 100644 index 0000000..c72e0d1 Binary files /dev/null and b/src/latex/cmdline_8c_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 b/src/latex/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 new file mode 100644 index 0000000..ead94ba --- /dev/null +++ b/src/latex/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 @@ -0,0 +1 @@ +56af0522eb4a1d11dbe8f2639662cac5 \ No newline at end of file diff --git a/src/latex/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.pdf b/src/latex/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.pdf new file mode 100644 index 0000000..46e4854 Binary files /dev/null and b/src/latex/cmdline_8c_a1f73418092a6e6eb3706aa0de2785e11_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.md5 b/src/latex/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.md5 new file mode 100644 index 0000000..b68671b --- /dev/null +++ b/src/latex/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.md5 @@ -0,0 +1 @@ +88a2567108d3481b124fbaff364dffcd \ No newline at end of file diff --git a/src/latex/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.pdf b/src/latex/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.pdf new file mode 100644 index 0000000..e209ee4 Binary files /dev/null and b/src/latex/cmdline_8c_a21d8824d410efa489c4921011c1c0765_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 b/src/latex/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 new file mode 100644 index 0000000..f5fbd62 --- /dev/null +++ b/src/latex/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 @@ -0,0 +1 @@ +6158e35717991c8d0607dbd5d3ac19fa \ No newline at end of file diff --git a/src/latex/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.pdf b/src/latex/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.pdf new file mode 100644 index 0000000..0b6344f Binary files /dev/null and b/src/latex/cmdline_8c_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 b/src/latex/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 new file mode 100644 index 0000000..4b15fa1 --- /dev/null +++ b/src/latex/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 @@ -0,0 +1 @@ +e850288109672e1d7e4a6b36b4494c5b \ No newline at end of file diff --git a/src/latex/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.pdf b/src/latex/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.pdf new file mode 100644 index 0000000..2794c2d Binary files /dev/null and b/src/latex/cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 b/src/latex/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 new file mode 100644 index 0000000..74bea51 --- /dev/null +++ b/src/latex/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 @@ -0,0 +1 @@ +8f27e38f0811fe84e75fef95cee9dd71 \ No newline at end of file diff --git a/src/latex/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.pdf b/src/latex/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.pdf new file mode 100644 index 0000000..b526703 Binary files /dev/null and b/src/latex/cmdline_8c_a96f1044799c552f3ee139f9b1387b363_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.md5 b/src/latex/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.md5 new file mode 100644 index 0000000..684c243 --- /dev/null +++ b/src/latex/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.md5 @@ -0,0 +1 @@ +d0effc2b0f395d45059a319c1126354b \ No newline at end of file diff --git a/src/latex/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.pdf b/src/latex/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.pdf new file mode 100644 index 0000000..f3acb23 Binary files /dev/null and b/src/latex/cmdline_8c_aaba43e1bb216c68c96e982c600c906a7_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 b/src/latex/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 new file mode 100644 index 0000000..9bb7f7e --- /dev/null +++ b/src/latex/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 @@ -0,0 +1 @@ +3cae80fbc9d8b713c6de749ef622dd59 \ No newline at end of file diff --git a/src/latex/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.pdf b/src/latex/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.pdf new file mode 100644 index 0000000..e84e591 Binary files /dev/null and b/src/latex/cmdline_8c_aca62b50d03d0d082968eeb1940f98650_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.md5 b/src/latex/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.md5 new file mode 100644 index 0000000..a686627 --- /dev/null +++ b/src/latex/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.md5 @@ -0,0 +1 @@ +aa2c58df7ccc9f021893928127075f07 \ No newline at end of file diff --git a/src/latex/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.pdf b/src/latex/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.pdf new file mode 100644 index 0000000..9881165 Binary files /dev/null and b/src/latex/cmdline_8c_ace6fb8241473bb89c5a575774eb4ba2a_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 b/src/latex/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 new file mode 100644 index 0000000..0278c03 --- /dev/null +++ b/src/latex/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 @@ -0,0 +1 @@ +bb2a8f9a26e4422563925d30b90185ab \ No newline at end of file diff --git a/src/latex/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.pdf b/src/latex/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.pdf new file mode 100644 index 0000000..fbae589 Binary files /dev/null and b/src/latex/cmdline_8c_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.md5 b/src/latex/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.md5 new file mode 100644 index 0000000..85da4ea --- /dev/null +++ b/src/latex/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.md5 @@ -0,0 +1 @@ +2f0a1e61f0cf888603282ee8810eea58 \ No newline at end of file diff --git a/src/latex/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.pdf b/src/latex/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.pdf new file mode 100644 index 0000000..1c7c571 Binary files /dev/null and b/src/latex/cmdline_8c_ad600bb9026825a295ea57df22bdf7eca_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 b/src/latex/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 new file mode 100644 index 0000000..c786029 --- /dev/null +++ b/src/latex/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 @@ -0,0 +1 @@ +b2716d4b7abe4812be045a74e0b15018 \ No newline at end of file diff --git a/src/latex/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.pdf b/src/latex/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.pdf new file mode 100644 index 0000000..62c3df7 Binary files /dev/null and b/src/latex/cmdline_8c_af1b97c4e92b88f736e350b3902266ba4_cgraph.pdf differ diff --git a/src/latex/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 b/src/latex/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 new file mode 100644 index 0000000..1649caf --- /dev/null +++ b/src/latex/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 @@ -0,0 +1 @@ +2a9c5176e25da223f514feae7c7e66be \ No newline at end of file diff --git a/src/latex/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.pdf b/src/latex/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.pdf new file mode 100644 index 0000000..ad5c92c Binary files /dev/null and b/src/latex/cmdline_8c_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.pdf differ diff --git a/src/latex/cmdline_8h.tex b/src/latex/cmdline_8h.tex new file mode 100644 index 0000000..636deda --- /dev/null +++ b/src/latex/cmdline_8h.tex @@ -0,0 +1,379 @@ +\hypertarget{cmdline_8h}{}\section{cmdline.\+h File Reference} +\label{cmdline_8h}\index{cmdline.\+h@{cmdline.\+h}} + + +The header file for the command line option parser generated by G\+NU Gengetopt version 2.\+22.\+1 \href{http://www.gnu.org/software/gengetopt}{\tt http\+://www.\+gnu.\+org/software/gengetopt}. DO N\+OT modify this file, since it can be overwritten. + + +{\ttfamily \#include $<$stdio.\+h$>$}\newline +Include dependency graph for cmdline.\+h\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=139pt]{cmdline_8h__incl} +\end{center} +\end{figure} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=226pt]{cmdline_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Classes} +\begin{DoxyCompactItemize} +\item +struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} +\begin{DoxyCompactList}\small\item\em Where the command line options are stored. \end{DoxyCompactList}\item +struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} +\begin{DoxyCompactList}\small\item\em The additional parameters to pass to parser functions. \end{DoxyCompactList}\end{DoxyCompactItemize} +\subsection*{Macros} +\begin{DoxyCompactItemize} +\item +\#define \hyperlink{cmdline_8h_aeb847973552c32bcbe5f14973a0a8a32}{C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+P\+A\+C\+K\+A\+GE}~P\+A\+C\+K\+A\+GE +\begin{DoxyCompactList}\small\item\em the program name \end{DoxyCompactList}\item +\#define \hyperlink{cmdline_8h_a1eeca7dc254bf6867ba9635f45771471}{C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+V\+E\+R\+S\+I\+ON}~V\+E\+R\+S\+I\+ON +\begin{DoxyCompactList}\small\item\em the program version \end{DoxyCompactList}\end{DoxyCompactItemize} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +int \hyperlink{cmdline_8h_a96f1044799c552f3ee139f9b1387b363}{cmdline\+\_\+parser} (int argc, char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$argv, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +int \hyperlink{cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7}{cmdline\+\_\+parser2} (int argc, char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$argv, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info, int override, int initialize, int check\+\_\+required) +\item +int \hyperlink{cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38}{cmdline\+\_\+parser\+\_\+ext} (int argc, char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$argv, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info, struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$params) +\item +int \hyperlink{cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11}{cmdline\+\_\+parser\+\_\+dump} (F\+I\+LE $\ast$\hyperlink{postscript_8c_ae581849c67336453bd5b81e6518019a9}{outfile}, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +int \hyperlink{cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818}{cmdline\+\_\+parser\+\_\+file\+\_\+save} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$filename, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +void \hyperlink{cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492}{cmdline\+\_\+parser\+\_\+print\+\_\+help} (void) +\item +void \hyperlink{cmdline_8h_a96f27bf35ce0ab8eea7a1f6e6b59a5e2}{cmdline\+\_\+parser\+\_\+print\+\_\+version} (void) +\item +void \hyperlink{cmdline_8h_af72b814611cffc706b2135ccdfe7e997}{cmdline\+\_\+parser\+\_\+params\+\_\+init} (struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$params) +\item +struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$ \hyperlink{cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92}{cmdline\+\_\+parser\+\_\+params\+\_\+create} (void) +\item +void \hyperlink{cmdline_8h_aca62b50d03d0d082968eeb1940f98650}{cmdline\+\_\+parser\+\_\+init} (struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +void \hyperlink{cmdline_8h_af1b97c4e92b88f736e350b3902266ba4}{cmdline\+\_\+parser\+\_\+free} (struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info) +\item +int \hyperlink{cmdline_8h_a83651e5be280d60aed58fdb72456a030}{cmdline\+\_\+parser\+\_\+required} (struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$prog\+\_\+name) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{cmdline_8h_a610c3307abce5a8fd304b86b018ae60b}{gengetopt\+\_\+args\+\_\+info\+\_\+purpose} +\begin{DoxyCompactList}\small\item\em the purpose string of the program \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{cmdline_8h_a9f397a306f363bfdebb611e86acf36d5}{gengetopt\+\_\+args\+\_\+info\+\_\+usage} +\begin{DoxyCompactList}\small\item\em the usage string of the program \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{cmdline_8h_a6af7a6b7fb37c0abaa916ee1cfa0a41f}{gengetopt\+\_\+args\+\_\+info\+\_\+help} \mbox{[}$\,$\mbox{]} +\begin{DoxyCompactList}\small\item\em all the lines making the help output \end{DoxyCompactList}\end{DoxyCompactItemize} + + +\subsection{Detailed Description} +The header file for the command line option parser generated by G\+NU Gengetopt version 2.\+22.\+1 \href{http://www.gnu.org/software/gengetopt}{\tt http\+://www.\+gnu.\+org/software/gengetopt}. DO N\+OT modify this file, since it can be overwritten. + +\begin{DoxyAuthor}{Author} +G\+NU Gengetopt by Lorenzo Bettini +\end{DoxyAuthor} + + +\subsection{Macro Definition Documentation} +\mbox{\Hypertarget{cmdline_8h_aeb847973552c32bcbe5f14973a0a8a32}\label{cmdline_8h_aeb847973552c32bcbe5f14973a0a8a32}} +\index{cmdline.\+h@{cmdline.\+h}!C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+P\+A\+C\+K\+A\+GE@{C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+P\+A\+C\+K\+A\+GE}} +\index{C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+P\+A\+C\+K\+A\+GE@{C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+P\+A\+C\+K\+A\+GE}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+P\+A\+C\+K\+A\+GE}{CMDLINE\_PARSER\_PACKAGE}} +{\footnotesize\ttfamily \#define C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+P\+A\+C\+K\+A\+GE~P\+A\+C\+K\+A\+GE} + + + +the program name + +\mbox{\Hypertarget{cmdline_8h_a1eeca7dc254bf6867ba9635f45771471}\label{cmdline_8h_a1eeca7dc254bf6867ba9635f45771471}} +\index{cmdline.\+h@{cmdline.\+h}!C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+V\+E\+R\+S\+I\+ON@{C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+V\+E\+R\+S\+I\+ON}} +\index{C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+V\+E\+R\+S\+I\+ON@{C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+V\+E\+R\+S\+I\+ON}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+V\+E\+R\+S\+I\+ON}{CMDLINE\_PARSER\_VERSION}} +{\footnotesize\ttfamily \#define C\+M\+D\+L\+I\+N\+E\+\_\+\+P\+A\+R\+S\+E\+R\+\_\+\+V\+E\+R\+S\+I\+ON~V\+E\+R\+S\+I\+ON} + + + +the program version + + + +\subsection{Function Documentation} +\mbox{\Hypertarget{cmdline_8h_a96f1044799c552f3ee139f9b1387b363}\label{cmdline_8h_a96f1044799c552f3ee139f9b1387b363}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser@{cmdline\+\_\+parser}} +\index{cmdline\+\_\+parser@{cmdline\+\_\+parser}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser()}{cmdline\_parser()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$}]{argv, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})} + +The command line parser +\begin{DoxyParams}{Parameters} +{\em argc} & the number of command line options \\ +\hline +{\em argv} & the command line options \\ +\hline +{\em args\+\_\+info} & the structure where option information will be stored \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} +0 if everything went fine, N\+ON 0 if an error took place +\end{DoxyReturn} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7}\label{cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser2@{cmdline\+\_\+parser2}} +\index{cmdline\+\_\+parser2@{cmdline\+\_\+parser2}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser2()}{cmdline\_parser2()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser2 (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$}]{argv, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info, }\item[{int}]{override, }\item[{int}]{initialize, }\item[{int}]{check\+\_\+required }\end{DoxyParamCaption})} + +The command line parser (version with additional parameters -\/ deprecated) +\begin{DoxyParams}{Parameters} +{\em argc} & the number of command line options \\ +\hline +{\em argv} & the command line options \\ +\hline +{\em args\+\_\+info} & the structure where option information will be stored \\ +\hline +{\em override} & whether to override possibly already present options \\ +\hline +{\em initialize} & whether to initialize the option structure my\+\_\+args\+\_\+info \\ +\hline +{\em check\+\_\+required} & whether to check that all required options were provided \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} +0 if everything went fine, N\+ON 0 if an error took place +\end{DoxyReturn} +\begin{DoxyRefDesc}{Deprecated} +\item[\hyperlink{deprecated__deprecated000001}{Deprecated}]use \hyperlink{cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38}{cmdline\+\_\+parser\+\_\+ext()} instead \end{DoxyRefDesc} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11}\label{cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser\+\_\+dump@{cmdline\+\_\+parser\+\_\+dump}} +\index{cmdline\+\_\+parser\+\_\+dump@{cmdline\+\_\+parser\+\_\+dump}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+dump()}{cmdline\_parser\_dump()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+dump (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{outfile, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})} + +Save the contents of the option struct into an already open F\+I\+LE stream. +\begin{DoxyParams}{Parameters} +{\em outfile} & the stream where to dump options \\ +\hline +{\em args\+\_\+info} & the option struct to dump \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} +0 if everything went fine, N\+ON 0 if an error took place +\end{DoxyReturn} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=305pt]{cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38}\label{cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser\+\_\+ext@{cmdline\+\_\+parser\+\_\+ext}} +\index{cmdline\+\_\+parser\+\_\+ext@{cmdline\+\_\+parser\+\_\+ext}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+ext()}{cmdline\_parser\_ext()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+ext (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$}]{argv, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info, }\item[{struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$}]{params }\end{DoxyParamCaption})} + +The command line parser (version with additional parameters) +\begin{DoxyParams}{Parameters} +{\em argc} & the number of command line options \\ +\hline +{\em argv} & the command line options \\ +\hline +{\em args\+\_\+info} & the structure where option information will be stored \\ +\hline +{\em params} & additional parameters for the parser \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} +0 if everything went fine, N\+ON 0 if an error took place +\end{DoxyReturn} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818}\label{cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser\+\_\+file\+\_\+save@{cmdline\+\_\+parser\+\_\+file\+\_\+save}} +\index{cmdline\+\_\+parser\+\_\+file\+\_\+save@{cmdline\+\_\+parser\+\_\+file\+\_\+save}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+file\+\_\+save()}{cmdline\_parser\_file\_save()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+file\+\_\+save (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{filename, }\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})} + +Save the contents of the option struct into a (text) file. This file can be read by the config file parser (if generated by gengetopt) +\begin{DoxyParams}{Parameters} +{\em filename} & the file where to save \\ +\hline +{\em args\+\_\+info} & the option struct to save \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} +0 if everything went fine, N\+ON 0 if an error took place +\end{DoxyReturn} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8h_af1b97c4e92b88f736e350b3902266ba4}\label{cmdline_8h_af1b97c4e92b88f736e350b3902266ba4}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser\+\_\+free@{cmdline\+\_\+parser\+\_\+free}} +\index{cmdline\+\_\+parser\+\_\+free@{cmdline\+\_\+parser\+\_\+free}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+free()}{cmdline\_parser\_free()}} +{\footnotesize\ttfamily void cmdline\+\_\+parser\+\_\+free (\begin{DoxyParamCaption}\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})} + +Deallocates the string fields of the \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} structure (but does not deallocate the structure itself) +\begin{DoxyParams}{Parameters} +{\em args\+\_\+info} & the structure to deallocate \\ +\hline +\end{DoxyParams} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8h_aca62b50d03d0d082968eeb1940f98650}\label{cmdline_8h_aca62b50d03d0d082968eeb1940f98650}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser\+\_\+init@{cmdline\+\_\+parser\+\_\+init}} +\index{cmdline\+\_\+parser\+\_\+init@{cmdline\+\_\+parser\+\_\+init}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+init()}{cmdline\_parser\_init()}} +{\footnotesize\ttfamily void cmdline\+\_\+parser\+\_\+init (\begin{DoxyParamCaption}\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info }\end{DoxyParamCaption})} + +Initializes the passed \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} structure\textquotesingle{}s fields (also set default values for options that have a default) +\begin{DoxyParams}{Parameters} +{\em args\+\_\+info} & the structure to initialize \\ +\hline +\end{DoxyParams} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=291pt]{cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92}\label{cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser\+\_\+params\+\_\+create@{cmdline\+\_\+parser\+\_\+params\+\_\+create}} +\index{cmdline\+\_\+parser\+\_\+params\+\_\+create@{cmdline\+\_\+parser\+\_\+params\+\_\+create}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+params\+\_\+create()}{cmdline\_parser\_params\_create()}} +{\footnotesize\ttfamily struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params}$\ast$ cmdline\+\_\+parser\+\_\+params\+\_\+create (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +Allocates dynamically a \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} structure and initializes all its fields to their default values \begin{DoxyReturn}{Returns} +the created and initialized \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} structure +\end{DoxyReturn} +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8h_af72b814611cffc706b2135ccdfe7e997}\label{cmdline_8h_af72b814611cffc706b2135ccdfe7e997}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser\+\_\+params\+\_\+init@{cmdline\+\_\+parser\+\_\+params\+\_\+init}} +\index{cmdline\+\_\+parser\+\_\+params\+\_\+init@{cmdline\+\_\+parser\+\_\+params\+\_\+init}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+params\+\_\+init()}{cmdline\_parser\_params\_init()}} +{\footnotesize\ttfamily void cmdline\+\_\+parser\+\_\+params\+\_\+init (\begin{DoxyParamCaption}\item[{struct \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} $\ast$}]{params }\end{DoxyParamCaption})} + +Initializes all the fields a \hyperlink{structcmdline__parser__params}{cmdline\+\_\+parser\+\_\+params} structure to their default values +\begin{DoxyParams}{Parameters} +{\em params} & the structure to initialize \\ +\hline +\end{DoxyParams} +\mbox{\Hypertarget{cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492}\label{cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser\+\_\+print\+\_\+help@{cmdline\+\_\+parser\+\_\+print\+\_\+help}} +\index{cmdline\+\_\+parser\+\_\+print\+\_\+help@{cmdline\+\_\+parser\+\_\+print\+\_\+help}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+print\+\_\+help()}{cmdline\_parser\_print\_help()}} +{\footnotesize\ttfamily void cmdline\+\_\+parser\+\_\+print\+\_\+help (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +Print the help Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{cmdline_8h_a96f27bf35ce0ab8eea7a1f6e6b59a5e2}\label{cmdline_8h_a96f27bf35ce0ab8eea7a1f6e6b59a5e2}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser\+\_\+print\+\_\+version@{cmdline\+\_\+parser\+\_\+print\+\_\+version}} +\index{cmdline\+\_\+parser\+\_\+print\+\_\+version@{cmdline\+\_\+parser\+\_\+print\+\_\+version}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+print\+\_\+version()}{cmdline\_parser\_print\_version()}} +{\footnotesize\ttfamily void cmdline\+\_\+parser\+\_\+print\+\_\+version (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +Print the version \mbox{\Hypertarget{cmdline_8h_a83651e5be280d60aed58fdb72456a030}\label{cmdline_8h_a83651e5be280d60aed58fdb72456a030}} +\index{cmdline.\+h@{cmdline.\+h}!cmdline\+\_\+parser\+\_\+required@{cmdline\+\_\+parser\+\_\+required}} +\index{cmdline\+\_\+parser\+\_\+required@{cmdline\+\_\+parser\+\_\+required}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{cmdline\+\_\+parser\+\_\+required()}{cmdline\_parser\_required()}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+required (\begin{DoxyParamCaption}\item[{struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$}]{args\+\_\+info, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{prog\+\_\+name }\end{DoxyParamCaption})} + +Checks that all the required options were specified +\begin{DoxyParams}{Parameters} +{\em args\+\_\+info} & the structure to check \\ +\hline +{\em prog\+\_\+name} & the name of the program that will be used to print possible errors \\ +\hline +\end{DoxyParams} +\begin{DoxyReturn}{Returns} + +\end{DoxyReturn} + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{cmdline_8h_a6af7a6b7fb37c0abaa916ee1cfa0a41f}\label{cmdline_8h_a6af7a6b7fb37c0abaa916ee1cfa0a41f}} +\index{cmdline.\+h@{cmdline.\+h}!gengetopt\+\_\+args\+\_\+info\+\_\+help@{gengetopt\+\_\+args\+\_\+info\+\_\+help}} +\index{gengetopt\+\_\+args\+\_\+info\+\_\+help@{gengetopt\+\_\+args\+\_\+info\+\_\+help}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{gengetopt\+\_\+args\+\_\+info\+\_\+help}{gengetopt\_args\_info\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+\_\+help\mbox{[}$\,$\mbox{]}} + + + +all the lines making the help output + +\mbox{\Hypertarget{cmdline_8h_a610c3307abce5a8fd304b86b018ae60b}\label{cmdline_8h_a610c3307abce5a8fd304b86b018ae60b}} +\index{cmdline.\+h@{cmdline.\+h}!gengetopt\+\_\+args\+\_\+info\+\_\+purpose@{gengetopt\+\_\+args\+\_\+info\+\_\+purpose}} +\index{gengetopt\+\_\+args\+\_\+info\+\_\+purpose@{gengetopt\+\_\+args\+\_\+info\+\_\+purpose}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{gengetopt\+\_\+args\+\_\+info\+\_\+purpose}{gengetopt\_args\_info\_purpose}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+\_\+purpose} + + + +the purpose string of the program + +\mbox{\Hypertarget{cmdline_8h_a9f397a306f363bfdebb611e86acf36d5}\label{cmdline_8h_a9f397a306f363bfdebb611e86acf36d5}} +\index{cmdline.\+h@{cmdline.\+h}!gengetopt\+\_\+args\+\_\+info\+\_\+usage@{gengetopt\+\_\+args\+\_\+info\+\_\+usage}} +\index{gengetopt\+\_\+args\+\_\+info\+\_\+usage@{gengetopt\+\_\+args\+\_\+info\+\_\+usage}!cmdline.\+h@{cmdline.\+h}} +\subsubsection{\texorpdfstring{gengetopt\+\_\+args\+\_\+info\+\_\+usage}{gengetopt\_args\_info\_usage}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+\_\+usage} + + + +the usage string of the program + diff --git a/src/latex/cmdline_8h__dep__incl.md5 b/src/latex/cmdline_8h__dep__incl.md5 new file mode 100644 index 0000000..638a914 --- /dev/null +++ b/src/latex/cmdline_8h__dep__incl.md5 @@ -0,0 +1 @@ +7783f70449ea6208545dc1bdb1ecc4ff \ No newline at end of file diff --git a/src/latex/cmdline_8h__dep__incl.pdf b/src/latex/cmdline_8h__dep__incl.pdf new file mode 100644 index 0000000..2e17329 Binary files /dev/null and b/src/latex/cmdline_8h__dep__incl.pdf differ diff --git a/src/latex/cmdline_8h__incl.md5 b/src/latex/cmdline_8h__incl.md5 new file mode 100644 index 0000000..8d57cc9 --- /dev/null +++ b/src/latex/cmdline_8h__incl.md5 @@ -0,0 +1 @@ +cc4d26f0706a9c3f665f5c6f840b6241 \ No newline at end of file diff --git a/src/latex/cmdline_8h__incl.pdf b/src/latex/cmdline_8h__incl.pdf new file mode 100644 index 0000000..505564d Binary files /dev/null and b/src/latex/cmdline_8h__incl.pdf differ diff --git a/src/latex/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 b/src/latex/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 new file mode 100644 index 0000000..7cff17a --- /dev/null +++ b/src/latex/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.md5 @@ -0,0 +1 @@ +6b819a4ab9c18264c7ba1e2076ec3737 \ No newline at end of file diff --git a/src/latex/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.pdf b/src/latex/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.pdf new file mode 100644 index 0000000..c72e0d1 Binary files /dev/null and b/src/latex/cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7_cgraph.pdf differ diff --git a/src/latex/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 b/src/latex/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 new file mode 100644 index 0000000..52bb05c --- /dev/null +++ b/src/latex/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.md5 @@ -0,0 +1 @@ +a2486664cfce1f7e5e00980ff531c4f4 \ No newline at end of file diff --git a/src/latex/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.pdf b/src/latex/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.pdf new file mode 100644 index 0000000..46e4854 Binary files /dev/null and b/src/latex/cmdline_8h_a1f73418092a6e6eb3706aa0de2785e11_cgraph.pdf differ diff --git a/src/latex/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 b/src/latex/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 new file mode 100644 index 0000000..2870802 --- /dev/null +++ b/src/latex/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.md5 @@ -0,0 +1 @@ +8c4d9c054d47de0c0ca891de1575eb28 \ No newline at end of file diff --git a/src/latex/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.pdf b/src/latex/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.pdf new file mode 100644 index 0000000..0b6344f Binary files /dev/null and b/src/latex/cmdline_8h_a5f3e9412f88f1058a31ac28ad2ea2818_cgraph.pdf differ diff --git a/src/latex/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 b/src/latex/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 new file mode 100644 index 0000000..b376fe5 --- /dev/null +++ b/src/latex/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.md5 @@ -0,0 +1 @@ +90a1cfafcce4045c5abc1c027ff0c011 \ No newline at end of file diff --git a/src/latex/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.pdf b/src/latex/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.pdf new file mode 100644 index 0000000..2794c2d Binary files /dev/null and b/src/latex/cmdline_8h_a77e461b5bdfd4a36c59a96bfb1813e38_cgraph.pdf differ diff --git a/src/latex/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 b/src/latex/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 new file mode 100644 index 0000000..ae2882f --- /dev/null +++ b/src/latex/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.md5 @@ -0,0 +1 @@ +0094ab262c94a3e250f53f8e387fa839 \ No newline at end of file diff --git a/src/latex/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.pdf b/src/latex/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.pdf new file mode 100644 index 0000000..b526703 Binary files /dev/null and b/src/latex/cmdline_8h_a96f1044799c552f3ee139f9b1387b363_cgraph.pdf differ diff --git a/src/latex/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 b/src/latex/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 new file mode 100644 index 0000000..5a25c9c --- /dev/null +++ b/src/latex/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.md5 @@ -0,0 +1 @@ +7bd0e9ad4808520037be388ab50e6ed5 \ No newline at end of file diff --git a/src/latex/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.pdf b/src/latex/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.pdf new file mode 100644 index 0000000..e84e591 Binary files /dev/null and b/src/latex/cmdline_8h_aca62b50d03d0d082968eeb1940f98650_cgraph.pdf differ diff --git a/src/latex/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 b/src/latex/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 new file mode 100644 index 0000000..2667178 --- /dev/null +++ b/src/latex/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.md5 @@ -0,0 +1 @@ +0502dd1629f8d70c37854c2f730aa3d4 \ No newline at end of file diff --git a/src/latex/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.pdf b/src/latex/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.pdf new file mode 100644 index 0000000..fbae589 Binary files /dev/null and b/src/latex/cmdline_8h_ad4f7db2fa4002379eb30e5206f3b7492_cgraph.pdf differ diff --git a/src/latex/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 b/src/latex/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 new file mode 100644 index 0000000..f20696e --- /dev/null +++ b/src/latex/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.md5 @@ -0,0 +1 @@ +0c8b3c2ddbb27f2722295182fd692bad \ No newline at end of file diff --git a/src/latex/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.pdf b/src/latex/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.pdf new file mode 100644 index 0000000..62c3df7 Binary files /dev/null and b/src/latex/cmdline_8h_af1b97c4e92b88f736e350b3902266ba4_cgraph.pdf differ diff --git a/src/latex/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 b/src/latex/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 new file mode 100644 index 0000000..1426f0c --- /dev/null +++ b/src/latex/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.md5 @@ -0,0 +1 @@ +2a804602f34eeba5c8e3d2efcc288be2 \ No newline at end of file diff --git a/src/latex/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.pdf b/src/latex/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.pdf new file mode 100644 index 0000000..ad5c92c Binary files /dev/null and b/src/latex/cmdline_8h_afd778af110fe0ee1ea5eac7aa9939d92_cgraph.pdf differ diff --git a/src/latex/code_8c.tex b/src/latex/code_8c.tex new file mode 100644 index 0000000..dd5a031 --- /dev/null +++ b/src/latex/code_8c.tex @@ -0,0 +1,157 @@ +\hypertarget{code_8c}{}\section{code.\+c File Reference} +\label{code_8c}\index{code.\+c@{code.\+c}} +{\ttfamily \#include $<$stdlib.\+h$>$}\newline +{\ttfamily \#include $<$string.\+h$>$}\newline +{\ttfamily \#include \char`\"{}code.\+h\char`\"{}}\newline +Include dependency graph for code.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=260pt]{code_8c__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +char $\ast$ \hyperlink{code_8c_a8d64bc3ec5de4db181efd7ff565ff894}{translate\+Seq} (char $\ast$seq) +\item +int $\ast$ \hyperlink{code_8c_a011bbc41b53a2519b2bb46214b7a1fcc}{encode\+Seq} (char $\ast$seq) +\item +int \hyperlink{code_8c_a617a88955038003d70de0d9113b505eb}{encode\+AA} (char aa) +\item +char \hyperlink{code_8c_a124646f7d65dd512584b8fbab1fcc7a4}{decode\+AA} (int encoded\+AA) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +int \hyperlink{code_8c_a119a7eb0ecd417f83e41f4325ce522c8}{transcode} \mbox{[}4\mbox{]}\mbox{[}4\mbox{]}\mbox{[}4\mbox{]} +\item +int \hyperlink{code_8c_a528f2f941a2c7a8de187c946e438d107}{B\+L\+O\+S\+U\+M62} \mbox{[}24\mbox{]}\mbox{[}24\mbox{]} +\item +int \hyperlink{code_8c_addcd68ee32c359359fcb55b5bfd8a62f}{B\+L\+O\+S\+U\+M90} \mbox{[}24\mbox{]}\mbox{[}24\mbox{]} +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{code_8c_a124646f7d65dd512584b8fbab1fcc7a4}\label{code_8c_a124646f7d65dd512584b8fbab1fcc7a4}} +\index{code.\+c@{code.\+c}!decode\+AA@{decode\+AA}} +\index{decode\+AA@{decode\+AA}!code.\+c@{code.\+c}} +\subsubsection{\texorpdfstring{decode\+A\+A()}{decodeAA()}} +{\footnotesize\ttfamily char decode\+AA (\begin{DoxyParamCaption}\item[{int}]{encoded\+AA }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{code_8c_a617a88955038003d70de0d9113b505eb}\label{code_8c_a617a88955038003d70de0d9113b505eb}} +\index{code.\+c@{code.\+c}!encode\+AA@{encode\+AA}} +\index{encode\+AA@{encode\+AA}!code.\+c@{code.\+c}} +\subsubsection{\texorpdfstring{encode\+A\+A()}{encodeAA()}} +{\footnotesize\ttfamily int encode\+AA (\begin{DoxyParamCaption}\item[{char}]{aa }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{code_8c_a011bbc41b53a2519b2bb46214b7a1fcc}\label{code_8c_a011bbc41b53a2519b2bb46214b7a1fcc}} +\index{code.\+c@{code.\+c}!encode\+Seq@{encode\+Seq}} +\index{encode\+Seq@{encode\+Seq}!code.\+c@{code.\+c}} +\subsubsection{\texorpdfstring{encode\+Seq()}{encodeSeq()}} +{\footnotesize\ttfamily int$\ast$ encode\+Seq (\begin{DoxyParamCaption}\item[{char $\ast$}]{seq }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{code_8c_a8d64bc3ec5de4db181efd7ff565ff894}\label{code_8c_a8d64bc3ec5de4db181efd7ff565ff894}} +\index{code.\+c@{code.\+c}!translate\+Seq@{translate\+Seq}} +\index{translate\+Seq@{translate\+Seq}!code.\+c@{code.\+c}} +\subsubsection{\texorpdfstring{translate\+Seq()}{translateSeq()}} +{\footnotesize\ttfamily char$\ast$ translate\+Seq (\begin{DoxyParamCaption}\item[{char $\ast$}]{seq }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=252pt]{code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph} +\end{center} +\end{figure} + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{code_8c_a528f2f941a2c7a8de187c946e438d107}\label{code_8c_a528f2f941a2c7a8de187c946e438d107}} +\index{code.\+c@{code.\+c}!B\+L\+O\+S\+U\+M62@{B\+L\+O\+S\+U\+M62}} +\index{B\+L\+O\+S\+U\+M62@{B\+L\+O\+S\+U\+M62}!code.\+c@{code.\+c}} +\subsubsection{\texorpdfstring{B\+L\+O\+S\+U\+M62}{BLOSUM62}} +{\footnotesize\ttfamily int B\+L\+O\+S\+U\+M62\mbox{[}24\mbox{]}\mbox{[}24\mbox{]}} + +{\bfseries Initial value\+:} +\begin{DoxyCode} +=\{\{ 4,-1,-2,-2, 0,-1,-1, 0,-2,-1,-1,-1,-1,-2,-1, 1, 0,-3,-2, 0,-2,-1, 0,-4\}, + \{-1, 5, 0,-2,-3, 1, 0,-2, 0,-3,-2, 2,-1,-3,-2,-1,-1,-3,-2,-3,-1, 0,-1,-4\}, + \{-2, 0, 6, 1,-3, 0, 0, 0, 1,-3,-3, 0,-2,-3,-2, 1, 0,-4,-2,-3, 3, 0,-1,-4\}, + \{-2,-2, 1, 6,-3, 0, 2,-1,-1,-3,-4,-1,-3,-3,-1, 0,-1,-4,-3,-3, 4, 1,-1,-4\}, + \{ 0,-3,-3,-3, 9,-3,-4,-3,-3,-1,-1,-3,-1,-2,-3,-1,-1,-2,-2,-1,-3,-3,-2,-4\}, + \{-1, 1, 0, 0,-3, 5, 2,-2, 0,-3,-2, 1, 0,-3,-1, 0,-1,-2,-1,-2, 0, 3,-1,-4\}, + \{-1, 0, 0, 2,-4, 2, 5,-2, 0,-3,-3, 1,-2,-3,-1, 0,-1,-3,-2,-2, 1, 4,-1,-4\}, + \{ 0,-2, 0,-1,-3,-2,-2, 6,-2,-4,-4,-2,-3,-3,-2, 0,-2,-2,-3,-3,-1,-2,-1,-4\}, + \{-2, 0, 1,-1,-3, 0, 0,-2, 8,-3,-3,-1,-2,-1,-2,-1,-2,-2, 2,-3, 0, 0,-1,-4\}, + \{-1,-3,-3,-3,-1,-3,-3,-4,-3, 4, 2,-3, 1, 0,-3,-2,-1,-3,-1, 3,-3,-3,-1,-4\}, + \{-1,-2,-3,-4,-1,-2,-3,-4,-3, 2, 4,-2, 2, 0,-3,-2,-1,-2,-1, 1,-4,-3,-1,-4\}, + \{-1, 2, 0,-1,-3, 1, 1,-2,-1,-3,-2, 5,-1,-3,-1, 0,-1,-3,-2,-2, 0, 1,-1,-4\}, + \{-1,-1,-2,-3,-1, 0,-2,-3,-2, 1, 2,-1, 5, 0,-2,-1,-1,-1,-1, 1,-3,-1,-1,-4\}, + \{-2,-3,-3,-3,-2,-3,-3,-3,-1, 0, 0,-3, 0, 6,-4,-2,-2, 1, 3,-1,-3,-3,-1,-4\}, + \{-1,-2,-2,-1,-3,-1,-1,-2,-2,-3,-3,-1,-2,-4, 7,-1,-1,-4,-3,-2,-2,-1,-2,-4\}, + \{ 1,-1, 1, 0,-1, 0, 0, 0,-1,-2,-2, 0,-1,-2,-1, 4, 1,-3,-2,-2, 0, 0, 0,-4\}, + \{ 0,-1, 0,-1,-1,-1,-1,-2,-2,-1,-1,-1,-1,-2,-1, 1, 5,-2,-2, 0,-1,-1, 0,-4\}, + \{-3,-3,-4,-4,-2,-2,-3,-2,-2,-3,-2,-3,-1, 1,-4,-3,-2, 11, 2,-3,-4,-3,-2,-4\}, + \{-2,-2,-2,-3,-2,-1,-2,-3, 2,-1,-1,-2,-1, 3,-3,-2,-2, 2, 7,-1,-3,-2,-1,-4\}, + \{ 0,-3,-3,-3,-1,-2,-2,-3,-3, 3, 1,-2, 1,-1,-2,-2, 0,-3,-1, 4,-3,-2,-1,-4\}, + \{-2,-1, 3, 4,-3, 0, 1,-1, 0,-3,-4, 0,-3,-3,-2, 0,-1,-4,-3,-3, 4, 1,-1,-4\}, + \{-1, 0, 0, 1,-3, 3, 4,-2, 0,-3,-3, 1,-1,-3,-1, 0,-1,-3,-2,-2, 1, 4,-1,-4\}, + \{ 0,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2, 0, 0,-2,-1,-1,-1,-1,-1,-4\}, + \{-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, 1\}\} +\end{DoxyCode} +\mbox{\Hypertarget{code_8c_addcd68ee32c359359fcb55b5bfd8a62f}\label{code_8c_addcd68ee32c359359fcb55b5bfd8a62f}} +\index{code.\+c@{code.\+c}!B\+L\+O\+S\+U\+M90@{B\+L\+O\+S\+U\+M90}} +\index{B\+L\+O\+S\+U\+M90@{B\+L\+O\+S\+U\+M90}!code.\+c@{code.\+c}} +\subsubsection{\texorpdfstring{B\+L\+O\+S\+U\+M90}{BLOSUM90}} +{\footnotesize\ttfamily int B\+L\+O\+S\+U\+M90\mbox{[}24\mbox{]}\mbox{[}24\mbox{]}} + +{\bfseries Initial value\+:} +\begin{DoxyCode} +=\{\{ 5,-2,-2,-3,-1,-1,-1, 0,-2,-2,-2,-1,-2,-3,-1, 1, 0,-4,-3,-1,-2,-1,-1,-6\}, + \{-2, 6,-1,-3,-5, 1,-1,-3, 0,-4,-3, 2,-2,-4,-3,-1,-2,-4,-3,-3,-2, 0,-2,-6\}, + \{-2,-1, 7, 1,-4, 0,-1,-1, 0,-4,-4, 0,-3,-4,-3, 0, 0,-5,-3,-4, 4,-1,-2,-6\}, + \{-3,-3, 1, 7,-5,-1, 1,-2,-2,-5,-5,-1,-4,-5,-3,-1,-2,-6,-4,-5, 4, 0,-2,-6\}, + \{-1,-5,-4,-5, 9,-4,-6,-4,-5,-2,-2,-4,-2,-3,-4,-2,-2,-4,-4,-2,-4,-5,-3,-6\}, + \{-1, 1, 0,-1,-4, 7, 2,-3, 1,-4,-3, 1, 0,-4,-2,-1,-1,-3,-3,-3,-1, 4,-1,-6\}, + \{-1,-1,-1, 1,-6, 2, 6,-3,-1,-4,-4, 0,-3,-5,-2,-1,-1,-5,-4,-3, 0, 4,-2,-6\}, + \{ 0,-3,-1,-2,-4,-3,-3, 6,-3,-5,-5,-2,-4,-5,-3,-1,-3,-4,-5,-5,-2,-3,-2,-6\}, + \{-2, 0, 0,-2,-5, 1,-1,-3, 8,-4,-4,-1,-3,-2,-3,-2,-2,-3, 1,-4,-1, 0,-2,-6\}, + \{-2,-4,-4,-5,-2,-4,-4,-5,-4, 5, 1,-4, 1,-1,-4,-3,-1,-4,-2, 3,-5,-4,-2,-6\}, + \{-2,-3,-4,-5,-2,-3,-4,-5,-4, 1, 5,-3, 2, 0,-4,-3,-2,-3,-2, 0,-5,-4,-2,-6\}, + \{-1, 2, 0,-1,-4, 1, 0,-2,-1,-4,-3, 6,-2,-4,-2,-1,-1,-5,-3,-3,-1, 1,-1,-6\}, + \{-2,-2,-3,-4,-2, 0,-3,-4,-3, 1, 2,-2, 7,-1,-3,-2,-1,-2,-2, 0,-4,-2,-1,-6\}, + \{-3,-4,-4,-5,-3,-4,-5,-5,-2,-1, 0,-4,-1, 7,-4,-3,-3, 0, 3,-2,-4,-4,-2,-6\}, + \{-1,-3,-3,-3,-4,-2,-2,-3,-3,-4,-4,-2,-3,-4, 8,-2,-2,-5,-4,-3,-3,-2,-2,-6\}, + \{ 1,-1, 0,-1,-2,-1,-1,-1,-2,-3,-3,-1,-2,-3,-2, 5, 1,-4,-3,-2, 0,-1,-1,-6\}, + \{ 0,-2, 0,-2,-2,-1,-1,-3,-2,-1,-2,-1,-1,-3,-2, 1, 6,-4,-2,-1,-1,-1,-1,-6\}, + \{-4,-4,-5,-6,-4,-3,-5,-4,-3,-4,-3,-5,-2, 0,-5,-4,-4, 11, 2,-3,-6,-4,-3,-6\}, + \{-3,-3,-3,-4,-4,-3,-4,-5, 1,-2,-2,-3,-2, 3,-4,-3,-2, 2, 8,-3,-4,-3,-2,-6\}, + \{-1,-3,-4,-5,-2,-3,-3,-5,-4, 3, 0,-3, 0,-2,-3,-2,-1,-3,-3, 5,-4,-3,-2,-6\}, + \{-2,-2, 4, 4,-4,-1, 0,-2,-1,-5,-5,-1,-4,-4,-3, 0,-1,-6,-4,-4, 4, 0,-2,-6\}, + \{-1, 0,-1, 0,-5, 4, 4,-3, 0,-4,-4, 1,-2,-4,-2,-1,-1,-4,-3,-3, 0, 4,-1,-6\}, + \{-1,-2,-2,-2,-3,-1,-2,-2,-2,-2,-2,-1,-1,-2,-2,-1,-1,-3,-2,-2,-2,-1,-2,-6\}, + \{-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, 1\}, +\} +\end{DoxyCode} +\mbox{\Hypertarget{code_8c_a119a7eb0ecd417f83e41f4325ce522c8}\label{code_8c_a119a7eb0ecd417f83e41f4325ce522c8}} +\index{code.\+c@{code.\+c}!transcode@{transcode}} +\index{transcode@{transcode}!code.\+c@{code.\+c}} +\subsubsection{\texorpdfstring{transcode}{transcode}} +{\footnotesize\ttfamily int transcode\mbox{[}4\mbox{]}\mbox{[}4\mbox{]}\mbox{[}4\mbox{]}} + +{\bfseries Initial value\+:} +\begin{DoxyCode} +=\{\{\{ 11, 2 , 11, 2 \},\{ 16, 16, 16, 16\},\{ 1 , 15, 1 , 15\},\{ 9 , 9 , 12, 9 \}\}, + + + \{\{ 5 , 8 , 5 , 8 \},\{ 14, 14, 14, 14\},\{ 1 , 1 , 1 , 1 \},\{ 10, 10, 10, 10 \}\}, + + + \{\{ 6 , 3 , 6 , 3 \},\{ 0 , 0 , 0 , 0 \},\{ 7 , 7 , 7 , 7 \},\{ 19, 19, 19, 19\}\}, + + + \{\{ -1, 18, -1, 18\},\{ 15, 15, 15, 15\},\{ -1, 4 , 17, 4 \},\{ 10, 13, 10, 13\}\}\} +\end{DoxyCode} diff --git a/src/latex/code_8c__incl.md5 b/src/latex/code_8c__incl.md5 new file mode 100644 index 0000000..b4c3e41 --- /dev/null +++ b/src/latex/code_8c__incl.md5 @@ -0,0 +1 @@ +e3bc3766ebc349a415ec34aec38200ea \ No newline at end of file diff --git a/src/latex/code_8c__incl.pdf b/src/latex/code_8c__incl.pdf new file mode 100644 index 0000000..55f902d Binary files /dev/null and b/src/latex/code_8c__incl.pdf differ diff --git a/src/latex/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 b/src/latex/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 new file mode 100644 index 0000000..9adbaf4 --- /dev/null +++ b/src/latex/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 @@ -0,0 +1 @@ +b6f41da6cc93904b04d8a91d613808c9 \ No newline at end of file diff --git a/src/latex/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.pdf b/src/latex/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.pdf new file mode 100644 index 0000000..5385453 Binary files /dev/null and b/src/latex/code_8c_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.pdf differ diff --git a/src/latex/code_8h.tex b/src/latex/code_8h.tex new file mode 100644 index 0000000..934730e --- /dev/null +++ b/src/latex/code_8h.tex @@ -0,0 +1,56 @@ +\hypertarget{code_8h}{}\section{code.\+h File Reference} +\label{code_8h}\index{code.\+h@{code.\+h}} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{code_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +int $\ast$ \hyperlink{code_8h_a011bbc41b53a2519b2bb46214b7a1fcc}{encode\+Seq} (char $\ast$seq) +\item +int \hyperlink{code_8h_a617a88955038003d70de0d9113b505eb}{encode\+AA} (char aa) +\item +char \hyperlink{code_8h_a124646f7d65dd512584b8fbab1fcc7a4}{decode\+AA} (int encoded\+AA) +\item +char $\ast$ \hyperlink{code_8h_a8d64bc3ec5de4db181efd7ff565ff894}{translate\+Seq} (char $\ast$seq) +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{code_8h_a124646f7d65dd512584b8fbab1fcc7a4}\label{code_8h_a124646f7d65dd512584b8fbab1fcc7a4}} +\index{code.\+h@{code.\+h}!decode\+AA@{decode\+AA}} +\index{decode\+AA@{decode\+AA}!code.\+h@{code.\+h}} +\subsubsection{\texorpdfstring{decode\+A\+A()}{decodeAA()}} +{\footnotesize\ttfamily char decode\+AA (\begin{DoxyParamCaption}\item[{int}]{encoded\+AA }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{code_8h_a617a88955038003d70de0d9113b505eb}\label{code_8h_a617a88955038003d70de0d9113b505eb}} +\index{code.\+h@{code.\+h}!encode\+AA@{encode\+AA}} +\index{encode\+AA@{encode\+AA}!code.\+h@{code.\+h}} +\subsubsection{\texorpdfstring{encode\+A\+A()}{encodeAA()}} +{\footnotesize\ttfamily int encode\+AA (\begin{DoxyParamCaption}\item[{char}]{aa }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{code_8h_a011bbc41b53a2519b2bb46214b7a1fcc}\label{code_8h_a011bbc41b53a2519b2bb46214b7a1fcc}} +\index{code.\+h@{code.\+h}!encode\+Seq@{encode\+Seq}} +\index{encode\+Seq@{encode\+Seq}!code.\+h@{code.\+h}} +\subsubsection{\texorpdfstring{encode\+Seq()}{encodeSeq()}} +{\footnotesize\ttfamily int$\ast$ encode\+Seq (\begin{DoxyParamCaption}\item[{char $\ast$}]{seq }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{code_8h_a8d64bc3ec5de4db181efd7ff565ff894}\label{code_8h_a8d64bc3ec5de4db181efd7ff565ff894}} +\index{code.\+h@{code.\+h}!translate\+Seq@{translate\+Seq}} +\index{translate\+Seq@{translate\+Seq}!code.\+h@{code.\+h}} +\subsubsection{\texorpdfstring{translate\+Seq()}{translateSeq()}} +{\footnotesize\ttfamily char$\ast$ translate\+Seq (\begin{DoxyParamCaption}\item[{char $\ast$}]{seq }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=252pt]{code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph} +\end{center} +\end{figure} diff --git a/src/latex/code_8h__dep__incl.md5 b/src/latex/code_8h__dep__incl.md5 new file mode 100644 index 0000000..1f9f191 --- /dev/null +++ b/src/latex/code_8h__dep__incl.md5 @@ -0,0 +1 @@ +e9c00158172442b9afedb7ef9727b6d3 \ No newline at end of file diff --git a/src/latex/code_8h__dep__incl.pdf b/src/latex/code_8h__dep__incl.pdf new file mode 100644 index 0000000..f8ffa2c Binary files /dev/null and b/src/latex/code_8h__dep__incl.pdf differ diff --git a/src/latex/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 b/src/latex/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 new file mode 100644 index 0000000..9adbaf4 --- /dev/null +++ b/src/latex/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.md5 @@ -0,0 +1 @@ +b6f41da6cc93904b04d8a91d613808c9 \ No newline at end of file diff --git a/src/latex/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.pdf b/src/latex/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.pdf new file mode 100644 index 0000000..5385453 Binary files /dev/null and b/src/latex/code_8h_a8d64bc3ec5de4db181efd7ff565ff894_cgraph.pdf differ diff --git a/src/latex/deprecated.tex b/src/latex/deprecated.tex new file mode 100644 index 0000000..f18618b --- /dev/null +++ b/src/latex/deprecated.tex @@ -0,0 +1,6 @@ + +\begin{DoxyRefList} +\item[\label{deprecated__deprecated000001}% +\Hypertarget{deprecated__deprecated000001}% +Member \hyperlink{cmdline_8h_a08e3536edc64ec5ee7c2df546c6e9dd7}{cmdline\+\_\+parser2} (int argc, char $\ast$const $\ast$argv, struct \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} $\ast$args\+\_\+info, int override, int initialize, int check\+\_\+required)]use \hyperlink{cmdline_8c_a77e461b5bdfd4a36c59a96bfb1813e38}{cmdline\+\_\+parser\+\_\+ext()} instead +\end{DoxyRefList} \ No newline at end of file diff --git a/src/latex/doxygen.sty b/src/latex/doxygen.sty new file mode 100644 index 0000000..e457acc --- /dev/null +++ b/src/latex/doxygen.sty @@ -0,0 +1,503 @@ +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{doxygen} + +% Packages used by this style file +\RequirePackage{alltt} +\RequirePackage{array} +\RequirePackage{calc} +\RequirePackage{float} +\RequirePackage{ifthen} +\RequirePackage{verbatim} +\RequirePackage[table]{xcolor} +\RequirePackage{longtable} +\RequirePackage{tabu} +\RequirePackage{tabularx} +\RequirePackage{multirow} + +%---------- Internal commands used in this style file ---------------- + +\newcommand{\ensurespace}[1]{% + \begingroup% + \setlength{\dimen@}{#1}% + \vskip\z@\@plus\dimen@% + \penalty -100\vskip\z@\@plus -\dimen@% + \vskip\dimen@% + \penalty 9999% + \vskip -\dimen@% + \vskip\z@skip% hide the previous |\vskip| from |\addvspace| + \endgroup% +} + +\newcommand{\DoxyLabelFont}{} +\newcommand{\entrylabel}[1]{% + {% + \parbox[b]{\labelwidth-4pt}{% + \makebox[0pt][l]{\DoxyLabelFont#1}% + \vspace{1.5\baselineskip}% + }% + }% +} + +\newenvironment{DoxyDesc}[1]{% + \ensurespace{4\baselineskip}% + \begin{list}{}{% + \settowidth{\labelwidth}{20pt}% + \setlength{\parsep}{0pt}% + \setlength{\itemsep}{0pt}% + \setlength{\leftmargin}{\labelwidth+\labelsep}% + \renewcommand{\makelabel}{\entrylabel}% + }% + \item[#1]% +}{% + \end{list}% +} + +\newsavebox{\xrefbox} +\newlength{\xreflength} +\newcommand{\xreflabel}[1]{% + \sbox{\xrefbox}{#1}% + \setlength{\xreflength}{\wd\xrefbox}% + \ifthenelse{\xreflength>\labelwidth}{% + \begin{minipage}{\textwidth}% + \setlength{\parindent}{0pt}% + \hangindent=15pt\bfseries #1\vspace{1.2\itemsep}% + \end{minipage}% + }{% + \parbox[b]{\labelwidth}{\makebox[0pt][l]{\textbf{#1}}}% + }% +} + +%---------- Commands used by doxygen LaTeX output generator ---------- + +% Used by
 ... 
+\newenvironment{DoxyPre}{% + \small% + \begin{alltt}% +}{% + \end{alltt}% + \normalsize% +} + +% Used by @code ... @endcode +\newenvironment{DoxyCode}{% + \par% + \scriptsize% + \begin{alltt}% +}{% + \end{alltt}% + \normalsize% +} + +% Used by @example, @include, @includelineno and @dontinclude +\newenvironment{DoxyCodeInclude}{% + \DoxyCode% +}{% + \endDoxyCode% +} + +% Used by @verbatim ... @endverbatim +\newenvironment{DoxyVerb}{% + \footnotesize% + \verbatim% +}{% + \endverbatim% + \normalsize% +} + +% Used by @verbinclude +\newenvironment{DoxyVerbInclude}{% + \DoxyVerb% +}{% + \endDoxyVerb% +} + +% Used by numbered lists (using '-#' or
    ...
) +\newenvironment{DoxyEnumerate}{% + \enumerate% +}{% + \endenumerate% +} + +% Used by bullet lists (using '-', @li, @arg, or
    ...
) +\newenvironment{DoxyItemize}{% + \itemize% +}{% + \enditemize% +} + +% Used by description lists (using
...
) +\newenvironment{DoxyDescription}{% + \description% +}{% + \enddescription% +} + +% Used by @image, @dotfile, @dot ... @enddot, and @msc ... @endmsc +% (only if caption is specified) +\newenvironment{DoxyImage}{% + \begin{figure}[H]% + \begin{center}% +}{% + \end{center}% + \end{figure}% +} + +% Used by @image, @dotfile, @dot ... @enddot, and @msc ... @endmsc +% (only if no caption is specified) +\newenvironment{DoxyImageNoCaption}{% + \begin{center}% +}{% + \end{center}% +} + +% Used by @attention +\newenvironment{DoxyAttention}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @author and @authors +\newenvironment{DoxyAuthor}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @date +\newenvironment{DoxyDate}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @invariant +\newenvironment{DoxyInvariant}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @note +\newenvironment{DoxyNote}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @post +\newenvironment{DoxyPostcond}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @pre +\newenvironment{DoxyPrecond}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @copyright +\newenvironment{DoxyCopyright}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @remark +\newenvironment{DoxyRemark}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @return and @returns +\newenvironment{DoxyReturn}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @since +\newenvironment{DoxySince}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @see +\newenvironment{DoxySeeAlso}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @version +\newenvironment{DoxyVersion}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @warning +\newenvironment{DoxyWarning}[1]{% + \begin{DoxyDesc}{#1}% +}{% + \end{DoxyDesc}% +} + +% Used by @internal +\newenvironment{DoxyInternal}[1]{% + \paragraph*{#1}% +}{% +} + +% Used by @par and @paragraph +\newenvironment{DoxyParagraph}[1]{% + \begin{list}{}{% + \settowidth{\labelwidth}{40pt}% + \setlength{\leftmargin}{\labelwidth}% + \setlength{\parsep}{0pt}% + \setlength{\itemsep}{-4pt}% + \renewcommand{\makelabel}{\entrylabel}% + }% + \item[#1]% +}{% + \end{list}% +} + +% Used by parameter lists +\newenvironment{DoxyParams}[2][]{% + \tabulinesep=1mm% + \par% + \ifthenelse{\equal{#1}{}}% + {\begin{longtabu} spread 0pt [l]{|X[-1,l]|X[-1,l]|}}% name + description + {\ifthenelse{\equal{#1}{1}}% + {\begin{longtabu} spread 0pt [l]{|X[-1,l]|X[-1,l]|X[-1,l]|}}% in/out + name + desc + {\begin{longtabu} spread 0pt [l]{|X[-1,l]|X[-1,l]|X[-1,l]|X[-1,l]|}}% in/out + type + name + desc + } + \multicolumn{2}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #2}\\[1ex]% + \hline% + \endfirsthead% + \multicolumn{2}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #2}\\[1ex]% + \hline% + \endhead% +}{% + \end{longtabu}% + \vspace{6pt}% +} + +% Used for fields of simple structs +\newenvironment{DoxyFields}[1]{% + \tabulinesep=1mm% + \par% + \begin{longtabu} spread 0pt [l]{|X[-1,r]|X[-1,l]|X[-1,l]|}% + \multicolumn{3}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #1}\\[1ex]% + \hline% + \endfirsthead% + \multicolumn{3}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #1}\\[1ex]% + \hline% + \endhead% +}{% + \end{longtabu}% + \vspace{6pt}% +} + +% Used for fields simple class style enums +\newenvironment{DoxyEnumFields}[1]{% + \tabulinesep=1mm% + \par% + \begin{longtabu} spread 0pt [l]{|X[-1,r]|X[-1,l]|}% + \multicolumn{2}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #1}\\[1ex]% + \hline% + \endfirsthead% + \multicolumn{2}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #1}\\[1ex]% + \hline% + \endhead% +}{% + \end{longtabu}% + \vspace{6pt}% +} + +% Used for parameters within a detailed function description +\newenvironment{DoxyParamCaption}{% + \renewcommand{\item}[2][]{\\ \hspace*{2.0cm} ##1 {\em ##2}}% +}{% +} + +% Used by return value lists +\newenvironment{DoxyRetVals}[1]{% + \tabulinesep=1mm% + \par% + \begin{longtabu} spread 0pt [l]{|X[-1,r]|X[-1,l]|}% + \multicolumn{2}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #1}\\[1ex]% + \hline% + \endfirsthead% + \multicolumn{2}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #1}\\[1ex]% + \hline% + \endhead% +}{% + \end{longtabu}% + \vspace{6pt}% +} + +% Used by exception lists +\newenvironment{DoxyExceptions}[1]{% + \tabulinesep=1mm% + \par% + \begin{longtabu} spread 0pt [l]{|X[-1,r]|X[-1,l]|}% + \multicolumn{2}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #1}\\[1ex]% + \hline% + \endfirsthead% + \multicolumn{2}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #1}\\[1ex]% + \hline% + \endhead% +}{% + \end{longtabu}% + \vspace{6pt}% +} + +% Used by template parameter lists +\newenvironment{DoxyTemplParams}[1]{% + \tabulinesep=1mm% + \par% + \begin{longtabu} spread 0pt [l]{|X[-1,r]|X[-1,l]|}% + \multicolumn{2}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #1}\\[1ex]% + \hline% + \endfirsthead% + \multicolumn{2}{l}{\hspace{-6pt}\bfseries\fontseries{bc}\selectfont\color{darkgray} #1}\\[1ex]% + \hline% + \endhead% +}{% + \end{longtabu}% + \vspace{6pt}% +} + +% Used for member lists +\newenvironment{DoxyCompactItemize}{% + \begin{itemize}% + \setlength{\itemsep}{-3pt}% + \setlength{\parsep}{0pt}% + \setlength{\topsep}{0pt}% + \setlength{\partopsep}{0pt}% +}{% + \end{itemize}% +} + +% Used for member descriptions +\newenvironment{DoxyCompactList}{% + \begin{list}{}{% + \setlength{\leftmargin}{0.5cm}% + \setlength{\itemsep}{0pt}% + \setlength{\parsep}{0pt}% + \setlength{\topsep}{0pt}% + \renewcommand{\makelabel}{\hfill}% + }% +}{% + \end{list}% +} + +% Used for reference lists (@bug, @deprecated, @todo, etc.) +\newenvironment{DoxyRefList}{% + \begin{list}{}{% + \setlength{\labelwidth}{10pt}% + \setlength{\leftmargin}{\labelwidth}% + \addtolength{\leftmargin}{\labelsep}% + \renewcommand{\makelabel}{\xreflabel}% + }% +}{% + \end{list}% +} + +% Used by @bug, @deprecated, @todo, etc. +\newenvironment{DoxyRefDesc}[1]{% + \begin{list}{}{% + \renewcommand\makelabel[1]{\textbf{##1}}% + \settowidth\labelwidth{\makelabel{#1}}% + \setlength\leftmargin{\labelwidth+\labelsep}% + }% +}{% + \end{list}% +} + +% Used by parameter lists and simple sections +\newenvironment{Desc} +{\begin{list}{}{% + \settowidth{\labelwidth}{20pt}% + \setlength{\parsep}{0pt}% + \setlength{\itemsep}{0pt}% + \setlength{\leftmargin}{\labelwidth+\labelsep}% + \renewcommand{\makelabel}{\entrylabel}% + } +}{% + \end{list}% +} + +% Used by tables +\newcommand{\PBS}[1]{\let\temp=\\#1\let\\=\temp}% +\newenvironment{TabularC}[1]% +{\tabulinesep=1mm +\begin{longtabu} spread 0pt [c]{*#1{|X[-1]}|}}% +{\end{longtabu}\par}% + +\newenvironment{TabularNC}[1]% +{\begin{tabu} spread 0pt [l]{*#1{|X[-1]}|}}% +{\end{tabu}\par}% + +% Used for member group headers +\newenvironment{Indent}{% + \begin{list}{}{% + \setlength{\leftmargin}{0.5cm}% + }% + \item[]\ignorespaces% +}{% + \unskip% + \end{list}% +} + +% Used when hyperlinks are turned off +\newcommand{\doxyref}[3]{% + \textbf{#1} (\textnormal{#2}\,\pageref{#3})% +} + +% Used to link to a table when hyperlinks are turned on +\newcommand{\doxytablelink}[2]{% + \ref{#1}% +} + +% Used to link to a table when hyperlinks are turned off +\newcommand{\doxytableref}[3]{% + \ref{#3}% +} + +% Used by @addindex +\newcommand{\lcurly}{\{} +\newcommand{\rcurly}{\}} + +% Colors used for syntax highlighting +\definecolor{comment}{rgb}{0.5,0.0,0.0} +\definecolor{keyword}{rgb}{0.0,0.5,0.0} +\definecolor{keywordtype}{rgb}{0.38,0.25,0.125} +\definecolor{keywordflow}{rgb}{0.88,0.5,0.0} +\definecolor{preprocessor}{rgb}{0.5,0.38,0.125} +\definecolor{stringliteral}{rgb}{0.0,0.125,0.25} +\definecolor{charliteral}{rgb}{0.0,0.5,0.5} +\definecolor{vhdldigit}{rgb}{1.0,0.0,1.0} +\definecolor{vhdlkeyword}{rgb}{0.43,0.0,0.43} +\definecolor{vhdllogic}{rgb}{1.0,0.0,0.0} +\definecolor{vhdlchar}{rgb}{0.0,0.0,0.0} + +% Color used for table heading +\newcommand{\tableheadbgcolor}{lightgray}% + +% Version of hypertarget with correct landing location +\newcommand{\Hypertarget}[1]{\Hy@raisedlink{\hypertarget{#1}{}}} + +% Define caption that is also suitable in a table +\makeatletter +\def\doxyfigcaption{% +\refstepcounter{figure}% +\@dblarg{\@caption{figure}}} +\makeatother diff --git a/src/latex/extreme__fit_8c.tex b/src/latex/extreme__fit_8c.tex new file mode 100644 index 0000000..483bfea --- /dev/null +++ b/src/latex/extreme__fit_8c.tex @@ -0,0 +1,53 @@ +\hypertarget{extreme__fit_8c}{}\section{extreme\+\_\+fit.\+c File Reference} +\label{extreme__fit_8c}\index{extreme\+\_\+fit.\+c@{extreme\+\_\+fit.\+c}} +{\ttfamily \#include $<$stdlib.\+h$>$}\newline +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include $<$math.\+h$>$}\newline +{\ttfamily \#include \char`\"{}extreme\+\_\+fit.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}lm.\+h\char`\"{}}\newline +Include dependency graph for extreme\+\_\+fit.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{extreme__fit_8c__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +void \hyperlink{extreme__fit_8c_ac7d28c2cfa789de3864ed5d07ef800ec}{Lawless416} (double $\ast$x, int $\ast$y, int n, double lambda, double $\ast$ret\+\_\+f, double $\ast$ret\+\_\+df) +\item +void \hyperlink{extreme__fit_8c_a05c76c8801e372734c3888b165c28f86}{Lawless422} (double $\ast$x, int $\ast$y, int n, int z, double c, double lambda, double $\ast$ret\+\_\+f, double $\ast$ret\+\_\+df) +\item +int \hyperlink{extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984}{E\+V\+D\+Max\+Likely\+Fit} (double $\ast$x, int $\ast$c, int n, double $\ast$ret\+\_\+mu, double $\ast$ret\+\_\+lambda) +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984}\label{extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984}} +\index{extreme\+\_\+fit.\+c@{extreme\+\_\+fit.\+c}!E\+V\+D\+Max\+Likely\+Fit@{E\+V\+D\+Max\+Likely\+Fit}} +\index{E\+V\+D\+Max\+Likely\+Fit@{E\+V\+D\+Max\+Likely\+Fit}!extreme\+\_\+fit.\+c@{extreme\+\_\+fit.\+c}} +\subsubsection{\texorpdfstring{E\+V\+D\+Max\+Likely\+Fit()}{EVDMaxLikelyFit()}} +{\footnotesize\ttfamily int E\+V\+D\+Max\+Likely\+Fit (\begin{DoxyParamCaption}\item[{double $\ast$}]{x, }\item[{int $\ast$}]{c, }\item[{int}]{n, }\item[{double $\ast$}]{ret\+\_\+mu, }\item[{double $\ast$}]{ret\+\_\+lambda }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=277pt]{extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{extreme__fit_8c_ac7d28c2cfa789de3864ed5d07ef800ec}\label{extreme__fit_8c_ac7d28c2cfa789de3864ed5d07ef800ec}} +\index{extreme\+\_\+fit.\+c@{extreme\+\_\+fit.\+c}!Lawless416@{Lawless416}} +\index{Lawless416@{Lawless416}!extreme\+\_\+fit.\+c@{extreme\+\_\+fit.\+c}} +\subsubsection{\texorpdfstring{Lawless416()}{Lawless416()}} +{\footnotesize\ttfamily void Lawless416 (\begin{DoxyParamCaption}\item[{double $\ast$}]{x, }\item[{int $\ast$}]{y, }\item[{int}]{n, }\item[{double}]{lambda, }\item[{double $\ast$}]{ret\+\_\+f, }\item[{double $\ast$}]{ret\+\_\+df }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{extreme__fit_8c_a05c76c8801e372734c3888b165c28f86}\label{extreme__fit_8c_a05c76c8801e372734c3888b165c28f86}} +\index{extreme\+\_\+fit.\+c@{extreme\+\_\+fit.\+c}!Lawless422@{Lawless422}} +\index{Lawless422@{Lawless422}!extreme\+\_\+fit.\+c@{extreme\+\_\+fit.\+c}} +\subsubsection{\texorpdfstring{Lawless422()}{Lawless422()}} +{\footnotesize\ttfamily void Lawless422 (\begin{DoxyParamCaption}\item[{double $\ast$}]{x, }\item[{int $\ast$}]{y, }\item[{int}]{n, }\item[{int}]{z, }\item[{double}]{c, }\item[{double}]{lambda, }\item[{double $\ast$}]{ret\+\_\+f, }\item[{double $\ast$}]{ret\+\_\+df }\end{DoxyParamCaption})} + diff --git a/src/latex/extreme__fit_8c__incl.md5 b/src/latex/extreme__fit_8c__incl.md5 new file mode 100644 index 0000000..4141c8b --- /dev/null +++ b/src/latex/extreme__fit_8c__incl.md5 @@ -0,0 +1 @@ +707e05b05165b32b45d652301f4cad35 \ No newline at end of file diff --git a/src/latex/extreme__fit_8c__incl.pdf b/src/latex/extreme__fit_8c__incl.pdf new file mode 100644 index 0000000..07682dc Binary files /dev/null and b/src/latex/extreme__fit_8c__incl.pdf differ diff --git a/src/latex/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 b/src/latex/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 new file mode 100644 index 0000000..c2936dc --- /dev/null +++ b/src/latex/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 @@ -0,0 +1 @@ +a2ca527923484faf26237497112f7efe \ No newline at end of file diff --git a/src/latex/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.pdf b/src/latex/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.pdf new file mode 100644 index 0000000..6f2ef3a Binary files /dev/null and b/src/latex/extreme__fit_8c_a51c7409c6447353e0bd3b7c48d982984_cgraph.pdf differ diff --git a/src/latex/extreme__fit_8h.tex b/src/latex/extreme__fit_8h.tex new file mode 100644 index 0000000..5052339 --- /dev/null +++ b/src/latex/extreme__fit_8h.tex @@ -0,0 +1,32 @@ +\hypertarget{extreme__fit_8h}{}\section{extreme\+\_\+fit.\+h File Reference} +\label{extreme__fit_8h}\index{extreme\+\_\+fit.\+h@{extreme\+\_\+fit.\+h}} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=308pt]{extreme__fit_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +int \hyperlink{extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984}{E\+V\+D\+Max\+Likely\+Fit} (double $\ast$x, int $\ast$c, int n, double $\ast$ret\+\_\+mu, double $\ast$ret\+\_\+lambda) +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984}\label{extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984}} +\index{extreme\+\_\+fit.\+h@{extreme\+\_\+fit.\+h}!E\+V\+D\+Max\+Likely\+Fit@{E\+V\+D\+Max\+Likely\+Fit}} +\index{E\+V\+D\+Max\+Likely\+Fit@{E\+V\+D\+Max\+Likely\+Fit}!extreme\+\_\+fit.\+h@{extreme\+\_\+fit.\+h}} +\subsubsection{\texorpdfstring{E\+V\+D\+Max\+Likely\+Fit()}{EVDMaxLikelyFit()}} +{\footnotesize\ttfamily int E\+V\+D\+Max\+Likely\+Fit (\begin{DoxyParamCaption}\item[{double $\ast$}]{x, }\item[{int $\ast$}]{c, }\item[{int}]{n, }\item[{double $\ast$}]{ret\+\_\+mu, }\item[{double $\ast$}]{ret\+\_\+lambda }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=277pt]{extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph} +\end{center} +\end{figure} diff --git a/src/latex/extreme__fit_8h__dep__incl.md5 b/src/latex/extreme__fit_8h__dep__incl.md5 new file mode 100644 index 0000000..babe5eb --- /dev/null +++ b/src/latex/extreme__fit_8h__dep__incl.md5 @@ -0,0 +1 @@ +d9abd4fdf5de73eb3255b545e4d6555f \ No newline at end of file diff --git a/src/latex/extreme__fit_8h__dep__incl.pdf b/src/latex/extreme__fit_8h__dep__incl.pdf new file mode 100644 index 0000000..846c2a9 Binary files /dev/null and b/src/latex/extreme__fit_8h__dep__incl.pdf differ diff --git a/src/latex/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 b/src/latex/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 new file mode 100644 index 0000000..c2936dc --- /dev/null +++ b/src/latex/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.md5 @@ -0,0 +1 @@ +a2ca527923484faf26237497112f7efe \ No newline at end of file diff --git a/src/latex/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.pdf b/src/latex/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.pdf new file mode 100644 index 0000000..6f2ef3a Binary files /dev/null and b/src/latex/extreme__fit_8h_a51c7409c6447353e0bd3b7c48d982984_cgraph.pdf differ diff --git a/src/latex/files.tex b/src/latex/files.tex new file mode 100644 index 0000000..d791c97 --- /dev/null +++ b/src/latex/files.tex @@ -0,0 +1,29 @@ +\section{File List} +Here is a list of all files with brief descriptions\+:\begin{DoxyCompactList} +\item\contentsline{section}{\hyperlink{cmdline_8c}{cmdline.\+c} }{\pageref{cmdline_8c}}{} +\item\contentsline{section}{\hyperlink{cmdline_8h}{cmdline.\+h} \\*The header file for the command line option parser generated by G\+NU Gengetopt version 2.\+22.\+1 \href{http://www.gnu.org/software/gengetopt}{\tt http\+://www.\+gnu.\+org/software/gengetopt}. DO N\+OT modify this file, since it can be overwritten }{\pageref{cmdline_8h}}{} +\item\contentsline{section}{\hyperlink{code_8c}{code.\+c} }{\pageref{code_8c}}{} +\item\contentsline{section}{\hyperlink{code_8h}{code.\+h} }{\pageref{code_8h}}{} +\item\contentsline{section}{\hyperlink{extreme__fit_8c}{extreme\+\_\+fit.\+c} }{\pageref{extreme__fit_8c}}{} +\item\contentsline{section}{\hyperlink{extreme__fit_8h}{extreme\+\_\+fit.\+h} }{\pageref{extreme__fit_8h}}{} +\item\contentsline{section}{\hyperlink{getopt_8c}{getopt.\+c} }{\pageref{getopt_8c}}{} +\item\contentsline{section}{\hyperlink{getopt_8h}{getopt.\+h} }{\pageref{getopt_8h}}{} +\item\contentsline{section}{\hyperlink{misc_8c}{misc.\+c} }{\pageref{misc_8c}}{} +\item\contentsline{section}{\hyperlink{misc_8h}{misc.\+h} }{\pageref{misc_8h}}{} +\item\contentsline{section}{\hyperlink{postscript_8c}{postscript.\+c} }{\pageref{postscript_8c}}{} +\item\contentsline{section}{\hyperlink{postscript_8h}{postscript.\+h} }{\pageref{postscript_8h}}{} +\item\contentsline{section}{\hyperlink{RNAcode_8c}{R\+N\+Acode.\+c} }{\pageref{RNAcode_8c}}{} +\item\contentsline{section}{\hyperlink{RNAcode_8h}{R\+N\+Acode.\+h} }{\pageref{RNAcode_8h}}{} +\item\contentsline{section}{\hyperlink{rnaz__utils_8c}{rnaz\+\_\+utils.\+c} }{\pageref{rnaz__utils_8c}}{} +\item\contentsline{section}{\hyperlink{rnaz__utils_8h}{rnaz\+\_\+utils.\+h} }{\pageref{rnaz__utils_8h}}{} +\item\contentsline{section}{\hyperlink{score_8c}{score.\+c} }{\pageref{score_8c}}{} +\item\contentsline{section}{\hyperlink{score_8h}{score.\+h} }{\pageref{score_8h}}{} +\item\contentsline{section}{\hyperlink{treeML_8c}{tree\+M\+L.\+c} }{\pageref{treeML_8c}}{} +\item\contentsline{section}{\hyperlink{treeML_8h}{tree\+M\+L.\+h} }{\pageref{treeML_8h}}{} +\item\contentsline{section}{\hyperlink{treeSimulate_8c}{tree\+Simulate.\+c} }{\pageref{treeSimulate_8c}}{} +\item\contentsline{section}{\hyperlink{treeSimulate_8h}{tree\+Simulate.\+h} }{\pageref{treeSimulate_8h}}{} +\item\contentsline{section}{\hyperlink{utils_8c}{utils.\+c} }{\pageref{utils_8c}}{} +\item\contentsline{section}{\hyperlink{utils_8h}{utils.\+h} }{\pageref{utils_8h}}{} +\item\contentsline{section}{\hyperlink{weight_8c}{weight.\+c} }{\pageref{weight_8c}}{} +\item\contentsline{section}{\hyperlink{weight_8h}{weight.\+h} }{\pageref{weight_8h}}{} +\end{DoxyCompactList} diff --git a/src/latex/getopt_8c.tex b/src/latex/getopt_8c.tex new file mode 100644 index 0000000..2e3ee40 --- /dev/null +++ b/src/latex/getopt_8c.tex @@ -0,0 +1,268 @@ +\hypertarget{getopt_8c}{}\section{getopt.\+c File Reference} +\label{getopt_8c}\index{getopt.\+c@{getopt.\+c}} +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include \char`\"{}getopt.\+h\char`\"{}}\newline +{\ttfamily \#include $<$strings.\+h$>$}\newline +Include dependency graph for getopt.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=268pt]{getopt_8c__incl} +\end{center} +\end{figure} +\subsection*{Macros} +\begin{DoxyCompactItemize} +\item +\#define \hyperlink{getopt_8c_a9bcd7db9771ff03b7e5a9fec9c489861}{\+\_\+\+N\+O\+\_\+\+P\+R\+O\+TO} +\item +\#define \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} +\item +\#define \hyperlink{getopt_8c_a5325c715897861c318d3ae312ac452cc}{G\+E\+T\+O\+P\+T\+\_\+\+I\+N\+T\+E\+R\+F\+A\+C\+E\+\_\+\+V\+E\+R\+S\+I\+ON}~2 +\item +\#define \hyperlink{getopt_8c_a86a239addea586602343007a370bf8ad}{\+\_\+}(msgid)~(msgid) +\item +\#define \hyperlink{getopt_8c_a6e06e56c5fa96faaf47f3b231e015e35}{S\+W\+A\+P\+\_\+\+F\+L\+A\+GS}(ch1, ch2) +\item +\#define \hyperlink{getopt_8c_a71ceb8911d64b39b402041ba5ea8453c}{N\+O\+N\+O\+P\+T\+I\+O\+N\+\_\+P}~(argv\mbox{[}\hyperlink{getopt_8h_ad5e1c16213bbee2d5e8cc363309f418c}{optind}\mbox{]}\mbox{[}0\mbox{]} != \textquotesingle{}-\/\textquotesingle{} $\vert$$\vert$ argv\mbox{[}\hyperlink{getopt_8h_ad5e1c16213bbee2d5e8cc363309f418c}{optind}\mbox{]}\mbox{[}1\mbox{]} == \textquotesingle{}\textbackslash{}0\textquotesingle{}) +\end{DoxyCompactItemize} +\subsection*{Enumerations} +\begin{DoxyCompactItemize} +\item +enum \{ \hyperlink{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55ba0e73a0691c110b1442d8364d1d12eccc}{R\+E\+Q\+U\+I\+R\+E\+\_\+\+O\+R\+D\+ER}, +\hyperlink{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55bacfdde4b47c27f4efbd832e1ac7f8a8fc}{P\+E\+R\+M\+U\+TE}, +\hyperlink{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55ba3c56550bfafe809d9214b863b69c31c5}{R\+E\+T\+U\+R\+N\+\_\+\+I\+N\+\_\+\+O\+R\+D\+ER} + \} +\end{DoxyCompactItemize} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +char $\ast$ \hyperlink{getopt_8c_aee28fd8a0e40b6d958f7d20348e45368}{getenv} () +\item +static char $\ast$ \hyperlink{getopt_8c_ae0ac978b7775f69496c0f127ffdada9d}{my\+\_\+index} (char $\ast$str, int chr) \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} +\item +static void \hyperlink{getopt_8c_a4621659dd6377e52ac50a0869625bb6e}{exchange} (char $\ast$$\ast$argv) +\item +static \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f}{\+\_\+getopt\+\_\+initialize} (int argc, char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$argv, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$optstring) +\item +int \hyperlink{getopt_8c_a0df92a0ae8fe1fd43268c738f548674f}{\+\_\+getopt\+\_\+internal} (int argc, char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$argv, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$optstring, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structoption}{option} $\ast$longopts, int $\ast$longind, int long\+\_\+only) +\item +int \hyperlink{getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e}{getopt} (int argc, char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$argv, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$optstring) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +char $\ast$ \hyperlink{getopt_8c_adb50a0eab9fed92fc3bfc7dfa4f2c410}{optarg} +\item +int \hyperlink{getopt_8c_ad5e1c16213bbee2d5e8cc363309f418c}{optind} = 1 +\item +int \hyperlink{getopt_8c_a28286be757527aeb1db951b5da9aeec1}{\+\_\+\+\_\+getopt\+\_\+initialized} +\item +static char $\ast$ \hyperlink{getopt_8c_a47a40a4c365dae45f94751ad32aab530}{nextchar} +\item +int \hyperlink{getopt_8c_ae30f05ee1e2e5652f174a35c7875d25e}{opterr} = 1 +\item +int \hyperlink{getopt_8c_a475b8db98445da73e5f62a1ef6324b95}{optopt} = \textquotesingle{}?\textquotesingle{} +\item +static enum \{ ... \} \hyperlink{getopt_8c_a67a84cf4dacaa8337be68345f8b9a8cc}{ordering} +\item +static char $\ast$ \hyperlink{getopt_8c_ad0ccb64bbd4defe7a57dbad2045ddd14}{posixly\+\_\+correct} +\item +static int \hyperlink{getopt_8c_a7b0f4f3bfbee147113f282427ce933ed}{first\+\_\+nonopt} +\item +static int \hyperlink{getopt_8c_a580f2c2acf35dad51ca18b427212bf15}{last\+\_\+nonopt} +\end{DoxyCompactItemize} + + +\subsection{Macro Definition Documentation} +\mbox{\Hypertarget{getopt_8c_a86a239addea586602343007a370bf8ad}\label{getopt_8c_a86a239addea586602343007a370bf8ad}} +\index{getopt.\+c@{getopt.\+c}!\+\_\+@{\+\_\+}} +\index{\+\_\+@{\+\_\+}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{\+\_\+}{\_}} +{\footnotesize\ttfamily \#define \+\_\+(\begin{DoxyParamCaption}\item[{}]{msgid }\end{DoxyParamCaption})~(msgid)} + +\mbox{\Hypertarget{getopt_8c_a9bcd7db9771ff03b7e5a9fec9c489861}\label{getopt_8c_a9bcd7db9771ff03b7e5a9fec9c489861}} +\index{getopt.\+c@{getopt.\+c}!\+\_\+\+N\+O\+\_\+\+P\+R\+O\+TO@{\+\_\+\+N\+O\+\_\+\+P\+R\+O\+TO}} +\index{\+\_\+\+N\+O\+\_\+\+P\+R\+O\+TO@{\+\_\+\+N\+O\+\_\+\+P\+R\+O\+TO}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{\+\_\+\+N\+O\+\_\+\+P\+R\+O\+TO}{\_NO\_PROTO}} +{\footnotesize\ttfamily \#define \+\_\+\+N\+O\+\_\+\+P\+R\+O\+TO} + +\mbox{\Hypertarget{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}\label{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}} +\index{getopt.\+c@{getopt.\+c}!const@{const}} +\index{const@{const}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{const}{const}} +{\footnotesize\ttfamily \#define const} + +\mbox{\Hypertarget{getopt_8c_a5325c715897861c318d3ae312ac452cc}\label{getopt_8c_a5325c715897861c318d3ae312ac452cc}} +\index{getopt.\+c@{getopt.\+c}!G\+E\+T\+O\+P\+T\+\_\+\+I\+N\+T\+E\+R\+F\+A\+C\+E\+\_\+\+V\+E\+R\+S\+I\+ON@{G\+E\+T\+O\+P\+T\+\_\+\+I\+N\+T\+E\+R\+F\+A\+C\+E\+\_\+\+V\+E\+R\+S\+I\+ON}} +\index{G\+E\+T\+O\+P\+T\+\_\+\+I\+N\+T\+E\+R\+F\+A\+C\+E\+\_\+\+V\+E\+R\+S\+I\+ON@{G\+E\+T\+O\+P\+T\+\_\+\+I\+N\+T\+E\+R\+F\+A\+C\+E\+\_\+\+V\+E\+R\+S\+I\+ON}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{G\+E\+T\+O\+P\+T\+\_\+\+I\+N\+T\+E\+R\+F\+A\+C\+E\+\_\+\+V\+E\+R\+S\+I\+ON}{GETOPT\_INTERFACE\_VERSION}} +{\footnotesize\ttfamily \#define G\+E\+T\+O\+P\+T\+\_\+\+I\+N\+T\+E\+R\+F\+A\+C\+E\+\_\+\+V\+E\+R\+S\+I\+ON~2} + +\mbox{\Hypertarget{getopt_8c_a71ceb8911d64b39b402041ba5ea8453c}\label{getopt_8c_a71ceb8911d64b39b402041ba5ea8453c}} +\index{getopt.\+c@{getopt.\+c}!N\+O\+N\+O\+P\+T\+I\+O\+N\+\_\+P@{N\+O\+N\+O\+P\+T\+I\+O\+N\+\_\+P}} +\index{N\+O\+N\+O\+P\+T\+I\+O\+N\+\_\+P@{N\+O\+N\+O\+P\+T\+I\+O\+N\+\_\+P}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{N\+O\+N\+O\+P\+T\+I\+O\+N\+\_\+P}{NONOPTION\_P}} +{\footnotesize\ttfamily \#define N\+O\+N\+O\+P\+T\+I\+O\+N\+\_\+P~(argv\mbox{[}\hyperlink{getopt_8h_ad5e1c16213bbee2d5e8cc363309f418c}{optind}\mbox{]}\mbox{[}0\mbox{]} != \textquotesingle{}-\/\textquotesingle{} $\vert$$\vert$ argv\mbox{[}\hyperlink{getopt_8h_ad5e1c16213bbee2d5e8cc363309f418c}{optind}\mbox{]}\mbox{[}1\mbox{]} == \textquotesingle{}\textbackslash{}0\textquotesingle{})} + +\mbox{\Hypertarget{getopt_8c_a6e06e56c5fa96faaf47f3b231e015e35}\label{getopt_8c_a6e06e56c5fa96faaf47f3b231e015e35}} +\index{getopt.\+c@{getopt.\+c}!S\+W\+A\+P\+\_\+\+F\+L\+A\+GS@{S\+W\+A\+P\+\_\+\+F\+L\+A\+GS}} +\index{S\+W\+A\+P\+\_\+\+F\+L\+A\+GS@{S\+W\+A\+P\+\_\+\+F\+L\+A\+GS}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{S\+W\+A\+P\+\_\+\+F\+L\+A\+GS}{SWAP\_FLAGS}} +{\footnotesize\ttfamily \#define S\+W\+A\+P\+\_\+\+F\+L\+A\+GS(\begin{DoxyParamCaption}\item[{}]{ch1, }\item[{}]{ch2 }\end{DoxyParamCaption})} + + + +\subsection{Enumeration Type Documentation} +\mbox{\Hypertarget{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55b}\label{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55b}} +\subsubsection{\texorpdfstring{anonymous enum}{anonymous enum}} +{\footnotesize\ttfamily anonymous enum} + +\begin{DoxyEnumFields}{Enumerator} +\raisebox{\heightof{T}}[0pt][0pt]{\index{R\+E\+Q\+U\+I\+R\+E\+\_\+\+O\+R\+D\+ER@{R\+E\+Q\+U\+I\+R\+E\+\_\+\+O\+R\+D\+ER}!getopt.\+c@{getopt.\+c}}\index{getopt.\+c@{getopt.\+c}!R\+E\+Q\+U\+I\+R\+E\+\_\+\+O\+R\+D\+ER@{R\+E\+Q\+U\+I\+R\+E\+\_\+\+O\+R\+D\+ER}}}\mbox{\Hypertarget{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55ba0e73a0691c110b1442d8364d1d12eccc}\label{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55ba0e73a0691c110b1442d8364d1d12eccc}} +R\+E\+Q\+U\+I\+R\+E\+\_\+\+O\+R\+D\+ER&\\ +\hline + +\raisebox{\heightof{T}}[0pt][0pt]{\index{P\+E\+R\+M\+U\+TE@{P\+E\+R\+M\+U\+TE}!getopt.\+c@{getopt.\+c}}\index{getopt.\+c@{getopt.\+c}!P\+E\+R\+M\+U\+TE@{P\+E\+R\+M\+U\+TE}}}\mbox{\Hypertarget{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55bacfdde4b47c27f4efbd832e1ac7f8a8fc}\label{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55bacfdde4b47c27f4efbd832e1ac7f8a8fc}} +P\+E\+R\+M\+U\+TE&\\ +\hline + +\raisebox{\heightof{T}}[0pt][0pt]{\index{R\+E\+T\+U\+R\+N\+\_\+\+I\+N\+\_\+\+O\+R\+D\+ER@{R\+E\+T\+U\+R\+N\+\_\+\+I\+N\+\_\+\+O\+R\+D\+ER}!getopt.\+c@{getopt.\+c}}\index{getopt.\+c@{getopt.\+c}!R\+E\+T\+U\+R\+N\+\_\+\+I\+N\+\_\+\+O\+R\+D\+ER@{R\+E\+T\+U\+R\+N\+\_\+\+I\+N\+\_\+\+O\+R\+D\+ER}}}\mbox{\Hypertarget{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55ba3c56550bfafe809d9214b863b69c31c5}\label{getopt_8c_a06fc87d81c62e9abb8790b6e5713c55ba3c56550bfafe809d9214b863b69c31c5}} +R\+E\+T\+U\+R\+N\+\_\+\+I\+N\+\_\+\+O\+R\+D\+ER&\\ +\hline + +\end{DoxyEnumFields} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f}\label{getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f}} +\index{getopt.\+c@{getopt.\+c}!\+\_\+getopt\+\_\+initialize@{\+\_\+getopt\+\_\+initialize}} +\index{\+\_\+getopt\+\_\+initialize@{\+\_\+getopt\+\_\+initialize}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{\+\_\+getopt\+\_\+initialize()}{\_getopt\_initialize()}} +{\footnotesize\ttfamily static \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ \+\_\+getopt\+\_\+initialize (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$}]{argv, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{optstring }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=251pt]{getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{getopt_8c_a0df92a0ae8fe1fd43268c738f548674f}\label{getopt_8c_a0df92a0ae8fe1fd43268c738f548674f}} +\index{getopt.\+c@{getopt.\+c}!\+\_\+getopt\+\_\+internal@{\+\_\+getopt\+\_\+internal}} +\index{\+\_\+getopt\+\_\+internal@{\+\_\+getopt\+\_\+internal}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{\+\_\+getopt\+\_\+internal()}{\_getopt\_internal()}} +{\footnotesize\ttfamily int \+\_\+getopt\+\_\+internal (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$}]{argv, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{optstring, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structoption}{option} $\ast$}]{longopts, }\item[{int $\ast$}]{longind, }\item[{int}]{long\+\_\+only }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{getopt_8c_a4621659dd6377e52ac50a0869625bb6e}\label{getopt_8c_a4621659dd6377e52ac50a0869625bb6e}} +\index{getopt.\+c@{getopt.\+c}!exchange@{exchange}} +\index{exchange@{exchange}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{exchange()}{exchange()}} +{\footnotesize\ttfamily static void exchange (\begin{DoxyParamCaption}\item[{char $\ast$$\ast$}]{argv }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=346pt]{getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{getopt_8c_aee28fd8a0e40b6d958f7d20348e45368}\label{getopt_8c_aee28fd8a0e40b6d958f7d20348e45368}} +\index{getopt.\+c@{getopt.\+c}!getenv@{getenv}} +\index{getenv@{getenv}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{getenv()}{getenv()}} +{\footnotesize\ttfamily char$\ast$ getenv (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e}\label{getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e}} +\index{getopt.\+c@{getopt.\+c}!getopt@{getopt}} +\index{getopt@{getopt}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{getopt()}{getopt()}} +{\footnotesize\ttfamily int getopt (\begin{DoxyParamCaption}\item[{int}]{argc, }\item[{char $\ast$\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} $\ast$}]{argv, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{optstring }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{getopt_8c_ae0ac978b7775f69496c0f127ffdada9d}\label{getopt_8c_ae0ac978b7775f69496c0f127ffdada9d}} +\index{getopt.\+c@{getopt.\+c}!my\+\_\+index@{my\+\_\+index}} +\index{my\+\_\+index@{my\+\_\+index}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{my\+\_\+index()}{my\_index()}} +{\footnotesize\ttfamily static char$\ast$ my\+\_\+index (\begin{DoxyParamCaption}\item[{char $\ast$}]{str, }\item[{int}]{chr }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [static]}} + + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{getopt_8c_a28286be757527aeb1db951b5da9aeec1}\label{getopt_8c_a28286be757527aeb1db951b5da9aeec1}} +\index{getopt.\+c@{getopt.\+c}!\+\_\+\+\_\+getopt\+\_\+initialized@{\+\_\+\+\_\+getopt\+\_\+initialized}} +\index{\+\_\+\+\_\+getopt\+\_\+initialized@{\+\_\+\+\_\+getopt\+\_\+initialized}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{\+\_\+\+\_\+getopt\+\_\+initialized}{\_\_getopt\_initialized}} +{\footnotesize\ttfamily int \+\_\+\+\_\+getopt\+\_\+initialized} + +\mbox{\Hypertarget{getopt_8c_a7b0f4f3bfbee147113f282427ce933ed}\label{getopt_8c_a7b0f4f3bfbee147113f282427ce933ed}} +\index{getopt.\+c@{getopt.\+c}!first\+\_\+nonopt@{first\+\_\+nonopt}} +\index{first\+\_\+nonopt@{first\+\_\+nonopt}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{first\+\_\+nonopt}{first\_nonopt}} +{\footnotesize\ttfamily int first\+\_\+nonopt\hspace{0.3cm}{\ttfamily [static]}} + +\mbox{\Hypertarget{getopt_8c_a580f2c2acf35dad51ca18b427212bf15}\label{getopt_8c_a580f2c2acf35dad51ca18b427212bf15}} +\index{getopt.\+c@{getopt.\+c}!last\+\_\+nonopt@{last\+\_\+nonopt}} +\index{last\+\_\+nonopt@{last\+\_\+nonopt}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{last\+\_\+nonopt}{last\_nonopt}} +{\footnotesize\ttfamily int last\+\_\+nonopt\hspace{0.3cm}{\ttfamily [static]}} + +\mbox{\Hypertarget{getopt_8c_a47a40a4c365dae45f94751ad32aab530}\label{getopt_8c_a47a40a4c365dae45f94751ad32aab530}} +\index{getopt.\+c@{getopt.\+c}!nextchar@{nextchar}} +\index{nextchar@{nextchar}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{nextchar}{nextchar}} +{\footnotesize\ttfamily char$\ast$ nextchar\hspace{0.3cm}{\ttfamily [static]}} + +\mbox{\Hypertarget{getopt_8c_adb50a0eab9fed92fc3bfc7dfa4f2c410}\label{getopt_8c_adb50a0eab9fed92fc3bfc7dfa4f2c410}} +\index{getopt.\+c@{getopt.\+c}!optarg@{optarg}} +\index{optarg@{optarg}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{optarg}{optarg}} +{\footnotesize\ttfamily char$\ast$ optarg} + +\mbox{\Hypertarget{getopt_8c_ae30f05ee1e2e5652f174a35c7875d25e}\label{getopt_8c_ae30f05ee1e2e5652f174a35c7875d25e}} +\index{getopt.\+c@{getopt.\+c}!opterr@{opterr}} +\index{opterr@{opterr}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{opterr}{opterr}} +{\footnotesize\ttfamily int opterr = 1} + +\mbox{\Hypertarget{getopt_8c_ad5e1c16213bbee2d5e8cc363309f418c}\label{getopt_8c_ad5e1c16213bbee2d5e8cc363309f418c}} +\index{getopt.\+c@{getopt.\+c}!optind@{optind}} +\index{optind@{optind}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{optind}{optind}} +{\footnotesize\ttfamily int optind = 1} + +\mbox{\Hypertarget{getopt_8c_a475b8db98445da73e5f62a1ef6324b95}\label{getopt_8c_a475b8db98445da73e5f62a1ef6324b95}} +\index{getopt.\+c@{getopt.\+c}!optopt@{optopt}} +\index{optopt@{optopt}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{optopt}{optopt}} +{\footnotesize\ttfamily int optopt = \textquotesingle{}?\textquotesingle{}} + +\mbox{\Hypertarget{getopt_8c_a67a84cf4dacaa8337be68345f8b9a8cc}\label{getopt_8c_a67a84cf4dacaa8337be68345f8b9a8cc}} +\index{getopt.\+c@{getopt.\+c}!ordering@{ordering}} +\index{ordering@{ordering}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{ordering}{ordering}} +{\footnotesize\ttfamily enum \{ ... \} ordering\hspace{0.3cm}{\ttfamily [static]}} + +\mbox{\Hypertarget{getopt_8c_ad0ccb64bbd4defe7a57dbad2045ddd14}\label{getopt_8c_ad0ccb64bbd4defe7a57dbad2045ddd14}} +\index{getopt.\+c@{getopt.\+c}!posixly\+\_\+correct@{posixly\+\_\+correct}} +\index{posixly\+\_\+correct@{posixly\+\_\+correct}!getopt.\+c@{getopt.\+c}} +\subsubsection{\texorpdfstring{posixly\+\_\+correct}{posixly\_correct}} +{\footnotesize\ttfamily char$\ast$ posixly\+\_\+correct\hspace{0.3cm}{\ttfamily [static]}} + diff --git a/src/latex/getopt_8c__incl.md5 b/src/latex/getopt_8c__incl.md5 new file mode 100644 index 0000000..95a6402 --- /dev/null +++ b/src/latex/getopt_8c__incl.md5 @@ -0,0 +1 @@ +65e394c880e342edce4264327d3b1704 \ No newline at end of file diff --git a/src/latex/getopt_8c__incl.pdf b/src/latex/getopt_8c__incl.pdf new file mode 100644 index 0000000..88fa634 Binary files /dev/null and b/src/latex/getopt_8c__incl.pdf differ diff --git a/src/latex/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.md5 b/src/latex/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.md5 new file mode 100644 index 0000000..33c396c --- /dev/null +++ b/src/latex/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.md5 @@ -0,0 +1 @@ +b7e0bedbfaf8de076db62b4ade189a42 \ No newline at end of file diff --git a/src/latex/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.pdf b/src/latex/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.pdf new file mode 100644 index 0000000..901980d Binary files /dev/null and b/src/latex/getopt_8c_a0df92a0ae8fe1fd43268c738f548674f_cgraph.pdf differ diff --git a/src/latex/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.md5 b/src/latex/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.md5 new file mode 100644 index 0000000..9d96757 --- /dev/null +++ b/src/latex/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.md5 @@ -0,0 +1 @@ +a00f91580a6b0a0f6cad57897bcfb9e2 \ No newline at end of file diff --git a/src/latex/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.pdf b/src/latex/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.pdf new file mode 100644 index 0000000..4f93fe3 Binary files /dev/null and b/src/latex/getopt_8c_a17475cbc1ffae0c12af2e0a3319d197f_cgraph.pdf differ diff --git a/src/latex/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.md5 b/src/latex/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.md5 new file mode 100644 index 0000000..0c19a3e --- /dev/null +++ b/src/latex/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.md5 @@ -0,0 +1 @@ +70eba24515fca0128d16a4c954ded2d1 \ No newline at end of file diff --git a/src/latex/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.pdf b/src/latex/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.pdf new file mode 100644 index 0000000..9f32253 Binary files /dev/null and b/src/latex/getopt_8c_a1b2ada39ab92162c6ec9c67c8093fa2e_cgraph.pdf differ diff --git a/src/latex/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.md5 b/src/latex/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.md5 new file mode 100644 index 0000000..c18db57 --- /dev/null +++ b/src/latex/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.md5 @@ -0,0 +1 @@ +abbfb77fa492bd0bb3afc9e0a9fb998c \ No newline at end of file diff --git a/src/latex/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.pdf b/src/latex/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.pdf new file mode 100644 index 0000000..dc95bbb Binary files /dev/null and b/src/latex/getopt_8c_a4621659dd6377e52ac50a0869625bb6e_cgraph.pdf differ diff --git a/src/latex/getopt_8h.tex b/src/latex/getopt_8h.tex new file mode 100644 index 0000000..7490dfd --- /dev/null +++ b/src/latex/getopt_8h.tex @@ -0,0 +1,129 @@ +\hypertarget{getopt_8h}{}\section{getopt.\+h File Reference} +\label{getopt_8h}\index{getopt.\+h@{getopt.\+h}} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=210pt]{getopt_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Classes} +\begin{DoxyCompactItemize} +\item +struct \hyperlink{structoption}{option} +\end{DoxyCompactItemize} +\subsection*{Macros} +\begin{DoxyCompactItemize} +\item +\#define \hyperlink{getopt_8h_aaafc27a0389aa87797164b227566342d}{\+\_\+\+G\+E\+T\+O\+P\+T\+\_\+H}~1 +\item +\#define \hyperlink{getopt_8h_a3bc1d5f667b5b4ca4b4abb685dc874ce}{no\+\_\+argument}~0 +\item +\#define \hyperlink{getopt_8h_a6ece8d8dfa8378778f7290fdaba5b8bc}{required\+\_\+argument}~1 +\item +\#define \hyperlink{getopt_8h_acca06c0a947656bd8b395bf1084ffb72}{optional\+\_\+argument}~2 +\end{DoxyCompactItemize} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +int \hyperlink{getopt_8h_a6c5b232cca42dab05f40b47f69715f8b}{getopt} () +\item +int \hyperlink{getopt_8h_a8616b8a74ae6c01a7ad95ad2876226ec}{getopt\+\_\+long} () +\item +int \hyperlink{getopt_8h_ac07930413317507d5c51c19b3ac6ed20}{getopt\+\_\+long\+\_\+only} () +\item +int \hyperlink{getopt_8h_a60428225710059ca135c6b2a8941855f}{\+\_\+getopt\+\_\+internal} () +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +char $\ast$ \hyperlink{getopt_8h_adb50a0eab9fed92fc3bfc7dfa4f2c410}{optarg} +\item +int \hyperlink{getopt_8h_ad5e1c16213bbee2d5e8cc363309f418c}{optind} +\item +int \hyperlink{getopt_8h_ae30f05ee1e2e5652f174a35c7875d25e}{opterr} +\item +int \hyperlink{getopt_8h_a475b8db98445da73e5f62a1ef6324b95}{optopt} +\end{DoxyCompactItemize} + + +\subsection{Macro Definition Documentation} +\mbox{\Hypertarget{getopt_8h_aaafc27a0389aa87797164b227566342d}\label{getopt_8h_aaafc27a0389aa87797164b227566342d}} +\index{getopt.\+h@{getopt.\+h}!\+\_\+\+G\+E\+T\+O\+P\+T\+\_\+H@{\+\_\+\+G\+E\+T\+O\+P\+T\+\_\+H}} +\index{\+\_\+\+G\+E\+T\+O\+P\+T\+\_\+H@{\+\_\+\+G\+E\+T\+O\+P\+T\+\_\+H}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{\+\_\+\+G\+E\+T\+O\+P\+T\+\_\+H}{\_GETOPT\_H}} +{\footnotesize\ttfamily \#define \+\_\+\+G\+E\+T\+O\+P\+T\+\_\+H~1} + +\mbox{\Hypertarget{getopt_8h_a3bc1d5f667b5b4ca4b4abb685dc874ce}\label{getopt_8h_a3bc1d5f667b5b4ca4b4abb685dc874ce}} +\index{getopt.\+h@{getopt.\+h}!no\+\_\+argument@{no\+\_\+argument}} +\index{no\+\_\+argument@{no\+\_\+argument}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{no\+\_\+argument}{no\_argument}} +{\footnotesize\ttfamily \#define no\+\_\+argument~0} + +\mbox{\Hypertarget{getopt_8h_acca06c0a947656bd8b395bf1084ffb72}\label{getopt_8h_acca06c0a947656bd8b395bf1084ffb72}} +\index{getopt.\+h@{getopt.\+h}!optional\+\_\+argument@{optional\+\_\+argument}} +\index{optional\+\_\+argument@{optional\+\_\+argument}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{optional\+\_\+argument}{optional\_argument}} +{\footnotesize\ttfamily \#define optional\+\_\+argument~2} + +\mbox{\Hypertarget{getopt_8h_a6ece8d8dfa8378778f7290fdaba5b8bc}\label{getopt_8h_a6ece8d8dfa8378778f7290fdaba5b8bc}} +\index{getopt.\+h@{getopt.\+h}!required\+\_\+argument@{required\+\_\+argument}} +\index{required\+\_\+argument@{required\+\_\+argument}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{required\+\_\+argument}{required\_argument}} +{\footnotesize\ttfamily \#define required\+\_\+argument~1} + + + +\subsection{Function Documentation} +\mbox{\Hypertarget{getopt_8h_a60428225710059ca135c6b2a8941855f}\label{getopt_8h_a60428225710059ca135c6b2a8941855f}} +\index{getopt.\+h@{getopt.\+h}!\+\_\+getopt\+\_\+internal@{\+\_\+getopt\+\_\+internal}} +\index{\+\_\+getopt\+\_\+internal@{\+\_\+getopt\+\_\+internal}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{\+\_\+getopt\+\_\+internal()}{\_getopt\_internal()}} +{\footnotesize\ttfamily int \+\_\+getopt\+\_\+internal (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{getopt_8h_a6c5b232cca42dab05f40b47f69715f8b}\label{getopt_8h_a6c5b232cca42dab05f40b47f69715f8b}} +\index{getopt.\+h@{getopt.\+h}!getopt@{getopt}} +\index{getopt@{getopt}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{getopt()}{getopt()}} +{\footnotesize\ttfamily int getopt (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{getopt_8h_a8616b8a74ae6c01a7ad95ad2876226ec}\label{getopt_8h_a8616b8a74ae6c01a7ad95ad2876226ec}} +\index{getopt.\+h@{getopt.\+h}!getopt\+\_\+long@{getopt\+\_\+long}} +\index{getopt\+\_\+long@{getopt\+\_\+long}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{getopt\+\_\+long()}{getopt\_long()}} +{\footnotesize\ttfamily int getopt\+\_\+long (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{getopt_8h_ac07930413317507d5c51c19b3ac6ed20}\label{getopt_8h_ac07930413317507d5c51c19b3ac6ed20}} +\index{getopt.\+h@{getopt.\+h}!getopt\+\_\+long\+\_\+only@{getopt\+\_\+long\+\_\+only}} +\index{getopt\+\_\+long\+\_\+only@{getopt\+\_\+long\+\_\+only}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{getopt\+\_\+long\+\_\+only()}{getopt\_long\_only()}} +{\footnotesize\ttfamily int getopt\+\_\+long\+\_\+only (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})} + + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{getopt_8h_adb50a0eab9fed92fc3bfc7dfa4f2c410}\label{getopt_8h_adb50a0eab9fed92fc3bfc7dfa4f2c410}} +\index{getopt.\+h@{getopt.\+h}!optarg@{optarg}} +\index{optarg@{optarg}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{optarg}{optarg}} +{\footnotesize\ttfamily char$\ast$ optarg} + +\mbox{\Hypertarget{getopt_8h_ae30f05ee1e2e5652f174a35c7875d25e}\label{getopt_8h_ae30f05ee1e2e5652f174a35c7875d25e}} +\index{getopt.\+h@{getopt.\+h}!opterr@{opterr}} +\index{opterr@{opterr}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{opterr}{opterr}} +{\footnotesize\ttfamily int opterr} + +\mbox{\Hypertarget{getopt_8h_ad5e1c16213bbee2d5e8cc363309f418c}\label{getopt_8h_ad5e1c16213bbee2d5e8cc363309f418c}} +\index{getopt.\+h@{getopt.\+h}!optind@{optind}} +\index{optind@{optind}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{optind}{optind}} +{\footnotesize\ttfamily int optind} + +\mbox{\Hypertarget{getopt_8h_a475b8db98445da73e5f62a1ef6324b95}\label{getopt_8h_a475b8db98445da73e5f62a1ef6324b95}} +\index{getopt.\+h@{getopt.\+h}!optopt@{optopt}} +\index{optopt@{optopt}!getopt.\+h@{getopt.\+h}} +\subsubsection{\texorpdfstring{optopt}{optopt}} +{\footnotesize\ttfamily int optopt} + diff --git a/src/latex/getopt_8h__dep__incl.md5 b/src/latex/getopt_8h__dep__incl.md5 new file mode 100644 index 0000000..38be245 --- /dev/null +++ b/src/latex/getopt_8h__dep__incl.md5 @@ -0,0 +1 @@ +69da04a5fd004fd18e4f70d0452e41e4 \ No newline at end of file diff --git a/src/latex/getopt_8h__dep__incl.pdf b/src/latex/getopt_8h__dep__incl.pdf new file mode 100644 index 0000000..ca493c3 Binary files /dev/null and b/src/latex/getopt_8h__dep__incl.pdf differ diff --git a/src/latex/misc_8c.tex b/src/latex/misc_8c.tex new file mode 100644 index 0000000..f594d24 --- /dev/null +++ b/src/latex/misc_8c.tex @@ -0,0 +1,207 @@ +\hypertarget{misc_8c}{}\section{misc.\+c File Reference} +\label{misc_8c}\index{misc.\+c@{misc.\+c}} +{\ttfamily \#include $<$string.\+h$>$}\newline +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include $<$stdlib.\+h$>$}\newline +{\ttfamily \#include $<$math.\+h$>$}\newline +{\ttfamily \#include $<$sys/stat.\+h$>$}\newline +{\ttfamily \#include $<$errno.\+h$>$}\newline +{\ttfamily \#include \char`\"{}R\+N\+Acode.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}misc.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}postscript.\+h\char`\"{}}\newline +Include dependency graph for misc.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{misc_8c__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +float $\ast$$\ast$$\ast$$\ast$ \hyperlink{misc_8c_ab8906f987e8caa1c304422e2105784db}{allocate\+Sk} (int N, int L) +\item +void \hyperlink{misc_8c_a540d653adf9134e345a0be15556bef9f}{copy\+Sk} (float $\ast$$\ast$$\ast$$\ast$from, float $\ast$$\ast$$\ast$$\ast$to, int N, int L) +\item +int \hyperlink{misc_8c_a3003bc209fbd623b0ebf8d55c3f76454}{compare\+Scores} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$a, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$b) +\item +int \hyperlink{misc_8c_a08c97f6ebbb296bfe2d0f74e7a3a8af8}{compare\+Location} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$a, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$b) +\item +void \hyperlink{misc_8c_a8eed68ed1197df02c8b9a49264efc717}{reintroduce\+Gaps} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$orig\+Aln\mbox{[}$\,$\mbox{]}, struct \hyperlink{structaln}{aln} $\ast$sampled\+Aln\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{misc_8c_a5753372a1a3c3974fc6be9a6030a67bf}{sort\+Aln} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$orig\+Aln\mbox{[}$\,$\mbox{]}, struct \hyperlink{structaln}{aln} $\ast$sampled\+Aln\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{misc_8c_a9fe543fe19ab3ff4ae9def519e1f0ac1}{get\+Block} (int i, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$seq\+\_\+0, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$seq\+\_\+k, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} int $\ast$map\+\_\+0, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} int $\ast$map\+\_\+k, char $\ast$block\+\_\+0, char $\ast$block\+\_\+k, int $\ast$z) +\item +int \hyperlink{misc_8c_af49091737065e3ea21101edf17533dcf}{pos2col} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$seq, int pos) +\item +int \hyperlink{misc_8c_a935b3901ff2b656c44257b4606ceab6c}{get\+Seq\+Length} (char $\ast$seq) +\item +void \hyperlink{misc_8c_a71b140f8ccd1190776a6cc04f42f7b0d}{free\+Results} (\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} results\mbox{[}$\,$\mbox{]}) +\item +int \hyperlink{misc_8c_a62dbd6f5f78b8829c91c5e373b897f67}{h\+Dist} (int a1, int a2, int a3, int b1, int b2, int b3) +\item +float \hyperlink{misc_8c_a29db63ab5182ac2f88eb37329c092126}{avg} (float $\ast$data, int N) +\item +float \hyperlink{misc_8c_ac9b591bdb26f6a8b8ee56aee3e809c65}{stddev} (float $\ast$data, int N) +\item +void \hyperlink{misc_8c_a0da1742a6a7f546827bee85fbdf53592}{copy\+Aln} (struct \hyperlink{structaln}{aln} $\ast$src\mbox{[}$\,$\mbox{]}, struct \hyperlink{structaln}{aln} $\ast$dest\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{misc_8c_a622e2235405d5fce48465d284271642c}{print\+Aln\+Clustal} (F\+I\+LE $\ast$out, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{misc_8c_a326b72f1de05ef655a3188af0af23aee}{print\+Results} (F\+I\+LE $\ast$\hyperlink{postscript_8c_ae581849c67336453bd5b81e6518019a9}{outfile}, int output\+Format, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$input\+Aln\mbox{[}$\,$\mbox{]}, \hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} results\mbox{[}$\,$\mbox{]}) +\item +int \hyperlink{misc_8c_a6017c986a43a1bba1569a8efb1b3aedb}{extend\+Region} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, int pos, int direction) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +\hyperlink{RNAcode_8h_ac21aeabbefffddb27496994611a09dcd}{parameters} \hyperlink{misc_8c_a8dea3b88a171ed8de9f8f98079e7561a}{pars} +\item +long int \hyperlink{misc_8c_a8c5872fcd4604b525d509ffd6afc5631}{hit\+Counter} +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{misc_8c_ab8906f987e8caa1c304422e2105784db}\label{misc_8c_ab8906f987e8caa1c304422e2105784db}} +\index{misc.\+c@{misc.\+c}!allocate\+Sk@{allocate\+Sk}} +\index{allocate\+Sk@{allocate\+Sk}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{allocate\+Sk()}{allocateSk()}} +{\footnotesize\ttfamily float$\ast$$\ast$$\ast$$\ast$ allocate\+Sk (\begin{DoxyParamCaption}\item[{int}]{N, }\item[{int}]{L }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a29db63ab5182ac2f88eb37329c092126}\label{misc_8c_a29db63ab5182ac2f88eb37329c092126}} +\index{misc.\+c@{misc.\+c}!avg@{avg}} +\index{avg@{avg}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{avg()}{avg()}} +{\footnotesize\ttfamily float avg (\begin{DoxyParamCaption}\item[{float $\ast$}]{data, }\item[{int}]{N }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a08c97f6ebbb296bfe2d0f74e7a3a8af8}\label{misc_8c_a08c97f6ebbb296bfe2d0f74e7a3a8af8}} +\index{misc.\+c@{misc.\+c}!compare\+Location@{compare\+Location}} +\index{compare\+Location@{compare\+Location}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{compare\+Location()}{compareLocation()}} +{\footnotesize\ttfamily int compare\+Location (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$}]{a, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$}]{b }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a3003bc209fbd623b0ebf8d55c3f76454}\label{misc_8c_a3003bc209fbd623b0ebf8d55c3f76454}} +\index{misc.\+c@{misc.\+c}!compare\+Scores@{compare\+Scores}} +\index{compare\+Scores@{compare\+Scores}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{compare\+Scores()}{compareScores()}} +{\footnotesize\ttfamily int compare\+Scores (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$}]{a, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$}]{b }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a0da1742a6a7f546827bee85fbdf53592}\label{misc_8c_a0da1742a6a7f546827bee85fbdf53592}} +\index{misc.\+c@{misc.\+c}!copy\+Aln@{copy\+Aln}} +\index{copy\+Aln@{copy\+Aln}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{copy\+Aln()}{copyAln()}} +{\footnotesize\ttfamily void copy\+Aln (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{src\mbox{[}$\,$\mbox{]}, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{dest\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=328pt]{misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{misc_8c_a540d653adf9134e345a0be15556bef9f}\label{misc_8c_a540d653adf9134e345a0be15556bef9f}} +\index{misc.\+c@{misc.\+c}!copy\+Sk@{copy\+Sk}} +\index{copy\+Sk@{copy\+Sk}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{copy\+Sk()}{copySk()}} +{\footnotesize\ttfamily void copy\+Sk (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$$\ast$$\ast$}]{from, }\item[{float $\ast$$\ast$$\ast$$\ast$}]{to, }\item[{int}]{N, }\item[{int}]{L }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a6017c986a43a1bba1569a8efb1b3aedb}\label{misc_8c_a6017c986a43a1bba1569a8efb1b3aedb}} +\index{misc.\+c@{misc.\+c}!extend\+Region@{extend\+Region}} +\index{extend\+Region@{extend\+Region}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{extend\+Region()}{extendRegion()}} +{\footnotesize\ttfamily int extend\+Region (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{int}]{pos, }\item[{int}]{direction }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=270pt]{misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{misc_8c_a71b140f8ccd1190776a6cc04f42f7b0d}\label{misc_8c_a71b140f8ccd1190776a6cc04f42f7b0d}} +\index{misc.\+c@{misc.\+c}!free\+Results@{free\+Results}} +\index{free\+Results@{free\+Results}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{free\+Results()}{freeResults()}} +{\footnotesize\ttfamily void free\+Results (\begin{DoxyParamCaption}\item[{\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}}]{results\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a9fe543fe19ab3ff4ae9def519e1f0ac1}\label{misc_8c_a9fe543fe19ab3ff4ae9def519e1f0ac1}} +\index{misc.\+c@{misc.\+c}!get\+Block@{get\+Block}} +\index{get\+Block@{get\+Block}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{get\+Block()}{getBlock()}} +{\footnotesize\ttfamily void get\+Block (\begin{DoxyParamCaption}\item[{int}]{i, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{seq\+\_\+0, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{seq\+\_\+k, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} int $\ast$}]{map\+\_\+0, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} int $\ast$}]{map\+\_\+k, }\item[{char $\ast$}]{block\+\_\+0, }\item[{char $\ast$}]{block\+\_\+k, }\item[{int $\ast$}]{z }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a935b3901ff2b656c44257b4606ceab6c}\label{misc_8c_a935b3901ff2b656c44257b4606ceab6c}} +\index{misc.\+c@{misc.\+c}!get\+Seq\+Length@{get\+Seq\+Length}} +\index{get\+Seq\+Length@{get\+Seq\+Length}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{get\+Seq\+Length()}{getSeqLength()}} +{\footnotesize\ttfamily int get\+Seq\+Length (\begin{DoxyParamCaption}\item[{char $\ast$}]{seq }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a62dbd6f5f78b8829c91c5e373b897f67}\label{misc_8c_a62dbd6f5f78b8829c91c5e373b897f67}} +\index{misc.\+c@{misc.\+c}!h\+Dist@{h\+Dist}} +\index{h\+Dist@{h\+Dist}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{h\+Dist()}{hDist()}} +{\footnotesize\ttfamily int h\+Dist (\begin{DoxyParamCaption}\item[{int}]{a1, }\item[{int}]{a2, }\item[{int}]{a3, }\item[{int}]{b1, }\item[{int}]{b2, }\item[{int}]{b3 }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_af49091737065e3ea21101edf17533dcf}\label{misc_8c_af49091737065e3ea21101edf17533dcf}} +\index{misc.\+c@{misc.\+c}!pos2col@{pos2col}} +\index{pos2col@{pos2col}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{pos2col()}{pos2col()}} +{\footnotesize\ttfamily int pos2col (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{seq, }\item[{int}]{pos }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a622e2235405d5fce48465d284271642c}\label{misc_8c_a622e2235405d5fce48465d284271642c}} +\index{misc.\+c@{misc.\+c}!print\+Aln\+Clustal@{print\+Aln\+Clustal}} +\index{print\+Aln\+Clustal@{print\+Aln\+Clustal}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{print\+Aln\+Clustal()}{printAlnClustal()}} +{\footnotesize\ttfamily void print\+Aln\+Clustal (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{out, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a326b72f1de05ef655a3188af0af23aee}\label{misc_8c_a326b72f1de05ef655a3188af0af23aee}} +\index{misc.\+c@{misc.\+c}!print\+Results@{print\+Results}} +\index{print\+Results@{print\+Results}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{print\+Results()}{printResults()}} +{\footnotesize\ttfamily void print\+Results (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{outfile, }\item[{int}]{output\+Format, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{input\+Aln\mbox{[}$\,$\mbox{]}, }\item[{\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}}]{results\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{misc_8c_a8eed68ed1197df02c8b9a49264efc717}\label{misc_8c_a8eed68ed1197df02c8b9a49264efc717}} +\index{misc.\+c@{misc.\+c}!reintroduce\+Gaps@{reintroduce\+Gaps}} +\index{reintroduce\+Gaps@{reintroduce\+Gaps}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{reintroduce\+Gaps()}{reintroduceGaps()}} +{\footnotesize\ttfamily void reintroduce\+Gaps (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{orig\+Aln\mbox{[}$\,$\mbox{]}, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{sampled\+Aln\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_a5753372a1a3c3974fc6be9a6030a67bf}\label{misc_8c_a5753372a1a3c3974fc6be9a6030a67bf}} +\index{misc.\+c@{misc.\+c}!sort\+Aln@{sort\+Aln}} +\index{sort\+Aln@{sort\+Aln}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{sort\+Aln()}{sortAln()}} +{\footnotesize\ttfamily void sort\+Aln (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{orig\+Aln\mbox{[}$\,$\mbox{]}, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{sampled\+Aln\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8c_ac9b591bdb26f6a8b8ee56aee3e809c65}\label{misc_8c_ac9b591bdb26f6a8b8ee56aee3e809c65}} +\index{misc.\+c@{misc.\+c}!stddev@{stddev}} +\index{stddev@{stddev}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{stddev()}{stddev()}} +{\footnotesize\ttfamily float stddev (\begin{DoxyParamCaption}\item[{float $\ast$}]{data, }\item[{int}]{N }\end{DoxyParamCaption})} + + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{misc_8c_a8c5872fcd4604b525d509ffd6afc5631}\label{misc_8c_a8c5872fcd4604b525d509ffd6afc5631}} +\index{misc.\+c@{misc.\+c}!hit\+Counter@{hit\+Counter}} +\index{hit\+Counter@{hit\+Counter}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{hit\+Counter}{hitCounter}} +{\footnotesize\ttfamily long int hit\+Counter} + +\mbox{\Hypertarget{misc_8c_a8dea3b88a171ed8de9f8f98079e7561a}\label{misc_8c_a8dea3b88a171ed8de9f8f98079e7561a}} +\index{misc.\+c@{misc.\+c}!pars@{pars}} +\index{pars@{pars}!misc.\+c@{misc.\+c}} +\subsubsection{\texorpdfstring{pars}{pars}} +{\footnotesize\ttfamily \hyperlink{RNAcode_8h_ac21aeabbefffddb27496994611a09dcd}{parameters} pars} + diff --git a/src/latex/misc_8c__incl.md5 b/src/latex/misc_8c__incl.md5 new file mode 100644 index 0000000..482ead5 --- /dev/null +++ b/src/latex/misc_8c__incl.md5 @@ -0,0 +1 @@ +15fdd1eb4ab496edf78359c317d475ef \ No newline at end of file diff --git a/src/latex/misc_8c__incl.pdf b/src/latex/misc_8c__incl.pdf new file mode 100644 index 0000000..ea8957e Binary files /dev/null and b/src/latex/misc_8c__incl.pdf differ diff --git a/src/latex/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 b/src/latex/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 new file mode 100644 index 0000000..4157a49 --- /dev/null +++ b/src/latex/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 @@ -0,0 +1 @@ +b51471098fe17bc2cc20d57452ce8d69 \ No newline at end of file diff --git a/src/latex/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.pdf b/src/latex/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.pdf new file mode 100644 index 0000000..576bec3 Binary files /dev/null and b/src/latex/misc_8c_a0da1742a6a7f546827bee85fbdf53592_cgraph.pdf differ diff --git a/src/latex/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.md5 b/src/latex/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.md5 new file mode 100644 index 0000000..fa196ac --- /dev/null +++ b/src/latex/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.md5 @@ -0,0 +1 @@ +1fa380247667803373cea01d7e03d4fa \ No newline at end of file diff --git a/src/latex/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.pdf b/src/latex/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.pdf new file mode 100644 index 0000000..9e5b340 Binary files /dev/null and b/src/latex/misc_8c_a326b72f1de05ef655a3188af0af23aee_cgraph.pdf differ diff --git a/src/latex/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 b/src/latex/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 new file mode 100644 index 0000000..ac5674c --- /dev/null +++ b/src/latex/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 @@ -0,0 +1 @@ +eda540934bf30f0deea3ef3a98421c1b \ No newline at end of file diff --git a/src/latex/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.pdf b/src/latex/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.pdf new file mode 100644 index 0000000..7356506 Binary files /dev/null and b/src/latex/misc_8c_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.pdf differ diff --git a/src/latex/misc_8h.tex b/src/latex/misc_8h.tex new file mode 100644 index 0000000..2700ba6 --- /dev/null +++ b/src/latex/misc_8h.tex @@ -0,0 +1,187 @@ +\hypertarget{misc_8h}{}\section{misc.\+h File Reference} +\label{misc_8h}\index{misc.\+h@{misc.\+h}} +{\ttfamily \#include \char`\"{}score.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}code.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}rnaz\+\_\+utils.\+h\char`\"{}}\newline +Include dependency graph for misc.\+h\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=317pt]{misc_8h__incl} +\end{center} +\end{figure} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{misc_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +float $\ast$$\ast$$\ast$$\ast$ \hyperlink{misc_8h_ab8906f987e8caa1c304422e2105784db}{allocate\+Sk} (int N, int L) +\item +void \hyperlink{misc_8h_a540d653adf9134e345a0be15556bef9f}{copy\+Sk} (float $\ast$$\ast$$\ast$$\ast$from, float $\ast$$\ast$$\ast$$\ast$to, int N, int L) +\item +int \hyperlink{misc_8h_a3003bc209fbd623b0ebf8d55c3f76454}{compare\+Scores} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$a, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$b) +\item +void \hyperlink{misc_8h_a8eed68ed1197df02c8b9a49264efc717}{reintroduce\+Gaps} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$orig\+Aln\mbox{[}$\,$\mbox{]}, struct \hyperlink{structaln}{aln} $\ast$sampled\+Aln\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{misc_8h_a5753372a1a3c3974fc6be9a6030a67bf}{sort\+Aln} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$orig\+Aln\mbox{[}$\,$\mbox{]}, struct \hyperlink{structaln}{aln} $\ast$sampled\+Aln\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{misc_8h_a71b140f8ccd1190776a6cc04f42f7b0d}{free\+Results} (\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} results\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{misc_8h_a9fe543fe19ab3ff4ae9def519e1f0ac1}{get\+Block} (int i, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$seq\+\_\+0, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$seq\+\_\+k, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} int $\ast$map\+\_\+0, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} int $\ast$map\+\_\+k, char $\ast$block\+\_\+0, char $\ast$block\+\_\+k, int $\ast$z) +\item +int \hyperlink{misc_8h_af49091737065e3ea21101edf17533dcf}{pos2col} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$seq, int pos) +\item +int \hyperlink{misc_8h_a935b3901ff2b656c44257b4606ceab6c}{get\+Seq\+Length} (char $\ast$seq) +\item +int \hyperlink{misc_8h_a62dbd6f5f78b8829c91c5e373b897f67}{h\+Dist} (int a1, int a2, int a3, int b1, int b2, int b3) +\item +float \hyperlink{misc_8h_a29db63ab5182ac2f88eb37329c092126}{avg} (float $\ast$data, int N) +\item +float \hyperlink{misc_8h_ac9b591bdb26f6a8b8ee56aee3e809c65}{stddev} (float $\ast$data, int N) +\item +float \hyperlink{misc_8h_af625860d4b3644771a9b58a316518d00}{gaussian} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} float sigma) +\item +void \hyperlink{misc_8h_a0da1742a6a7f546827bee85fbdf53592}{copy\+Aln} (struct \hyperlink{structaln}{aln} $\ast$src\mbox{[}$\,$\mbox{]}, struct \hyperlink{structaln}{aln} $\ast$dest\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{misc_8h_a622e2235405d5fce48465d284271642c}{print\+Aln\+Clustal} (F\+I\+LE $\ast$out, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{misc_8h_a92f776363f89ffb2864dc72fa7c8471f}{print\+Results} (F\+I\+LE $\ast$\hyperlink{postscript_8c_ae581849c67336453bd5b81e6518019a9}{outfile}, int output\+Format, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}, \hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} results\mbox{[}$\,$\mbox{]}) +\item +int \hyperlink{misc_8h_a6017c986a43a1bba1569a8efb1b3aedb}{extend\+Region} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, int pos, int direction) +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{misc_8h_ab8906f987e8caa1c304422e2105784db}\label{misc_8h_ab8906f987e8caa1c304422e2105784db}} +\index{misc.\+h@{misc.\+h}!allocate\+Sk@{allocate\+Sk}} +\index{allocate\+Sk@{allocate\+Sk}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{allocate\+Sk()}{allocateSk()}} +{\footnotesize\ttfamily float$\ast$$\ast$$\ast$$\ast$ allocate\+Sk (\begin{DoxyParamCaption}\item[{int}]{N, }\item[{int}]{L }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_a29db63ab5182ac2f88eb37329c092126}\label{misc_8h_a29db63ab5182ac2f88eb37329c092126}} +\index{misc.\+h@{misc.\+h}!avg@{avg}} +\index{avg@{avg}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{avg()}{avg()}} +{\footnotesize\ttfamily float avg (\begin{DoxyParamCaption}\item[{float $\ast$}]{data, }\item[{int}]{N }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_a3003bc209fbd623b0ebf8d55c3f76454}\label{misc_8h_a3003bc209fbd623b0ebf8d55c3f76454}} +\index{misc.\+h@{misc.\+h}!compare\+Scores@{compare\+Scores}} +\index{compare\+Scores@{compare\+Scores}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{compare\+Scores()}{compareScores()}} +{\footnotesize\ttfamily int compare\+Scores (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$}]{a, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} void $\ast$}]{b }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_a0da1742a6a7f546827bee85fbdf53592}\label{misc_8h_a0da1742a6a7f546827bee85fbdf53592}} +\index{misc.\+h@{misc.\+h}!copy\+Aln@{copy\+Aln}} +\index{copy\+Aln@{copy\+Aln}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{copy\+Aln()}{copyAln()}} +{\footnotesize\ttfamily void copy\+Aln (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{src\mbox{[}$\,$\mbox{]}, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{dest\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=328pt]{misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{misc_8h_a540d653adf9134e345a0be15556bef9f}\label{misc_8h_a540d653adf9134e345a0be15556bef9f}} +\index{misc.\+h@{misc.\+h}!copy\+Sk@{copy\+Sk}} +\index{copy\+Sk@{copy\+Sk}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{copy\+Sk()}{copySk()}} +{\footnotesize\ttfamily void copy\+Sk (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$$\ast$$\ast$}]{from, }\item[{float $\ast$$\ast$$\ast$$\ast$}]{to, }\item[{int}]{N, }\item[{int}]{L }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_a6017c986a43a1bba1569a8efb1b3aedb}\label{misc_8h_a6017c986a43a1bba1569a8efb1b3aedb}} +\index{misc.\+h@{misc.\+h}!extend\+Region@{extend\+Region}} +\index{extend\+Region@{extend\+Region}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{extend\+Region()}{extendRegion()}} +{\footnotesize\ttfamily int extend\+Region (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{int}]{pos, }\item[{int}]{direction }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=270pt]{misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{misc_8h_a71b140f8ccd1190776a6cc04f42f7b0d}\label{misc_8h_a71b140f8ccd1190776a6cc04f42f7b0d}} +\index{misc.\+h@{misc.\+h}!free\+Results@{free\+Results}} +\index{free\+Results@{free\+Results}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{free\+Results()}{freeResults()}} +{\footnotesize\ttfamily void free\+Results (\begin{DoxyParamCaption}\item[{\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}}]{results\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_af625860d4b3644771a9b58a316518d00}\label{misc_8h_af625860d4b3644771a9b58a316518d00}} +\index{misc.\+h@{misc.\+h}!gaussian@{gaussian}} +\index{gaussian@{gaussian}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{gaussian()}{gaussian()}} +{\footnotesize\ttfamily float gaussian (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} float}]{sigma }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_a9fe543fe19ab3ff4ae9def519e1f0ac1}\label{misc_8h_a9fe543fe19ab3ff4ae9def519e1f0ac1}} +\index{misc.\+h@{misc.\+h}!get\+Block@{get\+Block}} +\index{get\+Block@{get\+Block}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{get\+Block()}{getBlock()}} +{\footnotesize\ttfamily void get\+Block (\begin{DoxyParamCaption}\item[{int}]{i, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{seq\+\_\+0, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{seq\+\_\+k, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} int $\ast$}]{map\+\_\+0, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} int $\ast$}]{map\+\_\+k, }\item[{char $\ast$}]{block\+\_\+0, }\item[{char $\ast$}]{block\+\_\+k, }\item[{int $\ast$}]{z }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_a935b3901ff2b656c44257b4606ceab6c}\label{misc_8h_a935b3901ff2b656c44257b4606ceab6c}} +\index{misc.\+h@{misc.\+h}!get\+Seq\+Length@{get\+Seq\+Length}} +\index{get\+Seq\+Length@{get\+Seq\+Length}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{get\+Seq\+Length()}{getSeqLength()}} +{\footnotesize\ttfamily int get\+Seq\+Length (\begin{DoxyParamCaption}\item[{char $\ast$}]{seq }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_a62dbd6f5f78b8829c91c5e373b897f67}\label{misc_8h_a62dbd6f5f78b8829c91c5e373b897f67}} +\index{misc.\+h@{misc.\+h}!h\+Dist@{h\+Dist}} +\index{h\+Dist@{h\+Dist}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{h\+Dist()}{hDist()}} +{\footnotesize\ttfamily int h\+Dist (\begin{DoxyParamCaption}\item[{int}]{a1, }\item[{int}]{a2, }\item[{int}]{a3, }\item[{int}]{b1, }\item[{int}]{b2, }\item[{int}]{b3 }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_af49091737065e3ea21101edf17533dcf}\label{misc_8h_af49091737065e3ea21101edf17533dcf}} +\index{misc.\+h@{misc.\+h}!pos2col@{pos2col}} +\index{pos2col@{pos2col}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{pos2col()}{pos2col()}} +{\footnotesize\ttfamily int pos2col (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{seq, }\item[{int}]{pos }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_a622e2235405d5fce48465d284271642c}\label{misc_8h_a622e2235405d5fce48465d284271642c}} +\index{misc.\+h@{misc.\+h}!print\+Aln\+Clustal@{print\+Aln\+Clustal}} +\index{print\+Aln\+Clustal@{print\+Aln\+Clustal}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{print\+Aln\+Clustal()}{printAlnClustal()}} +{\footnotesize\ttfamily void print\+Aln\+Clustal (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{out, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_a92f776363f89ffb2864dc72fa7c8471f}\label{misc_8h_a92f776363f89ffb2864dc72fa7c8471f}} +\index{misc.\+h@{misc.\+h}!print\+Results@{print\+Results}} +\index{print\+Results@{print\+Results}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{print\+Results()}{printResults()}} +{\footnotesize\ttfamily void print\+Results (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{outfile, }\item[{int}]{output\+Format, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]}, }\item[{\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}}]{results\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{misc_8h_a8eed68ed1197df02c8b9a49264efc717}\label{misc_8h_a8eed68ed1197df02c8b9a49264efc717}} +\index{misc.\+h@{misc.\+h}!reintroduce\+Gaps@{reintroduce\+Gaps}} +\index{reintroduce\+Gaps@{reintroduce\+Gaps}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{reintroduce\+Gaps()}{reintroduceGaps()}} +{\footnotesize\ttfamily void reintroduce\+Gaps (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{orig\+Aln\mbox{[}$\,$\mbox{]}, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{sampled\+Aln\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_a5753372a1a3c3974fc6be9a6030a67bf}\label{misc_8h_a5753372a1a3c3974fc6be9a6030a67bf}} +\index{misc.\+h@{misc.\+h}!sort\+Aln@{sort\+Aln}} +\index{sort\+Aln@{sort\+Aln}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{sort\+Aln()}{sortAln()}} +{\footnotesize\ttfamily void sort\+Aln (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{orig\+Aln\mbox{[}$\,$\mbox{]}, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{sampled\+Aln\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{misc_8h_ac9b591bdb26f6a8b8ee56aee3e809c65}\label{misc_8h_ac9b591bdb26f6a8b8ee56aee3e809c65}} +\index{misc.\+h@{misc.\+h}!stddev@{stddev}} +\index{stddev@{stddev}!misc.\+h@{misc.\+h}} +\subsubsection{\texorpdfstring{stddev()}{stddev()}} +{\footnotesize\ttfamily float stddev (\begin{DoxyParamCaption}\item[{float $\ast$}]{data, }\item[{int}]{N }\end{DoxyParamCaption})} + diff --git a/src/latex/misc_8h__dep__incl.md5 b/src/latex/misc_8h__dep__incl.md5 new file mode 100644 index 0000000..041e997 --- /dev/null +++ b/src/latex/misc_8h__dep__incl.md5 @@ -0,0 +1 @@ +2541f89c3fcad0aa8f073394ed717ea4 \ No newline at end of file diff --git a/src/latex/misc_8h__dep__incl.pdf b/src/latex/misc_8h__dep__incl.pdf new file mode 100644 index 0000000..bdb229b Binary files /dev/null and b/src/latex/misc_8h__dep__incl.pdf differ diff --git a/src/latex/misc_8h__incl.md5 b/src/latex/misc_8h__incl.md5 new file mode 100644 index 0000000..ceec2fa --- /dev/null +++ b/src/latex/misc_8h__incl.md5 @@ -0,0 +1 @@ +4b2b57aa914d633facc987559aaba1bf \ No newline at end of file diff --git a/src/latex/misc_8h__incl.pdf b/src/latex/misc_8h__incl.pdf new file mode 100644 index 0000000..cf83bef Binary files /dev/null and b/src/latex/misc_8h__incl.pdf differ diff --git a/src/latex/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 b/src/latex/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 new file mode 100644 index 0000000..e141af4 --- /dev/null +++ b/src/latex/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.md5 @@ -0,0 +1 @@ +ccf62359e9e94a1a395b1e877a89d097 \ No newline at end of file diff --git a/src/latex/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.pdf b/src/latex/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.pdf new file mode 100644 index 0000000..576bec3 Binary files /dev/null and b/src/latex/misc_8h_a0da1742a6a7f546827bee85fbdf53592_cgraph.pdf differ diff --git a/src/latex/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 b/src/latex/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 new file mode 100644 index 0000000..c6c7995 --- /dev/null +++ b/src/latex/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.md5 @@ -0,0 +1 @@ +467b735a30cc8fe6e77bec7b2bffbff2 \ No newline at end of file diff --git a/src/latex/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.pdf b/src/latex/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.pdf new file mode 100644 index 0000000..7356506 Binary files /dev/null and b/src/latex/misc_8h_a6017c986a43a1bba1569a8efb1b3aedb_cgraph.pdf differ diff --git a/src/latex/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.md5 b/src/latex/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.md5 new file mode 100644 index 0000000..fa196ac --- /dev/null +++ b/src/latex/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.md5 @@ -0,0 +1 @@ +1fa380247667803373cea01d7e03d4fa \ No newline at end of file diff --git a/src/latex/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.pdf b/src/latex/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.pdf new file mode 100644 index 0000000..9e5b340 Binary files /dev/null and b/src/latex/misc_8h_a92f776363f89ffb2864dc72fa7c8471f_cgraph.pdf differ diff --git a/src/latex/postscript_8c.tex b/src/latex/postscript_8c.tex new file mode 100644 index 0000000..9fea459 --- /dev/null +++ b/src/latex/postscript_8c.tex @@ -0,0 +1,270 @@ +\hypertarget{postscript_8c}{}\section{postscript.\+c File Reference} +\label{postscript_8c}\index{postscript.\+c@{postscript.\+c}} +{\ttfamily \#include $<$string.\+h$>$}\newline +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include $<$stdlib.\+h$>$}\newline +{\ttfamily \#include $<$math.\+h$>$}\newline +{\ttfamily \#include \char`\"{}score.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}code.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}misc.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}postscript.\+h\char`\"{}}\newline +Include dependency graph for postscript.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{postscript_8c__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +void \hyperlink{postscript_8c_a1d6c94586a33965dd4277c7fe62de430}{set\+Parameters} () +\item +int \hyperlink{postscript_8c_ac7d6bf70e040d36788b6eacace4cb312}{color\+Aln} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$filename, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, \hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} region) +\item +void \hyperlink{postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e}{color\+H\+SS} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$filename, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, \hyperlink{score_8h_a0751e1c4932f95e3e60c73409408a97f}{backtrack\+Data} $\ast$bt, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$label, int b, int i) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +float \hyperlink{postscript_8c_a05a25f17ddf6ed395c481d783d1af2b4}{font\+Width} +\item +float \hyperlink{postscript_8c_a8fc5219f9ead102b3596111331374b2f}{font\+Height} +\item +float \hyperlink{postscript_8c_a97b51530ccb867cc13f911e57be3a559}{image\+Height} +\item +float \hyperlink{postscript_8c_a056677386b85246c5b6f9de91327868c}{image\+Width} +\item +float \hyperlink{postscript_8c_a7e166443fa8165daca1829477a3678c1}{tmp\+Columns} +\item +int \hyperlink{postscript_8c_a9f59b34b1f25fe00023291b678246bcc}{length} +\item +int \hyperlink{postscript_8c_a04c4ce9dea57def69ca277c748f1ec4a}{max\+Name} +\item +int \hyperlink{postscript_8c_af4b91d5ea883f66de1f385aee64a0d5f}{max\+Num} +\item +int \hyperlink{postscript_8c_aee13643f97e046b7492876910b23b59d}{curr\+Pos} +\item +int \hyperlink{postscript_8c_acb1a982424fe4ce17865ade904f6afbb}{column\+Width} +\item +float \hyperlink{postscript_8c_a47c6c3302e0a9d686ba540869d4f3688}{line\+Step} +\item +float \hyperlink{postscript_8c_a2d6e8a7836bfad8586715c3bb775cbb4}{block\+Step} +\item +float \hyperlink{postscript_8c_a6290c97dafee311a97e747d02251da9d}{cons\+Step} +\item +float \hyperlink{postscript_8c_a0fa03894e3a7c9aa3690c217af65c7c3}{ss\+Step} +\item +float \hyperlink{postscript_8c_adbb97a02a7e2f5bc69940fc230062839}{ruler\+Step} +\item +float \hyperlink{postscript_8c_a7b9ed0953c4c3a72b4763f3913467d83}{name\+Step} +\item +float \hyperlink{postscript_8c_ab2e008e977e58c17747a69818f653584}{number\+Step} +\item +float \hyperlink{postscript_8c_a0c4c0a1f79429ea034c156318b576175}{max\+Cons\+Bar} +\item +float \hyperlink{postscript_8c_aa3dfc2d68f6a44a7941b7e6f2940ecac}{startY} +\item +float \hyperlink{postscript_8c_ab9e364a4cf29b5aad82e7ec316ac09e9}{namesX} +\item +float \hyperlink{postscript_8c_a69294d581be62ee920a2ef6622500cbd}{seqsX} +\item +float \hyperlink{postscript_8c_a6cd3947c7e694dc9a6516a4efce1c73d}{currY} +\item +F\+I\+LE $\ast$ \hyperlink{postscript_8c_ae581849c67336453bd5b81e6518019a9}{outfile} +\item +float $\ast$$\ast$$\ast$$\ast$ \hyperlink{postscript_8c_a189ec0118947b93b0df1359ab643d3ce}{Sk\+\_\+native} +\item +float $\ast$$\ast$$\ast$$\ast$ \hyperlink{postscript_8c_a720f3e09e87f08ee95fd84af1c9c575e}{Sk\+\_\+native\+\_\+rev} +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{postscript_8c_ac7d6bf70e040d36788b6eacace4cb312}\label{postscript_8c_ac7d6bf70e040d36788b6eacace4cb312}} +\index{postscript.\+c@{postscript.\+c}!color\+Aln@{color\+Aln}} +\index{color\+Aln@{color\+Aln}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{color\+Aln()}{colorAln()}} +{\footnotesize\ttfamily int color\+Aln (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{filename, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}}]{region }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e}\label{postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e}} +\index{postscript.\+c@{postscript.\+c}!color\+H\+SS@{color\+H\+SS}} +\index{color\+H\+SS@{color\+H\+SS}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{color\+H\+S\+S()}{colorHSS()}} +{\footnotesize\ttfamily void color\+H\+SS (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{filename, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{\hyperlink{score_8h_a0751e1c4932f95e3e60c73409408a97f}{backtrack\+Data} $\ast$}]{bt, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{label, }\item[{int}]{b, }\item[{int}]{i }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{postscript_8c_a1d6c94586a33965dd4277c7fe62de430}\label{postscript_8c_a1d6c94586a33965dd4277c7fe62de430}} +\index{postscript.\+c@{postscript.\+c}!set\+Parameters@{set\+Parameters}} +\index{set\+Parameters@{set\+Parameters}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{set\+Parameters()}{setParameters()}} +{\footnotesize\ttfamily void set\+Parameters (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})} + + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{postscript_8c_a2d6e8a7836bfad8586715c3bb775cbb4}\label{postscript_8c_a2d6e8a7836bfad8586715c3bb775cbb4}} +\index{postscript.\+c@{postscript.\+c}!block\+Step@{block\+Step}} +\index{block\+Step@{block\+Step}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{block\+Step}{blockStep}} +{\footnotesize\ttfamily float block\+Step} + +\mbox{\Hypertarget{postscript_8c_acb1a982424fe4ce17865ade904f6afbb}\label{postscript_8c_acb1a982424fe4ce17865ade904f6afbb}} +\index{postscript.\+c@{postscript.\+c}!column\+Width@{column\+Width}} +\index{column\+Width@{column\+Width}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{column\+Width}{columnWidth}} +{\footnotesize\ttfamily int column\+Width} + +\mbox{\Hypertarget{postscript_8c_a6290c97dafee311a97e747d02251da9d}\label{postscript_8c_a6290c97dafee311a97e747d02251da9d}} +\index{postscript.\+c@{postscript.\+c}!cons\+Step@{cons\+Step}} +\index{cons\+Step@{cons\+Step}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{cons\+Step}{consStep}} +{\footnotesize\ttfamily float cons\+Step} + +\mbox{\Hypertarget{postscript_8c_aee13643f97e046b7492876910b23b59d}\label{postscript_8c_aee13643f97e046b7492876910b23b59d}} +\index{postscript.\+c@{postscript.\+c}!curr\+Pos@{curr\+Pos}} +\index{curr\+Pos@{curr\+Pos}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{curr\+Pos}{currPos}} +{\footnotesize\ttfamily int curr\+Pos} + +\mbox{\Hypertarget{postscript_8c_a6cd3947c7e694dc9a6516a4efce1c73d}\label{postscript_8c_a6cd3947c7e694dc9a6516a4efce1c73d}} +\index{postscript.\+c@{postscript.\+c}!currY@{currY}} +\index{currY@{currY}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{currY}{currY}} +{\footnotesize\ttfamily float currY} + +\mbox{\Hypertarget{postscript_8c_a8fc5219f9ead102b3596111331374b2f}\label{postscript_8c_a8fc5219f9ead102b3596111331374b2f}} +\index{postscript.\+c@{postscript.\+c}!font\+Height@{font\+Height}} +\index{font\+Height@{font\+Height}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{font\+Height}{fontHeight}} +{\footnotesize\ttfamily float font\+Height} + +\mbox{\Hypertarget{postscript_8c_a05a25f17ddf6ed395c481d783d1af2b4}\label{postscript_8c_a05a25f17ddf6ed395c481d783d1af2b4}} +\index{postscript.\+c@{postscript.\+c}!font\+Width@{font\+Width}} +\index{font\+Width@{font\+Width}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{font\+Width}{fontWidth}} +{\footnotesize\ttfamily float font\+Width} + +\mbox{\Hypertarget{postscript_8c_a97b51530ccb867cc13f911e57be3a559}\label{postscript_8c_a97b51530ccb867cc13f911e57be3a559}} +\index{postscript.\+c@{postscript.\+c}!image\+Height@{image\+Height}} +\index{image\+Height@{image\+Height}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{image\+Height}{imageHeight}} +{\footnotesize\ttfamily float image\+Height} + +\mbox{\Hypertarget{postscript_8c_a056677386b85246c5b6f9de91327868c}\label{postscript_8c_a056677386b85246c5b6f9de91327868c}} +\index{postscript.\+c@{postscript.\+c}!image\+Width@{image\+Width}} +\index{image\+Width@{image\+Width}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{image\+Width}{imageWidth}} +{\footnotesize\ttfamily float image\+Width} + +\mbox{\Hypertarget{postscript_8c_a9f59b34b1f25fe00023291b678246bcc}\label{postscript_8c_a9f59b34b1f25fe00023291b678246bcc}} +\index{postscript.\+c@{postscript.\+c}!length@{length}} +\index{length@{length}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{length}{length}} +{\footnotesize\ttfamily int length} + +\mbox{\Hypertarget{postscript_8c_a47c6c3302e0a9d686ba540869d4f3688}\label{postscript_8c_a47c6c3302e0a9d686ba540869d4f3688}} +\index{postscript.\+c@{postscript.\+c}!line\+Step@{line\+Step}} +\index{line\+Step@{line\+Step}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{line\+Step}{lineStep}} +{\footnotesize\ttfamily float line\+Step} + +\mbox{\Hypertarget{postscript_8c_a0c4c0a1f79429ea034c156318b576175}\label{postscript_8c_a0c4c0a1f79429ea034c156318b576175}} +\index{postscript.\+c@{postscript.\+c}!max\+Cons\+Bar@{max\+Cons\+Bar}} +\index{max\+Cons\+Bar@{max\+Cons\+Bar}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{max\+Cons\+Bar}{maxConsBar}} +{\footnotesize\ttfamily float max\+Cons\+Bar} + +\mbox{\Hypertarget{postscript_8c_a04c4ce9dea57def69ca277c748f1ec4a}\label{postscript_8c_a04c4ce9dea57def69ca277c748f1ec4a}} +\index{postscript.\+c@{postscript.\+c}!max\+Name@{max\+Name}} +\index{max\+Name@{max\+Name}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{max\+Name}{maxName}} +{\footnotesize\ttfamily int max\+Name} + +\mbox{\Hypertarget{postscript_8c_af4b91d5ea883f66de1f385aee64a0d5f}\label{postscript_8c_af4b91d5ea883f66de1f385aee64a0d5f}} +\index{postscript.\+c@{postscript.\+c}!max\+Num@{max\+Num}} +\index{max\+Num@{max\+Num}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{max\+Num}{maxNum}} +{\footnotesize\ttfamily int max\+Num} + +\mbox{\Hypertarget{postscript_8c_a7b9ed0953c4c3a72b4763f3913467d83}\label{postscript_8c_a7b9ed0953c4c3a72b4763f3913467d83}} +\index{postscript.\+c@{postscript.\+c}!name\+Step@{name\+Step}} +\index{name\+Step@{name\+Step}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{name\+Step}{nameStep}} +{\footnotesize\ttfamily float name\+Step} + +\mbox{\Hypertarget{postscript_8c_ab9e364a4cf29b5aad82e7ec316ac09e9}\label{postscript_8c_ab9e364a4cf29b5aad82e7ec316ac09e9}} +\index{postscript.\+c@{postscript.\+c}!namesX@{namesX}} +\index{namesX@{namesX}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{namesX}{namesX}} +{\footnotesize\ttfamily float namesX} + +\mbox{\Hypertarget{postscript_8c_ab2e008e977e58c17747a69818f653584}\label{postscript_8c_ab2e008e977e58c17747a69818f653584}} +\index{postscript.\+c@{postscript.\+c}!number\+Step@{number\+Step}} +\index{number\+Step@{number\+Step}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{number\+Step}{numberStep}} +{\footnotesize\ttfamily float number\+Step} + +\mbox{\Hypertarget{postscript_8c_ae581849c67336453bd5b81e6518019a9}\label{postscript_8c_ae581849c67336453bd5b81e6518019a9}} +\index{postscript.\+c@{postscript.\+c}!outfile@{outfile}} +\index{outfile@{outfile}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{outfile}{outfile}} +{\footnotesize\ttfamily F\+I\+LE$\ast$ outfile} + +\mbox{\Hypertarget{postscript_8c_adbb97a02a7e2f5bc69940fc230062839}\label{postscript_8c_adbb97a02a7e2f5bc69940fc230062839}} +\index{postscript.\+c@{postscript.\+c}!ruler\+Step@{ruler\+Step}} +\index{ruler\+Step@{ruler\+Step}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{ruler\+Step}{rulerStep}} +{\footnotesize\ttfamily float ruler\+Step} + +\mbox{\Hypertarget{postscript_8c_a69294d581be62ee920a2ef6622500cbd}\label{postscript_8c_a69294d581be62ee920a2ef6622500cbd}} +\index{postscript.\+c@{postscript.\+c}!seqsX@{seqsX}} +\index{seqsX@{seqsX}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{seqsX}{seqsX}} +{\footnotesize\ttfamily float seqsX} + +\mbox{\Hypertarget{postscript_8c_a189ec0118947b93b0df1359ab643d3ce}\label{postscript_8c_a189ec0118947b93b0df1359ab643d3ce}} +\index{postscript.\+c@{postscript.\+c}!Sk\+\_\+native@{Sk\+\_\+native}} +\index{Sk\+\_\+native@{Sk\+\_\+native}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{Sk\+\_\+native}{Sk\_native}} +{\footnotesize\ttfamily float$\ast$$\ast$$\ast$$\ast$ Sk\+\_\+native} + +\mbox{\Hypertarget{postscript_8c_a720f3e09e87f08ee95fd84af1c9c575e}\label{postscript_8c_a720f3e09e87f08ee95fd84af1c9c575e}} +\index{postscript.\+c@{postscript.\+c}!Sk\+\_\+native\+\_\+rev@{Sk\+\_\+native\+\_\+rev}} +\index{Sk\+\_\+native\+\_\+rev@{Sk\+\_\+native\+\_\+rev}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{Sk\+\_\+native\+\_\+rev}{Sk\_native\_rev}} +{\footnotesize\ttfamily float$\ast$$\ast$$\ast$$\ast$ Sk\+\_\+native\+\_\+rev} + +\mbox{\Hypertarget{postscript_8c_a0fa03894e3a7c9aa3690c217af65c7c3}\label{postscript_8c_a0fa03894e3a7c9aa3690c217af65c7c3}} +\index{postscript.\+c@{postscript.\+c}!ss\+Step@{ss\+Step}} +\index{ss\+Step@{ss\+Step}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{ss\+Step}{ssStep}} +{\footnotesize\ttfamily float ss\+Step} + +\mbox{\Hypertarget{postscript_8c_aa3dfc2d68f6a44a7941b7e6f2940ecac}\label{postscript_8c_aa3dfc2d68f6a44a7941b7e6f2940ecac}} +\index{postscript.\+c@{postscript.\+c}!startY@{startY}} +\index{startY@{startY}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{startY}{startY}} +{\footnotesize\ttfamily float startY} + +\mbox{\Hypertarget{postscript_8c_a7e166443fa8165daca1829477a3678c1}\label{postscript_8c_a7e166443fa8165daca1829477a3678c1}} +\index{postscript.\+c@{postscript.\+c}!tmp\+Columns@{tmp\+Columns}} +\index{tmp\+Columns@{tmp\+Columns}!postscript.\+c@{postscript.\+c}} +\subsubsection{\texorpdfstring{tmp\+Columns}{tmpColumns}} +{\footnotesize\ttfamily float tmp\+Columns} + diff --git a/src/latex/postscript_8c__incl.md5 b/src/latex/postscript_8c__incl.md5 new file mode 100644 index 0000000..5e6c4eb --- /dev/null +++ b/src/latex/postscript_8c__incl.md5 @@ -0,0 +1 @@ +e79b4f4ae511edf7e2d2efb3a3212cab \ No newline at end of file diff --git a/src/latex/postscript_8c__incl.pdf b/src/latex/postscript_8c__incl.pdf new file mode 100644 index 0000000..23ef96e Binary files /dev/null and b/src/latex/postscript_8c__incl.pdf differ diff --git a/src/latex/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 b/src/latex/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 new file mode 100644 index 0000000..f40f3b9 --- /dev/null +++ b/src/latex/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 @@ -0,0 +1 @@ +997588a5e597201a95325e1fc7434e11 \ No newline at end of file diff --git a/src/latex/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.pdf b/src/latex/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.pdf new file mode 100644 index 0000000..eb4a5ec Binary files /dev/null and b/src/latex/postscript_8c_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.pdf differ diff --git a/src/latex/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 b/src/latex/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 new file mode 100644 index 0000000..91ce760 --- /dev/null +++ b/src/latex/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 @@ -0,0 +1 @@ +6d3276e99ac823824e2c7a900ce583bc \ No newline at end of file diff --git a/src/latex/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.pdf b/src/latex/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.pdf new file mode 100644 index 0000000..683c0a5 Binary files /dev/null and b/src/latex/postscript_8c_ac7d6bf70e040d36788b6eacace4cb312_cgraph.pdf differ diff --git a/src/latex/postscript_8h.tex b/src/latex/postscript_8h.tex new file mode 100644 index 0000000..a61d576 --- /dev/null +++ b/src/latex/postscript_8h.tex @@ -0,0 +1,66 @@ +\hypertarget{postscript_8h}{}\section{postscript.\+h File Reference} +\label{postscript_8h}\index{postscript.\+h@{postscript.\+h}} +{\ttfamily \#include \char`\"{}rnaz\+\_\+utils.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}code.\+h\char`\"{}}\newline +Include dependency graph for postscript.\+h\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=212pt]{postscript_8h__incl} +\end{center} +\end{figure} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=298pt]{postscript_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +int \hyperlink{postscript_8h_ac7d6bf70e040d36788b6eacace4cb312}{color\+Aln} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$filename, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, \hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} region) +\item +void \hyperlink{postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e}{color\+H\+SS} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$filename, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, \hyperlink{score_8h_a0751e1c4932f95e3e60c73409408a97f}{backtrack\+Data} $\ast$bt, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$label, int b, int i) +\item +void \hyperlink{postscript_8h_a1d6c94586a33965dd4277c7fe62de430}{set\+Parameters} () +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{postscript_8h_ac7d6bf70e040d36788b6eacace4cb312}\label{postscript_8h_ac7d6bf70e040d36788b6eacace4cb312}} +\index{postscript.\+h@{postscript.\+h}!color\+Aln@{color\+Aln}} +\index{color\+Aln@{color\+Aln}!postscript.\+h@{postscript.\+h}} +\subsubsection{\texorpdfstring{color\+Aln()}{colorAln()}} +{\footnotesize\ttfamily int color\+Aln (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{filename, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}}]{region }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e}\label{postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e}} +\index{postscript.\+h@{postscript.\+h}!color\+H\+SS@{color\+H\+SS}} +\index{color\+H\+SS@{color\+H\+SS}!postscript.\+h@{postscript.\+h}} +\subsubsection{\texorpdfstring{color\+H\+S\+S()}{colorHSS()}} +{\footnotesize\ttfamily void color\+H\+SS (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{filename, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{\hyperlink{score_8h_a0751e1c4932f95e3e60c73409408a97f}{backtrack\+Data} $\ast$}]{bt, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{label, }\item[{int}]{b, }\item[{int}]{i }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{postscript_8h_a1d6c94586a33965dd4277c7fe62de430}\label{postscript_8h_a1d6c94586a33965dd4277c7fe62de430}} +\index{postscript.\+h@{postscript.\+h}!set\+Parameters@{set\+Parameters}} +\index{set\+Parameters@{set\+Parameters}!postscript.\+h@{postscript.\+h}} +\subsubsection{\texorpdfstring{set\+Parameters()}{setParameters()}} +{\footnotesize\ttfamily void set\+Parameters (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})} + diff --git a/src/latex/postscript_8h__dep__incl.md5 b/src/latex/postscript_8h__dep__incl.md5 new file mode 100644 index 0000000..baba541 --- /dev/null +++ b/src/latex/postscript_8h__dep__incl.md5 @@ -0,0 +1 @@ +d69ac54025567c6ae691355daf989b10 \ No newline at end of file diff --git a/src/latex/postscript_8h__dep__incl.pdf b/src/latex/postscript_8h__dep__incl.pdf new file mode 100644 index 0000000..b7a8f0b Binary files /dev/null and b/src/latex/postscript_8h__dep__incl.pdf differ diff --git a/src/latex/postscript_8h__incl.md5 b/src/latex/postscript_8h__incl.md5 new file mode 100644 index 0000000..6c79e3b --- /dev/null +++ b/src/latex/postscript_8h__incl.md5 @@ -0,0 +1 @@ +c29db1da9ff5fa37b874181c87a98e4f \ No newline at end of file diff --git a/src/latex/postscript_8h__incl.pdf b/src/latex/postscript_8h__incl.pdf new file mode 100644 index 0000000..8ce0bed Binary files /dev/null and b/src/latex/postscript_8h__incl.pdf differ diff --git a/src/latex/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 b/src/latex/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 new file mode 100644 index 0000000..f40f3b9 --- /dev/null +++ b/src/latex/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.md5 @@ -0,0 +1 @@ +997588a5e597201a95325e1fc7434e11 \ No newline at end of file diff --git a/src/latex/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.pdf b/src/latex/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.pdf new file mode 100644 index 0000000..eb4a5ec Binary files /dev/null and b/src/latex/postscript_8h_a88d8c5c3031b8ee553b4bfc437e4b73e_cgraph.pdf differ diff --git a/src/latex/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 b/src/latex/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 new file mode 100644 index 0000000..91ce760 --- /dev/null +++ b/src/latex/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.md5 @@ -0,0 +1 @@ +6d3276e99ac823824e2c7a900ce583bc \ No newline at end of file diff --git a/src/latex/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.pdf b/src/latex/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.pdf new file mode 100644 index 0000000..683c0a5 Binary files /dev/null and b/src/latex/postscript_8h_ac7d6bf70e040d36788b6eacace4cb312_cgraph.pdf differ diff --git a/src/latex/refman.tex b/src/latex/refman.tex new file mode 100644 index 0000000..0ecfc73 --- /dev/null +++ b/src/latex/refman.tex @@ -0,0 +1,195 @@ +\documentclass[twoside]{book} + +% Packages required by doxygen +\usepackage{fixltx2e} +\usepackage{calc} +\usepackage{doxygen} +\usepackage[export]{adjustbox} % also loads graphicx +\usepackage{graphicx} +\usepackage[utf8]{inputenc} +\usepackage{makeidx} +\usepackage{multicol} +\usepackage{multirow} +\PassOptionsToPackage{warn}{textcomp} +\usepackage{textcomp} +\usepackage[nointegrals]{wasysym} +\usepackage[table]{xcolor} + +% Font selection +\usepackage[T1]{fontenc} +\usepackage[scaled=.90]{helvet} +\usepackage{courier} +\usepackage{amssymb} +\usepackage{sectsty} +\renewcommand{\familydefault}{\sfdefault} +\allsectionsfont{% + \fontseries{bc}\selectfont% + \color{darkgray}% +} +\renewcommand{\DoxyLabelFont}{% + \fontseries{bc}\selectfont% + \color{darkgray}% +} +\newcommand{\+}{\discretionary{\mbox{\scriptsize$\hookleftarrow$}}{}{}} + +% Page & text layout +\usepackage{geometry} +\geometry{% + a4paper,% + top=2.5cm,% + bottom=2.5cm,% + left=2.5cm,% + right=2.5cm% +} +\tolerance=750 +\hfuzz=15pt +\hbadness=750 +\setlength{\emergencystretch}{15pt} +\setlength{\parindent}{0cm} +\setlength{\parskip}{3ex plus 2ex minus 2ex} +\makeatletter +\renewcommand{\paragraph}{% + \@startsection{paragraph}{4}{0ex}{-1.0ex}{1.0ex}{% + \normalfont\normalsize\bfseries\SS@parafont% + }% +} +\renewcommand{\subparagraph}{% + \@startsection{subparagraph}{5}{0ex}{-1.0ex}{1.0ex}{% + \normalfont\normalsize\bfseries\SS@subparafont% + }% +} +\makeatother + +% Headers & footers +\usepackage{fancyhdr} +\pagestyle{fancyplain} +\fancyhead[LE]{\fancyplain{}{\bfseries\thepage}} +\fancyhead[CE]{\fancyplain{}{}} +\fancyhead[RE]{\fancyplain{}{\bfseries\leftmark}} +\fancyhead[LO]{\fancyplain{}{\bfseries\rightmark}} +\fancyhead[CO]{\fancyplain{}{}} +\fancyhead[RO]{\fancyplain{}{\bfseries\thepage}} +\fancyfoot[LE]{\fancyplain{}{}} +\fancyfoot[CE]{\fancyplain{}{}} +\fancyfoot[RE]{\fancyplain{}{\bfseries\scriptsize Generated by Doxygen }} +\fancyfoot[LO]{\fancyplain{}{\bfseries\scriptsize Generated by Doxygen }} +\fancyfoot[CO]{\fancyplain{}{}} +\fancyfoot[RO]{\fancyplain{}{}} +\renewcommand{\footrulewidth}{0.4pt} +\renewcommand{\chaptermark}[1]{% + \markboth{#1}{}% +} +\renewcommand{\sectionmark}[1]{% + \markright{\thesection\ #1}% +} + +% Indices & bibliography +\usepackage{natbib} +\usepackage[titles]{tocloft} +\setcounter{tocdepth}{3} +\setcounter{secnumdepth}{5} +\makeindex + +% Hyperlinks (required, but should be loaded last) +\usepackage{ifpdf} +\ifpdf + \usepackage[pdftex,pagebackref=true]{hyperref} +\else + \usepackage[ps2pdf,pagebackref=true]{hyperref} +\fi +\hypersetup{% + colorlinks=true,% + linkcolor=blue,% + citecolor=blue,% + unicode% +} + +% Custom commands +\newcommand{\clearemptydoublepage}{% + \newpage{\pagestyle{empty}\cleardoublepage}% +} + +\usepackage{caption} +\captionsetup{labelsep=space,justification=centering,font={bf},singlelinecheck=off,skip=4pt,position=top} + +%===== C O N T E N T S ===== + +\begin{document} + +% Titlepage & ToC +\hypersetup{pageanchor=false, + bookmarksnumbered=true, + pdfencoding=unicode + } +\pagenumbering{alph} +\begin{titlepage} +\vspace*{7cm} +\begin{center}% +{\Large My Project }\\ +\vspace*{1cm} +{\large Generated by Doxygen 1.8.13}\\ +\end{center} +\end{titlepage} +\clearemptydoublepage +\pagenumbering{roman} +\tableofcontents +\clearemptydoublepage +\pagenumbering{arabic} +\hypersetup{pageanchor=true} + +%--- Begin generated contents --- +\chapter{Deprecated List} +\label{deprecated} +\Hypertarget{deprecated} +\input{deprecated} +\chapter{Class Index} +\input{annotated} +\chapter{File Index} +\input{files} +\chapter{Class Documentation} +\input{struct__backtrackData} +\input{struct__bgModel} +\input{struct__parameters} +\input{struct__segmentStats} +\input{structaln} +\input{structcmdline__parser__params} +\input{structgengetopt__args__info} +\input{structoption} +\chapter{File Documentation} +\input{cmdline_8c} +\input{cmdline_8h} +\input{code_8c} +\input{code_8h} +\input{extreme__fit_8c} +\input{extreme__fit_8h} +\input{getopt_8c} +\input{getopt_8h} +\input{misc_8c} +\input{misc_8h} +\input{postscript_8c} +\input{postscript_8h} +\input{RNAcode_8c} +\input{RNAcode_8h} +\input{rnaz__utils_8c} +\input{rnaz__utils_8h} +\input{score_8c} +\input{score_8h} +\input{treeML_8c} +\input{treeML_8h} +\input{treeSimulate_8c} +\input{treeSimulate_8h} +\input{utils_8c} +\input{utils_8h} +\input{weight_8c} +\input{weight_8h} +%--- End generated contents --- + +% Index +\backmatter +\newpage +\phantomsection +\clearemptydoublepage +\addcontentsline{toc}{chapter}{Index} +\printindex + +\end{document} diff --git a/src/latex/rnaz__utils_8c.tex b/src/latex/rnaz__utils_8c.tex new file mode 100644 index 0000000..3ab1a31 --- /dev/null +++ b/src/latex/rnaz__utils_8c.tex @@ -0,0 +1,277 @@ +\hypertarget{rnaz__utils_8c}{}\section{rnaz\+\_\+utils.\+c File Reference} +\label{rnaz__utils_8c}\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +{\ttfamily \#include \char`\"{}config.\+h\char`\"{}}\newline +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include $<$stdlib.\+h$>$}\newline +{\ttfamily \#include $<$math.\+h$>$}\newline +{\ttfamily \#include $<$ctype.\+h$>$}\newline +{\ttfamily \#include $<$unistd.\+h$>$}\newline +{\ttfamily \#include $<$string.\+h$>$}\newline +{\ttfamily \#include \char`\"{}fold.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}fold\+\_\+vars.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}utils.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}pair\+\_\+mat.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}alifold.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}rnaz\+\_\+utils.\+h\char`\"{}}\newline +Include dependency graph for rnaz\+\_\+utils.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{rnaz__utils_8c__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +int \hyperlink{rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163}{read\+\_\+clustal} (F\+I\+LE $\ast$clust, struct \hyperlink{structaln}{aln} $\ast$aligned\+Seqs\mbox{[}$\,$\mbox{]}) +\item +int \hyperlink{rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476}{read\+\_\+maf} (F\+I\+LE $\ast$clust, struct \hyperlink{structaln}{aln} $\ast$aligned\+Seqs\mbox{[}$\,$\mbox{]}) +\item +char $\ast$ \hyperlink{rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5}{consensus} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +double \hyperlink{rnaz__utils_8c_a802470f11cb32abaa510b2c67f098235}{mean\+Pair\+ID} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2}{rev\+Aln} (struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065}{slice\+Aln} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$source\+Aln\mbox{[}$\,$\mbox{]}, struct \hyperlink{structaln}{aln} $\ast$dest\+Aln\mbox{[}$\,$\mbox{]}, int from, int to) +\item +void \hyperlink{rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673}{free\+Aln} (struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +struct \hyperlink{structaln}{aln} $\ast$ \hyperlink{rnaz__utils_8c_ab3af11f3fc09669574f682072f795865}{create\+Aln\+Entry} (char $\ast$name, char $\ast$seq, int start, int \hyperlink{postscript_8c_a9f59b34b1f25fe00023291b678246bcc}{length}, int full\+Length, char strand) +\item +void \hyperlink{rnaz__utils_8c_ac38565a99389ebf0aed62a623d893299}{free\+Aln\+Entry} (struct \hyperlink{structaln}{aln} $\ast$entry) +\item +void \hyperlink{rnaz__utils_8c_ad1830dc656474e2da129e5322927ee15}{print\+Aln} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +int \hyperlink{rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470}{check\+Format} (F\+I\+LE $\ast$file) +\item +char $\ast$$\ast$ \hyperlink{rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b}{split\+Fields} (char $\ast$string) +\item +char $\ast$$\ast$ \hyperlink{rnaz__utils_8c_ad897a202b424203bee4a1746872aa095}{split\+Lines} (char $\ast$string) +\item +void \hyperlink{rnaz__utils_8c_a5afeb493cf63c3077bc7ccc2df25208d}{free\+Fields} (char $\ast$$\ast$fields) +\item +double \hyperlink{rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b}{comb\+Per\+Pair} (struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}, char $\ast$structure) +\item +int \hyperlink{rnaz__utils_8c_a48ca69cad11fcf2c4d962b73ff4388ee}{encode\+Base} (char base) +\item +void \hyperlink{rnaz__utils_8c_a7dc7886bc41a49ff0a19e67451026d81}{print\+Aln\+M\+AF} (F\+I\+LE $\ast$out, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}, int printU) +\item +void \hyperlink{rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985}{prune\+Aln} (char $\ast$species, struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +char $\ast$$\ast$ \hyperlink{rnaz__utils_8c_a7d5f1b4f24c9a156013547278b473278}{split\+String} (char $\ast$string, char $\ast$separators) +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470}\label{rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!check\+Format@{check\+Format}} +\index{check\+Format@{check\+Format}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{check\+Format()}{checkFormat()}} +{\footnotesize\ttfamily int check\+Format (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{file }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b}\label{rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!comb\+Per\+Pair@{comb\+Per\+Pair}} +\index{comb\+Per\+Pair@{comb\+Per\+Pair}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{comb\+Per\+Pair()}{combPerPair()}} +{\footnotesize\ttfamily double comb\+Per\+Pair (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]}, }\item[{char $\ast$}]{structure }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=260pt]{rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5}\label{rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!consensus@{consensus}} +\index{consensus@{consensus}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{consensus()}{consensus()}} +{\footnotesize\ttfamily char$\ast$ consensus (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=223pt]{rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_ab3af11f3fc09669574f682072f795865}\label{rnaz__utils_8c_ab3af11f3fc09669574f682072f795865}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!create\+Aln\+Entry@{create\+Aln\+Entry}} +\index{create\+Aln\+Entry@{create\+Aln\+Entry}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{create\+Aln\+Entry()}{createAlnEntry()}} +{\footnotesize\ttfamily struct \hyperlink{structaln}{aln}$\ast$ create\+Aln\+Entry (\begin{DoxyParamCaption}\item[{char $\ast$}]{name, }\item[{char $\ast$}]{seq, }\item[{int}]{start, }\item[{int}]{length, }\item[{int}]{full\+Length, }\item[{char}]{strand }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=240pt]{rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_a48ca69cad11fcf2c4d962b73ff4388ee}\label{rnaz__utils_8c_a48ca69cad11fcf2c4d962b73ff4388ee}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!encode\+Base@{encode\+Base}} +\index{encode\+Base@{encode\+Base}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{encode\+Base()}{encodeBase()}} +{\footnotesize\ttfamily int encode\+Base (\begin{DoxyParamCaption}\item[{char}]{base }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673}\label{rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!free\+Aln@{free\+Aln}} +\index{free\+Aln@{free\+Aln}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{free\+Aln()}{freeAln()}} +{\footnotesize\ttfamily void free\+Aln (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=234pt]{rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_ac38565a99389ebf0aed62a623d893299}\label{rnaz__utils_8c_ac38565a99389ebf0aed62a623d893299}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!free\+Aln\+Entry@{free\+Aln\+Entry}} +\index{free\+Aln\+Entry@{free\+Aln\+Entry}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{free\+Aln\+Entry()}{freeAlnEntry()}} +{\footnotesize\ttfamily void free\+Aln\+Entry (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{entry }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8c_a5afeb493cf63c3077bc7ccc2df25208d}\label{rnaz__utils_8c_a5afeb493cf63c3077bc7ccc2df25208d}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!free\+Fields@{free\+Fields}} +\index{free\+Fields@{free\+Fields}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{free\+Fields()}{freeFields()}} +{\footnotesize\ttfamily void free\+Fields (\begin{DoxyParamCaption}\item[{char $\ast$$\ast$}]{fields }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8c_a802470f11cb32abaa510b2c67f098235}\label{rnaz__utils_8c_a802470f11cb32abaa510b2c67f098235}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!mean\+Pair\+ID@{mean\+Pair\+ID}} +\index{mean\+Pair\+ID@{mean\+Pair\+ID}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{mean\+Pair\+I\+D()}{meanPairID()}} +{\footnotesize\ttfamily double mean\+Pair\+ID (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8c_ad1830dc656474e2da129e5322927ee15}\label{rnaz__utils_8c_ad1830dc656474e2da129e5322927ee15}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!print\+Aln@{print\+Aln}} +\index{print\+Aln@{print\+Aln}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{print\+Aln()}{printAln()}} +{\footnotesize\ttfamily void print\+Aln (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8c_a7dc7886bc41a49ff0a19e67451026d81}\label{rnaz__utils_8c_a7dc7886bc41a49ff0a19e67451026d81}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!print\+Aln\+M\+AF@{print\+Aln\+M\+AF}} +\index{print\+Aln\+M\+AF@{print\+Aln\+M\+AF}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{print\+Aln\+M\+A\+F()}{printAlnMAF()}} +{\footnotesize\ttfamily void print\+Aln\+M\+AF (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{out, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]}, }\item[{int}]{printU }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985}\label{rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!prune\+Aln@{prune\+Aln}} +\index{prune\+Aln@{prune\+Aln}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{prune\+Aln()}{pruneAln()}} +{\footnotesize\ttfamily void prune\+Aln (\begin{DoxyParamCaption}\item[{char $\ast$}]{species, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=231pt]{rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163}\label{rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!read\+\_\+clustal@{read\+\_\+clustal}} +\index{read\+\_\+clustal@{read\+\_\+clustal}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{read\+\_\+clustal()}{read\_clustal()}} +{\footnotesize\ttfamily int read\+\_\+clustal (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{clust, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{aligned\+Seqs\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476}\label{rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!read\+\_\+maf@{read\+\_\+maf}} +\index{read\+\_\+maf@{read\+\_\+maf}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{read\+\_\+maf()}{read\_maf()}} +{\footnotesize\ttfamily int read\+\_\+maf (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{clust, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{aligned\+Seqs\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2}\label{rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!rev\+Aln@{rev\+Aln}} +\index{rev\+Aln@{rev\+Aln}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{rev\+Aln()}{revAln()}} +{\footnotesize\ttfamily void rev\+Aln (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=203pt]{rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065}\label{rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!slice\+Aln@{slice\+Aln}} +\index{slice\+Aln@{slice\+Aln}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{slice\+Aln()}{sliceAln()}} +{\footnotesize\ttfamily void slice\+Aln (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{source\+Aln\mbox{[}$\,$\mbox{]}, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{dest\+Aln\mbox{[}$\,$\mbox{]}, }\item[{int}]{from, }\item[{int}]{to }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=327pt]{rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b}\label{rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!split\+Fields@{split\+Fields}} +\index{split\+Fields@{split\+Fields}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{split\+Fields()}{splitFields()}} +{\footnotesize\ttfamily char$\ast$$\ast$ split\+Fields (\begin{DoxyParamCaption}\item[{char $\ast$}]{string }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=307pt]{rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_ad897a202b424203bee4a1746872aa095}\label{rnaz__utils_8c_ad897a202b424203bee4a1746872aa095}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!split\+Lines@{split\+Lines}} +\index{split\+Lines@{split\+Lines}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{split\+Lines()}{splitLines()}} +{\footnotesize\ttfamily char$\ast$$\ast$ split\+Lines (\begin{DoxyParamCaption}\item[{char $\ast$}]{string }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=304pt]{rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8c_a7d5f1b4f24c9a156013547278b473278}\label{rnaz__utils_8c_a7d5f1b4f24c9a156013547278b473278}} +\index{rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}!split\+String@{split\+String}} +\index{split\+String@{split\+String}!rnaz\+\_\+utils.\+c@{rnaz\+\_\+utils.\+c}} +\subsubsection{\texorpdfstring{split\+String()}{splitString()}} +{\footnotesize\ttfamily char$\ast$$\ast$ split\+String (\begin{DoxyParamCaption}\item[{char $\ast$}]{string, }\item[{char $\ast$}]{separators }\end{DoxyParamCaption})} + diff --git a/src/latex/rnaz__utils_8c__incl.md5 b/src/latex/rnaz__utils_8c__incl.md5 new file mode 100644 index 0000000..83c21a1 --- /dev/null +++ b/src/latex/rnaz__utils_8c__incl.md5 @@ -0,0 +1 @@ +ad34ccf593c3cdff5f1ba8c47f59ed94 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c__incl.pdf b/src/latex/rnaz__utils_8c__incl.pdf new file mode 100644 index 0000000..cf3e602 Binary files /dev/null and b/src/latex/rnaz__utils_8c__incl.pdf differ diff --git a/src/latex/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.md5 b/src/latex/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.md5 new file mode 100644 index 0000000..fb64d4b --- /dev/null +++ b/src/latex/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.md5 @@ -0,0 +1 @@ +b28e5564a097c9f1d1f2a4d72383bd09 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.pdf b/src/latex/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.pdf new file mode 100644 index 0000000..cfa2f4f Binary files /dev/null and b/src/latex/rnaz__utils_8c_a121bcc17b926e5be6edd36caea0a8985_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 b/src/latex/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 new file mode 100644 index 0000000..70809fa --- /dev/null +++ b/src/latex/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 @@ -0,0 +1 @@ +c3406820ccf11417b00ce08b78048881 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.pdf b/src/latex/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.pdf new file mode 100644 index 0000000..5965f45 Binary files /dev/null and b/src/latex/rnaz__utils_8c_a174b786ba35d783d0937a545d2d4071b_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 b/src/latex/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 new file mode 100644 index 0000000..7034ed9 --- /dev/null +++ b/src/latex/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 @@ -0,0 +1 @@ +82ca692459b96417f0065de93408a054 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.pdf b/src/latex/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.pdf new file mode 100644 index 0000000..1daf0ca Binary files /dev/null and b/src/latex/rnaz__utils_8c_a2207280ef510cc5d737b0b04bcfba476_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 b/src/latex/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 new file mode 100644 index 0000000..85074af --- /dev/null +++ b/src/latex/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 @@ -0,0 +1 @@ +bf0d32757a865064d412d1714c15ac46 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.pdf b/src/latex/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.pdf new file mode 100644 index 0000000..93bcf31 Binary files /dev/null and b/src/latex/rnaz__utils_8c_a43cebeec9c40c9be2970b4ed266e7065_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 b/src/latex/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 new file mode 100644 index 0000000..e939d78 --- /dev/null +++ b/src/latex/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 @@ -0,0 +1 @@ +e960c9b463fc805e427a0881c31ec05f \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.pdf b/src/latex/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.pdf new file mode 100644 index 0000000..03f436d Binary files /dev/null and b/src/latex/rnaz__utils_8c_a7e802ce86090ca9375d5e39ebacc1470_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 b/src/latex/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 new file mode 100644 index 0000000..95c7fb3 --- /dev/null +++ b/src/latex/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 @@ -0,0 +1 @@ +e51375dd76f825ba3aa0a615ef04abf3 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.pdf b/src/latex/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.pdf new file mode 100644 index 0000000..e18d7a6 Binary files /dev/null and b/src/latex/rnaz__utils_8c_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 b/src/latex/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 new file mode 100644 index 0000000..1f9fba1 --- /dev/null +++ b/src/latex/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 @@ -0,0 +1 @@ +8429cc9888f9c5599cbb9b5d766d4b0f \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.pdf b/src/latex/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.pdf new file mode 100644 index 0000000..907bd6e Binary files /dev/null and b/src/latex/rnaz__utils_8c_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 b/src/latex/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 new file mode 100644 index 0000000..fc126af --- /dev/null +++ b/src/latex/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 @@ -0,0 +1 @@ +011391e7643303d28d2d4522b7ed7be0 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.pdf b/src/latex/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.pdf new file mode 100644 index 0000000..3939d92 Binary files /dev/null and b/src/latex/rnaz__utils_8c_aa870f4f41dc7bf4808af716a34482ac5_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.md5 b/src/latex/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.md5 new file mode 100644 index 0000000..6389fc8 --- /dev/null +++ b/src/latex/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.md5 @@ -0,0 +1 @@ +a38e296ee5e8035ec3313afd723a04cf \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.pdf b/src/latex/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.pdf new file mode 100644 index 0000000..21a7fbe Binary files /dev/null and b/src/latex/rnaz__utils_8c_ab3af11f3fc09669574f682072f795865_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.md5 b/src/latex/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.md5 new file mode 100644 index 0000000..c6acc36 --- /dev/null +++ b/src/latex/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.md5 @@ -0,0 +1 @@ +9db954e950fee9f8c546b8446897d43f \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.pdf b/src/latex/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.pdf new file mode 100644 index 0000000..16b3784 Binary files /dev/null and b/src/latex/rnaz__utils_8c_ace5cb65b010161f9eb138717b4592673_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 b/src/latex/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 new file mode 100644 index 0000000..465ff0e --- /dev/null +++ b/src/latex/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 @@ -0,0 +1 @@ +4e79f07584ccb736e844d74fe08b8b05 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.pdf b/src/latex/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.pdf new file mode 100644 index 0000000..efa19c5 Binary files /dev/null and b/src/latex/rnaz__utils_8c_ad571d9ad5858c8e2d834225efec51163_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.md5 b/src/latex/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.md5 new file mode 100644 index 0000000..6317bc0 --- /dev/null +++ b/src/latex/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.md5 @@ -0,0 +1 @@ +49e5dd0b060c49ffc1b1414cb642ebcd \ No newline at end of file diff --git a/src/latex/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.pdf b/src/latex/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.pdf new file mode 100644 index 0000000..2d1a26e Binary files /dev/null and b/src/latex/rnaz__utils_8c_ad897a202b424203bee4a1746872aa095_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h.tex b/src/latex/rnaz__utils_8h.tex new file mode 100644 index 0000000..1a2ce5e --- /dev/null +++ b/src/latex/rnaz__utils_8h.tex @@ -0,0 +1,330 @@ +\hypertarget{rnaz__utils_8h}{}\section{rnaz\+\_\+utils.\+h File Reference} +\label{rnaz__utils_8h}\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{rnaz__utils_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Classes} +\begin{DoxyCompactItemize} +\item +struct \hyperlink{structaln}{aln} +\end{DoxyCompactItemize} +\subsection*{Macros} +\begin{DoxyCompactItemize} +\item +\#define \hyperlink{rnaz__utils_8h_a5e151c615eda34903514212f05a5ccf8}{P\+R\+I\+V\+A\+TE}~static +\item +\#define \hyperlink{rnaz__utils_8h_a9b65dc832210814414fe462bbafba8b8}{M\+A\+X\+\_\+\+N\+U\+M\+\_\+\+N\+A\+M\+ES}~500 +\item +\#define \hyperlink{rnaz__utils_8h_ae0b9cd0ce090bd69b951aa73e8fa4f7d}{M\+I\+N2}(A, B)~((A) $<$ (B) ? (A) \+: (B)) +\end{DoxyCompactItemize} +\subsection*{Enumerations} +\begin{DoxyCompactItemize} +\item +enum \hyperlink{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189}{aln\+Format} \{ \hyperlink{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189a6ce26a62afab55d7606ad4e92428b30c}{U\+N\+K\+N\+O\+WN} =0, +\hyperlink{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189a0c9e4d1c84d67fc10b7d54da4aad56ca}{C\+L\+U\+S\+T\+AL} =1, +\hyperlink{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189a2d41a0476d221862995d2a0a02f6b3b3}{M\+AF} =2 + \} +\end{DoxyCompactItemize} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +int \hyperlink{rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163}{read\+\_\+clustal} (F\+I\+LE $\ast$clust, struct \hyperlink{structaln}{aln} $\ast$aligned\+Seqs\mbox{[}$\,$\mbox{]}) +\item +int \hyperlink{rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476}{read\+\_\+maf} (F\+I\+LE $\ast$clust, struct \hyperlink{structaln}{aln} $\ast$aligned\+Seqs\mbox{[}$\,$\mbox{]}) +\item +char $\ast$ \hyperlink{rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5}{consensus} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +double \hyperlink{rnaz__utils_8h_a802470f11cb32abaa510b2c67f098235}{mean\+Pair\+ID} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2}{rev\+Aln} (struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +double \hyperlink{rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b}{comb\+Per\+Pair} (struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}, char $\ast$structure) +\item +int \hyperlink{rnaz__utils_8h_a48ca69cad11fcf2c4d962b73ff4388ee}{encode\+Base} (char base) +\item +void \hyperlink{rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065}{slice\+Aln} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$source\+Aln\mbox{[}$\,$\mbox{]}, struct \hyperlink{structaln}{aln} $\ast$dest\+Aln\mbox{[}$\,$\mbox{]}, int from, int to) +\item +void \hyperlink{rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673}{free\+Aln} (struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +struct \hyperlink{structaln}{aln} $\ast$ \hyperlink{rnaz__utils_8h_ab3af11f3fc09669574f682072f795865}{create\+Aln\+Entry} (char $\ast$name, char $\ast$seq, int start, int \hyperlink{postscript_8c_a9f59b34b1f25fe00023291b678246bcc}{length}, int full\+Length, char strand) +\item +void \hyperlink{rnaz__utils_8h_ac38565a99389ebf0aed62a623d893299}{free\+Aln\+Entry} (struct \hyperlink{structaln}{aln} $\ast$entry) +\item +void \hyperlink{rnaz__utils_8h_ad1830dc656474e2da129e5322927ee15}{print\+Aln} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +int \hyperlink{rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470}{check\+Format} (F\+I\+LE $\ast$file) +\item +char $\ast$$\ast$ \hyperlink{rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b}{split\+Fields} (char $\ast$string) +\item +void \hyperlink{rnaz__utils_8h_a5afeb493cf63c3077bc7ccc2df25208d}{free\+Fields} (char $\ast$$\ast$fields) +\item +char $\ast$$\ast$ \hyperlink{rnaz__utils_8h_ad897a202b424203bee4a1746872aa095}{split\+Lines} (char $\ast$string) +\item +void \hyperlink{rnaz__utils_8h_a7dc7886bc41a49ff0a19e67451026d81}{print\+Aln\+M\+AF} (F\+I\+LE $\ast$out, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}, int printU) +\item +void \hyperlink{rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb}{prune\+Aln} (char $\ast$species, struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +char $\ast$$\ast$ \hyperlink{rnaz__utils_8h_a7d5f1b4f24c9a156013547278b473278}{split\+String} (char $\ast$string, char $\ast$separators) +\end{DoxyCompactItemize} + + +\subsection{Macro Definition Documentation} +\mbox{\Hypertarget{rnaz__utils_8h_a9b65dc832210814414fe462bbafba8b8}\label{rnaz__utils_8h_a9b65dc832210814414fe462bbafba8b8}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!M\+A\+X\+\_\+\+N\+U\+M\+\_\+\+N\+A\+M\+ES@{M\+A\+X\+\_\+\+N\+U\+M\+\_\+\+N\+A\+M\+ES}} +\index{M\+A\+X\+\_\+\+N\+U\+M\+\_\+\+N\+A\+M\+ES@{M\+A\+X\+\_\+\+N\+U\+M\+\_\+\+N\+A\+M\+ES}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{M\+A\+X\+\_\+\+N\+U\+M\+\_\+\+N\+A\+M\+ES}{MAX\_NUM\_NAMES}} +{\footnotesize\ttfamily \#define M\+A\+X\+\_\+\+N\+U\+M\+\_\+\+N\+A\+M\+ES~500} + +\mbox{\Hypertarget{rnaz__utils_8h_ae0b9cd0ce090bd69b951aa73e8fa4f7d}\label{rnaz__utils_8h_ae0b9cd0ce090bd69b951aa73e8fa4f7d}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!M\+I\+N2@{M\+I\+N2}} +\index{M\+I\+N2@{M\+I\+N2}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{M\+I\+N2}{MIN2}} +{\footnotesize\ttfamily \#define M\+I\+N2(\begin{DoxyParamCaption}\item[{}]{A, }\item[{}]{B }\end{DoxyParamCaption})~((A) $<$ (B) ? (A) \+: (B))} + +\mbox{\Hypertarget{rnaz__utils_8h_a5e151c615eda34903514212f05a5ccf8}\label{rnaz__utils_8h_a5e151c615eda34903514212f05a5ccf8}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!P\+R\+I\+V\+A\+TE@{P\+R\+I\+V\+A\+TE}} +\index{P\+R\+I\+V\+A\+TE@{P\+R\+I\+V\+A\+TE}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{P\+R\+I\+V\+A\+TE}{PRIVATE}} +{\footnotesize\ttfamily \#define P\+R\+I\+V\+A\+TE~static} + + + +\subsection{Enumeration Type Documentation} +\mbox{\Hypertarget{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189}\label{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!aln\+Format@{aln\+Format}} +\index{aln\+Format@{aln\+Format}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{aln\+Format}{alnFormat}} +{\footnotesize\ttfamily enum \hyperlink{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189}{aln\+Format}} + +\begin{DoxyEnumFields}{Enumerator} +\raisebox{\heightof{T}}[0pt][0pt]{\index{U\+N\+K\+N\+O\+WN@{U\+N\+K\+N\+O\+WN}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}}\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!U\+N\+K\+N\+O\+WN@{U\+N\+K\+N\+O\+WN}}}\mbox{\Hypertarget{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189a6ce26a62afab55d7606ad4e92428b30c}\label{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189a6ce26a62afab55d7606ad4e92428b30c}} +U\+N\+K\+N\+O\+WN&\\ +\hline + +\raisebox{\heightof{T}}[0pt][0pt]{\index{C\+L\+U\+S\+T\+AL@{C\+L\+U\+S\+T\+AL}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}}\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!C\+L\+U\+S\+T\+AL@{C\+L\+U\+S\+T\+AL}}}\mbox{\Hypertarget{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189a0c9e4d1c84d67fc10b7d54da4aad56ca}\label{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189a0c9e4d1c84d67fc10b7d54da4aad56ca}} +C\+L\+U\+S\+T\+AL&\\ +\hline + +\raisebox{\heightof{T}}[0pt][0pt]{\index{M\+AF@{M\+AF}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}}\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!M\+AF@{M\+AF}}}\mbox{\Hypertarget{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189a2d41a0476d221862995d2a0a02f6b3b3}\label{rnaz__utils_8h_ad849a5b1ae21b9dd57228a7cc706a189a2d41a0476d221862995d2a0a02f6b3b3}} +M\+AF&\\ +\hline + +\end{DoxyEnumFields} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470}\label{rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!check\+Format@{check\+Format}} +\index{check\+Format@{check\+Format}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{check\+Format()}{checkFormat()}} +{\footnotesize\ttfamily int check\+Format (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{file }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b}\label{rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!comb\+Per\+Pair@{comb\+Per\+Pair}} +\index{comb\+Per\+Pair@{comb\+Per\+Pair}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{comb\+Per\+Pair()}{combPerPair()}} +{\footnotesize\ttfamily double comb\+Per\+Pair (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]}, }\item[{char $\ast$}]{structure }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=260pt]{rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5}\label{rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!consensus@{consensus}} +\index{consensus@{consensus}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{consensus()}{consensus()}} +{\footnotesize\ttfamily char$\ast$ consensus (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=223pt]{rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_ab3af11f3fc09669574f682072f795865}\label{rnaz__utils_8h_ab3af11f3fc09669574f682072f795865}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!create\+Aln\+Entry@{create\+Aln\+Entry}} +\index{create\+Aln\+Entry@{create\+Aln\+Entry}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{create\+Aln\+Entry()}{createAlnEntry()}} +{\footnotesize\ttfamily struct \hyperlink{structaln}{aln}$\ast$ create\+Aln\+Entry (\begin{DoxyParamCaption}\item[{char $\ast$}]{name, }\item[{char $\ast$}]{seq, }\item[{int}]{start, }\item[{int}]{length, }\item[{int}]{full\+Length, }\item[{char}]{strand }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=240pt]{rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_a48ca69cad11fcf2c4d962b73ff4388ee}\label{rnaz__utils_8h_a48ca69cad11fcf2c4d962b73ff4388ee}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!encode\+Base@{encode\+Base}} +\index{encode\+Base@{encode\+Base}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{encode\+Base()}{encodeBase()}} +{\footnotesize\ttfamily int encode\+Base (\begin{DoxyParamCaption}\item[{char}]{base }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673}\label{rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!free\+Aln@{free\+Aln}} +\index{free\+Aln@{free\+Aln}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{free\+Aln()}{freeAln()}} +{\footnotesize\ttfamily void free\+Aln (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=234pt]{rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_ac38565a99389ebf0aed62a623d893299}\label{rnaz__utils_8h_ac38565a99389ebf0aed62a623d893299}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!free\+Aln\+Entry@{free\+Aln\+Entry}} +\index{free\+Aln\+Entry@{free\+Aln\+Entry}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{free\+Aln\+Entry()}{freeAlnEntry()}} +{\footnotesize\ttfamily void free\+Aln\+Entry (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{entry }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8h_a5afeb493cf63c3077bc7ccc2df25208d}\label{rnaz__utils_8h_a5afeb493cf63c3077bc7ccc2df25208d}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!free\+Fields@{free\+Fields}} +\index{free\+Fields@{free\+Fields}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{free\+Fields()}{freeFields()}} +{\footnotesize\ttfamily void free\+Fields (\begin{DoxyParamCaption}\item[{char $\ast$$\ast$}]{fields }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8h_a802470f11cb32abaa510b2c67f098235}\label{rnaz__utils_8h_a802470f11cb32abaa510b2c67f098235}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!mean\+Pair\+ID@{mean\+Pair\+ID}} +\index{mean\+Pair\+ID@{mean\+Pair\+ID}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{mean\+Pair\+I\+D()}{meanPairID()}} +{\footnotesize\ttfamily double mean\+Pair\+ID (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8h_ad1830dc656474e2da129e5322927ee15}\label{rnaz__utils_8h_ad1830dc656474e2da129e5322927ee15}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!print\+Aln@{print\+Aln}} +\index{print\+Aln@{print\+Aln}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{print\+Aln()}{printAln()}} +{\footnotesize\ttfamily void print\+Aln (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8h_a7dc7886bc41a49ff0a19e67451026d81}\label{rnaz__utils_8h_a7dc7886bc41a49ff0a19e67451026d81}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!print\+Aln\+M\+AF@{print\+Aln\+M\+AF}} +\index{print\+Aln\+M\+AF@{print\+Aln\+M\+AF}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{print\+Aln\+M\+A\+F()}{printAlnMAF()}} +{\footnotesize\ttfamily void print\+Aln\+M\+AF (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{out, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]}, }\item[{int}]{printU }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb}\label{rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!prune\+Aln@{prune\+Aln}} +\index{prune\+Aln@{prune\+Aln}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{prune\+Aln()}{pruneAln()}} +{\footnotesize\ttfamily void prune\+Aln (\begin{DoxyParamCaption}\item[{char $\ast$}]{species, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=231pt]{rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163}\label{rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!read\+\_\+clustal@{read\+\_\+clustal}} +\index{read\+\_\+clustal@{read\+\_\+clustal}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{read\+\_\+clustal()}{read\_clustal()}} +{\footnotesize\ttfamily int read\+\_\+clustal (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{clust, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{aligned\+Seqs\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476}\label{rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!read\+\_\+maf@{read\+\_\+maf}} +\index{read\+\_\+maf@{read\+\_\+maf}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{read\+\_\+maf()}{read\_maf()}} +{\footnotesize\ttfamily int read\+\_\+maf (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{clust, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{aligned\+Seqs\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2}\label{rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!rev\+Aln@{rev\+Aln}} +\index{rev\+Aln@{rev\+Aln}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{rev\+Aln()}{revAln()}} +{\footnotesize\ttfamily void rev\+Aln (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=203pt]{rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065}\label{rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!slice\+Aln@{slice\+Aln}} +\index{slice\+Aln@{slice\+Aln}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{slice\+Aln()}{sliceAln()}} +{\footnotesize\ttfamily void slice\+Aln (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{source\+Aln\mbox{[}$\,$\mbox{]}, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{dest\+Aln\mbox{[}$\,$\mbox{]}, }\item[{int}]{from, }\item[{int}]{to }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=327pt]{rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b}\label{rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!split\+Fields@{split\+Fields}} +\index{split\+Fields@{split\+Fields}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{split\+Fields()}{splitFields()}} +{\footnotesize\ttfamily char$\ast$$\ast$ split\+Fields (\begin{DoxyParamCaption}\item[{char $\ast$}]{string }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=307pt]{rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_ad897a202b424203bee4a1746872aa095}\label{rnaz__utils_8h_ad897a202b424203bee4a1746872aa095}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!split\+Lines@{split\+Lines}} +\index{split\+Lines@{split\+Lines}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{split\+Lines()}{splitLines()}} +{\footnotesize\ttfamily char$\ast$$\ast$ split\+Lines (\begin{DoxyParamCaption}\item[{char $\ast$}]{string }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=304pt]{rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{rnaz__utils_8h_a7d5f1b4f24c9a156013547278b473278}\label{rnaz__utils_8h_a7d5f1b4f24c9a156013547278b473278}} +\index{rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}!split\+String@{split\+String}} +\index{split\+String@{split\+String}!rnaz\+\_\+utils.\+h@{rnaz\+\_\+utils.\+h}} +\subsubsection{\texorpdfstring{split\+String()}{splitString()}} +{\footnotesize\ttfamily char$\ast$$\ast$ split\+String (\begin{DoxyParamCaption}\item[{char $\ast$}]{string, }\item[{char $\ast$}]{separators }\end{DoxyParamCaption})} + diff --git a/src/latex/rnaz__utils_8h__dep__incl.md5 b/src/latex/rnaz__utils_8h__dep__incl.md5 new file mode 100644 index 0000000..64de747 --- /dev/null +++ b/src/latex/rnaz__utils_8h__dep__incl.md5 @@ -0,0 +1 @@ +7196c8e09fa3f1bbdbcf4780972b1ad3 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h__dep__incl.pdf b/src/latex/rnaz__utils_8h__dep__incl.pdf new file mode 100644 index 0000000..04f45c1 Binary files /dev/null and b/src/latex/rnaz__utils_8h__dep__incl.pdf differ diff --git a/src/latex/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 b/src/latex/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 new file mode 100644 index 0000000..70809fa --- /dev/null +++ b/src/latex/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.md5 @@ -0,0 +1 @@ +c3406820ccf11417b00ce08b78048881 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.pdf b/src/latex/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.pdf new file mode 100644 index 0000000..5965f45 Binary files /dev/null and b/src/latex/rnaz__utils_8h_a174b786ba35d783d0937a545d2d4071b_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 b/src/latex/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 new file mode 100644 index 0000000..7034ed9 --- /dev/null +++ b/src/latex/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.md5 @@ -0,0 +1 @@ +82ca692459b96417f0065de93408a054 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.pdf b/src/latex/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.pdf new file mode 100644 index 0000000..50e5b03 Binary files /dev/null and b/src/latex/rnaz__utils_8h_a2207280ef510cc5d737b0b04bcfba476_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 b/src/latex/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 new file mode 100644 index 0000000..85074af --- /dev/null +++ b/src/latex/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.md5 @@ -0,0 +1 @@ +bf0d32757a865064d412d1714c15ac46 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.pdf b/src/latex/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.pdf new file mode 100644 index 0000000..93bcf31 Binary files /dev/null and b/src/latex/rnaz__utils_8h_a43cebeec9c40c9be2970b4ed266e7065_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.md5 b/src/latex/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.md5 new file mode 100644 index 0000000..fb64d4b --- /dev/null +++ b/src/latex/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.md5 @@ -0,0 +1 @@ +b28e5564a097c9f1d1f2a4d72383bd09 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.pdf b/src/latex/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.pdf new file mode 100644 index 0000000..3e9ce82 Binary files /dev/null and b/src/latex/rnaz__utils_8h_a4dbf87f40603a4c37ccb6e312f7ee4fb_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 b/src/latex/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 new file mode 100644 index 0000000..e939d78 --- /dev/null +++ b/src/latex/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.md5 @@ -0,0 +1 @@ +e960c9b463fc805e427a0881c31ec05f \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.pdf b/src/latex/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.pdf new file mode 100644 index 0000000..75b6342 Binary files /dev/null and b/src/latex/rnaz__utils_8h_a7e802ce86090ca9375d5e39ebacc1470_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 b/src/latex/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 new file mode 100644 index 0000000..95c7fb3 --- /dev/null +++ b/src/latex/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.md5 @@ -0,0 +1 @@ +e51375dd76f825ba3aa0a615ef04abf3 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.pdf b/src/latex/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.pdf new file mode 100644 index 0000000..e18d7a6 Binary files /dev/null and b/src/latex/rnaz__utils_8h_a9c0adcc1f46e9fceab51c54bd25475e2_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 b/src/latex/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 new file mode 100644 index 0000000..1f9fba1 --- /dev/null +++ b/src/latex/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.md5 @@ -0,0 +1 @@ +8429cc9888f9c5599cbb9b5d766d4b0f \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.pdf b/src/latex/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.pdf new file mode 100644 index 0000000..bef2d88 Binary files /dev/null and b/src/latex/rnaz__utils_8h_aa5d9fd87f6384e8d19af13f1365b503b_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 b/src/latex/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 new file mode 100644 index 0000000..fc126af --- /dev/null +++ b/src/latex/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.md5 @@ -0,0 +1 @@ +011391e7643303d28d2d4522b7ed7be0 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.pdf b/src/latex/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.pdf new file mode 100644 index 0000000..6c44e50 Binary files /dev/null and b/src/latex/rnaz__utils_8h_aa870f4f41dc7bf4808af716a34482ac5_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.md5 b/src/latex/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.md5 new file mode 100644 index 0000000..6389fc8 --- /dev/null +++ b/src/latex/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.md5 @@ -0,0 +1 @@ +a38e296ee5e8035ec3313afd723a04cf \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.pdf b/src/latex/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.pdf new file mode 100644 index 0000000..d151bd9 Binary files /dev/null and b/src/latex/rnaz__utils_8h_ab3af11f3fc09669574f682072f795865_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.md5 b/src/latex/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.md5 new file mode 100644 index 0000000..c6acc36 --- /dev/null +++ b/src/latex/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.md5 @@ -0,0 +1 @@ +9db954e950fee9f8c546b8446897d43f \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.pdf b/src/latex/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.pdf new file mode 100644 index 0000000..8d22e58 Binary files /dev/null and b/src/latex/rnaz__utils_8h_ace5cb65b010161f9eb138717b4592673_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 b/src/latex/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 new file mode 100644 index 0000000..465ff0e --- /dev/null +++ b/src/latex/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.md5 @@ -0,0 +1 @@ +4e79f07584ccb736e844d74fe08b8b05 \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.pdf b/src/latex/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.pdf new file mode 100644 index 0000000..3f88bb7 Binary files /dev/null and b/src/latex/rnaz__utils_8h_ad571d9ad5858c8e2d834225efec51163_cgraph.pdf differ diff --git a/src/latex/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.md5 b/src/latex/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.md5 new file mode 100644 index 0000000..6317bc0 --- /dev/null +++ b/src/latex/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.md5 @@ -0,0 +1 @@ +49e5dd0b060c49ffc1b1414cb642ebcd \ No newline at end of file diff --git a/src/latex/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.pdf b/src/latex/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.pdf new file mode 100644 index 0000000..2d1a26e Binary files /dev/null and b/src/latex/rnaz__utils_8h_ad897a202b424203bee4a1746872aa095_cgraph.pdf differ diff --git a/src/latex/score_8c.tex b/src/latex/score_8c.tex new file mode 100644 index 0000000..0e1fc08 --- /dev/null +++ b/src/latex/score_8c.tex @@ -0,0 +1,327 @@ +\hypertarget{score_8c}{}\section{score.\+c File Reference} +\label{score_8c}\index{score.\+c@{score.\+c}} +{\ttfamily \#include $<$string.\+h$>$}\newline +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include $<$stdlib.\+h$>$}\newline +{\ttfamily \#include $<$math.\+h$>$}\newline +{\ttfamily \#include \char`\"{}score.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}R\+N\+Acode.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}code.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}misc.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}extreme\+\_\+fit.\+h\char`\"{}}\newline +Include dependency graph for score.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{score_8c__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +int $\ast$$\ast$ \hyperlink{score_8c_a5deb0fecb3a13330879241f24575ac6c}{get\+Scoring\+Matrix} () +\item +void \hyperlink{score_8c_a92e464aeb840be0a3082485f30bd094b}{free\+Scoring\+Matrix} (int $\ast$$\ast$matrix) +\item +void \hyperlink{score_8c_afa0b54f696bdcdf5395fb5e5185bd129}{calculate\+BG} (\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{treeSimulate_8c_a027a1f1731d22465c926ce57be2364c3}{model}) +\item +float \hyperlink{score_8c_a10a41c7b92952d470f0f8d2af7bd2c1b}{prob\+H\+KY} (int i, int j, float d, float freqs\mbox{[}4\mbox{]}, float kappa) +\item +void \hyperlink{score_8c_a73aae058cfc643479adf77c5ffc48a45}{count\+Freqs\+Mono} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, float freqs\mbox{[}$\,$\mbox{]}) +\item +\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$ \hyperlink{score_8c_ad5c373a610e54d23a1cb8500d2634e9b}{get\+Models} (T\+Tree $\ast$tree, struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, float kappa) +\item +void \hyperlink{score_8c_a303c139a77497eb1282c6d2a4d415c1c}{free\+Models} (\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models}, int N) +\item +float \hyperlink{score_8c_aa7ac5e027c4335c220657e63d95b18ec}{calculate\+Sigma} (char $\ast$block\+\_\+0, char $\ast$block\+\_\+k, int k, \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models}) +\item +void \hyperlink{score_8c_a6589227c4b47c35cca34ecc18c7f9634}{get\+Pairwise\+Score\+Matrix} (\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models}, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +\hyperlink{score_8h_a0751e1c4932f95e3e60c73409408a97f}{backtrack\+Data} $\ast$ \hyperlink{score_8c_a0557015d88daf987d0730792a31493ad}{backtrack} (int opt\+\_\+b, int opt\+\_\+i, float $\ast$$\ast$$\ast$$\ast$S\+Sk, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +float $\ast$$\ast$ \hyperlink{score_8c_af6b84950cd47402f4580d56eb22854fd}{get\+Multiple\+Score\+Matrix} (float $\ast$$\ast$$\ast$$\ast$\hyperlink{score_8c_a1662932a5f2814e67dfbbd95ab925073}{Sk}, \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models}, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} $\ast$ \hyperlink{score_8c_a93045a86d8c050d38eed9c213ced83c7}{get\+H\+SS} (float $\ast$$\ast$S, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$$\ast$input\+Aln, char strand) +\item +int \hyperlink{score_8c_aa313efebb5f1c1c987e98178c1668452}{get\+Extreme\+Value\+Pars} (T\+Tree $\ast$tree, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, int sampleN, float max\+Native\+Score, float $\ast$par\+Mu, float $\ast$par\+Lambda) +\item +\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} $\ast$ \hyperlink{score_8c_a098269687ae30d844d2c6b58793f2d2c}{score\+Aln} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$input\+Aln\mbox{[}$\,$\mbox{]}, T\+Tree $\ast$tree, float kappa, int \hyperlink{score_8h_a0557015d88daf987d0730792a31493ad}{backtrack}) +\item +void \hyperlink{score_8c_ab2954f5929699167062e554323b3ec08}{freeS} (float $\ast$$\ast$S, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{score_8c_a39c41782e70b3f6d743e3287c015d573}{free\+Sk} (float $\ast$$\ast$$\ast$$\ast$S, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +\hyperlink{RNAcode_8h_ac21aeabbefffddb27496994611a09dcd}{parameters} \hyperlink{score_8c_a8dea3b88a171ed8de9f8f98079e7561a}{pars} +\item +int \hyperlink{score_8c_a119a7eb0ecd417f83e41f4325ce522c8}{transcode} \mbox{[}4\mbox{]}\mbox{[}4\mbox{]}\mbox{[}4\mbox{]} +\item +int \hyperlink{score_8c_a528f2f941a2c7a8de187c946e438d107}{B\+L\+O\+S\+U\+M62} \mbox{[}24\mbox{]}\mbox{[}24\mbox{]} +\item +int \hyperlink{score_8c_addcd68ee32c359359fcb55b5bfd8a62f}{B\+L\+O\+S\+U\+M90} \mbox{[}24\mbox{]}\mbox{[}24\mbox{]} +\item +\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$ \hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models} +\item +\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$ \hyperlink{score_8c_a63827dfbc95488762e66ea061bc89afd}{models\+Rev} +\item +float $\ast$$\ast$$\ast$$\ast$ \hyperlink{score_8c_a1662932a5f2814e67dfbbd95ab925073}{Sk} +\item +float $\ast$$\ast$$\ast$$\ast$ \hyperlink{score_8c_a189ec0118947b93b0df1359ab643d3ce}{Sk\+\_\+native} +\item +float $\ast$$\ast$$\ast$$\ast$ \hyperlink{score_8c_a720f3e09e87f08ee95fd84af1c9c575e}{Sk\+\_\+native\+\_\+rev} +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{score_8c_a0557015d88daf987d0730792a31493ad}\label{score_8c_a0557015d88daf987d0730792a31493ad}} +\index{score.\+c@{score.\+c}!backtrack@{backtrack}} +\index{backtrack@{backtrack}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{backtrack()}{backtrack()}} +{\footnotesize\ttfamily \hyperlink{score_8h_a0751e1c4932f95e3e60c73409408a97f}{backtrack\+Data}$\ast$ backtrack (\begin{DoxyParamCaption}\item[{int}]{opt\+\_\+b, }\item[{int}]{opt\+\_\+i, }\item[{float $\ast$$\ast$$\ast$$\ast$}]{S\+Sk, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=252pt]{score_8c_a0557015d88daf987d0730792a31493ad_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_afa0b54f696bdcdf5395fb5e5185bd129}\label{score_8c_afa0b54f696bdcdf5395fb5e5185bd129}} +\index{score.\+c@{score.\+c}!calculate\+BG@{calculate\+BG}} +\index{calculate\+BG@{calculate\+BG}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{calculate\+B\+G()}{calculateBG()}} +{\footnotesize\ttfamily void calculate\+BG (\begin{DoxyParamCaption}\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{model }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=242pt]{score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_aa7ac5e027c4335c220657e63d95b18ec}\label{score_8c_aa7ac5e027c4335c220657e63d95b18ec}} +\index{score.\+c@{score.\+c}!calculate\+Sigma@{calculate\+Sigma}} +\index{calculate\+Sigma@{calculate\+Sigma}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{calculate\+Sigma()}{calculateSigma()}} +{\footnotesize\ttfamily float calculate\+Sigma (\begin{DoxyParamCaption}\item[{char $\ast$}]{block\+\_\+0, }\item[{char $\ast$}]{block\+\_\+k, }\item[{int}]{k, }\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{models }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=239pt]{score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_a73aae058cfc643479adf77c5ffc48a45}\label{score_8c_a73aae058cfc643479adf77c5ffc48a45}} +\index{score.\+c@{score.\+c}!count\+Freqs\+Mono@{count\+Freqs\+Mono}} +\index{count\+Freqs\+Mono@{count\+Freqs\+Mono}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{count\+Freqs\+Mono()}{countFreqsMono()}} +{\footnotesize\ttfamily void count\+Freqs\+Mono (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{float}]{freqs\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8c_a303c139a77497eb1282c6d2a4d415c1c}\label{score_8c_a303c139a77497eb1282c6d2a4d415c1c}} +\index{score.\+c@{score.\+c}!free\+Models@{free\+Models}} +\index{free\+Models@{free\+Models}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{free\+Models()}{freeModels()}} +{\footnotesize\ttfamily void free\+Models (\begin{DoxyParamCaption}\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{models, }\item[{int}]{N }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=274pt]{score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_ab2954f5929699167062e554323b3ec08}\label{score_8c_ab2954f5929699167062e554323b3ec08}} +\index{score.\+c@{score.\+c}!freeS@{freeS}} +\index{freeS@{freeS}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{free\+S()}{freeS()}} +{\footnotesize\ttfamily void freeS (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$}]{S, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=233pt]{score_8c_ab2954f5929699167062e554323b3ec08_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_a92e464aeb840be0a3082485f30bd094b}\label{score_8c_a92e464aeb840be0a3082485f30bd094b}} +\index{score.\+c@{score.\+c}!free\+Scoring\+Matrix@{free\+Scoring\+Matrix}} +\index{free\+Scoring\+Matrix@{free\+Scoring\+Matrix}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{free\+Scoring\+Matrix()}{freeScoringMatrix()}} +{\footnotesize\ttfamily void free\+Scoring\+Matrix (\begin{DoxyParamCaption}\item[{int $\ast$$\ast$}]{matrix }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8c_a39c41782e70b3f6d743e3287c015d573}\label{score_8c_a39c41782e70b3f6d743e3287c015d573}} +\index{score.\+c@{score.\+c}!free\+Sk@{free\+Sk}} +\index{free\+Sk@{free\+Sk}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{free\+Sk()}{freeSk()}} +{\footnotesize\ttfamily void free\+Sk (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$$\ast$$\ast$}]{S, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=238pt]{score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_aa313efebb5f1c1c987e98178c1668452}\label{score_8c_aa313efebb5f1c1c987e98178c1668452}} +\index{score.\+c@{score.\+c}!get\+Extreme\+Value\+Pars@{get\+Extreme\+Value\+Pars}} +\index{get\+Extreme\+Value\+Pars@{get\+Extreme\+Value\+Pars}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{get\+Extreme\+Value\+Pars()}{getExtremeValuePars()}} +{\footnotesize\ttfamily int get\+Extreme\+Value\+Pars (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{int}]{sampleN, }\item[{float}]{max\+Native\+Score, }\item[{float $\ast$}]{par\+Mu, }\item[{float $\ast$}]{par\+Lambda }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_a93045a86d8c050d38eed9c213ced83c7}\label{score_8c_a93045a86d8c050d38eed9c213ced83c7}} +\index{score.\+c@{score.\+c}!get\+H\+SS@{get\+H\+SS}} +\index{get\+H\+SS@{get\+H\+SS}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{get\+H\+S\+S()}{getHSS()}} +{\footnotesize\ttfamily \hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}$\ast$ get\+H\+SS (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$}]{S, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$$\ast$}]{input\+Aln, }\item[{char}]{strand }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=244pt]{score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_ad5c373a610e54d23a1cb8500d2634e9b}\label{score_8c_ad5c373a610e54d23a1cb8500d2634e9b}} +\index{score.\+c@{score.\+c}!get\+Models@{get\+Models}} +\index{get\+Models@{get\+Models}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{get\+Models()}{getModels()}} +{\footnotesize\ttfamily \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model}$\ast$ get\+Models (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{float}]{kappa }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_af6b84950cd47402f4580d56eb22854fd}\label{score_8c_af6b84950cd47402f4580d56eb22854fd}} +\index{score.\+c@{score.\+c}!get\+Multiple\+Score\+Matrix@{get\+Multiple\+Score\+Matrix}} +\index{get\+Multiple\+Score\+Matrix@{get\+Multiple\+Score\+Matrix}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{get\+Multiple\+Score\+Matrix()}{getMultipleScoreMatrix()}} +{\footnotesize\ttfamily float$\ast$$\ast$ get\+Multiple\+Score\+Matrix (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$$\ast$$\ast$}]{Sk, }\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{models, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=309pt]{score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_a6589227c4b47c35cca34ecc18c7f9634}\label{score_8c_a6589227c4b47c35cca34ecc18c7f9634}} +\index{score.\+c@{score.\+c}!get\+Pairwise\+Score\+Matrix@{get\+Pairwise\+Score\+Matrix}} +\index{get\+Pairwise\+Score\+Matrix@{get\+Pairwise\+Score\+Matrix}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{get\+Pairwise\+Score\+Matrix()}{getPairwiseScoreMatrix()}} +{\footnotesize\ttfamily void get\+Pairwise\+Score\+Matrix (\begin{DoxyParamCaption}\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{models, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8c_a5deb0fecb3a13330879241f24575ac6c}\label{score_8c_a5deb0fecb3a13330879241f24575ac6c}} +\index{score.\+c@{score.\+c}!get\+Scoring\+Matrix@{get\+Scoring\+Matrix}} +\index{get\+Scoring\+Matrix@{get\+Scoring\+Matrix}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{get\+Scoring\+Matrix()}{getScoringMatrix()}} +{\footnotesize\ttfamily int$\ast$$\ast$ get\+Scoring\+Matrix (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8c_a10a41c7b92952d470f0f8d2af7bd2c1b}\label{score_8c_a10a41c7b92952d470f0f8d2af7bd2c1b}} +\index{score.\+c@{score.\+c}!prob\+H\+KY@{prob\+H\+KY}} +\index{prob\+H\+KY@{prob\+H\+KY}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{prob\+H\+K\+Y()}{probHKY()}} +{\footnotesize\ttfamily float prob\+H\+KY (\begin{DoxyParamCaption}\item[{int}]{i, }\item[{int}]{j, }\item[{float}]{d, }\item[{float}]{freqs\mbox{[}4\mbox{]}, }\item[{float}]{kappa }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8c_a098269687ae30d844d2c6b58793f2d2c}\label{score_8c_a098269687ae30d844d2c6b58793f2d2c}} +\index{score.\+c@{score.\+c}!score\+Aln@{score\+Aln}} +\index{score\+Aln@{score\+Aln}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{score\+Aln()}{scoreAln()}} +{\footnotesize\ttfamily \hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}$\ast$ score\+Aln (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{input\+Aln\mbox{[}$\,$\mbox{]}, }\item[{T\+Tree $\ast$}]{tree, }\item[{float}]{kappa, }\item[{int}]{backtrack }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph} +\end{center} +\end{figure} + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{score_8c_a528f2f941a2c7a8de187c946e438d107}\label{score_8c_a528f2f941a2c7a8de187c946e438d107}} +\index{score.\+c@{score.\+c}!B\+L\+O\+S\+U\+M62@{B\+L\+O\+S\+U\+M62}} +\index{B\+L\+O\+S\+U\+M62@{B\+L\+O\+S\+U\+M62}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{B\+L\+O\+S\+U\+M62}{BLOSUM62}} +{\footnotesize\ttfamily int B\+L\+O\+S\+U\+M62\mbox{[}24\mbox{]}\mbox{[}24\mbox{]}} + +\mbox{\Hypertarget{score_8c_addcd68ee32c359359fcb55b5bfd8a62f}\label{score_8c_addcd68ee32c359359fcb55b5bfd8a62f}} +\index{score.\+c@{score.\+c}!B\+L\+O\+S\+U\+M90@{B\+L\+O\+S\+U\+M90}} +\index{B\+L\+O\+S\+U\+M90@{B\+L\+O\+S\+U\+M90}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{B\+L\+O\+S\+U\+M90}{BLOSUM90}} +{\footnotesize\ttfamily int B\+L\+O\+S\+U\+M90\mbox{[}24\mbox{]}\mbox{[}24\mbox{]}} + +\mbox{\Hypertarget{score_8c_a2351b02aa48f9f78d350b4b19408d38f}\label{score_8c_a2351b02aa48f9f78d350b4b19408d38f}} +\index{score.\+c@{score.\+c}!models@{models}} +\index{models@{models}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{models}{models}} +{\footnotesize\ttfamily \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model}$\ast$ models} + +\mbox{\Hypertarget{score_8c_a63827dfbc95488762e66ea061bc89afd}\label{score_8c_a63827dfbc95488762e66ea061bc89afd}} +\index{score.\+c@{score.\+c}!models\+Rev@{models\+Rev}} +\index{models\+Rev@{models\+Rev}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{models\+Rev}{modelsRev}} +{\footnotesize\ttfamily \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model}$\ast$ models\+Rev} + +\mbox{\Hypertarget{score_8c_a8dea3b88a171ed8de9f8f98079e7561a}\label{score_8c_a8dea3b88a171ed8de9f8f98079e7561a}} +\index{score.\+c@{score.\+c}!pars@{pars}} +\index{pars@{pars}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{pars}{pars}} +{\footnotesize\ttfamily \hyperlink{RNAcode_8h_ac21aeabbefffddb27496994611a09dcd}{parameters} pars} + +\mbox{\Hypertarget{score_8c_a1662932a5f2814e67dfbbd95ab925073}\label{score_8c_a1662932a5f2814e67dfbbd95ab925073}} +\index{score.\+c@{score.\+c}!Sk@{Sk}} +\index{Sk@{Sk}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{Sk}{Sk}} +{\footnotesize\ttfamily float$\ast$$\ast$$\ast$$\ast$ Sk} + +\mbox{\Hypertarget{score_8c_a189ec0118947b93b0df1359ab643d3ce}\label{score_8c_a189ec0118947b93b0df1359ab643d3ce}} +\index{score.\+c@{score.\+c}!Sk\+\_\+native@{Sk\+\_\+native}} +\index{Sk\+\_\+native@{Sk\+\_\+native}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{Sk\+\_\+native}{Sk\_native}} +{\footnotesize\ttfamily float$\ast$$\ast$$\ast$$\ast$ Sk\+\_\+native} + +\mbox{\Hypertarget{score_8c_a720f3e09e87f08ee95fd84af1c9c575e}\label{score_8c_a720f3e09e87f08ee95fd84af1c9c575e}} +\index{score.\+c@{score.\+c}!Sk\+\_\+native\+\_\+rev@{Sk\+\_\+native\+\_\+rev}} +\index{Sk\+\_\+native\+\_\+rev@{Sk\+\_\+native\+\_\+rev}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{Sk\+\_\+native\+\_\+rev}{Sk\_native\_rev}} +{\footnotesize\ttfamily float$\ast$$\ast$$\ast$$\ast$ Sk\+\_\+native\+\_\+rev} + +\mbox{\Hypertarget{score_8c_a119a7eb0ecd417f83e41f4325ce522c8}\label{score_8c_a119a7eb0ecd417f83e41f4325ce522c8}} +\index{score.\+c@{score.\+c}!transcode@{transcode}} +\index{transcode@{transcode}!score.\+c@{score.\+c}} +\subsubsection{\texorpdfstring{transcode}{transcode}} +{\footnotesize\ttfamily int transcode\mbox{[}4\mbox{]}\mbox{[}4\mbox{]}\mbox{[}4\mbox{]}} + diff --git a/src/latex/score_8c__incl.md5 b/src/latex/score_8c__incl.md5 new file mode 100644 index 0000000..ab5ac7c --- /dev/null +++ b/src/latex/score_8c__incl.md5 @@ -0,0 +1 @@ +11aeef3334ac9e698ab449a824d1b803 \ No newline at end of file diff --git a/src/latex/score_8c__incl.pdf b/src/latex/score_8c__incl.pdf new file mode 100644 index 0000000..0beb992 Binary files /dev/null and b/src/latex/score_8c__incl.pdf differ diff --git a/src/latex/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.md5 b/src/latex/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.md5 new file mode 100644 index 0000000..43d1632 --- /dev/null +++ b/src/latex/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.md5 @@ -0,0 +1 @@ +c14797f46d51cf7f5480cf38ec5cc00a \ No newline at end of file diff --git a/src/latex/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.pdf b/src/latex/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.pdf new file mode 100644 index 0000000..72df72f Binary files /dev/null and b/src/latex/score_8c_a0557015d88daf987d0730792a31493ad_cgraph.pdf differ diff --git a/src/latex/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.md5 b/src/latex/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.md5 new file mode 100644 index 0000000..17a54c6 --- /dev/null +++ b/src/latex/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.md5 @@ -0,0 +1 @@ +2fece0c17b10d60c16f166256b8415f3 \ No newline at end of file diff --git a/src/latex/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.pdf b/src/latex/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.pdf new file mode 100644 index 0000000..2654737 Binary files /dev/null and b/src/latex/score_8c_a098269687ae30d844d2c6b58793f2d2c_cgraph.pdf differ diff --git a/src/latex/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 b/src/latex/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 new file mode 100644 index 0000000..828002d --- /dev/null +++ b/src/latex/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.md5 @@ -0,0 +1 @@ +838200128d3d156ff9c552e5531fd191 \ No newline at end of file diff --git a/src/latex/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.pdf b/src/latex/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.pdf new file mode 100644 index 0000000..e6f4a4a Binary files /dev/null and b/src/latex/score_8c_a303c139a77497eb1282c6d2a4d415c1c_cgraph.pdf differ diff --git a/src/latex/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 b/src/latex/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 new file mode 100644 index 0000000..63ea389 --- /dev/null +++ b/src/latex/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 @@ -0,0 +1 @@ +47c2978c7de18e80709d376c3b17fa01 \ No newline at end of file diff --git a/src/latex/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.pdf b/src/latex/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.pdf new file mode 100644 index 0000000..2ba1414 Binary files /dev/null and b/src/latex/score_8c_a39c41782e70b3f6d743e3287c015d573_cgraph.pdf differ diff --git a/src/latex/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 b/src/latex/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 new file mode 100644 index 0000000..0c9dfc3 --- /dev/null +++ b/src/latex/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 @@ -0,0 +1 @@ +c277905ae8ab8bb88ad864765857b711 \ No newline at end of file diff --git a/src/latex/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.pdf b/src/latex/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.pdf new file mode 100644 index 0000000..e6bde7b Binary files /dev/null and b/src/latex/score_8c_a6589227c4b47c35cca34ecc18c7f9634_cgraph.pdf differ diff --git a/src/latex/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 b/src/latex/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 new file mode 100644 index 0000000..a6d7277 --- /dev/null +++ b/src/latex/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 @@ -0,0 +1 @@ +bfe877f18585a816af50437f884e78a7 \ No newline at end of file diff --git a/src/latex/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.pdf b/src/latex/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.pdf new file mode 100644 index 0000000..e631783 Binary files /dev/null and b/src/latex/score_8c_a93045a86d8c050d38eed9c213ced83c7_cgraph.pdf differ diff --git a/src/latex/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 b/src/latex/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 new file mode 100644 index 0000000..2c52bcd --- /dev/null +++ b/src/latex/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 @@ -0,0 +1 @@ +c3230cc52fc3ba713f7af9ee59c8fde8 \ No newline at end of file diff --git a/src/latex/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.pdf b/src/latex/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.pdf new file mode 100644 index 0000000..784815e Binary files /dev/null and b/src/latex/score_8c_aa313efebb5f1c1c987e98178c1668452_cgraph.pdf differ diff --git a/src/latex/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.md5 b/src/latex/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.md5 new file mode 100644 index 0000000..8bec9e6 --- /dev/null +++ b/src/latex/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.md5 @@ -0,0 +1 @@ +8ec4184ab498617e24c52c1bff11dbaa \ No newline at end of file diff --git a/src/latex/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.pdf b/src/latex/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.pdf new file mode 100644 index 0000000..b4bbdf5 Binary files /dev/null and b/src/latex/score_8c_aa7ac5e027c4335c220657e63d95b18ec_cgraph.pdf differ diff --git a/src/latex/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.md5 b/src/latex/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.md5 new file mode 100644 index 0000000..9f41a87 --- /dev/null +++ b/src/latex/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.md5 @@ -0,0 +1 @@ +9be50b5987c511680a2eccc1e866e5f6 \ No newline at end of file diff --git a/src/latex/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.pdf b/src/latex/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.pdf new file mode 100644 index 0000000..8868517 Binary files /dev/null and b/src/latex/score_8c_ab2954f5929699167062e554323b3ec08_cgraph.pdf differ diff --git a/src/latex/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 b/src/latex/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 new file mode 100644 index 0000000..0e6d19f --- /dev/null +++ b/src/latex/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 @@ -0,0 +1 @@ +fd789b452e313be6d85641f7b8851a0a \ No newline at end of file diff --git a/src/latex/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.pdf b/src/latex/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.pdf new file mode 100644 index 0000000..3a13375 Binary files /dev/null and b/src/latex/score_8c_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.pdf differ diff --git a/src/latex/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 b/src/latex/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 new file mode 100644 index 0000000..413fdc2 --- /dev/null +++ b/src/latex/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 @@ -0,0 +1 @@ +e8f5dfb0053012412fb12ea2fa0d3f19 \ No newline at end of file diff --git a/src/latex/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.pdf b/src/latex/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.pdf new file mode 100644 index 0000000..673d6ec Binary files /dev/null and b/src/latex/score_8c_af6b84950cd47402f4580d56eb22854fd_cgraph.pdf differ diff --git a/src/latex/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.md5 b/src/latex/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.md5 new file mode 100644 index 0000000..f18352c --- /dev/null +++ b/src/latex/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.md5 @@ -0,0 +1 @@ +611ef47e8f4ff346a98fc60d6761577a \ No newline at end of file diff --git a/src/latex/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.pdf b/src/latex/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.pdf new file mode 100644 index 0000000..f2295cc Binary files /dev/null and b/src/latex/score_8c_afa0b54f696bdcdf5395fb5e5185bd129_cgraph.pdf differ diff --git a/src/latex/score_8h.tex b/src/latex/score_8h.tex new file mode 100644 index 0000000..ee3d417 --- /dev/null +++ b/src/latex/score_8h.tex @@ -0,0 +1,366 @@ +\hypertarget{score_8h}{}\section{score.\+h File Reference} +\label{score_8h}\index{score.\+h@{score.\+h}} +{\ttfamily \#include \char`\"{}rnaz\+\_\+utils.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}tree.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}tree\+Simulate.\+h\char`\"{}}\newline +Include dependency graph for score.\+h\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=238pt]{score_8h__incl} +\end{center} +\end{figure} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{score_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Classes} +\begin{DoxyCompactItemize} +\item +struct \hyperlink{struct__bgModel}{\+\_\+bg\+Model} +\item +struct \hyperlink{struct__segmentStats}{\+\_\+segment\+Stats} +\item +struct \hyperlink{struct__backtrackData}{\+\_\+backtrack\+Data} +\end{DoxyCompactItemize} +\subsection*{Macros} +\begin{DoxyCompactItemize} +\item +\#define \hyperlink{score_8h_abde25a67f4046530ae1c572cefeb5869}{U\+N\+D\+EF}~-\/9.\+0 +\item +\#define \hyperlink{score_8h_aa48b28e62c168ecef26792b023bedb09}{M\+I\+N\+U\+S\+\_\+\+I\+NF}~-\/99.\+0 +\item +\#define \hyperlink{score_8h_aacc3ee1a7f283f8ef65cea31f4436a95}{M\+AX}(x, y)~(((x)$>$(y)) ? (x) \+: (y)) +\item +\#define \hyperlink{score_8h_a7751a16322c502dc5d35d620b69277af}{M\+A\+X3}(x, y, z)~(\hyperlink{score_8h_aacc3ee1a7f283f8ef65cea31f4436a95}{M\+AX}( (\hyperlink{score_8h_aacc3ee1a7f283f8ef65cea31f4436a95}{M\+AX}((x),(y))) ,(z))) +\item +\#define \hyperlink{score_8h_afb073915b50e7112cfed534aff6524cf}{C\+MP}(x, y)~(((x) $>$ (y) ? ((x)-\/(y)) \+: ((y)-\/(x))) $<$ 0.\+00001) +\end{DoxyCompactItemize} +\subsection*{Typedefs} +\begin{DoxyCompactItemize} +\item +typedef struct \hyperlink{struct__bgModel}{\+\_\+bg\+Model} \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} +\item +typedef struct \hyperlink{struct__segmentStats}{\+\_\+segment\+Stats} \hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} +\item +typedef struct \hyperlink{struct__backtrackData}{\+\_\+backtrack\+Data} \hyperlink{score_8h_a0751e1c4932f95e3e60c73409408a97f}{backtrack\+Data} +\end{DoxyCompactItemize} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +float \hyperlink{score_8h_a10a41c7b92952d470f0f8d2af7bd2c1b}{prob\+H\+KY} (int i, int j, float d, float freqs\mbox{[}4\mbox{]}, float kappa) +\item +int $\ast$$\ast$ \hyperlink{score_8h_a5deb0fecb3a13330879241f24575ac6c}{get\+Scoring\+Matrix} () +\item +void \hyperlink{score_8h_a92e464aeb840be0a3082485f30bd094b}{free\+Scoring\+Matrix} (int $\ast$$\ast$matrix) +\item +void \hyperlink{score_8h_a853a7de0874087a99e452ed917b3fdfa}{calculate\+BG} (\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models}) +\item +void \hyperlink{score_8h_a50f4b7f86944e31e967a5d2e7d045c01}{strip\+Gaps} (struct \hyperlink{structaln}{aln} $\ast$AS\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{score_8h_a73aae058cfc643479adf77c5ffc48a45}{count\+Freqs\+Mono} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, float freqs\mbox{[}$\,$\mbox{]}) +\item +float $\ast$ \hyperlink{score_8h_ab64745553f4c76c089d6dc44f76f639b}{sum\+Of\+Pair\+Score} (\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models}, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, int from, int to) +\item +float $\ast$ \hyperlink{score_8h_ae5aac97ccd98fa3231294f3677204992}{get\+Cum\+Sum} (float $\ast$scores, int N) +\item +\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$ \hyperlink{score_8h_a909825ebbd6f4923c4e425186001f095}{get\+Model\+Matrix} (T\+Tree $\ast$tree, struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, float kappa) +\item +void \hyperlink{score_8h_a5c86ff30dfac4ac88d64ac6db1c6c559}{free\+Model\+Matrix} (\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models}, int N) +\item +int \hyperlink{score_8h_aa313efebb5f1c1c987e98178c1668452}{get\+Extreme\+Value\+Pars} (T\+Tree $\ast$tree, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, int sampleN, float max\+Native\+Score, float $\ast$par\+Mu, float $\ast$par\+Lambda) +\item +\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} $\ast$ \hyperlink{score_8h_a93045a86d8c050d38eed9c213ced83c7}{get\+H\+SS} (float $\ast$$\ast$S, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$$\ast$input\+Aln, char strand) +\item +void \hyperlink{score_8h_a6589227c4b47c35cca34ecc18c7f9634}{get\+Pairwise\+Score\+Matrix} (\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models}, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +float $\ast$$\ast$ \hyperlink{score_8h_af6b84950cd47402f4580d56eb22854fd}{get\+Multiple\+Score\+Matrix} (float $\ast$$\ast$$\ast$$\ast$\hyperlink{score_8c_a1662932a5f2814e67dfbbd95ab925073}{Sk}, \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$\hyperlink{score_8c_a2351b02aa48f9f78d350b4b19408d38f}{models}, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +\hyperlink{score_8h_a0751e1c4932f95e3e60c73409408a97f}{backtrack\+Data} $\ast$ \hyperlink{score_8h_a0557015d88daf987d0730792a31493ad}{backtrack} (int opt\+\_\+b, int opt\+\_\+i, float $\ast$$\ast$$\ast$$\ast$S\+Sk, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{score_8h_a39c41782e70b3f6d743e3287c015d573}{free\+Sk} (float $\ast$$\ast$$\ast$$\ast$S, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{score_8h_ab2954f5929699167062e554323b3ec08}{freeS} (float $\ast$$\ast$S, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +\hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats} $\ast$ \hyperlink{score_8h_af667df05b60aeb3ec0bd6bd423e268db}{score\+Aln} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, T\+Tree $\ast$tree, float kappa, int \hyperlink{score_8h_a0557015d88daf987d0730792a31493ad}{backtrack}) +\item +\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$ \hyperlink{score_8h_ad5c373a610e54d23a1cb8500d2634e9b}{get\+Models} (T\+Tree $\ast$tree, struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, float kappa) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +int \hyperlink{score_8h_a5eb739b80c0e44d631e8cd4b317ea39e}{nt\+Map} \mbox{[}256\mbox{]} +\item +int \hyperlink{score_8h_a119a7eb0ecd417f83e41f4325ce522c8}{transcode} \mbox{[}4\mbox{]}\mbox{[}4\mbox{]}\mbox{[}4\mbox{]} +\end{DoxyCompactItemize} + + +\subsection{Macro Definition Documentation} +\mbox{\Hypertarget{score_8h_afb073915b50e7112cfed534aff6524cf}\label{score_8h_afb073915b50e7112cfed534aff6524cf}} +\index{score.\+h@{score.\+h}!C\+MP@{C\+MP}} +\index{C\+MP@{C\+MP}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{C\+MP}{CMP}} +{\footnotesize\ttfamily \#define C\+MP(\begin{DoxyParamCaption}\item[{}]{x, }\item[{}]{y }\end{DoxyParamCaption})~(((x) $>$ (y) ? ((x)-\/(y)) \+: ((y)-\/(x))) $<$ 0.\+00001)} + +\mbox{\Hypertarget{score_8h_aacc3ee1a7f283f8ef65cea31f4436a95}\label{score_8h_aacc3ee1a7f283f8ef65cea31f4436a95}} +\index{score.\+h@{score.\+h}!M\+AX@{M\+AX}} +\index{M\+AX@{M\+AX}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{M\+AX}{MAX}} +{\footnotesize\ttfamily \#define M\+AX(\begin{DoxyParamCaption}\item[{}]{x, }\item[{}]{y }\end{DoxyParamCaption})~(((x)$>$(y)) ? (x) \+: (y))} + +\mbox{\Hypertarget{score_8h_a7751a16322c502dc5d35d620b69277af}\label{score_8h_a7751a16322c502dc5d35d620b69277af}} +\index{score.\+h@{score.\+h}!M\+A\+X3@{M\+A\+X3}} +\index{M\+A\+X3@{M\+A\+X3}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{M\+A\+X3}{MAX3}} +{\footnotesize\ttfamily \#define M\+A\+X3(\begin{DoxyParamCaption}\item[{}]{x, }\item[{}]{y, }\item[{}]{z }\end{DoxyParamCaption})~(\hyperlink{score_8h_aacc3ee1a7f283f8ef65cea31f4436a95}{M\+AX}( (\hyperlink{score_8h_aacc3ee1a7f283f8ef65cea31f4436a95}{M\+AX}((x),(y))) ,(z)))} + +\mbox{\Hypertarget{score_8h_aa48b28e62c168ecef26792b023bedb09}\label{score_8h_aa48b28e62c168ecef26792b023bedb09}} +\index{score.\+h@{score.\+h}!M\+I\+N\+U\+S\+\_\+\+I\+NF@{M\+I\+N\+U\+S\+\_\+\+I\+NF}} +\index{M\+I\+N\+U\+S\+\_\+\+I\+NF@{M\+I\+N\+U\+S\+\_\+\+I\+NF}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{M\+I\+N\+U\+S\+\_\+\+I\+NF}{MINUS\_INF}} +{\footnotesize\ttfamily \#define M\+I\+N\+U\+S\+\_\+\+I\+NF~-\/99.\+0} + +\mbox{\Hypertarget{score_8h_abde25a67f4046530ae1c572cefeb5869}\label{score_8h_abde25a67f4046530ae1c572cefeb5869}} +\index{score.\+h@{score.\+h}!U\+N\+D\+EF@{U\+N\+D\+EF}} +\index{U\+N\+D\+EF@{U\+N\+D\+EF}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{U\+N\+D\+EF}{UNDEF}} +{\footnotesize\ttfamily \#define U\+N\+D\+EF~-\/9.\+0} + + + +\subsection{Typedef Documentation} +\mbox{\Hypertarget{score_8h_a0751e1c4932f95e3e60c73409408a97f}\label{score_8h_a0751e1c4932f95e3e60c73409408a97f}} +\index{score.\+h@{score.\+h}!backtrack\+Data@{backtrack\+Data}} +\index{backtrack\+Data@{backtrack\+Data}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{backtrack\+Data}{backtrackData}} +{\footnotesize\ttfamily typedef struct \hyperlink{struct__backtrackData}{\+\_\+backtrack\+Data} \hyperlink{score_8h_a0751e1c4932f95e3e60c73409408a97f}{backtrack\+Data}} + +\mbox{\Hypertarget{score_8h_aec88546fa977a827f3312b2c12738421}\label{score_8h_aec88546fa977a827f3312b2c12738421}} +\index{score.\+h@{score.\+h}!bg\+Model@{bg\+Model}} +\index{bg\+Model@{bg\+Model}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{bg\+Model}{bgModel}} +{\footnotesize\ttfamily typedef struct \hyperlink{struct__bgModel}{\+\_\+bg\+Model} \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model}} + +\mbox{\Hypertarget{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}\label{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}} +\index{score.\+h@{score.\+h}!segment\+Stats@{segment\+Stats}} +\index{segment\+Stats@{segment\+Stats}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{segment\+Stats}{segmentStats}} +{\footnotesize\ttfamily typedef struct \hyperlink{struct__segmentStats}{\+\_\+segment\+Stats} \hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}} + + + +\subsection{Function Documentation} +\mbox{\Hypertarget{score_8h_a0557015d88daf987d0730792a31493ad}\label{score_8h_a0557015d88daf987d0730792a31493ad}} +\index{score.\+h@{score.\+h}!backtrack@{backtrack}} +\index{backtrack@{backtrack}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{backtrack()}{backtrack()}} +{\footnotesize\ttfamily \hyperlink{score_8h_a0751e1c4932f95e3e60c73409408a97f}{backtrack\+Data}$\ast$ backtrack (\begin{DoxyParamCaption}\item[{int}]{opt\+\_\+b, }\item[{int}]{opt\+\_\+i, }\item[{float $\ast$$\ast$$\ast$$\ast$}]{S\+Sk, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=252pt]{score_8h_a0557015d88daf987d0730792a31493ad_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8h_a853a7de0874087a99e452ed917b3fdfa}\label{score_8h_a853a7de0874087a99e452ed917b3fdfa}} +\index{score.\+h@{score.\+h}!calculate\+BG@{calculate\+BG}} +\index{calculate\+BG@{calculate\+BG}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{calculate\+B\+G()}{calculateBG()}} +{\footnotesize\ttfamily void calculate\+BG (\begin{DoxyParamCaption}\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{models }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=242pt]{score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8h_a73aae058cfc643479adf77c5ffc48a45}\label{score_8h_a73aae058cfc643479adf77c5ffc48a45}} +\index{score.\+h@{score.\+h}!count\+Freqs\+Mono@{count\+Freqs\+Mono}} +\index{count\+Freqs\+Mono@{count\+Freqs\+Mono}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{count\+Freqs\+Mono()}{countFreqsMono()}} +{\footnotesize\ttfamily void count\+Freqs\+Mono (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{float}]{freqs\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8h_a5c86ff30dfac4ac88d64ac6db1c6c559}\label{score_8h_a5c86ff30dfac4ac88d64ac6db1c6c559}} +\index{score.\+h@{score.\+h}!free\+Model\+Matrix@{free\+Model\+Matrix}} +\index{free\+Model\+Matrix@{free\+Model\+Matrix}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{free\+Model\+Matrix()}{freeModelMatrix()}} +{\footnotesize\ttfamily void free\+Model\+Matrix (\begin{DoxyParamCaption}\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{models, }\item[{int}]{N }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8h_ab2954f5929699167062e554323b3ec08}\label{score_8h_ab2954f5929699167062e554323b3ec08}} +\index{score.\+h@{score.\+h}!freeS@{freeS}} +\index{freeS@{freeS}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{free\+S()}{freeS()}} +{\footnotesize\ttfamily void freeS (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$}]{S, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=233pt]{score_8h_ab2954f5929699167062e554323b3ec08_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8h_a92e464aeb840be0a3082485f30bd094b}\label{score_8h_a92e464aeb840be0a3082485f30bd094b}} +\index{score.\+h@{score.\+h}!free\+Scoring\+Matrix@{free\+Scoring\+Matrix}} +\index{free\+Scoring\+Matrix@{free\+Scoring\+Matrix}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{free\+Scoring\+Matrix()}{freeScoringMatrix()}} +{\footnotesize\ttfamily void free\+Scoring\+Matrix (\begin{DoxyParamCaption}\item[{int $\ast$$\ast$}]{matrix }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8h_a39c41782e70b3f6d743e3287c015d573}\label{score_8h_a39c41782e70b3f6d743e3287c015d573}} +\index{score.\+h@{score.\+h}!free\+Sk@{free\+Sk}} +\index{free\+Sk@{free\+Sk}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{free\+Sk()}{freeSk()}} +{\footnotesize\ttfamily void free\+Sk (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$$\ast$$\ast$}]{S, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=238pt]{score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8h_ae5aac97ccd98fa3231294f3677204992}\label{score_8h_ae5aac97ccd98fa3231294f3677204992}} +\index{score.\+h@{score.\+h}!get\+Cum\+Sum@{get\+Cum\+Sum}} +\index{get\+Cum\+Sum@{get\+Cum\+Sum}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{get\+Cum\+Sum()}{getCumSum()}} +{\footnotesize\ttfamily float$\ast$ get\+Cum\+Sum (\begin{DoxyParamCaption}\item[{float $\ast$}]{scores, }\item[{int}]{N }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8h_aa313efebb5f1c1c987e98178c1668452}\label{score_8h_aa313efebb5f1c1c987e98178c1668452}} +\index{score.\+h@{score.\+h}!get\+Extreme\+Value\+Pars@{get\+Extreme\+Value\+Pars}} +\index{get\+Extreme\+Value\+Pars@{get\+Extreme\+Value\+Pars}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{get\+Extreme\+Value\+Pars()}{getExtremeValuePars()}} +{\footnotesize\ttfamily int get\+Extreme\+Value\+Pars (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{int}]{sampleN, }\item[{float}]{max\+Native\+Score, }\item[{float $\ast$}]{par\+Mu, }\item[{float $\ast$}]{par\+Lambda }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8h_a93045a86d8c050d38eed9c213ced83c7}\label{score_8h_a93045a86d8c050d38eed9c213ced83c7}} +\index{score.\+h@{score.\+h}!get\+H\+SS@{get\+H\+SS}} +\index{get\+H\+SS@{get\+H\+SS}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{get\+H\+S\+S()}{getHSS()}} +{\footnotesize\ttfamily \hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}$\ast$ get\+H\+SS (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$}]{S, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$$\ast$}]{input\+Aln, }\item[{char}]{strand }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=244pt]{score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8h_a909825ebbd6f4923c4e425186001f095}\label{score_8h_a909825ebbd6f4923c4e425186001f095}} +\index{score.\+h@{score.\+h}!get\+Model\+Matrix@{get\+Model\+Matrix}} +\index{get\+Model\+Matrix@{get\+Model\+Matrix}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{get\+Model\+Matrix()}{getModelMatrix()}} +{\footnotesize\ttfamily \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model}$\ast$ get\+Model\+Matrix (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{float}]{kappa }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8h_ad5c373a610e54d23a1cb8500d2634e9b}\label{score_8h_ad5c373a610e54d23a1cb8500d2634e9b}} +\index{score.\+h@{score.\+h}!get\+Models@{get\+Models}} +\index{get\+Models@{get\+Models}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{get\+Models()}{getModels()}} +{\footnotesize\ttfamily \hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model}$\ast$ get\+Models (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{float}]{kappa }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8h_af6b84950cd47402f4580d56eb22854fd}\label{score_8h_af6b84950cd47402f4580d56eb22854fd}} +\index{score.\+h@{score.\+h}!get\+Multiple\+Score\+Matrix@{get\+Multiple\+Score\+Matrix}} +\index{get\+Multiple\+Score\+Matrix@{get\+Multiple\+Score\+Matrix}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{get\+Multiple\+Score\+Matrix()}{getMultipleScoreMatrix()}} +{\footnotesize\ttfamily float$\ast$$\ast$ get\+Multiple\+Score\+Matrix (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$$\ast$$\ast$}]{Sk, }\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{models, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=309pt]{score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8h_a6589227c4b47c35cca34ecc18c7f9634}\label{score_8h_a6589227c4b47c35cca34ecc18c7f9634}} +\index{score.\+h@{score.\+h}!get\+Pairwise\+Score\+Matrix@{get\+Pairwise\+Score\+Matrix}} +\index{get\+Pairwise\+Score\+Matrix@{get\+Pairwise\+Score\+Matrix}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{get\+Pairwise\+Score\+Matrix()}{getPairwiseScoreMatrix()}} +{\footnotesize\ttfamily void get\+Pairwise\+Score\+Matrix (\begin{DoxyParamCaption}\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{models, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8h_a5deb0fecb3a13330879241f24575ac6c}\label{score_8h_a5deb0fecb3a13330879241f24575ac6c}} +\index{score.\+h@{score.\+h}!get\+Scoring\+Matrix@{get\+Scoring\+Matrix}} +\index{get\+Scoring\+Matrix@{get\+Scoring\+Matrix}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{get\+Scoring\+Matrix()}{getScoringMatrix()}} +{\footnotesize\ttfamily int$\ast$$\ast$ get\+Scoring\+Matrix (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8h_a10a41c7b92952d470f0f8d2af7bd2c1b}\label{score_8h_a10a41c7b92952d470f0f8d2af7bd2c1b}} +\index{score.\+h@{score.\+h}!prob\+H\+KY@{prob\+H\+KY}} +\index{prob\+H\+KY@{prob\+H\+KY}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{prob\+H\+K\+Y()}{probHKY()}} +{\footnotesize\ttfamily float prob\+H\+KY (\begin{DoxyParamCaption}\item[{int}]{i, }\item[{int}]{j, }\item[{float}]{d, }\item[{float}]{freqs\mbox{[}4\mbox{]}, }\item[{float}]{kappa }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8h_af667df05b60aeb3ec0bd6bd423e268db}\label{score_8h_af667df05b60aeb3ec0bd6bd423e268db}} +\index{score.\+h@{score.\+h}!score\+Aln@{score\+Aln}} +\index{score\+Aln@{score\+Aln}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{score\+Aln()}{scoreAln()}} +{\footnotesize\ttfamily \hyperlink{score_8h_a5b7f5df9506ff8c871dc49e4bf9f22af}{segment\+Stats}$\ast$ score\+Aln (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{T\+Tree $\ast$}]{tree, }\item[{float}]{kappa, }\item[{int}]{backtrack }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{score_8h_a50f4b7f86944e31e967a5d2e7d045c01}\label{score_8h_a50f4b7f86944e31e967a5d2e7d045c01}} +\index{score.\+h@{score.\+h}!strip\+Gaps@{strip\+Gaps}} +\index{strip\+Gaps@{strip\+Gaps}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{strip\+Gaps()}{stripGaps()}} +{\footnotesize\ttfamily void strip\+Gaps (\begin{DoxyParamCaption}\item[{struct \hyperlink{structaln}{aln} $\ast$}]{AS\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{score_8h_ab64745553f4c76c089d6dc44f76f639b}\label{score_8h_ab64745553f4c76c089d6dc44f76f639b}} +\index{score.\+h@{score.\+h}!sum\+Of\+Pair\+Score@{sum\+Of\+Pair\+Score}} +\index{sum\+Of\+Pair\+Score@{sum\+Of\+Pair\+Score}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{sum\+Of\+Pair\+Score()}{sumOfPairScore()}} +{\footnotesize\ttfamily float$\ast$ sum\+Of\+Pair\+Score (\begin{DoxyParamCaption}\item[{\hyperlink{score_8h_aec88546fa977a827f3312b2c12738421}{bg\+Model} $\ast$}]{models, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{int}]{from, }\item[{int}]{to }\end{DoxyParamCaption})} + + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{score_8h_a5eb739b80c0e44d631e8cd4b317ea39e}\label{score_8h_a5eb739b80c0e44d631e8cd4b317ea39e}} +\index{score.\+h@{score.\+h}!nt\+Map@{nt\+Map}} +\index{nt\+Map@{nt\+Map}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{nt\+Map}{ntMap}} +{\footnotesize\ttfamily int nt\+Map\mbox{[}256\mbox{]}} + +\mbox{\Hypertarget{score_8h_a119a7eb0ecd417f83e41f4325ce522c8}\label{score_8h_a119a7eb0ecd417f83e41f4325ce522c8}} +\index{score.\+h@{score.\+h}!transcode@{transcode}} +\index{transcode@{transcode}!score.\+h@{score.\+h}} +\subsubsection{\texorpdfstring{transcode}{transcode}} +{\footnotesize\ttfamily int transcode\mbox{[}4\mbox{]}\mbox{[}4\mbox{]}\mbox{[}4\mbox{]}} + diff --git a/src/latex/score_8h__dep__incl.md5 b/src/latex/score_8h__dep__incl.md5 new file mode 100644 index 0000000..ebcee48 --- /dev/null +++ b/src/latex/score_8h__dep__incl.md5 @@ -0,0 +1 @@ +24cf213d175abdf2bdd69ba6ee8bca4f \ No newline at end of file diff --git a/src/latex/score_8h__dep__incl.pdf b/src/latex/score_8h__dep__incl.pdf new file mode 100644 index 0000000..b1f2a54 Binary files /dev/null and b/src/latex/score_8h__dep__incl.pdf differ diff --git a/src/latex/score_8h__incl.md5 b/src/latex/score_8h__incl.md5 new file mode 100644 index 0000000..fdfb5b3 --- /dev/null +++ b/src/latex/score_8h__incl.md5 @@ -0,0 +1 @@ +bfc25078e937d1992b34aa484a011750 \ No newline at end of file diff --git a/src/latex/score_8h__incl.pdf b/src/latex/score_8h__incl.pdf new file mode 100644 index 0000000..72fb2d2 Binary files /dev/null and b/src/latex/score_8h__incl.pdf differ diff --git a/src/latex/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.md5 b/src/latex/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.md5 new file mode 100644 index 0000000..43d1632 --- /dev/null +++ b/src/latex/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.md5 @@ -0,0 +1 @@ +c14797f46d51cf7f5480cf38ec5cc00a \ No newline at end of file diff --git a/src/latex/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.pdf b/src/latex/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.pdf new file mode 100644 index 0000000..72df72f Binary files /dev/null and b/src/latex/score_8h_a0557015d88daf987d0730792a31493ad_cgraph.pdf differ diff --git a/src/latex/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 b/src/latex/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 new file mode 100644 index 0000000..bcdf40f --- /dev/null +++ b/src/latex/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.md5 @@ -0,0 +1 @@ +7800f9c5fda102562387a2fcfdae5bc2 \ No newline at end of file diff --git a/src/latex/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.pdf b/src/latex/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.pdf new file mode 100644 index 0000000..2ba1414 Binary files /dev/null and b/src/latex/score_8h_a39c41782e70b3f6d743e3287c015d573_cgraph.pdf differ diff --git a/src/latex/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 b/src/latex/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 new file mode 100644 index 0000000..09d7526 --- /dev/null +++ b/src/latex/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.md5 @@ -0,0 +1 @@ +9c21828e6b05df287a3dfa1fbb8b7d0a \ No newline at end of file diff --git a/src/latex/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.pdf b/src/latex/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.pdf new file mode 100644 index 0000000..e6bde7b Binary files /dev/null and b/src/latex/score_8h_a6589227c4b47c35cca34ecc18c7f9634_cgraph.pdf differ diff --git a/src/latex/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.md5 b/src/latex/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.md5 new file mode 100644 index 0000000..f18352c --- /dev/null +++ b/src/latex/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.md5 @@ -0,0 +1 @@ +611ef47e8f4ff346a98fc60d6761577a \ No newline at end of file diff --git a/src/latex/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.pdf b/src/latex/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.pdf new file mode 100644 index 0000000..f2295cc Binary files /dev/null and b/src/latex/score_8h_a853a7de0874087a99e452ed917b3fdfa_cgraph.pdf differ diff --git a/src/latex/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 b/src/latex/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 new file mode 100644 index 0000000..65d1ff0 --- /dev/null +++ b/src/latex/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.md5 @@ -0,0 +1 @@ +3494f0e174c39b202a892c8819e5d856 \ No newline at end of file diff --git a/src/latex/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.pdf b/src/latex/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.pdf new file mode 100644 index 0000000..e631783 Binary files /dev/null and b/src/latex/score_8h_a93045a86d8c050d38eed9c213ced83c7_cgraph.pdf differ diff --git a/src/latex/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 b/src/latex/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 new file mode 100644 index 0000000..698b64f --- /dev/null +++ b/src/latex/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.md5 @@ -0,0 +1 @@ +605121de8fa054052aa3ed0ae24ef078 \ No newline at end of file diff --git a/src/latex/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.pdf b/src/latex/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.pdf new file mode 100644 index 0000000..784815e Binary files /dev/null and b/src/latex/score_8h_aa313efebb5f1c1c987e98178c1668452_cgraph.pdf differ diff --git a/src/latex/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.md5 b/src/latex/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.md5 new file mode 100644 index 0000000..66bbf58 --- /dev/null +++ b/src/latex/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.md5 @@ -0,0 +1 @@ +986e6b36d226752b356747942f0caccd \ No newline at end of file diff --git a/src/latex/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.pdf b/src/latex/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.pdf new file mode 100644 index 0000000..8868517 Binary files /dev/null and b/src/latex/score_8h_ab2954f5929699167062e554323b3ec08_cgraph.pdf differ diff --git a/src/latex/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 b/src/latex/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 new file mode 100644 index 0000000..8163a54 --- /dev/null +++ b/src/latex/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.md5 @@ -0,0 +1 @@ +d6f1c1a72dad3394aec3e11e07be6624 \ No newline at end of file diff --git a/src/latex/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.pdf b/src/latex/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.pdf new file mode 100644 index 0000000..3a13375 Binary files /dev/null and b/src/latex/score_8h_ad5c373a610e54d23a1cb8500d2634e9b_cgraph.pdf differ diff --git a/src/latex/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.md5 b/src/latex/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.md5 new file mode 100644 index 0000000..9cb98da --- /dev/null +++ b/src/latex/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.md5 @@ -0,0 +1 @@ +1bd929752f8520e3eed73e8d573157ce \ No newline at end of file diff --git a/src/latex/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.pdf b/src/latex/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.pdf new file mode 100644 index 0000000..2654737 Binary files /dev/null and b/src/latex/score_8h_af667df05b60aeb3ec0bd6bd423e268db_cgraph.pdf differ diff --git a/src/latex/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 b/src/latex/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 new file mode 100644 index 0000000..509490f --- /dev/null +++ b/src/latex/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.md5 @@ -0,0 +1 @@ +56f12cd43d8a93911d14b64a6d75c27b \ No newline at end of file diff --git a/src/latex/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.pdf b/src/latex/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.pdf new file mode 100644 index 0000000..673d6ec Binary files /dev/null and b/src/latex/score_8h_af6b84950cd47402f4580d56eb22854fd_cgraph.pdf differ diff --git a/src/latex/struct__backtrackData.tex b/src/latex/struct__backtrackData.tex new file mode 100644 index 0000000..d3f874f --- /dev/null +++ b/src/latex/struct__backtrackData.tex @@ -0,0 +1,49 @@ +\hypertarget{struct__backtrackData}{}\section{\+\_\+backtrack\+Data Struct Reference} +\label{struct__backtrackData}\index{\+\_\+backtrack\+Data@{\+\_\+backtrack\+Data}} + + +{\ttfamily \#include $<$score.\+h$>$} + +\subsection*{Public Attributes} +\begin{DoxyCompactItemize} +\item +float $\ast$ \hyperlink{struct__backtrackData_af803a69e3c75e33c0ba7df036642c44d}{scores} +\item +int $\ast$ \hyperlink{struct__backtrackData_a72e1450e2610bee1d867d8428f33a2cc}{z} +\item +int $\ast$ \hyperlink{struct__backtrackData_a5dc8d2471b3ad228bfba4b4a4638ac85}{states} +\item +int $\ast$ \hyperlink{struct__backtrackData_ac559f1f5976ad99432828f9f9ea7f218}{transitions} +\end{DoxyCompactItemize} + + +\subsection{Member Data Documentation} +\mbox{\Hypertarget{struct__backtrackData_af803a69e3c75e33c0ba7df036642c44d}\label{struct__backtrackData_af803a69e3c75e33c0ba7df036642c44d}} +\index{\+\_\+backtrack\+Data@{\+\_\+backtrack\+Data}!scores@{scores}} +\index{scores@{scores}!\+\_\+backtrack\+Data@{\+\_\+backtrack\+Data}} +\subsubsection{\texorpdfstring{scores}{scores}} +{\footnotesize\ttfamily float$\ast$ \+\_\+backtrack\+Data\+::scores} + +\mbox{\Hypertarget{struct__backtrackData_a5dc8d2471b3ad228bfba4b4a4638ac85}\label{struct__backtrackData_a5dc8d2471b3ad228bfba4b4a4638ac85}} +\index{\+\_\+backtrack\+Data@{\+\_\+backtrack\+Data}!states@{states}} +\index{states@{states}!\+\_\+backtrack\+Data@{\+\_\+backtrack\+Data}} +\subsubsection{\texorpdfstring{states}{states}} +{\footnotesize\ttfamily int$\ast$ \+\_\+backtrack\+Data\+::states} + +\mbox{\Hypertarget{struct__backtrackData_ac559f1f5976ad99432828f9f9ea7f218}\label{struct__backtrackData_ac559f1f5976ad99432828f9f9ea7f218}} +\index{\+\_\+backtrack\+Data@{\+\_\+backtrack\+Data}!transitions@{transitions}} +\index{transitions@{transitions}!\+\_\+backtrack\+Data@{\+\_\+backtrack\+Data}} +\subsubsection{\texorpdfstring{transitions}{transitions}} +{\footnotesize\ttfamily int$\ast$ \+\_\+backtrack\+Data\+::transitions} + +\mbox{\Hypertarget{struct__backtrackData_a72e1450e2610bee1d867d8428f33a2cc}\label{struct__backtrackData_a72e1450e2610bee1d867d8428f33a2cc}} +\index{\+\_\+backtrack\+Data@{\+\_\+backtrack\+Data}!z@{z}} +\index{z@{z}!\+\_\+backtrack\+Data@{\+\_\+backtrack\+Data}} +\subsubsection{\texorpdfstring{z}{z}} +{\footnotesize\ttfamily int$\ast$ \+\_\+backtrack\+Data\+::z} + + + +The documentation for this struct was generated from the following file\+:\begin{DoxyCompactItemize} +\item +\hyperlink{score_8h}{score.\+h}\end{DoxyCompactItemize} diff --git a/src/latex/struct__bgModel.tex b/src/latex/struct__bgModel.tex new file mode 100644 index 0000000..20e3270 --- /dev/null +++ b/src/latex/struct__bgModel.tex @@ -0,0 +1,73 @@ +\hypertarget{struct__bgModel}{}\section{\+\_\+bg\+Model Struct Reference} +\label{struct__bgModel}\index{\+\_\+bg\+Model@{\+\_\+bg\+Model}} + + +{\ttfamily \#include $<$score.\+h$>$} + +\subsection*{Public Attributes} +\begin{DoxyCompactItemize} +\item +float \hyperlink{struct__bgModel_af4fae6328e121d42a0a8fb3dd882c549}{scores} \mbox{[}4\mbox{]} +\item +float \hyperlink{struct__bgModel_ac106ea61c120d4a60f38c98a97254f49}{probs} \mbox{[}4\mbox{]} +\item +float \hyperlink{struct__bgModel_a251b8c86d6c01c5f1813c37df31c3096}{kappa} +\item +float \hyperlink{struct__bgModel_a3757c1ef6b0176dfdeb6046365bf8524}{dist} +\item +float \hyperlink{struct__bgModel_a906bda936ba864ba209eecff5f1ab721}{freqs} \mbox{[}4\mbox{]} +\item +int $\ast$$\ast$ \hyperlink{struct__bgModel_a6843a94f9717bd58819c3fbffe9fbe56}{matrix} +\item +float \hyperlink{struct__bgModel_a00821dd196f2cf6dbccbfa8400a15752}{weight} +\end{DoxyCompactItemize} + + +\subsection{Member Data Documentation} +\mbox{\Hypertarget{struct__bgModel_a3757c1ef6b0176dfdeb6046365bf8524}\label{struct__bgModel_a3757c1ef6b0176dfdeb6046365bf8524}} +\index{\+\_\+bg\+Model@{\+\_\+bg\+Model}!dist@{dist}} +\index{dist@{dist}!\+\_\+bg\+Model@{\+\_\+bg\+Model}} +\subsubsection{\texorpdfstring{dist}{dist}} +{\footnotesize\ttfamily float \+\_\+bg\+Model\+::dist} + +\mbox{\Hypertarget{struct__bgModel_a906bda936ba864ba209eecff5f1ab721}\label{struct__bgModel_a906bda936ba864ba209eecff5f1ab721}} +\index{\+\_\+bg\+Model@{\+\_\+bg\+Model}!freqs@{freqs}} +\index{freqs@{freqs}!\+\_\+bg\+Model@{\+\_\+bg\+Model}} +\subsubsection{\texorpdfstring{freqs}{freqs}} +{\footnotesize\ttfamily float \+\_\+bg\+Model\+::freqs\mbox{[}4\mbox{]}} + +\mbox{\Hypertarget{struct__bgModel_a251b8c86d6c01c5f1813c37df31c3096}\label{struct__bgModel_a251b8c86d6c01c5f1813c37df31c3096}} +\index{\+\_\+bg\+Model@{\+\_\+bg\+Model}!kappa@{kappa}} +\index{kappa@{kappa}!\+\_\+bg\+Model@{\+\_\+bg\+Model}} +\subsubsection{\texorpdfstring{kappa}{kappa}} +{\footnotesize\ttfamily float \+\_\+bg\+Model\+::kappa} + +\mbox{\Hypertarget{struct__bgModel_a6843a94f9717bd58819c3fbffe9fbe56}\label{struct__bgModel_a6843a94f9717bd58819c3fbffe9fbe56}} +\index{\+\_\+bg\+Model@{\+\_\+bg\+Model}!matrix@{matrix}} +\index{matrix@{matrix}!\+\_\+bg\+Model@{\+\_\+bg\+Model}} +\subsubsection{\texorpdfstring{matrix}{matrix}} +{\footnotesize\ttfamily int$\ast$$\ast$ \+\_\+bg\+Model\+::matrix} + +\mbox{\Hypertarget{struct__bgModel_ac106ea61c120d4a60f38c98a97254f49}\label{struct__bgModel_ac106ea61c120d4a60f38c98a97254f49}} +\index{\+\_\+bg\+Model@{\+\_\+bg\+Model}!probs@{probs}} +\index{probs@{probs}!\+\_\+bg\+Model@{\+\_\+bg\+Model}} +\subsubsection{\texorpdfstring{probs}{probs}} +{\footnotesize\ttfamily float \+\_\+bg\+Model\+::probs\mbox{[}4\mbox{]}} + +\mbox{\Hypertarget{struct__bgModel_af4fae6328e121d42a0a8fb3dd882c549}\label{struct__bgModel_af4fae6328e121d42a0a8fb3dd882c549}} +\index{\+\_\+bg\+Model@{\+\_\+bg\+Model}!scores@{scores}} +\index{scores@{scores}!\+\_\+bg\+Model@{\+\_\+bg\+Model}} +\subsubsection{\texorpdfstring{scores}{scores}} +{\footnotesize\ttfamily float \+\_\+bg\+Model\+::scores\mbox{[}4\mbox{]}} + +\mbox{\Hypertarget{struct__bgModel_a00821dd196f2cf6dbccbfa8400a15752}\label{struct__bgModel_a00821dd196f2cf6dbccbfa8400a15752}} +\index{\+\_\+bg\+Model@{\+\_\+bg\+Model}!weight@{weight}} +\index{weight@{weight}!\+\_\+bg\+Model@{\+\_\+bg\+Model}} +\subsubsection{\texorpdfstring{weight}{weight}} +{\footnotesize\ttfamily float \+\_\+bg\+Model\+::weight} + + + +The documentation for this struct was generated from the following file\+:\begin{DoxyCompactItemize} +\item +\hyperlink{score_8h}{score.\+h}\end{DoxyCompactItemize} diff --git a/src/latex/struct__parameters.tex b/src/latex/struct__parameters.tex new file mode 100644 index 0000000..0dcca33 --- /dev/null +++ b/src/latex/struct__parameters.tex @@ -0,0 +1,201 @@ +\hypertarget{struct__parameters}{}\section{\+\_\+parameters Struct Reference} +\label{struct__parameters}\index{\+\_\+parameters@{\+\_\+parameters}} + + +{\ttfamily \#include $<$R\+N\+Acode.\+h$>$} + +\subsection*{Public Attributes} +\begin{DoxyCompactItemize} +\item +float \hyperlink{struct__parameters_a8f69e384c5cc468de9c3c527bd9a3722}{omega} +\item +float \hyperlink{struct__parameters_ab9173ba4e45a417ed8e7317699b5c77c}{Omega} +\item +float \hyperlink{struct__parameters_a9a5b85aa0c04d7e22e824e315b14e4cd}{Delta} +\item +float \hyperlink{struct__parameters_a35c6c83856e4256be0fb543410014f1e}{stop\+Penalty\+\_\+0} +\item +float \hyperlink{struct__parameters_ae26af9c558d90b735b7ed5c2bb8bbb1b}{stop\+Penalty\+\_\+k} +\item +F\+I\+LE $\ast$ \hyperlink{struct__parameters_a37a15ced629242ecdf8a8ccf9f49d81b}{input\+File} +\item +F\+I\+LE $\ast$ \hyperlink{struct__parameters_a683e0de09c9d45e219db06753f89bc7e}{output\+File} +\item +F\+I\+LE $\ast$ \hyperlink{struct__parameters_ab616c6d418c255985ac50a9311d8c26a}{debug\+File} +\item +int \hyperlink{struct__parameters_a40706f4d64be0c9ee5cb411cee949416}{sampleN} +\item +char \hyperlink{struct__parameters_ab9f7cf2359b590f2476fff80a85aff43}{limit} \mbox{[}10000\mbox{]} +\item +float \hyperlink{struct__parameters_a6e3ed4fee9836ba83e10f42a0b9d89b2}{cutoff} +\item +int \hyperlink{struct__parameters_a37dadb0f3fa7deca9cdc43797cc0ff5b}{output\+Format} +\item +int \hyperlink{struct__parameters_ad170b87fd49f42a1ca464c93e36fa0e3}{stop\+Early} +\item +int \hyperlink{struct__parameters_acdebd1fac8029bad117f9ba82bef93d5}{best\+Only} +\item +int \hyperlink{struct__parameters_ad8bdd1fcbd46e8fb6842e5ab77b9c8fe}{best\+Region} +\item +int \hyperlink{struct__parameters_a3857ab2091fd5bbda92463952163163f}{blosum} +\item +char \hyperlink{struct__parameters_a82681df81d7bc113bc6fad0b5328a95d}{debug\+File\+Name} \mbox{[}1024\mbox{]} +\item +char \hyperlink{struct__parameters_a1b9b47e6f58186d767de1d34d956b516}{input\+File\+Name} \mbox{[}1024\mbox{]} +\item +float \hyperlink{struct__parameters_ad73fc37c8e5f6964149f12899200472b}{print\+If\+Below} +\item +float \hyperlink{struct__parameters_aa9034282619631f32acd19230990ea6e}{print\+If\+Above} +\item +int \hyperlink{struct__parameters_a7080180324a5b3081e85eb308d2d530c}{postscript} +\item +float \hyperlink{struct__parameters_a796cc87fce657443f51845fd1098f0df}{postscript\+\_\+cutoff} +\item +char \hyperlink{struct__parameters_a6c33be73b16d623ca8e5af964d248424}{postscript\+Dir} \mbox{[}1024\mbox{]} +\end{DoxyCompactItemize} + + +\subsection{Member Data Documentation} +\mbox{\Hypertarget{struct__parameters_acdebd1fac8029bad117f9ba82bef93d5}\label{struct__parameters_acdebd1fac8029bad117f9ba82bef93d5}} +\index{\+\_\+parameters@{\+\_\+parameters}!best\+Only@{best\+Only}} +\index{best\+Only@{best\+Only}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{best\+Only}{bestOnly}} +{\footnotesize\ttfamily int \+\_\+parameters\+::best\+Only} + +\mbox{\Hypertarget{struct__parameters_ad8bdd1fcbd46e8fb6842e5ab77b9c8fe}\label{struct__parameters_ad8bdd1fcbd46e8fb6842e5ab77b9c8fe}} +\index{\+\_\+parameters@{\+\_\+parameters}!best\+Region@{best\+Region}} +\index{best\+Region@{best\+Region}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{best\+Region}{bestRegion}} +{\footnotesize\ttfamily int \+\_\+parameters\+::best\+Region} + +\mbox{\Hypertarget{struct__parameters_a3857ab2091fd5bbda92463952163163f}\label{struct__parameters_a3857ab2091fd5bbda92463952163163f}} +\index{\+\_\+parameters@{\+\_\+parameters}!blosum@{blosum}} +\index{blosum@{blosum}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{blosum}{blosum}} +{\footnotesize\ttfamily int \+\_\+parameters\+::blosum} + +\mbox{\Hypertarget{struct__parameters_a6e3ed4fee9836ba83e10f42a0b9d89b2}\label{struct__parameters_a6e3ed4fee9836ba83e10f42a0b9d89b2}} +\index{\+\_\+parameters@{\+\_\+parameters}!cutoff@{cutoff}} +\index{cutoff@{cutoff}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{cutoff}{cutoff}} +{\footnotesize\ttfamily float \+\_\+parameters\+::cutoff} + +\mbox{\Hypertarget{struct__parameters_ab616c6d418c255985ac50a9311d8c26a}\label{struct__parameters_ab616c6d418c255985ac50a9311d8c26a}} +\index{\+\_\+parameters@{\+\_\+parameters}!debug\+File@{debug\+File}} +\index{debug\+File@{debug\+File}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{debug\+File}{debugFile}} +{\footnotesize\ttfamily F\+I\+LE$\ast$ \+\_\+parameters\+::debug\+File} + +\mbox{\Hypertarget{struct__parameters_a82681df81d7bc113bc6fad0b5328a95d}\label{struct__parameters_a82681df81d7bc113bc6fad0b5328a95d}} +\index{\+\_\+parameters@{\+\_\+parameters}!debug\+File\+Name@{debug\+File\+Name}} +\index{debug\+File\+Name@{debug\+File\+Name}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{debug\+File\+Name}{debugFileName}} +{\footnotesize\ttfamily char \+\_\+parameters\+::debug\+File\+Name\mbox{[}1024\mbox{]}} + +\mbox{\Hypertarget{struct__parameters_a9a5b85aa0c04d7e22e824e315b14e4cd}\label{struct__parameters_a9a5b85aa0c04d7e22e824e315b14e4cd}} +\index{\+\_\+parameters@{\+\_\+parameters}!Delta@{Delta}} +\index{Delta@{Delta}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{Delta}{Delta}} +{\footnotesize\ttfamily float \+\_\+parameters\+::\+Delta} + +\mbox{\Hypertarget{struct__parameters_a37a15ced629242ecdf8a8ccf9f49d81b}\label{struct__parameters_a37a15ced629242ecdf8a8ccf9f49d81b}} +\index{\+\_\+parameters@{\+\_\+parameters}!input\+File@{input\+File}} +\index{input\+File@{input\+File}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{input\+File}{inputFile}} +{\footnotesize\ttfamily F\+I\+LE$\ast$ \+\_\+parameters\+::input\+File} + +\mbox{\Hypertarget{struct__parameters_a1b9b47e6f58186d767de1d34d956b516}\label{struct__parameters_a1b9b47e6f58186d767de1d34d956b516}} +\index{\+\_\+parameters@{\+\_\+parameters}!input\+File\+Name@{input\+File\+Name}} +\index{input\+File\+Name@{input\+File\+Name}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{input\+File\+Name}{inputFileName}} +{\footnotesize\ttfamily char \+\_\+parameters\+::input\+File\+Name\mbox{[}1024\mbox{]}} + +\mbox{\Hypertarget{struct__parameters_ab9f7cf2359b590f2476fff80a85aff43}\label{struct__parameters_ab9f7cf2359b590f2476fff80a85aff43}} +\index{\+\_\+parameters@{\+\_\+parameters}!limit@{limit}} +\index{limit@{limit}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{limit}{limit}} +{\footnotesize\ttfamily char \+\_\+parameters\+::limit\mbox{[}10000\mbox{]}} + +\mbox{\Hypertarget{struct__parameters_a8f69e384c5cc468de9c3c527bd9a3722}\label{struct__parameters_a8f69e384c5cc468de9c3c527bd9a3722}} +\index{\+\_\+parameters@{\+\_\+parameters}!omega@{omega}} +\index{omega@{omega}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{omega}{omega}} +{\footnotesize\ttfamily float \+\_\+parameters\+::omega} + +\mbox{\Hypertarget{struct__parameters_ab9173ba4e45a417ed8e7317699b5c77c}\label{struct__parameters_ab9173ba4e45a417ed8e7317699b5c77c}} +\index{\+\_\+parameters@{\+\_\+parameters}!Omega@{Omega}} +\index{Omega@{Omega}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{Omega}{Omega}} +{\footnotesize\ttfamily float \+\_\+parameters\+::\+Omega} + +\mbox{\Hypertarget{struct__parameters_a683e0de09c9d45e219db06753f89bc7e}\label{struct__parameters_a683e0de09c9d45e219db06753f89bc7e}} +\index{\+\_\+parameters@{\+\_\+parameters}!output\+File@{output\+File}} +\index{output\+File@{output\+File}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{output\+File}{outputFile}} +{\footnotesize\ttfamily F\+I\+LE$\ast$ \+\_\+parameters\+::output\+File} + +\mbox{\Hypertarget{struct__parameters_a37dadb0f3fa7deca9cdc43797cc0ff5b}\label{struct__parameters_a37dadb0f3fa7deca9cdc43797cc0ff5b}} +\index{\+\_\+parameters@{\+\_\+parameters}!output\+Format@{output\+Format}} +\index{output\+Format@{output\+Format}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{output\+Format}{outputFormat}} +{\footnotesize\ttfamily int \+\_\+parameters\+::output\+Format} + +\mbox{\Hypertarget{struct__parameters_a7080180324a5b3081e85eb308d2d530c}\label{struct__parameters_a7080180324a5b3081e85eb308d2d530c}} +\index{\+\_\+parameters@{\+\_\+parameters}!postscript@{postscript}} +\index{postscript@{postscript}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{postscript}{postscript}} +{\footnotesize\ttfamily int \+\_\+parameters\+::postscript} + +\mbox{\Hypertarget{struct__parameters_a796cc87fce657443f51845fd1098f0df}\label{struct__parameters_a796cc87fce657443f51845fd1098f0df}} +\index{\+\_\+parameters@{\+\_\+parameters}!postscript\+\_\+cutoff@{postscript\+\_\+cutoff}} +\index{postscript\+\_\+cutoff@{postscript\+\_\+cutoff}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{postscript\+\_\+cutoff}{postscript\_cutoff}} +{\footnotesize\ttfamily float \+\_\+parameters\+::postscript\+\_\+cutoff} + +\mbox{\Hypertarget{struct__parameters_a6c33be73b16d623ca8e5af964d248424}\label{struct__parameters_a6c33be73b16d623ca8e5af964d248424}} +\index{\+\_\+parameters@{\+\_\+parameters}!postscript\+Dir@{postscript\+Dir}} +\index{postscript\+Dir@{postscript\+Dir}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{postscript\+Dir}{postscriptDir}} +{\footnotesize\ttfamily char \+\_\+parameters\+::postscript\+Dir\mbox{[}1024\mbox{]}} + +\mbox{\Hypertarget{struct__parameters_aa9034282619631f32acd19230990ea6e}\label{struct__parameters_aa9034282619631f32acd19230990ea6e}} +\index{\+\_\+parameters@{\+\_\+parameters}!print\+If\+Above@{print\+If\+Above}} +\index{print\+If\+Above@{print\+If\+Above}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{print\+If\+Above}{printIfAbove}} +{\footnotesize\ttfamily float \+\_\+parameters\+::print\+If\+Above} + +\mbox{\Hypertarget{struct__parameters_ad73fc37c8e5f6964149f12899200472b}\label{struct__parameters_ad73fc37c8e5f6964149f12899200472b}} +\index{\+\_\+parameters@{\+\_\+parameters}!print\+If\+Below@{print\+If\+Below}} +\index{print\+If\+Below@{print\+If\+Below}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{print\+If\+Below}{printIfBelow}} +{\footnotesize\ttfamily float \+\_\+parameters\+::print\+If\+Below} + +\mbox{\Hypertarget{struct__parameters_a40706f4d64be0c9ee5cb411cee949416}\label{struct__parameters_a40706f4d64be0c9ee5cb411cee949416}} +\index{\+\_\+parameters@{\+\_\+parameters}!sampleN@{sampleN}} +\index{sampleN@{sampleN}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{sampleN}{sampleN}} +{\footnotesize\ttfamily int \+\_\+parameters\+::sampleN} + +\mbox{\Hypertarget{struct__parameters_ad170b87fd49f42a1ca464c93e36fa0e3}\label{struct__parameters_ad170b87fd49f42a1ca464c93e36fa0e3}} +\index{\+\_\+parameters@{\+\_\+parameters}!stop\+Early@{stop\+Early}} +\index{stop\+Early@{stop\+Early}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{stop\+Early}{stopEarly}} +{\footnotesize\ttfamily int \+\_\+parameters\+::stop\+Early} + +\mbox{\Hypertarget{struct__parameters_a35c6c83856e4256be0fb543410014f1e}\label{struct__parameters_a35c6c83856e4256be0fb543410014f1e}} +\index{\+\_\+parameters@{\+\_\+parameters}!stop\+Penalty\+\_\+0@{stop\+Penalty\+\_\+0}} +\index{stop\+Penalty\+\_\+0@{stop\+Penalty\+\_\+0}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{stop\+Penalty\+\_\+0}{stopPenalty\_0}} +{\footnotesize\ttfamily float \+\_\+parameters\+::stop\+Penalty\+\_\+0} + +\mbox{\Hypertarget{struct__parameters_ae26af9c558d90b735b7ed5c2bb8bbb1b}\label{struct__parameters_ae26af9c558d90b735b7ed5c2bb8bbb1b}} +\index{\+\_\+parameters@{\+\_\+parameters}!stop\+Penalty\+\_\+k@{stop\+Penalty\+\_\+k}} +\index{stop\+Penalty\+\_\+k@{stop\+Penalty\+\_\+k}!\+\_\+parameters@{\+\_\+parameters}} +\subsubsection{\texorpdfstring{stop\+Penalty\+\_\+k}{stopPenalty\_k}} +{\footnotesize\ttfamily float \+\_\+parameters\+::stop\+Penalty\+\_\+k} + + + +The documentation for this struct was generated from the following file\+:\begin{DoxyCompactItemize} +\item +\hyperlink{RNAcode_8h}{R\+N\+Acode.\+h}\end{DoxyCompactItemize} diff --git a/src/latex/struct__segmentStats.tex b/src/latex/struct__segmentStats.tex new file mode 100644 index 0000000..2aa732c --- /dev/null +++ b/src/latex/struct__segmentStats.tex @@ -0,0 +1,113 @@ +\hypertarget{struct__segmentStats}{}\section{\+\_\+segment\+Stats Struct Reference} +\label{struct__segmentStats}\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} + + +{\ttfamily \#include $<$score.\+h$>$} + +\subsection*{Public Attributes} +\begin{DoxyCompactItemize} +\item +int \hyperlink{struct__segmentStats_acbd4b0e7ceaa05b6506aab77d2bf1090}{start} +\item +int \hyperlink{struct__segmentStats_a4d3d7af903f88c69e687d259590b00a3}{end} +\item +int \hyperlink{struct__segmentStats_a95a69dcd9686db97033daded2f42878b}{start\+Genomic} +\item +int \hyperlink{struct__segmentStats_acf8d8441557c049db6d84d96ed7f7ca3}{end\+Genomic} +\item +int \hyperlink{struct__segmentStats_a403f946ddab65393861d93fbb81f0d5a}{start\+Site} +\item +int \hyperlink{struct__segmentStats_af419d597e7393b0e78078eaa842ded6c}{end\+Site} +\item +int \hyperlink{struct__segmentStats_a84cfdd51d1e7fe9555f887c3658e9ced}{strand} +\item +int \hyperlink{struct__segmentStats_aaa79b059634ee49ceb65150735dae1dd}{frame} +\item +char $\ast$ \hyperlink{struct__segmentStats_aea84cdd90979dc3c173424166ef8d532}{name} +\item +float \hyperlink{struct__segmentStats_aea28293c9c59198e9f14542d99ac1484}{score} +\item +float \hyperlink{struct__segmentStats_a36c8958e60d5f733eb6b3bc0e178ad61}{pvalue} +\item +int \hyperlink{struct__segmentStats_a7db5f703ed1ff2f2105f756cb79eaecf}{hide} +\end{DoxyCompactItemize} + + +\subsection{Member Data Documentation} +\mbox{\Hypertarget{struct__segmentStats_a4d3d7af903f88c69e687d259590b00a3}\label{struct__segmentStats_a4d3d7af903f88c69e687d259590b00a3}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!end@{end}} +\index{end@{end}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{end}{end}} +{\footnotesize\ttfamily int \+\_\+segment\+Stats\+::end} + +\mbox{\Hypertarget{struct__segmentStats_acf8d8441557c049db6d84d96ed7f7ca3}\label{struct__segmentStats_acf8d8441557c049db6d84d96ed7f7ca3}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!end\+Genomic@{end\+Genomic}} +\index{end\+Genomic@{end\+Genomic}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{end\+Genomic}{endGenomic}} +{\footnotesize\ttfamily int \+\_\+segment\+Stats\+::end\+Genomic} + +\mbox{\Hypertarget{struct__segmentStats_af419d597e7393b0e78078eaa842ded6c}\label{struct__segmentStats_af419d597e7393b0e78078eaa842ded6c}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!end\+Site@{end\+Site}} +\index{end\+Site@{end\+Site}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{end\+Site}{endSite}} +{\footnotesize\ttfamily int \+\_\+segment\+Stats\+::end\+Site} + +\mbox{\Hypertarget{struct__segmentStats_aaa79b059634ee49ceb65150735dae1dd}\label{struct__segmentStats_aaa79b059634ee49ceb65150735dae1dd}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!frame@{frame}} +\index{frame@{frame}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{frame}{frame}} +{\footnotesize\ttfamily int \+\_\+segment\+Stats\+::frame} + +\mbox{\Hypertarget{struct__segmentStats_a7db5f703ed1ff2f2105f756cb79eaecf}\label{struct__segmentStats_a7db5f703ed1ff2f2105f756cb79eaecf}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!hide@{hide}} +\index{hide@{hide}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{hide}{hide}} +{\footnotesize\ttfamily int \+\_\+segment\+Stats\+::hide} + +\mbox{\Hypertarget{struct__segmentStats_aea84cdd90979dc3c173424166ef8d532}\label{struct__segmentStats_aea84cdd90979dc3c173424166ef8d532}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!name@{name}} +\index{name@{name}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{name}{name}} +{\footnotesize\ttfamily char$\ast$ \+\_\+segment\+Stats\+::name} + +\mbox{\Hypertarget{struct__segmentStats_a36c8958e60d5f733eb6b3bc0e178ad61}\label{struct__segmentStats_a36c8958e60d5f733eb6b3bc0e178ad61}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!pvalue@{pvalue}} +\index{pvalue@{pvalue}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{pvalue}{pvalue}} +{\footnotesize\ttfamily float \+\_\+segment\+Stats\+::pvalue} + +\mbox{\Hypertarget{struct__segmentStats_aea28293c9c59198e9f14542d99ac1484}\label{struct__segmentStats_aea28293c9c59198e9f14542d99ac1484}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!score@{score}} +\index{score@{score}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{score}{score}} +{\footnotesize\ttfamily float \+\_\+segment\+Stats\+::score} + +\mbox{\Hypertarget{struct__segmentStats_acbd4b0e7ceaa05b6506aab77d2bf1090}\label{struct__segmentStats_acbd4b0e7ceaa05b6506aab77d2bf1090}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!start@{start}} +\index{start@{start}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{start}{start}} +{\footnotesize\ttfamily int \+\_\+segment\+Stats\+::start} + +\mbox{\Hypertarget{struct__segmentStats_a95a69dcd9686db97033daded2f42878b}\label{struct__segmentStats_a95a69dcd9686db97033daded2f42878b}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!start\+Genomic@{start\+Genomic}} +\index{start\+Genomic@{start\+Genomic}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{start\+Genomic}{startGenomic}} +{\footnotesize\ttfamily int \+\_\+segment\+Stats\+::start\+Genomic} + +\mbox{\Hypertarget{struct__segmentStats_a403f946ddab65393861d93fbb81f0d5a}\label{struct__segmentStats_a403f946ddab65393861d93fbb81f0d5a}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!start\+Site@{start\+Site}} +\index{start\+Site@{start\+Site}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{start\+Site}{startSite}} +{\footnotesize\ttfamily int \+\_\+segment\+Stats\+::start\+Site} + +\mbox{\Hypertarget{struct__segmentStats_a84cfdd51d1e7fe9555f887c3658e9ced}\label{struct__segmentStats_a84cfdd51d1e7fe9555f887c3658e9ced}} +\index{\+\_\+segment\+Stats@{\+\_\+segment\+Stats}!strand@{strand}} +\index{strand@{strand}!\+\_\+segment\+Stats@{\+\_\+segment\+Stats}} +\subsubsection{\texorpdfstring{strand}{strand}} +{\footnotesize\ttfamily int \+\_\+segment\+Stats\+::strand} + + + +The documentation for this struct was generated from the following file\+:\begin{DoxyCompactItemize} +\item +\hyperlink{score_8h}{score.\+h}\end{DoxyCompactItemize} diff --git a/src/latex/structaln.tex b/src/latex/structaln.tex new file mode 100644 index 0000000..1cabfab --- /dev/null +++ b/src/latex/structaln.tex @@ -0,0 +1,73 @@ +\hypertarget{structaln}{}\section{aln Struct Reference} +\label{structaln}\index{aln@{aln}} + + +{\ttfamily \#include $<$rnaz\+\_\+utils.\+h$>$} + +\subsection*{Public Attributes} +\begin{DoxyCompactItemize} +\item +char $\ast$ \hyperlink{structaln_af655f033b20fc2f4361576240cac2c0f}{name} +\item +char $\ast$ \hyperlink{structaln_aee1fbffa2c18c0b3d6016b8fe409eeae}{seq} +\item +char $\ast$ \hyperlink{structaln_ad86e38ddd090ff01a1665db42fe80775}{full\+Seq} +\item +int \hyperlink{structaln_a1cde67bfa55bc9e8f2d98f9e53a4ba12}{start} +\item +int \hyperlink{structaln_ad03a776f899ce00d63827146906ab6b4}{length} +\item +int \hyperlink{structaln_a483afd3cef94d6713429e91b3ea2f9a9}{full\+Length} +\item +char \hyperlink{structaln_aa3a2e698a569a230e9e14e14d3afe653}{strand} +\end{DoxyCompactItemize} + + +\subsection{Member Data Documentation} +\mbox{\Hypertarget{structaln_a483afd3cef94d6713429e91b3ea2f9a9}\label{structaln_a483afd3cef94d6713429e91b3ea2f9a9}} +\index{aln@{aln}!full\+Length@{full\+Length}} +\index{full\+Length@{full\+Length}!aln@{aln}} +\subsubsection{\texorpdfstring{full\+Length}{fullLength}} +{\footnotesize\ttfamily int aln\+::full\+Length} + +\mbox{\Hypertarget{structaln_ad86e38ddd090ff01a1665db42fe80775}\label{structaln_ad86e38ddd090ff01a1665db42fe80775}} +\index{aln@{aln}!full\+Seq@{full\+Seq}} +\index{full\+Seq@{full\+Seq}!aln@{aln}} +\subsubsection{\texorpdfstring{full\+Seq}{fullSeq}} +{\footnotesize\ttfamily char$\ast$ aln\+::full\+Seq} + +\mbox{\Hypertarget{structaln_ad03a776f899ce00d63827146906ab6b4}\label{structaln_ad03a776f899ce00d63827146906ab6b4}} +\index{aln@{aln}!length@{length}} +\index{length@{length}!aln@{aln}} +\subsubsection{\texorpdfstring{length}{length}} +{\footnotesize\ttfamily int aln\+::length} + +\mbox{\Hypertarget{structaln_af655f033b20fc2f4361576240cac2c0f}\label{structaln_af655f033b20fc2f4361576240cac2c0f}} +\index{aln@{aln}!name@{name}} +\index{name@{name}!aln@{aln}} +\subsubsection{\texorpdfstring{name}{name}} +{\footnotesize\ttfamily char$\ast$ aln\+::name} + +\mbox{\Hypertarget{structaln_aee1fbffa2c18c0b3d6016b8fe409eeae}\label{structaln_aee1fbffa2c18c0b3d6016b8fe409eeae}} +\index{aln@{aln}!seq@{seq}} +\index{seq@{seq}!aln@{aln}} +\subsubsection{\texorpdfstring{seq}{seq}} +{\footnotesize\ttfamily char$\ast$ aln\+::seq} + +\mbox{\Hypertarget{structaln_a1cde67bfa55bc9e8f2d98f9e53a4ba12}\label{structaln_a1cde67bfa55bc9e8f2d98f9e53a4ba12}} +\index{aln@{aln}!start@{start}} +\index{start@{start}!aln@{aln}} +\subsubsection{\texorpdfstring{start}{start}} +{\footnotesize\ttfamily int aln\+::start} + +\mbox{\Hypertarget{structaln_aa3a2e698a569a230e9e14e14d3afe653}\label{structaln_aa3a2e698a569a230e9e14e14d3afe653}} +\index{aln@{aln}!strand@{strand}} +\index{strand@{strand}!aln@{aln}} +\subsubsection{\texorpdfstring{strand}{strand}} +{\footnotesize\ttfamily char aln\+::strand} + + + +The documentation for this struct was generated from the following file\+:\begin{DoxyCompactItemize} +\item +\hyperlink{rnaz__utils_8h}{rnaz\+\_\+utils.\+h}\end{DoxyCompactItemize} diff --git a/src/latex/structcmdline__parser__params.tex b/src/latex/structcmdline__parser__params.tex new file mode 100644 index 0000000..3330533 --- /dev/null +++ b/src/latex/structcmdline__parser__params.tex @@ -0,0 +1,85 @@ +\hypertarget{structcmdline__parser__params}{}\section{cmdline\+\_\+parser\+\_\+params Struct Reference} +\label{structcmdline__parser__params}\index{cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}} + + +The additional parameters to pass to parser functions. + + + + +{\ttfamily \#include $<$cmdline.\+h$>$} + +\subsection*{Public Attributes} +\begin{DoxyCompactItemize} +\item +int \hyperlink{structcmdline__parser__params_ad3ff9d69146e69a47506782197b5675c}{override} +\begin{DoxyCompactList}\small\item\em whether to override possibly already present options (default 0) \end{DoxyCompactList}\item +int \hyperlink{structcmdline__parser__params_a97ed8a6eabd39291ae7d73f273e12c11}{initialize} +\begin{DoxyCompactList}\small\item\em whether to initialize the option structure \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} (default 1) \end{DoxyCompactList}\item +int \hyperlink{structcmdline__parser__params_a44ff439d7e9e36799e59173af74829c6}{check\+\_\+required} +\begin{DoxyCompactList}\small\item\em whether to check that all required options were provided (default 1) \end{DoxyCompactList}\item +int \hyperlink{structcmdline__parser__params_a6e4442704fc40b0b655f7cc602f13ec4}{check\+\_\+ambiguity} +\begin{DoxyCompactList}\small\item\em whether to check for options already specified in the option structure \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} (default 0) \end{DoxyCompactList}\item +int \hyperlink{structcmdline__parser__params_a3236f066777488e8502abe05ccd24455}{print\+\_\+errors} +\begin{DoxyCompactList}\small\item\em whether getopt\+\_\+long should print an error message for a bad option (default 1) \end{DoxyCompactList}\end{DoxyCompactItemize} + + +\subsection{Detailed Description} +The additional parameters to pass to parser functions. + +\subsection{Member Data Documentation} +\mbox{\Hypertarget{structcmdline__parser__params_a6e4442704fc40b0b655f7cc602f13ec4}\label{structcmdline__parser__params_a6e4442704fc40b0b655f7cc602f13ec4}} +\index{cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}!check\+\_\+ambiguity@{check\+\_\+ambiguity}} +\index{check\+\_\+ambiguity@{check\+\_\+ambiguity}!cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}} +\subsubsection{\texorpdfstring{check\+\_\+ambiguity}{check\_ambiguity}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+params\+::check\+\_\+ambiguity} + + + +whether to check for options already specified in the option structure \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} (default 0) + +\mbox{\Hypertarget{structcmdline__parser__params_a44ff439d7e9e36799e59173af74829c6}\label{structcmdline__parser__params_a44ff439d7e9e36799e59173af74829c6}} +\index{cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}!check\+\_\+required@{check\+\_\+required}} +\index{check\+\_\+required@{check\+\_\+required}!cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}} +\subsubsection{\texorpdfstring{check\+\_\+required}{check\_required}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+params\+::check\+\_\+required} + + + +whether to check that all required options were provided (default 1) + +\mbox{\Hypertarget{structcmdline__parser__params_a97ed8a6eabd39291ae7d73f273e12c11}\label{structcmdline__parser__params_a97ed8a6eabd39291ae7d73f273e12c11}} +\index{cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}!initialize@{initialize}} +\index{initialize@{initialize}!cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}} +\subsubsection{\texorpdfstring{initialize}{initialize}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+params\+::initialize} + + + +whether to initialize the option structure \hyperlink{structgengetopt__args__info}{gengetopt\+\_\+args\+\_\+info} (default 1) + +\mbox{\Hypertarget{structcmdline__parser__params_ad3ff9d69146e69a47506782197b5675c}\label{structcmdline__parser__params_ad3ff9d69146e69a47506782197b5675c}} +\index{cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}!override@{override}} +\index{override@{override}!cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}} +\subsubsection{\texorpdfstring{override}{override}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+params\+::override} + + + +whether to override possibly already present options (default 0) + +\mbox{\Hypertarget{structcmdline__parser__params_a3236f066777488e8502abe05ccd24455}\label{structcmdline__parser__params_a3236f066777488e8502abe05ccd24455}} +\index{cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}!print\+\_\+errors@{print\+\_\+errors}} +\index{print\+\_\+errors@{print\+\_\+errors}!cmdline\+\_\+parser\+\_\+params@{cmdline\+\_\+parser\+\_\+params}} +\subsubsection{\texorpdfstring{print\+\_\+errors}{print\_errors}} +{\footnotesize\ttfamily int cmdline\+\_\+parser\+\_\+params\+::print\+\_\+errors} + + + +whether getopt\+\_\+long should print an error message for a bad option (default 1) + + + +The documentation for this struct was generated from the following file\+:\begin{DoxyCompactItemize} +\item +\hyperlink{cmdline_8h}{cmdline.\+h}\end{DoxyCompactItemize} diff --git a/src/latex/structgengetopt__args__info.tex b/src/latex/structgengetopt__args__info.tex new file mode 100644 index 0000000..e591323 --- /dev/null +++ b/src/latex/structgengetopt__args__info.tex @@ -0,0 +1,745 @@ +\hypertarget{structgengetopt__args__info}{}\section{gengetopt\+\_\+args\+\_\+info Struct Reference} +\label{structgengetopt__args__info}\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} + + +Where the command line options are stored. + + + + +{\ttfamily \#include $<$cmdline.\+h$>$} + +\subsection*{Public Attributes} +\begin{DoxyCompactItemize} +\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_afb4efa68a6f43a4d112e9b96ffe89101}{help\+\_\+help} +\begin{DoxyCompactList}\small\item\em Print help and exit help description. \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_adef454ea6f3ff4114ae5009e58360cfc}{version\+\_\+help} +\begin{DoxyCompactList}\small\item\em Print version and exit help description. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_ab9e3d63af39beb195c0ce4b30628475b}{outfile\+\_\+arg} +\begin{DoxyCompactList}\small\item\em Output filename. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_a39782404c00e6f9107f8fdcae948222f}{outfile\+\_\+orig} +\begin{DoxyCompactList}\small\item\em Output filename original value given at command line. \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_ae7d54ef8556b73161c14a77b20fe321f}{outfile\+\_\+help} +\begin{DoxyCompactList}\small\item\em Output filename help description. \end{DoxyCompactList}\item +int \hyperlink{structgengetopt__args__info_a3cc76992b00eb5f69d49ecabfa65de28}{gtf\+\_\+flag} +\begin{DoxyCompactList}\small\item\em G\+TF output (default=off). \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_a7eb6417bded13cc26a47a1ee53bcb8dc}{gtf\+\_\+help} +\begin{DoxyCompactList}\small\item\em G\+TF output help description. \end{DoxyCompactList}\item +int \hyperlink{structgengetopt__args__info_aa01935a1796974d3347aff6062718afc}{tabular\+\_\+flag} +\begin{DoxyCompactList}\small\item\em Tab delimited output (default=off). \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_a923b9288287e40df1b3f21bfe288f123}{tabular\+\_\+help} +\begin{DoxyCompactList}\small\item\em Tab delimited output help description. \end{DoxyCompactList}\item +int \hyperlink{structgengetopt__args__info_ab0275ce8469b8fa0415ec84a692aba90}{best\+\_\+only\+\_\+flag} +\begin{DoxyCompactList}\small\item\em Print only best hit per alignment (default=off). \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_a4f31622f59d764e13fe3ef9d3d0cc579}{best\+\_\+only\+\_\+help} +\begin{DoxyCompactList}\small\item\em Print only best hit per alignment help description. \end{DoxyCompactList}\item +int \hyperlink{structgengetopt__args__info_a4ee2d5172359ee7a6b7fd042fae11817}{best\+\_\+region\+\_\+flag} +\begin{DoxyCompactList}\small\item\em Print all best non-\/overlapping hits per alignment (default=off). \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_a8943d1adc6dc6a89790adb4ce383943e}{best\+\_\+region\+\_\+help} +\begin{DoxyCompactList}\small\item\em Print all best non-\/overlapping hits per alignment help description. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_a965c61281e9339738647ff5e44604d8b}{pars\+\_\+arg} +\begin{DoxyCompactList}\small\item\em String with parameters. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_a2c6837447e74b77af713002cdb58949b}{pars\+\_\+orig} +\begin{DoxyCompactList}\small\item\em String with parameters original value given at command line. \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_aacd28fcc4238ef2516cca7526df79533}{pars\+\_\+help} +\begin{DoxyCompactList}\small\item\em String with parameters help description. \end{DoxyCompactList}\item +int \hyperlink{structgengetopt__args__info_aa4b8393ab6c37bca14cb1b291b5871df}{stop\+\_\+early\+\_\+flag} +\begin{DoxyCompactList}\small\item\em Don\textquotesingle{}t calculate p-\/values if below cutoff (default=off). \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_aefd3bdbabef305d8e53741dc229e7cb0}{stop\+\_\+early\+\_\+help} +\begin{DoxyCompactList}\small\item\em Don\textquotesingle{}t calculate p-\/values if below cutoff help description. \end{DoxyCompactList}\item +int \hyperlink{structgengetopt__args__info_ac62c13305dd12c4d426aeb82b6e4561b}{num\+\_\+samples\+\_\+arg} +\begin{DoxyCompactList}\small\item\em Number of samples. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_a043409e12989cdbf8cd34fa47f8c6a4c}{num\+\_\+samples\+\_\+orig} +\begin{DoxyCompactList}\small\item\em Number of samples original value given at command line. \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_a1c4039a0fea549c7db4b2c62482179f8}{num\+\_\+samples\+\_\+help} +\begin{DoxyCompactList}\small\item\em Number of samples help description. \end{DoxyCompactList}\item +float \hyperlink{structgengetopt__args__info_a79efa24e1a3d614f474d323f147edf10}{cutoff\+\_\+arg} +\begin{DoxyCompactList}\small\item\em p-\/value cutoff. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_ac1cc7e0fbe8552f19e4760b827349622}{cutoff\+\_\+orig} +\begin{DoxyCompactList}\small\item\em p-\/value cutoff original value given at command line. \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_a46f7d71837544abf13c5972fc5e528b3}{cutoff\+\_\+help} +\begin{DoxyCompactList}\small\item\em p-\/value cutoff help description. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_a648135bce096c7f592d4a6cc6d2b4d20}{debug\+\_\+file\+\_\+arg} +\begin{DoxyCompactList}\small\item\em Debug file. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_a2b22e7ebbc50b2b054e9be56785fb2de}{debug\+\_\+file\+\_\+orig} +\begin{DoxyCompactList}\small\item\em Debug file original value given at command line. \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_af5d881c802b02a6f85b5e4b957de85e9}{debug\+\_\+file\+\_\+help} +\begin{DoxyCompactList}\small\item\em Debug file help description. \end{DoxyCompactList}\item +int \hyperlink{structgengetopt__args__info_a4c97eb3971c8f9222073e63484872bf0}{eps\+\_\+flag} +\begin{DoxyCompactList}\small\item\em Postscript output (default=off). \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_aa87d33b8ebe4fa33c6c4b7454c3e7e55}{eps\+\_\+help} +\begin{DoxyCompactList}\small\item\em Postscript output help description. \end{DoxyCompactList}\item +float \hyperlink{structgengetopt__args__info_a7d5c15c092764baac13552613fda575f}{eps\+\_\+cutoff\+\_\+arg} +\begin{DoxyCompactList}\small\item\em Postscript output p-\/value cutoff. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_ad2f45ed857ac6e6d8b1a371d85b65e25}{eps\+\_\+cutoff\+\_\+orig} +\begin{DoxyCompactList}\small\item\em Postscript output p-\/value cutoff original value given at command line. \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_a32790cf21a0f8e8623371d12deb4b337}{eps\+\_\+cutoff\+\_\+help} +\begin{DoxyCompactList}\small\item\em Postscript output p-\/value cutoff help description. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_a29434f1b1030755c24dde59d8c157de5}{eps\+\_\+dir\+\_\+arg} +\begin{DoxyCompactList}\small\item\em Postscript directory. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_a7474b0d19ed3f9c13ebc88e6cf652c65}{eps\+\_\+dir\+\_\+orig} +\begin{DoxyCompactList}\small\item\em Postscript directory original value given at command line. \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_a1c676a66f0cf100d49679440032ae4ab}{eps\+\_\+dir\+\_\+help} +\begin{DoxyCompactList}\small\item\em Postscript directory help description. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_afe75799aec30a1011e3f65a93538eb88}{limit\+\_\+arg} +\begin{DoxyCompactList}\small\item\em limit to species. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_a77bc7cac390e1901106ad9c70e04b9aa}{limit\+\_\+orig} +\begin{DoxyCompactList}\small\item\em limit to species original value given at command line. \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_ac54bb7e91539b98c4d0756254880b4ee}{limit\+\_\+help} +\begin{DoxyCompactList}\small\item\em limit to species help description. \end{DoxyCompactList}\item +int \hyperlink{structgengetopt__args__info_a7d3c9030b97320380911d603e2130e0d}{blosum\+\_\+arg} +\begin{DoxyCompactList}\small\item\em B\+L\+O\+S\+UM matrix version. \end{DoxyCompactList}\item +char $\ast$ \hyperlink{structgengetopt__args__info_a93a262b5d97dda58b75849a1318e2918}{blosum\+\_\+orig} +\begin{DoxyCompactList}\small\item\em B\+L\+O\+S\+UM matrix version original value given at command line. \end{DoxyCompactList}\item +\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$ \hyperlink{structgengetopt__args__info_a6527f32b39a7c09ee3daffe899887075}{blosum\+\_\+help} +\begin{DoxyCompactList}\small\item\em B\+L\+O\+S\+UM matrix version help description. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_ab9fd677f890731fd7d6f6c62e6dfc99c}{help\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether help was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_ad4953a2130b2f8b94a3a687014f278e1}{version\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether version was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_af6f058929187956cb68a0192b866f942}{outfile\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether outfile was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a0e6e111149cf2a4bc171c80ee4055f8e}{gtf\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether gtf was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a3b5a200c98e9f33b1dfa0adf5fbaf69d}{tabular\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether tabular was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a6c48b4d066a85f4a580a6a64dbdb176e}{best\+\_\+only\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether best-\/only was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_afd4b6f3efee5f421948359ec5eea335c}{best\+\_\+region\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether best-\/region was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_abaf16e517f88e5ad41e06e0584045074}{pars\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether pars was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a69729e2dba0de954d98a56a1b3d8d1c1}{stop\+\_\+early\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether stop-\/early was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a26d6c50dc3b78c9194509a8399d62888}{num\+\_\+samples\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether num-\/samples was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_ace7446eaaaffb4c8be5ee2d157933ac1}{cutoff\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether cutoff was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a87bd42cd11567d4e27859cc0569752d6}{debug\+\_\+file\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether debug-\/file was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a9d52e7e979f21f9278bcb39005164a44}{eps\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether eps was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a60b5aec84888abe557256b1909b01a01}{eps\+\_\+cutoff\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether eps-\/cutoff was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a33c0504245a49e483924248119b400a6}{eps\+\_\+dir\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether eps-\/dir was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a1058bb49a05830b377b2335d9ae1c7c9}{limit\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether limit was given. \end{DoxyCompactList}\item +unsigned int \hyperlink{structgengetopt__args__info_a5c4114dd20295edf631f04e637214386}{blosum\+\_\+given} +\begin{DoxyCompactList}\small\item\em Whether blosum was given. \end{DoxyCompactList}\item +char $\ast$$\ast$ \hyperlink{structgengetopt__args__info_a9604690019dd09b318302dae6868726c}{inputs} +\begin{DoxyCompactList}\small\item\em unamed options (options without names) \end{DoxyCompactList}\item +unsigned \hyperlink{structgengetopt__args__info_a3d69c180d5ac0b1124fd9a6fe680706c}{inputs\+\_\+num} +\begin{DoxyCompactList}\small\item\em unamed options number \end{DoxyCompactList}\end{DoxyCompactItemize} + + +\subsection{Detailed Description} +Where the command line options are stored. + +\subsection{Member Data Documentation} +\mbox{\Hypertarget{structgengetopt__args__info_ab0275ce8469b8fa0415ec84a692aba90}\label{structgengetopt__args__info_ab0275ce8469b8fa0415ec84a692aba90}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!best\+\_\+only\+\_\+flag@{best\+\_\+only\+\_\+flag}} +\index{best\+\_\+only\+\_\+flag@{best\+\_\+only\+\_\+flag}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{best\+\_\+only\+\_\+flag}{best\_only\_flag}} +{\footnotesize\ttfamily int gengetopt\+\_\+args\+\_\+info\+::best\+\_\+only\+\_\+flag} + + + +Print only best hit per alignment (default=off). + +\mbox{\Hypertarget{structgengetopt__args__info_a6c48b4d066a85f4a580a6a64dbdb176e}\label{structgengetopt__args__info_a6c48b4d066a85f4a580a6a64dbdb176e}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!best\+\_\+only\+\_\+given@{best\+\_\+only\+\_\+given}} +\index{best\+\_\+only\+\_\+given@{best\+\_\+only\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{best\+\_\+only\+\_\+given}{best\_only\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::best\+\_\+only\+\_\+given} + + + +Whether best-\/only was given. + +\mbox{\Hypertarget{structgengetopt__args__info_a4f31622f59d764e13fe3ef9d3d0cc579}\label{structgengetopt__args__info_a4f31622f59d764e13fe3ef9d3d0cc579}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!best\+\_\+only\+\_\+help@{best\+\_\+only\+\_\+help}} +\index{best\+\_\+only\+\_\+help@{best\+\_\+only\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{best\+\_\+only\+\_\+help}{best\_only\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::best\+\_\+only\+\_\+help} + + + +Print only best hit per alignment help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a4ee2d5172359ee7a6b7fd042fae11817}\label{structgengetopt__args__info_a4ee2d5172359ee7a6b7fd042fae11817}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!best\+\_\+region\+\_\+flag@{best\+\_\+region\+\_\+flag}} +\index{best\+\_\+region\+\_\+flag@{best\+\_\+region\+\_\+flag}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{best\+\_\+region\+\_\+flag}{best\_region\_flag}} +{\footnotesize\ttfamily int gengetopt\+\_\+args\+\_\+info\+::best\+\_\+region\+\_\+flag} + + + +Print all best non-\/overlapping hits per alignment (default=off). + +\mbox{\Hypertarget{structgengetopt__args__info_afd4b6f3efee5f421948359ec5eea335c}\label{structgengetopt__args__info_afd4b6f3efee5f421948359ec5eea335c}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!best\+\_\+region\+\_\+given@{best\+\_\+region\+\_\+given}} +\index{best\+\_\+region\+\_\+given@{best\+\_\+region\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{best\+\_\+region\+\_\+given}{best\_region\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::best\+\_\+region\+\_\+given} + + + +Whether best-\/region was given. + +\mbox{\Hypertarget{structgengetopt__args__info_a8943d1adc6dc6a89790adb4ce383943e}\label{structgengetopt__args__info_a8943d1adc6dc6a89790adb4ce383943e}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!best\+\_\+region\+\_\+help@{best\+\_\+region\+\_\+help}} +\index{best\+\_\+region\+\_\+help@{best\+\_\+region\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{best\+\_\+region\+\_\+help}{best\_region\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::best\+\_\+region\+\_\+help} + + + +Print all best non-\/overlapping hits per alignment help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a7d3c9030b97320380911d603e2130e0d}\label{structgengetopt__args__info_a7d3c9030b97320380911d603e2130e0d}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!blosum\+\_\+arg@{blosum\+\_\+arg}} +\index{blosum\+\_\+arg@{blosum\+\_\+arg}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{blosum\+\_\+arg}{blosum\_arg}} +{\footnotesize\ttfamily int gengetopt\+\_\+args\+\_\+info\+::blosum\+\_\+arg} + + + +B\+L\+O\+S\+UM matrix version. + +\mbox{\Hypertarget{structgengetopt__args__info_a5c4114dd20295edf631f04e637214386}\label{structgengetopt__args__info_a5c4114dd20295edf631f04e637214386}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!blosum\+\_\+given@{blosum\+\_\+given}} +\index{blosum\+\_\+given@{blosum\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{blosum\+\_\+given}{blosum\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::blosum\+\_\+given} + + + +Whether blosum was given. + +\mbox{\Hypertarget{structgengetopt__args__info_a6527f32b39a7c09ee3daffe899887075}\label{structgengetopt__args__info_a6527f32b39a7c09ee3daffe899887075}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!blosum\+\_\+help@{blosum\+\_\+help}} +\index{blosum\+\_\+help@{blosum\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{blosum\+\_\+help}{blosum\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::blosum\+\_\+help} + + + +B\+L\+O\+S\+UM matrix version help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a93a262b5d97dda58b75849a1318e2918}\label{structgengetopt__args__info_a93a262b5d97dda58b75849a1318e2918}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!blosum\+\_\+orig@{blosum\+\_\+orig}} +\index{blosum\+\_\+orig@{blosum\+\_\+orig}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{blosum\+\_\+orig}{blosum\_orig}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::blosum\+\_\+orig} + + + +B\+L\+O\+S\+UM matrix version original value given at command line. + +\mbox{\Hypertarget{structgengetopt__args__info_a79efa24e1a3d614f474d323f147edf10}\label{structgengetopt__args__info_a79efa24e1a3d614f474d323f147edf10}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!cutoff\+\_\+arg@{cutoff\+\_\+arg}} +\index{cutoff\+\_\+arg@{cutoff\+\_\+arg}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{cutoff\+\_\+arg}{cutoff\_arg}} +{\footnotesize\ttfamily float gengetopt\+\_\+args\+\_\+info\+::cutoff\+\_\+arg} + + + +p-\/value cutoff. + +\mbox{\Hypertarget{structgengetopt__args__info_ace7446eaaaffb4c8be5ee2d157933ac1}\label{structgengetopt__args__info_ace7446eaaaffb4c8be5ee2d157933ac1}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!cutoff\+\_\+given@{cutoff\+\_\+given}} +\index{cutoff\+\_\+given@{cutoff\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{cutoff\+\_\+given}{cutoff\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::cutoff\+\_\+given} + + + +Whether cutoff was given. + +\mbox{\Hypertarget{structgengetopt__args__info_a46f7d71837544abf13c5972fc5e528b3}\label{structgengetopt__args__info_a46f7d71837544abf13c5972fc5e528b3}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!cutoff\+\_\+help@{cutoff\+\_\+help}} +\index{cutoff\+\_\+help@{cutoff\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{cutoff\+\_\+help}{cutoff\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::cutoff\+\_\+help} + + + +p-\/value cutoff help description. + +\mbox{\Hypertarget{structgengetopt__args__info_ac1cc7e0fbe8552f19e4760b827349622}\label{structgengetopt__args__info_ac1cc7e0fbe8552f19e4760b827349622}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!cutoff\+\_\+orig@{cutoff\+\_\+orig}} +\index{cutoff\+\_\+orig@{cutoff\+\_\+orig}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{cutoff\+\_\+orig}{cutoff\_orig}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::cutoff\+\_\+orig} + + + +p-\/value cutoff original value given at command line. + +\mbox{\Hypertarget{structgengetopt__args__info_a648135bce096c7f592d4a6cc6d2b4d20}\label{structgengetopt__args__info_a648135bce096c7f592d4a6cc6d2b4d20}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!debug\+\_\+file\+\_\+arg@{debug\+\_\+file\+\_\+arg}} +\index{debug\+\_\+file\+\_\+arg@{debug\+\_\+file\+\_\+arg}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{debug\+\_\+file\+\_\+arg}{debug\_file\_arg}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::debug\+\_\+file\+\_\+arg} + + + +Debug file. + +\mbox{\Hypertarget{structgengetopt__args__info_a87bd42cd11567d4e27859cc0569752d6}\label{structgengetopt__args__info_a87bd42cd11567d4e27859cc0569752d6}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!debug\+\_\+file\+\_\+given@{debug\+\_\+file\+\_\+given}} +\index{debug\+\_\+file\+\_\+given@{debug\+\_\+file\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{debug\+\_\+file\+\_\+given}{debug\_file\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::debug\+\_\+file\+\_\+given} + + + +Whether debug-\/file was given. + +\mbox{\Hypertarget{structgengetopt__args__info_af5d881c802b02a6f85b5e4b957de85e9}\label{structgengetopt__args__info_af5d881c802b02a6f85b5e4b957de85e9}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!debug\+\_\+file\+\_\+help@{debug\+\_\+file\+\_\+help}} +\index{debug\+\_\+file\+\_\+help@{debug\+\_\+file\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{debug\+\_\+file\+\_\+help}{debug\_file\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::debug\+\_\+file\+\_\+help} + + + +Debug file help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a2b22e7ebbc50b2b054e9be56785fb2de}\label{structgengetopt__args__info_a2b22e7ebbc50b2b054e9be56785fb2de}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!debug\+\_\+file\+\_\+orig@{debug\+\_\+file\+\_\+orig}} +\index{debug\+\_\+file\+\_\+orig@{debug\+\_\+file\+\_\+orig}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{debug\+\_\+file\+\_\+orig}{debug\_file\_orig}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::debug\+\_\+file\+\_\+orig} + + + +Debug file original value given at command line. + +\mbox{\Hypertarget{structgengetopt__args__info_a7d5c15c092764baac13552613fda575f}\label{structgengetopt__args__info_a7d5c15c092764baac13552613fda575f}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+cutoff\+\_\+arg@{eps\+\_\+cutoff\+\_\+arg}} +\index{eps\+\_\+cutoff\+\_\+arg@{eps\+\_\+cutoff\+\_\+arg}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+cutoff\+\_\+arg}{eps\_cutoff\_arg}} +{\footnotesize\ttfamily float gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+cutoff\+\_\+arg} + + + +Postscript output p-\/value cutoff. + +\mbox{\Hypertarget{structgengetopt__args__info_a60b5aec84888abe557256b1909b01a01}\label{structgengetopt__args__info_a60b5aec84888abe557256b1909b01a01}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+cutoff\+\_\+given@{eps\+\_\+cutoff\+\_\+given}} +\index{eps\+\_\+cutoff\+\_\+given@{eps\+\_\+cutoff\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+cutoff\+\_\+given}{eps\_cutoff\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+cutoff\+\_\+given} + + + +Whether eps-\/cutoff was given. + +\mbox{\Hypertarget{structgengetopt__args__info_a32790cf21a0f8e8623371d12deb4b337}\label{structgengetopt__args__info_a32790cf21a0f8e8623371d12deb4b337}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+cutoff\+\_\+help@{eps\+\_\+cutoff\+\_\+help}} +\index{eps\+\_\+cutoff\+\_\+help@{eps\+\_\+cutoff\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+cutoff\+\_\+help}{eps\_cutoff\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+cutoff\+\_\+help} + + + +Postscript output p-\/value cutoff help description. + +\mbox{\Hypertarget{structgengetopt__args__info_ad2f45ed857ac6e6d8b1a371d85b65e25}\label{structgengetopt__args__info_ad2f45ed857ac6e6d8b1a371d85b65e25}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+cutoff\+\_\+orig@{eps\+\_\+cutoff\+\_\+orig}} +\index{eps\+\_\+cutoff\+\_\+orig@{eps\+\_\+cutoff\+\_\+orig}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+cutoff\+\_\+orig}{eps\_cutoff\_orig}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+cutoff\+\_\+orig} + + + +Postscript output p-\/value cutoff original value given at command line. + +\mbox{\Hypertarget{structgengetopt__args__info_a29434f1b1030755c24dde59d8c157de5}\label{structgengetopt__args__info_a29434f1b1030755c24dde59d8c157de5}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+dir\+\_\+arg@{eps\+\_\+dir\+\_\+arg}} +\index{eps\+\_\+dir\+\_\+arg@{eps\+\_\+dir\+\_\+arg}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+dir\+\_\+arg}{eps\_dir\_arg}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+dir\+\_\+arg} + + + +Postscript directory. + +\mbox{\Hypertarget{structgengetopt__args__info_a33c0504245a49e483924248119b400a6}\label{structgengetopt__args__info_a33c0504245a49e483924248119b400a6}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+dir\+\_\+given@{eps\+\_\+dir\+\_\+given}} +\index{eps\+\_\+dir\+\_\+given@{eps\+\_\+dir\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+dir\+\_\+given}{eps\_dir\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+dir\+\_\+given} + + + +Whether eps-\/dir was given. + +\mbox{\Hypertarget{structgengetopt__args__info_a1c676a66f0cf100d49679440032ae4ab}\label{structgengetopt__args__info_a1c676a66f0cf100d49679440032ae4ab}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+dir\+\_\+help@{eps\+\_\+dir\+\_\+help}} +\index{eps\+\_\+dir\+\_\+help@{eps\+\_\+dir\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+dir\+\_\+help}{eps\_dir\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+dir\+\_\+help} + + + +Postscript directory help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a7474b0d19ed3f9c13ebc88e6cf652c65}\label{structgengetopt__args__info_a7474b0d19ed3f9c13ebc88e6cf652c65}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+dir\+\_\+orig@{eps\+\_\+dir\+\_\+orig}} +\index{eps\+\_\+dir\+\_\+orig@{eps\+\_\+dir\+\_\+orig}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+dir\+\_\+orig}{eps\_dir\_orig}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+dir\+\_\+orig} + + + +Postscript directory original value given at command line. + +\mbox{\Hypertarget{structgengetopt__args__info_a4c97eb3971c8f9222073e63484872bf0}\label{structgengetopt__args__info_a4c97eb3971c8f9222073e63484872bf0}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+flag@{eps\+\_\+flag}} +\index{eps\+\_\+flag@{eps\+\_\+flag}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+flag}{eps\_flag}} +{\footnotesize\ttfamily int gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+flag} + + + +Postscript output (default=off). + +\mbox{\Hypertarget{structgengetopt__args__info_a9d52e7e979f21f9278bcb39005164a44}\label{structgengetopt__args__info_a9d52e7e979f21f9278bcb39005164a44}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+given@{eps\+\_\+given}} +\index{eps\+\_\+given@{eps\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+given}{eps\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+given} + + + +Whether eps was given. + +\mbox{\Hypertarget{structgengetopt__args__info_aa87d33b8ebe4fa33c6c4b7454c3e7e55}\label{structgengetopt__args__info_aa87d33b8ebe4fa33c6c4b7454c3e7e55}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!eps\+\_\+help@{eps\+\_\+help}} +\index{eps\+\_\+help@{eps\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{eps\+\_\+help}{eps\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::eps\+\_\+help} + + + +Postscript output help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a3cc76992b00eb5f69d49ecabfa65de28}\label{structgengetopt__args__info_a3cc76992b00eb5f69d49ecabfa65de28}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!gtf\+\_\+flag@{gtf\+\_\+flag}} +\index{gtf\+\_\+flag@{gtf\+\_\+flag}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{gtf\+\_\+flag}{gtf\_flag}} +{\footnotesize\ttfamily int gengetopt\+\_\+args\+\_\+info\+::gtf\+\_\+flag} + + + +G\+TF output (default=off). + +\mbox{\Hypertarget{structgengetopt__args__info_a0e6e111149cf2a4bc171c80ee4055f8e}\label{structgengetopt__args__info_a0e6e111149cf2a4bc171c80ee4055f8e}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!gtf\+\_\+given@{gtf\+\_\+given}} +\index{gtf\+\_\+given@{gtf\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{gtf\+\_\+given}{gtf\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::gtf\+\_\+given} + + + +Whether gtf was given. + +\mbox{\Hypertarget{structgengetopt__args__info_a7eb6417bded13cc26a47a1ee53bcb8dc}\label{structgengetopt__args__info_a7eb6417bded13cc26a47a1ee53bcb8dc}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!gtf\+\_\+help@{gtf\+\_\+help}} +\index{gtf\+\_\+help@{gtf\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{gtf\+\_\+help}{gtf\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::gtf\+\_\+help} + + + +G\+TF output help description. + +\mbox{\Hypertarget{structgengetopt__args__info_ab9fd677f890731fd7d6f6c62e6dfc99c}\label{structgengetopt__args__info_ab9fd677f890731fd7d6f6c62e6dfc99c}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!help\+\_\+given@{help\+\_\+given}} +\index{help\+\_\+given@{help\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{help\+\_\+given}{help\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::help\+\_\+given} + + + +Whether help was given. + +\mbox{\Hypertarget{structgengetopt__args__info_afb4efa68a6f43a4d112e9b96ffe89101}\label{structgengetopt__args__info_afb4efa68a6f43a4d112e9b96ffe89101}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!help\+\_\+help@{help\+\_\+help}} +\index{help\+\_\+help@{help\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{help\+\_\+help}{help\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::help\+\_\+help} + + + +Print help and exit help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a9604690019dd09b318302dae6868726c}\label{structgengetopt__args__info_a9604690019dd09b318302dae6868726c}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!inputs@{inputs}} +\index{inputs@{inputs}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{inputs}{inputs}} +{\footnotesize\ttfamily char$\ast$$\ast$ gengetopt\+\_\+args\+\_\+info\+::inputs} + + + +unamed options (options without names) + +\mbox{\Hypertarget{structgengetopt__args__info_a3d69c180d5ac0b1124fd9a6fe680706c}\label{structgengetopt__args__info_a3d69c180d5ac0b1124fd9a6fe680706c}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!inputs\+\_\+num@{inputs\+\_\+num}} +\index{inputs\+\_\+num@{inputs\+\_\+num}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{inputs\+\_\+num}{inputs\_num}} +{\footnotesize\ttfamily unsigned gengetopt\+\_\+args\+\_\+info\+::inputs\+\_\+num} + + + +unamed options number + +\mbox{\Hypertarget{structgengetopt__args__info_afe75799aec30a1011e3f65a93538eb88}\label{structgengetopt__args__info_afe75799aec30a1011e3f65a93538eb88}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!limit\+\_\+arg@{limit\+\_\+arg}} +\index{limit\+\_\+arg@{limit\+\_\+arg}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{limit\+\_\+arg}{limit\_arg}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::limit\+\_\+arg} + + + +limit to species. + +\mbox{\Hypertarget{structgengetopt__args__info_a1058bb49a05830b377b2335d9ae1c7c9}\label{structgengetopt__args__info_a1058bb49a05830b377b2335d9ae1c7c9}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!limit\+\_\+given@{limit\+\_\+given}} +\index{limit\+\_\+given@{limit\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{limit\+\_\+given}{limit\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::limit\+\_\+given} + + + +Whether limit was given. + +\mbox{\Hypertarget{structgengetopt__args__info_ac54bb7e91539b98c4d0756254880b4ee}\label{structgengetopt__args__info_ac54bb7e91539b98c4d0756254880b4ee}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!limit\+\_\+help@{limit\+\_\+help}} +\index{limit\+\_\+help@{limit\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{limit\+\_\+help}{limit\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::limit\+\_\+help} + + + +limit to species help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a77bc7cac390e1901106ad9c70e04b9aa}\label{structgengetopt__args__info_a77bc7cac390e1901106ad9c70e04b9aa}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!limit\+\_\+orig@{limit\+\_\+orig}} +\index{limit\+\_\+orig@{limit\+\_\+orig}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{limit\+\_\+orig}{limit\_orig}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::limit\+\_\+orig} + + + +limit to species original value given at command line. + +\mbox{\Hypertarget{structgengetopt__args__info_ac62c13305dd12c4d426aeb82b6e4561b}\label{structgengetopt__args__info_ac62c13305dd12c4d426aeb82b6e4561b}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!num\+\_\+samples\+\_\+arg@{num\+\_\+samples\+\_\+arg}} +\index{num\+\_\+samples\+\_\+arg@{num\+\_\+samples\+\_\+arg}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{num\+\_\+samples\+\_\+arg}{num\_samples\_arg}} +{\footnotesize\ttfamily int gengetopt\+\_\+args\+\_\+info\+::num\+\_\+samples\+\_\+arg} + + + +Number of samples. + +\mbox{\Hypertarget{structgengetopt__args__info_a26d6c50dc3b78c9194509a8399d62888}\label{structgengetopt__args__info_a26d6c50dc3b78c9194509a8399d62888}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!num\+\_\+samples\+\_\+given@{num\+\_\+samples\+\_\+given}} +\index{num\+\_\+samples\+\_\+given@{num\+\_\+samples\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{num\+\_\+samples\+\_\+given}{num\_samples\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::num\+\_\+samples\+\_\+given} + + + +Whether num-\/samples was given. + +\mbox{\Hypertarget{structgengetopt__args__info_a1c4039a0fea549c7db4b2c62482179f8}\label{structgengetopt__args__info_a1c4039a0fea549c7db4b2c62482179f8}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!num\+\_\+samples\+\_\+help@{num\+\_\+samples\+\_\+help}} +\index{num\+\_\+samples\+\_\+help@{num\+\_\+samples\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{num\+\_\+samples\+\_\+help}{num\_samples\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::num\+\_\+samples\+\_\+help} + + + +Number of samples help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a043409e12989cdbf8cd34fa47f8c6a4c}\label{structgengetopt__args__info_a043409e12989cdbf8cd34fa47f8c6a4c}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!num\+\_\+samples\+\_\+orig@{num\+\_\+samples\+\_\+orig}} +\index{num\+\_\+samples\+\_\+orig@{num\+\_\+samples\+\_\+orig}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{num\+\_\+samples\+\_\+orig}{num\_samples\_orig}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::num\+\_\+samples\+\_\+orig} + + + +Number of samples original value given at command line. + +\mbox{\Hypertarget{structgengetopt__args__info_ab9e3d63af39beb195c0ce4b30628475b}\label{structgengetopt__args__info_ab9e3d63af39beb195c0ce4b30628475b}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!outfile\+\_\+arg@{outfile\+\_\+arg}} +\index{outfile\+\_\+arg@{outfile\+\_\+arg}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{outfile\+\_\+arg}{outfile\_arg}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::outfile\+\_\+arg} + + + +Output filename. + +\mbox{\Hypertarget{structgengetopt__args__info_af6f058929187956cb68a0192b866f942}\label{structgengetopt__args__info_af6f058929187956cb68a0192b866f942}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!outfile\+\_\+given@{outfile\+\_\+given}} +\index{outfile\+\_\+given@{outfile\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{outfile\+\_\+given}{outfile\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::outfile\+\_\+given} + + + +Whether outfile was given. + +\mbox{\Hypertarget{structgengetopt__args__info_ae7d54ef8556b73161c14a77b20fe321f}\label{structgengetopt__args__info_ae7d54ef8556b73161c14a77b20fe321f}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!outfile\+\_\+help@{outfile\+\_\+help}} +\index{outfile\+\_\+help@{outfile\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{outfile\+\_\+help}{outfile\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::outfile\+\_\+help} + + + +Output filename help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a39782404c00e6f9107f8fdcae948222f}\label{structgengetopt__args__info_a39782404c00e6f9107f8fdcae948222f}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!outfile\+\_\+orig@{outfile\+\_\+orig}} +\index{outfile\+\_\+orig@{outfile\+\_\+orig}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{outfile\+\_\+orig}{outfile\_orig}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::outfile\+\_\+orig} + + + +Output filename original value given at command line. + +\mbox{\Hypertarget{structgengetopt__args__info_a965c61281e9339738647ff5e44604d8b}\label{structgengetopt__args__info_a965c61281e9339738647ff5e44604d8b}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!pars\+\_\+arg@{pars\+\_\+arg}} +\index{pars\+\_\+arg@{pars\+\_\+arg}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{pars\+\_\+arg}{pars\_arg}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::pars\+\_\+arg} + + + +String with parameters. + +\mbox{\Hypertarget{structgengetopt__args__info_abaf16e517f88e5ad41e06e0584045074}\label{structgengetopt__args__info_abaf16e517f88e5ad41e06e0584045074}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!pars\+\_\+given@{pars\+\_\+given}} +\index{pars\+\_\+given@{pars\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{pars\+\_\+given}{pars\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::pars\+\_\+given} + + + +Whether pars was given. + +\mbox{\Hypertarget{structgengetopt__args__info_aacd28fcc4238ef2516cca7526df79533}\label{structgengetopt__args__info_aacd28fcc4238ef2516cca7526df79533}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!pars\+\_\+help@{pars\+\_\+help}} +\index{pars\+\_\+help@{pars\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{pars\+\_\+help}{pars\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::pars\+\_\+help} + + + +String with parameters help description. + +\mbox{\Hypertarget{structgengetopt__args__info_a2c6837447e74b77af713002cdb58949b}\label{structgengetopt__args__info_a2c6837447e74b77af713002cdb58949b}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!pars\+\_\+orig@{pars\+\_\+orig}} +\index{pars\+\_\+orig@{pars\+\_\+orig}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{pars\+\_\+orig}{pars\_orig}} +{\footnotesize\ttfamily char$\ast$ gengetopt\+\_\+args\+\_\+info\+::pars\+\_\+orig} + + + +String with parameters original value given at command line. + +\mbox{\Hypertarget{structgengetopt__args__info_aa4b8393ab6c37bca14cb1b291b5871df}\label{structgengetopt__args__info_aa4b8393ab6c37bca14cb1b291b5871df}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!stop\+\_\+early\+\_\+flag@{stop\+\_\+early\+\_\+flag}} +\index{stop\+\_\+early\+\_\+flag@{stop\+\_\+early\+\_\+flag}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{stop\+\_\+early\+\_\+flag}{stop\_early\_flag}} +{\footnotesize\ttfamily int gengetopt\+\_\+args\+\_\+info\+::stop\+\_\+early\+\_\+flag} + + + +Don\textquotesingle{}t calculate p-\/values if below cutoff (default=off). + +\mbox{\Hypertarget{structgengetopt__args__info_a69729e2dba0de954d98a56a1b3d8d1c1}\label{structgengetopt__args__info_a69729e2dba0de954d98a56a1b3d8d1c1}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!stop\+\_\+early\+\_\+given@{stop\+\_\+early\+\_\+given}} +\index{stop\+\_\+early\+\_\+given@{stop\+\_\+early\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{stop\+\_\+early\+\_\+given}{stop\_early\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::stop\+\_\+early\+\_\+given} + + + +Whether stop-\/early was given. + +\mbox{\Hypertarget{structgengetopt__args__info_aefd3bdbabef305d8e53741dc229e7cb0}\label{structgengetopt__args__info_aefd3bdbabef305d8e53741dc229e7cb0}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!stop\+\_\+early\+\_\+help@{stop\+\_\+early\+\_\+help}} +\index{stop\+\_\+early\+\_\+help@{stop\+\_\+early\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{stop\+\_\+early\+\_\+help}{stop\_early\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::stop\+\_\+early\+\_\+help} + + + +Don\textquotesingle{}t calculate p-\/values if below cutoff help description. + +\mbox{\Hypertarget{structgengetopt__args__info_aa01935a1796974d3347aff6062718afc}\label{structgengetopt__args__info_aa01935a1796974d3347aff6062718afc}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!tabular\+\_\+flag@{tabular\+\_\+flag}} +\index{tabular\+\_\+flag@{tabular\+\_\+flag}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{tabular\+\_\+flag}{tabular\_flag}} +{\footnotesize\ttfamily int gengetopt\+\_\+args\+\_\+info\+::tabular\+\_\+flag} + + + +Tab delimited output (default=off). + +\mbox{\Hypertarget{structgengetopt__args__info_a3b5a200c98e9f33b1dfa0adf5fbaf69d}\label{structgengetopt__args__info_a3b5a200c98e9f33b1dfa0adf5fbaf69d}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!tabular\+\_\+given@{tabular\+\_\+given}} +\index{tabular\+\_\+given@{tabular\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{tabular\+\_\+given}{tabular\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::tabular\+\_\+given} + + + +Whether tabular was given. + +\mbox{\Hypertarget{structgengetopt__args__info_a923b9288287e40df1b3f21bfe288f123}\label{structgengetopt__args__info_a923b9288287e40df1b3f21bfe288f123}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!tabular\+\_\+help@{tabular\+\_\+help}} +\index{tabular\+\_\+help@{tabular\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{tabular\+\_\+help}{tabular\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::tabular\+\_\+help} + + + +Tab delimited output help description. + +\mbox{\Hypertarget{structgengetopt__args__info_ad4953a2130b2f8b94a3a687014f278e1}\label{structgengetopt__args__info_ad4953a2130b2f8b94a3a687014f278e1}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!version\+\_\+given@{version\+\_\+given}} +\index{version\+\_\+given@{version\+\_\+given}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{version\+\_\+given}{version\_given}} +{\footnotesize\ttfamily unsigned int gengetopt\+\_\+args\+\_\+info\+::version\+\_\+given} + + + +Whether version was given. + +\mbox{\Hypertarget{structgengetopt__args__info_adef454ea6f3ff4114ae5009e58360cfc}\label{structgengetopt__args__info_adef454ea6f3ff4114ae5009e58360cfc}} +\index{gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}!version\+\_\+help@{version\+\_\+help}} +\index{version\+\_\+help@{version\+\_\+help}!gengetopt\+\_\+args\+\_\+info@{gengetopt\+\_\+args\+\_\+info}} +\subsubsection{\texorpdfstring{version\+\_\+help}{version\_help}} +{\footnotesize\ttfamily \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char$\ast$ gengetopt\+\_\+args\+\_\+info\+::version\+\_\+help} + + + +Print version and exit help description. + + + +The documentation for this struct was generated from the following file\+:\begin{DoxyCompactItemize} +\item +\hyperlink{cmdline_8h}{cmdline.\+h}\end{DoxyCompactItemize} diff --git a/src/latex/structoption.tex b/src/latex/structoption.tex new file mode 100644 index 0000000..3a78a24 --- /dev/null +++ b/src/latex/structoption.tex @@ -0,0 +1,49 @@ +\hypertarget{structoption}{}\section{option Struct Reference} +\label{structoption}\index{option@{option}} + + +{\ttfamily \#include $<$getopt.\+h$>$} + +\subsection*{Public Attributes} +\begin{DoxyCompactItemize} +\item +char $\ast$ \hyperlink{structoption_a92c850a23c7828c1dba453bf8d15e1f0}{name} +\item +int \hyperlink{structoption_a90d7ee9a51eea5c002682dbd0af149e4}{has\+\_\+arg} +\item +int $\ast$ \hyperlink{structoption_ab366eea5fe7be25c1928328ba715e353}{flag} +\item +int \hyperlink{structoption_a13bd155ec3b405d29c41ab8d0793be11}{val} +\end{DoxyCompactItemize} + + +\subsection{Member Data Documentation} +\mbox{\Hypertarget{structoption_ab366eea5fe7be25c1928328ba715e353}\label{structoption_ab366eea5fe7be25c1928328ba715e353}} +\index{option@{option}!flag@{flag}} +\index{flag@{flag}!option@{option}} +\subsubsection{\texorpdfstring{flag}{flag}} +{\footnotesize\ttfamily int$\ast$ option\+::flag} + +\mbox{\Hypertarget{structoption_a90d7ee9a51eea5c002682dbd0af149e4}\label{structoption_a90d7ee9a51eea5c002682dbd0af149e4}} +\index{option@{option}!has\+\_\+arg@{has\+\_\+arg}} +\index{has\+\_\+arg@{has\+\_\+arg}!option@{option}} +\subsubsection{\texorpdfstring{has\+\_\+arg}{has\_arg}} +{\footnotesize\ttfamily int option\+::has\+\_\+arg} + +\mbox{\Hypertarget{structoption_a92c850a23c7828c1dba453bf8d15e1f0}\label{structoption_a92c850a23c7828c1dba453bf8d15e1f0}} +\index{option@{option}!name@{name}} +\index{name@{name}!option@{option}} +\subsubsection{\texorpdfstring{name}{name}} +{\footnotesize\ttfamily char$\ast$ option\+::name} + +\mbox{\Hypertarget{structoption_a13bd155ec3b405d29c41ab8d0793be11}\label{structoption_a13bd155ec3b405d29c41ab8d0793be11}} +\index{option@{option}!val@{val}} +\index{val@{val}!option@{option}} +\subsubsection{\texorpdfstring{val}{val}} +{\footnotesize\ttfamily int option\+::val} + + + +The documentation for this struct was generated from the following file\+:\begin{DoxyCompactItemize} +\item +\hyperlink{getopt_8h}{getopt.\+h}\end{DoxyCompactItemize} diff --git a/src/latex/treeML_8c.tex b/src/latex/treeML_8c.tex new file mode 100644 index 0000000..081b947 --- /dev/null +++ b/src/latex/treeML_8c.tex @@ -0,0 +1,53 @@ +\hypertarget{treeML_8c}{}\section{tree\+M\+L.\+c File Reference} +\label{treeML_8c}\index{tree\+M\+L.\+c@{tree\+M\+L.\+c}} +{\ttfamily \#include \char`\"{}spr.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}utilities.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}lk.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}optimiz.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}bionj.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}models.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}free.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}options.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}simu.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}eigen.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}pars.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}alrt.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}rnaz\+\_\+utils.\+h\char`\"{}}\newline +Include dependency graph for tree\+M\+L.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{treeML_8c__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +seq $\ast$$\ast$ \hyperlink{treeML_8c_a8a90f2586451905454dd568da9a0f759}{Get\+\_\+\+Seq\+\_\+local} (seq $\ast$$\ast$, \hyperlink{structoption}{option} $\ast$io, int rw) +\item +int \hyperlink{treeML_8c_a252122923da9d542436a6ce49c15c819}{tree\+ML} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, char $\ast$$\ast$tree\+String, float $\ast$kappa) +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{treeML_8c_a8a90f2586451905454dd568da9a0f759}\label{treeML_8c_a8a90f2586451905454dd568da9a0f759}} +\index{tree\+M\+L.\+c@{tree\+M\+L.\+c}!Get\+\_\+\+Seq\+\_\+local@{Get\+\_\+\+Seq\+\_\+local}} +\index{Get\+\_\+\+Seq\+\_\+local@{Get\+\_\+\+Seq\+\_\+local}!tree\+M\+L.\+c@{tree\+M\+L.\+c}} +\subsubsection{\texorpdfstring{Get\+\_\+\+Seq\+\_\+local()}{Get\_Seq\_local()}} +{\footnotesize\ttfamily seq $\ast$$\ast$ Get\+\_\+\+Seq\+\_\+local (\begin{DoxyParamCaption}\item[{seq $\ast$$\ast$}]{data, }\item[{\hyperlink{structoption}{option} $\ast$}]{io, }\item[{int}]{rw }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{treeML_8c_a252122923da9d542436a6ce49c15c819}\label{treeML_8c_a252122923da9d542436a6ce49c15c819}} +\index{tree\+M\+L.\+c@{tree\+M\+L.\+c}!tree\+ML@{tree\+ML}} +\index{tree\+ML@{tree\+ML}!tree\+M\+L.\+c@{tree\+M\+L.\+c}} +\subsubsection{\texorpdfstring{tree\+M\+L()}{treeML()}} +{\footnotesize\ttfamily int tree\+ML (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{char $\ast$$\ast$}]{tree\+String, }\item[{float $\ast$}]{kappa }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=243pt]{treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph} +\end{center} +\end{figure} diff --git a/src/latex/treeML_8c__incl.md5 b/src/latex/treeML_8c__incl.md5 new file mode 100644 index 0000000..6d3f1f4 --- /dev/null +++ b/src/latex/treeML_8c__incl.md5 @@ -0,0 +1 @@ +3f514337712c22548328cd29ec397588 \ No newline at end of file diff --git a/src/latex/treeML_8c__incl.pdf b/src/latex/treeML_8c__incl.pdf new file mode 100644 index 0000000..6ddfa5e Binary files /dev/null and b/src/latex/treeML_8c__incl.pdf differ diff --git a/src/latex/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.md5 b/src/latex/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.md5 new file mode 100644 index 0000000..7fb097a --- /dev/null +++ b/src/latex/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.md5 @@ -0,0 +1 @@ +c4699aaa3a8e99051d2b3d3cef71d4a8 \ No newline at end of file diff --git a/src/latex/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.pdf b/src/latex/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.pdf new file mode 100644 index 0000000..7595e41 Binary files /dev/null and b/src/latex/treeML_8c_a252122923da9d542436a6ce49c15c819_cgraph.pdf differ diff --git a/src/latex/treeML_8h.tex b/src/latex/treeML_8h.tex new file mode 100644 index 0000000..03b1412 --- /dev/null +++ b/src/latex/treeML_8h.tex @@ -0,0 +1,46 @@ +\hypertarget{treeML_8h}{}\section{tree\+M\+L.\+h File Reference} +\label{treeML_8h}\index{tree\+M\+L.\+h@{tree\+M\+L.\+h}} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=148pt]{treeML_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Macros} +\begin{DoxyCompactItemize} +\item +\#define \hyperlink{treeML_8h_a881b73a915d74c35b5bdae930066e817}{P\+H\+Y\+ML} +\end{DoxyCompactItemize} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +int \hyperlink{treeML_8h_a252122923da9d542436a6ce49c15c819}{tree\+ML} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}, char $\ast$$\ast$tree\+String, float $\ast$kappa) +\end{DoxyCompactItemize} + + +\subsection{Macro Definition Documentation} +\mbox{\Hypertarget{treeML_8h_a881b73a915d74c35b5bdae930066e817}\label{treeML_8h_a881b73a915d74c35b5bdae930066e817}} +\index{tree\+M\+L.\+h@{tree\+M\+L.\+h}!P\+H\+Y\+ML@{P\+H\+Y\+ML}} +\index{P\+H\+Y\+ML@{P\+H\+Y\+ML}!tree\+M\+L.\+h@{tree\+M\+L.\+h}} +\subsubsection{\texorpdfstring{P\+H\+Y\+ML}{PHYML}} +{\footnotesize\ttfamily \#define P\+H\+Y\+ML} + + + +\subsection{Function Documentation} +\mbox{\Hypertarget{treeML_8h_a252122923da9d542436a6ce49c15c819}\label{treeML_8h_a252122923da9d542436a6ce49c15c819}} +\index{tree\+M\+L.\+h@{tree\+M\+L.\+h}!tree\+ML@{tree\+ML}} +\index{tree\+ML@{tree\+ML}!tree\+M\+L.\+h@{tree\+M\+L.\+h}} +\subsubsection{\texorpdfstring{tree\+M\+L()}{treeML()}} +{\footnotesize\ttfamily int tree\+ML (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]}, }\item[{char $\ast$$\ast$}]{tree\+String, }\item[{float $\ast$}]{kappa }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=243pt]{treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph} +\end{center} +\end{figure} diff --git a/src/latex/treeML_8h__dep__incl.md5 b/src/latex/treeML_8h__dep__incl.md5 new file mode 100644 index 0000000..c30accb --- /dev/null +++ b/src/latex/treeML_8h__dep__incl.md5 @@ -0,0 +1 @@ +0be8bfa141620f2e3ef28fa89b8f2c5a \ No newline at end of file diff --git a/src/latex/treeML_8h__dep__incl.pdf b/src/latex/treeML_8h__dep__incl.pdf new file mode 100644 index 0000000..dcdd04b Binary files /dev/null and b/src/latex/treeML_8h__dep__incl.pdf differ diff --git a/src/latex/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.md5 b/src/latex/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.md5 new file mode 100644 index 0000000..435c977 --- /dev/null +++ b/src/latex/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.md5 @@ -0,0 +1 @@ +56784f18dd32bfe2e0edad70e058b7cb \ No newline at end of file diff --git a/src/latex/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.pdf b/src/latex/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.pdf new file mode 100644 index 0000000..03d6ea2 Binary files /dev/null and b/src/latex/treeML_8h_a252122923da9d542436a6ce49c15c819_cgraph.pdf differ diff --git a/src/latex/treeSimulate_8c.tex b/src/latex/treeSimulate_8c.tex new file mode 100644 index 0000000..1385951 --- /dev/null +++ b/src/latex/treeSimulate_8c.tex @@ -0,0 +1,182 @@ +\hypertarget{treeSimulate_8c}{}\section{tree\+Simulate.\+c File Reference} +\label{treeSimulate_8c}\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}} +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include $<$stdlib.\+h$>$}\newline +{\ttfamily \#include $<$string.\+h$>$}\newline +{\ttfamily \#include $<$ctype.\+h$>$}\newline +{\ttfamily \#include $<$time.\+h$>$}\newline +{\ttfamily \#include $<$math.\+h$>$}\newline +{\ttfamily \#include \char`\"{}rnaz\+\_\+utils.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}tree\+Simulate.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}global.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}treefile.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}evolve.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}model.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}nucmodels.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}aamodels.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}progress.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}twister.\+h\char`\"{}}\newline +Include dependency graph for tree\+Simulate.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{treeSimulate_8c__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +void \hyperlink{treeSimulate_8c_a2a10fb3293a345ad28201efc8f452348}{simulate\+Tree} (T\+Tree $\ast$tree, float freqs\mbox{[}$\,$\mbox{]}, float kap, int L) +\item +T\+Tree $\ast$ \hyperlink{treeSimulate_8c_af77eeafe78dc6291a2c5a0f9e0dea164}{string2tree} (char $\ast$tree\+String) +\item +float $\ast$$\ast$ \hyperlink{treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f}{get\+Distance\+Matrix} (T\+Tree $\ast$tree, struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +T\+Node $\ast$ \hyperlink{treeSimulate_8c_a3d5dbc026864385b3c931c928110b32a}{get\+L\+CA} (T\+Tree $\ast$tree, T\+Node $\ast$nodeA, T\+Node $\ast$nodeB) +\item +void \hyperlink{treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6}{tree2aln} (T\+Tree $\ast$tree, struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{treeSimulate_8c_a0f4d088716aa0dbcb5485641a0be7096}{free\+Seqgen\+Tree} (T\+Tree $\ast$tree) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +int \hyperlink{treeSimulate_8c_a027a1f1731d22465c926ce57be2364c3}{model} +\item +int \hyperlink{treeSimulate_8c_a39cc268c324972ce5653c35bdc8aa80f}{num\+States} +\item +int \hyperlink{treeSimulate_8c_a72e05eb4637bf2f93aa05f211b1a57b2}{is\+Nuc\+Model} +\item +int \hyperlink{treeSimulate_8c_a2d2500b39f829187e7542d576b71a547}{user\+Freqs} +\item +int \hyperlink{treeSimulate_8c_a85ef69963901475137a5babcaf4233b3}{equal\+Freqs} +\item +int \hyperlink{treeSimulate_8c_a13ffae79c3c34f8e30570d5baf7641b0}{num\+Sites} +\item +double \hyperlink{treeSimulate_8c_a489eb68465b539564550251550697a47}{tstv} +\item +double \hyperlink{treeSimulate_8c_a720f633590f8f9d192891d52735cfcce}{nuc\+Freq} \mbox{[}N\+U\+M\+\_\+\+N\+UC\mbox{]} +\item +int \hyperlink{treeSimulate_8c_a3893608bdd239b0b3b47338282608791}{num\+Taxa} +\item +char $\ast$ \hyperlink{treeSimulate_8c_aed2d481a3756e5431b6d0e26b1d4b246}{P} +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{treeSimulate_8c_a0f4d088716aa0dbcb5485641a0be7096}\label{treeSimulate_8c_a0f4d088716aa0dbcb5485641a0be7096}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!free\+Seqgen\+Tree@{free\+Seqgen\+Tree}} +\index{free\+Seqgen\+Tree@{free\+Seqgen\+Tree}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{free\+Seqgen\+Tree()}{freeSeqgenTree()}} +{\footnotesize\ttfamily void free\+Seqgen\+Tree (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f}\label{treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!get\+Distance\+Matrix@{get\+Distance\+Matrix}} +\index{get\+Distance\+Matrix@{get\+Distance\+Matrix}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{get\+Distance\+Matrix()}{getDistanceMatrix()}} +{\footnotesize\ttfamily float$\ast$$\ast$ get\+Distance\+Matrix (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=262pt]{treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{treeSimulate_8c_a3d5dbc026864385b3c931c928110b32a}\label{treeSimulate_8c_a3d5dbc026864385b3c931c928110b32a}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!get\+L\+CA@{get\+L\+CA}} +\index{get\+L\+CA@{get\+L\+CA}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{get\+L\+C\+A()}{getLCA()}} +{\footnotesize\ttfamily T\+Node$\ast$ get\+L\+CA (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{T\+Node $\ast$}]{nodeA, }\item[{T\+Node $\ast$}]{nodeB }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{treeSimulate_8c_a2a10fb3293a345ad28201efc8f452348}\label{treeSimulate_8c_a2a10fb3293a345ad28201efc8f452348}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!simulate\+Tree@{simulate\+Tree}} +\index{simulate\+Tree@{simulate\+Tree}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{simulate\+Tree()}{simulateTree()}} +{\footnotesize\ttfamily void simulate\+Tree (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{float}]{freqs\mbox{[}$\,$\mbox{]}, }\item[{float}]{kap, }\item[{int}]{L }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{treeSimulate_8c_af77eeafe78dc6291a2c5a0f9e0dea164}\label{treeSimulate_8c_af77eeafe78dc6291a2c5a0f9e0dea164}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!string2tree@{string2tree}} +\index{string2tree@{string2tree}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{string2tree()}{string2tree()}} +{\footnotesize\ttfamily T\+Tree$\ast$ string2tree (\begin{DoxyParamCaption}\item[{char $\ast$}]{tree\+String }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6}\label{treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!tree2aln@{tree2aln}} +\index{tree2aln@{tree2aln}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{tree2aln()}{tree2aln()}} +{\footnotesize\ttfamily void tree2aln (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=327pt]{treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph} +\end{center} +\end{figure} + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{treeSimulate_8c_a85ef69963901475137a5babcaf4233b3}\label{treeSimulate_8c_a85ef69963901475137a5babcaf4233b3}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!equal\+Freqs@{equal\+Freqs}} +\index{equal\+Freqs@{equal\+Freqs}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{equal\+Freqs}{equalFreqs}} +{\footnotesize\ttfamily int equal\+Freqs} + +\mbox{\Hypertarget{treeSimulate_8c_a72e05eb4637bf2f93aa05f211b1a57b2}\label{treeSimulate_8c_a72e05eb4637bf2f93aa05f211b1a57b2}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!is\+Nuc\+Model@{is\+Nuc\+Model}} +\index{is\+Nuc\+Model@{is\+Nuc\+Model}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{is\+Nuc\+Model}{isNucModel}} +{\footnotesize\ttfamily int is\+Nuc\+Model} + +\mbox{\Hypertarget{treeSimulate_8c_a027a1f1731d22465c926ce57be2364c3}\label{treeSimulate_8c_a027a1f1731d22465c926ce57be2364c3}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!model@{model}} +\index{model@{model}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{model}{model}} +{\footnotesize\ttfamily int model} + +\mbox{\Hypertarget{treeSimulate_8c_a720f633590f8f9d192891d52735cfcce}\label{treeSimulate_8c_a720f633590f8f9d192891d52735cfcce}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!nuc\+Freq@{nuc\+Freq}} +\index{nuc\+Freq@{nuc\+Freq}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{nuc\+Freq}{nucFreq}} +{\footnotesize\ttfamily double nuc\+Freq\mbox{[}N\+U\+M\+\_\+\+N\+UC\mbox{]}} + +\mbox{\Hypertarget{treeSimulate_8c_a13ffae79c3c34f8e30570d5baf7641b0}\label{treeSimulate_8c_a13ffae79c3c34f8e30570d5baf7641b0}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!num\+Sites@{num\+Sites}} +\index{num\+Sites@{num\+Sites}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{num\+Sites}{numSites}} +{\footnotesize\ttfamily int num\+Sites} + +\mbox{\Hypertarget{treeSimulate_8c_a39cc268c324972ce5653c35bdc8aa80f}\label{treeSimulate_8c_a39cc268c324972ce5653c35bdc8aa80f}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!num\+States@{num\+States}} +\index{num\+States@{num\+States}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{num\+States}{numStates}} +{\footnotesize\ttfamily int num\+States} + +\mbox{\Hypertarget{treeSimulate_8c_a3893608bdd239b0b3b47338282608791}\label{treeSimulate_8c_a3893608bdd239b0b3b47338282608791}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!num\+Taxa@{num\+Taxa}} +\index{num\+Taxa@{num\+Taxa}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{num\+Taxa}{numTaxa}} +{\footnotesize\ttfamily int num\+Taxa} + +\mbox{\Hypertarget{treeSimulate_8c_aed2d481a3756e5431b6d0e26b1d4b246}\label{treeSimulate_8c_aed2d481a3756e5431b6d0e26b1d4b246}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!P@{P}} +\index{P@{P}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{P}{P}} +{\footnotesize\ttfamily char$\ast$ P} + +\mbox{\Hypertarget{treeSimulate_8c_a489eb68465b539564550251550697a47}\label{treeSimulate_8c_a489eb68465b539564550251550697a47}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!tstv@{tstv}} +\index{tstv@{tstv}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{tstv}{tstv}} +{\footnotesize\ttfamily double tstv} + +\mbox{\Hypertarget{treeSimulate_8c_a2d2500b39f829187e7542d576b71a547}\label{treeSimulate_8c_a2d2500b39f829187e7542d576b71a547}} +\index{tree\+Simulate.\+c@{tree\+Simulate.\+c}!user\+Freqs@{user\+Freqs}} +\index{user\+Freqs@{user\+Freqs}!tree\+Simulate.\+c@{tree\+Simulate.\+c}} +\subsubsection{\texorpdfstring{user\+Freqs}{userFreqs}} +{\footnotesize\ttfamily int user\+Freqs} + diff --git a/src/latex/treeSimulate_8c__incl.md5 b/src/latex/treeSimulate_8c__incl.md5 new file mode 100644 index 0000000..374c3ba --- /dev/null +++ b/src/latex/treeSimulate_8c__incl.md5 @@ -0,0 +1 @@ +b2eaccd13c41af4247e0993112b74a93 \ No newline at end of file diff --git a/src/latex/treeSimulate_8c__incl.pdf b/src/latex/treeSimulate_8c__incl.pdf new file mode 100644 index 0000000..69c6b0e Binary files /dev/null and b/src/latex/treeSimulate_8c__incl.pdf differ diff --git a/src/latex/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 b/src/latex/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 new file mode 100644 index 0000000..e158b90 --- /dev/null +++ b/src/latex/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 @@ -0,0 +1 @@ +be50194904c876e27467b90ec11fbea7 \ No newline at end of file diff --git a/src/latex/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.pdf b/src/latex/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.pdf new file mode 100644 index 0000000..4946025 Binary files /dev/null and b/src/latex/treeSimulate_8c_a3de1638db8b0f14df05b49f41bae2da6_cgraph.pdf differ diff --git a/src/latex/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 b/src/latex/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 new file mode 100644 index 0000000..b89094e --- /dev/null +++ b/src/latex/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 @@ -0,0 +1 @@ +ee4c9c6a3ed76829e7adffb331081e10 \ No newline at end of file diff --git a/src/latex/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.pdf b/src/latex/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.pdf new file mode 100644 index 0000000..1ebb15f Binary files /dev/null and b/src/latex/treeSimulate_8c_a684681e84edaa63e768ec7ad1ff4884f_cgraph.pdf differ diff --git a/src/latex/treeSimulate_8h.tex b/src/latex/treeSimulate_8h.tex new file mode 100644 index 0000000..9c2815a --- /dev/null +++ b/src/latex/treeSimulate_8h.tex @@ -0,0 +1,90 @@ +\hypertarget{treeSimulate_8h}{}\section{tree\+Simulate.\+h File Reference} +\label{treeSimulate_8h}\index{tree\+Simulate.\+h@{tree\+Simulate.\+h}} +{\ttfamily \#include \char`\"{}tree.\+h\char`\"{}}\newline +{\ttfamily \#include \char`\"{}rnaz\+\_\+utils.\+h\char`\"{}}\newline +Include dependency graph for tree\+Simulate.\+h\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=206pt]{treeSimulate_8h__incl} +\end{center} +\end{figure} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{treeSimulate_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +T\+Node $\ast$ \hyperlink{treeSimulate_8h_a3d5dbc026864385b3c931c928110b32a}{get\+L\+CA} (T\+Tree $\ast$tree, T\+Node $\ast$nodeA, T\+Node $\ast$nodeB) +\item +void \hyperlink{treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6}{tree2aln} (T\+Tree $\ast$tree, struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +T\+Tree $\ast$ \hyperlink{treeSimulate_8h_af77eeafe78dc6291a2c5a0f9e0dea164}{string2tree} (char $\ast$tree\+String) +\item +void \hyperlink{treeSimulate_8h_a2a10fb3293a345ad28201efc8f452348}{simulate\+Tree} (T\+Tree $\ast$tree, float freqs\mbox{[}$\,$\mbox{]}, float kap, int L) +\item +float $\ast$$\ast$ \hyperlink{treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f}{get\+Distance\+Matrix} (T\+Tree $\ast$tree, struct \hyperlink{structaln}{aln} $\ast$alignment\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{treeSimulate_8h_a0f4d088716aa0dbcb5485641a0be7096}{free\+Seqgen\+Tree} (T\+Tree $\ast$tree) +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{treeSimulate_8h_a0f4d088716aa0dbcb5485641a0be7096}\label{treeSimulate_8h_a0f4d088716aa0dbcb5485641a0be7096}} +\index{tree\+Simulate.\+h@{tree\+Simulate.\+h}!free\+Seqgen\+Tree@{free\+Seqgen\+Tree}} +\index{free\+Seqgen\+Tree@{free\+Seqgen\+Tree}!tree\+Simulate.\+h@{tree\+Simulate.\+h}} +\subsubsection{\texorpdfstring{free\+Seqgen\+Tree()}{freeSeqgenTree()}} +{\footnotesize\ttfamily void free\+Seqgen\+Tree (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f}\label{treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f}} +\index{tree\+Simulate.\+h@{tree\+Simulate.\+h}!get\+Distance\+Matrix@{get\+Distance\+Matrix}} +\index{get\+Distance\+Matrix@{get\+Distance\+Matrix}!tree\+Simulate.\+h@{tree\+Simulate.\+h}} +\subsubsection{\texorpdfstring{get\+Distance\+Matrix()}{getDistanceMatrix()}} +{\footnotesize\ttfamily float$\ast$$\ast$ get\+Distance\+Matrix (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=262pt]{treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{treeSimulate_8h_a3d5dbc026864385b3c931c928110b32a}\label{treeSimulate_8h_a3d5dbc026864385b3c931c928110b32a}} +\index{tree\+Simulate.\+h@{tree\+Simulate.\+h}!get\+L\+CA@{get\+L\+CA}} +\index{get\+L\+CA@{get\+L\+CA}!tree\+Simulate.\+h@{tree\+Simulate.\+h}} +\subsubsection{\texorpdfstring{get\+L\+C\+A()}{getLCA()}} +{\footnotesize\ttfamily T\+Node$\ast$ get\+L\+CA (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{T\+Node $\ast$}]{nodeA, }\item[{T\+Node $\ast$}]{nodeB }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{treeSimulate_8h_a2a10fb3293a345ad28201efc8f452348}\label{treeSimulate_8h_a2a10fb3293a345ad28201efc8f452348}} +\index{tree\+Simulate.\+h@{tree\+Simulate.\+h}!simulate\+Tree@{simulate\+Tree}} +\index{simulate\+Tree@{simulate\+Tree}!tree\+Simulate.\+h@{tree\+Simulate.\+h}} +\subsubsection{\texorpdfstring{simulate\+Tree()}{simulateTree()}} +{\footnotesize\ttfamily void simulate\+Tree (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{float}]{freqs\mbox{[}$\,$\mbox{]}, }\item[{float}]{kap, }\item[{int}]{L }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{treeSimulate_8h_af77eeafe78dc6291a2c5a0f9e0dea164}\label{treeSimulate_8h_af77eeafe78dc6291a2c5a0f9e0dea164}} +\index{tree\+Simulate.\+h@{tree\+Simulate.\+h}!string2tree@{string2tree}} +\index{string2tree@{string2tree}!tree\+Simulate.\+h@{tree\+Simulate.\+h}} +\subsubsection{\texorpdfstring{string2tree()}{string2tree()}} +{\footnotesize\ttfamily T\+Tree$\ast$ string2tree (\begin{DoxyParamCaption}\item[{char $\ast$}]{tree\+String }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6}\label{treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6}} +\index{tree\+Simulate.\+h@{tree\+Simulate.\+h}!tree2aln@{tree2aln}} +\index{tree2aln@{tree2aln}!tree\+Simulate.\+h@{tree\+Simulate.\+h}} +\subsubsection{\texorpdfstring{tree2aln()}{tree2aln()}} +{\footnotesize\ttfamily void tree2aln (\begin{DoxyParamCaption}\item[{T\+Tree $\ast$}]{tree, }\item[{struct \hyperlink{structaln}{aln} $\ast$}]{alignment\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=327pt]{treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph} +\end{center} +\end{figure} diff --git a/src/latex/treeSimulate_8h__dep__incl.md5 b/src/latex/treeSimulate_8h__dep__incl.md5 new file mode 100644 index 0000000..552b636 --- /dev/null +++ b/src/latex/treeSimulate_8h__dep__incl.md5 @@ -0,0 +1 @@ +47676f72e5d5ccfafb38bc5d847243e6 \ No newline at end of file diff --git a/src/latex/treeSimulate_8h__dep__incl.pdf b/src/latex/treeSimulate_8h__dep__incl.pdf new file mode 100644 index 0000000..dd2922b Binary files /dev/null and b/src/latex/treeSimulate_8h__dep__incl.pdf differ diff --git a/src/latex/treeSimulate_8h__incl.md5 b/src/latex/treeSimulate_8h__incl.md5 new file mode 100644 index 0000000..5670fb5 --- /dev/null +++ b/src/latex/treeSimulate_8h__incl.md5 @@ -0,0 +1 @@ +fd3af92757382aacbb3a2485fa42eb25 \ No newline at end of file diff --git a/src/latex/treeSimulate_8h__incl.pdf b/src/latex/treeSimulate_8h__incl.pdf new file mode 100644 index 0000000..41933f3 Binary files /dev/null and b/src/latex/treeSimulate_8h__incl.pdf differ diff --git a/src/latex/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 b/src/latex/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 new file mode 100644 index 0000000..e158b90 --- /dev/null +++ b/src/latex/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.md5 @@ -0,0 +1 @@ +be50194904c876e27467b90ec11fbea7 \ No newline at end of file diff --git a/src/latex/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.pdf b/src/latex/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.pdf new file mode 100644 index 0000000..4946025 Binary files /dev/null and b/src/latex/treeSimulate_8h_a3de1638db8b0f14df05b49f41bae2da6_cgraph.pdf differ diff --git a/src/latex/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 b/src/latex/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 new file mode 100644 index 0000000..b89094e --- /dev/null +++ b/src/latex/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.md5 @@ -0,0 +1 @@ +ee4c9c6a3ed76829e7adffb331081e10 \ No newline at end of file diff --git a/src/latex/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.pdf b/src/latex/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.pdf new file mode 100644 index 0000000..1ebb15f Binary files /dev/null and b/src/latex/treeSimulate_8h_a684681e84edaa63e768ec7ad1ff4884f_cgraph.pdf differ diff --git a/src/latex/utils_8c.tex b/src/latex/utils_8c.tex new file mode 100644 index 0000000..7c2c987 --- /dev/null +++ b/src/latex/utils_8c.tex @@ -0,0 +1,266 @@ +\hypertarget{utils_8c}{}\section{utils.\+c File Reference} +\label{utils_8c}\index{utils.\+c@{utils.\+c}} +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include $<$stdlib.\+h$>$}\newline +{\ttfamily \#include $<$errno.\+h$>$}\newline +{\ttfamily \#include $<$time.\+h$>$}\newline +{\ttfamily \#include $<$string.\+h$>$}\newline +{\ttfamily \#include \char`\"{}../config.\+h\char`\"{}}\newline +Include dependency graph for utils.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{utils_8c__incl} +\end{center} +\end{figure} +\subsection*{Macros} +\begin{DoxyCompactItemize} +\item +\#define \hyperlink{utils_8c_a5e151c615eda34903514212f05a5ccf8}{P\+R\+I\+V\+A\+TE}~static +\item +\#define \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} +\end{DoxyCompactItemize} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} void $\ast$ \hyperlink{utils_8c_a5dac704be118855d7c4dd3aa3bc31fc3}{space} (unsigned int size) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} void \hyperlink{utils_8c_a93e5a2447f559f7930054555a4252ccd}{nrerror} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char message\mbox{[}$\,$\mbox{]}) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} double \hyperlink{utils_8c_ab838605c6654ebdddc4ad19280855a25}{urn} (void) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} int \hyperlink{utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6}{int\+\_\+urn} (int from, int to) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} void \hyperlink{utils_8c_ae3ef8f02d94a4aeaa2050fb210acd3b0}{filecopy} (F\+I\+LE $\ast$from, F\+I\+LE $\ast$to) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} char $\ast$ \hyperlink{utils_8c_ade7ba8b8ed6a11e4c6f20e9e603e8799}{time\+\_\+stamp} (void) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} char $\ast$ \hyperlink{utils_8c_ab4ae5a543569ad8c331564963ea50f68}{random\+\_\+string} (int l, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char symbols\mbox{[}$\,$\mbox{]}) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} int \hyperlink{utils_8c_aad87a2700e9dcc28f48007ba3927f80e}{hamming} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$s1, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$s2) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} char $\ast$ \hyperlink{utils_8c_a39d4415a69dcce7a8301d38829101d50}{get\+\_\+line} (F\+I\+LE $\ast$fp) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} void $\ast$ \hyperlink{utils_8c_a38098f2a039377364b35c84560792ecb}{space} (unsigned size) +\item +void $\ast$ \hyperlink{utils_8c_a9037ada838835b1b9db41581a021b0c8}{xrealloc} (void $\ast$p, unsigned size) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} void \hyperlink{utils_8c_ade17b35078a34c6d26b09148c6f81f4d}{init\+\_\+rand} (void) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} char $\ast$ \hyperlink{utils_8c_aa3a18376e73375f7ccb0abc90d162a02}{pack\+\_\+structure} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$struc) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} char $\ast$ \hyperlink{utils_8c_aeda5e0295cdcacc9da2ae479db08396c}{unpack\+\_\+structure} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$packed) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} short $\ast$ \hyperlink{utils_8c_a84f42ca126d57c91364fde04b622b014}{make\+\_\+pair\+\_\+table} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$structure) +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} int \hyperlink{utils_8c_ad3b3262478312877d19d74950030de73}{bp\+\_\+distance} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$str1, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$str2) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +static char \hyperlink{utils_8c_af1b3bff1622925d03c9cd14c5f1a51bf}{rcsid} \mbox{[}$\,$\mbox{]} = \char`\"{}\$Id\+: utils.\+c,v 1.\+2 2007-\/07-\/22 20\+:58\+:48 wash Exp \$\char`\"{} +\item +\hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} unsigned short \hyperlink{utils_8c_a082c5a4e1e1e662b3452b3eb021291fb}{xsubi} \mbox{[}3\mbox{]} +\end{DoxyCompactItemize} + + +\subsection{Macro Definition Documentation} +\mbox{\Hypertarget{utils_8c_a5e151c615eda34903514212f05a5ccf8}\label{utils_8c_a5e151c615eda34903514212f05a5ccf8}} +\index{utils.\+c@{utils.\+c}!P\+R\+I\+V\+A\+TE@{P\+R\+I\+V\+A\+TE}} +\index{P\+R\+I\+V\+A\+TE@{P\+R\+I\+V\+A\+TE}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{P\+R\+I\+V\+A\+TE}{PRIVATE}} +{\footnotesize\ttfamily \#define P\+R\+I\+V\+A\+TE~static} + +\mbox{\Hypertarget{utils_8c_ad17d551e31d1828c68acf40684849b7e}\label{utils_8c_ad17d551e31d1828c68acf40684849b7e}} +\index{utils.\+c@{utils.\+c}!P\+U\+B\+L\+IC@{P\+U\+B\+L\+IC}} +\index{P\+U\+B\+L\+IC@{P\+U\+B\+L\+IC}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{P\+U\+B\+L\+IC}{PUBLIC}} +{\footnotesize\ttfamily \#define P\+U\+B\+L\+IC} + + + +\subsection{Function Documentation} +\mbox{\Hypertarget{utils_8c_ad3b3262478312877d19d74950030de73}\label{utils_8c_ad3b3262478312877d19d74950030de73}} +\index{utils.\+c@{utils.\+c}!bp\+\_\+distance@{bp\+\_\+distance}} +\index{bp\+\_\+distance@{bp\+\_\+distance}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{bp\+\_\+distance()}{bp\_distance()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} int bp\+\_\+distance (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{str1, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{str2 }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{utils_8c_ad3b3262478312877d19d74950030de73_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8c_ae3ef8f02d94a4aeaa2050fb210acd3b0}\label{utils_8c_ae3ef8f02d94a4aeaa2050fb210acd3b0}} +\index{utils.\+c@{utils.\+c}!filecopy@{filecopy}} +\index{filecopy@{filecopy}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{filecopy()}{filecopy()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} void filecopy (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{from, }\item[{F\+I\+LE $\ast$}]{to }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8c_a39d4415a69dcce7a8301d38829101d50}\label{utils_8c_a39d4415a69dcce7a8301d38829101d50}} +\index{utils.\+c@{utils.\+c}!get\+\_\+line@{get\+\_\+line}} +\index{get\+\_\+line@{get\+\_\+line}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{get\+\_\+line()}{get\_line()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} char $\ast$ get\+\_\+line (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{fp }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=296pt]{utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8c_aad87a2700e9dcc28f48007ba3927f80e}\label{utils_8c_aad87a2700e9dcc28f48007ba3927f80e}} +\index{utils.\+c@{utils.\+c}!hamming@{hamming}} +\index{hamming@{hamming}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{hamming()}{hamming()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} int hamming (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{s1, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{s2 }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8c_ade17b35078a34c6d26b09148c6f81f4d}\label{utils_8c_ade17b35078a34c6d26b09148c6f81f4d}} +\index{utils.\+c@{utils.\+c}!init\+\_\+rand@{init\+\_\+rand}} +\index{init\+\_\+rand@{init\+\_\+rand}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{init\+\_\+rand()}{init\_rand()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} void init\+\_\+rand (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6}\label{utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6}} +\index{utils.\+c@{utils.\+c}!int\+\_\+urn@{int\+\_\+urn}} +\index{int\+\_\+urn@{int\+\_\+urn}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{int\+\_\+urn()}{int\_urn()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} int int\+\_\+urn (\begin{DoxyParamCaption}\item[{int}]{from, }\item[{int}]{to }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=192pt]{utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8c_a84f42ca126d57c91364fde04b622b014}\label{utils_8c_a84f42ca126d57c91364fde04b622b014}} +\index{utils.\+c@{utils.\+c}!make\+\_\+pair\+\_\+table@{make\+\_\+pair\+\_\+table}} +\index{make\+\_\+pair\+\_\+table@{make\+\_\+pair\+\_\+table}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{make\+\_\+pair\+\_\+table()}{make\_pair\_table()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} short$\ast$ make\+\_\+pair\+\_\+table (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{structure }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=248pt]{utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8c_a93e5a2447f559f7930054555a4252ccd}\label{utils_8c_a93e5a2447f559f7930054555a4252ccd}} +\index{utils.\+c@{utils.\+c}!nrerror@{nrerror}} +\index{nrerror@{nrerror}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{nrerror()}{nrerror()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} void nrerror (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char}]{message\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8c_aa3a18376e73375f7ccb0abc90d162a02}\label{utils_8c_aa3a18376e73375f7ccb0abc90d162a02}} +\index{utils.\+c@{utils.\+c}!pack\+\_\+structure@{pack\+\_\+structure}} +\index{pack\+\_\+structure@{pack\+\_\+structure}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{pack\+\_\+structure()}{pack\_structure()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} char$\ast$ pack\+\_\+structure (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{struc }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=241pt]{utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8c_ab4ae5a543569ad8c331564963ea50f68}\label{utils_8c_ab4ae5a543569ad8c331564963ea50f68}} +\index{utils.\+c@{utils.\+c}!random\+\_\+string@{random\+\_\+string}} +\index{random\+\_\+string@{random\+\_\+string}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{random\+\_\+string()}{random\_string()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} char $\ast$ random\+\_\+string (\begin{DoxyParamCaption}\item[{int}]{l, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char}]{symbols\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=237pt]{utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8c_a5dac704be118855d7c4dd3aa3bc31fc3}\label{utils_8c_a5dac704be118855d7c4dd3aa3bc31fc3}} +\index{utils.\+c@{utils.\+c}!space@{space}} +\index{space@{space}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{space()}{space()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} void$\ast$ space (\begin{DoxyParamCaption}\item[{unsigned int}]{size }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8c_a38098f2a039377364b35c84560792ecb}\label{utils_8c_a38098f2a039377364b35c84560792ecb}} +\index{utils.\+c@{utils.\+c}!space@{space}} +\index{space@{space}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{space()}{space()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} void$\ast$ space (\begin{DoxyParamCaption}\item[{unsigned}]{size }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=203pt]{utils_8c_a38098f2a039377364b35c84560792ecb_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8c_ade7ba8b8ed6a11e4c6f20e9e603e8799}\label{utils_8c_ade7ba8b8ed6a11e4c6f20e9e603e8799}} +\index{utils.\+c@{utils.\+c}!time\+\_\+stamp@{time\+\_\+stamp}} +\index{time\+\_\+stamp@{time\+\_\+stamp}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{time\+\_\+stamp()}{time\_stamp()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} char $\ast$ time\+\_\+stamp (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8c_aeda5e0295cdcacc9da2ae479db08396c}\label{utils_8c_aeda5e0295cdcacc9da2ae479db08396c}} +\index{utils.\+c@{utils.\+c}!unpack\+\_\+structure@{unpack\+\_\+structure}} +\index{unpack\+\_\+structure@{unpack\+\_\+structure}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{unpack\+\_\+structure()}{unpack\_structure()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} char$\ast$ unpack\+\_\+structure (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{packed }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=251pt]{utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8c_ab838605c6654ebdddc4ad19280855a25}\label{utils_8c_ab838605c6654ebdddc4ad19280855a25}} +\index{utils.\+c@{utils.\+c}!urn@{urn}} +\index{urn@{urn}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{urn()}{urn()}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} double urn (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8c_a9037ada838835b1b9db41581a021b0c8}\label{utils_8c_a9037ada838835b1b9db41581a021b0c8}} +\index{utils.\+c@{utils.\+c}!xrealloc@{xrealloc}} +\index{xrealloc@{xrealloc}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{xrealloc()}{xrealloc()}} +{\footnotesize\ttfamily void$\ast$ xrealloc (\begin{DoxyParamCaption}\item[{void $\ast$}]{p, }\item[{unsigned}]{size }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=210pt]{utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph} +\end{center} +\end{figure} + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{utils_8c_af1b3bff1622925d03c9cd14c5f1a51bf}\label{utils_8c_af1b3bff1622925d03c9cd14c5f1a51bf}} +\index{utils.\+c@{utils.\+c}!rcsid@{rcsid}} +\index{rcsid@{rcsid}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{rcsid}{rcsid}} +{\footnotesize\ttfamily char rcsid\mbox{[}$\,$\mbox{]} = \char`\"{}\$Id\+: utils.\+c,v 1.\+2 2007-\/07-\/22 20\+:58\+:48 wash Exp \$\char`\"{}\hspace{0.3cm}{\ttfamily [static]}} + +\mbox{\Hypertarget{utils_8c_a082c5a4e1e1e662b3452b3eb021291fb}\label{utils_8c_a082c5a4e1e1e662b3452b3eb021291fb}} +\index{utils.\+c@{utils.\+c}!xsubi@{xsubi}} +\index{xsubi@{xsubi}!utils.\+c@{utils.\+c}} +\subsubsection{\texorpdfstring{xsubi}{xsubi}} +{\footnotesize\ttfamily \hyperlink{utils_8c_ad17d551e31d1828c68acf40684849b7e}{P\+U\+B\+L\+IC} unsigned short xsubi\mbox{[}3\mbox{]}} + diff --git a/src/latex/utils_8c__incl.md5 b/src/latex/utils_8c__incl.md5 new file mode 100644 index 0000000..20881ac --- /dev/null +++ b/src/latex/utils_8c__incl.md5 @@ -0,0 +1 @@ +813b661cb26ea52e4534ec3538ee1695 \ No newline at end of file diff --git a/src/latex/utils_8c__incl.pdf b/src/latex/utils_8c__incl.pdf new file mode 100644 index 0000000..e9f9eb3 Binary files /dev/null and b/src/latex/utils_8c__incl.pdf differ diff --git a/src/latex/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.md5 b/src/latex/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.md5 new file mode 100644 index 0000000..bc0ce3f --- /dev/null +++ b/src/latex/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.md5 @@ -0,0 +1 @@ +d86ebdee56d3cd91fa9623e593bcaed0 \ No newline at end of file diff --git a/src/latex/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.pdf b/src/latex/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.pdf new file mode 100644 index 0000000..68db6c6 Binary files /dev/null and b/src/latex/utils_8c_a38098f2a039377364b35c84560792ecb_cgraph.pdf differ diff --git a/src/latex/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.md5 b/src/latex/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.md5 new file mode 100644 index 0000000..83d48fb --- /dev/null +++ b/src/latex/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.md5 @@ -0,0 +1 @@ +819635774a032553e2936c9fb85a0b54 \ No newline at end of file diff --git a/src/latex/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.pdf b/src/latex/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.pdf new file mode 100644 index 0000000..53c2011 Binary files /dev/null and b/src/latex/utils_8c_a39d4415a69dcce7a8301d38829101d50_cgraph.pdf differ diff --git a/src/latex/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.md5 b/src/latex/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.md5 new file mode 100644 index 0000000..d123fca --- /dev/null +++ b/src/latex/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.md5 @@ -0,0 +1 @@ +284c449463005a44f508f1702ad2cf35 \ No newline at end of file diff --git a/src/latex/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.pdf b/src/latex/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.pdf new file mode 100644 index 0000000..b730cbc Binary files /dev/null and b/src/latex/utils_8c_a84f42ca126d57c91364fde04b622b014_cgraph.pdf differ diff --git a/src/latex/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 b/src/latex/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 new file mode 100644 index 0000000..38b8e99 --- /dev/null +++ b/src/latex/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 @@ -0,0 +1 @@ +6b90224fe78e7c2baae11892dce94c16 \ No newline at end of file diff --git a/src/latex/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.pdf b/src/latex/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.pdf new file mode 100644 index 0000000..9bd6782 Binary files /dev/null and b/src/latex/utils_8c_a9037ada838835b1b9db41581a021b0c8_cgraph.pdf differ diff --git a/src/latex/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.md5 b/src/latex/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.md5 new file mode 100644 index 0000000..fe3595f --- /dev/null +++ b/src/latex/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.md5 @@ -0,0 +1 @@ +5744166f06b3b27afc3e28ba5f3f210a \ No newline at end of file diff --git a/src/latex/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.pdf b/src/latex/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.pdf new file mode 100644 index 0000000..7fe2de1 Binary files /dev/null and b/src/latex/utils_8c_aa3a18376e73375f7ccb0abc90d162a02_cgraph.pdf differ diff --git a/src/latex/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.md5 b/src/latex/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.md5 new file mode 100644 index 0000000..cf1b797 --- /dev/null +++ b/src/latex/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.md5 @@ -0,0 +1 @@ +c16e467700b7eff84c112a4e51e2ec1c \ No newline at end of file diff --git a/src/latex/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.pdf b/src/latex/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.pdf new file mode 100644 index 0000000..a37cdfb Binary files /dev/null and b/src/latex/utils_8c_ab4ae5a543569ad8c331564963ea50f68_cgraph.pdf differ diff --git a/src/latex/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.md5 b/src/latex/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.md5 new file mode 100644 index 0000000..71eb067 --- /dev/null +++ b/src/latex/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.md5 @@ -0,0 +1 @@ +ed2953e033addcae8da7fb0758a618dc \ No newline at end of file diff --git a/src/latex/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.pdf b/src/latex/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.pdf new file mode 100644 index 0000000..e688bd9 Binary files /dev/null and b/src/latex/utils_8c_ad3b3262478312877d19d74950030de73_cgraph.pdf differ diff --git a/src/latex/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.md5 b/src/latex/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.md5 new file mode 100644 index 0000000..7c1292a --- /dev/null +++ b/src/latex/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.md5 @@ -0,0 +1 @@ +00fa08b007e77236fbbadc9beecabcc0 \ No newline at end of file diff --git a/src/latex/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.pdf b/src/latex/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.pdf new file mode 100644 index 0000000..ec1cf1e Binary files /dev/null and b/src/latex/utils_8c_aeda5e0295cdcacc9da2ae479db08396c_cgraph.pdf differ diff --git a/src/latex/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.md5 b/src/latex/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.md5 new file mode 100644 index 0000000..d66e227 --- /dev/null +++ b/src/latex/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.md5 @@ -0,0 +1 @@ +b6c94bfcdef94b1c36740ce8805530a3 \ No newline at end of file diff --git a/src/latex/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.pdf b/src/latex/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.pdf new file mode 100644 index 0000000..242e4bd Binary files /dev/null and b/src/latex/utils_8c_af0a9bc3a6894eea7895d5cdf825bccd6_cgraph.pdf differ diff --git a/src/latex/utils_8h.tex b/src/latex/utils_8h.tex new file mode 100644 index 0000000..f53c626 --- /dev/null +++ b/src/latex/utils_8h.tex @@ -0,0 +1,214 @@ +\hypertarget{utils_8h}{}\section{utils.\+h File Reference} +\label{utils_8h}\index{utils.\+h@{utils.\+h}} +This graph shows which files directly or indirectly include this file\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=234pt]{utils_8h__dep__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +void $\ast$ \hyperlink{utils_8h_ad7e1e137b3bf1f7108933d302a7f0177}{space} (unsigned size) +\item +void $\ast$ \hyperlink{utils_8h_a9037ada838835b1b9db41581a021b0c8}{xrealloc} (void $\ast$p, unsigned size) +\item +void \hyperlink{utils_8h_a127ce946e56b5a5773781cabe68e38c5}{nrerror} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char message\mbox{[}$\,$\mbox{]}) +\item +void \hyperlink{utils_8h_a8aaa6d9be6f803f496d9b97375c371f3}{init\+\_\+rand} (void) +\item +double \hyperlink{utils_8h_aaa328491c84996e445d027fde9800f2e}{urn} (void) +\item +int \hyperlink{utils_8h_a68ff0849d44f62fe491800378a5ffcb4}{int\+\_\+urn} (int from, int to) +\item +void \hyperlink{utils_8h_ab213334ce977b6d21611cdea6b80c3bf}{filecopy} (F\+I\+LE $\ast$from, F\+I\+LE $\ast$to) +\item +char $\ast$ \hyperlink{utils_8h_a7afeb906cb36e9d77379eabc6907ac46}{time\+\_\+stamp} (void) +\item +char $\ast$ \hyperlink{utils_8h_a1b95eac365a021572e1c37e5993a89be}{random\+\_\+string} (int l, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char symbols\mbox{[}$\,$\mbox{]}) +\item +int \hyperlink{utils_8h_ad9dc7bfc9aa664dc6698f17ce07fc7e7}{hamming} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$s1, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$s2) +\item +char $\ast$ \hyperlink{utils_8h_a90fb7a370255e405c5384c4332bce847}{get\+\_\+line} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} F\+I\+LE $\ast$fp) +\item +char $\ast$ \hyperlink{utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced}{pack\+\_\+structure} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$struc) +\item +char $\ast$ \hyperlink{utils_8h_a071c6921efe1eb974f115ee6fefa3c39}{unpack\+\_\+structure} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$packed) +\item +short $\ast$ \hyperlink{utils_8h_a89c32307ee50a0026f4a3131fac0845a}{make\+\_\+pair\+\_\+table} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$structure) +\item +int \hyperlink{utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db}{bp\+\_\+distance} (\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$str1, \hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$str2) +\end{DoxyCompactItemize} +\subsection*{Variables} +\begin{DoxyCompactItemize} +\item +unsigned short \hyperlink{utils_8h_af9a866c8417afda7368bbac939ab3c47}{xsubi} \mbox{[}3\mbox{]} +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db}\label{utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db}} +\index{utils.\+h@{utils.\+h}!bp\+\_\+distance@{bp\+\_\+distance}} +\index{bp\+\_\+distance@{bp\+\_\+distance}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{bp\+\_\+distance()}{bp\_distance()}} +{\footnotesize\ttfamily int bp\+\_\+distance (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{str1, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{str2 }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=350pt]{utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8h_ab213334ce977b6d21611cdea6b80c3bf}\label{utils_8h_ab213334ce977b6d21611cdea6b80c3bf}} +\index{utils.\+h@{utils.\+h}!filecopy@{filecopy}} +\index{filecopy@{filecopy}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{filecopy()}{filecopy()}} +{\footnotesize\ttfamily void filecopy (\begin{DoxyParamCaption}\item[{F\+I\+LE $\ast$}]{from, }\item[{F\+I\+LE $\ast$}]{to }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8h_a90fb7a370255e405c5384c4332bce847}\label{utils_8h_a90fb7a370255e405c5384c4332bce847}} +\index{utils.\+h@{utils.\+h}!get\+\_\+line@{get\+\_\+line}} +\index{get\+\_\+line@{get\+\_\+line}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{get\+\_\+line()}{get\_line()}} +{\footnotesize\ttfamily char$\ast$ get\+\_\+line (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} F\+I\+LE $\ast$}]{fp }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8h_ad9dc7bfc9aa664dc6698f17ce07fc7e7}\label{utils_8h_ad9dc7bfc9aa664dc6698f17ce07fc7e7}} +\index{utils.\+h@{utils.\+h}!hamming@{hamming}} +\index{hamming@{hamming}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{hamming()}{hamming()}} +{\footnotesize\ttfamily int hamming (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{s1, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{s2 }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8h_a8aaa6d9be6f803f496d9b97375c371f3}\label{utils_8h_a8aaa6d9be6f803f496d9b97375c371f3}} +\index{utils.\+h@{utils.\+h}!init\+\_\+rand@{init\+\_\+rand}} +\index{init\+\_\+rand@{init\+\_\+rand}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{init\+\_\+rand()}{init\_rand()}} +{\footnotesize\ttfamily void init\+\_\+rand (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8h_a68ff0849d44f62fe491800378a5ffcb4}\label{utils_8h_a68ff0849d44f62fe491800378a5ffcb4}} +\index{utils.\+h@{utils.\+h}!int\+\_\+urn@{int\+\_\+urn}} +\index{int\+\_\+urn@{int\+\_\+urn}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{int\+\_\+urn()}{int\_urn()}} +{\footnotesize\ttfamily int int\+\_\+urn (\begin{DoxyParamCaption}\item[{int}]{from, }\item[{int}]{to }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=192pt]{utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8h_a89c32307ee50a0026f4a3131fac0845a}\label{utils_8h_a89c32307ee50a0026f4a3131fac0845a}} +\index{utils.\+h@{utils.\+h}!make\+\_\+pair\+\_\+table@{make\+\_\+pair\+\_\+table}} +\index{make\+\_\+pair\+\_\+table@{make\+\_\+pair\+\_\+table}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{make\+\_\+pair\+\_\+table()}{make\_pair\_table()}} +{\footnotesize\ttfamily short$\ast$ make\+\_\+pair\+\_\+table (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{structure }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=248pt]{utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8h_a127ce946e56b5a5773781cabe68e38c5}\label{utils_8h_a127ce946e56b5a5773781cabe68e38c5}} +\index{utils.\+h@{utils.\+h}!nrerror@{nrerror}} +\index{nrerror@{nrerror}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{nrerror()}{nrerror()}} +{\footnotesize\ttfamily void nrerror (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char}]{message\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced}\label{utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced}} +\index{utils.\+h@{utils.\+h}!pack\+\_\+structure@{pack\+\_\+structure}} +\index{pack\+\_\+structure@{pack\+\_\+structure}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{pack\+\_\+structure()}{pack\_structure()}} +{\footnotesize\ttfamily char$\ast$ pack\+\_\+structure (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{struc }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=241pt]{utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8h_a1b95eac365a021572e1c37e5993a89be}\label{utils_8h_a1b95eac365a021572e1c37e5993a89be}} +\index{utils.\+h@{utils.\+h}!random\+\_\+string@{random\+\_\+string}} +\index{random\+\_\+string@{random\+\_\+string}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{random\+\_\+string()}{random\_string()}} +{\footnotesize\ttfamily char$\ast$ random\+\_\+string (\begin{DoxyParamCaption}\item[{int}]{l, }\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char}]{symbols\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=237pt]{utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8h_ad7e1e137b3bf1f7108933d302a7f0177}\label{utils_8h_ad7e1e137b3bf1f7108933d302a7f0177}} +\index{utils.\+h@{utils.\+h}!space@{space}} +\index{space@{space}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{space()}{space()}} +{\footnotesize\ttfamily void$\ast$ space (\begin{DoxyParamCaption}\item[{unsigned}]{size }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=203pt]{utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8h_a7afeb906cb36e9d77379eabc6907ac46}\label{utils_8h_a7afeb906cb36e9d77379eabc6907ac46}} +\index{utils.\+h@{utils.\+h}!time\+\_\+stamp@{time\+\_\+stamp}} +\index{time\+\_\+stamp@{time\+\_\+stamp}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{time\+\_\+stamp()}{time\_stamp()}} +{\footnotesize\ttfamily char$\ast$ time\+\_\+stamp (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8h_a071c6921efe1eb974f115ee6fefa3c39}\label{utils_8h_a071c6921efe1eb974f115ee6fefa3c39}} +\index{utils.\+h@{utils.\+h}!unpack\+\_\+structure@{unpack\+\_\+structure}} +\index{unpack\+\_\+structure@{unpack\+\_\+structure}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{unpack\+\_\+structure()}{unpack\_structure()}} +{\footnotesize\ttfamily char$\ast$ unpack\+\_\+structure (\begin{DoxyParamCaption}\item[{\hyperlink{getopt_8c_a2c212835823e3c54a8ab6d95c652660e}{const} char $\ast$}]{packed }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=251pt]{utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph} +\end{center} +\end{figure} +\mbox{\Hypertarget{utils_8h_aaa328491c84996e445d027fde9800f2e}\label{utils_8h_aaa328491c84996e445d027fde9800f2e}} +\index{utils.\+h@{utils.\+h}!urn@{urn}} +\index{urn@{urn}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{urn()}{urn()}} +{\footnotesize\ttfamily double urn (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{utils_8h_a9037ada838835b1b9db41581a021b0c8}\label{utils_8h_a9037ada838835b1b9db41581a021b0c8}} +\index{utils.\+h@{utils.\+h}!xrealloc@{xrealloc}} +\index{xrealloc@{xrealloc}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{xrealloc()}{xrealloc()}} +{\footnotesize\ttfamily void$\ast$ xrealloc (\begin{DoxyParamCaption}\item[{void $\ast$}]{p, }\item[{unsigned}]{size }\end{DoxyParamCaption})} + +Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=210pt]{utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph} +\end{center} +\end{figure} + + +\subsection{Variable Documentation} +\mbox{\Hypertarget{utils_8h_af9a866c8417afda7368bbac939ab3c47}\label{utils_8h_af9a866c8417afda7368bbac939ab3c47}} +\index{utils.\+h@{utils.\+h}!xsubi@{xsubi}} +\index{xsubi@{xsubi}!utils.\+h@{utils.\+h}} +\subsubsection{\texorpdfstring{xsubi}{xsubi}} +{\footnotesize\ttfamily unsigned short xsubi\mbox{[}3\mbox{]}} + diff --git a/src/latex/utils_8h__dep__incl.md5 b/src/latex/utils_8h__dep__incl.md5 new file mode 100644 index 0000000..8699642 --- /dev/null +++ b/src/latex/utils_8h__dep__incl.md5 @@ -0,0 +1 @@ +26cd890f8641cbc181ee562b934561df \ No newline at end of file diff --git a/src/latex/utils_8h__dep__incl.pdf b/src/latex/utils_8h__dep__incl.pdf new file mode 100644 index 0000000..51eb12a Binary files /dev/null and b/src/latex/utils_8h__dep__incl.pdf differ diff --git a/src/latex/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.md5 b/src/latex/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.md5 new file mode 100644 index 0000000..5a439c4 --- /dev/null +++ b/src/latex/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.md5 @@ -0,0 +1 @@ +3633b10cf6c249586eb1ef3e9fe47ffe \ No newline at end of file diff --git a/src/latex/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.pdf b/src/latex/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.pdf new file mode 100644 index 0000000..ec1cf1e Binary files /dev/null and b/src/latex/utils_8h_a071c6921efe1eb974f115ee6fefa3c39_cgraph.pdf differ diff --git a/src/latex/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.md5 b/src/latex/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.md5 new file mode 100644 index 0000000..755b141 --- /dev/null +++ b/src/latex/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.md5 @@ -0,0 +1 @@ +9a5d528b137e2e0807b75774d73a3dd7 \ No newline at end of file diff --git a/src/latex/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.pdf b/src/latex/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.pdf new file mode 100644 index 0000000..a37cdfb Binary files /dev/null and b/src/latex/utils_8h_a1b95eac365a021572e1c37e5993a89be_cgraph.pdf differ diff --git a/src/latex/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.md5 b/src/latex/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.md5 new file mode 100644 index 0000000..b515706 --- /dev/null +++ b/src/latex/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.md5 @@ -0,0 +1 @@ +b95c8a39dac79f57f2bea01fb2ae6191 \ No newline at end of file diff --git a/src/latex/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.pdf b/src/latex/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.pdf new file mode 100644 index 0000000..242e4bd Binary files /dev/null and b/src/latex/utils_8h_a68ff0849d44f62fe491800378a5ffcb4_cgraph.pdf differ diff --git a/src/latex/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.md5 b/src/latex/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.md5 new file mode 100644 index 0000000..71eb067 --- /dev/null +++ b/src/latex/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.md5 @@ -0,0 +1 @@ +ed2953e033addcae8da7fb0758a618dc \ No newline at end of file diff --git a/src/latex/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.pdf b/src/latex/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.pdf new file mode 100644 index 0000000..e688bd9 Binary files /dev/null and b/src/latex/utils_8h_a6ebbcd29a754f0e4f1a66d1fd84184db_cgraph.pdf differ diff --git a/src/latex/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.md5 b/src/latex/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.md5 new file mode 100644 index 0000000..72722e1 --- /dev/null +++ b/src/latex/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.md5 @@ -0,0 +1 @@ +29d7ed7b92a7fdd807997b2f66c7cbfe \ No newline at end of file diff --git a/src/latex/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.pdf b/src/latex/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.pdf new file mode 100644 index 0000000..b730cbc Binary files /dev/null and b/src/latex/utils_8h_a89c32307ee50a0026f4a3131fac0845a_cgraph.pdf differ diff --git a/src/latex/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 b/src/latex/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 new file mode 100644 index 0000000..e4ef4cc --- /dev/null +++ b/src/latex/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.md5 @@ -0,0 +1 @@ +8e705e6fb2013aa82b5916b9877b3b2c \ No newline at end of file diff --git a/src/latex/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.pdf b/src/latex/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.pdf new file mode 100644 index 0000000..9bd6782 Binary files /dev/null and b/src/latex/utils_8h_a9037ada838835b1b9db41581a021b0c8_cgraph.pdf differ diff --git a/src/latex/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.md5 b/src/latex/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.md5 new file mode 100644 index 0000000..45d7aeb --- /dev/null +++ b/src/latex/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.md5 @@ -0,0 +1 @@ +02a9b9b27f2b7424bf252faac12afa67 \ No newline at end of file diff --git a/src/latex/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.pdf b/src/latex/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.pdf new file mode 100644 index 0000000..7fe2de1 Binary files /dev/null and b/src/latex/utils_8h_ac6dfa5e22928c087c6e09ff0054a7ced_cgraph.pdf differ diff --git a/src/latex/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.md5 b/src/latex/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.md5 new file mode 100644 index 0000000..c5057ab --- /dev/null +++ b/src/latex/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.md5 @@ -0,0 +1 @@ +e91478b1eecc312987e8583da63265d3 \ No newline at end of file diff --git a/src/latex/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.pdf b/src/latex/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.pdf new file mode 100644 index 0000000..68db6c6 Binary files /dev/null and b/src/latex/utils_8h_ad7e1e137b3bf1f7108933d302a7f0177_cgraph.pdf differ diff --git a/src/latex/weight_8c.tex b/src/latex/weight_8c.tex new file mode 100644 index 0000000..9dba634 --- /dev/null +++ b/src/latex/weight_8c.tex @@ -0,0 +1,48 @@ +\hypertarget{weight_8c}{}\section{weight.\+c File Reference} +\label{weight_8c}\index{weight.\+c@{weight.\+c}} +{\ttfamily \#include $<$stdio.\+h$>$}\newline +{\ttfamily \#include $<$strings.\+h$>$}\newline +{\ttfamily \#include $<$malloc.\+h$>$}\newline +{\ttfamily \#include $<$math.\+h$>$}\newline +Include dependency graph for weight.\+c\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=335pt]{weight_8c__incl} +\end{center} +\end{figure} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +float $\ast$ \hyperlink{weight_8c_a0c41284822a5ce5bfea7cd745ac71edc}{weights} (float $\ast$$\ast$D, int N) +\item +int \hyperlink{weight_8c_a938fd9f0d302e85abaed502179b51275}{linsys} (float $\ast$$\ast$a, float $\ast$b, int N) +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{weight_8c_a938fd9f0d302e85abaed502179b51275}\label{weight_8c_a938fd9f0d302e85abaed502179b51275}} +\index{weight.\+c@{weight.\+c}!linsys@{linsys}} +\index{linsys@{linsys}!weight.\+c@{weight.\+c}} +\subsubsection{\texorpdfstring{linsys()}{linsys()}} +{\footnotesize\ttfamily int linsys (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$}]{a, }\item[{float $\ast$}]{b, }\item[{int}]{N }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{weight_8c_a0c41284822a5ce5bfea7cd745ac71edc}\label{weight_8c_a0c41284822a5ce5bfea7cd745ac71edc}} +\index{weight.\+c@{weight.\+c}!weights@{weights}} +\index{weights@{weights}!weight.\+c@{weight.\+c}} +\subsubsection{\texorpdfstring{weights()}{weights()}} +{\footnotesize\ttfamily float$\ast$ weights (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$}]{D, }\item[{int}]{N }\end{DoxyParamCaption})} + +working arrays + +call Gauss elimination + +normalize Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=208pt]{weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph} +\end{center} +\end{figure} diff --git a/src/latex/weight_8c__incl.md5 b/src/latex/weight_8c__incl.md5 new file mode 100644 index 0000000..9110ed3 --- /dev/null +++ b/src/latex/weight_8c__incl.md5 @@ -0,0 +1 @@ +07c5716e3cc657ee68ab6f0df246d37a \ No newline at end of file diff --git a/src/latex/weight_8c__incl.pdf b/src/latex/weight_8c__incl.pdf new file mode 100644 index 0000000..8707fad Binary files /dev/null and b/src/latex/weight_8c__incl.pdf differ diff --git a/src/latex/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.md5 b/src/latex/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.md5 new file mode 100644 index 0000000..4cd99d5 --- /dev/null +++ b/src/latex/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.md5 @@ -0,0 +1 @@ +d35e447819ff062a738d1f690427c181 \ No newline at end of file diff --git a/src/latex/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.pdf b/src/latex/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.pdf new file mode 100644 index 0000000..d87182f Binary files /dev/null and b/src/latex/weight_8c_a0c41284822a5ce5bfea7cd745ac71edc_cgraph.pdf differ diff --git a/src/latex/weight_8h.tex b/src/latex/weight_8h.tex new file mode 100644 index 0000000..2820b1b --- /dev/null +++ b/src/latex/weight_8h.tex @@ -0,0 +1,36 @@ +\hypertarget{weight_8h}{}\section{weight.\+h File Reference} +\label{weight_8h}\index{weight.\+h@{weight.\+h}} +\subsection*{Functions} +\begin{DoxyCompactItemize} +\item +int \hyperlink{weight_8h_a938fd9f0d302e85abaed502179b51275}{linsys} (float $\ast$$\ast$a, float $\ast$b, int N) +\item +double $\ast$ \hyperlink{weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385}{weights} (float $\ast$$\ast$D, int N) +\end{DoxyCompactItemize} + + +\subsection{Function Documentation} +\mbox{\Hypertarget{weight_8h_a938fd9f0d302e85abaed502179b51275}\label{weight_8h_a938fd9f0d302e85abaed502179b51275}} +\index{weight.\+h@{weight.\+h}!linsys@{linsys}} +\index{linsys@{linsys}!weight.\+h@{weight.\+h}} +\subsubsection{\texorpdfstring{linsys()}{linsys()}} +{\footnotesize\ttfamily int linsys (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$}]{a, }\item[{float $\ast$}]{b, }\item[{int}]{N }\end{DoxyParamCaption})} + +\mbox{\Hypertarget{weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385}\label{weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385}} +\index{weight.\+h@{weight.\+h}!weights@{weights}} +\index{weights@{weights}!weight.\+h@{weight.\+h}} +\subsubsection{\texorpdfstring{weights()}{weights()}} +{\footnotesize\ttfamily double$\ast$ weights (\begin{DoxyParamCaption}\item[{float $\ast$$\ast$}]{D, }\item[{int}]{N }\end{DoxyParamCaption})} + +working arrays + +call Gauss elimination + +normalize Here is the call graph for this function\+: +\nopagebreak +\begin{figure}[H] +\begin{center} +\leavevmode +\includegraphics[width=208pt]{weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph} +\end{center} +\end{figure} diff --git a/src/latex/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.md5 b/src/latex/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.md5 new file mode 100644 index 0000000..4cd99d5 --- /dev/null +++ b/src/latex/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.md5 @@ -0,0 +1 @@ +d35e447819ff062a738d1f690427c181 \ No newline at end of file diff --git a/src/latex/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.pdf b/src/latex/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.pdf new file mode 100644 index 0000000..d87182f Binary files /dev/null and b/src/latex/weight_8h_a2d3bb1f6e0b7a4b2c564e8843f51e385_cgraph.pdf differ diff --git a/src/old_Makefile b/src/old_Makefile new file mode 100644 index 0000000..8b868be --- /dev/null +++ b/src/old_Makefile @@ -0,0 +1,612 @@ +# Makefile.in generated by automake 1.15.1 from Makefile.am. +# src/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2017 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/RNAcode +pkgincludedir = $(includedir)/RNAcode +pkglibdir = $(libdir)/RNAcode +pkglibexecdir = $(libexecdir)/RNAcode +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +bin_PROGRAMS = RNAcode$(EXEEXT) +subdir = src +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +PROGRAMS = $(bin_PROGRAMS) +am_RNAcode_OBJECTS = RNAcode.$(OBJEXT) rnaz_utils.$(OBJEXT) \ + utils.$(OBJEXT) cmdline.$(OBJEXT) treeSimulate.$(OBJEXT) \ + treeML.$(OBJEXT) code.$(OBJEXT) postscript.$(OBJEXT) \ + extreme_fit.$(OBJEXT) score.$(OBJEXT) misc.$(OBJEXT) +RNAcode_OBJECTS = $(am_RNAcode_OBJECTS) +RNAcode_LDADD = $(LDADD) +RNAcode_DEPENDENCIES = +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I. -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(RNAcode_SOURCES) +DIST_SOURCES = $(RNAcode_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} /home/work/projects/RNAcode/missing aclocal-1.15 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 1 +AUTOCONF = ${SHELL} /home/work/projects/RNAcode/missing autoconf +AUTOHEADER = ${SHELL} /home/work/projects/RNAcode/missing autoheader +AUTOMAKE = ${SHELL} /home/work/projects/RNAcode/missing automake-1.15 +AWK = gawk +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -g -O2 +CPP = gcc -E +CPPFLAGS = +CXX = g++ +CXXDEPMODE = depmode=gcc3 +CXXFLAGS = -g -O2 +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +EXEEXT = +GREP = /bin/grep +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +ISODATE = 2020-08-24 +LDFLAGS = +LIBOBJS = +LIBS = +LTLIBOBJS = +MAKEINFO = ${SHELL} /home/work/projects/RNAcode/missing makeinfo +MKDIR_P = /bin/mkdir -p +OBJEXT = o +PACKAGE = RNAcode +PACKAGE_BUGREPORT = wash@mit.edu +PACKAGE_NAME = RNAcode +PACKAGE_STRING = RNAcode 0.3 +PACKAGE_TARNAME = RNAcode +PACKAGE_URL = +PACKAGE_VERSION = 0.3 +PATH_SEPARATOR = : +RANLIB = ranlib +SET_MAKE = +SHELL = /bin/bash +STRIP = +VERSION = 0.3 +abs_builddir = /home/work/projects/RNAcode/src +abs_srcdir = /home/work/projects/RNAcode/src +abs_top_builddir = /home/work/projects/RNAcode +abs_top_srcdir = /home/work/projects/RNAcode +ac_ct_CC = gcc +ac_ct_CXX = g++ +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build_alias = +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host_alias = +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /home/work/projects/RNAcode/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../ +top_builddir = .. +top_srcdir = .. +AM_CPPFLAGS = -I../phyml3 -I../seqgen -I../levmar -I../librna +RNAcode_SOURCES = \ + RNAcode.c \ + RNAcode.h \ + rnaz_utils.h \ + rnaz_utils.c \ + utils.h \ + utils.c \ + cmdline.c \ + cmdline.h \ + treeSimulate.c \ + treeSimulate.h \ + treeML.h \ + treeML.c \ + code.c \ + postscript.c \ + code.h \ + extreme_fit.c \ + extreme_fit.h \ + postscript.h \ + score.c \ + score.h \ + misc.c \ + misc.h + +LDADD = \ + -L../levmar -llevmar \ + -L../seqgen -lseqgen \ + -L../librna -lRNA \ + -lm\ + -L../phyml -lPHYML \ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p \ + ; then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' \ + -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' \ + `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +RNAcode$(EXEEXT): $(RNAcode_OBJECTS) $(RNAcode_DEPENDENCIES) $(EXTRA_RNAcode_DEPENDENCIES) + @rm -f RNAcode$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(RNAcode_OBJECTS) $(RNAcode_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +include ./$(DEPDIR)/RNAcode.Po +include ./$(DEPDIR)/cmdline.Po +include ./$(DEPDIR)/code.Po +include ./$(DEPDIR)/extreme_fit.Po +include ./$(DEPDIR)/misc.Po +include ./$(DEPDIR)/postscript.Po +include ./$(DEPDIR)/rnaz_utils.Po +include ./$(DEPDIR)/score.Po +include ./$(DEPDIR)/treeML.Po +include ./$(DEPDIR)/treeSimulate.Po +include ./$(DEPDIR)/utils.Po + +.c.o: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ $< + +.c.obj: + $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` + $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \ + clean-binPROGRAMS clean-generic cscopelist-am ctags ctags-am \ + distclean distclean-compile distclean-generic distclean-tags \ + distdir dvi dvi-am html html-am info info-am install \ + install-am install-binPROGRAMS install-data install-data-am \ + install-dvi install-dvi-am install-exec install-exec-am \ + install-html install-html-am install-info install-info-am \ + install-man install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \ + ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-binPROGRAMS + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/old_treeML.c b/src/old_treeML.c new file mode 100644 index 0000000..a3f8c89 --- /dev/null +++ b/src/old_treeML.c @@ -0,0 +1,226 @@ +/* Copyright 2009, Stefan Washietl + + This file is part of RNAcode. + + RNAcode is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + RNAcode 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with RNAcode. If not, see . */ + + +//#include "spr.h" +#include "utilities.h" +#include "lk.h" +#include "optimiz.h" +#include "bionj.h" +#include "models.h" +#include "free.h" +#include "options.h" +#include "simu.h" +#include "eigen.h" +#include "pars.h" +#include "alrt.h" +#include "rnaz_utils.h" +#include "make.h" + +seq **Get_Seq_local(seq**, option *io, int rw); + +int treeML(const struct aln *alignment[], char** treeString, float* kappa){ + + int i; + seq **data; + allseq *alldata; + option *io; + arbre *tree; + int n_otu; + matrix *mat; + model *mod; + time_t t_beg,t_end; + div_t hour,min; + phydbl best_lnL; + int L,r_seed; + + /* Initialize data structures */ + + tree = NULL; + mod = NULL; + data = NULL; + best_lnL = UNLIKELY; + + + io = (option *)Make_Input(); + Set_Defaults_Input(io); + Set_Defaults_Model(io->mod); + Set_Defaults_Optimiz(io->mod->s_opt); + r_seed = time(NULL); + srand(r_seed); + Make_Model_Complete(io->mod); + mod = io->mod; + + + /* Set options */ + + io->mod->datatype=NT; /* Nucleotides not amino acids */ + io->mod->s_opt->print=0; /* Shut of verbose output */ + io->mod->s_opt->opt_topo = 0; /* Do not optimize topology */ + io->mod->s_opt->opt_bl = 1; /* Optimize branch lengths*/ + io->mod->s_opt->opt_num_param = 1; /* Optimize kappa, initialize with 4.0*/ + io->mod->s_opt->opt_kappa = 1; + io->mod->kappa = 4.0; + + /* Manually fill data structure with the alignment */ + + n_otu = 0; + + L=strlen(alignment[0]->seq); + for (n_otu=0; alignment[n_otu]!=NULL; n_otu++); + + io->mod->n_otu=n_otu; + + data = (seq **)mCalloc(n_otu,sizeof(seq *)); + + for (i=0;ilen = L; + data[i]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); + strcpy(data[i]->name,alignment[i]->name); + data[i]->state = (char *)mCalloc(T_MAX_SEQ,sizeof(char)); + strcpy(data[i]->state,alignment[i]->seq); + data[i]->is_ambigu = NULL; + } + + /* Call modified version of Get_Seq, that does some processing */ + data=Get_Seq_local(data, io, 0); + alldata = Compact_Seq(data,io); + Free_Seq(data,alldata->n_otu); + Check_Ambiguities(alldata,io->mod->datatype,io->mod->stepsize); + if (Init_Model(alldata,mod)!=1){ + return(0); + } + + /* Calculate pairwise distances and make BIONJ tree*/ + mat = ML_Dist(alldata,mod); + Fill_Missing_Dist(mat); + mat->tree = Make_Tree_From_Scratch(alldata->n_otu,alldata); + + + // bionj.h + + Bionj(mat); + tree = mat->tree; + tree->mat = mat; + tree->mod = mod; + tree->io = io; + tree->data = alldata; + tree->both_sides = 1; + tree->n_pattern = tree->data->crunch_len/tree->mod->stepsize; + time(&t_beg); + time(&(tree->t_beg)); + + /* Prepare for optimization and optimize */ + + Fill_Dir_Table(tree); + Update_Dirs(tree); + Make_Tree_4_Pars(tree,alldata,alldata->init_len); + Make_Tree_4_Lk(tree,alldata,alldata->init_len); + tree->triplet_struct = Make_Triplet_Struct(mod); + Br_Len_Not_Involving_Invar(tree); + Order_Tree_CSeq(tree,alldata); + Round_Optimize(tree,tree->data); + + //treeString=(char *)mCalloc(T_MAX_LINE,sizeof(char)); + + *treeString=Write_Tree(tree); + *kappa=io->mod->kappa; + + Free_Mat(tree->mat); + Free_Triplet(tree->triplet_struct); + Free_Tree_Pars(tree); + Free_Tree_Lk(tree); + Free_Tree(tree); + + Free_Cseq(alldata); + + Free_Model(mod); + + Free_Input(io); + + return(1); + +} + +/* Function from Seqgen (c) Andrew Rambaut & Nick Grassly */ + +seq **Get_Seq_local(seq** data, option *io, int rw) +{ + int i,j; + char **buff; + int n_unkn,n_removed,pos; + int *remove; + + +/* rewind(fp_seq); */ + + + if(data) + { + buff = (char **)mCalloc(io->mod->n_otu,sizeof(char *)); + For(i,io->mod->n_otu) buff[i] = (char *)mCalloc(data[0]->len,sizeof(char)); + remove = (int *)mCalloc(data[0]->len,sizeof(int)); + + n_removed = 0; + + For(i,data[0]->len) + { + For(j,io->mod->n_otu) + { + if((data[j]->state[i] == '?') || (data[j]->state[i] == '-')) data[j]->state[i] = 'X'; + if((io->mod->datatype == NT) && (data[j]->state[i] == 'N')) data[j]->state[i] = 'X'; + if(data[j]->state[i] == 'U') data[j]->state[i] = 'T'; + } + + n_unkn = 0; + For(j,io->mod->n_otu) if(data[j]->state[i] == 'X') n_unkn++; + + if(n_unkn == io->mod->n_otu) + { + remove[i] = 1; + n_removed++; + } + + For(j,io->mod->n_otu) buff[j][i] = data[j]->state[i]; + } + + if(n_removed > 0) + { + if(io->mod->datatype == NT) + printf("\n. %d sites are made from completely undetermined states ('X', '-', '?' or 'N')...\n",n_removed); + else + printf("\n. %d sites are made from completely undetermined states ('X', '-', '?')...\n",n_removed); + } + + pos = 0; + For(i,data[0]->len) + { +/* if(!remove[i]) */ +/* { */ + For(j,io->mod->n_otu) data[j]->state[pos] = buff[j][i]; + pos++; +/* } */ + } + + For(i,io->mod->n_otu) data[i]->len = pos; + For(i,io->mod->n_otu) Free(buff[i]); + Free(buff); + Free(remove); + } + return data; +} diff --git a/src/rnaz_utils.c b/src/rnaz_utils.c index e5762bb..0cad67f 100644 --- a/src/rnaz_utils.c +++ b/src/rnaz_utils.c @@ -26,6 +26,129 @@ #include "pair_mat.h" #include "alifold.h" #include "rnaz_utils.h" +#include +#include +#include +#include + +/* + int64_t read_line(char **restrict line, size_t *restrict len, FILE *restrict fp){ + // Check if either line, len or fp are NULL pointers + if(line == NULL || len == NULL || fp == NULL) { + errno = EINVAL; + return -1; + } + // Use a chunk array of 128 bytes as parameter for fgets + char chunk[128]; + // Allocate a block of memory for *line if it is NULL or smaller than the chunk array + if(*line == NULL || *len < sizeof(chunk)) { + *len = sizeof(chunk); + if((*line = malloc(*len)) == NULL) { + errno = ENOMEM; + return -1; + } + } + // "Empty" the string + (*line)[0] = '\0'; + while(fgets(chunk, sizeof(chunk), fp) != NULL) { + // Resize the line buffer if necessary + size_t len_used = strlen(*line); + size_t chunk_used = strlen(chunk); + if(*len - len_used < chunk_used) { + // Check for overflow + if(*len > SIZE_MAX / 2) { + errno = EOVERFLOW; + return -1; + } + else { + *len *= 2; + } + if((*line = realloc(*line, *len)) == NULL) { + errno = ENOMEM; + return -1; + } + } + // Copy the chunk to the end of the line buffer + memcpy(*line + len_used, chunk, chunk_used); + len_used += chunk_used; + (*line)[len_used] = '\0'; + + // Check if *line contains '\n', if yes, return the *line length + if((*line)[len_used - 1] == '\n') { + return len_used; + } + } + return -1; + } + + + + int64_t read_clustal2(FILE *fp, struct aln **alignments){ + const char delim[] = " "; + char * token; + struct aln *tmp_alignments = NULL; + char *line = NULL; + int no_alignments = 0; + size_t len = 0; + int current_no_alignment; + char *alignment_id = NULL; + read_line(&line, &len, fp); + if (strncmp(line,"CLUSTAL", 7)==0) { + errno = EINVAL; + return -1; + } + bool alignment_id_unknown; + while(read_line(&line, &len, fp) != -1) { + if (strlen(line) == 1){ + continue; + } + token = strtok(line, delim); + alignment_id = token; + alignment_id_unknown = true; + for (current_no_alignment = 0; current_no_alignment < no_alignments; current_no_alignment++){ + if (strcmp(tmp_alignments[current_no_alignment].name, alignment_id) == 0){ + alignment_id_unknown = false; + break; + } + } + if (alignment_id_unknown){ + no_alignments += 1; + tmp_alignments = realloc(tmp_alignments, sizeof(struct aln) * no_alignments); + if (!tmp_alignments){ + errno = ENOMEM; + return -1; + } + tmp_alignments[current_no_alignment].name = malloc(sizeof(char) * (strlen(alignment_id)+1)); + if (!tmp_alignments[current_no_alignment].name){ + errno = ENOMEM; + return -1; + } + strcpy(tmp_alignments[current_no_alignment].name, alignment_id); + tmp_alignments[current_no_alignment].seq = malloc(sizeof(char)); + tmp_alignments[current_no_alignment].seq[0] = '\0'; + tmp_alignments[current_no_alignment].seqlen = 0; + } + token = strtok(NULL, delim); + while( token != NULL ) { + tmp_alignments[current_no_alignment].seqlen += strlen(token); + tmp_alignments[current_no_alignment].seq = realloc(tmp_alignments[current_no_alignment].seq, sizeof(char) * tmp_alignments[current_no_alignment].seqlen); + if (!tmp_alignments[current_no_alignment].seq){ + errno = ENOMEM; + return -1; + } + tmp_alignments[current_no_alignment].seq[tmp_alignments[current_no_alignment].seqlen - 1] = '\0'; + uppercase(token); + strncat(tmp_alignments[current_no_alignment].seq, token, strlen(token) - 1); + token = strtok(NULL, delim); + } + tmp_alignments[current_no_alignment].seq[tmp_alignments[current_no_alignment].seqlen - 1] = '\0'; + } + *alignments = tmp_alignments; + fclose(fp); + free(line); + return no_alignments; + } +*/ /******************************************************************** * * @@ -112,7 +235,74 @@ int read_clustal(FILE *clust, struct aln *alignedSeqs[]) { return num_seq; } - +/* + int64_t read_maf2(FILE *fp, struct aln **alignments){ + const char delim[] = " "; + char * token; + struct aln *tmp_alignments = NULL; + char *line = NULL; + int no_alignments = 0; + size_t len = 0; + int current_no_alignment; + char *alignment_id = NULL; + read_line(&line, &len, fp); + bool alignment_id_unknown; + char *seq = NULL; + while(read_line(&line, &len, fp) != -1) { + if (strlen(line) == 1){ + continue; + } + token = strtok(line, delim); + if (strcmp("s", token) != 0) { + continue; + } + token = strtok(NULL, delim); + alignment_id = token; + alignment_id_unknown = true; + for (current_no_alignment = 0; current_no_alignment < no_alignments; current_no_alignment++){ + if (strcmp(tmp_alignments[current_no_alignment].name, alignment_id) == 0){ + alignment_id_unknown = false; + break; + } + } + if (alignment_id_unknown){ + no_alignments += 1; + tmp_alignments = realloc(tmp_alignments, sizeof(struct aln) * no_alignments); + if (!tmp_alignments){ + errno = ENOMEM; + return -1; + } + tmp_alignments[current_no_alignment].name = malloc(sizeof(char) * (strlen(alignment_id)+1)); + if (!tmp_alignments[current_no_alignment].name){ + errno = ENOMEM; + return -1; + } + strcpy(tmp_alignments[current_no_alignment].name, alignment_id); + tmp_alignments[current_no_alignment].seq = malloc(sizeof(char)); + tmp_alignments[current_no_alignment].seq[0] = '\0'; + tmp_alignments[current_no_alignment].seqlen = 0; + } + token = strtok(NULL, ""); + seq = strrchr(token, ' '); + seq++; + if (seq != NULL){ + uppercase(seq); + tmp_alignments[current_no_alignment].seqlen += strlen(seq); + tmp_alignments[current_no_alignment].seq = realloc(tmp_alignments[current_no_alignment].seq, sizeof(char) * tmp_alignments[current_no_alignment].seqlen + 1); + if (!tmp_alignments[current_no_alignment].seq){ + errno = ENOMEM; + return -1; + } + tmp_alignments[current_no_alignment].seq[tmp_alignments[current_no_alignment].seqlen] = '\0'; + strncat(tmp_alignments[current_no_alignment].seq, seq, strlen(seq) - 1); + } + } + *alignments = tmp_alignments; + fclose(fp); + free(line); + return no_alignments; + } +*/ /******************************************************************** * * diff --git a/src/treeML.c b/src/treeML.c index 88f6a29..121ddbc 100644 --- a/src/treeML.c +++ b/src/treeML.c @@ -23,198 +23,521 @@ #include "bionj.h" #include "models.h" #include "free.h" -#include "options.h" +//#include "options.h" #include "simu.h" #include "eigen.h" #include "pars.h" #include "alrt.h" #include "rnaz_utils.h" +#include "make.h" -seq **Get_Seq_local(seq**, option *io, int rw); +align **Get_Seq_local(align**, option *io, int rw); -int treeML(const struct aln *alignment[], char** treeString, float* kappa){ +int treeML(const struct aln *alignment[], char** treeString, float* kappa) { - int i; - seq **data; - allseq *alldata; + + calign *cdata; option *io; - arbre *tree; - int n_otu; - matrix *mat; - model *mod; - time_t t_beg,t_end; - div_t hour,min; + t_tree *tree; + int num_data_set; + int num_tree, num_rand_tree; + t_mod *mod; + time_t t_beg, t_end; phydbl best_lnL; int L,r_seed; + char *most_likely_tree = NULL; + int orig_random_input_tree; + t_opt *s_opt; - /* Initialize data structures */ + align **data; + int n_otu; + + /* Initialize data structures */ tree = NULL; mod = NULL; - data = NULL; best_lnL = UNLIKELY; - io = (option *)Make_Input(); + + io = (option *)Make_Input(); + mod = (t_mod *)Make_Model_Basic(); + s_opt = (t_opt *)Make_Optimiz(); + Set_Defaults_Input(io); - Set_Defaults_Model(io->mod); - Set_Defaults_Optimiz(io->mod->s_opt); - r_seed = time(NULL); + Set_Defaults_Model(mod); + Set_Defaults_Optimiz(s_opt); + io->mod = mod; + mod->io = io; + mod->s_opt = s_opt; + + + if (!io) return (0); + else { + if (io->use_xml == YES) { + Free(io); + return (0); + } + } + r_seed = (io->r_seed < 0) ? (time(NULL)) : (io->r_seed); srand(r_seed); + io->r_seed = r_seed; + + if (io->in_tree == 2) Test_Multiple_Data_Set_Format(io); + else io->n_trees = 1; + + if (io->n_trees == 0 && io->in_tree == 2) + { + PhyML_Printf("\n== Err.: the input tree file does not provide a tree in valid format."); + Exit("\n"); + } + + if ((io->n_data_sets > 1) && (io->n_trees > 1)) + { + io->n_data_sets = MIN(io->n_trees, io->n_data_sets); + io->n_trees = MIN(io->n_trees, io->n_data_sets); + } + + for (num_data_set = 0; num_data_set < io->n_data_sets; num_data_set++) + { + best_lnL = UNLIKELY; + + + n_otu = 0; + + L = strlen(alignment[0]->seq); + for (n_otu = 0; alignment[n_otu] != NULL; n_otu++); + + io->n_otu = n_otu; + + for (int i=0; iseq); + } + + + data = (align **)mCalloc(n_otu, sizeof(align *)); + + for (int i = 0; i < n_otu; i++) { + data[i] = (align *)mCalloc(1, sizeof(align)); + data[i]->len = L; + data[i]->name = (char *)mCalloc(T_MAX_NAME, sizeof(char)); + strcpy(data[i]->name, alignment[i]->name); + data[i]->state = (char *)mCalloc(T_MAX_SEQ, sizeof(char)); + strcpy(data[i]->state, alignment[i]->seq); + data[i]->is_ambigu = NULL; + } + + /* Call modified version of Get_Seq, that does some processing */ + data = Get_Seq_local(data, io, 0); + io->data = data; + //Get_Seq(io); + + + Make_Model_Complete(io->mod); + Set_Model_Name(io->mod); + Print_Settings(io); + mod = io->mod; + orig_random_input_tree = io->mod->s_opt->random_input_tree; + + + if (io->data) { + if (io->n_data_sets > 1) PhyML_Printf("\n. Data set [#%d]\n", num_data_set + 1); + cdata = Compact_Data(io->data, io); + + Free_Seq(io->data, cdata->n_otu); + + for (num_tree = (io->n_trees == 1) ? (0) : (num_data_set); num_tree < io->n_trees; num_tree++) + { + if (io->mod->s_opt->random_input_tree == NO) io->mod->s_opt->n_rand_starts = 1; + + if (orig_random_input_tree == YES && io->n_trees > 1) + { + PhyML_Printf("\n== Cannot combine random starting trees with multiple input trees."); + Exit("\n"); + } + + for (num_rand_tree = 0; num_rand_tree < io->mod->s_opt->n_rand_starts; num_rand_tree++) + { + if ((io->mod->s_opt->random_input_tree) && (io->mod->s_opt->topo_search != NNI_MOVE)) + if (!io->quiet) PhyML_Printf("\n\n. [Random start %3d/%3d]", num_rand_tree + 1, io->mod->s_opt->n_rand_starts); + + Init_Model(cdata, mod, io); + switch (io->in_tree) + { + case 0 : case 1 : { tree = Dist_And_BioNJ(cdata, mod, io); break; } + case 2 : { tree = Read_User_Tree(cdata, mod, io); break; } + } + + if (io->mod->s_opt->opt_topo == YES) Remove_Duplicates(cdata, io, tree); + + if (io->fp_in_constraint_tree != NULL) + { + char *s; + + PhyML_Printf("\n. Reading constraint tree file..."); + + io->cstr_tree = Read_Tree_File_Phylip(io->fp_in_constraint_tree); + + if (io->cstr_tree->n_root != NULL) + { + PhyML_Printf("\n== The constraint tree file must be unrooted"); + Exit("\n"); + } + + s = Add_Taxa_To_Constraint_Tree(io->fp_in_constraint_tree, cdata); + fflush(NULL); + Free_Tree(tree); + tree = Read_Tree(&s); + io->in_tree = 2; + Free(s); + Check_Constraint_Tree_Taxa_Names(io->cstr_tree, cdata); + Alloc_Bip(io->cstr_tree); + Get_Bip(io->cstr_tree->a_nodes[0], + io->cstr_tree->a_nodes[0]->v[0], + io->cstr_tree); + if (tree->has_branch_lengths == NO) Add_BioNJ_Branch_Lengths(tree, cdata, mod, NULL); + } + + + if (!tree) continue; + + time(&t_beg); + time(&(tree->t_beg)); + + tree->mod = mod; + tree->io = io; + tree->data = cdata; + tree->n_pattern = tree->data->crunch_len; + tree->n_root = NULL; + tree->e_root = NULL; + tree->n_tot_bl_opt = 0; + + Set_Both_Sides(YES, tree); + + if ((!num_data_set) && (!num_tree) && (!num_rand_tree)) Check_Memory_Amount(tree); + + if (io->cstr_tree && !Check_Topo_Constraints(tree, io->cstr_tree)) + { + PhyML_Printf("\n\n== The initial tree does not satisfy the topological constraint."); + PhyML_Printf("\n== Please use the user input tree option with an adequate tree topology."); + Exit("\n"); + } + + Connect_CSeqs_To_Nodes(tree->data, tree->io, tree); + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); + Make_Spr(tree); + Br_Len_Not_Involving_Invar(tree); + Unscale_Br_Len_Multiplier_Tree(tree); + if (tree->io->print_json_trace == YES) JSON_Tree_Io(tree, tree->io->fp_out_json_trace); + + + + Set_Update_Eigen(YES, tree->mod); + Lk(NULL, tree); + Set_Update_Eigen(NO, tree->mod); + + + if (tree->mod->s_opt->opt_topo) { + Global_Spr_Search(tree); + if (tree->n_root) Add_Root(tree->a_edges[0], tree); + } + else + { + if (tree->mod->s_opt->opt_subst_param || tree->mod->s_opt->opt_bl) Round_Optimize(tree, ROUND_MAX); + } + + + if (tree->mod->gamma_mgf_bl) Best_Root_Position_IL_Model(tree); + + Set_Both_Sides(YES, tree); + Lk(NULL, tree); + Pars(NULL, tree); + Get_Tree_Size(tree); + PhyML_Printf("\n\n. Log likelihood of the current tree: %.*f.", DECIMAL_DIG, tree->c_lnL); + if (tree->io->ancestral == YES) Ancestral_Sequences(tree, YES); + + Check_Br_Lens(tree); + Br_Len_Involving_Invar(tree); + Rescale_Br_Len_Multiplier_Tree(tree); + if (!tree->n_root) Get_Best_Root_Position(tree); + + /* Print the tree estimated using the current random (or BioNJ) starting tree */ + /* if(io->mod->s_opt->n_rand_starts > 1) */ + if (orig_random_input_tree == YES) + { + Print_Tree(io->fp_out_trees, tree); + fflush(NULL); + } + + /* Record the most likely tree in a string of characters */ + if (tree->c_lnL > best_lnL) + { + best_lnL = tree->c_lnL; + if (most_likely_tree) Free(most_likely_tree); + most_likely_tree = Write_Tree(tree); + + time(&t_end); + /* + Print_Fp_Out(io->fp_out_stats, t_beg, t_end, tree, + io, num_data_set + 1, + (orig_random_input_tree == YES) ? (num_rand_tree) : (num_tree), + (num_rand_tree == io->mod->s_opt->n_rand_starts - 1) ? (YES) : (NO), io->precision); + */ + if (tree->io->print_site_lnl) Print_Site_Lk(tree, io->fp_out_lk); + } + + + + /* Start from BioNJ tree */ + if ((num_rand_tree == io->mod->s_opt->n_rand_starts - 1) && (tree->mod->s_opt->random_input_tree)) + { + /* Do one more iteration in the loop, but don't randomize the tree */ + tree->mod->s_opt->n_rand_starts++; + tree->mod->s_opt->random_input_tree = NO; + } + Free_One_Spr(tree->best_spr); + Free_Spr_List_One_Edge(tree); + Free_Spr_List_All_Edge(tree); + Free_Tree_Pars(tree); + Free_Tree_Lk(tree); + Free_Tree(tree); + } //Tree done + + //if (io->n_data_sets == 1) rewind(io->fp_out_tree); + //if (most_likely_tree) PhyML_Fprintf(io->fp_out_tree, "%s\n", most_likely_tree); + + + /* Launch bootstrap analysis */ + if (io->do_boot || io->do_tbe) + { + if (!io->quiet) PhyML_Printf("\n\n. Launch bootstrap analysis on the most likely tree..."); + most_likely_tree = Bootstrap_From_String(most_likely_tree, cdata, mod, io); + + PhyML_Printf("\n\n. Completed the bootstrap analysis succesfully."); fflush(NULL); + } + else if (io->ratio_test != NO) + { + /* Launch aLRT */ + most_likely_tree = aLRT_From_String(most_likely_tree, cdata, mod, io); + } + + + /* Print the most likely tree in the output file */ + //if (!io->quiet) PhyML_Printf("\n\n. Printing the most likely tree in file '%s'.", Basename(io->out_tree_file)); + //if (io->n_data_sets == 1) rewind(io->fp_out_tree); + + t_tree *dum; + dum = Read_Tree(&most_likely_tree); + dum->data = cdata; + dum->mod = mod; + dum->io = io; + Connect_CSeqs_To_Nodes(cdata, io, dum); + Insert_Duplicates(dum); + Free(most_likely_tree); + most_likely_tree = Write_Tree(dum); + Free_Tree(dum); + + //PhyML_Fprintf(io->fp_out_tree, "%s\n", most_likely_tree); + + if (io->n_trees > 1 && io->n_data_sets > 1) break; + } + Free_Calign(cdata); + } + else + { + PhyML_Printf("\n== No data was found.\n"); + PhyML_Printf("\n== Err. in file %s at line %d\n", __FILE__, __LINE__); + Exit("\n"); + } + Free_Model_Complete(mod); + } + *treeString = most_likely_tree; + //if (most_likely_tree) Free(most_likely_tree); + + if (mod->s_opt->n_rand_starts > 1) PhyML_Printf("\n. Best log likelihood: %f\n", best_lnL); + + Free_Optimiz(mod->s_opt); + Free_Model_Basic(mod); + + if (io->fp_in_constraint_tree) fclose(io->fp_in_constraint_tree); + //if (io->fp_in_align) fclose(io->fp_in_align); + if (io->fp_in_tree) fclose(io->fp_in_tree); + if (io->fp_out_lk) fclose(io->fp_out_lk); + //if (io->fp_out_tree) fclose(io->fp_out_tree); + if (io->fp_out_trees) fclose(io->fp_out_trees); + if (io->fp_out_stats) fclose(io->fp_out_stats); + if (io->fp_out_trace) fclose(io->fp_out_trace); + if (io->fp_out_json_trace) fclose(io->fp_out_json_trace); + + if (io->fp_in_constraint_tree != NULL) Free_Tree(io->cstr_tree); + Free_Input(io); + return 1; + +} + +/* Function from Seqgen (c) Andrew Rambaut & Nick Grassly */ + +align **Get_Seq_local(align** data, option *io, int rw) +{ + int i, j; + char **buff; + int n_unkn, n_removed, pos; + int *remove; + + + /* rewind(fp_seq); */ + + + if (data) + { + buff = (char **)mCalloc(io->n_otu, sizeof(char *)); + For(i, io->n_otu) buff[i] = (char *)mCalloc(data[0]->len, sizeof(char)); + remove = (int *)mCalloc(data[0]->len, sizeof(int)); + + n_removed = 0; + + For(i, data[0]->len) + { + For(j, io->n_otu) + { + if ((data[j]->state[i] == '?') || (data[j]->state[i] == '-')) data[j]->state[i] = 'X'; + if ((io->datatype == NT) && (data[j]->state[i] == 'N')) data[j]->state[i] = 'X'; + if (data[j]->state[i] == 'U') data[j]->state[i] = 'T'; + } + + n_unkn = 0; + For(j, io->n_otu) if (data[j]->state[i] == 'X') n_unkn++; + + if (n_unkn == io->n_otu) + { + remove[i] = 1; + n_removed++; + } + + For(j, io->n_otu) buff[j][i] = data[j]->state[i]; + } + + if (n_removed > 0) + { + if (io->datatype == NT) + printf("\n. %d sites are made from completely undetermined states ('X', '-', '?' or 'N')...\n", n_removed); + else + printf("\n. %d sites are made from completely undetermined states ('X', '-', '?')...\n", n_removed); + } + + pos = 0; + For(i, data[0]->len) + { + /* if(!remove[i]) */ + /* { */ + For(j, io->n_otu) data[j]->state[pos] = buff[j][i]; + pos++; + /* } */ + } + + For(i, io->n_otu) data[i]->len = pos; + For(i, io->n_otu) Free(buff[i]); + Free(buff); + Free(remove); + } + return data; +} + + +/* + + + Make_Model_Complete(io->mod); mod = io->mod; - - /* Set options */ - io->mod->datatype=NT; /* Nucleotides not amino acids */ - io->mod->s_opt->print=0; /* Shut of verbose output */ - io->mod->s_opt->opt_topo = 0; /* Do not optimize topology */ - io->mod->s_opt->opt_bl = 1; /* Optimize branch lengths*/ - io->mod->s_opt->opt_num_param = 1; /* Optimize kappa, initialize with 4.0*/ + //Set options + + io->datatype = NT; // Nucleotides not amino acids + io->mod->s_opt->opt_topo = 0; // Do not optimize topology + io->mod->s_opt->opt_bl = 1; // Optimize branch lengths + io->mod->s_opt->opt_subst_param = 1; // Optimize kappa, initialize with 4.0 io->mod->s_opt->opt_kappa = 1; - io->mod->kappa = 4.0; - - /* Manually fill data structure with the alignment */ - + io->mod->kappa->v = 4.0; + + // Manually fill data structure with the alignment + n_otu = 0; - L=strlen(alignment[0]->seq); - for (n_otu=0; alignment[n_otu]!=NULL; n_otu++); + L = strlen(alignment[0]->seq); + for (n_otu = 0; alignment[n_otu] != NULL; n_otu++); - io->mod->n_otu=n_otu; + io->n_otu = n_otu; - data = (seq **)mCalloc(n_otu,sizeof(seq *)); + data = (align **)mCalloc(n_otu, sizeof(align *)); - for (i=0;ilen = L; - data[i]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); - strcpy(data[i]->name,alignment[i]->name); - data[i]->state = (char *)mCalloc(T_MAX_SEQ,sizeof(char)); - strcpy(data[i]->state,alignment[i]->seq); + data[i]->name = (char *)mCalloc(T_MAX_NAME, sizeof(char)); + strcpy(data[i]->name, alignment[i]->name); + data[i]->state = (char *)mCalloc(T_MAX_SEQ, sizeof(char)); + strcpy(data[i]->state, alignment[i]->seq); data[i]->is_ambigu = NULL; } - /* Call modified version of Get_Seq, that does some processing */ - data=Get_Seq_local(data, io, 0); - alldata = Compact_Seq(data,io); - Free_Seq(data,alldata->n_otu); - Check_Ambiguities(alldata,io->mod->datatype,io->mod->stepsize); - if (Init_Model(alldata,mod)!=1){ - return(0); - } + // Call modified version of Get_Seq, that does some processing + data = Get_Seq_local(data, io, 0); + alldata = Compact_Data(data, io); + Free_Seq(data, alldata->n_otu); + Check_Ambiguities(alldata, io->datatype, io->state_len); + Init_Model(alldata, mod, io); + - /* Calculate pairwise distances and make BIONJ tree*/ - mat = ML_Dist(alldata,mod); + // Calculate pairwise distances and make BIONJ tree + mat = ML_Dist(alldata, mod); Fill_Missing_Dist(mat); - mat->tree = Make_Tree_From_Scratch(alldata->n_otu,alldata); + mat->tree = Make_Tree_From_Scratch(alldata->n_otu, alldata); + + + // bionj.h + Bionj(mat); tree = mat->tree; - tree->mat = mat; + tree->verbose = 0; // Shut of verbose output tree->mod = mod; tree->io = io; tree->data = alldata; tree->both_sides = 1; - tree->n_pattern = tree->data->crunch_len/tree->mod->stepsize; - time(&t_beg); - time(&(tree->t_beg)); + tree->n_pattern = tree->data->crunch_len / io->state_len; + //time(&t_beg); + //time(&(tree->t_beg)); - /* Prepare for optimization and optimize */ + // Prepare for optimization and optimize Fill_Dir_Table(tree); Update_Dirs(tree); - Make_Tree_4_Pars(tree,alldata,alldata->init_len); - Make_Tree_4_Lk(tree,alldata,alldata->init_len); - tree->triplet_struct = Make_Triplet_Struct(mod); + Connect_CSeqs_To_Nodes(tree->data, tree->io, tree); + Make_Tree_For_Pars(tree); + Make_Tree_For_Lk(tree); + //tree->triplet_struct = Make_Triplet_Struct(mod); Br_Len_Not_Involving_Invar(tree); - Order_Tree_CSeq(tree,alldata); - Round_Optimize(tree,tree->data); + //Connect_CSeqs_To_Nodes(alldata,io,tree); + Round_Optimize(tree, ROUND_MAX); //treeString=(char *)mCalloc(T_MAX_LINE,sizeof(char)); - - *treeString=Write_Tree(tree); - *kappa=io->mod->kappa; + + *treeString = Write_Tree(tree); + //what that for?? + // *kappa=io->mod->kappa; Free_Mat(tree->mat); - Free_Triplet(tree->triplet_struct); + //Free_Triplet(tree->triplet_struct); Free_Tree_Pars(tree); Free_Tree_Lk(tree); Free_Tree(tree); - - Free_Cseq(alldata); + + Free_Calign(alldata); Free_Model(mod); Free_Input(io); - return(1); - -} - -/* Function from Seqgen (c) Andrew Rambaut & Nick Grassly */ - -seq **Get_Seq_local(seq** data, option *io, int rw) -{ - int i,j; - char **buff; - int n_unkn,n_removed,pos; - int *remove; - - -/* rewind(fp_seq); */ - - - if(data) - { - buff = (char **)mCalloc(io->mod->n_otu,sizeof(char *)); - For(i,io->mod->n_otu) buff[i] = (char *)mCalloc(data[0]->len,sizeof(char)); - remove = (int *)mCalloc(data[0]->len,sizeof(int)); - - n_removed = 0; - - For(i,data[0]->len) - { - For(j,io->mod->n_otu) - { - if((data[j]->state[i] == '?') || (data[j]->state[i] == '-')) data[j]->state[i] = 'X'; - if((io->mod->datatype == NT) && (data[j]->state[i] == 'N')) data[j]->state[i] = 'X'; - if(data[j]->state[i] == 'U') data[j]->state[i] = 'T'; - } - - n_unkn = 0; - For(j,io->mod->n_otu) if(data[j]->state[i] == 'X') n_unkn++; - - if(n_unkn == io->mod->n_otu) - { - remove[i] = 1; - n_removed++; - } - - For(j,io->mod->n_otu) buff[j][i] = data[j]->state[i]; - } - - if(n_removed > 0) - { - if(io->mod->datatype == NT) - printf("\n. %d sites are made from completely undetermined states ('X', '-', '?' or 'N')...\n",n_removed); - else - printf("\n. %d sites are made from completely undetermined states ('X', '-', '?')...\n",n_removed); - } - - pos = 0; - For(i,data[0]->len) - { -/* if(!remove[i]) */ -/* { */ - For(j,io->mod->n_otu) data[j]->state[pos] = buff[j][i]; - pos++; -/* } */ - } - - For(i,io->mod->n_otu) data[i]->len = pos; - For(i,io->mod->n_otu) Free(buff[i]); - Free(buff); - Free(remove); - } - return data; -} + return (1); + */ \ No newline at end of file diff --git a/src/treeSimulate.c b/src/treeSimulate.c index 140de57..d2473c5 100644 --- a/src/treeSimulate.c +++ b/src/treeSimulate.c @@ -103,7 +103,7 @@ TTree* string2tree(char* treeString){ TTree* tree; int dummy1; double dummy2; - + tmpfh = tmpfile(); fprintf(tmpfh,"%s",treeString); rewind(tmpfh);