Bio-MUST-Core

 view release on metacpan or  search on metacpan

lib/Bio/MUST/Core/Tree.pm  view on Meta::CPAN

package Bio::MUST::Core::Tree;
# ABSTRACT: Thin wrapper around Bio::Phylo trees
# CONTRIBUTOR: Valerian LUPO <valerian.lupo@uliege.be>
$Bio::MUST::Core::Tree::VERSION = '0.252040';
use Moose;
# use MooseX::SemiAffordanceAccessor;
use namespace::autoclean;

use autodie;
use feature qw(say);

use Smart::Comments '###';

use Carp;
use Const::Fast;
use File::Basename;
use List::AllUtils qw(uniq max_by);
use Tie::IxHash;

use Bio::Phylo::Util::Logger ':levels';
use Bio::Phylo::IO qw(parse);

# silence warnings about removing orphan nodes
use Bio::Phylo::Forest::TreeRole 'verbose' => ERROR;

use Bio::MUST::Core::Types;
use Bio::MUST::Core::Constants qw(:files);
use Bio::MUST::Core::Utils qw(:filenames);
use aliased 'Bio::MUST::Core::SeqId';
use aliased 'Bio::MUST::Core::IdList';
# TODO: check if no circularity issue between Tree and Tree::Splits load?
use aliased 'Bio::MUST::Core::Tree::Splits';
with 'Bio::MUST::Core::Roles::Commentable',
     'Bio::MUST::Core::Roles::Listable';


has 'tree' => (
    is       => 'ro',
    isa      => 'Maybe[Bio::Phylo::Forest::Tree]',
    default  => undef,
    writer   => '_set_tree',
);



sub newick_str {                            ## no critic (RequireArgUnpacking)
    return _clean_newick_str( shift->tree->to_newick(@_) );     # currying
}

sub _clean_newick_str {
    my $newick_str = shift;

    # remove quotes...
    # ...and trailing zero-length branch length (RAxML) if any
    $newick_str =~ tr{'"}{}d;
    $newick_str =~ s{:0\.0+;}{;}xmsg;

    return $newick_str;
}

# color for uncolored taxon (see Taxonomy::ColorScheme)
const my $BLACK => '#000000';

# Note: we don't store SeqId objects in the tree but dynamically build them
# to benefit from SeqId methods (e.g., auto-removal of first '_'). This is
# the most flexible approach without costing too much in CPU-time.



( run in 2.147 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )