First commit of PhyloMOEO files with some additions to Paradiseo-MOEO

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1335 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
wcancino 2009-01-15 15:27:23 +00:00
commit aa33715685
44 changed files with 8623 additions and 0 deletions

View file

@ -0,0 +1,57 @@
/***************************************************************************
* Copyright (C) 2005 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#ifndef _ExceptionManager_H_
#define _ExceptionManager_H_
using namespace std;
class ExceptionManager
{
string msg;
short number;
public:
ExceptionManager(int n) {
number = n;
switch(number){
case 10:
msg = "Could not open file\n";
break;
case 11:
msg ="Incorrect file format\n";
break;
case 12:
msg = "Could not write to file\n";
break;
}
};
void Report()
{
cout << endl << msg << endl;
cout << "PhyloMOEA was finished because errors." << endl;
exit(1);
}
};
#endif

View file

@ -0,0 +1,27 @@
INCLUDES = -I$(top_srcdir)/. -I$(top_srcdir)/eo -I$(top_srcdir)/mo \
-I$(top_srcdir)/moeo -I$(top_srcdir)/moeo/core
METASOURCES = AUTO
bin_PROGRAMS = PhyloMOEA
PhyloMOEA_SOURCES = ExceptionManager.h Patterns.h PhyloMOEA.cpp ProbMatrix.cpp \
ProbMatrix.h RandomNr.cpp RandomNr.h Sequences.cpp Sequences.h SubsModel.cpp \
SubsModel.h eigensolver.cpp eigensolver.h likelihoodcalculator.cpp \
likelihoodcalculator.h likoptimizer.cpp likoptimizer.h matrixutils.cpp matrixutils.h \
parsimonycalculator.cpp parsimonycalculator.h phylotreeIND.cpp phylotreeIND.h \
probmatrixcontainer.cpp probmatrixcontainer.h treeIterator.cpp treeIterator.h tree_limits.h \
utils.cpp
PhyloMOEA_LDADD = $(top_builddir)/moeo/core/libmoeo.la \
$(top_builddir)/eo/utils/libutils.la $(top_builddir)/eo/ga/libga.la $(top_builddir)/eo/libeo.la -lGTL -lgsl \
-lgslcblas
noinst_HEADERS = PhyloMOEOProbMatrixContainerUpdater.h moeoObjVecStat.h \
vectorSortIndex.h
_SOURCES = PhyloMOEO.h
_SOURCES = PhyloMOEO.h PhyloMOEO_operators.h
_SOURCES = PhyloMOEO.h PhyloMOEO_init.h PhyloMOEO_operators.h
_SOURCES = PhyloMOEO.h PhyloMOEO_eval.h PhyloMOEO_init.h PhyloMOEO_operators.h
_SOURCES = PhyloMOEO.h PhyloMOEO_eval.h PhyloMOEO_init.h PhyloMOEO_operators.h \
utils.h
_SOURCES = eoCountedFileMonitor.h
_SOURCES = eoCountedFileMonitor.h eoSingleFileCountedStateSaver.h
_SOURCES = moeoPtrComparator.h
_SOURCES = PhyloMOEO_archive.h
_SOURCES = PhyloMOEOPartitionStat.h PhyloMOEO_archive.h

View file

@ -0,0 +1,509 @@
# Makefile.in generated by automake 1.10.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008 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@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@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 = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = PhyloMOEA$(EXEEXT)
subdir = moeo/PhyloMOEA
DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
am__installdirs = "$(DESTDIR)$(bindir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am_PhyloMOEA_OBJECTS = PhyloMOEA.$(OBJEXT) ProbMatrix.$(OBJEXT) \
RandomNr.$(OBJEXT) Sequences.$(OBJEXT) SubsModel.$(OBJEXT) \
eigensolver.$(OBJEXT) likelihoodcalculator.$(OBJEXT) \
likoptimizer.$(OBJEXT) matrixutils.$(OBJEXT) \
parsimonycalculator.$(OBJEXT) phylotreeIND.$(OBJEXT) \
probmatrixcontainer.$(OBJEXT) treeIterator.$(OBJEXT) \
utils.$(OBJEXT)
PhyloMOEA_OBJECTS = $(am_PhyloMOEA_OBJECTS)
PhyloMOEA_DEPENDENCIES = $(top_builddir)/moeo/core/libmoeo.la \
$(top_builddir)/eo/utils/libutils.la \
$(top_builddir)/eo/ga/libga.la $(top_builddir)/eo/libeo.la
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(PhyloMOEA_SOURCES)
DIST_SOURCES = $(PhyloMOEA_SOURCES)
HEADERS = $(noinst_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DSYMUTIL = @DSYMUTIL@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
GREP = @GREP@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NMEDIT = @NMEDIT@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SED = @SED@
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@
ac_ct_F77 = @ac_ct_F77@
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 = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
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_builddir = @top_builddir@
top_srcdir = @top_srcdir@
INCLUDES = -I$(top_srcdir)/. -I$(top_srcdir)/eo -I$(top_srcdir)/mo \
-I$(top_srcdir)/moeo -I$(top_srcdir)/moeo/core
METASOURCES = AUTO
PhyloMOEA_SOURCES = ExceptionManager.h Patterns.h PhyloMOEA.cpp ProbMatrix.cpp \
ProbMatrix.h RandomNr.cpp RandomNr.h Sequences.cpp Sequences.h SubsModel.cpp \
SubsModel.h eigensolver.cpp eigensolver.h likelihoodcalculator.cpp \
likelihoodcalculator.h likoptimizer.cpp likoptimizer.h matrixutils.cpp matrixutils.h \
parsimonycalculator.cpp parsimonycalculator.h phylotreeIND.cpp phylotreeIND.h \
probmatrixcontainer.cpp probmatrixcontainer.h treeIterator.cpp treeIterator.h tree_limits.h \
utils.cpp
PhyloMOEA_LDADD = $(top_builddir)/moeo/core/libmoeo.la \
$(top_builddir)/eo/utils/libutils.la $(top_builddir)/eo/ga/libga.la $(top_builddir)/eo/libeo.la -lGTL -lgsl \
-lgslcblas
noinst_HEADERS = PhyloMOEOProbMatrixContainerUpdater.h moeoObjVecStat.h \
vectorSortIndex.h
_SOURCES = PhyloMOEOPartitionStat.h PhyloMOEO_archive.h
all: all-am
.SUFFIXES:
.SUFFIXES: .cpp .lo .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 \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu moeo/PhyloMOEA/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu moeo/PhyloMOEA/Makefile
.PRECIOUS: 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
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; for p in $$list; do \
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
if test -f $$p \
|| test -f $$p1 \
; then \
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
clean-binPROGRAMS:
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
PhyloMOEA$(EXEEXT): $(PhyloMOEA_OBJECTS) $(PhyloMOEA_DEPENDENCIES)
@rm -f PhyloMOEA$(EXEEXT)
$(CXXLINK) $(PhyloMOEA_OBJECTS) $(PhyloMOEA_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PhyloMOEA.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ProbMatrix.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RandomNr.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Sequences.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SubsModel.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eigensolver.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/likelihoodcalculator.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/likoptimizer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/matrixutils.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parsimonycalculator.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/phylotreeIND.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/probmatrixcontainer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/treeIterator.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
.cpp.obj:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.cpp.lo:
@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
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 $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$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) $(HEADERS)
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:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_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 clean-libtool 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
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-exec-am: install-binPROGRAMS
install-html: install-html-am
install-info: install-info-am
install-man:
install-pdf: install-pdf-am
install-ps: 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 \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-binPROGRAMS
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
clean-generic clean-libtool ctags distclean distclean-compile \
distclean-generic distclean-libtool 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 mostlyclean-libtool \
pdf pdf-am ps ps-am tags uninstall uninstall-am \
uninstall-binPROGRAMS
# 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:

View file

@ -0,0 +1,54 @@
/***************************************************************************
* Copyright (C) 2005 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef PATTERNS_H
#define PATTERNS_H
#include <Sequences.h>
#include <vector>
#include <string>
class Patterns
{
private:
int num_patterns;
double freqs[4];
std::vector<unsigned char*> pattern;
std::vector<int> pattern_count;
Sequences &seqs;
public:
// return a pattern content
Patterns(Sequences &S);
~Patterns();
unsigned char* operator[](int n) const { return pattern[n]; }
inline int count(int n) const { return pattern_count[n]; }
inline int count() const { return num_patterns; }
inline double *frequences() { return freqs; }
inline double frequence(int i) const { return freqs[i]; }
inline std::string pattern_name(int i) const { return seqs.seqname(i); }
inline int search_taxon_name(std::string &s) const { return seqs.search_taxon_name(s); }
inline bool is_ambiguous(short int l) const { return seqs.is_ambiguous(l); }
inline bool is_gap(short int l) const { return seqs.is_gap(l); }
inline bool is_undefined(short int l) const { return seqs.is_undefined(l); }
inline unsigned char* ambiguos_meaning(short int l) const { return seqs.ambiguos_meaning(l); }
void calculate_frequences();
int num_sequences();
};
#endif

View file

@ -0,0 +1,236 @@
#include <eo>
#include <moeo>
#include <PhyloMOEO.h>
#include <PhyloMOEO_operators.h>
#include <PhyloMOEO_init.h>
#include <PhyloMOEO_eval.h>
#include <PhyloMOEO_archive.h>
#include <PhyloMOEOProbMatrixContainerUpdater.h>
#include <moeoObjVecStat.h>
#include <PhyloMOEOPartitionStat.h>
#include <eoCountedFileMonitor.h>
#include <eoSingleFileCountedStateSaver.h>
#include <vectorSortIndex.h>
#include <utils.h>
#include <ctime>
#include <apply.h>
gsl_rng *rn2;
RandomNr *rn;
//Sequences *seq;
long seed;
//vector<phylotreeIND> arbores;
string datafile,usertree, expid, path;
double pcrossover, pmutation, kappa, alpha;
unsigned int ngenerations, popsize, ncats;
ofstream exp_data,evolution_data, best_media_scores, final_trees, final_pareto_trees, clades_pareto, clades_final,final_scores,pareto_scores;
int main(int argc, char *argv[])
{
welcome_message();
eoParser parser(argc, argv);
seed = parser.createParam((unsigned int)(time(NULL)), "seed", "Random Seed", 's',"Param").value();
popsize = parser.createParam((unsigned int)(50), "popSize", "Population size", 'n',"Param").value();
pcrossover = parser.createParam((double)(0.8), "pcross", "Crossover Rate", 'c',"Param").value();
pmutation = parser.createParam((double)(0.1), "pmut", "Mutation Rate", 'm',"Param").value();
ngenerations = parser.createParam((unsigned int)(500), "nGen", "Number of Generations", 'g',"Param").value();
kappa = parser.createParam((double)(4.0), "kappa", "Kappa value", 'k',"Param").value();
alpha = parser.createParam((double)(2.0), "alpha", "Alpha value", 'a',"Param").value();
ncats = parser.createParam((unsigned int)(4), "nCat", "Number of Categories", 'r',"Param").value();
datafile = parser.createParam(string(), "data", "Datafile", 'd',"Param").value();
usertree = parser.createParam(string(), "treef", "Treefile", 't',"Param").value();
path = parser.createParam(string(), "path", "Treefile", 'p',"Param").value();
ostringstream convert;
convert << seed;
expid = parser.createParam(convert.str(), "expid", "Experiment ID", 'e',"Param").value();
if( datafile.size()==0 )
{
parser.printHelp( cout );
return(-1);
}
string filename = path + datafile;
cout << "\n\nReading Sequence Datafile...";
Sequences seq(filename.c_str());
cout << " done.\n";
// calculate datafile
seq.calculate_patterns();
seq.calculate_frequences();
rn2 = gsl_rng_alloc(gsl_rng_default);
rn = new RandomNr(seed);
phylotreeIND templatetree( rn, seq, rn2);
ParsimonyCalculator parsi_calc(templatetree);
SubstModel modelHKY( seq, SubstModel::HKY85);
modelHKY.init();
modelHKY.set_kappa(kappa); // banco_grande
ProbMatrixContainer probmatrixs(modelHKY);
LikelihoodCalculator lik_calc(templatetree, modelHKY, probmatrixs,ncats);
lik_calc.set_alpha(alpha);
modelHKY.init();
PhyloEval byobj( parsi_calc, lik_calc );
Phyloraninit initializer(templatetree);
eoState state;
//eoPop <PhyloMOEO> &population = state.takeOwnership(eoPop<PhyloMOEO>(popsize, initializer));
eoPop<PhyloMOEO> population(popsize, initializer);
//state.registerObject( population );
cout << "\n\nReading Initial Trees...";
if( usertree.size() >0)
{
filename = path + usertree;
readtrees(filename.c_str(), population);
}
cout << " done.\n";
cout << "\n\nCreating output files...";
try{
filename = path + datafile + "_exp_param_" + expid + ".txt";
exp_data.open(filename.c_str());
exp_data.precision(15);
exp_data.setf(ios::fixed);
if( !exp_data.is_open() )
{
throw( ExceptionManager(12) );
}
cout << " done.\n";
}
catch ( ExceptionManager e )
{
e.Report();
}
// create the moea
save_exp_params(exp_data);
seq.save_seq_data(exp_data);
moeoAverageObjVecStat <PhyloMOEO> bestfit;
moeoBestObjVecStat <PhyloMOEO> avgfit;
eoPopStat<PhyloMOEO> popstats;
eoCountedFileMonitor media_scores( 2, path + datafile + "_media_scores_" + expid + ".txt", "\t", true,true );
media_scores.add( bestfit);
media_scores.add( avgfit) ;
eoCountedFileMonitor evolution_scores( 2, path + datafile + "_evolution_data_" + expid + ".txt", "\n", true,true );
evolution_scores.add( popstats);
cout << "\n\nRunning NSGA-II ..." << endl;
eoGenContinue<PhyloMOEO> continuator(ngenerations);
eoCheckPoint<PhyloMOEO> cp(continuator);
eoValueParam<unsigned> generationCounter(0, "Gen.");
eoIncrementor<unsigned> increment(generationCounter.value());
cp.add(increment);
eoStdoutMonitor monitor(false);
monitor.add(generationCounter);
cp.add(monitor);
Phylomutate mutator;
Phylocross crossover;
eoSequentialOp<PhyloMOEO> operadores;
operadores.add(crossover,pcrossover);
operadores.add(mutator,pmutation);
PhyloMOEOProbMatrixContainerUpdater probmatrixupdater(probmatrixs);
cp.add( bestfit);
cp.add( avgfit);
cp.add( media_scores);
cp.add( evolution_scores );
cp.add( popstats);
cp.add( probmatrixupdater );
// apply<PhyloMOEO> ( byobj, population );
// population.printOn(cout);
moeoNSGAII < PhyloMOEO > nsgaII (cp, byobj, operadores);
nsgaII(population);
cout << "\nCalculating Final Solutions...";
cout << " done\n";
PhyloMOEOFinalSolutionsArchive finalsolutions;
finalsolutions.update(population);
//remove_final_solutions( population );
// optimize remaining solutions
cout << "\nOptimizing tree branch lenghts...\n";
optimize_solutions( finalsolutions, lik_calc );
cout << "\nReevaluating individuals \n";
apply<PhyloMOEO> ( byobj, finalsolutions );
finalsolutions.save_scores(path + datafile + "_final_scores_" + expid + ".txt","#Final Solutions Scores");
finalsolutions.save_trees(path + datafile + "_final_trees_" + expid + ".txt");
cout << "\ndone \n";
// print the optimized solutions
//print_scores_pop( -2, population, evolution_data);
//print_scores_pop( -2, population, final_scores);
//save_trees(finalsolutions, final_trees);
cout << "\n\nCalculating Final Solutions clade support...";
PhyloMOEOPartitionStat splitstats;
splitstats(finalsolutions);
eoFileMonitor finalsplitstatsaver(path+datafile+"_clades_final_"+expid+".txt");
finalsplitstatsaver.add(splitstats);
finalsplitstatsaver();
//cout << splitstats.value() << endl;
//partition_map split_frequences;
//calculate_frequence_splits(finalsolutions,split_frequences);
cout << " done\n";
//save_partitions(splitstats.value(), clades_final);
//split_frequences.clear();
// remove dominate solutions
cout << "\nCalculating Pareto-optimal Solutions...";
PhyloMOEOParetoSolutionsArchive paretosolutions;
paretosolutions.update(finalsolutions);
paretosolutions.save_scores(path + datafile + "_pareto_scores_" + expid + ".txt","#Pareto Solutions Scores");
paretosolutions.save_trees(path + datafile + "_pareto_trees_" + expid + ".txt");
cout << " done\n";
// print final pareto trees
//save_trees( paretosolutions, final_pareto_trees);
cout << "\nCalculating Pareto-optimal Solutions clade support...";
splitstats(paretosolutions);
//calculate_frequence_splits(paretosolutions,split_frequences);
eoFileMonitor paretosplitstatsaver(path+datafile+"_clades_pareto_"+expid+".txt");
paretosplitstatsaver.add(splitstats);
paretosplitstatsaver();
// save_partitions(splitstats.value(), clades_pareto);
//split_frequences.clear();
cout << " done\n";
exp_data.close();
evolution_data.close();
pareto_scores.close();
final_scores.close();
best_media_scores.close();
final_trees.close();
final_pareto_trees.close();
clades_pareto.close();
clades_final.close();
gsl_rng_free(rn2);
// delete probmatrixs;
delete rn;
cout << "\nPhyloMOEA execution finishes !\n";
return 0;
}

View file

@ -0,0 +1,83 @@
/***************************************************************************
* Copyright (C) 2008 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef PHYLOMOEO_H_
#define PHYLOMOEO_H_
#include "phylotreeIND.h"
#include <iostream>
class ObjectiveVectorTraits : public moeoObjectiveVectorTraits
{
public:
static bool minimizing (int i)
{
return true;
}
static bool maximizing (int i)
{
return false;
}
static unsigned int nObjectives ()
{
return 2;
}
};
typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector;
class PhyloMOEO : public MOEO< ObjectiveVector, double, double >
{
private:
phylotreeIND *tree;
void copy(const PhyloMOEO &other)
{
if(tree!=NULL)delete tree;
tree=NULL;
if(other.tree!=NULL)tree = new phylotreeIND(other.get_tree());
if(!other.invalidObjectiveVector())this->objectiveVector( other.objectiveVector() );
if(!other.invalidFitness())this->fitness( other.fitness() );
if(!other.invalidDiversity())this->diversity( other.diversity() );
}
public:
PhyloMOEO() : MOEO < ObjectiveVector, double, double >() { tree = NULL; }
PhyloMOEO(const PhyloMOEO &other) : MOEO < ObjectiveVector, double, double >(other) {
tree=NULL;
if(other.tree!=NULL)tree = new phylotreeIND(other.get_tree());
}
void set_tree_template(phylotreeIND &other) { if(tree!=NULL)delete tree; tree = other.clone(); };
void set_random_tree(phylotreeIND &other) { if(tree!=NULL)delete tree; tree = other.randomClone(); };
PhyloMOEO& operator= (const PhyloMOEO& other) {
copy(other);
return *this;
}
void readFrom (std::istream &_is)
{
string s;
_is >> s;
tree->read_newick2( s );
}
phylotreeIND & get_tree() const { return *tree; }
~PhyloMOEO() { if(tree!=NULL)delete tree; }
};
#endif

View file

@ -0,0 +1,187 @@
/***************************************************************************
* Copyright (C) 2008 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef PHYLOMOEOPARTITONSTAT_H_
#define PHYLOMOEOPARTITONSTAT_H_
#include <PhyloMOEA/moeoObjVecStat.h>
#include <PhyloMOEO.h>
//#include <utils.h>
struct part_info
{
int freq; double prob;
double dp, dl, tdp, tdl;
short int type; // 001=intermediate 1, 010=mp 2, 100=ml 4,
// 110= mp & ml 6, 101 = ml & int 5 011 mp & int 3 , 111 tree 7
bool inverse;
part_info(): freq(0), prob(0.0), dp(0), dl(0), tdp(0), tdl(0), type(0), inverse(false) {};
};
typedef std::map<string,struct part_info> partition_map;
class PhyloMOEOPartitionStat : public eoStat<PhyloMOEO, partition_map>
{
public :
using eoStat<PhyloMOEO, partition_map>::value;
PhyloMOEOPartitionStat(std::string _description = "Partition Stats")
: eoStat<PhyloMOEO, partition_map>(partition_map(), _description) {}
virtual void operator()(const eoPop<PhyloMOEO>& _pop){
doit(_pop); // specializations for scalar and std::vector
}
virtual std::string className(void) const { return "PhyloMOEOPartitionStat"; }
private :
// Specialization for pareto fitness
void doit(const eoPop<PhyloMOEO>& _pop)
{
value().clear();
calculate_frequence_splits( _pop, value() );
}
void calculate_frequence_splits( const eoPop<PhyloMOEO> &pop, partition_map &split_frequences)
{
bool ismp, isml;
isml = isml = false;
double dtp, dtl, maxdl, maxdp, dp, dl;
int n = pop.size();
double best_ml_score, best_mp_score;
string split, split_i;
graph::edge_iterator it, it_e;
//print_media_scores(pop, -1, best_l_idx, best_p_idx);
moeoBestObjVecStat<PhyloMOEO> best_inds;
best_inds(pop);
best_mp_score = (best_inds.value())[0];
best_ml_score = (best_inds.value())[1];
const PhyloMOEO &best_l = best_inds.bestindividuals(1);
const PhyloMOEO &best_p = best_inds.bestindividuals(0);
maxdl = maxdp = 0;
for(int i=0; i<n; i++)
{
dl = dtp = dtl = dp = 0;
isml = ismp = false;
const PhyloMOEO &sol = pop[i];
if(!sol.get_tree().splits_valid())sol.get_tree().calculate_splits_exp();
it = sol.get_tree().TREE.edges_begin();
it_e = sol.get_tree().TREE.edges_end();
// is the mp or ml tree
if( sol.objectiveVector().operator[](1) == best_ml_score) isml=true;
if( sol.objectiveVector().operator[](0) == best_mp_score) ismp= true;
dtl = sol.get_tree().compare_topology_2( best_l.get_tree()) / (2.0*(sol.get_tree().TREE.number_of_edges() - sol.get_tree().number_of_taxons()));
//sol->compare_topology_3( *best_l);
dtp = sol.get_tree().compare_topology_2( best_p.get_tree()) / (2.0*(sol.get_tree().TREE.number_of_edges() - sol.get_tree().number_of_taxons()));
//sol->compare_topology_3( *best_p);
while(it!=it_e)
{
if( sol.get_tree().is_internal( *it))
{
split = sol.get_tree().get_split_key( *it);
split_i = sol.get_tree().get_invert_split_key( *it);
if( split_frequences.find(split) != split_frequences.end() )
{
split_frequences[split].freq++;
split_frequences[split].prob += 1.0/n;
}
else if( split_frequences.find(split_i) != split_frequences.end() )
{
split_frequences[split_i].freq++;
split_frequences[split_i].prob += 1.0/n;
split = split_i;
}
else
{
split_frequences[split].freq = 1;
split_frequences[split].prob = 1.0/n;
}
if( isml )
split_frequences[split].type |= 4; // split belongs ml tree
if( ismp )
split_frequences[split].type |= 2; // split belongs mp tree
if( !(isml || ismp)) split_frequences[split].type |= 1; // split belong intermediate
dp = sol.objectiveVector().operator[](0) - best_mp_score;
dl = sol.objectiveVector().operator[](1) - best_ml_score;
split_frequences[split].dp += dp;
split_frequences[split].dl += dl;
maxdp = (dp > maxdp ? dp : maxdp);
maxdl = (dl > maxdl ? dl : maxdl);
split_frequences[split].tdp += dtp;
split_frequences[split].tdl += dtl;
}
++it;
}
//sol->invalidate_splits();
sol.get_tree().remove_split_memory();
}
partition_map::iterator it1 = split_frequences.begin();
partition_map::iterator it2 = split_frequences.end();
while(it1!=it2)
{
if(maxdp!=0) (*it1).second.dp /= (1.0*(*it1).second.freq*maxdp);
if(maxdl!=0)(*it1).second.dl /= (1.0*(*it1).second.freq*maxdl);
(*it1).second.tdp /= (1.0*(*it1).second.freq);
(*it1).second.tdl /= (1.0*(*it1).second.freq);
++it1;
}
}
};
std::string inverse_split( string split )
{
string s;
string::iterator it1 = split.begin();
string::iterator it2 = split.end();
while(it1!= it2)
{
s += *it1 == '*' ? '.' : '*';
++it1;
}
return s;
}
std::ostream & operator<<(std::ostream & _os, const partition_map & _map) {
partition_map::const_iterator it1 = _map.begin();
partition_map::const_iterator it2 = _map.end();
_os << _map.size() << endl;
_os.setf(ios::fixed);
while(it1!=it2)
{
_os <<
((*it1).second.inverse ? inverse_split((*it1).first) : (*it1).first)
<< '\t' << (*it1).second.freq << '\t' << (*it1).second.prob << '\t'
<< (*it1).second.dp << '\t' << (*it1).second.dl << '\t'
<< (*it1).second.tdp << '\t' << (*it1).second.tdl << '\t' << (*it1).second.type << endl;
++it1;
}
return _os;
}
std::istream & operator>>(std::istream & _is, const partition_map & _map) { std::cout << "not implemented\n"; return _is; }
#endif

View file

@ -0,0 +1,35 @@
/***************************************************************************
* Copyright (C) 2008 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef PHYLOMOEOPROBMATRIXCONTAINERUPDATER_H_
#define PHYLOMOEOPROBMATRIXCONTAINERUPDATER_H_
#include <probmatrixcontainer.h>
class PhyloMOEOProbMatrixContainerUpdater: public eoUpdater
{
public:
PhyloMOEOProbMatrixContainerUpdater(ProbMatrixContainer &_pm): pm(_pm) {}
void operator() () { pm.clear(); }
void lastCall() { operator()(); };
private:
ProbMatrixContainer &pm;
};
#endif

View file

@ -0,0 +1,108 @@
/***************************************************************************
* Copyright (C) 2008 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef PHYLOMOEO_ARCHIVE_H
#define PHYLOMOEO_ARCHIVE_H
#include <PhyloMOEA/PhyloMOEO.h>
typedef moeoArchive<PhyloMOEO> PhyloMOEOArchive;
typedef PhyloMOEOArchive PhyloMOEOPFArchive;
class PhyloMOEOParetoSolutionsArchive:public moeoArchive<PhyloMOEO>
{
public:
void save_trees( std::string filename, string title="" )
{
create_file( filename );
if(title.size()>0) os << title << endl;
os << size() << std::endl;
for(int i=0; i<size(); i++)
operator[](i).get_tree().printNewick(os);
os.close();
}
void save_scores( std::string filename, string title = "" )
{
create_file( filename );
if(title.size()>0) os << title << endl;
for(int i=0; i<size(); i++)
os << operator[](i) << std::endl;
os.close();
}
protected:
std::ofstream os;
private:
void create_file( std::string filename)
{
os.open(filename.c_str());
if (!os){
std::string str = "Could not open " + filename;
throw std::runtime_error(str);
}
}
};
class PhyloMOEODummyArchive:public PhyloMOEOParetoSolutionsArchive
{
public:
void update(const eoPop < PhyloMOEO > & _pop)
{
std::copy(_pop.begin(), _pop.end(), back_inserter(*this) );
}
};
class PhyloMOEOFinalSolutionsArchive: public PhyloMOEOParetoSolutionsArchive
{
public:
void update(const eoPop < PhyloMOEO > & _pop)
{
std::copy(_pop.begin(), _pop.end(), back_inserter(*this) );
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
for(int i=0; i< size()-1; i++)
{
//cout << (i+1)/(p.currentSize()*1.0) << "%" << endl;
for(int j=i+1; j< size(); j++)
{
phylotreeIND &sol = operator[](i).get_tree();
phylotreeIND &sol_2 = operator[](j).get_tree();
if( sol.compare_topology_2( sol_2) == 0)
{
if( paretoComparator( operator[](i).objectiveVector(), operator[](j).objectiveVector() ) )
{
operator[](i) = back();
pop_back();
i--; j = size();
}
else
{
operator[](j) = back();
pop_back();
j--;
}
}
}
}
}
};
#endif

View file

@ -0,0 +1,55 @@
/***************************************************************************
* Copyright (C) 2008 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef PHYLOMOEO_EVAL_H_
#define PHYLOMOEO_EVAL_H_
#include <PhyloMOEO.h>
#include <parsimonycalculator.h>
#include <likelihoodcalculator.h>
class PhyloEval : public moeoEvalFunc < PhyloMOEO >
{
public:
PhyloEval( ParsimonyCalculator &x, LikelihoodCalculator &y): parseval(x), likeval(y) { }
void operator () (PhyloMOEO & _sol)
{
if (_sol.invalidObjectiveVector())
{
ObjectiveVector objVec;
//if(! (_sol.get_tree().splits_valid() ) ) _sol.get_tree().calculate_splits();
parseval.set_tree(_sol.get_tree());
likeval.set_tree(_sol.get_tree());
//objVec[0] = 1;
//objVec[1] = 1;
objVec[0] = parseval.fitch();
objVec[1] = -likeval.calculate_likelihood();
_sol.objectiveVector(objVec);
}
}
private:
LikelihoodCalculator &likeval;
ParsimonyCalculator &parseval;
};
#endif

View file

@ -0,0 +1,51 @@
/***************************************************************************
* Copyright (C) 2008 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef PHYLOMOEO_INIT_H_
#define PHYLOMOEO_INIT_H_
#include <PhyloMOEO.h>
class Phyloraninit : public eoInit <PhyloMOEO>
{
public:
Phyloraninit(phylotreeIND &templatetree): tree(templatetree) { }
void operator()(PhyloMOEO &ind)
{
ind.set_random_tree(tree);
}
private:
phylotreeIND &tree;
};
class Phylonewickinit : public eoInit <PhyloMOEO>
{
public:
Phylonewickinit(std::string newick): tree_string(newick) { }
void operator()(PhyloMOEO &ind)
{
phylotreeIND &tree = ind.get_tree();
tree.read_newick2( tree_string );
}
private:
std::string tree_string;
};
#endif

View file

@ -0,0 +1,61 @@
/***************************************************************************
* Copyright (C) 2008 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _PHYLOMOEO_OPERATORS_H_
#define _PHYLOMOEO_OPERATORS_H_
#include <PhyloMOEO.h>
class Phylocross : public eoQuadOp < PhyloMOEO >
{
public:
/**
* the class name (used to display statistics)
*/
std::string className() const { return "Phylocross"; } ;
bool operator()(PhyloMOEO & _tree1, PhyloMOEO & _tree2)
{
phylotreeIND parent_1(_tree1.get_tree());
phylotreeIND parent_2(_tree2.get_tree());
phylotreeIND &son1 = _tree1.get_tree();
phylotreeIND &son2 = _tree2.get_tree();
parent_1.export_subtree( son2 );
parent_2.export_subtree( son1 );
parent_1.invalidate_splits();
parent_2.invalidate_splits();
return true;
}
};
class Phylomutate : public eoMonOp <PhyloMOEO>
{
public:
std::string className() const { return "Phylomut"; }
bool operator() (PhyloMOEO & _tree)
{
_tree.get_tree().mutate(1);
return true;
}
};
#endif

View file

@ -0,0 +1,178 @@
/***************************************************************************
* Copyright (C) 2005 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "ProbMatrix.h"
#include <cmath>
#include <matrixutils.h>
gsl_cheb_series ** ProbMatrix::cs = NULL;
double f_pij(double x, void *p)
{
struct params *ij = (struct params *)p;
ij->pmatrix->set_branch_length(x);
return ij->pmatrix->p_ij_t(ij->i,ij->j);
}
ProbMatrix::ProbMatrix(SubstModel *m, double bl)
{
model = m;
branchlenght = bl;
calculate_derivate=false;
p = new double[4*4];
p1d = new double[4*4];
p2d = new double[4*4];
tmpexp = new double[4*4];
}
/*
void ProbMatrix::init()
{
struct params par;
double tmpbl = branchlenght;
int k=0;
// first call
gsl_function F;
F.function = f_pij;
F.params = &par;
if(cs == NULL)
{
std::cout << "initializaing polynomials...\n";
cs = new gsl_cheb_series*[16];
calculatepmatrix();
// calculate chevchevy polynomials
for(int i=0; i<4; i++)
for(int j=0;j<4;j++)
{
cs[k] = gsl_cheb_alloc(8);
par.pmatrix = this;
par.i = i; par.j = j;
gsl_cheb_init (cs[k], &F, 0.0, 1.0);
k++;
}
}
//restore the original branch lenght
branchlenght = tmpbl;
calculatepmatrixchev();
}*/
void ProbMatrix::init_derivate()
{
if(calculate_derivate)return;
calculate_p1d_matrix();
calculate_p2d_matrix();
calculate_derivate=true;
}
// set a new branch lenght and recalculate the probability matrix
void ProbMatrix::set_branch_length(double t)
{
// save time if t = older branch lenght
if ( branchlenght != t)
{
branchlenght = t;
calculatepmatrix();
calculate_p1d_matrix();
calculate_p2d_matrix();
}
calculate_derivate=false;
}
// calculate the matrix P = evec*diag( e^eigenvalues )*ievec
void ProbMatrix::calculatepmatrix()
{
double temp;
double **xevec = model->eigensystem->eigenvectors();
double *xeval = model->eigensystem->eigenvalues();
double **xievec = (double **)model->ievec;
//diag( e^eigenvalues )*ievec
for (int i = 0; i < 4; i++)
{
temp = exp( branchlenght * xeval[i] );
for (int j = 0; j < 4; j++)
tmpexp[i*4+j] = xievec[i][j]*temp;
}
// P matrix
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
temp = 0.0;
for (int k = 0; k < 4; k++)
temp += xevec[i][k] * tmpexp[k*4+j];
p[i*4+j] = fabs(temp);
}
}
}
void ProbMatrix::calculatepmatrixchev()
{
int k=0;
for(int i=0; i<4; i++)
for(int j=0; j<4; j++)
{
p[i*4+j] = gsl_cheb_eval(cs[i*4+j], branchlenght);
k++;
}
}
// matrix Q*P
void ProbMatrix::calculate_p1d_matrix()
{
double temp;
double *q=model->rate;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
temp = 0.0;
for (int k = 0; k < 4; k++)
temp += q[i*4+k] * p[k*4+j];
p1d[i*4+j] = temp;
}
}
}
// calculate Q^2*P
void ProbMatrix::calculate_p2d_matrix()
{
double temp;
double *q=model->rate;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
temp = 0.0;
for (int k = 0; k < 4; k++)
temp += q[i*4+k]*p1d[i*4+k];
p2d[i*4+j] = temp;
}
}
}

View file

@ -0,0 +1,64 @@
/***************************************************************************
* Copyright (C) 2005 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef PROBMATRIX_H
#define PROBMATRIX_H
#include "SubsModel.h"
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_chebyshev.h>
#include <map>
// store a set of the probability matric according some brach-lenght
class ProbMatrix
{
private:
SubstModel *model;
double branchlenght;
double *tmpexp;
static gsl_cheb_series **cs;
bool calculate_derivate;
void calculatepmatrix();
void calculatepmatrixchev();
void calculate_p1d_matrix();
void calculate_p2d_matrix();
public:
double *p, *p1d, *p2d;
ProbMatrix( SubstModel *m, double bl );
~ProbMatrix() { delete [] tmpexp; delete [] p; delete [] p1d; delete [] p2d; }
inline void init() { calculatepmatrix(); }
//void init();
void init_derivate();
inline double p_ij_t(int i, int j) { return p[i*4+j]; }
inline double p1d_ij_t(int i, int j) { return p1d[i*4+j]; }
inline double p2d_ij_t(int i, int j) { return p2d[i*4+j]; }
void set_branch_length(double l);
};
struct params { ProbMatrix *pmatrix; int i; int j; };
#endif

View file

@ -0,0 +1,238 @@
/*******************************************************************************
RandomNr.cpp
last change: 01/20/1999
version: 0.0.0
design: Eckart Zitzler
Paul E. Sevinc
implementation: Paul E. Sevinc
(c) 1998-1999: Computer Engineering and Networks Laboratory
Swiss Federal Institute of Technology Zurich
description:
See RandomNr.h
*******************************************************************************/
#include "RandomNr.h"
#include <climits>
#include <cstddef>
#include <ctime>
#include <cmath>
#include <iostream>
using namespace std;
static long idum2=123456789;
static long iy=0;
static long iv[NTAB];
static long idum=0;
RandomNr::RandomNr()
{
z = static_cast< long >( time( 0 ) ); // see <ctime>
iy = idum = 0;
sran1(z);
}
RandomNr::RandomNr( long seed )
: z( seed )
{
sran2(seed);
}
void
RandomNr::setSeed( long seed )
{
z = seed;
sran2(seed);
}
double
RandomNr::uniform01()
{
// see Reiser, Martin / Wirth, Niklaus.
// - Programming in Oberon: Steps beyond Pascal and Modula.
const int a = 16807,
m = LONG_MAX, // see <climits> - replace by
// numeric_limits< long >::max()
// when <limits> is available
q = m / a,
r = m % a;
long gamma;
gamma = a * ( z % q ) - r * ( z / q );
z = ( gamma > 0 ) ? gamma : ( gamma + m );
return z * ( 1.0 / m );
// NOTE: we're in trouble if at some point z becomes -LONG_MAX, 0, or LONG_MAX...
}
void
RandomNr::sran1(unsigned int seed) {
int j;
long k;
idum = seed;
if (idum == 0) idum=1;
if (idum < 0) idum = -idum;
for (j=NTAB+7;j>=0;j--) {
k=(idum)/IQ;
idum=IA*(idum-k*IQ)-IR*k;
if (idum < 0) idum += IM;
if (j < NTAB) iv[j] = idum;
}
iy=iv[0];
}
double
RandomNr::ran1() {
int j;
long k;
double temp;
k=(idum)/IQ;
idum=IA*(idum-k*IQ)-IR*k;
if (idum < 0) idum += IM;
j=iy/NDIV;
iy=iv[j];
iv[j] = idum;
if ((temp=AM*iy) > RNMX) return RNMX;
else return temp;
}
void
RandomNr::sran2(unsigned int seed) {
int j;
long k;
idum = static_cast<long>(seed);
if (idum == 0) idum=1;
if (idum < 0) idum = -idum;
idum2=(idum);
for (j=NTAB+7;j>=0;j--) {
k=(idum)/IQ1;
idum=IA1*(idum-k*IQ1)-k*IR1;
if (idum < 0) idum += IM1;
if (j < NTAB) iv[j] = idum;
}
iy=iv[0];
}
double
RandomNr::ran2() {
int j;
long k;
float temp;
k=(idum)/IQ1;
idum=IA1*(idum-k*IQ1)-k*IR1;
if (idum < 0) idum += IM1;
k=idum2/IQ2;
idum2=IA2*(idum2-k*IQ2)-k*IR2;
if (idum2 < 0) idum2 += IM2;
j=iy/NDIV;
iy=iv[j]-idum2;
iv[j] = idum;
if (iy < 1) iy += IMM1;
if ((temp=AM*iy) > RNMX) {
return RNMX;
}
else{
return temp;
}
}
bool
RandomNr::flipP( double p )
{
return ran2() < p ? true : false;
}
unsigned int
RandomNr::uniform0Max( unsigned int max ) // exclusive
{
return static_cast< unsigned short >( max * ran2() );
}
int
RandomNr::uniformMinMax( int min, // inclusive
int max ) // exclusive
{
return min >= 0
? static_cast< int >( min + ( max - min ) * ran2() )
: static_cast< int >( min - 1 + ( max - min ) * ran2() );
}
int
RandomNr::gaussMinMax( int min, // inclusive
int max ) // exclusive
{
double tmp = UnitGaussian();
if ((max*tmp > max) || ( max*tmp < min))
{
return max;
}
return min >= 0
? static_cast< int >( max * tmp )
: static_cast< int >( max * tmp );
}
double
RandomNr::doubleuniformMinMax( double min, // inclusive
double max ) // exclusive
{
return static_cast< double >( min + ( max - min ) * ran2() );
}
double RandomNr::UnitGaussian(){
static int cached=0;
static double cachevalue;
if(cached == 1){
cached = 0;
return cachevalue;
}
double rsquare, factor, var1, var2;
do{
var1 = 2.0 * ran2() - 1.0;
var2 = 2.0 * ran2() - 1.0;
rsquare = var1*var1 + var2*var2;
} while(rsquare >= 1.0 || rsquare == 0.0);
double val = -2.0 * log(rsquare) / rsquare;
if(val > 0.0) factor = sqrt(val);
else factor = 0.0; // should not happen, but might due to roundoff
cachevalue = var1 * factor;
cached = 1;
return (var2 * factor);
}
void RandomNr::resumo(){
cout << "semilla =" << z << endl;
}

View file

@ -0,0 +1,116 @@
/*******************************************************************************
RandomNr.h
last change: 01/20/1999
version: 0.0.0
design: Eckart Zitzler
Paul E. Sevinc
implementation: Paul E. Sevinc
(c) 1998-1999: Computer Engineering and Networks Laboratory
Swiss Federal Institute of Technology Zurich
description:
RandomNr is a helper class for pseudo-random number
generation that doesn't need to be subclassed unless
one wants to replace the algorithm used or add
another method.
Usually, one only instance per optimization problem
is necessary, and classes or functions that make use
of random numbers keep a reference to that instance.
*******************************************************************************/
#ifndef RANDOM_NR_H
#define RANDOM_NR_H
#include <cstddef>
//#include "TIKEAFExceptions.h"
#define IM1 2147483563L
#define IM2 2147483399L
#define AM (1.0/IM1)
#define IMM1 (IM1-1)
#define IA1 40014L
#define IA2 40692L
#define IQ1 53668L
#define IQ2 52774L
#define IR1 12211L
#define IR2 3791
#define NTAB 32
#define NDIV (1+IMM1/NTAB)
#define EPS 1.2e-7
#define RNMX (1.0-EPS)
#define IA 16807L
#define IM 2147483647L
//#define AM (1.0/IM)
#define IQ 127773L
#define IR 2836L
//#define NTAB 32
//#define NDIV (1+(IM-1)/NTAB)
//#define EPS 1.2e-7
//#define RNMX (1.0-EPS)
//typedef unsigned int size_t;
/*static long iy = 0;
static long iv[NTAB];
static long idum = 0;*/
class RandomNr
{
protected:
long z;
public:
// use the current time as seed
RandomNr();
// use the argument as seed
RandomNr( long );
void setSeed( long );
virtual ~RandomNr() {};
// return the next uniformly distributed
// random real in ]0; 1[
virtual double uniform01();
// return the next uniformly distributed
// random integer in [Min; Max[
int uniformMinMax( int, int );
// throw ( LimitsException );
double doubleuniformMinMax(double, double);
int gaussMinMax(int, int ); // exclusive
double UnitGaussian();
// return the next uniformly distributed
// random integer (size_t) in [0; Max[
unsigned int uniform0Max( unsigned int );
// throw ( LimitsException );
// flip an unfair coin (head is up with
// probability P), return true if head
// is up and false otherwise
bool flipP( double );
//throw ( ProbabilityException );
void sran1(unsigned int seed);
double ran1();
void sran2(unsigned int seed);
double ran2();
void resumo();
long get_seed() { return z; }
};
#endif

View file

@ -0,0 +1,276 @@
/***************************************************************************
* Copyright (C) 2005 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <Sequences.h>
#include <iostream>
#include <fstream>
#include <map>
#include "assert.h"
#include <ExceptionManager.h>
void Sequences::list_taxons() const {
std::cout << "lista de taxons" << std::endl;
for(int i=0; i< seqnames.size(); i++)
std::cout << seqnames[i] << std::endl;
}
using namespace std;
Sequences::Sequences(const char *fn)
{
numseqs = 0;
seqlen = 0;
seqs = NULL;
fstream fin;
string tmpseq;
// ambiguos characters
meaning[0][0] = meaning[0][1] = 1; meaning[0][2] = meaning[0][3] = meaning[0][4] = 0; // M
meaning[1][0] = meaning[1][2] = 1; meaning[1][1] = meaning[1][3] = meaning[1][4] = 0; // R
meaning[2][0] = meaning[2][3] = 1; meaning[2][1] = meaning[2][2] = meaning[2][4] = 0; // W
meaning[3][1] = meaning[3][2] = 1; meaning[3][0] = meaning[3][3] = meaning[3][4] = 0; // S
meaning[4][1] = meaning[4][3] = 1; meaning[4][0] = meaning[4][2] = meaning[4][4] = 0; // Y
meaning[5][2] = meaning[5][3] = 1; meaning[5][0] = meaning[5][1] = meaning[5][4] = 0; // K
meaning[6][0] = meaning[6][1] = meaning[6][2] = 1 ; meaning[6][3] = meaning[6][4] = 0; // V
meaning[7][0] = meaning[7][1] = meaning[7][3] = 1 ; meaning[7][2] = meaning[7][4] = 0; // H
meaning[8][0] = meaning[8][2] = meaning[8][3] = 1 ; meaning[8][1] = meaning[8][4] = 0; // D
meaning[9][1] = meaning[9][2] = meaning[9][3] = 1 ; meaning[9][0] = meaning[9][4] = 0; // B
meaning[10][1] = meaning[10][2] = meaning[10][3] = meaning[10][0] = 0; meaning[10][4] = 1; // gap
meaning[11][1] = meaning[11][2] = meaning[11][3] = meaning[11][0] = 1; meaning[11][4] = 0; // undefined
// open the file for reading
try{
fin.open(fn, ios::in);
if(!fin.is_open())
{
cout << "\n" << fn << endl;
throw ExceptionManager(10);
}
// read numseq and seqlen
if(!(fin >> numseqs >> seqlen))
{
throw ExceptionManager(11);
}
seqs = new unsigned char[numseqs*seqlen];
seqnames.resize(numseqs);
for(int i=0; i < numseqs; i++)
{
fin >> seqnames[i];
fin >> tmpseq;
for(int j=0; j<seqlen; j++)
{
switch(toupper(tmpseq[j]))
{
case 'A': seqs[i*seqlen+j] = 0; break;
case 'C': seqs[i*seqlen+j] = 1; break;
case 'G': seqs[i*seqlen+j] = 2; break;
case 'T': seqs[i*seqlen+j] = 3; break;
case 'M': seqs[i*seqlen+j] = 4; break;
case 'R': seqs[i*seqlen+j] = 5; break;
case 'W': seqs[i*seqlen+j] = 6; break;
case 'S': seqs[i*seqlen+j] = 7; break;
case 'Y': seqs[i*seqlen+j] = 8; break;
case 'K': seqs[i*seqlen+j] = 9; break;
case 'V': seqs[i*seqlen+j] = 10; break;
case 'H': seqs[i*seqlen+j] = 11; break;
case 'D': seqs[i*seqlen+j] = 12; break;
case 'B': seqs[i*seqlen+j] = 13; break;
case '-': seqs[i*seqlen+j] = 14; break; // gap character
case '?':
case 'X':
case 'N' :
case 'O' : seqs[i*seqlen+j] = 15; break; // undefined character
default :
{
cout << "invalid character:" << tmpseq[j] << " seq:" << seqnames[i] << " column " << j << endl;
throw ExceptionManager(11);
assert(1==0); break; // invalid character
}
}
}
}
}
catch( ExceptionManager e)
{
e.Report();
}
fin.close();
}
int Sequences::search_taxon_name(std::string &s) const
{
int i;
for(i=numseqs-1; i>=0 && seqnames[i].substr(0,10)!=s; i--);
return i;
}
// return true is the site is informative
bool Sequences::is_informative(unsigned int col) const
{
unsigned char temp[16];
int sum = 0;
memset( temp, 0, 16*sizeof(unsigned char));
for(int j=0; j< numseqs; j++)
{
// check if the site is repeated
unsigned char l = (*this)[j][col]; //SeqData->pattern_pos(i,j);
if( temp[l] == 0)
{
temp[l] = 1; sum++;
}
}
// informative sites have at least two differents chars
return(sum > 1);
}
void Sequences::calculate_patterns()
{
// map pattern and index in the vector pattern
num_patterns=num_inf_sites=0;
map<string, int> pattern_map;
struct PatternInfo p;
string s;
for(int i=0; i< seqlen; i++)
{
s = position(i);
//if(s.find('?',0)== string::npos)cout << i << endl;
// new pattern
if( pattern_map.find(s) == pattern_map.end() )
{
pattern_map[s] = num_patterns;
p.idx = i;
p.count = 1;
patterns.push_back(p);
// calculate informative site
if( is_informative(i) )
{
inf_sites.push_back(num_patterns);
num_inf_sites++;
}
num_patterns++;
}
// old pattern
else
patterns[ pattern_map[s] ].count++;
}
//cout << "Padrones reconhecidos:" << num_patterns << endl;
//cout << "Sites informativos :" << num_inf_sites << endl;
}
void Sequences::calculate_frequences()
{
long num_undefined = 0; // number of undefined positions
freqs[0] = freqs[1] = freqs[2] = freqs[3] = 0.25;
double tmp[4];
double divisor;
// i don't know why most program do this
for(int m=0; m<8; m++)
{
tmp[0] = tmp[1] = tmp[2] = tmp[3] = 0;
for(int i=0; i< num_patterns; i++)
for(int j=0; j< numseqs; j++)
{
unsigned char l = pattern_pos(i,j);
if ( is_ambiguous(l) )
{
divisor = 0;
for(int k=0; k<4; k++)
divisor += ambiguos_meaning(l)[k] * freqs[k];
for(int k=0; k<4; k++)
tmp[k] +=
(ambiguos_meaning(l)[k]*freqs[k]/divisor)*
patterns[i].count;
}
else if( is_undefined(l) || is_gap(l) )
for(int k=0; k<4; k++) tmp[k] += freqs[k]*patterns[i].count;
else
tmp[l] += patterns[i].count;
}
for(int k=0; k<4; k++) freqs[k] = tmp[k] / (tmp[0]+tmp[1]+tmp[2]+tmp[3]);
}
// final frequences
//for(int i=0; i<4; i++){
// cout << "frequencia de " << i << " -->:" << freqs[i] << endl;
//}
// cout << "suma de frequencias:" << freqs[0] + freqs[1] + freqs[2] + freqs[3] << endl;
}
// get the
string Sequences::position(int pos)
{
string column;
unsigned char c;
char nucleotide;
for(int i=0; i < numseqs; i++)
{
c = seq_pos(i, pos);
switch(c)
{
case 0: nucleotide = 'A'; break;
case 1: nucleotide = 'C'; break;
case 2: nucleotide = 'G'; break;
case 3: nucleotide = 'T'; break;
case 4: nucleotide = 'M'; break;
case 5: nucleotide = 'R'; break;
case 6: nucleotide = 'W'; break;
case 7: nucleotide = 'S'; break;
case 8: nucleotide = 'Y'; break;
case 9: nucleotide = 'K'; break;
case 10: nucleotide = 'V'; break;
case 11: nucleotide = 'H'; break;
case 12: nucleotide = 'D'; break;
case 13: nucleotide = 'B'; break;
case 14: nucleotide = '-'; break;
case 15: nucleotide = '?'; break;
default: assert(1==0); break;
}
column+=nucleotide;
}
return column;
}
void Sequences::save_seq_data(ostream &of=cout)
{
of << "\nSequence Datafile Statistics\n";
of << "----------------------------------------------\n";
of << "Number of Sequences : " << this->numseqs << endl;
of << "Sequence Length : " << this->seqlen << endl;
of << "Number of Patterns : " << this->num_patterns << endl;
of << "Frequency A : " << this->freqs[0] << endl;
of << "Frequency C : " << this->freqs[1] << endl;
of << "Frequency G : " << this->freqs[2] << endl;
of << "Frequency T : " << this->freqs[3] << endl;
}

View file

@ -0,0 +1,89 @@
/***************************************************************************
* Copyright (C) 2005 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef SEQUENCES_H
#define SEQUENCES_H
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <cstring>
// class to store the sequences in a file
struct PatternInfo
{
int idx;
int count;
};
class Sequences
{
private:
//enum nucleotides = { A, C, G, T};
unsigned int num_patterns;
unsigned int num_inf_sites;
unsigned int numseqs;
unsigned int seqlen;
unsigned char *seqs;
std::vector<std::string> seqnames;
std::vector<struct PatternInfo> patterns;
std::vector<unsigned int> inf_sites;
unsigned char meaning[12][5];
double freqs[4];
bool is_informative(unsigned int col) const;
public:
inline unsigned char* operator[](int n) const { return &(seqs[n*seqlen]); }
Sequences(const char *filename);
~Sequences() {
delete [] seqs;
}
inline unsigned char seq_pos( int i, int j) const { return (*this)[i][j]; }
inline unsigned char pattern_pos(int i, int j) const
{ return seq_pos( j, patterns[i].idx); }
inline unsigned char infsite_pos(int i, int j) const
{ return pattern_pos( inf_sites[i], j); }
std::string position(int i);
inline int num_seqs() const { return numseqs; }
inline int seq_len() const { return seqlen; }
inline int pattern_count() const { return num_patterns; }
inline int pattern_count(int i) const { return patterns[i].count; }
inline int infsite_count() const { return num_inf_sites; }
inline int infsite_count(int i) const { return patterns[inf_sites[i]].count; }
inline double *frequences() { return freqs; }
inline double frequence(int i) const { return freqs[i]; }
inline std::string seqname(int i) const { return seqnames.at(i); }
inline bool is_defined(short int l) const { return l<4; }
inline bool is_ambiguous(short int l) const { return (l>3 && l<14); }
inline bool is_gap(short int l) const { return (l == 14); }
inline bool is_undefined(short int l) const { return (l ==15); }
inline std::vector<struct PatternInfo>& get_patterns() { return patterns; }
inline unsigned char* ambiguos_meaning(short int l) const { return
(unsigned char*) meaning[l-4]; }
void list_taxons() const;
int search_taxon_name(std::string &s) const;
void calculate_patterns();
void calculate_frequences();
void save_seq_data(std::ostream &of);
};
#endif

View file

@ -0,0 +1,214 @@
/***************************************************************************
* Copyright (C) 2005 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "SubsModel.h"
//#include <iostream>
using namespace std;
SubstModel::SubstModel(Sequences &p, int m)
{
model = m;
patterns = &p;
eigensystem = NULL;
patterns->calculate_frequences();
frequences = patterns->frequences();
kappa = 4;
//kappa = 32.451;
a=b=c=d=e=1;
ievec = new double*[4];
for(int i=0; i<4; i++)ievec[i] = new double[4];
}
void SubstModel::init()
{
init_rate_matrix();
switch(model)
{
case JC69:
jc69();break;
case F81:
f81();break;
case K2P:
k2p();break;
case HKY85:
hky85();break;
case GTR:
gtr();break;
default:
{
model = 1;
f81(); break;
}
}
// calculate eigenvalues and eigenvectors
if(eigensystem!=NULL)delete eigensystem;
eigensystem = new EigenSolver(rate, 4);
eigensystem->solve();
// calculat inverse eigenvectors
luinverse(eigensystem->eigenvectors(), ievec, NUM_AA);
}
void SubstModel::init_rate_matrix()
{
rate[0] = rate[1] = rate[2] = rate[3] =
rate[4] = rate[5] = rate[6] = rate[7] =
rate[8] = rate[9] = rate[10] = rate[11] =
rate[12] = rate[13] = rate[14] = rate[15] = 1.0;
}
void SubstModel::construct_rate_matrix()
{
// multiply the off-diagonal elements by the frequences
mult_frequences();
// calculate digonal elements
set_diagonal();
// normalize the rate matrix
normalize();
}
// multiple the off-diagonal elementes by the frequences
void SubstModel::mult_frequences()
{
for (int i = 0; i < 4; i++) {
for (int j = i+1; j < 4; j++) {
set_rate(i,j, get_rate(i,j) * frequences[j]);
set_rate(j,i, get_rate(j,i) * frequences[i]);
}
}
}
void SubstModel::set_diagonal()
{
// set the diagonal elements
for(int i=0; i<4; i++)
{
double sum = 0;
for(int j=0; j<4; j++) if(i!=j)sum+=get_rate(i,j);
set_rate(i,i, -sum);
}
}
// normaliza the rate matrix
void SubstModel::normalize()
{
double tmp = 0.0;
for (int i = 0; i < 4; i++)
{
tmp += -get_rate(i,i)*frequences[i];
}
//std::cout << "Rate matrix:" << std::endl;
//std::cout << "----------------------------------" << std::endl;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
set_rate(i,j, get_rate(i,j)/tmp);
//std::cout << get_rate(i,j) << " | ";
}
//std::cout << std::endl;
}
}
void SubstModel::print_rate_matrix()
{
std::cout << "Rate matrix:" << std::endl;
std::cout << "----------------------------------" << std::endl;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
std::cout << get_rate(i,j) << " | ";
}
std::cout << std::endl;
}
}
// useful for models that don't complain about nucleotide frequences
void SubstModel::set_equal_frequences()
{
frequences[0] = frequences[1] = frequences[2] = frequences[3] = 0.25;
}
// initialize the variables and matrizes
void SubstModel::f81()
{
// set the matrix
// parameter mu = 1.0
// nothing to do, only construct the matrix
construct_rate_matrix();
}
void SubstModel::jc69()
{
// set equal frequences
set_equal_frequences();
construct_rate_matrix();
}
void SubstModel::hky85()
{
//cout << "criando hky85 com kappa:" << kappa << endl;
// transition/traversion ratio
set_rate(0,2, kappa);
set_rate(1,3, kappa);
set_rate(2,0, kappa);
set_rate(3,1, kappa);
// multfrequences
construct_rate_matrix();
}
void SubstModel::k2p()
{
// set equal frequences
set_equal_frequences();
// the same of HKY85 except by the equal frequences
hky85();
}
void SubstModel::gtr()
{
a=1.23767538; b=3.58902963;
c=2.16811705; d=0.73102339; e=6.91039679;
set_rate(0,1, a);
set_rate(1,0, a);
set_rate(0,2, b);
set_rate(2,0, b);
set_rate(0,3, c);
set_rate(3,0, c);
set_rate(1,2, d);
set_rate(2,1, d);
set_rate(1,3, e);
set_rate(3,1, e);
// multfrequences
construct_rate_matrix();
}

View file

@ -0,0 +1,74 @@
/***************************************************************************
* Copyright (C) 2005 by Waldo Cancino *
* wcancino@icmc.usp.br *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef SUBSMODEL_H
#define SUBSMODEL_H
// substitution model class
// only nucleotides
#include "eigensolver.h"
#include "Patterns.h"
#include <iostream>
class SubstModel
{
private:
// instantaneus rate matrix 4x4
double rate[16]; // rate matrix
double **ievec; // inverse eigenvectors
double *frequences;
double a,b,c,d,e; // model parameterss
double kappa;
int model;
Sequences *patterns;
EigenSolver *eigensystem;
// define the substituion model
void construct_rate_matrix();
void setsubstmodel( int );
void calculatepmatrix(double);
void mult_frequences();
void set_diagonal();
void normalize();
void set_equal_frequences();
void init_rate_matrix();
void f81();
void k2p();
void jc69();
void hky85();
void gtr();
inline double get_rate(int i, int j) { return rate[4*i+j]; }
inline void set_rate( int i, int j, double val) { rate[4*i +j] = val; }
public:
enum models { JC69, F81, K2P, HKY85, GTR };
friend class ProbMatrix;
~SubstModel() { delete eigensystem; for(int i=0; i<4; i++) delete[] ievec[i]; delete [] ievec; }
SubstModel(Sequences &p, int m = 0);
void init();
void set_kappa(double t) { kappa = t; init(); }
double get_kappa() { return kappa; }
void print_rate_matrix();
};
#endif

Some files were not shown because too many files have changed in this diff Show more