Bio-Phylo
view release on metacpan or search on metacpan
lib/Bio/Phylo/Matrices/DatumRole.pm view on Meta::CPAN
=item new()
Datum object constructor.
Type : Constructor
Title : new
Usage : my $datum = Bio::Phylo::Matrices::Datum->new;
Function: Instantiates a Bio::Phylo::Matrices::Datum
object.
Returns : A Bio::Phylo::Matrices::Datum object.
Args : None required. Optional:
-taxon => $taxon,
-weight => 0.234,
-type => DNA,
-pos => 2,
=cut
sub new : Constructor {
# could be child class
my $class = shift;
# notify user
$logger->info("constructor called for '$class'");
if ( not $LOADED_WRAPPERS ) {
eval do { local $/; <DATA> };
die $@ if $@;
$LOADED_WRAPPERS++;
}
# go up inheritance tree, eventually get an ID
my $self = $class->SUPER::new(
@_,
'-listener' => \&_update_characters,
);
return $self;
}
=item new_from_bioperl()
Datum constructor from Bio::Seq argument.
Type : Constructor
Title : new_from_bioperl
Usage : my $datum =
Bio::Phylo::Matrices::Datum->new_from_bioperl($seq);
Function: Instantiates a
Bio::Phylo::Matrices::Datum object.
Returns : A Bio::Phylo::Matrices::Datum object.
Args : A Bio::Seq (or similar) object
=cut
sub new_from_bioperl {
my ( $class, $seq, @args ) = @_;
# want $seq type-check here? Allowable: is-a Bio::PrimarySeq,
# Bio::LocatableSeq /maj
my $type = $seq->alphabet || $seq->_guess_alphabet || 'dna';
my $self = $class->new( '-type' => $type, @args );
# copy seq string
my $seqstring = $seq->seq;
if ( $seqstring and $seqstring =~ /\S/ ) {
eval { $self->set_char($seqstring) };
if (
$@
and looks_like_instance(
$@, 'Bio::Phylo::Util::Exceptions::InvalidData'
)
)
{
$logger->error(
"\nAn exception of type Bio::Phylo::Util::Exceptions::InvalidData was caught\n\n"
. $@->description
. "\n\nThe BioPerl sequence object contains invalid data ($seqstring)\n"
. "I cannot store this string, I will continue instantiating an empty object.\n"
. "---------------------------------- STACK ----------------------------------\n"
. $@->trace->as_string
. "\n--------------------------------------------------------------------------"
);
}
}
# copy name
my $name = $seq->display_id;
$self->set_name($name) if defined $name;
# copy desc
my $desc = $seq->desc;
$self->set_desc($desc) if defined $desc;
# only Bio::LocatableSeq objs have these fields...
for my $field (qw(start end strand)) {
$self->$field( $seq->$field ) if $seq->can($field);
}
return $self;
}
=back
=head2 MUTATORS
=over
=item set_char()
Sets character state(s)
Type : Mutator
Title : set_char
Usage : $datum->set_char($char);
Function: Assigns a datum's character value.
Returns : Modified object.
Args : The $char argument is checked against
the allowed ranges for the various
character types: IUPAC nucleotide (for
types of DNA|RNA|NUCLEOTIDE), IUPAC
single letter amino acid codes (for type
( run in 3.578 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )