package jalview.ext.archaeopteryx; import jalview.analysis.TreeBuilder; import jalview.datamodel.SequenceI; import jalview.util.MessageManager; import org.forester.evoinference.matrix.distance.DistanceMatrix; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; public class ArchaeopteryxTreeConverter { protected SequenceI[] sequences; private Phylogeny aptxTree; private PhylogenyNode rootNode; protected DistanceMatrix distances; protected TreeBuilder jalviewTree; public String treeTitle; public ArchaeopteryxTreeConverter(TreeBuilder calculatedTree) { this.jalviewTree = calculatedTree; this.sequences = jalviewTree.getSequences(); this.distances = MatrixConverter.convertJalviewToForester( jalviewTree.getDistances(), jalviewTree.getSequences()); } public Phylogeny buildAptxTree() { this.rootNode = new PhylogenyNode(); return buildAptxTree(rootNode); } public Phylogeny buildAptxTree(PhylogenyNode treeRoot) { this.rootNode = treeRoot; this.aptxTree = new Phylogeny(); this.treeTitle = generateTreeName(); this.aptxTree.setName(treeTitle); // final NeighborJoiningF nj = NeighborJoiningF.createInstance(false, 5); // // final Phylogeny phy = nj.execute(JalviewMatrixToForesterMatrix // .convertJalviewToForester(distances)); return buildAptxTree(sequences); } // testing method to be removed public Phylogeny buildAptxTree(SequenceI[] sequences) { for (SequenceI sequence : sequences) { PhylogenyNode treeNode = new PhylogenyNode(sequence.getName()); rootNode.addAsChild(treeNode); } aptxTree.setRoot(rootNode); return aptxTree; } /** * Formats a localised title for the tree panel, like *
* Neighbour Joining Using BLOSUM62 *
* For a tree loaded from file, just uses the file name
*
* @return
*/
public String generateTreeName()
{
if (treeTitle != null) // will currently never happen, loaded tree file will
// take a different path
{
return treeTitle;
}
else
{
/*
* i18n description of Neighbour Joining or Average Distance method
*/
String treecalcnm = MessageManager
.getString("label.tree_calc_" + jalviewTree.getClass()
.getSimpleName().substring(0, 2).toLowerCase());
/*
* short score model name (long description can be too long)
*/
String smn = jalviewTree.getScoreModel().getName();
/*
* put them together as