├── test
├── out
│ ├── skip.out
│ ├── README.md
│ ├── 00110_NPDN_fasta.out
│ ├── 00110_NPDN_fasta.exe.out
│ ├── 00120_NPAN_fasta.out
│ ├── 00120_NPAN_fasta.exe.out
│ ├── partial-traversal.out
│ ├── asc-bias.out
│ └── 00010_NMDU_lkcalc.out
├── src
│ ├── pll.h
│ ├── common.h
│ ├── README.md
│ ├── 00120_NPAN_fasta.c
│ ├── hky.c
│ ├── common.c
│ ├── 00110_NPDN_fasta.c
│ ├── 00011_NMAU_lkcalc.c
│ ├── pmatrix.c
│ └── alpha-cats.c
├── .gitignore
├── testwin.sh
├── Makefile.w64
├── eval_valgrind.sh
├── Makefile
└── README.md
├── examples
├── protein-list
│ ├── .gitignore
│ ├── target.mk
│ └── Makefile
├── unrooted
│ ├── .gitignore
│ ├── target.mk
│ ├── Makefile
│ └── README.md
├── newick-fasta-rooted
│ ├── .gitignore
│ ├── target.mk
│ └── Makefile
├── partial-traversal
│ ├── .gitignore
│ ├── target.mk
│ └── Makefile
├── newick-fasta-unrooted
│ ├── .gitignore
│ ├── target.mk
│ └── Makefile
├── stepwise
│ ├── target.mk
│ └── Makefile
├── newton
│ ├── target.mk
│ └── Makefile
├── parsimony
│ ├── target.mk
│ └── Makefile
├── rooted
│ ├── target.mk
│ ├── Makefile
│ └── README.md
├── rooted-tacg
│ ├── target.mk
│ └── Makefile
├── load-utree
│ ├── target.mk
│ ├── Makefile
│ ├── load-utree.c
│ └── README.md
├── newick-export
│ ├── target.mk
│ ├── Makefile
│ └── newick-export.c
├── heterotachy
│ ├── target.mk
│ ├── Makefile
│ └── README.md
├── lg4
│ ├── target.mk
│ ├── data
│ │ ├── example.tree
│ │ └── example.fas
│ └── Makefile
├── newick-phylip-unrooted
│ ├── target.mk
│ └── Makefile
├── Makefile.am
└── README.md
├── autogen.sh
├── .gitignore
├── Makefile.am
├── man
└── Makefile.am
├── src
├── Makefile.am
├── list.c
├── output.c
├── lex_utree.l
├── lex_rtree.l
├── hardware.c
└── compress.c
├── .travis.yml
├── m4
├── ax_check_compile_flag.m4
├── ax_gcc_x86_avx_xgetbv.m4
└── ax_gcc_x86_cpuid.m4
├── configure.ac
└── ChangeLog.md
/test/out/skip.out:
--------------------------------------------------------------------------------
1 | Skip
2 |
--------------------------------------------------------------------------------
/test/src/pll.h:
--------------------------------------------------------------------------------
1 | ../../src/pll.h
--------------------------------------------------------------------------------
/examples/protein-list/.gitignore:
--------------------------------------------------------------------------------
1 | pl
2 |
--------------------------------------------------------------------------------
/examples/unrooted/.gitignore:
--------------------------------------------------------------------------------
1 | unrooted
2 |
--------------------------------------------------------------------------------
/examples/newick-fasta-rooted/.gitignore:
--------------------------------------------------------------------------------
1 | nfr
2 |
--------------------------------------------------------------------------------
/examples/partial-traversal/.gitignore:
--------------------------------------------------------------------------------
1 | partial
2 |
--------------------------------------------------------------------------------
/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | autoreconf --force --install
3 |
--------------------------------------------------------------------------------
/examples/newick-fasta-unrooted/.gitignore:
--------------------------------------------------------------------------------
1 | nfu
2 |
3 |
--------------------------------------------------------------------------------
/test/.gitignore:
--------------------------------------------------------------------------------
1 | obj
2 | testdata
3 | tmp
4 | tmperr
5 | result
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | src/libpll.so
2 | src/parse_rtree.h
3 | src/parse_utree.h
4 | src/parse_phylip.h
5 | *.o$
6 | *.so
7 |
--------------------------------------------------------------------------------
/examples/stepwise/target.mk:
--------------------------------------------------------------------------------
1 | stepwisedir = $(docdir)/examples/stepwise
2 | dist_stepwise_DATA = stepwise/stepwise.c stepwise/Makefile
3 |
--------------------------------------------------------------------------------
/examples/newton/target.mk:
--------------------------------------------------------------------------------
1 | newtondir = $(docdir)/examples/newton
2 | dist_newton_DATA = newton/newton.c newton/Makefile newton/README.md
3 |
--------------------------------------------------------------------------------
/examples/parsimony/target.mk:
--------------------------------------------------------------------------------
1 | parsimonydir = $(docdir)/examples/parsimony
2 | dist_parsimony_DATA = parsimony/npr-pars.c parsimony/Makefile
3 |
--------------------------------------------------------------------------------
/examples/rooted/target.mk:
--------------------------------------------------------------------------------
1 | rooteddir = $(docdir)/examples/rooted
2 | dist_rooted_DATA = rooted/rooted.c rooted/Makefile rooted/README.md
3 |
--------------------------------------------------------------------------------
/examples/rooted-tacg/target.mk:
--------------------------------------------------------------------------------
1 | rooted_tacgdir = $(docdir)/examples/rooted-tacg
2 | dist_rooted_tacg_DATA = rooted-tacg/rooted-tacg.c rooted-tacg/Makefile
3 |
--------------------------------------------------------------------------------
/examples/unrooted/target.mk:
--------------------------------------------------------------------------------
1 | unrooteddir = $(docdir)/examples/unrooted
2 | dist_unrooted_DATA = unrooted/unrooted.c unrooted/Makefile unrooted/README.md
3 |
--------------------------------------------------------------------------------
/Makefile.am:
--------------------------------------------------------------------------------
1 | ACLOCAL_AMFLAGS = -I m4 --install
2 | AUTOMAKE_OPTIONS = foreign
3 | SUBDIRS = src man examples
4 | EXTRA_DIST = autogen.sh ChangeLog.md LICENSE.txt
5 |
--------------------------------------------------------------------------------
/examples/protein-list/target.mk:
--------------------------------------------------------------------------------
1 | protein_listdir = $(docdir)/examples/protein-list
2 | dist_protein_list_DATA = protein-list/protein-list.c protein-list/Makefile
3 |
--------------------------------------------------------------------------------
/examples/load-utree/target.mk:
--------------------------------------------------------------------------------
1 | load_utreedir = $(docdir)/examples/load-utree
2 | dist_load_utree_DATA = load-utree/load-utree.c load-utree/Makefile load-utree/README.md
3 |
--------------------------------------------------------------------------------
/examples/newick-export/target.mk:
--------------------------------------------------------------------------------
1 | newick_exportdir = $(docdir)/examples/newick-export
2 | dist_newick_export_DATA = newick-export/newick-export.c newick-export/Makefile
3 |
--------------------------------------------------------------------------------
/test/testwin.sh:
--------------------------------------------------------------------------------
1 | for f in obj/*.exe; do
2 | OUT=`wine $f > /dev/null`
3 | if [ ! -z "$OUT" ]; then
4 | echo ERROR
5 | exit
6 | fi
7 | done
8 | echo OK!
9 |
--------------------------------------------------------------------------------
/examples/heterotachy/target.mk:
--------------------------------------------------------------------------------
1 | heterotachydir = $(docdir)/examples/heterotachy
2 | dist_heterotachy_DATA = heterotachy/heterotachy.c heterotachy/Makefile heterotachy/README.md
3 |
--------------------------------------------------------------------------------
/examples/partial-traversal/target.mk:
--------------------------------------------------------------------------------
1 | partial_traversaldir = $(docdir)/examples/partial-traversal
2 | dist_partial_traversal_DATA = partial-traversal/partial.c partial-traversal/Makefile
3 |
--------------------------------------------------------------------------------
/examples/newick-fasta-rooted/target.mk:
--------------------------------------------------------------------------------
1 | newick_fasta_rooteddir = $(docdir)/examples/newick-fasta-rooted
2 | dist_newick_fasta_rooted_DATA = newick-fasta-rooted/newick-fasta-rooted.c newick-fasta-rooted/Makefile
3 |
--------------------------------------------------------------------------------
/examples/lg4/target.mk:
--------------------------------------------------------------------------------
1 | lg4dir = $(docdir)/examples/lg4
2 | lg4_datadir = $(docdir)/examples/lg4/data
3 | dist_lg4_DATA = lg4/lg4.c lg4/Makefile
4 | dist_lg4_data_DATA = lg4/data/example.fas lg4/data/example.tree
5 |
--------------------------------------------------------------------------------
/examples/newick-fasta-unrooted/target.mk:
--------------------------------------------------------------------------------
1 | newick_fasta_unrooteddir = $(docdir)/examples/newick-fasta-unrooted
2 | dist_newick_fasta_unrooted_DATA = newick-fasta-unrooted/newick-fasta-unrooted.c newick-fasta-unrooted/Makefile
3 |
--------------------------------------------------------------------------------
/examples/newick-phylip-unrooted/target.mk:
--------------------------------------------------------------------------------
1 | newick_phylip_unrooteddir = $(docdir)/examples/newick-phylip-unrooted
2 | dist_newick_phylip_unrooted_DATA = newick-phylip-unrooted/newick-phylip-unrooted.c newick-phylip-unrooted/Makefile
3 |
--------------------------------------------------------------------------------
/test/out/README.md:
--------------------------------------------------------------------------------
1 | # Expected output for test cases
2 |
3 | For each test case implemented in src/ directory, there must exist here an analogous
4 | file named %.out (where the matching source is %.c) containing the expected output
5 | for the test case.
6 |
7 | When the expected output is set, the developer of the test case must ensure that the
8 | results here are correct, validating the displayed results as required
9 | (e.g., comparing the output with PhyML, RAxML, PAML, etc)
10 |
--------------------------------------------------------------------------------
/man/Makefile.am:
--------------------------------------------------------------------------------
1 | dist_man_MANS=libpll.3
2 |
3 | if HAVE_PS2PDF
4 |
5 | doc_DATA = libpll_manual.pdf
6 |
7 | libpll_manual.pdf : libpll.3
8 | TEMP=$$(mktemp temp.XXXXXXXX) ; \
9 | if [ $$(uname) == "Darwin" ] ; then \
10 | ${SED} -e 's/\\-/-/g' $< | \
11 | iconv -f UTF-8 -t ISO-8859-1 > $$TEMP ; \
12 | else \
13 | ${SED} -e 's/\\-/-/g' $< > $$TEMP ; \
14 | fi ; \
15 | man -t ./$$TEMP | ps2pdf -sPAPERSIZE=a4 - $@ ; \
16 | rm $$TEMP
17 |
18 | CLEANFILES=libpll_manual.pdf
19 |
20 | endif
21 |
--------------------------------------------------------------------------------
/examples/Makefile.am:
--------------------------------------------------------------------------------
1 | include heterotachy/target.mk
2 | include lg4/target.mk
3 | include load-utree/target.mk
4 | include newick-fasta-rooted/target.mk
5 | include newick-fasta-unrooted/target.mk
6 | include newick-phylip-unrooted/target.mk
7 | include newton/target.mk
8 | include parsimony/target.mk
9 | include partial-traversal/target.mk
10 | include protein-list/target.mk
11 | include rooted/target.mk
12 | include rooted-tacg/target.mk
13 | include unrooted/target.mk
14 | include stepwise/target.mk
15 |
--------------------------------------------------------------------------------
/examples/lg4/data/example.tree:
--------------------------------------------------------------------------------
1 | (((((((((((RL11_HUMAN:0.1551800,RL11_DROME:0.0854900):0.0882500,(((RL11_YEAST:
2 | 0.1429600,RL11_SCHPO:0.0875000):0.0873900,RL11_TETTH:0.2339800):0.0652200,
3 | (R111_ARATH:0.0698900,RL11_CHLRE:0.1904000):0.0941200):0.0839000):0.0287300,
4 | RL11_LEICH:0.1414200):0.4521600,((RL5_METJA:0.1374100,RL5_METVA:0.2718300)
5 | :0.1528200,RL5_SULAC:0.3595300):0.0839100):0.0845700,RL5_HALMA:0.3691600)
6 | :0.8932200,RL5_MYCCA:0.1851800):0.1082600,RL5_MYCGE:0.2360800):0.0507100,
7 | RK5_ODOSI:0.6278600):0.0727300,(RL5_BUCAK:0.1570200,RL5_MICLU:0.2811600)
8 | :0.1017400):0.0420600,(RK5_CYAPA:0.1638300,RK5_EUGGR:0.4177100):0.0974800)
9 | :0.0807800,RL5X_THETH:0.2117200,RL5_THEMA:0.2253200);
10 |
--------------------------------------------------------------------------------
/examples/heterotachy/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Diego Darriba
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Diego Darriba ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | PROFILING=-g
21 |
22 | # Compiler warnings
23 | WARN=-Wall -Wsign-compare
24 |
25 | CC = gcc
26 | CFLAGS = -Wall -g -O3 $(WARN)
27 | LINKFLAGS = -L. $(PROFILING)
28 | LIBS=-lpll -lm
29 | PROG=heterotachy
30 |
31 | all: $(PROG)
32 |
33 | OBJS=heterotachy.o
34 |
35 | $(PROG): $(OBJS)
36 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
37 |
38 | %.o: %.c
39 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
40 |
41 | clean:
42 | rm -f *~ $(OBJS) $(PROG)
43 |
--------------------------------------------------------------------------------
/examples/rooted/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=rooted
32 |
33 | all: $(PROG)
34 |
35 | OBJS=rooted.o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS)
39 |
40 | %.o: %.c
41 | $(CC) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/rooted-tacg/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=rooted-tacg
32 |
33 | all: $(PROG)
34 |
35 | OBJS=$(PROG).o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS)
39 |
40 | %.o: %.c
41 | $(CC) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/lg4/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=lg4
32 |
33 | all: $(PROG)
34 |
35 | OBJS=lg4.o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/newton/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=newton
32 |
33 | all: $(PROG)
34 |
35 | OBJS=newton.o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/parsimony/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=npr-pars
32 |
33 | all: $(PROG)
34 |
35 | OBJS=$(PROG).o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/stepwise/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=stepwise
32 |
33 | all: $(PROG)
34 |
35 | OBJS=$(PROG).o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/load-utree/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=load-utree
32 |
33 | all: $(PROG)
34 |
35 | OBJS=load-utree.o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/protein-list/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -I. -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=protein-list
32 |
33 | all: $(PROG)
34 |
35 | OBJS=$(PROG).o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/unrooted/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN) -std=c99
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=unrooted
32 |
33 | all: $(PROG)
34 |
35 | OBJS=unrooted.o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/partial-traversal/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=partial-traversal
32 |
33 | all: $(PROG)
34 |
35 | OBJS=partial.o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/newick-fasta-rooted/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=newick-fasta-rooted
32 |
33 | all: $(PROG)
34 |
35 | OBJS=$(PROG).o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/newick-fasta-unrooted/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=newick-fasta-unrooted
32 |
33 | all: $(PROG)
34 |
35 | OBJS=$(PROG).o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/newick-phylip-unrooted/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=newick-phylip-unrooted
32 |
33 | all: $(PROG)
34 |
35 | OBJS=$(PROG).o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/examples/newick-export/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Tomas Flouri
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Tomas Flouri ,
17 | # Heidelberg Institute for Theoretical Studies,
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | # Profiling
21 | #PROFILING=-g -pg
22 | PROFILING=-g
23 |
24 | # Compiler warnings
25 | WARN=-Wall -Wsign-compare
26 |
27 | CC = gcc
28 | CFLAGS = -Wall -g -O3 -D_GNU_SOURCE $(WARN)
29 | LINKFLAGS = -L. $(PROFILING)
30 | LIBS=-lpll -lm
31 | PROG=newick-export
32 |
33 | all: $(PROG)
34 |
35 | OBJS=newick-export.o
36 |
37 | $(PROG): $(OBJS)
38 | $(CC) $(LINKFLAGS) -o $@ $+ $(LIBS) $(LDFLAGS)
39 |
40 | %.o: %.c
41 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
42 |
43 | clean:
44 | rm -f *~ $(OBJS) gmon.out $(PROG)
45 |
--------------------------------------------------------------------------------
/test/Makefile.w64:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Diego Darriba
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Diego Darriba ,
17 | # Exelixis Lab, Heidelberg Instutute for Theoretical Studies
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | CC = i686-w64-mingw32-gcc
21 | CFLAGS = -g -O3 -Wall -L/usr/local/lib
22 | CLIBS = -lpll -lm
23 |
24 | CFILES = $(wildcard **/*.c)
25 | CFILES = $(shell find src/ -type f -name '*.c' | grep -v travers)
26 | OBJFILES = $(patsubst src/%.c, obj/%.exe, $(CFILES))
27 |
28 | DATADIR = testdata
29 | RESULTDIR = result
30 |
31 | DEPFILES = worms16s.fas small.fas small.tree 246x4465.fas 246x4465.tree \
32 | ribosomal_l5_pf00673.fas
33 | REQFILES = $(patsubst %, $(DATADIR)/%, $(DEPFILES))
34 | ASSETS = https://raw.githubusercontent.com/xflouris/assets/master/libpll
35 |
36 | all: $(OBJFILES) $(REQFILES)
37 | @mkdir -p $(RESULTDIR)
38 |
39 | $(DATADIR)/%:
40 | @mkdir -p "$(@D)"
41 | wget -O $@ $(ASSETS)/$@
42 |
43 | obj/%.exe: src/%.c $(DEPS)
44 | @mkdir -p "$(@D)"
45 | $(CC) $(CPPFLAGS) $(CFLAGS) -D__WIN64__ -o $@ $< $(CLIBS) $(LDFLAGS) -DDATADIR=\"$(DATADIR)\"
46 |
47 | clean:
48 | rm -rf obj
49 |
--------------------------------------------------------------------------------
/test/eval_valgrind.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Copyright (C) 2015 Diego Darriba
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU Affero General Public License as
7 | # published by the Free Software Foundation, either version 3 of the
8 | # License, or (at your option) any later version.
9 | #
10 | # This program 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 Affero General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Affero General Public License
16 | # along with this program. If not, see .
17 | #
18 | # Contact: Diego Darriba ,
19 | # Exelixis Lab, Heidelberg Instutute for Theoretical Studies
20 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
21 | #
22 |
23 | file=$1
24 | timestamp=$2
25 | shift
26 | shift
27 | args=$@
28 |
29 | outfile=tmpvalgrind
30 |
31 | valgrind --tool=memcheck --leak-check=full ${file} ${args} > /dev/null 2> ${outfile}
32 |
33 | deflost=`fgrep "definitely lost:" ${outfile} | xargs | cut -d' ' -f4 | sed "s/,//g"`
34 | indlost=`fgrep "indirectly lost:" ${outfile} | xargs | cut -d' ' -f4 | sed "s/,//g"`
35 | reachable=`fgrep "still reachable:" ${outfile} | xargs | cut -d' ' -f4 | sed "s/,//g"`
36 | errors=`fgrep "Invalid" ${outfile}`
37 |
38 | if [ -z "${deflost}" ]; then deflost=0; fi
39 | if [ -z "${indlost}" ]; then indlost=0; fi
40 | if [ -z "${reachable}" ]; then reachable=0; fi
41 | if [ -z "${errors}" ]; then errors=0; else errors=1; fi
42 |
43 | echo ${deflost} ${indlost} ${reachable} ${errors}
44 |
45 | if [ "$((errors+deflost+indlost+reachable))" -gt "0" ]; then
46 | filename="${file##*/}"
47 | mv ${outfile} result/valgrind_${filename}_${timestamp}
48 | else
49 | rm ${outfile}
50 | fi
51 |
--------------------------------------------------------------------------------
/test/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2015 Diego Darriba
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # Contact: Diego Darriba ,
17 | # Exelixis Lab, Heidelberg Instutute for Theoretical Studies
18 | # Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
19 |
20 | CC = gcc
21 | CFLAGS = -L. -g -O3 -Wall -std=c99
22 | CLIBS = -lpll -lm
23 |
24 | CFILES = $(shell find src -name '*.c' ! -name 'common.c')
25 |
26 | OBJFILES = $(patsubst src/%.c, obj/%, $(CFILES))
27 |
28 | OBJCOMMON = src/common.o
29 |
30 | DATADIR = testdata
31 | RESULTDIR = result
32 |
33 | DEPFILES = worms16s.fas \
34 | small.fas small.tree small.rooted.tree small.rooted.tip.tree \
35 | 246x4465.fas 246x4465.tree \
36 | ribosomal_l5_pf00673.fas ribosomal_l5_pf00673.tree \
37 | medium.fas medium.tree \
38 | 2000.fas 2000.tree \
39 | 200.fas 200.tree \
40 | 1000x5.dna.fas 1000.tree
41 |
42 | REQFILES = $(patsubst %, $(DATADIR)/%, $(DEPFILES))
43 | ASSETS = https://raw.githubusercontent.com/xflouris/assets/master/libpll
44 |
45 | all: $(OBJCOMMON) $(OBJFILES) $(REQFILES)
46 | @mkdir -p $(RESULTDIR)
47 |
48 | $(DATADIR)/%:
49 | @mkdir -p "$(@D)"
50 | wget -O $@ $(ASSETS)/$@
51 |
52 | obj/%: src/%.c $(DEPS)
53 | @mkdir -p "$(@D)"
54 | $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(OBJCOMMON) $(CLIBS) $(LDFLAGS) -DDATADIR=\"$(DATADIR)\"
55 |
56 | %.o: %.c
57 | $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< $(CLIBS) $(LDFLAGS) -DDATADIR=\"$(DATADIR)\"
58 |
59 | clean:
60 | rm -rf obj result/* $(OBJCOMMON)
61 |
--------------------------------------------------------------------------------
/test/src/common.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Diego Darriba, Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Diego Darriba ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 | #ifndef COMMON_H_
22 | #define COMMON_H_
23 |
24 | #ifndef PLL_H_
25 | #define PLL_H_
26 | #include "pll.h"
27 | #endif
28 |
29 | extern const unsigned int odd5_map[256];
30 |
31 | unsigned int get_attributes(int argc, char **argv);
32 | void skip_test();
33 |
34 | pll_partition_t * parse_msa(const char * filename,
35 | unsigned int states,
36 | unsigned int rate_cats,
37 | unsigned int rate_matrices,
38 | pll_utree_t * tree,
39 | unsigned int attributes);
40 |
41 | pll_partition_t * parse_msa_reduced(const char * filename,
42 | unsigned int states,
43 | unsigned int rate_cats,
44 | unsigned int rate_matrices,
45 | pll_utree_t * tree,
46 | unsigned int attributes,
47 | unsigned int max_sites);
48 | int cb_full_traversal(pll_unode_t * node);
49 | int cb_rfull_traversal(pll_rnode_t * node);
50 |
51 | /* print error and exit */
52 | void fatal(const char * format, ...) __attribute__ ((noreturn));
53 | char * xstrdup(const char * s);
54 | void * xmalloc(size_t size);
55 |
56 | #endif /* COMMON_H_ */
57 |
--------------------------------------------------------------------------------
/src/Makefile.am:
--------------------------------------------------------------------------------
1 | lib_LTLIBRARIES=libpll.la
2 |
3 | AM_CFLAGS=-Wall -Wsign-compare -D_GNU_SOURCE -std=c99 -O3 -fPIC
4 |
5 | LIBPLLHEADERS=\
6 | pll.h
7 |
8 | AM_YFLAGS = -d -p `${SED} -n 's/.*_\(.*\)/pll_\1_/p' <<<"$*"`
9 | AM_LFLAGS = -P `${SED} -n 's/.*_\(.*\)/pll_\1_/p' <<<"$*"` -o lex.yy.c
10 |
11 | libpll_la_SOURCES=\
12 | fasta.c \
13 | gamma.c \
14 | likelihood.c \
15 | list.c \
16 | maps.c \
17 | models.c \
18 | pll.c \
19 | output.c \
20 | utree.c \
21 | rtree.c \
22 | derivatives.c \
23 | partials.c \
24 | compress.c \
25 | utree_moves.c \
26 | utree_svg.c \
27 | parsimony.c \
28 | core_derivatives.c \
29 | core_partials.c \
30 | core_pmatrix.c \
31 | core_likelihood.c \
32 | parse_utree.y \
33 | parse_rtree.y \
34 | lex_utree.l \
35 | lex_rtree.l \
36 | fast_parsimony.c \
37 | stepwise.c \
38 | random.c \
39 | phylip.c \
40 | hardware.c
41 |
42 | libpll_la_CFLAGS = $(AM_CFLAGS)
43 |
44 | # To allow cross-compilation, those SIMD flags will be used for the respective source files only
45 | AVX2FLAGS=-mfma -mavx2
46 | AVXFLAGS=-mavx
47 | SSEFLAGS=-msse3
48 |
49 | SIMD_KERNELS=
50 |
51 | if HAVE_AVX2
52 | SIMD_KERNELS+=libsimd_avx2.la
53 | libsimd_avx2_la_CFLAGS=$(AM_CFLAGS) $(AVX2FLAGS)
54 | libsimd_avx2_la_SOURCES=\
55 | core_partials_avx2.c \
56 | core_derivatives_avx2.c \
57 | core_pmatrix_avx2.c \
58 | core_likelihood_avx2.c \
59 | fast_parsimony_avx2.c
60 | endif
61 |
62 | if HAVE_AVX
63 | SIMD_KERNELS+=libsimd_avx.la
64 | libsimd_avx_la_CFLAGS=$(AM_CFLAGS) $(AVXFLAGS)
65 | libsimd_avx_la_SOURCES=\
66 | core_partials_avx.c \
67 | core_derivatives_avx.c \
68 | core_pmatrix_avx.c \
69 | core_likelihood_avx.c \
70 | fast_parsimony_avx.c
71 | endif
72 |
73 | if HAVE_SSE3
74 | SIMD_KERNELS+=libsimd_sse.la
75 | libsimd_sse_la_CFLAGS=$(AM_CFLAGS) $(SSEFLAGS)
76 | libsimd_sse_la_SOURCES=\
77 | core_partials_sse.c \
78 | core_derivatives_sse.c \
79 | core_likelihood_sse.c \
80 | core_pmatrix_sse.c \
81 | fast_parsimony_sse.c
82 | endif
83 |
84 | libpll_la_LIBADD = $(SIMD_KERNELS)
85 | noinst_LTLIBRARIES = $(SIMD_KERNELS)
86 |
87 | # This is the version information for libtool and not the libpll version. For
88 | # more information see:
89 | # https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
90 | libpll_la_LDFLAGS = -version-info 0:0:0
91 |
92 | pkgincludedir=$(includedir)/libpll
93 | pkginclude_HEADERS = pll.h
94 |
--------------------------------------------------------------------------------
/src/list.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Tomas Flouri ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 |
22 | #include "pll.h"
23 |
24 | static int dlist_insert(pll_dlist_t ** dlist, void * data, int insert_end)
25 | {
26 | if (!*dlist)
27 | {
28 | *dlist = (pll_dlist_t *)malloc(sizeof(pll_dlist_t));
29 | if (!*dlist)
30 | {
31 | pll_errno = PLL_ERROR_MEM_ALLOC;
32 | snprintf(pll_errmsg, 200, "Unable to allocate enough memory.");
33 | return PLL_FAILURE;
34 | }
35 |
36 | (*dlist)->next = NULL;
37 | (*dlist)->prev = NULL;
38 | (*dlist)->data = data;
39 | return PLL_SUCCESS;
40 | }
41 |
42 | /* go to the last element if we chose to append */
43 | if (insert_end)
44 | for(; (*dlist)->next; dlist = &(*dlist)->next);
45 |
46 | (*dlist)->next = (pll_dlist_t *)malloc(sizeof(pll_dlist_t));
47 | if (!(*dlist)->next)
48 | {
49 | pll_errno = PLL_ERROR_MEM_ALLOC;
50 | snprintf(pll_errmsg, 200, "Unable to allocate enough memory.");
51 | return PLL_FAILURE;
52 | }
53 |
54 | (*dlist)->next->next = NULL;
55 | (*dlist)->next->data = data;
56 | (*dlist)->next->prev = (*dlist);
57 |
58 | return PLL_SUCCESS;
59 |
60 | }
61 |
62 | PLL_EXPORT int pll_dlist_append(pll_dlist_t ** dlist, void * data)
63 | {
64 | return dlist_insert(dlist, data, 1);
65 | }
66 |
67 | PLL_EXPORT int pll_dlist_prepend(pll_dlist_t ** dlist, void * data)
68 | {
69 | return dlist_insert(dlist, data, 0);
70 | }
71 |
72 | PLL_EXPORT int pll_dlist_remove(pll_dlist_t ** dlist, void * data)
73 | {
74 | for (; (*dlist) && (*dlist)->data != data; dlist = &((*dlist)->next));
75 |
76 | if (!*dlist) return PLL_FAILURE;
77 |
78 | if ((*dlist)->next)
79 | (*dlist)->next->prev = (*dlist)->prev;
80 | if ((*dlist)->prev)
81 | (*dlist)->prev->next = (*dlist)->next;
82 |
83 | free(*dlist);
84 | *dlist = NULL;
85 |
86 | return PLL_SUCCESS;
87 | }
88 |
--------------------------------------------------------------------------------
/examples/lg4/data/example.fas:
--------------------------------------------------------------------------------
1 | >RL5X_THETH
2 | PIGLRVTLRRDRMWIFLEKLLNVALPRIRDFRGLN--PNSFDGRGNYNLGLREQLIFPEITYDMVDALRGMDIAVVT------TAETDEE----------ARALLELLGFPFR
3 | >RL5_THEMA
4 | PIGLKVTLRGARMYNFLYKLINIVLPKVRDFRGLD--PNSFDGRGNYSFGLSEQLVFPELNPDEVRRIQGMDITIVT------TAKTDQE----------ARRLLELFGMPFK
5 | >RL5_MYCCA
6 | AIGAKVTLRGKKMYDFLDKLINVALPRVRDFRGVS--KTSFDGFGNFYTGIKEQIIFPEVDHDKVIRLRGMDITIVT------SAKTNKE----------AFALLQKIGMPFE
7 | >RK5_CYAPA
8 | PIGVMVTLRGDYMYAFLDRLINLSLPRIRDFRGIT--AKSFDGRGNYNLGLKEQLIFPEVDYDGIEQIRGMDISIVT------TAKTDQE----------GLALLKSLGMPFA
9 | >RL5_MICLU
10 | PIGTHATLRGDRMWEFLDRLVTLPLPRIRDFRGLS--DRQFDGNGNYTFGLSEQTVFHEIDQDKIDRVRGMDITVVT------TAKNDDE----------GRALLKALGFPFK
11 | >RL5_BUCAK
12 | PIGCKVTLRGERMWEFFERLISIAVPRIRDFRGLS--AKSFDGRGNYSMGVREQIIFPEIDYDKVDRVRGLDITITT------TAKSDDE----------GRALLAAFNFPFR
13 | >RL5_MYCGE
14 | LIGCKVTLRNKKMWSFLEKLIYIALPRVRDFRGLS--LRSFDGKGNYTIGIKEQIIFPEIVYDDIKRIRGFDITIVT------STNKDSE----------ALALLRALKMPFV
15 | >RK5_EUGGR
16 | PVGMFLTLRSEKMYSFLDRLINLSLPRIRDFQGIN--KNCFDGSGNFSFGLSEQSMFPEINFDKMIKVQGLNITIVT------TAETNQE----------AFFLLKELGIPFR
17 | >RK5_ODOSI
18 | ELGLTVTLRGSKMYSFLTKLIFFTFAQIRDFRGLS--VRSFDKAGNYTLGLKEQLIFPEIDYDDVDQTQGFSITLVF------SSTAPKSRSKTMDRVLNGMVLFKFLRFPLN
19 | >RL5_SULAC
20 | PIGVKATLRRQAAVEFLKKVL-----PAVNFRLK---QSSFDNYGNVSFGIAEHVLIPGTRYDPEIGIFGMDVAITLVRPGYRTMKRKRKKA----SIPRRHRVTKEEAINFM
21 | >RL5_METVA
22 | PIGLKVTLRGKNAEEFLENAF-----VAFKVSGKVLYASSFDKVGNFSFGVPEHIDFPGQKYDPTVGIYGMDICVTFEKPGYRVKSRKLKRS----HIPAKHLVKKEEAIEYI
23 | >RL5_METJA
24 | PIGLKVTLRGKKAEEFLKNAF-----EAFQKEGKKLYDYSFDDYGNFSFGIHEHIDFPGQKYDPMIGIFGMDVCVTLERPGFRVKRRKRCRA----KIPRRHRLTREEAIEFI
25 | >RL5_HALMA
26 | PIGAKVTLRDEMAEEFLQTAL-----PLAELATS-----QFDDTGNFSFGVEEHTEFPSQEYDPSIGIYGLDVTVNLVRPGYRVAKRDKASR----SIPTKHRLNPADAVAFI
27 | >RL11_YEAST
28 | KIAVHVTVRGPKAEEILERGL-----KVKEYQLR---DRNFSATGNFGFGIDEHIDL-GIKYDPSIGIFGMDFYVVMNRPGARVTRRKRCKG----TVGNSHKTTKEDTVSWF
29 | >RL11_SCHPO
30 | KIACHVTVRGPKAEEILERGL-----KVKEYELK---KRNFSATGNFGFGIQEHIDL-GIKYDPSIGIYGMDFYVVMDRPGMRVARRKAQRG----RVGYTHKINAEDTINWF
31 | >RL11_LEICH
32 | KIAVHCTVRGKKAEELLEKGL-----KVKEFELK---SYNFSDTGSFGFGIDEHIDL-GIKYDPSTGIYGMDFYVVLGRRGERVAHRKRKCS----RVGHSHHVTKEEAMKWF
33 | >RL11_DROME
34 | KIAVHCTVRGAKAEEILERGL-----KVREYELR---RENFSSTGNFGFGIQEHIDL-GIKYDPSIGIYGLDFYVVLGRPGYNVNHRKRKSG----TVGFQHRLTKEDAMKWF
35 | >RL11_HUMAN
36 | KIAVHCTVRGAKAEEILEKGL-----KVREYELR---KNNFSDTGNFGFGIQEHIDL-GIKYDPSIGIYGLDFYVVLGRPGFSIADKKRRTG----CIGAKHRISKEEAMRWF
37 | >RL11_CHLRE
38 | KISCYVTVRGEKAYDLVKRGL-----AVKEFELI---RKNFSDTGNFGFGIQEHIDL-GLKYDPSTGIYGMDFYVCLERRGYRVARRRKQKA----HVGVKHKVTKEDAIKWF
39 | >R111_ARATH
40 | KIACYVTVRGEKAMQLLESGL-----KVKEYELL---RRNFSDTGCFGFGIQEHIDL-GIKYDPSTGIYGMDFYVVLERPGYRVARRRRCKA----RVGIQHRVTKDDAMKWF
41 | >RL11_TETTH
42 | KMAVHVTIRGDKARDILTRGL-----KVKEMELR---KKNFSNTGNFGFGIQEHIDL-GMKYDPSTGIFGMDFYVVLERPGTRVARRRRATS----RVGNNQMISKEECINWF
43 |
--------------------------------------------------------------------------------
/examples/load-utree/load-utree.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Tomas Flouri ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 |
22 | #include "pll.h"
23 | #include
24 |
25 | static void fatal(const char * format, ...) __attribute__ ((noreturn));
26 |
27 | static void fatal(const char * format, ...)
28 | {
29 | va_list argptr;
30 | va_start(argptr, format);
31 | vfprintf(stderr, format, argptr);
32 | va_end(argptr);
33 | fprintf(stderr, "\n");
34 | exit(EXIT_FAILURE);
35 | }
36 |
37 | pll_utree_t * load_tree_unrooted(const char * filename)
38 | {
39 | pll_utree_t * utree;
40 | pll_rtree_t * rtree;
41 |
42 | if (!(rtree = pll_rtree_parse_newick(filename)))
43 | {
44 | if (!(utree = pll_utree_parse_newick(filename)))
45 | {
46 | fprintf(stderr, "%s\n", pll_errmsg);
47 | return NULL;
48 | }
49 | }
50 | else
51 | {
52 | utree = pll_rtree_unroot(rtree);
53 |
54 | pll_unode_t * root = utree->nodes[utree->tip_count+utree->inner_count-1];
55 |
56 | /* optional step if using default PLL clv/pmatrix index assignments */
57 | pll_utree_reset_template_indices(root, utree->tip_count);
58 |
59 | pll_rtree_destroy(rtree,NULL);
60 | }
61 |
62 | return utree;
63 | }
64 |
65 | int main(int argc, char * argv[])
66 | {
67 | if (argc != 2)
68 | fatal("syntax: %s [newick]", argv[0]);
69 |
70 | pll_utree_t * utree = load_tree_unrooted(argv[1]);
71 | if (!utree)
72 | fatal("Tree must be a rooted or unrooted binary.");
73 |
74 | /* select a random inner node */
75 | long int r = random() % utree->inner_count;
76 | pll_unode_t * root = utree->nodes[utree->tip_count + r];
77 |
78 | /* export the tree to newick format with the selected inner node as the root
79 | of the unrooted binary tree */
80 | char * newick = pll_utree_export_newick(root,NULL);
81 |
82 | printf("%s\n", newick);
83 |
84 | free(newick);
85 |
86 | pll_utree_destroy(utree,NULL);
87 |
88 | return 0;
89 | }
90 |
--------------------------------------------------------------------------------
/test/out/00110_NPDN_fasta.out:
--------------------------------------------------------------------------------
1 | Creating PLL partition
2 | Header of sequence 0(0) Allobophora_caliginosa (492 sites)
3 | Header of sequence 1(1) Allolobophora_tuberculata (492 sites)
4 | Header of sequence 2(2) Allolobophora_nocturna (492 sites)
5 | Header of sequence 3(3) Allolobophora_longa (492 sites)
6 | Header of sequence 4(4) Allolobophora_trapezoides (492 sites)
7 | Header of sequence 5(5) Allolobophora_clorotica (492 sites)
8 | Header of sequence 6(6) Allolobophora_chloroticaG (492 sites)
9 | Header of sequence 7(7) Allolobophora_choroticaP (492 sites)
10 | Header of sequence 8(8) Allolobophora_icterica (492 sites)
11 | Header of sequence 9(9) Allolobophora_molleri (492 sites)
12 | Header of sequence 10(10) Allolobophora_rosea (492 sites)
13 | Header of sequence 11(11) Eiseniella_tetraedra (492 sites)
14 | Header of sequence 12(12) Dendrobaena_octaedra (492 sites)
15 | Header of sequence 13(13) Scherotheca_gigas (492 sites)
16 | Header of sequence 14(14) Octolasion_lacteum (492 sites)
17 | Header of sequence 15(15) Octolasion_cyanemum (492 sites)
18 | Header of sequence 16(16) Octolasion_lacteumoscuro (492 sites)
19 | Header of sequence 17(17) Allolobophora_minuscula (492 sites)
20 | Header of sequence 18(18) Lumbricus_festivus (492 sites)
21 | Header of sequence 19(19) Lumbricus_friendi (492 sites)
22 | Header of sequence 20(20) Lumbricus_friendi_irlanda (492 sites)
23 | Header of sequence 21(21) Lumbricus_terrestris (492 sites)
24 | Header of sequence 22(22) Lumbricus_rubelus (492 sites)
25 | Header of sequence 23(23) Lumbricus_castaneus (492 sites)
26 | Header of sequence 24(24) Eisenia_andrei (492 sites)
27 | Header of sequence 25(25) Eisenia_fetida (492 sites)
28 | Header of sequence 26(26) Allolobophora_oliveirae (492 sites)
29 | Header of sequence 27(27) Dendrobaena_attemsi (492 sites)
30 | Header of sequence 28(28) Dendrobaena_rubida (492 sites)
31 | Header of sequence 29(29) Eisenia_eiseni (492 sites)
32 | Header of sequence 30(30) Dendrobaena_mammalis (492 sites)
33 | Header of sequence 31(31) Dendrobaena_madeirensis (492 sites)
34 | Header of sequence 32(32) Hornogaster_elisae (492 sites)
35 | Header of sequence 33(33) Criodrilus_lacuum (492 sites)
36 | Header of sequence 34(34) Prosellodrillus_practicola (492 sites)
37 | Header of sequence 35(35) Dendrobaena_veneta (492 sites)
38 | Header of sequence 36(36) Dendrobaena_hortensis (492 sites)
39 | Header of sequence 37(37) Allolobophora_limicola (492 sites)
40 | Header of sequence 38(38) Amynthas_corticis (492 sites)
41 | Header of sequence 39(39) Perionyx_excabatus (492 sites)
42 | Header of sequence 40(40) Microscolex_phosphoreus (492 sites)
43 | Header of sequence 41(41) Eudrilus_eugeniae (492 sites)
44 | Header of sequence 42(42) Pontoscolex_corethurus (492 sites)
45 | Big test OK
46 |
47 | logL: -6117.553841
48 | Small test OK
49 |
50 | Fail test OK
51 |
--------------------------------------------------------------------------------
/test/out/00110_NPDN_fasta.exe.out:
--------------------------------------------------------------------------------
1 | Creating PLL partition
2 | Header of sequence 0(0) Allobophora_caliginosa (492 sites)
3 | Header of sequence 1(1) Allolobophora_tuberculata (492 sites)
4 | Header of sequence 2(2) Allolobophora_nocturna (492 sites)
5 | Header of sequence 3(3) Allolobophora_longa (492 sites)
6 | Header of sequence 4(4) Allolobophora_trapezoides (492 sites)
7 | Header of sequence 5(5) Allolobophora_clorotica (492 sites)
8 | Header of sequence 6(6) Allolobophora_chloroticaG (492 sites)
9 | Header of sequence 7(7) Allolobophora_choroticaP (492 sites)
10 | Header of sequence 8(8) Allolobophora_icterica (492 sites)
11 | Header of sequence 9(9) Allolobophora_molleri (492 sites)
12 | Header of sequence 10(10) Allolobophora_rosea (492 sites)
13 | Header of sequence 11(11) Eiseniella_tetraedra (492 sites)
14 | Header of sequence 12(12) Dendrobaena_octaedra (492 sites)
15 | Header of sequence 13(13) Scherotheca_gigas (492 sites)
16 | Header of sequence 14(14) Octolasion_lacteum (492 sites)
17 | Header of sequence 15(15) Octolasion_cyanemum (492 sites)
18 | Header of sequence 16(16) Octolasion_lacteumoscuro (492 sites)
19 | Header of sequence 17(17) Allolobophora_minuscula (492 sites)
20 | Header of sequence 18(18) Lumbricus_festivus (492 sites)
21 | Header of sequence 19(19) Lumbricus_friendi (492 sites)
22 | Header of sequence 20(20) Lumbricus_friendi_irlanda (492 sites)
23 | Header of sequence 21(21) Lumbricus_terrestris (492 sites)
24 | Header of sequence 22(22) Lumbricus_rubelus (492 sites)
25 | Header of sequence 23(23) Lumbricus_castaneus (492 sites)
26 | Header of sequence 24(24) Eisenia_andrei (492 sites)
27 | Header of sequence 25(25) Eisenia_fetida (492 sites)
28 | Header of sequence 26(26) Allolobophora_oliveirae (492 sites)
29 | Header of sequence 27(27) Dendrobaena_attemsi (492 sites)
30 | Header of sequence 28(28) Dendrobaena_rubida (492 sites)
31 | Header of sequence 29(29) Eisenia_eiseni (492 sites)
32 | Header of sequence 30(30) Dendrobaena_mammalis (492 sites)
33 | Header of sequence 31(31) Dendrobaena_madeirensis (492 sites)
34 | Header of sequence 32(32) Hornogaster_elisae (492 sites)
35 | Header of sequence 33(33) Criodrilus_lacuum (492 sites)
36 | Header of sequence 34(34) Prosellodrillus_practicola (492 sites)
37 | Header of sequence 35(35) Dendrobaena_veneta (492 sites)
38 | Header of sequence 36(36) Dendrobaena_hortensis (492 sites)
39 | Header of sequence 37(37) Allolobophora_limicola (492 sites)
40 | Header of sequence 38(38) Amynthas_corticis (492 sites)
41 | Header of sequence 39(39) Perionyx_excabatus (492 sites)
42 | Header of sequence 40(40) Microscolex_phosphoreus (492 sites)
43 | Header of sequence 41(41) Eudrilus_eugeniae (492 sites)
44 | Header of sequence 42(42) Pontoscolex_corethurus (492 sites)
45 | Big test OK
46 |
47 | logL: -6117.553841
48 | Small test OK
49 |
50 | Fail test OK
51 |
--------------------------------------------------------------------------------
/examples/load-utree/README.md:
--------------------------------------------------------------------------------
1 | # Rooted tree example
2 |
3 | This example demonstrates how to write a function that loads an unrooted binary
4 | tree from a newick file. In case the newick file contains a binary rooted tree,
5 | it is automatically unrooted by removing the root node and summing up the
6 | root's two edges.
7 |
8 | ## Explanation of the example
9 |
10 | The example program composes of the following function
11 |
12 | ```C
13 | pll_utree_t * load_tree_unrooted(const char * filename,
14 | unsigned int * tip_count)
15 | {
16 | pll_utree_t * utree;
17 | pll_rtree_t * rtree;
18 |
19 | if (!(rtree = pll_rtree_parse_newick(filename, tip_count)))
20 | {
21 | if (!(utree = pll_utree_parse_newick(filename, tip_count)))
22 | {
23 | fprintf(stderr, "%s\n", pll_errmsg);
24 | return NULL;
25 | }
26 | }
27 | else
28 | {
29 | utree = pll_rtree_unroot(rtree);
30 |
31 | /* optional step if using default PLL clv/pmatrix index assignments */
32 | pll_utree_reset_template_indices(utree, *tip_count);
33 | }
34 |
35 | return utree;
36 | }
37 | ```
38 |
39 | which accepts two parameters, the name of the newick file and a variable where
40 | the number of tips will be stored. The function first attempts to load the tree
41 | as a rooted one, and if it fails, it attempts to read it as unrooted.
42 |
43 | In case the file contained a rooted binary tree, then it is converted to unrooted
44 | using the call
45 |
46 | ```C
47 | utree = pll_rtree_unroot(rtree);
48 | ```
49 |
50 | and, optionally, calls the function
51 |
52 | ```C
53 | pll_utree_reset_template_indices(utree, *tip_count);
54 | ```
55 |
56 | to reset CLV, p-matrix and scaler indices to the defaults used by the PLL functions.
57 | That means, tips will be assigned CLV and p-matrix indices ranging from 0 to `tip_count - 1`, and
58 | inner nodes indices from `tip_count` to `2*tip_count - 3`. Tips are assigned `PLL_SCALE_BUFFER_NONE`
59 | for scaler indices (since no scaling is required for tips) and inner nodes get scaler indices from
60 | 0 to `tip_count - 3`.
61 |
62 | ## Instructions to compile
63 |
64 | Before proceeding with the compilation, make sure that `pll.h` is accessible,
65 | by copying it to the current example directory, or modifying the line
66 |
67 | `#include "pll.h"`
68 |
69 | You will also need to make the shared object `libpll.so` accessible by either
70 | placing it in your system's library directory (typically `/lib` or
71 | `/usr/local/lib`), or by copying it to the current example directory.
72 |
73 | Now you may compile the example by running the included Makefile using
74 |
75 | `make`
76 |
77 | ## Instructions to run
78 |
79 | Make absolutely sure that the shared object `libpll.so` is accessible by either
80 | placing it in your system's library directory (typically `/lib` or
81 | `/usr/local/lib`). If it is not, you may copy it to a directory (for example
82 | $PWD), and run the command
83 |
84 | `export LD_LIBRARY_PATH=$PWD`
85 |
86 | Now, run the example by changing to the directory of the compiled file and
87 | typing:
88 |
89 | `./rooted`
90 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: c
2 |
3 | matrix:
4 | include:
5 | - os: linux
6 | compiler: gcc
7 | addons:
8 | apt:
9 | sources: ['ubuntu-toolchain-r-test']
10 | packages: ['gcc-4.6']
11 | env:
12 | - COMPILER=gcc-4.6 CONFPARAMS="--disable-avx2"
13 |
14 | - os: linux
15 | compiler: gcc
16 | addons:
17 | apt:
18 | sources: ['ubuntu-toolchain-r-test']
19 | packages: ['gcc-4.7']
20 | env:
21 | - COMPILER=gcc-4.7 CONFPARAMS=""
22 |
23 | - os: linux
24 | compiler: gcc
25 | addons:
26 | apt:
27 | sources: ['ubuntu-toolchain-r-test']
28 | packages: ['gcc-4.8']
29 | env:
30 | - COMPILER=gcc-4.8 CONFPARAMS=""
31 |
32 | - os: linux
33 | compiler: gcc
34 | addons:
35 | apt:
36 | sources: ['ubuntu-toolchain-r-test']
37 | packages: ['gcc-4.9']
38 | env:
39 | - COMPILER=gcc-4.9 CONFPARAMS=""
40 |
41 | - os: linux
42 | compiler: gcc
43 | addons:
44 | apt:
45 | sources: ['ubuntu-toolchain-r-test']
46 | packages: ['gcc-5']
47 | env:
48 | - COMPILER=gcc-5 CONFPARAMS=""
49 |
50 | - os: linux
51 | compiler: gcc
52 | addons:
53 | apt:
54 | sources: ['ubuntu-toolchain-r-test']
55 | packages: ['gcc-6']
56 | env:
57 | - COMPILER=gcc-6 CONFPARAMS=""
58 |
59 | - os: linux
60 | compiler: clang
61 | addons:
62 | apt:
63 | sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5']
64 | packages: ['clang-3.5']
65 | env:
66 | - COMPILER=clang-3.5 CONFPARAMS=""
67 |
68 | - os: linux
69 | compiler: clang
70 | addons:
71 | apt:
72 | sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
73 | packages: ['clang-3.6']
74 | env:
75 | - COMPILER=clang-3.6 CONFPARAMS=""
76 |
77 | - os: linux
78 | compiler: clang
79 | addons:
80 | apt:
81 | sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
82 | packages: ['clang-3.7']
83 | env:
84 | - COMPILER=clang-3.7 CONFPARAMS=""
85 |
86 | - os: linux
87 | compiler: clang
88 | addons:
89 | apt:
90 | sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.8']
91 | packages: ['clang-3.8']
92 | env:
93 | - COMPILER=clang-3.8 CONFPARAMS=""
94 |
95 | - os: linux
96 | dist: trusty
97 | compiler: clang
98 | addons:
99 | apt:
100 | sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.9']
101 | packages: ['clang-3.9']
102 | env:
103 | - COMPILER=clang-3.9 CONFPARAMS=""
104 |
105 | - os: linux
106 | dist: trusty
107 | compiler: clang
108 | addons:
109 | apt:
110 | sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
111 | packages: ['clang-4.0']
112 | env:
113 | - COMPILER=clang-4.0 CONFPARAMS=""
114 |
115 | script: ./autogen.sh && CC=$COMPILER ./configure $CONFPARAMS && make && make check
116 |
--------------------------------------------------------------------------------
/src/output.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Tomas Flouri ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 |
22 | #include "pll.h"
23 |
24 | static void unscale(double * prob, unsigned int times);
25 |
26 | PLL_EXPORT void pll_show_pmatrix(const pll_partition_t * partition,
27 | unsigned int index,
28 | unsigned int float_precision)
29 | {
30 | unsigned int i,j,k;
31 | double * pmatrix;
32 | unsigned int states = partition->states;
33 | unsigned int states_padded = partition->states_padded;
34 |
35 | for (k = 0; k < partition->rate_cats; ++k)
36 | {
37 | pmatrix = partition->pmatrix[index] + k*states*states_padded;
38 | for (i = 0; i < partition->states; ++i)
39 | {
40 | for (j = 0; j < states; ++j)
41 | printf("%+2.*f ", float_precision, pmatrix[i*states_padded+j]);
42 | printf("\n");
43 | }
44 | printf("\n");
45 | }
46 | }
47 |
48 | static void unscale(double * prob, unsigned int times)
49 | {
50 | unsigned int i;
51 |
52 | for (i = 0; i < times; ++i)
53 | *prob *= PLL_SCALE_THRESHOLD;
54 | }
55 |
56 | PLL_EXPORT void pll_show_clv(const pll_partition_t * partition,
57 | unsigned int clv_index,
58 | int scaler_index,
59 | unsigned int float_precision)
60 | {
61 | unsigned int i,j,k;
62 |
63 | double * clv = partition->clv[clv_index];
64 | unsigned int * scaler = (scaler_index == PLL_SCALE_BUFFER_NONE) ?
65 | NULL : partition->scale_buffer[scaler_index];
66 | unsigned int states = partition->states;
67 | unsigned int states_padded = partition->states_padded;
68 | unsigned int rates = partition->rate_cats;
69 | double prob;
70 |
71 | if ((clv_index < partition->tips) &&
72 | (partition->attributes & PLL_ATTRIB_PATTERN_TIP))
73 | return;
74 |
75 | printf ("[ ");
76 | for (i = 0; i < partition->sites; ++i)
77 | {
78 | printf("{");
79 | for (j = 0; j < rates; ++j)
80 | {
81 | printf("(");
82 | for (k = 0; k < states-1; ++k)
83 | {
84 | prob = clv[i*rates*states_padded + j*states_padded + k];
85 | if (scaler) unscale(&prob, scaler[i]);
86 | printf("%.*f,", float_precision, prob);
87 | }
88 | prob = clv[i*rates*states_padded + j*states_padded + k];
89 | if (scaler) unscale(&prob, scaler[i]);
90 | printf("%.*f)", float_precision, prob);
91 | if (j < rates - 1) printf(",");
92 | }
93 | printf("} ");
94 | }
95 | printf ("]\n");
96 | }
97 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # List of examples
2 |
3 | ## [`rooted`](https://github.com/xflouris/libpll/tree/master/examples/rooted)
4 |
5 | This example shows how to evaluate the log-likelihood of a rooted tree by
6 | creating a custom post-order traversal that drives the likelihood computation.
7 | It also demonstrates how to account for invariant sites when computing the
8 | likelihood.
9 |
10 | The example covers the following:
11 |
12 | * partition instance creation,
13 | * setting variable rates among sites (four discrete rates from Γ),
14 | * setting the parameters for the GTR model,
15 | * computation of probability matrices,
16 | * setting frequencies,
17 | * setting tip CLVs by passing the sequence and a map,
18 | * creating a tree traversal for driving the likelihood function,
19 | * computing the CLVs at inner nodes,
20 | * evaluating the log-likelihood at the root,
21 | * considering the Inv+Γ model,
22 | * displaying the CLVs and probability matrices on the console,
23 | * deallocating the partition instance.
24 |
25 | ## [`newick-fasta-unrooted`](https://github.com/xflouris/libpll/tree/master/examples/newick-fasta-unrooted)
26 |
27 | This example shows how to evaluate the log-likelihood of an
28 | [unrooted binary tree](http://en.wikipedia.org/wiki/Unrooted_binary_tree) tree
29 | which is loadded from a [newick](http://en.wikipedia.org/wiki/Newick_format)
30 | file using the `libpll` newick parser. The alignment is loaded from a FASTA
31 | file using the `libpll` fasta parser, and each sequence is associated to the
32 | corresponding tree taxon via the use of the standard
33 | [GNU C Library (glibc)](http://www.gnu.org/software/libc/) hash table. The
34 | parsed newick tree is stored in an intermediate structure which may be used to
35 | automagically and conveniently create the `libpll` operations structure.
36 |
37 | The example covers the following:
38 |
39 | * loading a newick tree file using the `libpll` parser into an intermediate unrooted binary tree structure,
40 | * loading sequences from a FASTA file,
41 | * querying the intermediate tree structure for a list of tip names
42 | * associating sequences to taxa using the `glibc` hash table functions,
43 | * getting a filled operations structure by using library functions to iterate over the parsed tree structure,
44 | * setting default branch lengths to branches which did not have an associated length in the newick format,
45 |
46 | ## [`unrooted`](https://github.com/xflouris/libpll/tree/master/examples/unrooted)
47 |
48 | This example shows how to evaluate the log-likelihood at an edge of an
49 | [unrooted binary tree](http://en.wikipedia.org/wiki/Unrooted_binary_tree) tree.
50 |
51 | This examples covers the following:
52 |
53 | * obtaining the rate categories from a discretized gamma distribution by providing the alpha shape parameter,
54 | * evaluating the log-likelihood at an edge of the unroted tree.
55 |
56 | ## [`newton`](https://github.com/xflouris/libpll/tree/master/examples/newton)
57 |
58 | This example shows how to evaluate the log-likelihood at an edge of an
59 | [unrooted binary tree](http://en.wikipedia.org/wiki/Unrooted_binary_tree) tree,
60 | and how to optimize the length of a given branch using [Newton's method](https://en.wikipedia.org/wiki/Newton's_method).
61 |
62 | This examples covers the following:
63 |
64 | * obtaining the rate categories from a discretized gamma distribution by providing the alpha shape parameter,
65 | * evaluating the log-likelihood at an edge of the unroted tree.
66 | * optimizing the length of a given branch using Newton's method.
67 |
--------------------------------------------------------------------------------
/m4/ax_check_compile_flag.m4:
--------------------------------------------------------------------------------
1 | # ===========================================================================
2 | # http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
3 | # ===========================================================================
4 | #
5 | # SYNOPSIS
6 | #
7 | # AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8 | #
9 | # DESCRIPTION
10 | #
11 | # Check whether the given FLAG works with the current language's compiler
12 | # or gives an error. (Warnings, however, are ignored)
13 | #
14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15 | # success/failure.
16 | #
17 | # If EXTRA-FLAGS is defined, it is added to the current language's default
18 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with
19 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
20 | # force the compiler to issue an error when a bad flag is given.
21 | #
22 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE.
23 | #
24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25 | # macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
26 | #
27 | # LICENSE
28 | #
29 | # Copyright (c) 2008 Guido U. Draheim
30 | # Copyright (c) 2011 Maarten Bosmans
31 | #
32 | # This program is free software: you can redistribute it and/or modify it
33 | # under the terms of the GNU General Public License as published by the
34 | # Free Software Foundation, either version 3 of the License, or (at your
35 | # option) any later version.
36 | #
37 | # This program is distributed in the hope that it will be useful, but
38 | # WITHOUT ANY WARRANTY; without even the implied warranty of
39 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40 | # Public License for more details.
41 | #
42 | # You should have received a copy of the GNU General Public License along
43 | # with this program. If not, see .
44 | #
45 | # As a special exception, the respective Autoconf Macro's copyright owner
46 | # gives unlimited permission to copy, distribute and modify the configure
47 | # scripts that are the output of Autoconf when processing the Macro. You
48 | # need not follow the terms of the GNU General Public License when using
49 | # or distributing such scripts, even though portions of the text of the
50 | # Macro appear in them. The GNU General Public License (GPL) does govern
51 | # all other use of the material that constitutes the Autoconf Macro.
52 | #
53 | # This special exception to the GPL applies to versions of the Autoconf
54 | # Macro released by the Autoconf Archive. When you make and distribute a
55 | # modified version of the Autoconf Macro, you may extend this special
56 | # exception to the GPL to apply to your modified version as well.
57 |
58 | #serial 4
59 |
60 | AC_DEFUN([AX_CHECK_COMPILE_FLAG],
61 | [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
62 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
63 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
64 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
65 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
66 | AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
67 | [AS_VAR_SET(CACHEVAR,[yes])],
68 | [AS_VAR_SET(CACHEVAR,[no])])
69 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
70 | AS_VAR_IF(CACHEVAR,yes,
71 | [m4_default([$2], :)],
72 | [m4_default([$3], :)])
73 | AS_VAR_POPDEF([CACHEVAR])dnl
74 | ])dnl AX_CHECK_COMPILE_FLAGS
75 |
--------------------------------------------------------------------------------
/m4/ax_gcc_x86_avx_xgetbv.m4:
--------------------------------------------------------------------------------
1 | # ===========================================================================
2 | # http://www.gnu.org/software/autoconf-archive/ax_gcc_x86_avx_xgetbv.html
3 | # ===========================================================================
4 | #
5 | # SYNOPSIS
6 | #
7 | # AX_GCC_X86_AVX_XGETBV
8 | #
9 | # DESCRIPTION
10 | #
11 | # On later x86 processors with AVX SIMD support, with gcc or a compiler
12 | # that has a compatible syntax for inline assembly instructions, run a
13 | # small program that executes the xgetbv instruction with input OP. This
14 | # can be used to detect if the OS supports AVX instruction usage.
15 | #
16 | # On output, the values of the eax and edx registers are stored as
17 | # hexadecimal strings as "eax:edx" in the cache variable
18 | # ax_cv_gcc_x86_avx_xgetbv.
19 | #
20 | # If the xgetbv instruction fails (because you are running a
21 | # cross-compiler, or because you are not using gcc, or because you are on
22 | # a processor that doesn't have this instruction),
23 | # ax_cv_gcc_x86_avx_xgetbv_OP is set to the string "unknown".
24 | #
25 | # This macro mainly exists to be used in AX_EXT.
26 | #
27 | # LICENSE
28 | #
29 | # Copyright (c) 2013 Michael Petch
30 | #
31 | # This program is free software: you can redistribute it and/or modify it
32 | # under the terms of the GNU General Public License as published by the
33 | # Free Software Foundation, either version 3 of the License, or (at your
34 | # option) any later version.
35 | #
36 | # This program is distributed in the hope that it will be useful, but
37 | # WITHOUT ANY WARRANTY; without even the implied warranty of
38 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
39 | # Public License for more details.
40 | #
41 | # You should have received a copy of the GNU General Public License along
42 | # with this program. If not, see .
43 | #
44 | # As a special exception, the respective Autoconf Macro's copyright owner
45 | # gives unlimited permission to copy, distribute and modify the configure
46 | # scripts that are the output of Autoconf when processing the Macro. You
47 | # need not follow the terms of the GNU General Public License when using
48 | # or distributing such scripts, even though portions of the text of the
49 | # Macro appear in them. The GNU General Public License (GPL) does govern
50 | # all other use of the material that constitutes the Autoconf Macro.
51 | #
52 | # This special exception to the GPL applies to versions of the Autoconf
53 | # Macro released by the Autoconf Archive. When you make and distribute a
54 | # modified version of the Autoconf Macro, you may extend this special
55 | # exception to the GPL to apply to your modified version as well.
56 |
57 | #serial 2
58 |
59 | AC_DEFUN([AX_GCC_X86_AVX_XGETBV],
60 | [AC_REQUIRE([AC_PROG_CC])
61 | AC_LANG_PUSH([C])
62 | AC_CACHE_CHECK(for x86-AVX xgetbv $1 output, ax_cv_gcc_x86_avx_xgetbv_$1,
63 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include ], [
64 | int op = $1, eax, edx;
65 | FILE *f;
66 | /* Opcodes for xgetbv */
67 | __asm__ __volatile__ (".byte 0x0f, 0x01, 0xd0"
68 | : "=a" (eax), "=d" (edx)
69 | : "c" (op));
70 | f = fopen("conftest_xgetbv", "w"); if (!f) return 1;
71 | fprintf(f, "%x:%x\n", eax, edx);
72 | fclose(f);
73 | return 0;
74 | ])],
75 | [ax_cv_gcc_x86_avx_xgetbv_$1=`cat conftest_xgetbv`; rm -f conftest_xgetbv],
76 | [ax_cv_gcc_x86_avx_xgetbv_$1=unknown; rm -f conftest_xgetbv],
77 | [ax_cv_gcc_x86_avx_xgetbv_$1=unknown])])
78 | AC_LANG_POP([C])
79 | ])
80 |
--------------------------------------------------------------------------------
/test/out/00120_NPAN_fasta.out:
--------------------------------------------------------------------------------
1 | Creating PLL partition
2 | Header of sequence 0(0) RL5X_THETH (113 sites)
3 | PIGLRVTLRRDRMWIFLEKLLNVALPRIRDFRGLN--PNSFDGRGNYNLGLREQLIFPEITYDMVDALRGMDIAVVT------TAETDEE----------ARALLELLGFPFR
4 | Header of sequence 1(1) RL5_THEMA (113 sites)
5 | PIGLKVTLRGARMYNFLYKLINIVLPKVRDFRGLD--PNSFDGRGNYSFGLSEQLVFPELNPDEVRRIQGMDITIVT------TAKTDQE----------ARRLLELFGMPFK
6 | Header of sequence 2(2) RL5_MYCCA (113 sites)
7 | AIGAKVTLRGKKMYDFLDKLINVALPRVRDFRGVS--KTSFDGFGNFYTGIKEQIIFPEVDHDKVIRLRGMDITIVT------SAKTNKE----------AFALLQKIGMPFE
8 | Header of sequence 3(3) RK5_CYAPA (113 sites)
9 | PIGVMVTLRGDYMYAFLDRLINLSLPRIRDFRGIT--AKSFDGRGNYNLGLKEQLIFPEVDYDGIEQIRGMDISIVT------TAKTDQE----------GLALLKSLGMPFA
10 | Header of sequence 4(4) RL5_MICLU (113 sites)
11 | PIGTHATLRGDRMWEFLDRLVTLPLPRIRDFRGLS--DRQFDGNGNYTFGLSEQTVFHEIDQDKIDRVRGMDITVVT------TAKNDDE----------GRALLKALGFPFK
12 | Header of sequence 5(5) RL5_BUCAK (113 sites)
13 | PIGCKVTLRGERMWEFFERLISIAVPRIRDFRGLS--AKSFDGRGNYSMGVREQIIFPEIDYDKVDRVRGLDITITT------TAKSDDE----------GRALLAAFNFPFR
14 | Header of sequence 6(6) RL5_MYCGE (113 sites)
15 | LIGCKVTLRNKKMWSFLEKLIYIALPRVRDFRGLS--LRSFDGKGNYTIGIKEQIIFPEIVYDDIKRIRGFDITIVT------STNKDSE----------ALALLRALKMPFV
16 | Header of sequence 7(7) RK5_EUGGR (113 sites)
17 | PVGMFLTLRSEKMYSFLDRLINLSLPRIRDFQGIN--KNCFDGSGNFSFGLSEQSMFPEINFDKMIKVQGLNITIVT------TAETNQE----------AFFLLKELGIPFR
18 | Header of sequence 8(8) RK5_ODOSI (113 sites)
19 | ELGLTVTLRGSKMYSFLTKLIFFTFAQIRDFRGLS--VRSFDKAGNYTLGLKEQLIFPEIDYDDVDQTQGFSITLVF------SSTAPKSRSKTMDRVLNGMVLFKFLRFPLN
20 | Header of sequence 9(9) RL5_SULAC (113 sites)
21 | PIGVKATLRRQAAVEFLKKVL-----PAVNFRLK---QSSFDNYGNVSFGIAEHVLIPGTRYDPEIGIFGMDVAITLVRPGYRTMKRKRKKA----SIPRRHRVTKEEAINFM
22 | Header of sequence 10(10) RL5_METVA (113 sites)
23 | PIGLKVTLRGKNAEEFLENAF-----VAFKVSGKVLYASSFDKVGNFSFGVPEHIDFPGQKYDPTVGIYGMDICVTFEKPGYRVKSRKLKRS----HIPAKHLVKKEEAIEYI
24 | Header of sequence 11(11) RL5_METJA (113 sites)
25 | PIGLKVTLRGKKAEEFLKNAF-----EAFQKEGKKLYDYSFDDYGNFSFGIHEHIDFPGQKYDPMIGIFGMDVCVTLERPGFRVKRRKRCRA----KIPRRHRLTREEAIEFI
26 | Header of sequence 12(12) RL5_HALMA (113 sites)
27 | PIGAKVTLRDEMAEEFLQTAL-----PLAELATS-----QFDDTGNFSFGVEEHTEFPSQEYDPSIGIYGLDVTVNLVRPGYRVAKRDKASR----SIPTKHRLNPADAVAFI
28 | Header of sequence 13(13) RL11_YEAST (113 sites)
29 | KIAVHVTVRGPKAEEILERGL-----KVKEYQLR---DRNFSATGNFGFGIDEHIDL-GIKYDPSIGIFGMDFYVVMNRPGARVTRRKRCKG----TVGNSHKTTKEDTVSWF
30 | Header of sequence 14(14) RL11_SCHPO (113 sites)
31 | KIACHVTVRGPKAEEILERGL-----KVKEYELK---KRNFSATGNFGFGIQEHIDL-GIKYDPSIGIYGMDFYVVMDRPGMRVARRKAQRG----RVGYTHKINAEDTINWF
32 | Header of sequence 15(15) RL11_LEICH (113 sites)
33 | KIAVHCTVRGKKAEELLEKGL-----KVKEFELK---SYNFSDTGSFGFGIDEHIDL-GIKYDPSTGIYGMDFYVVLGRRGERVAHRKRKCS----RVGHSHHVTKEEAMKWF
34 | Header of sequence 16(16) RL11_DROME (113 sites)
35 | KIAVHCTVRGAKAEEILERGL-----KVREYELR---RENFSSTGNFGFGIQEHIDL-GIKYDPSIGIYGLDFYVVLGRPGYNVNHRKRKSG----TVGFQHRLTKEDAMKWF
36 | Header of sequence 17(17) RL11_HUMAN (113 sites)
37 | KIAVHCTVRGAKAEEILEKGL-----KVREYELR---KNNFSDTGNFGFGIQEHIDL-GIKYDPSIGIYGLDFYVVLGRPGFSIADKKRRTG----CIGAKHRISKEEAMRWF
38 | Header of sequence 18(18) RL11_CHLRE (113 sites)
39 | KISCYVTVRGEKAYDLVKRGL-----AVKEFELI---RKNFSDTGNFGFGIQEHIDL-GLKYDPSTGIYGMDFYVCLERRGYRVARRRKQKA----HVGVKHKVTKEDAIKWF
40 | Header of sequence 19(19) R111_ARATH (113 sites)
41 | KIACYVTVRGEKAMQLLESGL-----KVKEYELL---RRNFSDTGCFGFGIQEHIDL-GIKYDPSTGIYGMDFYVVLERPGYRVARRRRCKA----RVGIQHRVTKDDAMKWF
42 | Header of sequence 20(20) RL11_TETTH (113 sites)
43 | KMAVHVTIRGDKARDILTRGL-----KVKEMELR---KKNFSNTGNFGFGIQEHIDL-GMKYDPSTGIFGMDFYVVLERPGTRVARRRRATS----RVGNNQMISKEECINWF
44 | Test OK
45 |
46 | Fail test OK (sequence 1)
47 |
--------------------------------------------------------------------------------
/test/out/00120_NPAN_fasta.exe.out:
--------------------------------------------------------------------------------
1 | Creating PLL partition
2 | Header of sequence 0(0) RL5X_THETH (113 sites)
3 | PIGLRVTLRRDRMWIFLEKLLNVALPRIRDFRGLN--PNSFDGRGNYNLGLREQLIFPEITYDMVDALRGMDIAVVT------TAETDEE----------ARALLELLGFPFR
4 | Header of sequence 1(1) RL5_THEMA (113 sites)
5 | PIGLKVTLRGARMYNFLYKLINIVLPKVRDFRGLD--PNSFDGRGNYSFGLSEQLVFPELNPDEVRRIQGMDITIVT------TAKTDQE----------ARRLLELFGMPFK
6 | Header of sequence 2(2) RL5_MYCCA (113 sites)
7 | AIGAKVTLRGKKMYDFLDKLINVALPRVRDFRGVS--KTSFDGFGNFYTGIKEQIIFPEVDHDKVIRLRGMDITIVT------SAKTNKE----------AFALLQKIGMPFE
8 | Header of sequence 3(3) RK5_CYAPA (113 sites)
9 | PIGVMVTLRGDYMYAFLDRLINLSLPRIRDFRGIT--AKSFDGRGNYNLGLKEQLIFPEVDYDGIEQIRGMDISIVT------TAKTDQE----------GLALLKSLGMPFA
10 | Header of sequence 4(4) RL5_MICLU (113 sites)
11 | PIGTHATLRGDRMWEFLDRLVTLPLPRIRDFRGLS--DRQFDGNGNYTFGLSEQTVFHEIDQDKIDRVRGMDITVVT------TAKNDDE----------GRALLKALGFPFK
12 | Header of sequence 5(5) RL5_BUCAK (113 sites)
13 | PIGCKVTLRGERMWEFFERLISIAVPRIRDFRGLS--AKSFDGRGNYSMGVREQIIFPEIDYDKVDRVRGLDITITT------TAKSDDE----------GRALLAAFNFPFR
14 | Header of sequence 6(6) RL5_MYCGE (113 sites)
15 | LIGCKVTLRNKKMWSFLEKLIYIALPRVRDFRGLS--LRSFDGKGNYTIGIKEQIIFPEIVYDDIKRIRGFDITIVT------STNKDSE----------ALALLRALKMPFV
16 | Header of sequence 7(7) RK5_EUGGR (113 sites)
17 | PVGMFLTLRSEKMYSFLDRLINLSLPRIRDFQGIN--KNCFDGSGNFSFGLSEQSMFPEINFDKMIKVQGLNITIVT------TAETNQE----------AFFLLKELGIPFR
18 | Header of sequence 8(8) RK5_ODOSI (113 sites)
19 | ELGLTVTLRGSKMYSFLTKLIFFTFAQIRDFRGLS--VRSFDKAGNYTLGLKEQLIFPEIDYDDVDQTQGFSITLVF------SSTAPKSRSKTMDRVLNGMVLFKFLRFPLN
20 | Header of sequence 9(9) RL5_SULAC (113 sites)
21 | PIGVKATLRRQAAVEFLKKVL-----PAVNFRLK---QSSFDNYGNVSFGIAEHVLIPGTRYDPEIGIFGMDVAITLVRPGYRTMKRKRKKA----SIPRRHRVTKEEAINFM
22 | Header of sequence 10(10) RL5_METVA (113 sites)
23 | PIGLKVTLRGKNAEEFLENAF-----VAFKVSGKVLYASSFDKVGNFSFGVPEHIDFPGQKYDPTVGIYGMDICVTFEKPGYRVKSRKLKRS----HIPAKHLVKKEEAIEYI
24 | Header of sequence 11(11) RL5_METJA (113 sites)
25 | PIGLKVTLRGKKAEEFLKNAF-----EAFQKEGKKLYDYSFDDYGNFSFGIHEHIDFPGQKYDPMIGIFGMDVCVTLERPGFRVKRRKRCRA----KIPRRHRLTREEAIEFI
26 | Header of sequence 12(12) RL5_HALMA (113 sites)
27 | PIGAKVTLRDEMAEEFLQTAL-----PLAELATS-----QFDDTGNFSFGVEEHTEFPSQEYDPSIGIYGLDVTVNLVRPGYRVAKRDKASR----SIPTKHRLNPADAVAFI
28 | Header of sequence 13(13) RL11_YEAST (113 sites)
29 | KIAVHVTVRGPKAEEILERGL-----KVKEYQLR---DRNFSATGNFGFGIDEHIDL-GIKYDPSIGIFGMDFYVVMNRPGARVTRRKRCKG----TVGNSHKTTKEDTVSWF
30 | Header of sequence 14(14) RL11_SCHPO (113 sites)
31 | KIACHVTVRGPKAEEILERGL-----KVKEYELK---KRNFSATGNFGFGIQEHIDL-GIKYDPSIGIYGMDFYVVMDRPGMRVARRKAQRG----RVGYTHKINAEDTINWF
32 | Header of sequence 15(15) RL11_LEICH (113 sites)
33 | KIAVHCTVRGKKAEELLEKGL-----KVKEFELK---SYNFSDTGSFGFGIDEHIDL-GIKYDPSTGIYGMDFYVVLGRRGERVAHRKRKCS----RVGHSHHVTKEEAMKWF
34 | Header of sequence 16(16) RL11_DROME (113 sites)
35 | KIAVHCTVRGAKAEEILERGL-----KVREYELR---RENFSSTGNFGFGIQEHIDL-GIKYDPSIGIYGLDFYVVLGRPGYNVNHRKRKSG----TVGFQHRLTKEDAMKWF
36 | Header of sequence 17(17) RL11_HUMAN (113 sites)
37 | KIAVHCTVRGAKAEEILEKGL-----KVREYELR---KNNFSDTGNFGFGIQEHIDL-GIKYDPSIGIYGLDFYVVLGRPGFSIADKKRRTG----CIGAKHRISKEEAMRWF
38 | Header of sequence 18(18) RL11_CHLRE (113 sites)
39 | KISCYVTVRGEKAYDLVKRGL-----AVKEFELI---RKNFSDTGNFGFGIQEHIDL-GLKYDPSTGIYGMDFYVCLERRGYRVARRRKQKA----HVGVKHKVTKEDAIKWF
40 | Header of sequence 19(19) R111_ARATH (113 sites)
41 | KIACYVTVRGEKAMQLLESGL-----KVKEYELL---RRNFSDTGCFGFGIQEHIDL-GIKYDPSTGIYGMDFYVVLERPGYRVARRRRCKA----RVGIQHRVTKDDAMKWF
42 | Header of sequence 20(20) RL11_TETTH (113 sites)
43 | KMAVHVTIRGDKARDILTRGL-----KVKEMELR---KKNFSNTGNFGFGIQEHIDL-GMKYDPSTGIFGMDFYVVLERPGTRVARRRRATS----RVGNNQMISKEECINWF
44 | Test OK
45 |
46 | Fail test OK (sequence 1)
47 |
--------------------------------------------------------------------------------
/test/src/README.md:
--------------------------------------------------------------------------------
1 | # Test cases
2 |
3 | In this directory go the source of the test cases. For each test case here,
4 | there must be a matching expected output in out/ directory.
5 |
6 | When implementing a test case it is necessary to ensure that there is no
7 | errors in the output, and of course it must be deterministic. Afterwards,
8 | place the expected output in the out/ directory and re-run the validations
9 | again just to make sure that everything is working properly.
10 |
11 | Each test must focus on evaluating one or a reduced set of features. Also
12 | testing cases that should fail and it is determined how the library would
13 | behave is interesting. For example, attempting to read an unexistent file.
14 |
15 | * 00010_NMPU_lkcalc compute likelihood score for a simple unrooted tree
16 | * 00020_NMPR_lkcalc compute likelihood score for a simple rooted tree
17 |
18 | ## alpha-cats
19 |
20 | Evaluate the likelihood for different alpha shape parameters and number of
21 | categories.
22 |
23 | ## blopt-minimal
24 |
25 | (optimize module) Optimize branch lengths for a minimal tree with 3 tips and
26 | 3 branches.
27 |
28 | ## derivatives
29 |
30 | Evaluate the computation of the likelihood derivatives at different branch
31 | lengths on a small tree and msa.
32 |
33 | The derivatives are computed twice at an inner edge and at a tip edge using 3
34 | different alphas, 4 proportion of invariant sites, 3 sets of rate categories
35 | and 9 branches ranging from 0.1 to 90.
36 |
37 | ## derivatives-oddstates
38 |
39 | Analogous to `derivatives` but using an odd number of states.
40 |
41 | ## fasta-dna
42 |
43 | Read a DNA MSA in FASTA format, load the sequences into the PLL partition
44 | and evaluate the likelihood.
45 |
46 | ## fasta-prot
47 |
48 | Read an amino acid MSA in FASTA format. Checks also that 'pll_fasta_get_next'
49 | would fail if the states map is wrong (dna instead of protein map). It does
50 | not evaluate the likelihood.
51 |
52 | ## hky
53 |
54 | Evaluate the likelihood for different transition-transversion ratios in
55 | HKY models.
56 |
57 | ## odd-states
58 |
59 | Evaluate the likelihood for a data set with 7 states. This is specially
60 | important where vector intrinsics are used and the states are padded to fit
61 | the alignment.
62 |
63 | ## partial-traversal
64 |
65 | Perform partial traversals on the tree.
66 |
67 | ## protein-models
68 |
69 | Evaluate the likelihood of a short sequence under all the available empirical
70 | amino acid replacement models
71 |
72 | ## rooted
73 |
74 | Evaluate the likelihood of a tree rooted at an inner-inner node with
75 | 4 categories and 4 different proportions of invariant sites, from 0.0 to 0.9
76 |
77 | /\
78 | / \
79 | / \
80 | /\ /\
81 | / \ / \
82 |
83 | ## rooted-tipinner
84 |
85 | Evaluate the likelihood of a tree rooted at a tip-inner node with 4 categories
86 | and 4 different proportions of invariant sites, from 0.0 to 0.9
87 |
88 | /\
89 | / \
90 | / \
91 | / /\
92 | / / \
93 |
94 | ## treemove-nni
95 |
96 | Validate Nearest Neighbor Interchange moves.
97 |
98 | ## scaling
99 |
100 | Validate CLV scaling on large trees (per-site and per-rate scaling modes)
101 |
102 | ## pmatrix
103 |
104 | Validate pmatrix computation, and specifically check for negative values which could
105 | appear due to numerical issues
106 |
107 | NOTE: expected output file for this test is intentionally missing, since negative
108 | values problem has not been fully fixed yet
109 |
110 | ## treemove-spr
111 |
112 | Validate Subtree Prunning and Regrafting moves.
113 |
114 | ## treemove-tbr
115 |
116 | Perform bisection, reconnection and local branch length optimization.
117 |
--------------------------------------------------------------------------------
/test/out/partial-traversal.out:
--------------------------------------------------------------------------------
1 | Number of tip/leaf nodes in tree: 246
2 | Number of inner nodes in tree: 244
3 | Total number of nodes in tree: 490
4 | Number of branches in tree: 489
5 |
6 | Computing logL between CLV 282 and 49 - (pmatrix 49 with branch length 0.021165)
7 | Traversal size: 490
8 | Operations: 244
9 | Matrices: 489
10 | Log-L: -131248.949029
11 |
12 | Computing logL between CLV 414 and 409 - (pmatrix 409 with branch length 0.035957)
13 | Traversal size: 25
14 | Operations: 20
15 | Matrices: 25
16 | Log-L: -131248.949029
17 |
18 | Computing logL between CLV 336 and 339 - (pmatrix 336 with branch length 0.011341)
19 | Traversal size: 13
20 | Operations: 12
21 | Matrices: 13
22 | Log-L: -131248.949029
23 |
24 | Computing logL between CLV 285 and 286 - (pmatrix 285 with branch length 0.000001)
25 | Traversal size: 22
26 | Operations: 19
27 | Matrices: 22
28 | Log-L: -131248.949029
29 |
30 | Computing logL between CLV 352 and 118 - (pmatrix 118 with branch length 0.000459)
31 | Traversal size: 23
32 | Operations: 18
33 | Matrices: 22
34 | Log-L: -131248.949029
35 |
36 | Computing logL between CLV 395 and 162 - (pmatrix 162 with branch length 0.001463)
37 | Traversal size: 16
38 | Operations: 10
39 | Matrices: 15
40 | Log-L: -131248.949029
41 |
42 | Computing logL between CLV 391 and 392 - (pmatrix 391 with branch length 0.052018)
43 | Traversal size: 8
44 | Operations: 5
45 | Matrices: 8
46 | Log-L: -131248.949029
47 |
48 | Computing logL between CLV 295 and 57 - (pmatrix 57 with branch length 0.036181)
49 | Traversal size: 19
50 | Operations: 14
51 | Matrices: 18
52 | Log-L: -131248.949029
53 |
54 | Computing logL between CLV 328 and 327 - (pmatrix 327 with branch length 0.000001)
55 | Traversal size: 20
56 | Operations: 15
57 | Matrices: 20
58 | Log-L: -131248.949029
59 |
60 | Computing logL between CLV 408 and 176 - (pmatrix 176 with branch length 0.065424)
61 | Traversal size: 14
62 | Operations: 11
63 | Matrices: 13
64 | Log-L: -131248.949029
65 |
66 | Computing logL between CLV 359 and 358 - (pmatrix 358 with branch length 0.000001)
67 | Traversal size: 18
68 | Operations: 14
69 | Matrices: 18
70 | Log-L: -131248.949029
71 |
72 | Computing logL between CLV 418 and 189 - (pmatrix 189 with branch length 0.004670)
73 | Traversal size: 25
74 | Operations: 18
75 | Matrices: 24
76 | Log-L: -131248.949029
77 |
78 | Computing logL between CLV 438 and 199 - (pmatrix 199 with branch length 0.011430)
79 | Traversal size: 19
80 | Operations: 11
81 | Matrices: 18
82 | Log-L: -131248.949029
83 |
84 | Computing logL between CLV 254 and 15 - (pmatrix 15 with branch length 0.001928)
85 | Traversal size: 23
86 | Operations: 18
87 | Matrices: 22
88 | Log-L: -131248.949029
89 |
90 | Computing logL between CLV 364 and 133 - (pmatrix 133 with branch length 0.003250)
91 | Traversal size: 26
92 | Operations: 19
93 | Matrices: 25
94 | Log-L: -131248.949029
95 |
96 | Computing logL between CLV 464 and 234 - (pmatrix 234 with branch length 0.096126)
97 | Traversal size: 29
98 | Operations: 20
99 | Matrices: 28
100 | Log-L: -131248.949029
101 |
102 | Computing logL between CLV 379 and 380 - (pmatrix 379 with branch length 0.004436)
103 | Traversal size: 27
104 | Operations: 20
105 | Matrices: 27
106 | Log-L: -131248.949029
107 |
108 | Computing logL between CLV 290 and 264 - (pmatrix 264 with branch length 0.055944)
109 | Traversal size: 20
110 | Operations: 17
111 | Matrices: 20
112 | Log-L: -131248.949029
113 |
114 | Computing logL between CLV 322 and 88 - (pmatrix 88 with branch length 0.003990)
115 | Traversal size: 20
116 | Operations: 16
117 | Matrices: 19
118 | Log-L: -131248.949029
119 |
120 | Computing logL between CLV 372 and 371 - (pmatrix 371 with branch length 0.001314)
121 | Traversal size: 20
122 | Operations: 15
123 | Matrices: 20
124 | Log-L: -131248.949029
125 |
--------------------------------------------------------------------------------
/test/README.md:
--------------------------------------------------------------------------------
1 | # PLL test framework
2 |
3 | src/ - source of test cases
4 | obj/ - binaries of test cases (automatically generated)
5 | out/ - expected output
6 | result/ - output of failed tests
7 |
8 | ## Update test framework
9 |
10 | How to create a new test:
11 |
12 | 1. Place test case source file %.c into src/
13 |
14 | Use a descriptive but short name.
15 | You could also write a long description into this file
16 |
17 | 2. Add the filename to CFILES variable in the Makefile
18 |
19 | e.g.,
20 |
21 | ```
22 | CFILES = src/alpha-cats.c \
23 | src/blopt-minimal.c \
24 | ...
25 | src/newtest.c
26 | ```
27 |
28 | 3. Compile with the provided Makefile
29 |
30 | A binary with the same name (%) should be created in obj/
31 |
32 | 4. Validate it propertly!
33 |
34 | Every time you place a buggy test case, god kills a kitten
35 | (and we do not want that)
36 |
37 | 5. Pipe the output into out/%.out
38 |
39 | 6. Proceed to next section and verify it matches the output and there are no leaks
40 |
41 | ## Run the test framework
42 |
43 | 1. Run `make` for compiling the test cases
44 | 2. Run `runtest.py` for executing the tests
45 | 3. Check the output for errors
46 | 4. If any of the tests fail, go and fix your code!
47 | The wrong output will be placed in result/
48 |
49 | ## Speed test
50 |
51 | By default, runtest.py executes the validation test.
52 | The same as 'runtest.py validation'
53 |
54 | Use 'runtest.py speed' for running the speed tests
55 |
56 | ## Evaluating a subset
57 |
58 | Use 'runtest.py validation|speed test1 test2 .. testN' for evaluating a
59 | subset of test cases.
60 |
61 | e.g., ./runtest.py speed hky alpha-cats
62 |
63 | ## Naming convention
64 |
65 | Source files for testing are named after the following convention:
66 |
67 | ```
68 | NNNNN_FLAGS_NAME.c
69 | ```
70 |
71 | NNNNN is a 5-digit code with format Class (1 digit) Subclass (1 digit) and ID (3 digits)
72 | FLAGS is a set of characters identifying different features:
73 |
74 | * A/N: [A]scertainment Bias Correction or [N]ot
75 | * P/M: FASTA/PHYLIP [P]arsing or [M]anual CLVs
76 | * D/A/O: [D]NA (4 states), [A]mino acid (20 states) or [O]dd number of states
77 | * R/U: [R]ooted or [U]nrooted
78 |
79 |
80 | ## Configure the test framework
81 |
82 | Some additional features can be configured inside the test script, in the
83 | configuration section at the beginning of runtest.py file.
84 |
85 | 1. do_memtest = [0,1] : if 0, memory errors and leaks are not checked
86 | 2. num_replicates = # : number of samples evaluated in the speed test
87 | 3. all_args = [0,1,..] : set of PLL attributes that are evaluated
88 |
89 | ## Build tests for Windows
90 |
91 | 1. Build the library dll file and place them in current directory
92 |
93 | 2. Run `make -f Makefile.w64`
94 |
95 | 3. Run `./testwin.sh` for testing
96 |
97 | 4. If some dll missing files are reported, locate them and copy them
98 | in current or obj/ directory.
99 |
100 | ## Check errors
101 |
102 | If a test fails, it will produce an error output in results directory.
103 | The generated files have the following format:
104 |
105 | `testfail_ATTR_TESTNAME_DATETIME` and `testfail_ATTR_TESTNAME_DATETIME.err`
106 |
107 | Where:
108 | * `ATTR` is the set of attributes used: `A` for AVX, `C` for CPU (non-vectorized version), `T` for tip vectors.
109 | * `TESTNAME` is the name of the test (e.g., alpha-cats)
110 | * `DATETIME` is the date and time when the error failed with format YYYYMMDDhhmmss
111 | * `.err` file is the error stream output. Most times it will be a blank file.
112 |
113 | Tests output may be very complex if they print out, for example, the CLVs. The
114 | best way to check what failed in the test is usually to compare the output with
115 | the expected one:
116 |
117 | e.g., `diff testfail_ATTR_TESTNAME_DATETIME out/TESTNAME.out`
118 | `vimdiff testfail_ATTR_TESTNAME_DATETIME out/TESTNAME.out`
119 |
120 |
--------------------------------------------------------------------------------
/m4/ax_gcc_x86_cpuid.m4:
--------------------------------------------------------------------------------
1 | # ===========================================================================
2 | # http://www.gnu.org/software/autoconf-archive/ax_gcc_x86_cpuid.html
3 | # ===========================================================================
4 | #
5 | # SYNOPSIS
6 | #
7 | # AX_GCC_X86_CPUID(OP)
8 | # AX_GCC_X86_CPUID_COUNT(OP, COUNT)
9 | #
10 | # DESCRIPTION
11 | #
12 | # On Pentium and later x86 processors, with gcc or a compiler that has a
13 | # compatible syntax for inline assembly instructions, run a small program
14 | # that executes the cpuid instruction with input OP. This can be used to
15 | # detect the CPU type. AX_GCC_X86_CPUID_COUNT takes an additional COUNT
16 | # parameter that gets passed into register ECX before calling cpuid.
17 | #
18 | # On output, the values of the eax, ebx, ecx, and edx registers are stored
19 | # as hexadecimal strings as "eax:ebx:ecx:edx" in the cache variable
20 | # ax_cv_gcc_x86_cpuid_OP.
21 | #
22 | # If the cpuid instruction fails (because you are running a
23 | # cross-compiler, or because you are not using gcc, or because you are on
24 | # a processor that doesn't have this instruction), ax_cv_gcc_x86_cpuid_OP
25 | # is set to the string "unknown".
26 | #
27 | # This macro mainly exists to be used in AX_GCC_ARCHFLAG.
28 | #
29 | # LICENSE
30 | #
31 | # Copyright (c) 2008 Steven G. Johnson
32 | # Copyright (c) 2008 Matteo Frigo
33 | # Copyright (c) 2015 Michael Petch
34 | #
35 | # This program is free software: you can redistribute it and/or modify it
36 | # under the terms of the GNU General Public License as published by the
37 | # Free Software Foundation, either version 3 of the License, or (at your
38 | # option) any later version.
39 | #
40 | # This program is distributed in the hope that it will be useful, but
41 | # WITHOUT ANY WARRANTY; without even the implied warranty of
42 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
43 | # Public License for more details.
44 | #
45 | # You should have received a copy of the GNU General Public License along
46 | # with this program. If not, see .
47 | #
48 | # As a special exception, the respective Autoconf Macro's copyright owner
49 | # gives unlimited permission to copy, distribute and modify the configure
50 | # scripts that are the output of Autoconf when processing the Macro. You
51 | # need not follow the terms of the GNU General Public License when using
52 | # or distributing such scripts, even though portions of the text of the
53 | # Macro appear in them. The GNU General Public License (GPL) does govern
54 | # all other use of the material that constitutes the Autoconf Macro.
55 | #
56 | # This special exception to the GPL applies to versions of the Autoconf
57 | # Macro released by the Autoconf Archive. When you make and distribute a
58 | # modified version of the Autoconf Macro, you may extend this special
59 | # exception to the GPL to apply to your modified version as well.
60 |
61 | #serial 9
62 |
63 | AC_DEFUN([AX_GCC_X86_CPUID],
64 | [AX_GCC_X86_CPUID_COUNT($1, 0)
65 | ])
66 |
67 | AC_DEFUN([AX_GCC_X86_CPUID_COUNT],
68 | [AC_REQUIRE([AC_PROG_CC])
69 | AC_LANG_PUSH([C])
70 | AC_CACHE_CHECK(for x86 cpuid $1 output, ax_cv_gcc_x86_cpuid_$1,
71 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include ], [
72 | int op = $1, level = $2, eax, ebx, ecx, edx;
73 | FILE *f;
74 | __asm__ __volatile__ ("xchg %%ebx, %1\n"
75 | "cpuid\n"
76 | "xchg %%ebx, %1\n"
77 | : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
78 | : "a" (op), "2" (level));
79 |
80 | f = fopen("conftest_cpuid", "w"); if (!f) return 1;
81 | fprintf(f, "%x:%x:%x:%x\n", eax, ebx, ecx, edx);
82 | fclose(f);
83 | return 0;
84 | ])],
85 | [ax_cv_gcc_x86_cpuid_$1=`cat conftest_cpuid`; rm -f conftest_cpuid],
86 | [ax_cv_gcc_x86_cpuid_$1=unknown; rm -f conftest_cpuid],
87 | [ax_cv_gcc_x86_cpuid_$1=unknown])])
88 | AC_LANG_POP([C])
89 | ])
90 |
91 |
--------------------------------------------------------------------------------
/configure.ac:
--------------------------------------------------------------------------------
1 | # -*- Autoconf -*-
2 | # Process this file with autoconf to produce a configure script.
3 |
4 | AC_PREREQ([2.63])
5 | AC_INIT([libpll], [0.3.2], [Tomas.Flouri@h-its.org])
6 | AM_INIT_AUTOMAKE([subdir-objects])
7 | AC_LANG([C])
8 | AC_CONFIG_SRCDIR([src/pll.c])
9 | AC_CONFIG_HEADERS([config.h])
10 | AC_CONFIG_MACRO_DIR([m4])
11 | AC_CANONICAL_HOST
12 |
13 | # set default gcc options
14 | CFLAGS='-g'
15 |
16 | # Checks for programs.
17 | AC_PROG_CC
18 | AC_PROG_LIBTOOL
19 | AC_PROG_LEX
20 | AC_PROG_YACC
21 | AC_PROG_INSTALL
22 |
23 | if test "x$LEX" != xflex; then
24 | AC_MSG_ERROR(could not find required installation of FLEX)
25 | fi
26 |
27 | if test "x$YACC" != x"bison -y"; then
28 | AC_MSG_ERROR(could not find required installation of BISON)
29 | fi
30 |
31 | LT_INIT
32 |
33 | # Checks for libraries.
34 | AC_CHECK_LIB([m],[exp])
35 |
36 | # Checks for header files.
37 | AC_CHECK_HEADERS([assert.h math.h stdio.h stdlib.h string.h ctype.h x86intrin.h])
38 |
39 | # Checks for typedefs, structures, and compiler characteristics.
40 | AC_C_INLINE
41 | AC_TYPE_SIZE_T
42 | AC_TYPE_UINT32_T
43 | AC_TYPE_INT64_T
44 | AC_TYPE_UINT64_T
45 | AC_TYPE_UINT8_T
46 |
47 | # Checks for library functions.
48 | AC_FUNC_MALLOC
49 | AC_FUNC_ALLOCA
50 | AC_FUNC_REALLOC
51 | AC_CHECK_FUNCS([asprintf memcpy memset posix_memalign])
52 |
53 | have_avx2=no
54 | have_avx=no
55 | have_sse3=no
56 | have_ps2pdf=no
57 |
58 | # Compile-time detection of processor features - now disabled
59 | #AX_EXT
60 | #
61 | #if test "x${ax_cv_have_fma3_ext}" = "xyes"; then
62 | # have_avx2=yes
63 | #fi
64 | #
65 | #if test "x${ax_cv_have_avx_ext}" = "xyes"; then
66 | # have_avx=yes
67 | #fi
68 | #
69 | #if test "x${ax_cv_have_sse3_ext}" = "xyes"; then
70 | # have_sse3=yes
71 | #fi
72 | #
73 | #AC_ARG_ENABLE(avx2, AS_HELP_STRING([--disable-avx2], [Build without AVX2/FMA support]))
74 | #AS_IF([test "x${ax_cv_have_fma3_ext}" = "xyes"], [
75 | # have_avx2=yes
76 | #])
77 | #
78 | #AC_ARG_ENABLE(avx, AS_HELP_STRING([--disable-avx], [Build without AVX support]))
79 | #AS_IF([test "x${ax_cv_have_avx_ext}" = "xyes"], [
80 | # have_avx=yes
81 | #])
82 | #
83 | #AC_ARG_ENABLE(sse, AS_HELP_STRING([--disable-sse],[Build without SSE support]))
84 | #AS_IF([test "x${ax_cv_have_sse3_ext}" = "xyes"], [
85 | # have_sse3=yes
86 | #])
87 | #
88 |
89 | AC_ARG_ENABLE(pdfman, AS_HELP_STRING([--disable-pdfman], [Disable PDF manual creation]))
90 | AS_IF([test "x$enable_pdfman" != "xno"], [
91 | have_ps2pdf=yes
92 | AC_CHECK_PROG(HAVE_PS2PDF, ps2pdf, yes, no)
93 | if test "x$HAVE_PS2PDF" = "xno"; then
94 | AC_MSG_WARN([*** ps2pdf is required to build a PDF version of the manual])
95 | have_ps2pdf=no
96 | fi
97 | ])
98 |
99 | AC_ARG_ENABLE(sse, AS_HELP_STRING([--disable-sse], [Build without SSE support]))
100 | AS_IF([test "x$enable_sse" != "xno"], [
101 | have_sse3=yes
102 | AC_DEFINE([HAVE_SSE3], [1], [Define to 1 to support Streaming SIMD Extensions 3])
103 | ])
104 |
105 | AC_ARG_ENABLE(avx, AS_HELP_STRING([--disable-avx], [Build without AVX support]))
106 | AS_IF([test "x$enable_avx" != "xno"], [
107 | have_avx=yes
108 | AC_DEFINE([HAVE_AVX], [1], [Define to 1 to support Advanced Vector Extensions])
109 | ])
110 |
111 | AC_ARG_ENABLE(avx2, AS_HELP_STRING([--disable-avx2], [Build without AVX2/FMA support]))
112 | AS_IF([test "x$enable_avx2" != "xno"], [
113 | have_avx2=yes
114 | AC_DEFINE([HAVE_AVX2], [1], [Define to 1 to support Advanced Vector Extensions 2])
115 | ])
116 |
117 | AM_CONDITIONAL(HAVE_AVX2, test "x${have_avx2}" = "xyes")
118 | AM_CONDITIONAL(HAVE_AVX, test "x${have_avx}" = "xyes")
119 | AM_CONDITIONAL(HAVE_SSE3, test "x${have_sse3}" = "xyes")
120 | AM_CONDITIONAL(HAVE_PS2PDF, test "x${have_ps2pdf}" = "xyes")
121 | AM_PROG_CC_C_O
122 |
123 | AC_CONFIG_FILES([Makefile
124 | src/Makefile
125 | man/Makefile
126 | examples/Makefile])
127 | AC_OUTPUT
128 |
129 | AC_MSG_RESULT([
130 | $PACKAGE $VERSION
131 |
132 | Target: $host_os $host_cpu
133 | Compiler: ${CC}
134 | CFLAGS: ${CFLAGS} ${CPPFLAGS}
135 | LIBS: ${LIBS} ${LDFLAGS}
136 |
137 | Continue with 'make' command
138 | ])
139 |
--------------------------------------------------------------------------------
/ChangeLog.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 | All notable changes to `libpll` will be documented in this file.
3 | This project adheres to [Semantic Versioning](http://semver.org/).
4 |
5 | ## [0.3.2] - 2017-07-12
6 | ### Added
7 | - Optional per-rate category scalers for protein and generic kernels
8 | - Hardware detection for APPLE builds defaults to assembly code
9 | ### Fixed
10 | - Improved fix for negative p-matrix values.
11 | - Derivatives computation for Lewis/Felsenstein ascertainment bias correction
12 | - set_tipchars() for ascertainment bias correction with non-DNA sequences
13 | - Excessive memory allocation when compressing site patterns
14 | - Issue with PHYLIP parsing when header ends with CRLF
15 |
16 | ## [0.3.1] - 2017-05-17
17 | ### Added
18 | - Checks for older versions of clang and gcc to use assembly instructions
19 | for cpu features detection
20 | - Include guards for pll.h
21 | ### Fixed
22 | - Correct updating of padded eigen-decomposition arrays for models with a
23 | number of states not being a power of two
24 | - Changed to the usage of builtin functions for cpu features detection
25 | - Check for x86intrin.h
26 |
27 | ## [0.3.0] - 2017-05-15
28 | ### Added
29 | - Run-time detection of cpu features
30 | - Vectorized (AVX) computation of 20-state transition probability matrices
31 | - Faster tip-inner kernels for 20-state models
32 | - Improved AVX vectorization of derivatives
33 | - Faster PHYLIP parser
34 | - vectorized scaling for 20-state and arbitrary-state models
35 | - AVX2 vectorizations for partials, likelihood and derivatives
36 | - Unweighted parsimony functions including SSE, AVX and AVX2 vectorizations
37 | - Randomized stepwise addition
38 | - Portable functions for parsing trees from a C-string
39 | - Optional per-rate category scalers to prevent numerical underflows on large
40 | trees
41 | - Setting of identity matrix if all exponentiations of eigenvalues multiplied
42 | by branch length and rate are approximately equal to one
43 | - Re-entrant cross-platform pseudo-random number generator
44 | - Wrapper tree structures
45 | - Custom exporting of tree structures using a callback function
46 | - Support for median category rates in discrete gamma model
47 |
48 | ### Fixed
49 | - Derivatives computation
50 | - Parsing of branch lengths in newick trees
51 | - Invariant sites computation
52 | - Multiplication of log-likelihood with pattern weight after scaling term
53 | - Added destructors for eliminating memory leaks when tree parsing fails
54 | - Sumtable computation when having multiple substitution matrices
55 | - Ascertainment bias computation
56 | - Per-site log-likelihood computation
57 | - Uninitialized values in testing framework
58 |
59 |
60 |
61 | ## [0.2.0] - 2016-09-09
62 | ### Added
63 | - Methods for ascertainment bias correction (Lewis, Felsenstein, Stamatakis)
64 | - Functions for performing NNI and SPR moves on unrooted trees
65 | - Iterator function (pll_utree_every)
66 | - Vectorized (AVX) computation of derivatives and sumtable
67 | - restructure of source code such that higher-level functions call lower level
68 | (core) functions
69 | - Vectorized (AVX and SSE) functions for log-likelihood computation on rooted
70 | and unrooted trees
71 | - Implementation of Sankoff's dynamic programming parsimony algorithm, which
72 | allows for arbitrary scoring matrices and facilitates ancestral state
73 | reconstruction
74 | - Faster vectorization scheme for computing partials under an arbitrary number
75 | of states
76 | - SSE vectorization for computing partials
77 | - Faster lookup table constructionf or tip-tip case (PLL_ATTRIB_PATTERN_TIP)
78 | - More error codes
79 | - AVX and SSE vectorized functions for updating transition probability matrices
80 | - SVG visualization for unrooted trees
81 | - man pages
82 |
83 | ### Fixed
84 | - When the number of states is not a power of 2, the log-likelihood results to
85 | -inf if PLL_ATTRIB_PATTERN_TIP is used
86 | - Missing memory initialization when using site pattern compression
87 | - Erroneous charmap usage in pattern compression
88 | - Removed likelihood computation from the function computing derivatives
89 | - bug in unrooted tree clone function
90 |
91 | ## [0.1.0] - 2016-05-25
92 | ### Added
93 | - AVX implementation for updating partials
94 | - Core functions
95 | - Selection between character states and cond. probability vectors for tips
96 | - Compatibility with MS Windows
97 | - Added basic PHYLIP parsing
98 | - Functions for obtaining first/second derivatives to approximate LH function
99 | - Trimming of line-feed/carriage-return when reading FASTA files
100 |
101 | ### Changed
102 | - Selection of a specific rate matrix selection for each rate category
103 |
104 | ### Fixed
105 | - Newick parsers handle arbitrary string literals as taxon names
106 |
--------------------------------------------------------------------------------
/src/lex_utree.l:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Tomas Flouri ,
18 | Heidelberg Institute for Theoretical Studies,
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 | %{
22 | #include "parse_utree.h"
23 | #include "pll.h"
24 |
25 | #define YY_USER_ACTION preaction();
26 |
27 | static size_t string_length = 0;
28 |
29 | int pll_utree_colstart = 0;
30 | int pll_utree_colend = 0;
31 |
32 | static void preaction()
33 | {
34 | pll_utree_colstart = pll_utree_colend;
35 | pll_utree_colend = pll_utree_colend + pll_utree_leng - 1;
36 | }
37 |
38 | static char * xstrndup(const char * s, size_t len)
39 | {
40 | char * p = (char *)malloc(len+1);
41 | if (!p)
42 | {
43 | pll_errno = PLL_ERROR_MEM_ALLOC;
44 | snprintf(pll_errmsg, 200, "Unable to allocate enough memory.");
45 | return PLL_FAILURE;
46 | }
47 | strncpy(p,s,len);
48 | p[len] = 0;
49 | return p;
50 | }
51 |
52 | static char * append(size_t * dstlen, const char * src, size_t srclen)
53 | {
54 | char * mem = (char *)malloc((*dstlen + srclen + 1)*sizeof(char));
55 | if (!mem)
56 | {
57 | pll_errno = PLL_ERROR_MEM_ALLOC;
58 | snprintf(pll_errmsg, 200, "Unable to allocate enough memory.");
59 | return PLL_FAILURE;
60 | }
61 | memcpy(mem,pll_utree_lval.s,*dstlen);
62 | strncpy(mem+(*dstlen),src,srclen);
63 | mem[*dstlen+srclen] = 0;
64 | if (*dstlen)
65 | free(pll_utree_lval.s);
66 | pll_utree_lval.s = mem;
67 | *dstlen += srclen;
68 | return pll_utree_lval.s;
69 | }
70 |
71 | %}
72 | %option noyywrap
73 | %option prefix="pll_utree_"
74 | %option nounput
75 | %option noinput
76 | %option yylineno
77 | %x apos
78 | %x quot
79 |
80 | %%
81 | {
82 | \\\" { append(&string_length, "\\\"", 2); }
83 | \' { append(&string_length, "\'", 1); }
84 | \" { BEGIN(INITIAL); return STRING; }
85 | }
86 |
87 | {
88 | \\\' { append(&string_length, "\\\'", 2); }
89 | \" { append(&string_length, "\"", 1); }
90 | \' { BEGIN(INITIAL);return STRING;}
91 | }
92 |
93 | {
94 | \\n { append(&string_length, "\\n", 2); }
95 | \\t { append(&string_length, "\\t", 2); }
96 | \\ { append(&string_length, "\\", 1); }
97 | \\\\ { append(&string_length, "\\\\", 2); }
98 | ([^\"\'\\]|\n)+ { append(&string_length, pll_utree_text, pll_utree_leng); }
99 | }
100 |
101 | \: { return COLON; }
102 | \; { return SEMICOLON; }
103 | \) { return CPAR; }
104 | \( { return OPAR; }
105 | \, { return COMMA; }
106 | \" { string_length = 0; BEGIN(quot); }
107 | \' { string_length = 0; BEGIN(apos); }
108 | \n { pll_utree_colstart = pll_utree_colend = 0; }
109 | [-+]?[0-9]+ { pll_utree_lval.d = xstrndup(pll_utree_text,pll_utree_leng);
110 | return NUMBER; }
111 | [+-]?(([0-9]+[\.]?[0-9]*)|([0-9]*[\.]?[0-9]+))([eE][+-]?[0-9]+)? {
112 | pll_utree_lval.d = xstrndup(pll_utree_text,pll_utree_leng);
113 | return NUMBER; }
114 | [^ \'\",\(\):;\[\]\t\n\r][^ \t\n\r\)\(\[\]\,:;]* {
115 | pll_utree_lval.s = xstrndup(pll_utree_text,pll_utree_leng);
116 | return STRING; }
117 | [ \t\r] { ; }
118 | . { snprintf(pll_errmsg, 200,
119 | "Syntax error (%c)\n", pll_utree_text[0]);
120 | pll_errno = PLL_ERROR_NEWICK_SYNTAX;
121 | return PLL_FAILURE; }
122 | %%
123 |
--------------------------------------------------------------------------------
/src/lex_rtree.l:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Tomas Flouri ,
18 | Heidelberg Institute for Theoretical Studies,
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 | %{
22 | #include "parse_rtree.h"
23 | #include "pll.h"
24 |
25 | #define YY_USER_ACTION preaction();
26 |
27 | static size_t string_length = 0;
28 |
29 | int pll_rtree_colstart = 0;
30 | int pll_rtree_colend = 0;
31 |
32 | static void preaction()
33 | {
34 | pll_rtree_colstart = pll_rtree_colend;
35 | pll_rtree_colend = pll_rtree_colend + pll_rtree_leng - 1;
36 | }
37 |
38 | static char * xstrndup(const char * s, size_t len)
39 | {
40 | char * p = (char *)malloc(len+1);
41 | if (!p)
42 | {
43 | pll_errno = PLL_ERROR_MEM_ALLOC;
44 | snprintf(pll_errmsg, 200, "Unable to allocate enough memory.");
45 | return PLL_FAILURE;
46 | }
47 | strncpy(p,s,len);
48 | p[len] = 0;
49 | return p;
50 | }
51 |
52 | static char * append(size_t * dstlen, const char * src, size_t srclen)
53 | {
54 | char * mem = (char *)malloc((*dstlen + srclen + 1)*sizeof(char));
55 | if (!mem)
56 | {
57 | pll_errno = PLL_ERROR_MEM_ALLOC;
58 | snprintf(pll_errmsg, 200, "Unable to allocate enough memory.");
59 | return PLL_FAILURE;
60 | }
61 | memcpy(mem,pll_rtree_lval.s,*dstlen);
62 | strncpy(mem+(*dstlen),src,srclen);
63 | mem[*dstlen+srclen] = 0;
64 | if (*dstlen)
65 | free(pll_rtree_lval.s);
66 | pll_rtree_lval.s = mem;
67 | *dstlen += srclen;
68 | return pll_rtree_lval.s;
69 | }
70 |
71 | %}
72 | %option noyywrap
73 | %option prefix="pll_rtree_"
74 | %option nounput
75 | %option noinput
76 | %option yylineno
77 | %x apos
78 | %x quot
79 |
80 | %%
81 | {
82 | \\\" { append(&string_length, "\\\"", 2); }
83 | \' { append(&string_length, "\'", 1); }
84 | \" { BEGIN(INITIAL); return STRING; }
85 | }
86 |
87 | {
88 | \\\' { append(&string_length, "\\\'", 2); }
89 | \" { append(&string_length, "\"", 1); }
90 | \' { BEGIN(INITIAL); return STRING; }
91 | }
92 |
93 | {
94 | \\n { append(&string_length, "\\n", 2); }
95 | \\t { append(&string_length, "\\t", 2); }
96 | \\ { append(&string_length, "\\", 1); }
97 | \\\\ { append(&string_length, "\\\\", 2); }
98 | ([^\"\'\\]|\n)+ { append(&string_length, pll_rtree_text, pll_rtree_leng); }
99 | }
100 |
101 | \: { return COLON; }
102 | \; { return SEMICOLON; }
103 | \) { return CPAR; }
104 | \( { return OPAR; }
105 | \, { return COMMA; }
106 | \" { string_length = 0; BEGIN(quot); }
107 | \' { string_length = 0; BEGIN(apos); }
108 | \n { pll_rtree_colstart = pll_rtree_colend = 0; }
109 | [-+]?[0-9]+ { pll_rtree_lval.d = xstrndup(pll_rtree_text,pll_rtree_leng);
110 | return NUMBER; }
111 | [+-]?(([0-9]+[\.]?[0-9]*)|([0-9]*[\.]?[0-9]+))([eE][+-]?[0-9]+)? {
112 | pll_rtree_lval.d = xstrndup(pll_rtree_text,pll_rtree_leng);
113 | return NUMBER; }
114 | [^ \'\",\(\):;\[\]\t\n\r][^ \t\n\r\)\(\[\]\,:;]* {
115 | pll_rtree_lval.s = xstrndup(pll_rtree_text,pll_rtree_leng);
116 | return STRING; }
117 | [ \t\r] { ; }
118 | . { snprintf(pll_errmsg, 200,
119 | "Syntax error (%c)\n", pll_rtree_text[0]);
120 | pll_errno = PLL_ERROR_NEWICK_SYNTAX;
121 | return PLL_FAILURE; }
122 | %%
123 |
--------------------------------------------------------------------------------
/test/src/00120_NPAN_fasta.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Diego Darriba, Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Diego Darriba ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 | #include "common.h"
22 | #include
23 | #include
24 |
25 | #define ALPHA 0.5
26 | #define N_STATES 20
27 | #define N_RATE_CATS 4
28 |
29 | #define N_TAXA 21
30 | #define N_SITES 112
31 |
32 | static int failtest(unsigned int attributes)
33 | {
34 | unsigned int i;
35 | char * seq, *header;
36 | long seq_len, header_len, seqno;
37 | pll_fasta_t * fp;
38 | pll_partition_t * partition;
39 |
40 | partition = pll_partition_create(N_TAXA, /* tips */
41 | 4, /* clv buffers */
42 | N_STATES, /* states */
43 | N_SITES, /* sites */
44 | 1, /* different rate parameters */
45 | 8, /* probability matrices */
46 | N_RATE_CATS, /* rate categories */
47 | 1,
48 | attributes
49 | );
50 |
51 | fp = pll_fasta_open ("testdata/ribosomal_l5_pf00673.fas", pll_map_fasta);
52 |
53 | i = 0;
54 | while (pll_fasta_getnext (fp, &header, &header_len, &seq, &seq_len, &seqno))
55 | {
56 | if (!pll_set_tip_states (partition, i, pll_map_nt, seq))
57 | {
58 | free (header);
59 | free (seq);
60 | pll_fasta_close (fp);
61 | pll_partition_destroy(partition);
62 | return (i+1);
63 | }
64 | free (header);
65 | free (seq);
66 | ++i;
67 | }
68 |
69 | return PLL_FAILURE;
70 | }
71 |
72 | static int proteintest(unsigned int attributes)
73 | {
74 | unsigned int i;
75 | char * seq, *header;
76 | long seq_len, header_len, seqno;
77 | pll_fasta_t * fp;
78 | pll_partition_t * partition;
79 |
80 | printf ("Creating PLL partition\n");
81 |
82 | partition = pll_partition_create(N_TAXA, /* tips */
83 | 4, /* clv buffers */
84 | N_STATES, /* states */
85 | N_SITES, /* sites */
86 | 1, /* different rate parameters */
87 | 8, /* probability matrices */
88 | N_RATE_CATS, /* rate categories */
89 | 1,
90 | attributes);
91 |
92 | fp = pll_fasta_open ("testdata/ribosomal_l5_pf00673.fas", pll_map_fasta);
93 | if (!fp)
94 | {
95 | printf (" ERROR opening file (%d): %s\n", pll_errno, pll_errmsg);
96 | return (PLL_FAILURE);
97 | }
98 |
99 | i = 0;
100 | while (pll_fasta_getnext (fp, &header, &header_len, &seq, &seq_len, &seqno))
101 | {
102 | if (seq_len != (N_SITES + 1))
103 | {
104 | printf (
105 | " ERROR: Mismatching sequence length for sequence %d (%ld, and it should be %d)\n",
106 | i, seq_len - 1, N_SITES);
107 | return (PLL_FAILURE);
108 | }
109 | if (!pll_set_tip_states (partition, i, pll_map_aa, seq))
110 | {
111 | printf (" ERROR setting states (%d): %s\n", pll_errno, pll_errmsg);
112 | return (PLL_FAILURE);
113 | }
114 | printf ("Header of sequence %d(%ld) %s (%ld sites)\n", i, seqno, header,
115 | seq_len);
116 | printf (" %s\n", seq);
117 | free (header);
118 | free (seq);
119 | ++i;
120 | }
121 |
122 | if (pll_errno != PLL_ERROR_FILE_EOF)
123 | {
124 | printf (" ERROR at the end (%d): %s\n", pll_errno, pll_errmsg);
125 | return (PLL_FAILURE);
126 | }
127 |
128 | if (i != N_TAXA)
129 | {
130 | printf (" ERROR: Number of taxa mismatch (%d): %d\n", i, N_TAXA);
131 | return (PLL_FAILURE);
132 | }
133 |
134 | pll_fasta_close (fp);
135 | pll_partition_destroy(partition);
136 |
137 | return PLL_SUCCESS;
138 | }
139 |
140 | int main (int argc, char * argv[])
141 | {
142 | unsigned int attributes = get_attributes(argc, argv);
143 |
144 | if (proteintest (attributes))
145 | printf ("Test OK\n\n");
146 |
147 | int fail_retval = failtest (attributes);
148 | if (fail_retval)
149 | printf ("Fail test OK (sequence %d)\n", fail_retval);
150 |
151 | return PLL_SUCCESS;
152 | }
153 |
--------------------------------------------------------------------------------
/examples/heterotachy/README.md:
--------------------------------------------------------------------------------
1 | # Heterotachous models example
2 |
3 | This examples evaluates the log-likelihood of the unrooted tree presented in
4 | the figure below, by creating a custom post-order traversal that drives the
5 | likelihood computation. The model used accounts for heterotachy, using 3
6 | different rate matrices, which are applied on different branches of the tree.
7 |
8 | 
9 |
10 | ## Explanation of the example
11 |
12 | The example is based on the unrooted tree example. Here are explained the
13 | features related to heterotachous models.
14 |
15 | ```C
16 | partition = pll_partition_create(4,
17 | 2,
18 | 4,
19 | 6,
20 | rmatrix_count,
21 | 5,
22 | 4,
23 | 1,
24 | PLL_ATTRIB_ARCH_SSE);
25 | ```
26 |
27 | The number of different rate matrices (composed from substitution rates and
28 | frequencies) has to be defined when calling the function
29 | `pll_partition_create`. It might happen that these number changes through time,
30 | for example if we want to optimize the number of per-branch models. In that
31 | case, here specify the **maximum** number of different models we would like to
32 | store.
33 |
34 | For a more detailed explanation of the function arguments refer to the [API Reference](https://github.com/xflouris/libpll/wiki/API-Reference#pll_partition_create).
35 |
36 | We set the frequencies and substitution rates for each of the `rmatrix_count`
37 | rate matrices.
38 |
39 | [`pll_set_frequencies(partition, i, 0, frequencies[i]);`](https://github.com/xflouris/libpll/wiki/API-Reference#void-pll_set_frequencies)
40 |
41 | [`pll_set_subst_params(partition, i, 0, subst_params[i], 6);`](https://github.com/xflouris/libpll/wiki/API-Reference#void-pll_set_subst_params)
42 |
43 | Next, we compute the transition probability matrices for each unique branch
44 | length in the tree. The plan here is to create the first two transition
45 | matrices (p-matrices) using the first rate matrix, p-matrices 3 and 4 using the
46 | second rate matrix, and p-matrix 5 using the third rate matrix. We accomplish
47 | this assignment with the following three arrays
48 |
49 | ```C
50 | unsigned int matrix_indices[5] = {0,1,2,3,4};
51 | unsigned int matrix_start[3] = {0,2,4};
52 | unsigned int matrix_count[3] = {2,2,1};
53 | ```
54 |
55 | and the custom function `update_pmatrices`
56 |
57 | ```C
58 | static void update_pmatrix_het(pll_partition_t * partition,
59 | unsigned int * matrix_indices,
60 | unsigned int * matrix_start,
61 | unsigned int * matrix_count,
62 | double * branch_lengths)
63 | {
64 | unsigned int i;
65 | unsigned int params_indices[4];
66 |
67 | for (i=0; i.
16 |
17 | Contact: Tomas Flouri ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 |
22 | #include "pll.h"
23 | #include
24 | #include
25 |
26 | static void fatal(const char * format, ...) __attribute__ ((noreturn));
27 |
28 | static void fatal(const char * format, ...)
29 | {
30 | va_list argptr;
31 | va_start(argptr, format);
32 | vfprintf(stderr, format, argptr);
33 | va_end(argptr);
34 | fprintf(stderr, "\n");
35 | exit(EXIT_FAILURE);
36 | }
37 |
38 | typedef struct nodedata_s
39 | {
40 | double support;
41 | double rvalue;
42 | } nodedata_t;
43 |
44 | /* a callback function that prints the following information for the two types
45 | * of nodes, tips and inners:
46 |
47 |
48 | for tip nodes:
49 | label, branch length and support value
50 |
51 | for inner nodes:
52 | label, branch length, support value, and a random value
53 |
54 | Note that this is not a standard format that can be read by all tree viewers
55 |
56 | Check the extended newick format for a more widespread notation:
57 | http://dmi.uib.es/~gcardona/BioInfo/enewick.html
58 |
59 | */
60 | static char * cb_serialize(const pll_unode_t * node)
61 | {
62 | char * s = NULL;
63 | nodedata_t * nd;
64 |
65 |
66 | /* inner node */
67 | if (node->next)
68 | {
69 | /* find which node of the round-about has the data element */
70 | if (node->data)
71 | nd = (nodedata_t *)(node->data);
72 | else if (node->next->data)
73 | nd = (nodedata_t *)(node->next->data);
74 | else
75 | nd = (nodedata_t *)(node->next->next->data);
76 |
77 | asprintf(&s,
78 | "%s[&support=%f,rvalue=%f]:%f",
79 | node->label ? node->label : "",
80 | nd->support,
81 | nd->rvalue,
82 | node->length);
83 | }
84 | else
85 | {
86 | nd = (nodedata_t *)(node->data);
87 | asprintf(&s,
88 | "%s[&support=%f]:%f",
89 | node->label ? node->label : "",
90 | nd->support,
91 | node->length);
92 | }
93 |
94 | return s;
95 | }
96 |
97 | pll_utree_t * load_tree_unrooted(const char * filename)
98 | {
99 | pll_utree_t * utree;
100 | pll_rtree_t * rtree;
101 |
102 | if (!(rtree = pll_rtree_parse_newick(filename)))
103 | {
104 | if (!(utree = pll_utree_parse_newick(filename)))
105 | {
106 | fprintf(stderr, "%s\n", pll_errmsg);
107 | return NULL;
108 | }
109 | }
110 | else
111 | {
112 | utree = pll_rtree_unroot(rtree);
113 |
114 | pll_unode_t * root = utree->nodes[utree->tip_count+utree->inner_count-1];
115 |
116 | /* optional step if using default PLL clv/pmatrix index assignments */
117 | pll_utree_reset_template_indices(root, utree->tip_count);
118 |
119 | pll_rtree_destroy(rtree,NULL);
120 | }
121 |
122 | return utree;
123 | }
124 |
125 | int main(int argc, char * argv[])
126 | {
127 | unsigned int i;
128 |
129 | if (argc != 2)
130 | fatal("syntax: %s [newick]", argv[0]);
131 |
132 | /* initialize pseudo-random number generator */
133 | srandom(time(NULL));
134 |
135 | /* load tree as unrooted */
136 | pll_utree_t * utree = load_tree_unrooted(argv[1]);
137 | if (!utree)
138 | fatal("Tree must be a rooted or unrooted binary.");
139 |
140 | /* set random support values for tip nodes */
141 | for (i = 0; i < utree->tip_count; ++i)
142 | {
143 | pll_unode_t * node = utree->nodes[i];
144 | nodedata_t * data;
145 |
146 | node->data = malloc(sizeof(nodedata_t));
147 |
148 | data = (nodedata_t *)(node->data);
149 |
150 | data->support = random() / (double)RAND_MAX;
151 | }
152 |
153 | /* set random support values and a random value to each inner node, but
154 | allocate the structure in only one of the three round-about nodes that make
155 | up an inner node */
156 | for (i = utree->tip_count; i < utree->tip_count + utree->inner_count; ++i)
157 | {
158 | pll_unode_t * node = utree->nodes[i];
159 | nodedata_t * data;
160 |
161 | node->data = malloc(sizeof(nodedata_t));
162 |
163 | data = (nodedata_t *)(node->data);
164 |
165 | data->support = random() / (double)RAND_MAX;
166 | data->rvalue = data->support * random();
167 | }
168 |
169 | /* select a random inner node */
170 | long int r = random() % utree->inner_count;
171 | pll_unode_t * root = utree->nodes[utree->tip_count + r];
172 |
173 | /* export the tree to newick format with the selected inner node as the root
174 | of the unrooted binary tree.
175 |
176 | If we pass NULL as the callback function, then the tree is printed in newick
177 | format with branch lengths only, i.e.
178 |
179 | char * newick = pll_utree_export_newick(root,NULL);
180 | */
181 |
182 | char * newick = pll_utree_export_newick(root,cb_serialize);
183 |
184 | printf("%s\n", newick);
185 |
186 | free(newick);
187 |
188 | pll_utree_destroy(utree,free);
189 |
190 | return 0;
191 | }
192 |
--------------------------------------------------------------------------------
/test/src/hky.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Diego Darriba, Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Diego Darriba ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 | #include "pll.h"
22 |
23 | #define NUM_TESTS 10
24 | #define N_STATES_NT 4
25 | #define N_CAT_GAMMA 4
26 | #define FLOAT_PRECISION 4
27 |
28 | static double titv[NUM_TESTS] = {
29 | 0.175, 1, 1.5, 2.25, 2.725, 4, 7.125, 8.19283745, 9.73647382, 10
30 | };
31 |
32 | int main(int argc, char * argv[])
33 | {
34 | unsigned int i,j;
35 | double lk_scores[NUM_TESTS];
36 |
37 | double alpha = 1.0;
38 |
39 | unsigned int n_sites = 20;
40 | unsigned int n_tips = 5;
41 | unsigned int params_indices[N_CAT_GAMMA] = {0,0,0,0};
42 |
43 | pll_partition_t * partition;
44 | pll_operation_t * operations;
45 | partition = pll_partition_create(n_tips,
46 | 4, /* clv buffers */
47 | N_STATES_NT, /* number of states */
48 | n_sites, /* sequence length */
49 | 1, /* different rate parameters */
50 | 2*n_tips-3, /* probability matrices */
51 | N_CAT_GAMMA, /* gamma categories */
52 | 0, /* scale buffers */
53 | PLL_ATTRIB_ARCH_AVX //| PLL_ATTRIB_PATTERN_TIP
54 | ); /* attributes */
55 | double branch_lengths[4] = { 0.1, 0.2, 1, 1};
56 | double frequencies[4] = { 0.3, 0.4, 0.1, 0.2 };
57 | unsigned int matrix_indices[4] = { 0, 1, 2, 3 };
58 | double subst_params[6] = {1,1,1,1,1,1};
59 | double rate_cats[4];
60 |
61 | pll_compute_gamma_cats(alpha, N_CAT_GAMMA, rate_cats, PLL_GAMMA_RATES_MEAN);
62 |
63 | pll_set_frequencies(partition, 0, frequencies);
64 |
65 | pll_set_category_rates(partition, rate_cats);
66 |
67 | pll_set_tip_states(partition, 0, pll_map_nt, "WAACTCGCTA--ATTCTAAT");
68 | pll_set_tip_states(partition, 1, pll_map_nt, "CACCATGCTA--ATTGTCTT");
69 | pll_set_tip_states(partition, 2, pll_map_nt, "AG-C-TGCAG--CTTCTACT");
70 | pll_set_tip_states(partition, 3, pll_map_nt, "CGTCTTGCAA--AT-C-AAG");
71 | pll_set_tip_states(partition, 4, pll_map_nt, "CGACTTGCCA--AT-T-AAG");
72 |
73 | operations = (pll_operation_t *)malloc(4* sizeof(pll_operation_t));
74 |
75 | operations[0].parent_clv_index = 5;
76 | operations[0].child1_clv_index = 0;
77 | operations[0].child2_clv_index = 1;
78 | operations[0].child1_matrix_index = 1;
79 | operations[0].child2_matrix_index = 1;
80 | operations[0].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
81 | operations[0].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
82 | operations[0].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
83 |
84 | operations[1].parent_clv_index = 6;
85 | operations[1].child1_clv_index = 5;
86 | operations[1].child2_clv_index = 2;
87 | operations[1].child1_matrix_index = 0;
88 | operations[1].child2_matrix_index = 1;
89 | operations[1].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
90 | operations[1].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
91 | operations[1].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
92 |
93 | operations[2].parent_clv_index = 7;
94 | operations[2].child1_clv_index = 3;
95 | operations[2].child2_clv_index = 4;
96 | operations[2].child1_matrix_index = 1;
97 | operations[2].child2_matrix_index = 1;
98 | operations[2].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
99 | operations[2].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
100 | operations[2].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
101 |
102 | for (i = 0; i < NUM_TESTS; ++i)
103 | {
104 | subst_params[1] = subst_params[4] = titv[i];
105 | pll_set_subst_params(partition, 0, subst_params);
106 |
107 | pll_update_prob_matrices(partition,
108 | params_indices,
109 | matrix_indices,
110 | branch_lengths,
111 | 4);
112 |
113 | pll_update_partials(partition, operations, 3);
114 |
115 | printf("\n\n TEST ti/tv = %.4f\n\n", titv[i]);
116 |
117 | for (j = 0; j < 4; ++j)
118 | {
119 | printf ("[%d] P-matrix for branch length %.4f\n", i, branch_lengths[j]);
120 | pll_show_pmatrix(partition, j, FLOAT_PRECISION);
121 | printf ("\n");
122 | }
123 |
124 | printf ("[%d] Tip 0: ", i);
125 | pll_show_clv(partition,0,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
126 | printf ("[%d] Tip 1: ", i);
127 | pll_show_clv(partition,1,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
128 | printf ("[%d] Tip 2: ", i);
129 | pll_show_clv(partition,2,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
130 | printf ("[%d] Tip 3: ", i);
131 | pll_show_clv(partition,3,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
132 | printf ("[%d] Tip 4: ", i);
133 | pll_show_clv(partition,4,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
134 | printf ("[%d] CLV 5: ", i);
135 | pll_show_clv(partition,5,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
136 | printf ("[%d] CLV 6: ", i);
137 | pll_show_clv(partition,6,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
138 | printf ("[%d] CLV 7: ", i);
139 | pll_show_clv(partition,7,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
140 |
141 | lk_scores[i] = pll_compute_edge_loglikelihood(partition,
142 | 6,
143 | PLL_SCALE_BUFFER_NONE,
144 | 7,
145 | PLL_SCALE_BUFFER_NONE,
146 | 0,
147 | params_indices,
148 | NULL);
149 | }
150 |
151 | printf("\n");
152 | for (i = 0; i < NUM_TESTS; ++i)
153 | {
154 | printf("ti/tv: %14.4f logL: %17.4f\n", titv[i], lk_scores[i]);
155 | }
156 |
157 | free(operations);
158 | pll_partition_destroy(partition);
159 |
160 | return (0);
161 | }
162 |
--------------------------------------------------------------------------------
/src/hardware.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2017 Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Tomas Flouri ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 |
22 | #include "pll.h"
23 |
24 | /*
25 | Apple machines should always default to assembly code due to
26 | inconsistent versioning in LLVM/clang, see issue #138
27 |
28 | https://github.com/xflouris/libpll/issues/138
29 |
30 | */
31 | #if (defined(__APPLE__)) || \
32 | (!defined(__clang__) && defined(__GNUC__) && (__GNUC__ < 4 || \
33 | (__GNUC__ == 4 && __GNUC_MINOR__ < 8))) || \
34 | (defined(__clang__) && (__clang_major__ < 3 || \
35 | (__clang_major__ == 3 && __clang_minor__ < 9)))
36 |
37 | #if defined(__i386__) && defined(__PIC__)
38 | #if (defined(__GNUC__) && __GNUC__ < 3)
39 | #define cpuid(level, count, a, b, c, d) \
40 | __asm__ ("xchgl\t%%ebx, %k1\n\t" \
41 | "cpuid\n\t" \
42 | "xchgl\t%%ebx, %k1\n\t" \
43 | : "=a" (a), "=&r" (b), "=c" (c), "=d" (d) \
44 | : "0" (level), "2" (count))
45 | #else
46 | #define cpuid(level, count, a, b, c, d) \
47 | __asm__ ("xchg{l}\t{%%}ebx, %k1\n\t" \
48 | "cpuid\n\t" \
49 | "xchg{l}\t{%%}ebx, %k1\n\t" \
50 | : "=a" (a), "=&r" (b), "=c" (c), "=d" (d) \
51 | : "0" (level), "2" (count))
52 | #endif
53 | #elif defined(__x86_64__) && (defined(__code_model_medium__) || \
54 | defined(__code_model_large__)) && defined(__PIC__)
55 | #define cpuid(level, count, a, b, c, d) \
56 | __asm__ ("xchg{q}\t{%%}rbx, %q1\n\t" \
57 | "cpuid\n\t" \
58 | "xchg{q}\t{%%}rbx, %q1\n\t" \
59 | : "=a" (a), "=&r" (b), "=c" (c), "=d" (d) \
60 | : "0" (level), "2" (count))
61 | #else
62 | #define cpuid(level, count, a, b, c, d) \
63 | __asm__ ("cpuid\n\t" \
64 | : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
65 | : "0" (level), "2" (count))
66 | #endif
67 |
68 | static void cpu_features_detect()
69 | {
70 | unsigned int a,b,c,d;
71 |
72 | memset(&pll_hardware,0,sizeof(pll_hardware_t));
73 |
74 | pll_hardware.init = 1;
75 |
76 | #if defined(__PPC__)
77 | pll_hardware.altivec_present = 1;
78 | #else
79 |
80 | cpuid(0,0,a,b,c,d);
81 | unsigned int maxlevel = a & 0xff;
82 |
83 | if (maxlevel >= 1)
84 | {
85 | cpuid(1,0,a,b,c,d);
86 | pll_hardware.mmx_present = (d >> 23) & 1;
87 | pll_hardware.sse_present = (d >> 25) & 1;
88 | pll_hardware.sse2_present = (d >> 26) & 1;
89 | pll_hardware.sse3_present = (c >> 0) & 1;
90 | pll_hardware.ssse3_present = (c >> 9) & 1;
91 | pll_hardware.sse41_present = (c >> 19) & 1;
92 | pll_hardware.sse42_present = (c >> 20) & 1;
93 | pll_hardware.popcnt_present = (c >> 23) & 1;
94 | pll_hardware.avx_present = (c >> 28) & 1;
95 |
96 | if (maxlevel >= 7)
97 | {
98 | cpuid(7,0,a,b,c,d);
99 | pll_hardware.avx2_present = (b >> 5) & 1;
100 | }
101 | }
102 | #endif
103 | }
104 |
105 | #else
106 |
107 |
108 | static void cpu_features_detect()
109 | {
110 | memset(&pll_hardware,0,sizeof(pll_hardware_t));
111 |
112 | pll_hardware.init = 1;
113 | #if defined(__PPC__)
114 | pll_hardware.altivec_present = __builtin_cpu_supports("altivec");
115 | #elif defined(__x86_64__) || defined(__i386__)
116 | pll_hardware.mmx_present = __builtin_cpu_supports("mmx");
117 | pll_hardware.sse_present = __builtin_cpu_supports("sse");
118 | pll_hardware.sse2_present = __builtin_cpu_supports("sse2");
119 | pll_hardware.sse3_present = __builtin_cpu_supports("sse3");
120 | pll_hardware.ssse3_present = __builtin_cpu_supports("ssse3");
121 | pll_hardware.sse41_present = __builtin_cpu_supports("sse4.1");
122 | pll_hardware.sse42_present = __builtin_cpu_supports("sse4.2");
123 | pll_hardware.popcnt_present = __builtin_cpu_supports("popcnt");
124 | pll_hardware.avx_present = __builtin_cpu_supports("avx");
125 | pll_hardware.avx2_present = __builtin_cpu_supports("avx2");
126 | #endif
127 | }
128 |
129 | #endif
130 |
131 | static void cpu_features_show()
132 | {
133 | fprintf(stderr, "CPU features:");
134 | if (pll_hardware.altivec_present)
135 | fprintf(stderr, " altivec");
136 | if (pll_hardware.mmx_present)
137 | fprintf(stderr, " mmx");
138 | if (pll_hardware.sse_present)
139 | fprintf(stderr, " sse");
140 | if (pll_hardware.sse2_present)
141 | fprintf(stderr, " sse2");
142 | if (pll_hardware.sse3_present)
143 | fprintf(stderr, " sse3");
144 | if (pll_hardware.ssse3_present)
145 | fprintf(stderr, " ssse3");
146 | if (pll_hardware.sse41_present)
147 | fprintf(stderr, " sse4.1");
148 | if (pll_hardware.sse42_present)
149 | fprintf(stderr, " sse4.2");
150 | if (pll_hardware.popcnt_present)
151 | fprintf(stderr, " popcnt");
152 | if (pll_hardware.avx_present)
153 | fprintf(stderr, " avx");
154 | if (pll_hardware.avx2_present)
155 | fprintf(stderr, " avx2");
156 | fprintf(stderr, "\n");
157 | }
158 |
159 | PLL_EXPORT int pll_hardware_probe()
160 | {
161 | /* probe cpu features */
162 | cpu_features_detect();
163 |
164 | return PLL_SUCCESS;
165 | }
166 |
167 | PLL_EXPORT void pll_hardware_dump()
168 | {
169 | if (!pll_hardware.init)
170 | pll_hardware_probe();
171 |
172 | cpu_features_show();
173 | }
174 |
175 | PLL_EXPORT void pll_hardware_ignore()
176 | {
177 | pll_hardware.init = 1;
178 | pll_hardware.altivec_present = 1;
179 | pll_hardware.mmx_present = 1;
180 | pll_hardware.sse_present = 1;
181 | pll_hardware.sse2_present = 1;
182 | pll_hardware.sse3_present = 1;
183 | pll_hardware.ssse3_present = 1;
184 | pll_hardware.sse41_present = 1;
185 | pll_hardware.sse42_present = 1;
186 | pll_hardware.popcnt_present = 1;
187 | pll_hardware.avx_present = 1;
188 | pll_hardware.avx2_present = 1;
189 | }
190 |
--------------------------------------------------------------------------------
/test/out/asc-bias.out:
--------------------------------------------------------------------------------
1 | Read testdata/2000.tree: 2000 taxa
2 | Read testdata/2000.fas: 1251 sites
3 |
4 | TEST 1: NO ASC BIAS
5 | Log-L: -376539.211547
6 | Br.Len logLikelihood 1st Deriv 2nd Deriv
7 | 0.0001 -376569.858622 -7.17805288e+03 9.00973704e+06 *
8 | 0.0010 -376565.211482 -4.02412312e+03 1.60951377e+06 *
9 | 0.0100 -376549.092340 -9.26475886e+02 9.12042854e+04 *
10 | 0.1000 -376546.759479 2.18660011e+02 1.79731004e+03 *
11 | 1.0000 -376790.406580 2.22401826e+02 -1.04126523e+02
12 | 10.0000 -377445.004318 2.42918481e+01 -3.40494037e+00
13 | 100.0000 -377836.767226 7.72835622e-01 -1.91544043e-02
14 |
15 | TEST 2: ASC BIAS LEWIS
16 | Log-L: -376534.406057
17 | Br.Len logLikelihood 1st Deriv 2nd Deriv
18 | 0.0001 -376565.047252 -7.17792843e+03 9.00973703e+06 *
19 | 0.0010 -376560.400224 -4.02399868e+03 1.60951376e+06 *
20 | 0.0100 -376544.282202 -9.26351502e+02 9.12042792e+04 *
21 | 0.1000 -376541.960510 2.18783836e+02 1.79730384e+03 *
22 | 1.0000 -376785.716589 2.22520222e+02 -1.04132398e+02
23 | 10.0000 -377441.178362 2.43689770e+01 -3.40845664e+00
24 | 100.0000 -377834.948574 7.77743047e-01 -1.92658552e-02
25 |
26 | TEST 2: ASC BIAS FELSENSTEIN
27 | Log-L: -377485.067669
28 | Br.Len logLikelihood 1st Deriv 2nd Deriv
29 | 0.0001 -377515.507269 -7.17366429e+03 9.00973694e+06 *
30 | 0.0010 -377510.864079 -4.01973463e+03 1.60951366e+06 *
31 | 0.0100 -377494.784429 -9.22088348e+02 9.12041795e+04 *
32 | 0.1000 -377492.846018 2.23038024e+02 1.79720428e+03 *
33 | 1.0000 -377740.390709 2.26685357e+02 -1.04230721e+02
34 | 10.0000 -378429.545536 2.77137045e+01 -3.49185337e+00
35 | 100.0000 -378947.603295 1.23122794e+00 -2.83269795e-02
36 |
37 | TEST 2: ASC BIAS STAMATAKIS
38 | Log-L: -377961.619605
39 | Br.Len logLikelihood 1st Deriv 2nd Deriv
40 | 0.0001 -377991.971916 -7.17181912e+03 9.00973694e+06 *
41 | 0.0010 -377987.330386 -4.01788946e+03 1.60951367e+06 *
42 | 0.0100 -377971.267343 -9.20243116e+02 9.12041859e+04 *
43 | 0.1000 -377969.495029 2.24883827e+02 1.79721051e+03 *
44 | 1.0000 -378218.703151 2.28535724e+02 -1.04226800e+02
45 | 10.0000 -378924.372499 2.95020195e+01 -3.50863767e+00
46 | 100.0000 -379504.407122 1.30619027e+00 -3.15896886e-02
47 |
48 | TEST 1: NO ASC BIAS
49 | Log-L: -376539.211547
50 | Br.Len logLikelihood 1st Deriv 2nd Deriv
51 | 0.0001 -376588.767896 -2.01491393e+04 4.35212664e+07 *
52 | 0.0010 -376578.147065 -7.83726887e+03 4.69011502e+06 *
53 | 0.0100 -376552.867352 -1.27249532e+03 1.36077377e+05 *
54 | 0.1000 -376546.153557 2.15083632e+02 1.92380335e+03 *
55 | 1.0000 -376787.910260 2.20059204e+02 -1.02352431e+02
56 | 10.0000 -377440.724115 2.43890918e+01 -3.40966697e+00
57 | 100.0000 -377835.804935 7.80659251e-01 -1.93956876e-02
58 |
59 | TEST 2: ASC BIAS LEWIS
60 | Log-L: -376534.406057
61 | Br.Len logLikelihood 1st Deriv 2nd Deriv
62 | 0.0001 -376583.956195 -2.01490149e+04 4.35212664e+07 *
63 | 0.0010 -376573.335476 -7.83714442e+03 4.69011502e+06 *
64 | 0.0100 -376548.056883 -1.27237093e+03 1.36077371e+05 *
65 | 0.1000 -376541.354258 2.15207466e+02 1.92379716e+03 *
66 | 1.0000 -376783.219948 2.20177610e+02 -1.02358306e+02
67 | 10.0000 -377436.897900 2.44662262e+01 -3.41318351e+00
68 | 100.0000 -377833.986162 7.85566995e-01 -1.95071458e-02
69 |
70 | TEST 2: ASC BIAS FELSENSTEIN
71 | Log-L: -377485.067669
72 | Br.Len logLikelihood 1st Deriv 2nd Deriv
73 | 0.0001 -377534.404871 -2.01447507e+04 4.35212663e+07 *
74 | 0.0010 -377523.787990 -7.83288036e+03 4.69011492e+06 *
75 | 0.0100 -377498.547769 -1.26810776e+03 1.36077271e+05 *
76 | 0.1000 -377492.228426 2.19461666e+02 1.92369759e+03 *
77 | 1.0000 -377737.882738 2.24342756e+02 -1.02456629e+02
78 | 10.0000 -378425.253834 2.78109621e+01 -3.49658061e+00
79 | 100.0000 -378946.629686 1.23905084e+00 -2.85682551e-02
80 |
81 | TEST 2: ASC BIAS STAMATAKIS
82 | Log-L: -377961.619605
83 | Br.Len logLikelihood 1st Deriv 2nd Deriv
84 | 0.0001 -378010.864604 -2.01429056e+04 4.35212663e+07 *
85 | 0.0010 -378000.249384 -7.83103519e+03 4.69011492e+06 *
86 | 0.0100 -377975.025770 -1.26626254e+03 1.36077278e+05 *
87 | 0.1000 -377968.872522 2.21307457e+02 1.92370382e+03 *
88 | 1.0000 -378216.190255 2.26193111e+02 -1.02452708e+02
89 | 10.0000 -378920.075798 2.95992716e+01 -3.51336437e+00
90 | 100.0000 -379503.428611 1.31401425e+00 -3.18309848e-02
91 |
92 | TEST 1: NO ASC BIAS
93 | Log-L: -376539.211547
94 | Br.Len logLikelihood 1st Deriv 2nd Deriv
95 | 0.0001 -376662.410545 -2.83159180e+04 5.91239012e+07 *
96 | 0.0010 -376646.551695 -1.25624606e+04 6.20431514e+06 *
97 | 0.0100 -376599.021044 -2.83234165e+03 2.34237871e+05 *
98 | 0.1000 -376540.111656 -8.58666183e+01 4.26252492e+03 *
99 | 1.0000 -376698.940701 1.82867072e+02 -6.06107215e+01
100 | 10.0000 -377294.479082 2.35183408e+01 -3.19063217e+00
101 | 100.0000 -377685.791460 7.84835181e-01 -1.94758100e-02
102 |
103 | TEST 2: ASC BIAS LEWIS
104 | Log-L: -376534.406057
105 | Br.Len logLikelihood 1st Deriv 2nd Deriv
106 | 0.0001 -376657.588431 -2.83157932e+04 5.91239012e+07 *
107 | 0.0010 -376641.729693 -1.25623359e+04 6.20431513e+06 *
108 | 0.0100 -376594.200164 -2.83221698e+03 2.34237864e+05 *
109 | 0.1000 -376535.301971 -8.57425086e+01 4.26251871e+03 *
110 | 1.0000 -376694.240245 1.82985740e+02 -6.06166099e+01
111 | 10.0000 -377290.644629 2.35956442e+01 -3.19415665e+00
112 | 100.0000 -377683.968743 7.89753173e-01 -1.95875013e-02
113 |
114 | TEST 2: ASC BIAS FELSENSTEIN
115 | Log-L: -377485.067669
116 | Br.Len logLikelihood 1st Deriv 2nd Deriv
117 | 0.0001 -377607.680708 -2.83115291e+04 5.91239011e+07 *
118 | 0.0010 -377591.825809 -1.25580718e+04 6.20431503e+06 *
119 | 0.0100 -377544.334652 -2.82795385e+03 2.34237765e+05 *
120 | 0.1000 -377485.819737 -8.14883441e+01 4.26241915e+03 *
121 | 1.0000 -377648.546601 1.87150851e+02 -6.07149337e+01
122 | 10.0000 -378278.643753 2.69403278e+01 -3.27755659e+00
123 | 100.0000 -378796.248227 1.24318914e+00 -2.86477576e-02
124 |
125 | TEST 2: ASC BIAS STAMATAKIS
126 | Log-L: -377961.619605
127 | Br.Len logLikelihood 1st Deriv 2nd Deriv
128 | 0.0001 -378083.985873 -2.83096842e+04 5.91239011e+07 *
129 | 0.0010 -378068.132634 -1.25562269e+04 6.20431504e+06 *
130 | 0.0100 -378020.658081 -2.82610887e+03 2.34237771e+05 *
131 | 0.1000 -377962.309241 -7.96427931e+01 4.26242539e+03 *
132 | 1.0000 -378126.699316 1.89000978e+02 -6.07109990e+01
133 | 10.0000 -378773.309382 2.87285203e+01 -3.29432956e+00
134 | 100.0000 -379352.893744 1.31819017e+00 -3.19111068e-02
135 |
--------------------------------------------------------------------------------
/test/src/common.c:
--------------------------------------------------------------------------------
1 | #include "common.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | const unsigned int odd5_map[256] =
9 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1f, 0, 0, 0x1f, 0, 0,
11 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1f, 0, 0x01, 0x02, 0x04,
12 | 0x08, 0x0c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
13 | 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0x02, 0x04, 0x08, 0x0c, 0, 0, 0, 0, 0,
14 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
19 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
20 |
21 |
22 | unsigned int get_attributes(int argc, char **argv)
23 | {
24 | int i;
25 | unsigned int attributes = PLL_ATTRIB_ARCH_CPU;
26 |
27 | for (i=1; itip_count;
93 | pll_partition_t * partition;
94 | long hdrlen, seqlen, seqno;
95 | char * seq = NULL,
96 | * hdr = NULL;
97 |
98 | /* open FASTA file */
99 | pll_fasta_t * fp = pll_fasta_open(filename, pll_map_fasta);
100 | if (!fp)
101 | {
102 | printf("Error opening file %s", filename);
103 | return NULL;
104 | }
105 |
106 | /* allocate arrays to store FASTA headers and sequences */
107 | char ** headers = (char **)calloc(taxa_count, sizeof(char *));
108 | char ** seqdata = (char **)calloc(taxa_count, sizeof(char *));
109 |
110 | /* read FASTA sequences and make sure they are all of the same length */
111 | int sites = -1;
112 | for (i = 0; pll_fasta_getnext(fp,&hdr,&hdrlen,&seq,&seqlen,&seqno); ++i)
113 | {
114 | if (sites == -1) sites = seqlen;
115 |
116 | headers[i] = hdr;
117 | seqdata[i] = seq;
118 | }
119 |
120 | if (pll_errno != PLL_ERROR_FILE_EOF)
121 | {
122 | printf("Error while reading file %s", filename);
123 | return NULL;
124 | }
125 |
126 | /* close FASTA file */
127 | pll_fasta_close(fp);
128 |
129 | if (sites == -1)
130 | {
131 | printf("Unable to read alignment");
132 | return NULL;
133 | }
134 |
135 | if (max_sites != -1)
136 | sites = max_sites;
137 |
138 | partition = pll_partition_create(taxa_count, /* tip nodes */
139 | taxa_count - 2, /* inner nodes */
140 | states,
141 | (unsigned int)sites,
142 | rate_matrices, /* rate matrices */
143 | 2*taxa_count - 3, /* prob matrices */
144 | rate_cats, /* rate categories */
145 | taxa_count - 2, /* scale buffers */
146 | attributes);
147 |
148 | /* create a libc hash table of size tip_nodes_count */
149 | hcreate(taxa_count);
150 |
151 | /* populate a libc hash table with tree tip labels */
152 | unsigned int * data = (unsigned int *)malloc(taxa_count *
153 | sizeof(unsigned int));
154 | for (i = 0; i < taxa_count; ++i)
155 | {
156 | data[i] = tree->nodes[i]->clv_index;
157 | ENTRY entry;
158 | #ifdef __APPLE__
159 | entry.key = xstrdup(tree->nodes[i]->label);
160 | #else
161 | entry.key = tree->nodes[i]->label;
162 | #endif
163 | entry.data = (void *)(data+i);
164 |
165 | hsearch(entry, ENTER);
166 | }
167 |
168 | for (i = 0; i < taxa_count; ++i)
169 | {
170 | ENTRY query;
171 | query.key = headers[i];
172 | ENTRY * found = NULL;
173 |
174 | found = hsearch(query,FIND);
175 |
176 | if (!found)
177 | {
178 | printf("Sequence with header %s does not appear in the tree", headers[i]);
179 | return NULL;
180 | }
181 |
182 | unsigned int tip_clv_index = *((unsigned int *)(found->data));
183 |
184 | const unsigned int * map = states == 4? pll_map_nt : pll_map_aa;
185 | pll_set_tip_states(partition, tip_clv_index, map, seqdata[i]);
186 |
187 | free(headers[i]);
188 | free(seqdata[i]);
189 | }
190 |
191 | /* clean */
192 | hdestroy();
193 | free(data);
194 | free(headers);
195 | free(seqdata);
196 |
197 | return partition;
198 | }
199 |
200 | int cb_full_traversal(pll_unode_t * node)
201 | {
202 | return 1;
203 | }
204 |
205 | int cb_rfull_traversal(pll_rnode_t * node)
206 | {
207 | return 1;
208 | }
209 |
210 | __attribute__((format(printf, 1, 2)))
211 | void fatal(const char * format, ...)
212 | {
213 | va_list argptr;
214 | va_start(argptr, format);
215 | vfprintf(stderr, format, argptr);
216 | va_end(argptr);
217 | fprintf(stderr, "\n");
218 | exit(EXIT_FAILURE);
219 | }
220 |
221 | void * xmalloc(size_t size)
222 | {
223 | void * t;
224 | t = malloc(size);
225 | if (!t)
226 | fatal("Unable to allocate enough memory.");
227 |
228 | return t;
229 | }
230 |
231 | char * xstrdup(const char * s)
232 | {
233 | size_t len = strlen(s);
234 | char * p = (char *)xmalloc(len+1);
235 | return strcpy(p,s);
236 | }
237 |
--------------------------------------------------------------------------------
/test/src/00110_NPDN_fasta.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Diego Darriba, Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Diego Darriba ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 | #include "common.h"
22 | #include
23 | #include
24 |
25 | #define ALPHA 0.5
26 | #define N_STATES 4
27 | #define N_RATE_CATS 4
28 |
29 | #define N_TAXA_BIG 43
30 | #define N_TAXA_SMALL 5
31 | #define N_SITES 491
32 |
33 | static int failtest(unsigned int attributes)
34 | {
35 | pll_fasta_t * fp;
36 | fp = pll_fasta_open ("unexistent-file", pll_map_fasta);
37 | assert(!fp && pll_errno == PLL_ERROR_FILE_OPEN);
38 |
39 | return PLL_SUCCESS;
40 | }
41 |
42 | static int bigtest(unsigned int attributes)
43 | {
44 | unsigned int i;
45 | char * seq, *header;
46 | long seq_len, header_len, seqno;
47 | pll_fasta_t * fp;
48 | pll_partition_t * partition;
49 |
50 | printf ("Creating PLL partition\n");
51 |
52 | partition = pll_partition_create(N_TAXA_BIG, /* tips */
53 | 4, /* clv buffers */
54 | N_STATES, /* states */
55 | N_SITES, /* sites */
56 | 1, /* different rate parameters */
57 | 8, /* probability matrices */
58 | N_RATE_CATS, /* rate categories */
59 | 1,
60 | attributes
61 | );
62 |
63 | fp = pll_fasta_open ("testdata/worms16s.fas", pll_map_fasta);
64 | if (!fp)
65 | {
66 | printf (" ERROR opening file (%d): %s\n", pll_errno, pll_errmsg);
67 | exit (PLL_FAILURE);
68 | }
69 |
70 | i = 0;
71 | while (pll_fasta_getnext (fp, &header, &header_len, &seq, &seq_len, &seqno))
72 | {
73 | if (seq_len != (N_SITES + 1))
74 | {
75 | printf (
76 | " ERROR: Mismatching sequence length for sequence %d (%ld, and it should be %d)\n",
77 | i, seq_len - 1, N_SITES);
78 | exit (PLL_FAILURE);
79 | }
80 | if (!pll_set_tip_states (partition, i, pll_map_nt, seq))
81 | {
82 | printf (" ERROR setting states (%d): %s\n", pll_errno, pll_errmsg);
83 | exit (PLL_FAILURE);
84 | }
85 | printf ("Header of sequence %d(%ld) %s (%ld sites)\n", i, seqno, header,
86 | seq_len);
87 | free (header);
88 | free (seq);
89 | ++i;
90 | }
91 |
92 | if (pll_errno != PLL_ERROR_FILE_EOF)
93 | {
94 | printf (" ERROR at the end (%d): %s\n", pll_errno, pll_errmsg);
95 | exit (PLL_FAILURE);
96 | }
97 |
98 | assert(i == N_TAXA_BIG);
99 |
100 | pll_fasta_close (fp);
101 | pll_partition_destroy(partition);
102 |
103 | return PLL_SUCCESS;
104 | }
105 |
106 | static int smalltest (unsigned int attributes)
107 | {
108 | unsigned int i;
109 | char * seq, *header;
110 | long seq_len, header_len, seqno;
111 | pll_fasta_t * fp;
112 | pll_partition_t * partition;
113 | pll_operation_t * operations;
114 | double rate_cats[4];
115 | unsigned int params_indices[N_RATE_CATS] = {0,0,0,0};
116 |
117 | unsigned int num_sites = 4 * N_SITES;
118 |
119 | double branch_lengths[4] =
120 | { 0.1, 0.2, 1, 1 };
121 | double frequencies[4] =
122 | { 0.1, 0.2, 0.3, 0.4 };
123 | unsigned int matrix_indices[4] = { 0, 1, 2, 3 };
124 | double subst_params[6] = { 1, 5, 1, 1, 5, 1 };
125 |
126 | partition = pll_partition_create(N_TAXA_SMALL, 4,
127 | N_STATES,
128 | num_sites, 1, 2 * N_TAXA_SMALL - 3,
129 | N_RATE_CATS,
130 | 1,
131 | attributes);
132 |
133 | fp = pll_fasta_open ("testdata/small.fas", pll_map_fasta);
134 | i = 0;
135 | while (pll_fasta_getnext (fp, &header, &header_len, &seq, &seq_len, &seqno))
136 | {
137 | if (!pll_set_tip_states (partition, i, pll_map_nt, seq))
138 | exit (PLL_FAILURE);
139 | free (header);
140 | free (seq);
141 | ++i;
142 | }
143 | assert(i == (N_TAXA_SMALL));
144 |
145 | operations = (pll_operation_t *) malloc (4 * sizeof(pll_operation_t));
146 |
147 | operations[0].parent_clv_index = 5;
148 | operations[0].child1_clv_index = 0;
149 | operations[0].child2_clv_index = 1;
150 | operations[0].child1_matrix_index = 1;
151 | operations[0].child2_matrix_index = 1;
152 | operations[0].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
153 | operations[0].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
154 | operations[0].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
155 |
156 | operations[1].parent_clv_index = 6;
157 | operations[1].child1_clv_index = 5;
158 | operations[1].child2_clv_index = 2;
159 | operations[1].child1_matrix_index = 0;
160 | operations[1].child2_matrix_index = 1;
161 | operations[1].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
162 | operations[1].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
163 | operations[1].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
164 |
165 | operations[2].parent_clv_index = 7;
166 | operations[2].child1_clv_index = 3;
167 | operations[2].child2_clv_index = 4;
168 | operations[2].child1_matrix_index = 1;
169 | operations[2].child2_matrix_index = 1;
170 | operations[2].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
171 | operations[2].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
172 | operations[2].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
173 |
174 | pll_compute_gamma_cats (ALPHA, N_RATE_CATS, rate_cats, PLL_GAMMA_RATES_MEAN);
175 | pll_set_subst_params (partition, 0, subst_params);
176 | pll_set_frequencies (partition, 0, frequencies);
177 | pll_set_category_rates (partition, rate_cats);
178 | pll_update_prob_matrices (partition, params_indices, matrix_indices, branch_lengths, 4);
179 | pll_update_partials (partition, operations, 3);
180 |
181 | printf ("logL: %17.6f\n",
182 | pll_compute_edge_loglikelihood(partition,
183 | 6,
184 | PLL_SCALE_BUFFER_NONE,
185 | 7,
186 | PLL_SCALE_BUFFER_NONE,
187 | 0,
188 | params_indices,
189 | NULL));
190 |
191 | free (operations);
192 | pll_fasta_close (fp);
193 | pll_partition_destroy(partition);
194 |
195 | return PLL_SUCCESS;
196 | }
197 |
198 | int main (int argc, char * argv[])
199 | {
200 | unsigned int attributes = get_attributes(argc, argv);
201 |
202 | if (bigtest (attributes))
203 | printf ("Big test OK\n\n");
204 |
205 | if (smalltest (attributes))
206 | printf ("Small test OK\n\n");
207 |
208 | if (failtest (attributes))
209 | printf ("Fail test OK\n");
210 |
211 | return PLL_SUCCESS;
212 | }
213 |
--------------------------------------------------------------------------------
/src/compress.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2016 Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Tomas Flouri ,
18 | Heidelberg Institute for Theoretical Studies,
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 |
22 | #include "pll.h"
23 |
24 | static void vecswap(int i, int j, int n, char ** x)
25 | {
26 | while (n--)
27 | {
28 | PLL_SWAP(x[i],x[j]);
29 | ++i; ++j;
30 | }
31 | }
32 |
33 | static void ssort1(char ** x, int n, int depth)
34 | {
35 | int a,b,c,d,r,v;
36 |
37 | if (n <= 1) return;
38 |
39 | a = rand() % n;
40 |
41 | PLL_SWAP(x[0], x[a]);
42 |
43 | v = x[0][depth];
44 |
45 | a = b = 1;
46 | c = d = n-1;
47 |
48 | while (1)
49 | {
50 | while (b <= c && (r = x[b][depth]-v) <= 0)
51 | {
52 | if (r == 0)
53 | {
54 | PLL_SWAP(x[a], x[b]);
55 | ++a;
56 | }
57 | ++b;
58 | }
59 | while (b <= c && (r = x[c][depth]-v) >= 0)
60 | {
61 | if (r == 0)
62 | {
63 | PLL_SWAP(x[c], x[d]);
64 | --d;
65 | }
66 | --c;
67 | }
68 | if (b > c) break;
69 | PLL_SWAP (x[b], x[c]);
70 | ++b; --c;
71 | }
72 |
73 | r = PLL_MIN(a,b-a); vecswap(0,b-r,r,x);
74 | r = PLL_MIN(d-c,n-d-1); vecswap(b,n-r,r,x);
75 | r = b-a; ssort1(x,r,depth);
76 |
77 | if (x[r][depth] != 0)
78 | ssort1 (x + r, a + n - d - 1, depth + 1);
79 |
80 | r = d - c; ssort1(x+n-r,r,depth);
81 | }
82 |
83 | static void remap_range(const unsigned int * map,
84 | unsigned char * charmap)
85 | {
86 | unsigned int oldmap[PLL_ASCII_SIZE];
87 | unsigned int i,j;
88 | unsigned char k = 1;
89 |
90 | memcpy(oldmap, map, PLL_ASCII_SIZE * sizeof(unsigned int));
91 | memset(charmap, 0, PLL_ASCII_SIZE * sizeof(unsigned char));
92 |
93 | for (i = 0; i < PLL_ASCII_SIZE; ++i)
94 | if (oldmap[i])
95 | {
96 | charmap[i] = k;
97 |
98 | for (j = i+1; j < PLL_ASCII_SIZE; ++j)
99 | if (oldmap[i] == oldmap[j])
100 | {
101 | charmap[j] = k;
102 | oldmap[j] = 0;
103 | }
104 |
105 | ++k;
106 | }
107 | }
108 |
109 | static unsigned int findmax(const unsigned int * map)
110 | {
111 | int i;
112 | unsigned int max = 0;
113 |
114 | for (i = 0; i < PLL_ASCII_SIZE; ++i)
115 | if (map[i] > max)
116 | max = map[i];
117 |
118 | return max;
119 | }
120 |
121 | static void encode(char ** sequence, const unsigned char * map, int count, int len)
122 | {
123 | int i,j;
124 | char * p;
125 |
126 | for (i = 0; i < count; ++i)
127 | {
128 | p = sequence[i];
129 | j = len;
130 | while (j--)
131 | {
132 | *p = map[(int)(*p)];
133 | ++p;
134 | }
135 | }
136 | }
137 |
138 | PLL_EXPORT unsigned int * pll_compress_site_patterns(char ** sequence,
139 | const unsigned int * map,
140 | int count,
141 | int * length)
142 | {
143 | int i,j;
144 | char * memptr;
145 | char ** column;
146 | unsigned int * weight;
147 |
148 | unsigned char charmap[PLL_ASCII_SIZE];
149 | unsigned char inv_charmap[PLL_ASCII_SIZE];
150 |
151 | /* check that at least one sequence is given */
152 | if (!count) return NULL;
153 |
154 | /* a map must be given */
155 | if (!map) return NULL;
156 |
157 | /* a zero can never be used as a state */
158 | if (map[0]) return NULL;
159 |
160 | /* if map states are out of the BYTE range, remap */
161 | if (findmax(map) >= PLL_ASCII_SIZE)
162 | {
163 | remap_range(map,charmap);
164 | }
165 | else
166 | {
167 | for (i = 0; i < PLL_ASCII_SIZE; ++i)
168 | charmap[i] = (unsigned char)(map[i]);
169 | }
170 |
171 | /* create inverse charmap to decode states back to characters when
172 | compression is finished */
173 | for (i = 0; i < PLL_ASCII_SIZE; ++i)
174 | if (map[i])
175 | inv_charmap[charmap[i]] = (unsigned char)i;
176 |
177 | /* encode sequences using charmap */
178 | encode(sequence,charmap,count,*length);
179 |
180 | /* allocate memory for columns */
181 | column = (char **)malloc((size_t)(*length)*sizeof(char *));
182 | if (!column)
183 | {
184 | pll_errno = PLL_ERROR_MEM_ALLOC;
185 | snprintf (pll_errmsg, 200,
186 | "Cannot allocate space for matrix columns.");
187 | return NULL;
188 | }
189 |
190 | /* allocate memory for the alignment */
191 | memptr = column[0] = (char *)malloc((size_t)(*length) *
192 | (size_t)(count+1) *
193 | sizeof(char));
194 | if (!memptr)
195 | {
196 | pll_errno = PLL_ERROR_MEM_ALLOC;
197 | snprintf (pll_errmsg, 200,
198 | "Cannot allocate space for matrix data.");
199 | free(column);
200 | return NULL;
201 | }
202 |
203 | /* map memory to each column */
204 | for (i = 1; i < *length; ++i)
205 | {
206 | column[i] = column[i-1] + (count+1);
207 | }
208 |
209 | /* allocate space for weight vector */
210 | weight = (unsigned int *)malloc((size_t)(*length)*sizeof(unsigned int));
211 | if (!weight)
212 | {
213 | pll_errno = PLL_ERROR_MEM_ALLOC;
214 | snprintf(pll_errmsg, 200,
215 | "Cannot allocate space for storing site weights.");
216 | free(column);
217 | free(memptr);
218 | return NULL;
219 | }
220 |
221 | /* split alignment into columns instead of rows */
222 | for (i = 0; i < (*length); ++i)
223 | {
224 | for (j = 0; j < count; ++j)
225 | column[i][j] = sequence[j][i];
226 | column[i][j] = 0;
227 | }
228 |
229 | /* sort the columns */
230 | ssort1(column, *length, 0);
231 |
232 | /* we have at least one unique site with weight 1 (the first site) */
233 | int compressed_length = 1;
234 | size_t ref = 0;
235 | weight[ref] = 1;
236 |
237 | /* find all unique columns and set their weights */
238 | for (i = 1; i < *length; ++i)
239 | {
240 | if (strcmp(column[i],column[i-1]))
241 | {
242 | column[ref+1] = column[i];
243 | ++ref;
244 | ++compressed_length;
245 | weight[ref] = 1;
246 | }
247 | else
248 | weight[ref]++;
249 | }
250 |
251 | /* copy the unique columns over the original sequences */
252 | for (i = 0; i < compressed_length; ++i)
253 | for (j = 0; j < count; ++j)
254 | sequence[j][i] = column[i][j];
255 |
256 | /* add terminating zero */
257 | for (j = 0; j < count; ++j)
258 | sequence[j][compressed_length] = 0;
259 |
260 | /* deallocate memory */
261 | free(memptr);
262 | free(column);
263 |
264 | /* adjust weight vector size to compressed length */
265 | unsigned int * mem = (unsigned int *)malloc((size_t)compressed_length *
266 | sizeof(unsigned int));
267 | if (mem)
268 | {
269 | /* copy weights */
270 | for (i = 0; i < compressed_length; ++i)
271 | mem[i] = weight[i];
272 |
273 | /* free and re-point */
274 | free(weight);
275 | weight = mem;
276 | }
277 |
278 |
279 | /* update length */
280 | *length = compressed_length;
281 |
282 | /* decode sequences using inv_charmap */
283 | encode(sequence,inv_charmap,count,compressed_length);
284 |
285 | return weight;
286 | }
287 |
--------------------------------------------------------------------------------
/test/src/00011_NMAU_lkcalc.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Diego Darriba, Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Diego Darriba ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 | #include "common.h"
22 |
23 | #define N_STATES_AA 20
24 | #define N_CAT_GAMMA 4
25 | #define FLOAT_PRECISION 4
26 |
27 | static double alpha = 0.5;
28 | static unsigned int n_cat_gamma = N_CAT_GAMMA;
29 | unsigned int params_indices[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
30 |
31 | int main(int argc, char * argv[])
32 | {
33 | unsigned int j;
34 | double lk_score;
35 | unsigned int n_sites = 15;
36 | unsigned int n_tips = 5;
37 | double rate_cats[N_CAT_GAMMA];
38 | pll_operation_t * operations;
39 | int return_val;
40 |
41 | operations = (pll_operation_t *)malloc(4* sizeof(pll_operation_t));
42 |
43 | operations[0].parent_clv_index = 5;
44 | operations[0].child1_clv_index = 0;
45 | operations[0].child2_clv_index = 1;
46 | operations[0].child1_matrix_index = 1;
47 | operations[0].child2_matrix_index = 1;
48 | operations[0].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
49 | operations[0].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
50 | operations[0].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
51 |
52 | operations[1].parent_clv_index = 6;
53 | operations[1].child1_clv_index = 5;
54 | operations[1].child2_clv_index = 2;
55 | operations[1].child1_matrix_index = 0;
56 | operations[1].child2_matrix_index = 1;
57 | operations[1].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
58 | operations[1].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
59 | operations[1].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
60 |
61 | operations[2].parent_clv_index = 7;
62 | operations[2].child1_clv_index = 3;
63 | operations[2].child2_clv_index = 4;
64 | operations[2].child1_matrix_index = 1;
65 | operations[2].child2_matrix_index = 1;
66 | operations[2].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
67 | operations[2].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
68 | operations[2].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
69 |
70 | /* check attributes */
71 | unsigned int attributes = get_attributes(argc, argv);
72 |
73 | pll_partition_t * partition;
74 | partition = pll_partition_create(
75 | n_tips, /* numer of tips */
76 | 4, /* clv buffers */
77 | N_STATES_AA, /* number of states */
78 | n_sites, /* sequence length */
79 | 1, /* different rate parameters */
80 | 2*n_tips-3, /* probability matrices */
81 | n_cat_gamma, /* gamma categories */
82 | 0, /* scale buffers */
83 | attributes
84 | ); /* attributes */
85 |
86 | if (!partition)
87 | {
88 | printf("Error %d: %s\n", pll_errno, pll_errmsg);
89 | fatal("Fail creating partition");
90 | }
91 |
92 | double branch_lengths[4] = { 0.1, 0.2, 1, 1};
93 | unsigned int matrix_indices[4] = { 0, 1, 2, 3 };
94 | double * persite_lnl = (double *) malloc(n_sites * sizeof(double));
95 | double checksum;
96 |
97 | if (pll_compute_gamma_cats(alpha, n_cat_gamma, rate_cats, PLL_GAMMA_RATES_MEAN) == PLL_FAILURE)
98 | {
99 | printf("Error %d: %s\n", pll_errno, pll_errmsg);
100 | fatal("Fail computing gamma cats");
101 | }
102 |
103 | pll_set_frequencies(partition, 0, pll_aa_freqs_dayhoff);
104 | pll_set_subst_params(partition, 0, pll_aa_rates_dayhoff);
105 |
106 | return_val = PLL_SUCCESS;
107 | return_val &= pll_set_tip_states(partition, 0, pll_map_aa, "PIGLRVTLRRDRMWI");
108 | return_val &= pll_set_tip_states(partition, 1, pll_map_aa, "IQGMDITIVT-----");
109 | return_val &= pll_set_tip_states(partition, 2, pll_map_aa, "--AFALLQKIGMPFE");
110 | return_val &= pll_set_tip_states(partition, 3, pll_map_aa, "MDISIVT------TA");
111 | return_val &= pll_set_tip_states(partition, 4, pll_map_aa, "GLSEQTVFHEIDQDK");
112 |
113 | if (!return_val)
114 | fatal("Error setting tip states");
115 |
116 | pll_set_category_rates(partition, rate_cats);
117 |
118 | pll_update_prob_matrices(partition, params_indices, matrix_indices, branch_lengths, 4);
119 | pll_update_partials(partition, operations, 3);
120 |
121 | for (j = 0; j < 4; ++j)
122 | {
123 | printf ("[%d] P-matrix for branch length %f\n", j+1, branch_lengths[j]);
124 | pll_show_pmatrix(partition, j, FLOAT_PRECISION);
125 | printf ("\n");
126 | }
127 |
128 | /* show CLVs */
129 | printf ("[5] CLV 5: ");
130 | pll_show_clv(partition,5,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
131 | printf ("[6] CLV 6: ");
132 | pll_show_clv(partition,6,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
133 | printf ("[7] CLV 7: ");
134 | pll_show_clv(partition,7,PLL_SCALE_BUFFER_NONE,FLOAT_PRECISION+1);
135 |
136 | lk_score = pll_compute_edge_loglikelihood(partition,
137 | 6,
138 | PLL_SCALE_BUFFER_NONE,
139 | 7,
140 | PLL_SCALE_BUFFER_NONE,
141 | 0,
142 | params_indices,
143 | persite_lnl);
144 |
145 | printf("\n");
146 | printf("inner-inner logL: %.6f\n",
147 | lk_score);
148 | printf("persite logL: ");
149 | checksum = 0.0;
150 | for (int i=0; isites);
173 | lk_score = pll_compute_edge_loglikelihood(partition,
174 | 7,
175 | PLL_SCALE_BUFFER_NONE,
176 | 4,
177 | PLL_SCALE_BUFFER_NONE,
178 | 1,
179 | params_indices,
180 | persite_lnl);
181 |
182 | printf("tip-inner logL: %.6f\n",
183 | lk_score);
184 | printf("persite logL: ");
185 | checksum = 0.0;
186 | for (int i=0; i.
16 |
17 | Contact: Alexey Kozlov ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 | #include "common.h"
22 |
23 | #define N_STATES_NT 4
24 | #define N_STATES_AA 20
25 | #define N_STATES_ODD 5
26 | #define N_CAT_GAMMA 4
27 | #define N_BASE_FREQS 3
28 | #define N_SUBST_MAT 3
29 | #define N_SITES 5
30 | #define N_BRANCHES 5
31 | #define FLOAT_PRECISION 4
32 |
33 | #define MIN(a,b) (apmatrix[matrix_index];
50 | unsigned int i;
51 | for (i = 0; i < p->rate_cats * p->states_padded * p->states; ++i)
52 | {
53 | if (isnan(mat[i]) || !isfinite(mat[i]) || mat[i] < 0.)
54 | fatal("ERROR invalid value in p-matrix %u: %lf\n", matrix_index, mat[i]);
55 | }
56 | }
57 |
58 | pll_partition_t * init_partition(unsigned int attrs, int datatype)
59 | {
60 | unsigned int i;
61 |
62 | unsigned int states = 0;
63 |
64 | switch(datatype)
65 | {
66 | case DATATYPE_NT:
67 | states = N_STATES_NT;
68 | break;
69 | case DATATYPE_AA:
70 | states = N_STATES_AA;
71 | break;
72 | case DATATYPE_ODD:
73 | states = N_STATES_ODD;
74 | break;
75 | default:
76 | assert(0);
77 | }
78 |
79 | pll_partition_t * p = pll_partition_create(N_BRANCHES-1, /* tips */
80 | 0, /* clv vectors */
81 | states,
82 | N_SITES,
83 | 1, /* rate matrices */
84 | N_BRANCHES, /* prob matrices */
85 | N_CAT_GAMMA,
86 | 0, /* scalers */
87 | attrs);
88 |
89 | if (!p)
90 | fatal("ERROR creating partition: %s\n", pll_errmsg);
91 |
92 | pll_set_category_rates(p, cat_rates);
93 |
94 | printf("category rates(%d): [", N_CAT_GAMMA);
95 | for (i = 0; i < N_CAT_GAMMA; ++i)
96 | printf("%lf ", cat_rates[i]);
97 | printf("]\n");
98 |
99 | return p;
100 | }
101 |
102 | void init(unsigned int attrs)
103 | {
104 | part_nt = init_partition(attrs, DATATYPE_NT);
105 | part_aa = init_partition(attrs, DATATYPE_AA);
106 | part_odd = init_partition(attrs, DATATYPE_ODD);
107 | }
108 |
109 | double * init_freqs(unsigned int n_states)
110 | {
111 | double * base_freqs =
112 | (double *) malloc(N_BASE_FREQS * n_states * sizeof(double));
113 |
114 | unsigned int k;
115 | unsigned int offset = 0;
116 |
117 | for (k = 0; k < n_states; ++k) /* equal freqs */
118 | base_freqs[offset + k] = 1.0 / (double) n_states;
119 |
120 | offset += n_states;
121 | for (k = 0; k < n_states; ++k) /* skewed freqs */
122 | {
123 | base_freqs[offset + k] = 1.0 / (double) n_states;
124 | const double skew = 1.0 / (3. * n_states);
125 | if (k % 2 == 0)
126 | base_freqs[offset + k] += skew;
127 | else if (k != n_states-1)
128 | base_freqs[offset + k] -= skew;
129 | }
130 |
131 | const double minfreq = 1e-3;
132 | const double maxfreq = (1. - 0.5 * n_states * minfreq) / (0.5 * n_states);
133 |
134 | offset += n_states;
135 | for (k = 0; k < n_states; ++k) /* extreme freqs */
136 | base_freqs[offset + k] = (k % 2 == 0) ? minfreq : maxfreq;
137 |
138 | return base_freqs;
139 | }
140 |
141 | double * init_rates(unsigned int n_rates)
142 | {
143 | double * subst_rates =
144 | (double *) malloc(N_SUBST_MAT * n_rates * sizeof(double));
145 |
146 | unsigned int k;
147 | unsigned int offset = 0;
148 | for (k = 0; k < n_rates; ++k) /* equal rates */
149 | subst_rates[offset + k] = 1.0;
150 |
151 | offset += n_rates;
152 | for (k = 0; k < n_rates; ++k) /* skewed rates */
153 | {
154 | subst_rates[offset + k] = 1.0;
155 | const double skew = 5.;
156 | if (k % 2 == 0)
157 | subst_rates[offset + k] *= skew;
158 | else if (k != n_rates-1)
159 | subst_rates[offset + k] /= skew;
160 | }
161 |
162 | offset += n_rates;
163 | for (k = 0; k < n_rates-1; ++k) /* extreme rates */
164 | subst_rates[offset + k] = (k % 2 == 0) ? 1e-3 : 1e3;
165 | subst_rates[offset + n_rates-1] = 1.0;
166 |
167 | return subst_rates;
168 | }
169 |
170 | int eval(pll_partition_t * partition, double * base_freqs, double * subst_rates)
171 | {
172 | unsigned int i;
173 |
174 | pll_set_frequencies(partition, 0, base_freqs);
175 | pll_set_subst_params(partition, 0, subst_rates);
176 |
177 | printf("datatype = ");
178 | if (partition->states == 4)
179 | printf("DNA");
180 | else if (partition->states == 20)
181 | printf("PROT");
182 | else
183 | printf("ODD");
184 | printf("\n");
185 |
186 | printf("base freqs: [");
187 | for (i = 0; i < partition->states; ++i)
188 | printf("%lf ", partition->frequencies[0][i]);
189 | printf("]\n");
190 |
191 | printf("subst rates: [");
192 | for (i = 0; i < partition->states * (partition->states -1) / 2; ++i)
193 | printf("%lf ", partition->subst_params[0][i]);
194 | printf("]\n");
195 |
196 | pll_update_prob_matrices(partition,
197 | params_indices,
198 | matrix_indices,
199 | branch_lengths,
200 | N_BRANCHES);
201 |
202 | for (i = 0; i < N_BRANCHES; ++i)
203 | {
204 | printf("P-matrix: %d, brlen = %lf\n", i, branch_lengths[i]);
205 | pll_show_pmatrix(partition, i, 9);
206 | check_matrix(partition, i);
207 | }
208 |
209 | return 1;
210 | }
211 |
212 | void cleanup()
213 | {
214 | pll_partition_destroy(part_nt);
215 | pll_partition_destroy(part_aa);
216 | pll_partition_destroy(part_odd);
217 | }
218 |
219 | int main(int argc, char * argv[])
220 | {
221 | unsigned int i, j, k;
222 |
223 | /* check attributes */
224 | unsigned int attributes = get_attributes(argc, argv);
225 |
226 | /* pattern tip is not relevant for pmatrix computation */
227 | if (attributes & PLL_ATTRIB_PATTERN_TIP)
228 | skip_test();
229 |
230 | init(attributes);
231 |
232 | pll_partition_t * parts[] = {part_nt, part_aa, part_odd};
233 |
234 | for (i = 0; i < 3; ++i)
235 | {
236 | pll_partition_t * p = parts[i];
237 |
238 | const unsigned int n_states = p->states;
239 | const unsigned int n_rates = n_states * (n_states-1) / 2;
240 |
241 | double * base_freqs = init_freqs(n_states);
242 | double * subst_rates = init_rates(n_rates);
243 |
244 | for (j = 0; j < N_BASE_FREQS; ++j)
245 | {
246 | for (k = 0; k < N_SUBST_MAT; ++k)
247 | {
248 | eval(p, base_freqs + j * n_states, subst_rates + k * n_rates);
249 | }
250 | }
251 |
252 | free(base_freqs);
253 | free(subst_rates);
254 | }
255 |
256 | cleanup();
257 |
258 | return (0);
259 | }
260 |
--------------------------------------------------------------------------------
/test/src/alpha-cats.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Diego Darriba, Tomas Flouri
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as
6 | published by the Free Software Foundation, either version 3 of the
7 | License, or (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU Affero General Public License for more details.
13 |
14 | You should have received a copy of the GNU Affero General Public License
15 | along with this program. If not, see .
16 |
17 | Contact: Diego Darriba ,
18 | Exelixis Lab, Heidelberg Instutute for Theoretical Studies
19 | Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
20 | */
21 | #include "common.h"
22 |
23 | #define NUM_ALPHAS 9
24 | #define NUM_CATS 5
25 | #define N_MODES 2
26 | #define N_STATES_NT 4
27 |
28 | #define FLOAT_PRECISION 4
29 |
30 | #define MODENAME(x) x == PLL_GAMMA_RATES_MEAN ? "MEAN" : "MEDIAN"
31 |
32 | static double titv = 2.5;
33 |
34 | static double alpha[NUM_ALPHAS] = {0.1, 0.5, 0.75, 1, 1.5, 5, 10, 50, 100};
35 | static unsigned int n_cat_gamma[NUM_CATS] = {1, 2, 4, 8, 16};
36 | unsigned int params_indices[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
37 |
38 | static int modes[N_MODES] =
39 | { PLL_GAMMA_RATES_MEDIAN, PLL_GAMMA_RATES_MEAN };
40 |
41 | int main(int argc, char * argv[])
42 | {
43 | unsigned int i,j,k,m;
44 | double lk_scores[NUM_ALPHAS * NUM_CATS * N_MODES];
45 | unsigned int n_sites = 20;
46 | unsigned int n_tips = 5;
47 | pll_operation_t * operations;
48 |
49 | operations = (pll_operation_t *)malloc(4* sizeof(pll_operation_t));
50 |
51 | operations[0].parent_clv_index = 5;
52 | operations[0].child1_clv_index = 0;
53 | operations[0].child2_clv_index = 1;
54 | operations[0].child1_matrix_index = 1;
55 | operations[0].child2_matrix_index = 1;
56 | operations[0].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
57 | operations[0].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
58 | operations[0].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
59 |
60 | operations[1].parent_clv_index = 6;
61 | operations[1].child1_clv_index = 5;
62 | operations[1].child2_clv_index = 2;
63 | operations[1].child1_matrix_index = 0;
64 | operations[1].child2_matrix_index = 1;
65 | operations[1].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
66 | operations[1].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
67 | operations[1].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
68 |
69 | operations[2].parent_clv_index = 7;
70 | operations[2].child1_clv_index = 3;
71 | operations[2].child2_clv_index = 4;
72 | operations[2].child1_matrix_index = 1;
73 | operations[2].child2_matrix_index = 1;
74 | operations[2].parent_scaler_index = PLL_SCALE_BUFFER_NONE;
75 | operations[2].child1_scaler_index = PLL_SCALE_BUFFER_NONE;
76 | operations[2].child2_scaler_index = PLL_SCALE_BUFFER_NONE;
77 |
78 | /* check attributes */
79 | unsigned int attributes = get_attributes(argc, argv);
80 |
81 | /* test illegal alpha value */
82 | double invalid_alpha = 0;
83 | double * rate_cats = (double *) malloc(4 * sizeof(double));
84 | if (pll_compute_gamma_cats(invalid_alpha, 4, rate_cats, PLL_GAMMA_RATES_MEAN) == PLL_FAILURE)
85 | {
86 | if (pll_errno != PLL_ERROR_PARAM_INVALID)
87 | printf("Error is %d instead of %d\n", pll_errno, PLL_ERROR_PARAM_INVALID);
88 | }
89 | else
90 | {
91 | printf("Computing gamma rates for alpha = %f should have failed\n",
92 | invalid_alpha);
93 | }
94 | free (rate_cats);
95 |
96 | for (k = 0; k < NUM_CATS; ++k)
97 | {
98 | pll_partition_t * partition;
99 | partition = pll_partition_create(
100 | n_tips, /* numer of tips */
101 | 4, /* clv buffers */
102 | N_STATES_NT, /* number of states */
103 | n_sites, /* sequence length */
104 | 1, /* different rate parameters */
105 | 2*n_tips-3, /* probability matrices */
106 | n_cat_gamma[k], /* gamma categories */
107 | 0, /* scale buffers */
108 | attributes
109 | ); /* attributes */
110 |
111 | if (!partition)
112 | {
113 | printf("Fail creating partition");
114 | continue;
115 | }
116 |
117 | double branch_lengths[4] = { 0.1, 0.2, 1, 1};
118 | double frequencies[4] = { 0.3, 0.4, 0.1, 0.2 };
119 | unsigned int matrix_indices[4] = { 0, 1, 2, 3 };
120 | double subst_params[6] = {1,titv,1,1,titv,1};
121 |
122 | pll_set_frequencies(partition, 0, frequencies);
123 | pll_set_subst_params(partition, 0, subst_params);
124 |
125 | pll_set_tip_states(partition, 0, pll_map_nt, "WAACTCGCTA--ATTCTAAT");
126 | pll_set_tip_states(partition, 1, pll_map_nt, "CACCATGCTA--ATTGTCTT");
127 | pll_set_tip_states(partition, 2, pll_map_nt, "AG-C-TGCAG--CTTCTACT");
128 | pll_set_tip_states(partition, 3, pll_map_nt, "CGTCTTGCAA--AT-C-AAG");
129 | pll_set_tip_states(partition, 4, pll_map_nt, "CGACTTGCCA--AT-T-AAG");
130 |
131 | for (i = 0; i < NUM_ALPHAS; ++i)
132 | {
133 | for (m = 0; m < N_MODES; ++m)
134 | {
135 | printf ("\n\n TEST alpha(ncats) = %6.2f(%2d), mode = %s\n\n",
136 | alpha[i], n_cat_gamma[k], MODENAME(m));
137 |
138 | double * rate_cats = (double *) malloc(n_cat_gamma[k] * sizeof(double));
139 |
140 | if (pll_compute_gamma_cats(alpha[i], n_cat_gamma[k],
141 | rate_cats, modes[m]) == PLL_FAILURE)
142 | {
143 | printf("Fail computing the gamma rates\n");
144 | continue;
145 | }
146 |
147 | for (j=0; j