blib/lib/Bio/ViennaNGS/Peak.pm

filter: Statementstmt 15.8% 41 / 258 Branchbran 0.0% 0 / 124 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 58.8% 10 / 17 Podpod 100% 3 / 3 totaltotal 12.5% 54 / 432 CC 74 SCAR 65.8
CC
74
Cov
10%
final_peaks
1056.0
raw_peaks
930.0
populate_data
210.0
CRAP 718.3
↑ Summary blib/lib/Bio/ViennaNGS/SpliceJunc.pm »
1 # -*-CPerl-*-
2 # Last changed Time-stamp: <2018-07-03 12:20:53 mtw>
3  
4 package Bio::ViennaNGS::Peak;
5  
6 1 ▶use Bio::ViennaNGS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use List::Util qw(sum sum0 min max first);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Bio::ViennaNGS::Util qw(sortbed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use version; our $VERSION = version->declare("$Bio::ViennaNGS::VERSION");
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 has 'data' => (
18 is => 'ro',
19 isa => 'HashRef',
20 predicate => 'has_data',
21 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 1 );
23  
24 has 'region' => (
25 is => 'ro',
26 isa => 'HashRef',
27 predicate => 'has_region',
28 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 1 );
30  
31 has 'peaks' => (
32 is => 'ro',
33 isa => 'HashRef',
34 predicate => 'has_peaks',
35 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 1 );
37  
38 1 has 'winsize' => (
39 is => 'ro',
40 isa => 'Int',
41 predicate => 'has_winsize',
42 );
43  
44 1 has 'interval' => (
45 is => 'ro',
46 isa => 'Int',
47 predicate => 'has_interval',
48 );
49  
50 1 has 'mincov' => (
51 is => 'ro',
52 isa => 'Int',
53 predicate => 'has_mincov',
54 );
55  
56 1 has 'length' => (
57 is => 'ro',
58 isa => 'Int',
59 predicate => 'has_length',
60 );
61  
62 1 has 'threshold' => (
63 is => 'ro',
64 isa => 'Value',
65 predicate => 'has_threshold',
66 );
67  
68 sub populate_data {
69 0 ▶ my ($self,$filep,$filen) = @_;
Subroutine populate_data: not called CC=14 SCAR=53.5
Pod documented
70 0 my $this_function = (caller(0))[3];
71 0 my ($i,$element,$chr,$start,$end,$val,$lastend);
72 0 my $have_lastend = 0;
73  
74 # parse [+] strand
75 0 foreach $element (@{$filep->data}){
76 0 ▶ unless (exists ${$self->region}{$element->chromosome}{pos}{start}){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists ${$self->region;}{$element->chromosome}{"pos"}{"start"}) 0 0 0
77 0 ${$self->region}{$element->chromosome}{pos}{start} = $element->start;
78 }
79 0 ▶ if($have_lastend == 1 && $element->start>$lastend){ # fill the gap with 0s
Branch: 1 branch
BranchTrueFalseTotal
if ($have_lastend == 1 and $element->start > $lastend) 0 0 0
Condition0%0/3
$have_lastend == 1 and $element->start > $lastend
!ll&&!rl&&r
000
MC/DC0%0/2
$have_lastend == 1 and $element->start > $lastend
$have_lastend == 1 $element->start > $lastend
Truth table0%0/3
A and B
A= $have_lastend == 1B= $element->start > $lastend
ABresult
0X0
100
111
80 0 ▶ for($i=$lastend;$i<$element->start;$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $element->start) 0 0 0
81 0 ${$self->data}{$element->chromosome}{pos}[$i] = 0.;
82 }
83 }
84 0 ▶ for ($i=$element->start;$i<$element->end;$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $element->end) 0 0 0
85 0 ${$self->data}{$element->chromosome}{pos}[$i]=$element->dataValue;
86 }
87 0 $lastend = $element->end;
88 0 $have_lastend = 1;
89 }
90  
91 0 $lastend = 0; # reset lastend before parsing [-] strand
92 0 $have_lastend = 1; # needed to get the values parsed correctly below
93  
94 # parse [-] strand
95 0 foreach $element (@{$filen->data}){
96 0 ▶ if ($element->{dataValue} <= 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($element->{"dataValue"} <= 0) 0 0 0
97 0 $element->{dataValue} *= -1;
98 }
99 0 ▶ unless (exists ${$self->region}{$element->chromosome}{neg}{start}){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists ${$self->region;}{$element->chromosome}{"neg"}{"start"}) 0 0 0
100 0 ${$self->region}{$element->chromosome}{neg}{start} = $element->start;
101 }
102 0 ▶ if($have_lastend == 1 && $element->start>$lastend){ # fill the gap with 0s
Branch: 1 branch
BranchTrueFalseTotal
if ($have_lastend == 1 and $element->start > $lastend) 0 0 0
Condition0%0/3
$have_lastend == 1 and $element->start > $lastend
!ll&&!rl&&r
000
MC/DC0%0/2
$have_lastend == 1 and $element->start > $lastend
$have_lastend == 1 $element->start > $lastend
Truth table0%0/3
A and B
A= $have_lastend == 1B= $element->start > $lastend
ABresult
0X0
100
111
103 0 ▶ for($i=$lastend;$i<$element->start;$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $element->start) 0 0 0
104 0 ${$self->data}{$element->chromosome}{neg}[$i] = 0.;
105 }
106 }
107 0 ▶ for ($i=$element->start;$i<$element->end;$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $element->end) 0 0 0
108 0 ${$self->data}{$element->chromosome}{neg}[$i]=$element->dataValue;
109 }
110 0 $lastend = $element->end;
111 0 $have_lastend = 1;
112 }
113 0 return;
114 }
115  
116 sub raw_peaks {
117 0 ▶ my ($self,$dest,$prefix,$log) = @_;
Subroutine raw_peaks: not called CC=30 SCAR=68.4
Pod documented
118 0 my ($fn,$tfn,$tfh,$maxidx,$have_pstart,$pstart,$pend,$chr);
119 0 my ($winstart, $winend, $winsum, $mean, $lastmax, $from, $to);
120 0 my ($index_of_maxwin);
121 0 my $suffix = "rawpeaks.bed";
122 0 my $this_function = (caller(0))[3];
123 0 my $flex = 10;
124  
125 0 ▶ croak "ERROR [$this_function]: $dest does not exist\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dest 0 0 0
126 unless (-d $dest);
127  
128 0 ▶ if (defined $log){open(LOG, ">", $log) or croak "$!"}
Branch: 2 branches
BranchTrueFalseTotal
if (defined $log) { } 0 0 0
open LOG, ">", $log or croak("$!") 0 0 0
129 0 else {croak "ERROR [$this_function] \$log not defined";}
130  
131 0 $fn = $prefix.".".$suffix; # filename of final, sorted RAWPEAKS bed file
132 0 (undef,$tfn) = tempfile('RAWPEAKS_XXXXXXX',UNLINK=>0);
133  
134 0 ▶ croak "ERROR [$this_function]: $self->data not available\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_data 0 0 0
135 unless ($self->has_data);
136  
137 0 ▶ croak "ERROR [$this_function]: $self->region not available\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_region 0 0 0
138 unless ($self->has_region);
139  
140 0 ▶ open ($tfh, ">", $tfn) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
open $tfh, ">", $tfn or croak($!) 0 0 0
141 0 $lastmax = 0;
142 0 foreach $chr (keys (%{$self->data})){
143  
144 # pos strand
145 0 $maxidx = $#{$self->data->{$chr}{pos}} ; # largest index in array
146 0 $have_pstart = 0;
147 0 $pstart = -1;
148 0 $pend = -1;
149 0 ▶ if (defined $log){print LOG "processing chr $chr [+] strand $maxidx\n"}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
150 croak "$chr has not been parsed in input data"
151 0 ▶ unless (exists $self->region->{$chr}{pos}{start});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->region->{$chr}{"pos"}{"start"} 0 0 0
152  
153 0 ▶ for ($winstart=$self->region->{$chr}{pos}{start};$winstart<($maxidx-$self->winsize);$winstart+=$self->interval){
Branch: 1 branch
BranchTrueFalseTotal
if ($winstart < $maxidx - $self->winsize) 0 0 0
154 # NOTE: does not handle the last window properly - > ignore this
155 0 $winend = $winstart + $self->winsize - 1;
156 0 $winsum = sum0 @{$self->data->{$chr}{pos}}[$winstart..$winend];
157 0 $mean = $winsum/$self->winsize;
158 #print LOG "**processing $winstart - $winend sum=$winsum mean=$mean lastmax=$lastmax\n";
159  
160 0 ▶ if ($mean > $lastmax){
Branch: 1 branch
BranchTrueFalseTotal
if ($mean > $lastmax) { } 0 0 0
161 0 $lastmax = $mean;
162 0 $index_of_maxwin = $winstart;
163 0 ▶ unless ($have_pstart == 1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($have_pstart == 1) 0 0 0
164 0 $pstart = $winstart;
165 0 $have_pstart = 1;
166 #print LOG "Peak start $chr:$winstart -- ";
167 }
168 }
169 else {
170 0 ▶ if ($mean > 0. && $mean <= $lastmax*$self->threshold ){ # peak stop criterion
Branch: 1 branch
BranchTrueFalseTotal
if ($mean > 0 and $mean <= $lastmax * $self->threshold) 0 0 0
Condition0%0/3
$mean > 0 and $mean <= $lastmax * $self->threshold
!ll&&!rl&&r
000
MC/DC0%0/2
$mean > 0 and $mean <= $lastmax * $self->threshold
$mean > 0 $mean <= $lastmax * $self->threshold
Truth table0%0/3
A and B
A= $mean > 0B= $mean <= $lastmax * $self->threshold
ABresult
0X0
100
111
171 0 $pend = $winend;
172 0 $have_pstart = 0;
173 0 $from = min($pstart,$pend);
174 0 $to = max($pstart, $pend);
175 0 ▶ next if ($from<0);
Branch: 1 branch
BranchTrueFalseTotal
if $from < 0 0 0 0
176 0 ▶ next if ($to<0);
Branch: 1 branch
BranchTrueFalseTotal
if $to < 0 0 0 0
177 # now add +- $flex nt to raw peaks, required fro better peak boundary determination below
178 0 ▶ if ($from-$flex > 0){$from = $from - $flex;}
Branch: 1 branch
BranchTrueFalseTotal
if ($from - $flex > 0) 0 0 0
179 0 $to= $to+$flex; # we dont know the chromsize here, hence override it in case
180 #print LOG "$pend end\n";
181 0 my %pk = (
182 chr => $chr,
183 start => $from,
184 end => $to,
185 strand => 'pos',
186 maxindex => $index_of_maxwin,
187 );
188 0 push (@{ $self->peaks->{$chr} }, \%pk);
189 0 ▶ if (defined $log){print LOG "**PEAK $chr [+] $from-$to max at $index_of_maxwin\n"}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
190 0 print $tfh "$chr\t$from\t$to\tRAW\t0\t+\n";
191  
192 # reset parameters
193 0 $lastmax = 0;
194 0 $pstart = -1;
195 0 $pend = -1;
196 }
197 }
198 } # end for
199 0 $lastmax = 0;
200  
201 # neg strand
202 0 $maxidx = $#{$self->data->{$chr}{neg}}; # largest index in array
203 0 $have_pstart = 0;
204 0 $pstart = -1;
205 0 $pend = -1;
206 0 ▶ if (defined $log){print LOG "processing chr $chr [-] strand $maxidx\n"}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
207 croak "$chr has not been parsed in input data"
208 0 ▶ unless (exists $self->region->{$chr}{neg}{start});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->region->{$chr}{"neg"}{"start"} 0 0 0
209  
210 0 ▶ for ($winstart=$maxidx;$winstart>($self->region->{$chr}{neg}{start}+$self->winsize);$winstart-=$self->interval){
Branch: 1 branch
BranchTrueFalseTotal
if ($winstart > $self->region->{$chr}{"neg"}{"start"} + $self->winsize) 0 0 0
211 # NOTE: does not handle the last window properly - > ignore this
212 0 $winend = $winstart - $self->winsize + 1;
213 0 $winsum = sum0 @{$self->data->{$chr}{neg}}[$winend..$winstart];
214 0 $mean = $winsum/$self->winsize;
215 #print "processing $winstart - $winend sum=$winsum mean=$mean lastmax=$lastmax\n";
216  
217 0 ▶ if ($mean > $lastmax){
Branch: 1 branch
BranchTrueFalseTotal
if ($mean > $lastmax) { } 0 0 0
218 0 $lastmax = $mean;
219 0 $index_of_maxwin = $winend;
220 0 ▶ unless ($have_pstart == 1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($have_pstart == 1) 0 0 0
221 0 $pstart = $winend;
222 0 $have_pstart = 1;
223 #print "Peak start $chr:$pstart -- ";
224 }
225 }
226 else {
227 0 ▶ if ($mean > 0. && $mean <= $lastmax*$self->threshold ){ # peak stop criterion
Branch: 1 branch
BranchTrueFalseTotal
if ($mean > 0 and $mean <= $lastmax * $self->threshold) 0 0 0
Condition0%0/3
$mean > 0 and $mean <= $lastmax * $self->threshold
!ll&&!rl&&r
000
MC/DC0%0/2
$mean > 0 and $mean <= $lastmax * $self->threshold
$mean > 0 $mean <= $lastmax * $self->threshold
Truth table0%0/3
A and B
A= $mean > 0B= $mean <= $lastmax * $self->threshold
ABresult
0X0
100
111
228 0 $pend = $winstart;
229 0 $have_pstart = 0;
230 0 $from = min($pstart,$pend);
231 0 $to = max($pstart, $pend);
232 0 ▶ next if ($from<0);
Branch: 1 branch
BranchTrueFalseTotal
if $from < 0 0 0 0
233 0 ▶ next if ($to<0);
Branch: 1 branch
BranchTrueFalseTotal
if $to < 0 0 0 0
234 # now add +- $flex nt to raw peaks, required fro better peak boundary determination below
235 0 ▶ if ($from-$flex > 0){$from = $from - $flex;}
Branch: 1 branch
BranchTrueFalseTotal
if ($from - $flex > 0) 0 0 0
236 0 $to = $to+$flex; # we dont know the chromsize here, hence override it in case
237 #print "$pend end\n";
238 0 my %pk = (
239 chr => $chr,
240 start => $from,
241 end => $to,
242 strand => 'neg',
243 maxindex => $index_of_maxwin,
244 );
245 0 push (@{ $self->peaks->{$chr} }, \%pk);
246 0 ▶ if (defined $log){print LOG "**PEAK $chr [-] $from-$to max at $index_of_maxwin\n"}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
247 0 print $tfh "$chr\t$from\t$to\tRAW\t0\t-\n";
248  
249 # reset parameters
250 0 $lastmax = 0;
251 0 $pstart = -1;
252 0 $pend = -1;
253 }
254 }
255 } # end for
256  
257 #print LOG Dumper($self->peaks);
258  
259 } # end foreach
260 0 close($tfh);
261 0 close(LOG);
262 0 sortbed($tfn,$dest,$fn,0,$log);
263 0 unlink($tfn);
264 }
265  
266 sub final_peaks {
267 0 ▶ my ($self,$dest,$prefix,$log) = @_;
Subroutine final_peaks: not called CC=32 SCAR=69.6
Pod documented
268 0 my ($fn,$tfn,$tfh,$strand,$max,$idx,$val,$peak,$position,$pleft,$pright,$str);
269 0 my $suffix = "candidatepeaks.bed";
270 0 my $this_function = (caller(0))[3];
271  
272 0 ▶ croak "ERROR [$this_function]: $dest does not exist\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dest 0 0 0
273 unless (-d $dest);
274  
275 0 ▶ if (defined $log){open(LOG, ">>", $log) or croak "$!";}
Branch: 2 branches
BranchTrueFalseTotal
if (defined $log) { } 0 0 0
open LOG, ">>", $log or croak("$!") 0 0 0
276 0 else {croak "ERROR [$this_function] \$log not defined";}
277  
278 0 $fn = $prefix.".".$suffix;
279 0 (undef,$tfn) = tempfile('CANDIDATEPEAKS_XXXXXXX',UNLINK=>0);
280  
281 0 ▶ croak "ERROR [$this_function]: $self->data not available\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_data 0 0 0
282 unless ($self->has_data);
283  
284 0 ▶ croak "ERROR [$this_function]: $self->peaks not available\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_peaks 0 0 0
285 unless ($self->has_peaks);
286  
287 0 ▶ open($tfh, ">", $tfn) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
open $tfh, ">", $tfn or croak($!) 0 0 0
288 0 foreach my $chr (keys (%{$self->peaks})){
289 0 ▶ if (defined $log){print LOG "filtering candidate peaks in $chr\n";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
290  
291 0 foreach $peak ( @{$self->peaks->{$chr}}){
292 0 my $have_pleft = 0; # we have found a proper left end
293 0 my $have_pright = 0; # we have found a proper right end
294 0 $strand = $$peak{strand};
295 0 ▶ if (defined $log){print LOG ">>processing peak $$peak{start}-$$peak{end} [$strand] ";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
296 0 $max = max @{$self->data->{$chr}{$strand}}[$$peak{start}..$$peak{end}]; # max peak elevation
297 0 ▶ if (defined $log){print LOG "max is $max";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
298 0 ▶ if ($max < $self->mincov){print LOG " ..SKIPPING\n";next;}
Branch: 1 branch
BranchTrueFalseTotal
if ($max < $self->mincov) 0 0 0
299 0 ▶ $idx = first { @{$self->data->{$chr}{$strand}}[$_] eq $max } $$peak{start}..$$peak{end}; # coordinate
Subroutine __ANON__: not called CC=1 SCAR=6.9
300 #print LOG Dumper(\$peak);
301 0 ▶ if (defined $log){print LOG " at $idx ..KEEPING\n";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
302  
303 # process regions left/right of the maximum to identify peak boundaries
304 # validity check first
305 die "maximum at $idx is not within peak region"
306 0 ▶ if ( $idx<$$peak{start} || $idx>$$peak{end} );
Branch: 1 branch
BranchTrueFalseTotal
if $idx < $peak->{"start"} or $idx > $peak->{"end"} 0 0 0
Condition0%0/3
$idx < $peak->{"start"} or $idx > $peak->{"end"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$idx < $peak->{"start"} or $idx > $peak->{"end"}
$idx < $peak->{"start"} $idx > $peak->{"end"}
Truth table0%0/3
A or B
A= $idx < $peak->{"start"}B= $idx > $peak->{"end"}
ABresult
1X1
011
000
307  
308 # find left end
309 0 ▶ for ($position = $idx; $position>$$peak{start}; $position--){
Branch: 1 branch
BranchTrueFalseTotal
if ($position > $peak->{"start"}) 0 0 0
310 0 $val = ${$self->data->{$chr}{$strand}}[$position];
311 0 ▶ if (defined $log){print LOG "** VAL_L at pos $position $val - \$have_pleft=$have_pleft ";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
312 0 ▶ if ( $val < $max*$self->threshold){
Branch: 1 branch
BranchTrueFalseTotal
if ($val < $max * $self->threshold) 0 0 0
313 0 $have_pleft = 1;
314 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
315 0 print LOG "exiting 'cause $val < ".$max*$self->threshold." - \$have_pleft=$have_pleft\n";
316 }
317 0 last;
318 }
319 0 ▶ if (defined $log){print LOG "\n";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
320 }
321 0 $pleft = $position;
322  
323 # find right end
324 0 ▶ for ($position = $idx; $position<=$$peak{end}; $position++){
Branch: 1 branch
BranchTrueFalseTotal
if ($position <= $peak->{"end"}) 0 0 0
325 0 $val = ${$self->data->{$chr}{$strand}}[$position];
326 0 ▶ if (defined $log){print LOG "** VAL_R at pos $position $val - \$have_pright=$have_pright ";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
327 0 ▶ if ( $val < $max*$self->threshold){
Branch: 1 branch
BranchTrueFalseTotal
if ($val < $max * $self->threshold) 0 0 0
328 0 $have_pright = 1;
329 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
330 0 print LOG "exiting 'cause $val < ".$max*$self->threshold."- \$have_pright=$have_pright\n";
331 }
332 0 last;
333 }
334 0 ▶ if (defined $log){print LOG "\n";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
335 }
336 0 $pright = $position;
337 0 ▶ if ($strand eq "neg"){
Branch: 1 branch
BranchTrueFalseTotal
if ($strand eq 'neg') { } 0 0 0
338 0 $str = '-';
339 }
340 else{
341 0 $str = '+';
342 }
343 0 ▶ if (defined $log){print LOG "# PEAK characterized at $chr:$pleft-$pright\n";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
344  
345 0 ▶ if ($have_pleft == 1 && $have_pright == 1){ # print only if its a proper peak
Branch: 1 branch
BranchTrueFalseTotal
if ($have_pleft == 1 and $have_pright == 1) 0 0 0
Condition0%0/3
$have_pleft == 1 and $have_pright == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$have_pleft == 1 and $have_pright == 1
$have_pleft == 1 $have_pright == 1
Truth table0%0/3
A and B
A= $have_pleft == 1B= $have_pright == 1
ABresult
0X0
100
111
346 0 ▶ if ($pright-$pleft<=$self->length){ # filter peak length
Branch: 1 branch
BranchTrueFalseTotal
if ($pright - $pleft <= $self->length) 0 0 0
347 0 ▶ if (defined $log){print $tfh "$chr\t$pleft\t$pright\tCANDIDATE\t$max\t$str\n";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
348 }
349 }
350 } # end foreach $peak
351 } # end foreach $chr
352 0 close($tfh);
353 0 sortbed($tfn,$dest,$fn,0,$log);
354 0 unlink($tfn);
355 }
356 1 __PACKAGE__->meta->make_immutable;
357  
358 1 1;
359 __END__
360  
361  
362 =head1 NAME
363  
364 Bio::ViennaNGS::Peak - An object oriented interface for characterizing
365 peaks in RNA-seq data
366  
367 =head1 SYNOPSIS
368  
369 use Bio::ViennaNGS::Peak;
370  
371 # get an instance of Bio::ViennaNGS::peak
372 my $peaks = Bio::ViennaNGS::Peak->new();
373  
374 # parse coverage for [+] and [-] strand from Bio::ViennaNGS::FeatureIO objects
375 $peaks->populate_data($filep,$filen);
376  
377 # identify regions covered by RNA-seq signal ('raw peaks')
378 $peaks->raw_peaks($dest,$prefix,$log);
379  
380 # characterize final peaks
381 $peaks->final_peaks($dest,$prefix,$log);
382  
383  
384 =head1 DESCRIPTION
385  
386 This module provides a L<Moose> interface for characterization of
387 peaks in RNA-seq coverage data.
388  
389 =head1 METHODS
390  
391 =over
392  
393 =item populate_data
394  
395 Title : populate_data
396  
397 Usage : C<$obj-E<gt>populate_data($filep,$filen);>
398  
399 Function : Parses RNA-seq coverage for positive and negative strand
400 into C<@{$self-E<gt>data}>, a Hash of Arrays data structure.
401  
402 Args : C<$filep> and C<$filen> are instances of L<Bio::ViennaNGS::FeatureIO>.
403  
404 Returns : None.
405  
406 Notes: The memory footprint of this method is rather high. It builds a
407 Hash of Arrays data structure from L<Bio::ViennaNGS::FeatureIO>
408 input objects of roughly the size of the underlying genome
409 (chromosomes are hash keys, and there is an array containing
410 coverage information for every genomic position referenced by
411 hash values).
412  
413 =item raw_peaks
414  
415 Title : raw_peaks
416  
417 Usage : C<$obj-E<gt>raw_peaks($dest,$prefix,$log);>
418  
419 Function : This method identifies genomic regions ('raw peaks')
420 covered by RNA-seq signal by means of a sliding window
421 approach. RNA-seq coverage is read from
422 C<@{$self-E<gt>data}> (which is populated by e.g. the
423 C<populate_data> method). The sliding window approach
424 processes [+] and [-] strand for all chromosomes in 5'
425 -E<gt> 3' direction, whereby the mean value of each window
426 is used as a representative for this window. Thereby both
427 start and end coordinates, as well as position of the
428 maximum elevation are identified. Here the end position of
429 a covered region is defined as the coordinate of the window
430 whose mean is less than a certain value
431 (i.e. C<$self-E<gt>threshold> * peak maximum).
432  
433 Raw peaks are stored in C<%{$self-E<gt>data}-E<gt>{peaks}>.
434  
435 Args : C<$dest> contains the output path for results, C<$prefix> the
436 prefix used for all output file names. C<$log> is the name of a
437 log file, or undef if no logging is reuqired.
438  
439 Returns : None. The output is a position-sorted BED6 file containing
440 all raw peaks.
441  
442 Notes : It is highly recommended to use I<normalized> input data in
443 order to allow for multiple calls of this method with the same
444 set of parameters on different samples.
445  
446 =item final_peaks
447  
448 Title : final_peaks
449  
450 Usage : C<$obj-E<gt>final_peaks($dest,$prefix,$log);>
451  
452 Function : This method characterizes final peaks from RNA-seq coverage
453 found in C<%{$self-E<gt>data}-E<gt>{peaks}>. The latter is
454 supposed to have been populated by C<$self-E<gt>raw_peaks>.
455  
456 The procedure for finding final peaks is as follows: For each raw peak
457 found in C<%{$self-E<gt>data}-E<gt>{peaks}> the window of maximum
458 coverage is retrieved and a (second) sliding window approach is then
459 applied to regions both upstream and downstream of the maximum. Peak
460 boundaries are set at the position where the mean coverage of the
461 respective window is lower than C<$self-E<gt>threshold> * peak
462 maximum).
463  
464 Peaks are reported if their total length (as determined by this
465 routine) is not longer than C<$self-E<gt>length>.
466  
467 Args : C<$dest> contains the output path for results, C<$prefix> the
468 prefix used for all output file names. C<$log> is the name of a
469 log file, or undef if no logging is reuqired.
470  
471 Returns : None. The output is a position-sorted BED6 file containing
472 all candidate peaks.
473  
474 Notes :
475  
476 =back
477  
478 =head1 DEPENDENCIES
479  
480 =over
481  
482 =item L<Moose>
483  
484 =item L<Carp>
485  
486 =item L<Path::Class>
487  
488 =item L<List::Util>
489  
490 =item L<namespace::autoclean>
491  
492 =back
493  
494 =head1 SEE ALSO
495  
496 =over
497  
498 =item L<Bio::ViennaNGS>
499  
500 =item L<Bio::ViennaNGS::Util>
501  
502 =back
503  
504 =head1 AUTHOR
505  
506 Michael T. Wolfinger, E<lt>michael@wolfinger.euE<gt>
507  
508 =head1 COPYRIGHT AND LICENSE
509  
510 Copyright (C) 2015-2018 by Michael T. Wolfinger
511  
512 This library is free software; you can redistribute it and/or modify
513 it under the same terms as Perl itself, either Perl version 5.10.0 or,
514 at your option, any later version of Perl 5 you may have available.
515  
516 This software is distributed in the hope that it will be useful, but
517 WITHOUT ANY WARRANTY; without even the implied warranty of
518 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
519  
520 =cut
↑ Summary blib/lib/Bio/ViennaNGS/SpliceJunc.pm »