使用PAL创建 NeighbourJoining tree 以及 从Unrooted tree 到 rootedTree


Overview:

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.

 



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值