blib/lib/PrimerMap.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
↑ Summary
1 #
2 # module for PrimerMap
3 #
4 # based on the Bio::SeqFeature::Generic modules
5 # by Ewan Birney <birney@ebi.ac.uk>
6 # and the Bio::Graphics modules
7 # by Lincoln Stein <lstein@cshl.org>
8 # Copyright Damien O'Halloran
9 #
10 # You may distribute this module under the same terms as perl itself
11 # History
12 # October 24, 2016
13 # POD documentation - main docs before the code
14
15 =head1 NAME
16
17 PrimerMap - generates a primer sequence graphical map
18
19 =head1 SYNOPSIS
20
21 use PrimerMap;
22 use Data::Dumper;
23
24 my $start = "12,24,28,32,824,888,902";
25 my $end = "40,59,48,50,801,848,880";
26 my $output = "myGene.png";
27
28 # can also collect primer coordinates from a text file
29 # my $inFile = "primermap_file.txt";
30 # $tmp->read_file($inFile);
31
32 my $tmp = PrimerMap->new();
33 $tmp->load_map(
34 primer_start => $start,
35 primer_end => $end,
36 seq_length => "1200",
37 gene_name => "myGene",
38 out_file => $output || "output.png"
39 );
40
41 # take a look at the object
42 print Dumper($tmp);
43
44 # print the primer map
45 $tmp->primer_map();
46 print "\n\n";
47
48 # getters and setters can be used as follows:
49 my $set_start = $tmp->set_start("22,24,2226");
50 print $set_start. "\n\n";
51
52 my $get_start = $tmp->get_start();
53 print $get_start. "\n\n";
54
55 my $set_end = $tmp->set_end("52,64,2202");
56 print $set_end. "\n\n";
57
58 my $get_end = $tmp->get_end();
59 print $get_end. "\n\n";
60
61 my $set_length = $tmp->set_length(2500);
62 print $set_length. "\n\n";
63
64 my $get_length = $tmp->get_length();
65 print $get_length. "\n\n";
66
67 my $set_id = $tmp->set_ID("myNewGeneName");
68 print $set_id. "\n\n";
69
70 my $get_id = $tmp->get_ID();
71 print $get_id. "\n\n";
72
73 my $set_file = $tmp->set_outfile("myOutPutFile.png");
74 print $set_file. "\n\n";
75
76 my $get_file = $tmp->get_outfile();
77 print $get_file. "\n\n";
78
79 # see the newly set object
80 print Dumper($tmp);
81
82 # see the newly set primer map
83 $tmp->primer_map();
84 print "\n\n";
85
86 =head1 DESCRIPTION
87
88 This object extends the Bio::SeqFeature::Generic class to provide an object for Bio::Graphics. Uses primer starting and ending coordinates (base pairs) to generate a primer map relative to a base sequence.
89
90 =head1 FEEDBACK
91
92 damienoh@gwu.edu
93
94 =head2 Mailing Lists
95
96 User feedback is an integral part of the evolution of this module. Send your comments and suggestions preferably to one of the mailing lists. Your participation is much appreciated.
97
98 =head2 Support
99
100 Please direct usage questions or support issues to:
101 <damienoh@gwu.edu>
102 Please include a thorough description of the problem with code and data examples if at all possible.
103
104 =head2 Reporting Bugs
105
106 Report bugs to the GitHub bug tracking system to help keep track of the bugs and their resolution. Bug reports can be submitted via the GitHub page:
107
108 https://github.com/dohalloran/Bio-SeqFeature-Generic-Ext-PrimerMap/issues
109
110 =head1 AUTHORS - Damien OHalloran
111
112 Email: damienoh@gwu.edu
113
114 =head1 APPENDIX
115
116 The rest of the documentation details each of the object
117 methods.
118
119 =cut
120
121 # Let the code begin...
122
123 package PrimerMap;
124
125 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
126
127 0 ▶use Bio::Graphics;
Subroutine BEGIN: called CC=1 SCAR=2.6
128
129 # inherits from the Bio::SeqFeature::Generic class
130 use parent qw/Bio::SeqFeature::Generic/;
131
132 our $VERSION = '1.3';
133 ##################################
134
135 =head2 read_file()
136
137 Title : read_file()
138 Usage : my $tmp->read_file($inFile);
139 Function: get data for $self hash from a file
140 Returns : Populates the $self->{start} and $self->{end} properties
141 Args : $filename, a texfile that contains input data of primer
142 starting and ending features as base pairs e.g.:
143 12,24,28,32,824,888,902
144 40,59,48,50,801,848,880
145 note: the starting positions is the first line
146
147 =cut
148
149 ##################################
150
151 sub read_file {
152 my ( $self, $filename ) = @_;
153 my @tempArr;
154 my $fh;
155 open $fh, '<', $filename or $self->throw("Cannot open $filename: $!");
156 while (<$fh>) {
157 chomp;
158 push @tempArr, $_;
159 }
160 close($fh);
161 $self->{start} = $tempArr[0];
162 $self->{end} = $tempArr[1];
163 }
164
165 ##################################
166
167 =head2 load_map()
168
169 Title : load_map()
170 Usage : my $tmp->load_map(
171 primer_start => $start, #don't include if loading file
172 primer_end => $end, #don't include if loading file
173 seq_length => "1200",
174 gene_name => "myGene",
175 out_file => $output || "output.png"
176 );
177 Function: Populates the user data into $self hash
178 Returns : nothing returned
179 Args :
180 -primer_start, a csv string of starting base pairs for primers
181 -primer_end, a csv string of final base pairs for primers
182 -seq_length, the length in base pairs of the gene sequence
183 -gene_name, the ID to give to the gene (optional)
184 -out_file, name of the resulting graphical output file (optional)
185
186 =cut
187
188 ##################################
189
190 sub load_map {
191 my ( $self, %arg ) = @_;
192 if ( defined $arg{primer_start} ) {
193 $self->{start} = $arg{primer_start};
194 }
195 if ( defined $arg{primer_end} ) {
196 $self->{end} = $arg{primer_end};
197 }
198 if ( defined $arg{seq_length} ) {
199 $self->{seq_len} = $arg{seq_length};
200 }
201 if ( defined $arg{gene_name} ) {
202 $self->{seq_id} = $arg{gene_name};
203 }
204 if ( defined $arg{out_file} ) {
205 $self->{out_file} = $arg{out_file};
206 }
207 }
208
209 ###################################
210
211 =head2 get_start()
212
213 Title : get_start()
214 Usage : my $get_start = $tmp->get_start();
215 Function: Retrieves the primer starting features
216 Returns : A string containing primer start features
217 Args : none
218
219 =cut
220
221 ##################################
222
223 sub get_start {
224 my ($self) = @_;
225 return $self->{start};
226 }
227
228 ###################################
229
230 =head2 set_start()
231
232 Title : set_start()
233 Usage : my $set_start = $tmp->set_start("22,24,2226");
234 Function: Populates the $self->{start} property
235 Returns : $self->{start}
236 Args : a csv string of starting base pairs for primers
237
238 =cut
239
240 ##################################
241
242 sub set_start {
243 my ( $self, $value ) = @_;
244 $self->{start} = $value;
245 return $self->{start};
246 }
247
248 ###################################
249
250 =head2 get_end()
251
252 Title : get_end()
253 Usage : my $get_end = $tmp->get_end();
254 Function: Retrieves the primer ending features
255 Returns : A string containing primer end features
256 Args : none
257
258 =cut
259
260 ##################################
261
262 sub get_end {
263 my ($self) = @_;
264 return $self->{end};
265 }
266
267 ###################################
268
269 =head2 set_end()
270
271 Title : set_end()
272 Usage : my $set_end = $tmp->set_end("52,64,2202");
273 Function: Populates the $self->{end} property
274 Returns : $self->{end}
275 Args : a csv string of ending base pairs for primers
276
277 =cut
278
279 ##################################
280
281 sub set_end {
282 my ( $self, $value ) = @_;
283 $self->{end} = $value;
284 return $self->{end};
285 }
286
287 ###################################
288
289 =head2 get_ID()
290
291 Title : get_ID()
292 Usage : my $get_ID = $tmp->get_ID();
293 Function: Retrieves the gene name
294 Returns : A string containing gene name
295 Args : none
296
297 =cut
298
299 ##################################
300
301 sub get_ID {
302 my ($self) = @_;
303 return $self->{seq_id};
304 }
305
306 ###################################
307
308 =head2 set_ID()
309
310 Title : set_ID()
311 Usage : my $set_id = $tmp->set_ID("myNewGeneName");
312 Function: Populates the $self->{seq_id} property
313 Returns : $self->{seq_id}
314 Args : the ID to give to the gene
315
316 =cut
317
318 ##################################
319
320 sub set_ID {
321 my ( $self, $value ) = @_;
322 $self->{seq_id} = $value;
323 return $self->{seq_id};
324 }
325
326 ###################################
327
328 =head2 get_outfile()
329
330 Title : get_outfile()
331 Usage : my $get_outfile = $tmp->get_outfile();
332 Function: Retrieves the output filename
333 Returns : A string containing filename
334 Args : none
335
336 =cut
337
338 ##################################
339
340 sub get_outfile {
341 my ($self) = @_;
342 return $self->{out_file};
343 }
344
345 ###################################
346
347 =head2 set_outfile()
348
349 Title : set_outfile()
350 Usage : my $set_output = $tmp->set_outfile("myOutPutFile.txt");
351 Function: Populates the $self->{out_file} property
352 Returns : $self->{out_file}
353 Args : name of the resulting graphical output file
354
355 =cut
356
357 ##################################
358
359 sub set_outfile {
360 my ( $self, $value ) = @_;
361 $self->{out_file} = $value;
362 return $self->{out_file};
363 }
364
365 ###################################
366
367 =head2 get_length()
368
369 Title : get_length()
370 Usage : my $get_length = $tmp->get_length();
371 Function: Retrieves the sequence length in base pairs
372 Returns : Gene length
373 Args : none
374
375 =cut
376
377 ###################################
378
379 sub get_length {
380 my ($self) = @_;
381 return $self->{seq_len};
382 }
383
384 ###################################
385
386 =head2 set_length()
387
388 Title : set_length()
389 Usage : my $set_length = $tmp->set_length(2500);
390 Function: Populates the $self->{seq_len} property
391 Returns : $self->{seq_len}
392 Args : length of gene
393
394 =cut
395
396 ###################################
397
398 sub set_length {
399 my ( $self, $value ) = @_;
400 $self->{seq_len} = $value;
401 return $self->{seq_len};
402 }
403
404 ###################################
405
406 =head2 primer_map()
407
408 Title : primer_map()
409 Usage : my $tmp->primer_map();
410 Function: Populate the panels for Bio::Graphics::Panel and Bio::SeqFeature::Generic
411 Returns : A graphical files containing primer sequence map
412 Args : all collected from the Bio::SeqFeature::Generic constructor
413
414 =cut
415
416 ##################################
417
418 sub primer_map {
419 my ($self) = @_;
420 my $orientation;
421 my $out_dir = 'Output';
422 if ( !-e $out_dir ) {
423 print "Output directory ($out_dir) does not exist! Creating...\n";
424 mkdir($out_dir) or $self->throw("Failed to create the output directory ($out_dir): $!\n");
425 print "Done\n\n";
426 }
427 my $outputfile = "./".$out_dir."/".$self->{out_file};
428 my $out;
429
430 open $out, '>', $outputfile or $self->throw("Cannot open $outputfile: $!");
431
432 my $panel = Bio::Graphics::Panel->new(
433 -length => $self->{seq_len},
434 -width => 800,
435 -pad_left => 30,
436 -pad_right => 30,
437 -pad_top => 20,
438 -pad_bottom => 20,
439 );
440
441 my $full_length = Bio::SeqFeature::Generic->new(
442 -start => 1,
443 -end => $self->{seq_len},
444 -display_name => $self->{seq_id},
445 );
446
447 $panel->add_track(
448 $full_length,
449 -glyph => 'arrow',
450 -tick => 2,
451 -fgcolor => 'black',
452 -double => 1,
453 -label => 1,
454 -strand_arrow => 1,
455 );
456
457 my $track = $panel->add_track(
458 -glyph => 'transcript2',
459 -label => 1,
460 -strand_arrow => 1,
461 -bgcolor => 'blue',
462 -bump => +1,
463 -height => 12,
464 );
465
466 my @start_position = split /,/, $self->{start};
467
468 my @end_position = split /,/, $self->{end};
469
470 for my $i ( 0 .. $#start_position ) {
471
472 if ( $start_position[$i] - $end_position[$i] < 1 ) {
473 $orientation = +1;
474 }
475 else {
476 $orientation = -1;
477 }
478 my $feature = Bio::SeqFeature::Generic->new(
479 -display_name => "primer: " . $start_position[$i],
480 -start => $start_position[$i],
481 -strand => $orientation,
482 -end => $end_position[$i]
483 );
484 $track->add_feature($feature);
485 }
486 binmode $out;
487 print $out $panel->png;
488 close($out);
489 }
490
491 ###################################
492
493 =head1 LICENSE AND COPYRIGHT
494
495 Copyright (C) 2016 Damien M. O'Halloran
496 GNU GENERAL PUBLIC LICENSE
497 Version 2, June 1991
498
499 =cut
500
501
502 1;
↑ Summary