blib/script/rnaseq_peakfinder.pl untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod n/a totaltotal 0.0% 0 / 94 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 # -*-CPerl-*-
3 # Last changed Time-stamp: <2016-10-11 15:55:03 mtw>
4 #
5 # Find peaks/enriched regions of certain size in RNA-seq data
6 #
7 # usage: rnaseq_peakfinder --bgpos pos.bg --bgneg neg.pg
8 #
9 # ***********************************************************************
10 # * Copyright notice
11 # *
12 # * Copyright 2015 Michael T. Wolfinger <michael@wolfinger.eu>
13 # * All rights reserved
14 # *
15 # * This program is free software: you can redistribute it and/or modify
16 # * it under the terms of the GNU General Public License as published by
17 # * the Free Software Foundation, either version 3 of the License, or
18 # * (at your option) any later version.
19 # *
20 # * This program is distributed in the hope that it will be useful,
21 # * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # * GNU General Public License for more details.
24 # *
25 # * You should have received a copy of the GNU General Public License
26 # * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 # *
28 # * This copyright notice MUST APPEAR in all copies of the script!
29 # ***********************************************************************
30  
31 use strict;
32 use warnings;
33 use Getopt::Long qw( :config posix_default bundling no_ignore_case );
34 use Pod::Usage;
35 use Data::Dumper;
36 use Cwd;
37 use Path::Class;
38 use Bio::ViennaNGS::FeatureIO;
39 use Bio::ViennaNGS::Peak;
40 use Bio::ViennaNGS::Util qw(mkdircheck);
41  
42  
43 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
44 #^^^^^^^^^^ Variables ^^^^^^^^^^^#
45 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
46 my ($infile1, $infile2, $lf);
47 my $logname = "rnaseq_peakfinder.log.txt";
48 my $fn_rawpeaks = "rawpeaks.bed";
49 my $fn_candidatepeaks = "candidatepeaks.bed";
50 my $winsize = 15; # sliding window size
51 my $wininterval = 1; # windows sliding interval
52 my $mincov = 100; # minimum coverage
53 my $maxlen = 100; # maximum peak length
54 my $threshold = 0.1; # cut off threhsold for peak end detection
55 my $debug = 0; # debug switch
56 my $dest = getcwd();
57  
58  
59 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
60 #^^^^^^^^^^^^^^ Main ^^^^^^^^^^^^^#
61 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
62 Getopt::Long::config('no_ignore_case');
63 pod2usage(-verbose => 1) unless GetOptions("bgpos=s" => \$infile1,
64 "bgneg=s" => \$infile2,
65 "w|winsize=i" => \$winsize,
66 "i|interval=i" => \$wininterval,
67 "m|mincov=i" => \$mincov,
68 "l|length=i" => \$maxlen,
69 "t|threshold=f" => \$threshold,
70 "out|o=s" => \$dest,
71 "d|debug" => sub{$debug=1},
72 "man" => sub{pod2usage(-verbose => 2)},
73 "help|h" => sub{pod2usage(1)}
74 );
75  
76 unless(-f $infile1){
77 warn "Could not find input bedGraph file for [+] strand provided via ---bgpos option";
78 pod2usage(-verbose => 0);
79 }
80 unless(-f $infile2){
81 warn "Could not find input bedGraph file for [-] strand provided via ---bgneg option";
82 pod2usage(-verbose => 0);
83 }
84 my $cwd = getcwd();
85 unless ($infile1 =~ /^\// || $infile1 =~ /^\.\//){$infile1 = file($cwd,$infile1);}
86 unless ($infile2 =~ /^\// || $infile2 =~ /^\.\//){$infile2 = file($cwd,$infile2);}
87 unless (-d $dest){mkdircheck($dest);}
88  
89 $lf = file($dest,$logname);
90  
91 # parse input files
92 my $io_pos = Bio::ViennaNGS::FeatureIO->new(file => "$infile1", # [+] strand
93 filetype => "BedGraph",
94 instanceOf => "BedGraphEntry",
95 );
96  
97 my $io_neg = Bio::ViennaNGS::FeatureIO->new(file => "$infile2", # [-] strand
98 filetype => "BedGraph",
99 instanceOf => "BedGraphEntry",
100 );
101  
102 # get an instance of Bio::ViennaNGS::Peak
103 my $peaks = Bio::ViennaNGS::Peak->new(winsize => $winsize,
104 interval => $wininterval,
105 mincov => $mincov,
106 length => $maxlen,
107 threshold => $threshold,
108 );
109  
110 # parse BedGraph coverage data from FeatureIO into the Peak object
111 $peaks->populate_data($io_pos, $io_neg);
112  
113 # identify covered regions
114 $peaks->raw_peaks($dest, "rnaseq_peakfinder", $lf);
115  
116 # characterize peaks
117 $peaks->final_peaks($dest, "rnaseq_peakfinder", $lf);
118  
119  
120 __END__
121  
122  
123 =head1 NAME
124  
125 rnaseq_peakfinder.pl - Identify peaks/enriched regions in RNA-seq data
126  
127 =head1 SYNOPSIS
128  
129 rnaseq_peakfinder.pl [--bgpos I<FILE>] [--bgneg I<FILE>] [options]
130  
131 =head1 DESCRIPTION
132  
133 This program identifies peaks in RNA-seq data. Starting from coverage
134 information in bedGraph format, this tool applies a two-step sliding
135 window approach to characterize enriched regions with predefined
136 properties, including maximum length, minimum coverage or maximum
137 coverage at both enads of the genomic inerval.
138  
139 B<Please note>: It is highly recommended to use I<normalized> input
140 data.
141  
142 =head1 OPTIONS
143  
144 =over
145  
146 =item B<--bgpos>
147  
148 BedGraph input file containing coverage of the [+] strand.
149  
150 =item B<--bgneg>
151  
152 BedGraph input file containing coverage of the [-] strand.
153  
154 =item B<--winsize -w>
155  
156 Size of the sliding window in nt.
157  
158 =item B<--interval -i>
159  
160 Size of the interval the sliding window is shifted at each step ('step
161 size').
162  
163 =item B<--mincov -m>
164  
165 Minimum coverage required for an enriched region to be considered.
166  
167 =item B<--length -l>
168  
169 Maximum length of a peak in nt.
170  
171 =item B<--threshold -t>
172  
173 Percentage of the maximum coverage value allowed at both ends of the
174 peaks (default 0.1). This value is used to identify peak boundaries.
175  
176 =item B<--out -o>
177  
178 Output directory.
179  
180 =item B<--help -h>
181  
182 Print short help
183  
184 =item B<--man>
185  
186 Prints the manual page and exits
187  
188 =back
189  
190 =head1 NOTES
191  
192 The memory footprint of this tool is rather high (several GB for
193 eucaryotic systems). This is due to the fact that the input BedGraph
194 files are first parsed into an Array of
195 L<Bio::ViennaNGS::BedGraphEntry> objects by
196 L<Bio::ViennaNGS::FeatureIO>. In a second step, this array is parsed
197 into a Hash of Arrays data structure within L<Bio::ViennaNGS::Peaks>
198 to allow for efficient window sliding. This may be refactored in a
199 future release.
200  
201  
202 =head1 AUTHOR
203  
204 Michael T. Wolfinger E<lt>michael@wolfinger.euE<gt>
205  
206 =cut
207  
208  
209  
210  
211