summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/phylogenetics/PhylogeneticTree.lua
blob: 242ccf183ff17cbd7477c42ba1770b4f6b26f6cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
-- Copyright 2013 by Sarah Mäusle and Till Tantau
--
-- This file may be distributed an/or modified
--
-- 1. under the LaTeX Project Public License and/or
-- 2. under the GNU Public License
--
-- See the file doc/generic/pgf/licenses/LICENSE for more information

-- @release $Header$


local PhylogeneticTree = {}


-- Namespace
require("pgf.gd.phylogenetics").PhylogeneticTree = PhylogeneticTree

-- Imports
local InterfaceToAlgorithms = require "pgf.gd.interface.InterfaceToAlgorithms"
local Storage               = require "pgf.gd.lib.Storage"
local Direct                = require "pgf.gd.lib.Direct"

-- Shorthand:
local declare = InterfaceToAlgorithms.declare


---
declare {
  key = "phylogenetic tree layout",
  algorithm = PhylogeneticTree,

  postconditions = {
    upward_oriented = true
  },

  summary = [["
    Layout for drawing phylogenetic trees.
  "]],
  documentation = [["
    ...
  "]],
  examples = [["
    \tikz \graph [phylogenetic tree layout, upgma,
                  distance matrix={
                    0 4 9 9 9 9 9
                    4 0 9 9 9 9 9
                    9 9 0 2 7 7 7
                    9 9 2 0 7 7 7
                    9 9 7 7 0 3 5
                    9 9 7 7 3 0 5
                    9 9 7 7 5 5 0}]
      { a, b, c, d, e, f, g };
  "]]
}


-- Computes a phylogenetic tree and/or visualizes it
-- - computes a phylogenetic tree according to what the "phylogenetic
-- algorithm" key is set to
-- - invokes a graph drawing algorithm according to what the
-- "phylogenetic layout" key is set to
function PhylogeneticTree:run()

  local options = self.digraph.options

  -- Two storages for some information computed by the phylogenetic
  -- tree generation algorithm
  local lengths   = Storage.newTableStorage()

  -- First, compute the phylogenetic tree
  local tree = options.algorithm_phases['phylogenetic tree generation'].new {
    main_algorithm = self,
    lengths        = lengths
  }:run()

  tree = Direct.ugraphFromDigraph(tree)

  -- Second, layout the tree
  local layout_class = options.algorithm_phases['phylogenetic tree layout']
  layout_class.new {
    main_algorithm = self,
    distances      = distances,
    lengths        = lengths,
    tree           = tree
  }:run()

  tree:sync()
end

return PhylogeneticTree