Added proper title to aptx trees
[jalview.git] / src / jalview / ext / archaeopteryx / ArchaeopteryxTreeConverter.java
1 package jalview.ext.archaeopteryx;
2
3 import jalview.analysis.TreeBuilder;
4 import jalview.datamodel.SequenceI;
5 import jalview.math.MatrixI;
6 import jalview.util.MessageManager;
7
8 import org.forester.phylogeny.Phylogeny;
9 import org.forester.phylogeny.PhylogenyNode;
10
11 public class ArchaeopteryxTreeConverter
12 {
13   protected SequenceI[] sequences;
14
15   private Phylogeny aptxTree;
16
17   private PhylogenyNode rootNode;
18
19   protected MatrixI distances;
20   
21   protected TreeBuilder jalviewTree;
22   
23   public String treeTitle;
24
25
26
27   public ArchaeopteryxTreeConverter(TreeBuilder calculatedTree)
28   {
29     this.jalviewTree = calculatedTree;
30     this.sequences = jalviewTree.getSequences();
31     this.distances = jalviewTree.getDistances();
32
33   }
34
35   public Phylogeny buildAptxTree()
36   {
37     this.rootNode = new PhylogenyNode();
38
39     return buildAptxTree(rootNode);
40
41   }
42
43   public Phylogeny buildAptxTree(PhylogenyNode treeRoot)
44   {
45
46     this.rootNode = treeRoot;
47
48     this.aptxTree = new Phylogeny();
49
50     this.treeTitle = generateTreeName();
51     this.aptxTree.setName(treeTitle);
52
53     // final NeighborJoiningF nj = NeighborJoiningF.createInstance(false, 5);
54
55     //
56     // final Phylogeny phy = nj.execute(JalviewMatrixToForesterMatrix
57     // .convertJalviewToForester(distances));
58
59     return buildAptxTree(sequences);
60
61   }
62
63   // testing method to be removed
64   public Phylogeny buildAptxTree(SequenceI[] sequences)
65   {
66
67     for (SequenceI sequence : sequences)
68     {
69       PhylogenyNode treeNode = new PhylogenyNode(sequence.getName());
70       rootNode.addAsChild(treeNode);
71
72     }
73
74     aptxTree.setRoot(rootNode);
75     return aptxTree;
76
77   }
78
79
80   /**
81    * Formats a localised title for the tree panel, like
82    * <p>
83    * Neighbour Joining Using BLOSUM62
84    * <p>
85    * For a tree loaded from file, just uses the file name
86    * 
87    * @return
88    */
89   public String generateTreeName()
90   {
91     if (treeTitle != null) // will currently never happen, loaded tree file will
92                            // take a different path
93     {
94       return treeTitle;
95     }
96     else
97     {
98       /*
99       * i18n description of Neighbour Joining or Average Distance method
100       */
101       String treecalcnm = MessageManager
102               .getString("label.tree_calc_" + jalviewTree.getClass()
103                       .getSimpleName().substring(0, 2).toLowerCase());
104       /*
105       * short score model name (long description can be too long)
106       */
107       String smn = jalviewTree.getScoreModel().getName();
108
109       /*
110       * put them together as <method> Using <model>
111       */
112       final String ttl = MessageManager
113               .formatMessage("label.treecalc_title", treecalcnm, smn);
114       return ttl;
115     }
116   }
117 }