File Coverage

blib/lib/GenOO/RegionCollection/Factory/SAM.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 1 0.0
total 28 30 93.3


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::SAM - Factory for creating GenOO::RegionCollection object from a SAM file
6              
7             =head1 SYNOPSIS
8              
9             # Creates GenOO::RegionCollection object from a SAM file
10              
11             # Preferably use it through the generic GenOO::RegionCollection::Factory
12             my $factory = GenOO::RegionCollection::Factory->new('SAM',
13             {
14             file => 'sample.sam'
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 SAM 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->new('SAM',
32             {
33             file => 'sample.sam'
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::SAM;
46             $GenOO::RegionCollection::Factory::SAM::VERSION = '1.4.6';
47 1     1   3343 use Moose;
  1         2  
  1         10  
48 1     1   6134 use namespace::autoclean;
  1         1  
  1         11  
49              
50 1     1   90 use GenOO::RegionCollection::Type::DoubleHashArray;
  1         2  
  1         58  
51 1     1   416 use GenOO::Data::File::SAM;
  1         2  
  1         258  
52              
53             has 'file' => (is => 'Str', is => 'ro');
54             has 'filter_code' => (isa => 'CodeRef', is => 'ro', default => sub{sub{return 1;}} );
55              
56             with 'GenOO::RegionCollection::Factory::Requires';
57              
58             #######################################################################
59             ######################## Interface Methods ########################
60             #######################################################################
61             sub read_collection {
62 1     1 0 1230 my ($self) = @_;
63            
64 1         52 my $collection = GenOO::RegionCollection::Type::DoubleHashArray->new;
65            
66 1         32 my $parser = GenOO::Data::File::SAM->new(
67             file => $self->file,
68             );
69 1         10 while (my $record = $parser->next_record) {
70 978 100 66     2133 if (($record->is_mapped) and ($self->filter_code->($record))){
71 645         1689 $collection->add_record($record);
72             }
73             }
74            
75 1         31 return $collection;
76             }
77              
78             1;