File Coverage

blib/lib/Bio/ViennaNGS/Fasta.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Bio::ViennaNGS::Fasta;
2              
3 1     1   17406 use 5.12.0;
  1         2  
  1         35  
4 1     1   431 use version; our $VERSION = qv('0.01');
  1         1425  
  1         5  
5 1     1   577 use Bio::DB::Fasta;
  1         76260  
  1         33  
6 1     1   304 use Moose;
  0            
  0            
7             use Carp;
8             use Data::Dumper;
9             use namespace::autoclean;
10              
11             has 'fa' => (
12             is => 'rw',
13             isa => 'Str',
14             required => 1,
15             predicate => 'has_fa',
16             );
17              
18             has 'fastadb' => (
19             is => 'rw',
20             isa => 'Bio::DB::Fasta',
21             builder => '_get_fastadb',
22             predicate => 'has_db',
23             lazy => 1,
24             );
25              
26             has 'fastaids' => (
27             is => 'ro',
28             isa => 'ArrayRef',
29             builder => '_get_fastaids',
30             predicate => 'has_ids',
31             lazy => 1,
32             );
33              
34             before 'fastaids' => sub{
35             my $self = shift;
36             $self->fastadb;
37             };
38              
39             sub _get_fastadb {
40             my $self = shift;
41             my $this_function = (caller(0))[3];
42             confess "ERROR [$this_function] Fasta input not available"
43             unless (-f $self->fa);
44             my $db = Bio::DB::Fasta->new($self->fa) or croak $!;
45             return $db;
46             }
47              
48             sub _get_fastaids {
49             my $self = shift;
50             my $this_function = (caller(0))[3];
51             confess "ERROR [$this_function] Attribute 'fastadb' not found $!"
52             unless ($self->has_db);
53             my $db = $self->fastadb or croak $!;
54             my @ids = $db->ids or croak $!;
55             return \@ids;
56             }
57              
58             __PACKAGE__->meta->make_immutable;
59              
60             1;
61             __END__
62              
63              
64             =head1 NAME
65              
66             Bio::ViennaNGS::Fasta - Moose warapper for Bio::DB::Fasta
67              
68             =head1 SYNOPSIS
69              
70             use Bio::ViennaNGS::Fasta;
71              
72             my $f = Bio::ViennaNGS::Fasta->new( fa => "data/foo.fa", );
73              
74             # get all FASTA IDs
75             my @ids = $f->fastaids;
76              
77             =head1 DESCRIPTION
78              
79             This module provides a L<Moose> interface to L<Bio::DB::Fasta>.
80              
81             =head1 EXPORT
82              
83             None by default.
84              
85              
86             =head1 SEE ALSO
87              
88             =over 2
89              
90             =item L<Bio::ViennaNGS>
91              
92             =item L<Bio::DB::Fasta>
93              
94             =back
95              
96             =head1 AUTHOR
97              
98             Michael T. Wolfinger, E<lt>michael@wolfinger.euE<gt>
99              
100             =head1 COPYRIGHT AND LICENSE
101              
102             Copyright (C) 2014 by Michael T. Wolfinger
103              
104             This library is free software; you can redistribute it and/or modify
105             it under the same terms as Perl itself, either Perl version 5.16.3 or,
106             at your option, any later version of Perl 5 you may have available.
107              
108             This software is distributed in the hope that it will be useful, but
109             WITHOUT ANY WARRANTY; without even the implied warranty of
110             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
111              
112             =cut