CLIPSeqTools/App/size_distribution.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 81 CC 10 SCAR 42.4
CC
10
Cov
0%
run
110.0
validate_args
2.0
BEGIN
2.0
CRAP 69.5
1 =head1 NAME
2  
3 CLIPSeqTools::App::size_distribution - Measure size distribution for reads.
4  
5 =head1 SYNOPSIS
6  
7 clipseqtools size_distribution [options/parameters]
8  
9 =head1 DESCRIPTION
10  
11 Measure size distribution of aligned reads.
12  
13 =head1 OPTIONS
14  
15 Input options for library.
16 --driver <Str> driver for database connection (eg. mysql,
17 SQLite).
18 --database <Str> database name or path to database file for file
19 based databases (eg. SQLite).
20 --table <Str> database table.
21 --host <Str> hostname for database connection.
22 --user <Str> username for database connection.
23 --password <Str> password for database connection.
24 --records_class <Str> type of records stored in database.
25 --filter <Filter> filter library. May be used multiple times.
26 Syntax: column_name="pattern"
27 e.g. keep reads with deletions AND not repeat
28 masked AND longer than 31
29 --filter deletion="def"
30 --filter rmsk="undef" .
31 --filter query_length=">31".
32 Operators: >, >=, <, <=, =, !=, def, undef
33  
34 Output
35 --o_prefix <Str> output path prefix. Script will create and add
36 extension to path. [Default: ./]
37  
38 Other options.
39 --plot call plotting script to create plots.
40 -v --verbose print progress lines and extra information.
41 -h -? --usage --help print help message
42  
43 =cut
44  
45 package CLIPSeqTools::App::size_distribution;
46 $CLIPSeqTools::App::size_distribution::VERSION = '1.0.0';
47  
48 # Make it an app command
49 use MooseX::App::Command;
50 extends 'CLIPSeqTools::App';
51  
52  
53 #######################################################################
54 ####################### Load External modules #####################
55 #######################################################################
56 use Modern::Perl;
57 use autodie;
58 use namespace::autoclean;
59 use List::Util qw(min max);
60  
61  
62 #######################################################################
63 ########################## Consume Roles ##########################
64 #######################################################################
65 with
66 "CLIPSeqTools::Role::Option::Library" => {
67 -alias => { validate_args => '_validate_args_for_library' },
68 -excludes => 'validate_args',
69 },
70 "CLIPSeqTools::Role::Option::Plot" => {
71 -alias => { validate_args => '_validate_args_for_plot' },
72 -excludes => 'validate_args',
73 },
74 "CLIPSeqTools::Role::Option::OutputPrefix" => {
75 -alias => { validate_args => '_validate_args_for_output_prefix' },
76 -excludes => 'validate_args',
77 };
78  
79
80 #######################################################################
81 ######################## Interface Methods ########################
82 #######################################################################
83 sub validate_args {
84 my ($self) = @_;
85
86 $self->_validate_args_for_library;
87 $self->_validate_args_for_plot;
88 $self->_validate_args_for_output_prefix;
89 }
90  
91 sub run {
92 my ($self) = @_;
93
94 warn "Starting analysis: size_distribution\n";
95
96 warn "Validating arguments\n" if $self->verbose;
97 $self->validate_args();
98
99 warn "Creating reads collection\n" if $self->verbose;
100 my $reads_collection = $self->reads_collection;
101 $reads_collection->schema->storage->debug(1) if $self->verbose > 1;
102
103 warn "Measuring aligned read sizes\n" if $self->verbose;
104 my %size_count;
105 $reads_collection->foreach_record_do( sub {
106 my ($rec) = @_;
107
108 return 0 if $rec->cigar =~ /N/; # throw away reads with huge gaps (introns)
109
110 $size_count{$rec->length} += $rec->copy_number;
111
112 return 0;
113 });
114 my $min_length = min(keys %size_count);
115 my $max_length = max(keys %size_count);
116  
117 warn "Creating output path\n" if $self->verbose;
118 $self->make_path_for_output_prefix();
119
120 warn "Printing results\n" if $self->verbose;
121 open (my $OUT1, '>', $self->o_prefix.'size_distribution.tab');
122 say $OUT1 join("\t", 'size', 'count');
123 say $OUT1 join("\t", $_, $size_count{$_} || 0) for ($min_length..$max_length);
124 close $OUT1;
125
126 if ($self->plot) {
127 warn "Creating plot\n" if $self->verbose;
128 CLIPSeqTools::PlotApp->initialize_command_class('CLIPSeqTools::PlotApp::size_distribution',
129 file => $self->o_prefix.'size_distribution.tab',
130 o_prefix => $self->o_prefix
131 )->run();
132 }
133 }
134  
135 1;