| 1 | package Bio::Phylo::Parsers::Taxlist; | ||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use base 'Bio::Phylo::Parsers::Abstract'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use Bio::Phylo::Util::CONSTANT; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | =head1 NAME | ||||||||||||
| 8 | |||||||||||||
| 9 | Bio::Phylo::Parsers::Taxlist - Parser used by Bio::Phylo::IO, no serviceable parts inside | ||||||||||||
| 10 | |||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||
| 12 | |||||||||||||
| 13 | This module is used for importing sets of taxa from plain text files, one taxon | ||||||||||||
| 14 | on each line. It is called by the L<Bio::Phylo::IO|Bio::Phylo::IO> object, so | ||||||||||||
| 15 | look there for usage examples. If you want to parse from a string, you | ||||||||||||
| 16 | may need to indicate the field separator (default is '\n') to the | ||||||||||||
| 17 | Bio::Phylo::IO->parse call: | ||||||||||||
| 18 | |||||||||||||
| 19 | -fieldsep => '\n', | ||||||||||||
| 20 | |||||||||||||
| 21 | =cut | ||||||||||||
| 22 | |||||||||||||
| 23 | 4 | ▶ | sub _parse { | ||||||||||
|
Subroutine
_parse: called CC=11 SCAR=30.6
| |||||||||||||
| 24 | 4 | my $self = shift; | |||||||||||
| 25 | 4 | my $fh = $self->_handle; | |||||||||||
| 26 | 4 | my $fac = $self->_factory; | |||||||||||
| 27 | 4 | my $taxa = $fac->create_taxa; | |||||||||||
| 28 | 4 | ▶ | local $/ = $self->_args->{'-fieldsep'} || "\n"; | ||||||||||
|
Condition100%2/2
$self->_args->{'-fieldsep'} || "\n"
MC/DC100%1/1
$self->_args->{'-fieldsep'} || "\n"
$self->_args->{'-fieldsep'}
Truth table100%2/2
A
A= $self->_args->{'-fieldsep'}
| |||||||||||||
| 29 | 4 | ▶ | my $delim = $self->_args->{'-delim'} || "\t"; | ||||||||||
|
Condition50%1/2
$self->_args->{'-delim'} || "\t"
MC/DC0%0/1
$self->_args->{'-delim'} || "\t"
$self->_args->{'-delim'}
Truth table50%1/2
A
A= $self->_args->{'-delim'}
| |||||||||||||
| 30 | 4 | my @header; | |||||||||||
| 31 | 4 | ▶ | LINE: while (<$fh>) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 17 | chomp; | |||||||||||
| 33 | 17 | my @fields = split /$delim/, $_; | |||||||||||
| 34 | 17 | my $name; | |||||||||||
| 35 | my %meta; | ||||||||||||
| 36 | |||||||||||||
| 37 | # this means it is actually tabular, which also means it has a header | ||||||||||||
| 38 | 17 | ▶ | if ( scalar @fields > 1 ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | |||||||||||||
| 40 | # this happens the first line | ||||||||||||
| 41 | 0 | ▶ | if ( not @header ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 0 | @header = @fields; | |||||||||||
| 43 | 0 | for my $predicate ( @header ) { | |||||||||||
| 44 | 0 | ▶ | if ( $predicate =~ /^(.+?):.+$/ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 0 | my $prefix = $1; | |||||||||||
| 46 | $taxa->set_namespaces( | ||||||||||||
| 47 | 0 | $prefix => $Bio::Phylo::Util::CONSTANT::NS->{$prefix} | |||||||||||
| 48 | ); | ||||||||||||
| 49 | } | ||||||||||||
| 50 | } | ||||||||||||
| 51 | 0 | next LINE; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | # create key value pairs to attach | ||||||||||||
| 55 | 0 | for my $i ( 1 .. $#fields ) { | |||||||||||
| 56 | 0 | ▶ | $meta{$header[$i]} = $fields[$i] if $fields[$i]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | } | ||||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | # this is the first field regardless | ||||||||||||
| 61 | 17 | $name = shift @fields; | |||||||||||
| 62 | 17 | my $taxon = $fac->create_taxon( '-name' => $name ); | |||||||||||
| 63 | |||||||||||||
| 64 | # attach metadata, if any | ||||||||||||
| 65 | 17 | for my $predicate ( keys %meta ) { | |||||||||||
| 66 | $taxon->add_meta( | ||||||||||||
| 67 | 0 | $fac->create_meta( '-triple' => { $predicate => $meta{$predicate} } ) | |||||||||||
| 68 | ); | ||||||||||||
| 69 | } | ||||||||||||
| 70 | 17 | $taxa->insert( $taxon ); | |||||||||||
| 71 | } | ||||||||||||
| 72 | 4 | return $taxa; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | # podinherit_insert_token | ||||||||||||
| 76 | |||||||||||||
| 77 | =head1 SEE ALSO | ||||||||||||
| 78 | |||||||||||||
| 79 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||||||||||||
| 80 | for any user or developer questions and discussions. | ||||||||||||
| 81 | |||||||||||||
| 82 | =over | ||||||||||||
| 83 | |||||||||||||
| 84 | =item L<Bio::Phylo::IO> | ||||||||||||
| 85 | |||||||||||||
| 86 | The taxon list parser is called by the L<Bio::Phylo::IO> object. | ||||||||||||
| 87 | Look there for examples. | ||||||||||||
| 88 | |||||||||||||
| 89 | =item L<Bio::Phylo::Manual> | ||||||||||||
| 90 | |||||||||||||
| 91 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||||||||||||
| 92 | |||||||||||||
| 93 | =back | ||||||||||||
| 94 | |||||||||||||
| 95 | =head1 CITATION | ||||||||||||
| 96 | |||||||||||||
| 97 | If you use Bio::Phylo in published research, please cite it: | ||||||||||||
| 98 | |||||||||||||
| 99 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||||||||||||
| 100 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||||||||||||
| 101 | I<BMC Bioinformatics> B<12>:63. | ||||||||||||
| 102 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||||||||||||
| 103 | |||||||||||||
| 104 | =cut | ||||||||||||
| 105 | |||||||||||||
| 106 | 2 | 1; | |||||||||||