生物信息学Bioperl-----基于fasta序列构建进化关系树代码
程序员文章站
2024-03-04 12:13:23
...
生物信息学Bioperl-----基于fasta序列构建进化关系树代码
方法一:
#使用如下模块
use Bio::AlignIO;
use Bio::Align::DNAStatistics;
use Bio::Tree::DistanceFactory;
use Bio::TreeIO;
#读取一个alignment文件,格式为clustalw格式,存储在alignIO对象$alnio中
my $alnio = Bio::AlignIO->new(-file => 'filename', -format=>'clustalw');
#新建一个DistanceFactory的对象实例,选择邻接neigborjoin算法计算距离
my $dfactory = Bio::Tree::DistanceFactory->new(-method => 'NJ');
#新建一个DNAStatistics的对象实例
my $stats = Bio::Align::DNAStatistics->new;
#新建一个TreeIO的对象实例,tree的格式指定为newick格式
my $treeout = Bio::TreeIO->new(-format => 'newick');
#while循环读取的alignment
while( my $aln = $alnio->next_aln ) {
#计算距离,并把距离矩阵保存在$mat对象实例中
my $mat = $stats->distance(-method => 'Kimura',
-align => $aln);
#生成进化树
my $tree = $dfactory->make_tree($mat);
#最后输出进化树
$treeout->write_tree($tree);
}
方法二:
#使用如下bioperl的模块
use Bio::AlignIO;
use Bio::Align::DNAStatistics;
use Bio::Tree::DistanceFactory;
use Bio::Matrix::IO;
use Bio::TreeIO;
#读取一个alignment文件,保存在一个alingIO的对象当中,对象名为$alinio
my $alnio = Bio::AlignIO->new(-file => 'filename', -format=>'clustalw');
#新建一个DistanceFactory的对象实例,选择邻接neigborjoin算法计算距离
my $dfactory = Bio::Tree::DistanceFactory->new(-method => 'NJ');
#新建一个DNAStatistics的对象实例
my $stats = Bio::Align::DNAStatistics->new;
#新建一个TreeIO的对象实例,tree的格式指定为newick格式
my $treeout = Bio::TreeIO->new(-format => 'newick');
#while循环读取的alignment
while( my $aln = $alnio->next_aln ) {
#读取外部软件phylip计算得到的alignment的距离值文件filename.dist,并保存在$parser对象中
my $parser = Bio::Matrix::IO->new(-format => 'phylip',
-file => 'filename.dist');
#调用$parser的next_matrix方法,这里可能是距离矩阵
my $mat = $parser->next_matrix;
#调用$dfactory的make_tree方法,参数是$mat,生成树,保存在$tree对象中
my $tree = $dfactory->make_tree($mat);
#最会输出生成的tree
$treeout->write_tree($tree);
}
上一篇: 可持久化数组
下一篇: 生物信息学-1-BASIC