File Coverage

blib/lib/BioX/SeqUtils/Promoter/SaveTypes/RImage.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package BioX::SeqUtils::Promoter::SaveTypes::RImage;
2             ####################################################################
3             # Charles Stephen Embry #
4             # MidSouth Bioinformatics Center #
5             # University of Arkansas Little Rock #
6             ####################################################################
7 1     1   2068 use base qw(BioX::SeqUtils::Promoter::SaveTypes::Base);
  1         3  
  1         140  
8             use Class::Std;
9             use Class::Std::Utils;
10             use POSIX qw(ceil);
11             use warnings;
12             use strict;
13             use Carp;
14             use BioX::SeqUtils::Promoter::Sequences;
15             use BioX::SeqUtils::Promoter::Sequence;
16             use BioX::SeqUtils::Promoter::Alignment;
17             use BioX::SeqUtils::Promoter::Annotations::Consensus;
18             use BioX::SeqUtils::Promoter::Annotations;
19              
20             use version; our $VERSION = qv('0.1.1');
21              
22             {
23             my %rcode_of :ATTR( :get :set :default<''> :init_arg );
24             my %width_of :ATTR( :get :set :default<''> :init_arg );
25             my %height_of :ATTR( :get :set :default<''> :init_arg );
26            
27             sub BUILD {
28             my ($self, $ident, $arg_ref) = @_;
29             return;
30             }
31              
32             sub START {
33             my ($self, $ident, $arg_ref) = @_;
34             #every pdf document will have a max of 68 character perline and 58 lines per page
35             my $r_code .= 'x=c(1,68)' . "\n";
36             $r_code .= 'y=c(1,58)' . "\n";
37             #$r_code .= 'y=c(1,25)' . "\n";
38             $self->set_rcode($r_code);
39             return;
40             }
41              
42              
43             sub save {
44             my ($self, $arg_ref) = @_;
45             #sequeces object will the parameter
46             my $sequences = defined $arg_ref->{sequences} ? $arg_ref->{sequences} : '';
47            
48             my $x_max = 60;
49             #my $y_max = 25;
50             my $y_max = 58;
51             my $image_count = 0;
52             print "Save $sequences\n";
53              
54             my @sequences = $sequences->get_objects();
55             print "@sequences\n";
56            
57             #my $test_label = $sequences[0]->get_label();
58             #my @sequences = values %$sequences;
59             my $r_code = $self->get_rcode();
60             my $seqcount = 0;
61             my $test_label = $sequences[0]->get_label();
62             #my $test_label = get_label($sequence[0]);
63            
64             #seen how long sequences are
65             my $seqlength = $self->length({ string => $sequences[0]->get_sequence( label => $test_label) });
66            
67             my $max_block = ceil($seqlength/$x_max);
68            
69             #lots of prints and test for debugging during creation of module
70             #print "@sequences\n";
71             #print "seqlength is $seqlength\n";
72             #my $test = ceil($test_value/$x_max);
73             #print "my $max_block = ceil($seqlength/$x_max)\n";
74             #my $test_value = 18;
75             #print "my $test = ceil($test_value/$x_max)\n";
76            
77            
78             my $number_seq = 0;
79             foreach my $seqobjcount (@sequences) {
80             #counts number of sequence objects in the sequences object
81             $number_seq++;
82             }
83              
84             my $slide_count = 0;
85             for (my $k = 0; $k < $max_block; $k++){
86             $image_count = $k;
87             print "block $k\n";
88             $r_code .= 'pdf(file = "/home/stephen/BioCapstone/BioX-SeqUtils-Promoter/data/block' . $k . '.pdf",onefile=TRUE,width=8,height=7,pointsize=8)' . "\n";
89             $r_code .= 'plot(x,y,adj=0,ann=FALSE,bty="n",mai=c(0,0,0,0),oma=c(0,0,0,0),pin=c(7,10),xaxt="n",yaxt="n",xpd=NA,col=c("000000"))' . "\n";
90             foreach my $seqobj (@sequences) {
91             my $color_list = $seqobj->get_color_list();
92             my $base_list = $seqobj->get_base_list();
93             my $label = $seqobj->get_label();
94             #keeps a label and its data on the same line on each document
95             my $ucount = $y_max - $seqcount + $slide_count;
96             $seqcount++;
97             $r_code .= 'text(3,' . $ucount . ',"' . $label . '",adj=1,col=c("black"))' . "\n";
98             #for ( my $i = 5; $i <= $x_max + 4; $i++ ) {
99             for ( my $i = 9; $i <= $x_max + 8; $i++ ) {
100             my $index = $i - 9 + ($k*$x_max);
101             if($index <= $seqlength){
102             my $letter = $base_list->[$index] ? $base_list->[$index] : '-';
103             #print "$index\n";
104             my $color = $color_list->[$index] ? $color_list->[$index] : 'black';
105             # this uses base_list and color_list from sequence objects to give every letter in sequence data a color in the PDF document
106             $r_code .= 'text(' . $i . ',' . $ucount . ',"' . $letter . '",adj=0,col=c("' . $color . '"))' . "\n";
107             #print 'text(' . $i . ',' . $seqcount . ',"' . $letter . '",adj=0,col=c("' . $color . '"))' . "\n";
108             }
109              
110             }
111              
112            
113             }
114             $slide_count = $slide_count + $number_seq;
115             #every pdf device in turned off before each new pdf is made. Gets around the pdf device limit in R
116             $r_code .= 'dev.off()' . "\n";
117             }
118              
119             #$r_code .= 'dev.off()' . "\n";
120             $self->set_rcode($r_code);
121             open (MYFILE, '>r_code.r');
122             print MYFILE $r_code;
123             close (MYFILE);
124             #runs the created R script in command line
125             `R CMD BATCH r_code.r r_code.out`;
126             for (my $j = 0; $j < $image_count + 1; $j++){
127             #creates png files for website
128             my $c_image = 'convert /home/stephen/BioCapstone/BioX-SeqUtils-Promoter/data/block' . $j . '.pdf' . ' /home/stephen/BioCapstone/BioX-SeqUtils-Promoter/data/block' . $j . '.png';
129             `$c_image`;
130             }
131              
132             }
133              
134             sub print { my ($self) = @_; print $self->get_rcode(); }
135             }
136              
137             1; # Magic true value required at end of module
138             __END__