CLIPSeqTools/PlotApp/size_distribution.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 58 CC 4 SCAR 21.5
CC
4
Cov
0%
run
20.0
validate_args
2.0
run_R
2.0
CRAP 8.5
1 =head1 NAME
2  
3 CLIPSeqTools::PlotApp::size_distribution - Create plots for script
4 size_distribution.
5  
6 =head1 SYNOPSIS
7  
8 clipseqtools-plot size_distribution [options/parameters]
9  
10 =head1 DESCRIPTION
11  
12 Create plots for script size_distribution.
13  
14 =head1 OPTIONS
15  
16 Input.
17 --file <Str> input file.
18  
19 Output
20 --o_prefix <Str> output path prefix. Script will create and add
21 extension to path. [Default: ./]
22  
23 -v --verbose print progress lines and extra information.
24 -h -? --usage --help print help message
25  
26 =cut
27  
28 package CLIPSeqTools::PlotApp::size_distribution;
29 $CLIPSeqTools::PlotApp::size_distribution::VERSION = '1.0.0';
30  
31 # Make it an app command
32 use MooseX::App::Command;
33 extends 'CLIPSeqTools::PlotApp';
34  
35  
36 #######################################################################
37 ####################### Load External modules #####################
38 #######################################################################
39 use Modern::Perl;
40 use autodie;
41 use namespace::autoclean;
42 use Statistics::R;
43  
44  
45 #######################################################################
46 ####################### Command line options ######################
47 #######################################################################
48 option 'file' => (
49 is => 'rw',
50 isa => 'Str',
51 required => 1,
52 documentation => 'file with long gaps distribution.',
53 );
54  
55  
56 #######################################################################
57 ########################## Consume Roles ##########################
58 #######################################################################
59 with
60 "CLIPSeqTools::Role::Option::OutputPrefix" => {
61 -alias => { validate_args => '_validate_args_for_output_prefix' },
62 -excludes => 'validate_args',
63 };
64  
65  
66 #######################################################################
67 ######################## Interface Methods ########################
68 #######################################################################
69 sub validate_args {
70 my ($self) = @_;
71  
72 $self->_validate_args_for_output_prefix;
73 }
74  
75 sub run {
76 my ($self) = @_;
77  
78 warn "Validating arguments\n" if $self->verbose;
79 $self->validate_args();
80  
81 warn "Creating output path\n" if $self->verbose;
82 $self->make_path_for_output_prefix();
83  
84 warn "Creating plots with R\n" if $self->verbose;
85 $self->run_R;
86 }
87  
88 sub run_R {
89 my ($self) = @_;
90  
91 my $figfile = $self->o_prefix . 'size_distribution.pdf';
92  
93 # Start R
94 my $R = Statistics::R->new();
95  
96 # Pass arguments to R
97 $R->set('ifile', $self->file);
98 $R->set('figfile', $figfile);
99  
100 # Disable scientific notation
101 $R->run(q{options(scipen=999)});
102  
103 # Read table with data
104 $R->run(q{idata = read.delim(ifile)});
105  
106 # Do plots
107 $R->run(q{pdf(figfile, width=14)});
108 $R->run(q{par(mfrow = c(1, 2), cex.lab=1.2, cex.axis=1.2, cex.main=1.2,
109 lwd=1.2, oma=c(0, 0, 2, 0), mar=c(5.1, 5.1, 4.1, 2.1))});
110 $R->run(q{plot(idata$size, idata$count, type="b", pch=19, xlab="Size",
111 ylab="Number of reads", main="Number of reads with given size")});
112 $R->run(q{plot(idata$size, (idata$count / sum(idata$count)) * 100,
113 type="b", pch=19, xlab="Size", ylab="Percent of reads (%)",
114 main="Percent of reads with given size")});
115 $R->run(q{graphics.off()});
116  
117 # Close R
118 $R->stop();
119 }
120  
121  
122 1;