CLIPSeqTools/Role/Option/ReferenceLibrary.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 58 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 = '1.0.0';
47  
48 #######################################################################
49 ####################### Load External modules #####################
50 #######################################################################
51 use Modern::Perl;
52 use MooseX::App::Role;
53 use MooseX::Getopt;
54  
55  
56 #######################################################################
57 ######################## Load GenOO modules #######################
58 #######################################################################
59 use GenOO::RegionCollection::Factory;
60  
61  
62 #######################################################################
63 ####################### Command line options ######################
64 #######################################################################
65 option 'r_driver' => (
66 is => 'rw',
67 isa => 'Str',
68 default => 'SQLite',
69 documentation => 'driver for database connection (eg. mysql, SQLite).',
70 cmd_tags => ['Reference library'],
71 );
72  
73 option 'r_database' => (
74 is => 'rw',
75 isa => 'Str',
76 required => 1,
77 documentation => 'database name or path.',
78 cmd_tags => ['Reference library'],
79 );
80  
81 option 'r_table' => (
82 is => 'rw',
83 isa => 'Str',
84 default => 'sample',
85 documentation => 'database table.',
86 cmd_tags => ['Reference library'],
87 );
88  
89 option 'r_host' => (
90 is => 'rw',
91 isa => 'Str',
92 documentation => 'hostname for database connection.',
93 cmd_tags => ['Reference library'],
94 );
95  
96 option 'r_user' => (
97 is => 'rw',
98 isa => 'Str',
99 documentation => 'username for database connection.',
100 cmd_tags => ['Reference library'],
101 );
102  
103 option 'r_password' => (
104 is => 'rw',
105 isa => 'Str',
106 documentation => 'password for database connection.',
107 cmd_tags => ['Reference library'],
108 );
109  
110 option 'r_filter' => (
111 is => 'rw',
112 isa => 'ArrayRef',
113 default => sub { [] },
114 documentation => 'filter reference library. Option can be given '.
115 'multiple times. Syntax: column_name="pattern" '.
116 'e.g. --r_filter deletion="def" '.
117 '--r_filter rmsk="undef" '.
118 '--r_filter query_length=">31" to keep reads with '.
119 'deletions AND not repeats AND longer than 31. '.
120 'Supports: >, >=, <, <=, =, !=, def, undef.',
121 cmd_tags => ['Reference library'],
122 );
123  
124  
125 #######################################################################
126 ###################### Interface Attributes #######################
127 #######################################################################
128 has 'r_reads_collection' => (
129 traits => [ 'NoGetopt' ],
130 is => 'rw',
131 builder => '_build_reference_collection',
132 lazy => 1,
133 );
134  
135 has 'r_records_class' => (
136 is => 'rw',
137 isa => 'Str',
138 default => 'GenOO::Data::DB::DBIC::Species::Schema'.
139 '::SampleResultBase::v3',
140 documentation => 'type of records stored in database.',
141 cmd_tags => ['Reference library'],
142 );
143  
144  
145 #######################################################################
146 ######################## Interface Methods ########################
147 #######################################################################
148 sub validate_args {}
149  
150  
151 #######################################################################
152 ######################### Private Methods #########################
153 #######################################################################
154 sub _build_reference_collection {
155 my ($self) = @_;
156  
157 my $collection = $self->_build_reference_collection_from_database;
158 _apply_simple_filters_on_reference_collection($self->filter, $collection);
159 return $collection;
160 }
161  
162 sub _build_reference_collection_from_database {
163 my ($self) = @_;
164  
165 return GenOO::RegionCollection::Factory->create('DBIC', {
166 driver => $self->r_driver,
167 host => $self->r_host,
168 database => $self->r_database,
169 user => $self->r_user,
170 password => $self->r_password,
171 table => $self->r_table,
172 records_class => $self->r_records_class,
173 })->read_collection;
174 }
175  
176  
177 #######################################################################
178 ######################## Private Functions ########################
179 #######################################################################
180 sub _apply_simple_filters_on_reference_collection {
181 my ($filters, $collection) = @_;
182  
183 my @elements = @{$filters};
184 foreach my $element (@elements) {
185 $element =~ /^(.+?)=(.+?)$/;
186 my $col_name = $1;
187 my $filter = $2;
188 $collection->simple_filter($col_name, $filter);
189 }
190 }
191  
192  
193 1;