CLIPSeqTools/App/reads_long_gaps_size_distribution.pm untested

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