summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/phylogenetics/AuthorDefinedPhylogeny.lua
blob: f1acbd71281d4a06b5b1057ff73c00b20ff879b7 (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
-- Copyright 2013 by 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 AuthorDefinedPhylogeny = {}


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

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

-- Shorthand:
local declare = InterfaceToAlgorithms.declare


---
declare {
  key = "phylogenetic tree by author",
  algorithm = AuthorDefinedPhylogeny,
  phase = "phylogenetic tree generation",
  phase_default = true,

  summary = [["  
      When this key is used, the phylogenetic tree must be specified
      by the author (rather than being generated algorithmically).
  "]],
  documentation = [["
      A spanning tree of the input graph will be computed first (it
      must be connected, otherwise errors will result).
      The evolutionary length of the edges must be specified through
      the use of the |length| key for each edge.
  "]],
  examples = [["
      \tikz \graph [phylogenetic tree layout] {
        a -- {
          b [>length=2] --[length=1] { c, d },
          e [>length=3]
        }
      };
  "]]
}
    


function AuthorDefinedPhylogeny:run()
  
  local spanning_tree = self.main_algorithm.digraph.options.algorithm_phases["spanning tree computation"].new {
    ugraph = self.main_algorithm.ugraph,
    events = {} -- no events
  }:run()

  local phylogenetic_tree = Direct.ugraphFromDigraph(spanning_tree)
  local lengths = self.lengths
  
  for _,a in ipairs(phylogenetic_tree.arcs) do
    lengths[a.tail][a.head] = a:options('length')
  end

  return phylogenetic_tree
end



return AuthorDefinedPhylogeny