File Coverage

blib/lib/GenOO/RegionCollection/Factory/BED.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 25 26 96.1


line stmt bran cond sub pod time code
1             # POD documentation - main docs before the code
2              
3             =head1 NAME
4              
5             GenOO::RegionCollection::Factory::BED - Factory for creating GenOO::RegionCollection object from a BED file
6              
7             =head1 SYNOPSIS
8              
9             # Creates GenOO::RegionCollection object from a BED file
10              
11             # Preferably use it through the generic GenOO::RegionCollection::Factory
12             my $factory = GenOO::RegionCollection::Factory->create('BED',
13             {
14             file => 'sample.bed'
15             }
16             );
17              
18             =head1 DESCRIPTION
19              
20             An instance of this class is a concrete factory for the creation of a
21             L<GenOO::RegionCollection> object from a BED file. It offers the method
22             "read_collection" (as the consumed role requires) which returns the actual
23             L<GenOO::RegionCollection> object in the form of
24             L<GenOO::RegionCollection::Type::DoubleHashArray>. The latter is the implementation
25             of the L<GenOO::RegionCollection> class based on the complex data structure
26             L<GenOO::Data::Structure::DoubleHashArray>.
27              
28             =head1 EXAMPLES
29              
30             # Create a concrete factory
31             my $factory_implementation = GenOO::RegionCollection::Factory->create('BED',
32             {
33             file => 'sample.bed'
34             }
35             );
36            
37             # Return the actual GenOO::RegionCollection object
38             my $collection = $factory_implementation->read_collection;
39             print ref($collection) # GenOO::RegionCollection::Type::DoubleHashArray
40              
41             =cut
42              
43             # Let the code begin...
44              
45             package GenOO::RegionCollection::Factory::BED;
46             $GenOO::RegionCollection::Factory::BED::VERSION = '1.4.6';
47              
48             #######################################################################
49             ####################### Load External modules #####################
50             #######################################################################
51 1     1   3580 use Moose;
  1         2  
  1         9  
52 1     1   5981 use namespace::autoclean;
  1         3  
  1         10  
53              
54              
55             #######################################################################
56             ######################### Load GenOO modules ######################
57             #######################################################################
58 1     1   80 use GenOO::RegionCollection::Type::DoubleHashArray;
  1         4  
  1         33  
59 1     1   4 use GenOO::Data::File::BED;
  1         2  
  1         238  
60              
61              
62             #######################################################################
63             ####################### Interface attributes ######################
64             #######################################################################
65             has 'file' => (
66             isa => 'Str',
67             is => 'ro',
68             required => 1
69             );
70              
71             has 'redirect_score_to_copy_number' => (
72             traits => ['Bool'],
73             is => 'rw',
74             isa => 'Bool',
75             default => 0,
76             lazy => 1
77             );
78              
79             has 'filter_code' => (
80             isa => 'CodeRef',
81             is => 'ro',
82             default => sub { sub {return 1} }
83             );
84              
85              
86             #######################################################################
87             ########################## Consumed roles #########################
88             #######################################################################
89             with 'GenOO::RegionCollection::Factory::Requires';
90              
91              
92             #######################################################################
93             ######################## Interface Methods ########################
94             #######################################################################
95             sub read_collection {
96 3     3 0 2588 my ($self) = @_;
97            
98 3         144 my $collection = GenOO::RegionCollection::Type::DoubleHashArray->new;
99            
100 3         99 my $parser = GenOO::Data::File::BED->new(
101             file => $self->file,
102             redirect_score_to_copy_number => $self->redirect_score_to_copy_number,
103             );
104            
105 3         29 while (my $record = $parser->next_record) {
106 27 100       1011 $collection->add_record($record) if $self->filter_code->($record);
107             }
108            
109 3         113 return $collection;
110             }
111              
112             1;