CLIPSeqTools/Role/Option/ReferenceLibrary.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 54 CC 1 SCAR 6.9
CC
1
Cov
0%
validate_args
2.0
_build_reference_collection
2.0
_build_reference_collection_from_database
2.0
CRAP 2.0
1 =head1 NAME
2  
3 CLIPSeqTools::Role::Option::ReferenceLibrary - Role to enable reading
4 reference libraries with reads from the command line
5  
6 =head1 SYNOPSIS
7  
8 Role to enable reading reference libraries with reads from the command line
9  
10 Defines options.
11 -r_driver <Str> driver for database connection for reference
12 library(eg. mysql, SQLite).
13 -r_database <Str> database name or path for reference library
14 (eg. SQLite).
15 -r_table <Str> database table for reference library.
16 -r_host <Str> hostname for database connection for reference
17 library.
18 -r_user <Str> username for database connection for reference
19 library.
20 -r_password <Str> password for database connection for reference
21 library.
22 -r_records_class <Str> type of records stored in database for
23 reference library (Default: GenOO::Data::DB::
24 DBIC::Species::Schema::SampleResultBase::v3).
25 -r_filter <Filter> filter library. Option can be given multiple
26 times.
27 Syntax: column_name="pattern"
28 e.g. -filter deletion="def"
29 -filter rmsk="undef"
30 to keep reads with deletions and not repeat
31 masked.
32 e.g. -filter query_length=">31"
33 -filter query_length="<=50"
34 to keep reads longer than 31 and shorter or
35 equal to 50.
36 Supports: >, >=, <, <=, =, !=, def, undef.
37  
38 Provides attributes.
39 r_reads_collection reads collection that is read from the specified
40 source.
41  
42 =cut
43  
44  
45 package CLIPSeqTools::Role::Option::ReferenceLibrary;
46 $CLIPSeqTools::Role::Option::ReferenceLibrary::VERSION = '0.1.1';
47  
48 #######################################################################
49 ####################### Load External modules #####################
50 #######################################################################
51 use Modern::Perl;
52 use MooseX::App::Role;
53  
54  
55 #######################################################################
56 ######################## Load GenOO modules #######################
57 #######################################################################
58 use GenOO::RegionCollection::Factory;
59  
60  
61 #######################################################################
62 ####################### Command line options ######################
63 #######################################################################
64 option 'r_driver' => (
65 is => 'rw',
66 isa => 'Str',
67 default => 'SQLite',
68 documentation => 'driver for database connection (eg. mysql, SQLite).',
69 cmd_tags => ['Reference library'],
70 );
71  
72 option 'r_database' => (
73 is => 'rw',
74 isa => 'Str',
75 required => 1,
76 documentation => 'database name or path.',
77 cmd_tags => ['Reference library'],
78 );
79  
80 option 'r_table' => (
81 is => 'rw',
82 isa => 'Str',
83 default => 'sample',
84 documentation => 'database table.',
85 cmd_tags => ['Reference library'],
86 );
87  
88 option 'r_host' => (
89 is => 'rw',
90 isa => 'Str',
91 documentation => 'hostname for database connection.',
92 cmd_tags => ['Reference library'],
93 );
94  
95 option 'r_user' => (
96 is => 'rw',
97 isa => 'Str',
98 documentation => 'username for database connection.',
99 cmd_tags => ['Reference library'],
100 );
101  
102 option 'r_password' => (
103 is => 'rw',
104 isa => 'Str',
105 documentation => 'password for database connection.',
106 cmd_tags => ['Reference library'],
107 );
108  
109 option 'r_filter' => (
110 is => 'rw',
111 isa => 'ArrayRef',
112 default => sub { [] },
113 documentation => 'filter reference library. Option can be given '.
114 'multiple times. Syntax: column_name="pattern" '.
115 'e.g. --r_filter deletion="def" '.
116 '--r_filter rmsk="undef" '.
117 '--r_filter query_length=">31" to keep reads with '.
118 'deletions AND not repeats AND longer than 31. '.
119 'Supports: >, >=, <, <=, =, !=, def, undef.',
120 cmd_tags => ['Reference library'],
121 );
122  
123  
124 #######################################################################
125 ###################### Interface Attributes #######################
126 #######################################################################
127 has 'r_reads_collection' => (
128 traits => [ 'NoGetopt' ],
129 is => 'rw',
130 builder => '_build_reference_collection',
131 lazy => 1,
132 );
133  
134 has 'r_records_class' => (
135 is => 'rw',
136 isa => 'Str',
137 default => 'GenOO::Data::DB::DBIC::Species::Schema'.
138 '::SampleResultBase::v3',
139 documentation => 'type of records stored in database.',
140 cmd_tags => ['Reference library'],
141 );
142  
143  
144 #######################################################################
145 ######################## Interface Methods ########################
146 #######################################################################
147 sub validate_args {}
148  
149  
150 #######################################################################
151 ######################### Private Methods #########################
152 #######################################################################
153 sub _build_reference_collection {
154 my ($self) = @_;
155  
156 my $collection = $self->_build_reference_collection_from_database;
157 _apply_simple_filters_on_reference_collection($self->filter, $collection);
158 return $collection;
159 }
160  
161 sub _build_reference_collection_from_database {
162 my ($self) = @_;
163  
164 return GenOO::RegionCollection::Factory->create('DBIC', {
165 driver => $self->r_driver,
166 host => $self->r_host,
167 database => $self->r_database,
168 user => $self->r_user,
169 password => $self->r_password,
170 table => $self->r_table,
171 records_class => $self->r_records_class,
172 })->read_collection;
173 }
174  
175  
176 #######################################################################
177 ######################## Private Functions ########################
178 #######################################################################
179 sub _apply_simple_filters_on_reference_collection {
180 my ($filters, $collection) = @_;
181  
182 my @elements = @{$filters};
183 foreach my $element (@elements) {
184 $element =~ /^(.+?)=(.+?)$/;
185 my $col_name = $1;
186 my $filter = $2;
187 $collection->simple_filter($col_name, $filter);
188 }
189 }
190  
191  
192 1;