| 1 | package Bio::Phylo::Parsers::Phylip; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base 'Bio::Phylo::Parsers::Abstract'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Bio::Phylo::Util::Exceptions 'throw'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | Bio::Phylo::Parsers::Phylip - Parser used by Bio::Phylo::IO, no serviceable parts inside | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | This module is used for parsing PHYLIP character state matrix files. At present this only | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | works on non-interleaved files. As PHYLIP files don't indicate what data type they are you | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | should indicate this as an argument to the Bio::Phylo::IO::parse function, i.e.: | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | use Bio::Phylo::IO 'parse'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | my $file = shift @ARGV; | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | my $type = 'dna'; # or rna, protein, restriction, standard, continuous | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | my $matrix = parse( | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | '-file' => $file, | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | '-format' => 'phylip', | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | '-type' => $type, | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | )->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | print ref($matrix); # probably prints Bio::Phylo::Matrices::Matrix; | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=9 SCAR=22.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | my $factory = $self->_factory; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | ▶ | my $type = $self->_args->{'-type'} || 'standard'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_args->{'-type'} || 'standard'
MC/DC0%0/1
$self->_args->{'-type'} || 'standard'
$self->_args->{'-type'}
Truth table50%1/2
A
A= $self->_args->{'-type'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | my $handle = $self->_handle; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | my $matrix = $factory->create_matrix( '-type' => $type ); | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | my ( $ntax, $nchar ); | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | LINE: while (<$handle>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 20 | my ( $name, $seq ); | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 20 | ▶ | if ( /^\s*(\d+)\s+(\d+)\s*$/ && !$ntax && !$nchar ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
/^\s*(\d+)\s+(\d+)\s*$/ and not $ntax and not $nchar
/^\s*(\d+)\s+(\d+)\s*$/ and not $ntax
MC/DC33%1/3
/^\s*(\d+)\s+(\d+)\s*$/ and not $ntax and not $nchar
/^\s*(\d+)\s+(\d+)\s*$/
not $ntax
not $nchar
Truth table50%2/4
A and not(B) and not(C)
A= /^\s*(\d+)\s+(\d+)\s*$/B= not $ntaxC= not $nchar
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ( $ntax, $nchar ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | next LINE; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | elsif ( /^\s*(\S+)\s+(.+)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | ( $name, $seq ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 16 | $seq =~ s/\s//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $name = substr( $_, 0, 10 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $seq = substr( $_, 10 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 16 | $matrix->insert( | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | $factory->create_datum( | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | '-type' => $type, | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | '-name' => $name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | '-char' => $matrix->get_type_object->split($seq), | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | my ( $my_nchar, $my_ntax ) = ( $matrix->get_nchar, $matrix->get_ntax ); | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | ▶ | $nchar != $my_nchar | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | && throw 'BadFormat' => "observed ($my_nchar) != expected ($nchar) nchar"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | $ntax != $my_ntax | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | && throw 'BadFormat' => "observed ($my_ntax) != expected ($ntax) ntax"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | return $matrix; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # podinherit_insert_token | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | for any user or developer questions and discussions. | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | =over | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | =item L<Bio::Phylo::IO> | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | The PHYLIP parser is called by the L<Bio::Phylo::IO> object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | Look there for examples. | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | =item L<Bio::Phylo::Manual> | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | =head1 CITATION | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | If you use Bio::Phylo in published research, please cite it: | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | I<BMC Bioinformatics> B<12>:63. | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||