Bio::Phylo::Unparsers::Fasta - Serializer used by Bio::Phylo::IO, no serviceable parts inside


Bio-Phylo documentation Contained in the Bio-Phylo distribution.

Index


Code Index:

NAME

Top

Bio::Phylo::Unparsers::Fasta - Serializer used by Bio::Phylo::IO, no serviceable parts inside

DESCRIPTION

Top

Definition lines for each FASTA records are either (first choice) created from the generic 'fasta_def_line' annotation which can be manipulated like so:

 $datum->set_generic( 'fasta_def_line' => $line )

So you can retrieve it by calling:

 my $line = $datum->get_generic('fasta_def_line');

Alternatively the name of the $datum is used, or, lacking that, the name of the associated taxon, if any.

SEE ALSO

Top

Bio::Phylo::IO

The phylip unparser is called by the Bio::Phylo::IO object. Look there to learn how to create phylip formatted files.

Bio::Phylo::Manual

Also see the manual: Bio::Phylo::Manual and http://rutgervos.blogspot.com.

CITATION

Top

If you use Bio::Phylo in published research, please cite it:

Rutger A Vos, Jason Caravas, Klaas Hartmann, Mark A Jensen and Chase Miller, 2011. Bio::Phylo - phyloinformatic analysis using Perl. BMC Bioinformatics 12:63. http://dx.doi.org/10.1186/1471-2105-12-63

REVISION

Top

 $Id: Phylip.pm 1660 2011-04-02 18:29:40Z rvos $


Bio-Phylo documentation Contained in the Bio-Phylo distribution.
package Bio::Phylo::Unparsers::Fasta;
use strict;
use base 'Bio::Phylo::Unparsers::Abstract';
use Bio::Phylo::Util::Exceptions 'throw';
use Bio::Phylo::Util::CONSTANT qw':objecttypes looks_like_object';

sub _to_string {
    my $self = shift;
    my $obj  = $self->{'PHYLO'};
    my $matrix;
    eval { $matrix = $obj if looks_like_object $obj, _MATRIX_; };
    if ($@) {
        undef($@);
        eval {
            ($matrix) = @{ $obj->get_matrices }
              if looks_like_object $obj, _PROJECT_;
        };
        if ( $@ or not $matrix ) {
            throw 'ObjectMismatch' => 'Invalid object!';
        }
    }
    my $string = '';
    for my $seq ( @{ $matrix->get_entities } ) {
        my $taxon_name = '';
        if ( my $taxon = $seq->get_taxon ) {
            $taxon_name = $taxon->get_name;
        }
        my $name = $seq->get_generic('fasta_def_line') || $seq->get_name || $taxon_name;
        my $def  = '>' . $name . "\n";
        my $char = $seq->get_char;
        my $n = 80;    # $n is group size.
        my @groups = unpack "a$n" x ((length($char)/$n)-1) . "a*", $char;
        $string .= $def . join("\n", @groups) . "\n";
    }
    return $string;
}

# podinherit_insert_token

1;