The PAL project is a collaborative effort to provide a high quality Java library for use in molecular evolution and phylogenetics. Updates of PAL are released in regular intervals. At present (version 1.4) PAL consists of approximately 200 public classes/interfaces in 16 packages with a total of more than 35,000 lines of Java code. Please refer to the API documentation (available in source archives) for a detailed description of all classes and methods available, and to the release history for an overview of the development history of PAL.
More info. please refer: http://www.cebl.auckland.ac.nz/pal-project/
Following, I'll illustrate how to use PAL to construct Neighbour Joinning (NJ) tree, according to the algorithm of NJ, the result tree is a unrooted tree, but, sometimes, we need rooted tree, then in this page, I'll also illustrate how to use PAL to convert an unrootd tree to rooted tree.
GOAL:
1. Using PAL to construct unrooted tree.
2. Using PAL to convert unrooted tree to rooted tree.
1. Using PAL to construct unrooted tree.
import pal.distance.DistanceMatrix;
import pal.tree.NeighborJoiningTree;
NeighborJoiningTree njTree = new NeighborJoiningTree(DistanceMatrix);
njTree.toString(); // Newick format representation of NJ tree.
In order to constract NJ tree, we need pal.distance.DistanceMatrix;
//new DistanceMatrix(double[][] distance, IdGroup idGroup).
DistanceMatrix distanceMatrix = new DistanceMatrix(distance, TaxaGroup );
While in PAL IdGroup is an interface, we need an implentation for it, here TaxaGroup is an implementation for it.
package picb.wavefancy.ReweightedTree;
import pal.misc.IdGroup;
import pal.misc.Identifier;
/**
* @author icorner
*
*/
public class TaxaGroup implements IdGroup {
private static final long serialVersionUID = -8639297673966439918L;
private Identifier[] identifiers;
private String[] taxaNames;
public TaxaGroup(String[] taxas){
identifiers = new Identifier[taxas.length];
for (int i = 0; i < taxas.length; i++) {
identifiers[i] = new Identifier(taxas[i]);
}
setTaxaNames(taxas);
}
public String[] getTaxaNames() {
return taxaNames;
}
public void setTaxaNames(String[] taxaNames) {
this.taxaNames = taxaNames;
}
/* Returns the number of identifiers in this group
* @see pal.misc.IdGroup#getIdCount()
*/
public int getIdCount() {
// TODO Auto-generated method stub
return identifiers.length;
}
/* Returns the ith identifier.
* @see pal.misc.IdGroup#getIdentifier(int)
*/
public Identifier getIdentifier(int index) {
// TODO Auto-generated method stub
return identifiers[index];
}
/* Sets the ith identifier.
* @see pal.misc.IdGroup#setIdentifier(int, pal.misc.Identifier)
*/
public void setIdentifier(int index, Identifier identifier) {
// TODO Auto-generated method stub
identifiers[index] = identifier;
}
/* returns the index of the identifier with the given name. return -1 if didn't find the target one.
* @see pal.misc.IdGroup#whichIdNumber(java.lang.String)
*/
public int whichIdNumber(String identifierName) {
for (int i = 0; i < identifiers.length; i++) {
if (identifiers[i].getName().equals(identifierName)) {
return i;
}
}
return -1;
}
}
2. Using PAL to convert unrooted tree to rooted tree.
The NeighborJoiningTree in PAL is a unrooted tree. We could use the toolset in PAL to convert an unrooted tree to rooted tree.
import pal.distance.DistanceMatrix;
import pal.tree.NeighborJoiningTree;
import pal.tree.Tree;
import pal.tree.TreeTool;
NeighborJoiningTree njTree = new NeighborJoiningTree(distanceMatrix);
String[] outGroupArr = new String[1]; //It's OK to specify several outgroup.More info. please refer PAL api.
Tree rootedTree = TreeTool.getRooted(njTree,outGroupArr);
rootedTree.toString(); // Newick format representation of a rooted tree.