File Coverage

blib/lib/Bio/ViennaNGS/Bed.pm
Criterion Covered Total %
statement 12 29 41.3
branch 0 6 0.0
condition n/a
subroutine 4 6 66.6
pod 1 1 100.0
total 17 42 40.4


line stmt bran cond sub pod time code
1             # -*-CPerl-*-
2             # Last changed Time-stamp: <2015-02-06 16:28:50 mtw>
3              
4             package Bio::ViennaNGS::Bed;
5              
6 1     1   1723 use version; our $VERSION = qv('0.12_15');
  1         2  
  1         4  
7 1     1   69 use Carp;
  1         2  
  1         43  
8 1     1   4 use Moose;
  1         1  
  1         4  
9 1     1   5709 use namespace::autoclean;
  1         2  
  1         8  
10              
11             extends 'Bio::ViennaNGS::Feature';
12              
13             has '+strand' => (
14             required => 1,
15             );
16              
17             has 'thickStart' => (
18             is => 'rw',
19             isa => 'Int',
20             predicate => 'has_thickStart',
21             );
22              
23             has 'thickEnd' => (
24             is => 'rw',
25             isa => 'Int',
26             predicate => 'has_thickEnd',
27             );
28              
29             has 'itemRgb' => (
30             is => 'rw',
31             isa => 'Str',
32             lazy => 1,
33             default => '0',
34             );
35              
36             has 'blockCount' => (
37             is => 'rw',
38             isa => 'Int',
39             predicate => 'has_blockCount',
40             );
41              
42             has 'blockSizes' => (
43             is => 'rw',
44             isa => 'Value',
45             );
46              
47             has 'blockStarts' => (
48             is => 'rw',
49             isa => 'Value',
50             );
51              
52             has 'length' => (
53             is => 'rw',
54             isa => 'Int',
55             builder => '_build_length',
56             lazy => 1,
57             predicate => 'has_length',
58             );
59              
60              
61             sub _build_length {
62 0     0     my ($self) = @_;
63 0           my ($i,$len) = 0x2;
64 0           my $this_function = (caller(0))[3];
65 0           my @blockSizes = split (/,/ ,$self->blockSizes);
66 0           my $bc = scalar @blockSizes;
67 0 0         croak "ERROR [$this_function] invalid blockSount in BED12 line"
68             unless ($bc == $self->blockCount);
69              
70 0           for ($i=0;$i<$bc;$i++){
71 0           $len += $blockSizes[$i];
72             }
73 0           $self->length($len);
74             }
75              
76             sub as_bed_line {
77 0     0 1   my ($self,$n) = @_;
78 0           my $this_function = (caller(0))[3];
79 0 0         croak "ERROR [$this_function] argument of as_bed_line() must be 6 or 12"
80             unless ( ($n == 6) | ($n == 12) );
81 0           my $bed6= join ("\t",
82             $self->chromosome,
83             $self->start,
84             $self->end,
85             $self->name,
86             $self->score,
87             $self->strand,
88             );
89 0           my $bed12 = join ("\t", $bed6,
90             $self->thickStart,
91             $self->thickEnd,
92             $self->itemRgb,
93             $self->blockCount,
94             $self->blockSizes,
95             $self->blockStarts,
96             );
97 0 0         if ($n ==6){
98 0           return $bed6;
99             }
100             else{
101 0           return $bed12;
102             }
103             }
104              
105             # TODO:
106             # sub from_FeatureLine()
107             # sub to_FeatureLine()
108              
109             __PACKAGE__->meta->make_immutable;
110              
111             1;
112              
113             __END__
114              
115             =head1 NAME
116              
117             Bio::ViennaNGS::Bed - Object-oriented interface for manipulation of
118             genomic interval data in BED format
119              
120             =head1 SYNOPSIS
121              
122             use Bio::ViennaNGS::Bed;
123              
124             my $bedobject = Bio::ViennaNGS::Bed->new();
125              
126             # compute the length of a BED12 block
127             $bedobject->_build_length();
128              
129             # dump an object as BED12 line
130             $bedobject->as_bed_line(12);
131              
132             =head1 DESCRIPTION
133              
134             This module provides a Moose interface for storage and manipulation of
135             genomic interval data. It is primarily used as a convenience wrapper
136             for BED data with more generic L<Bio::ViennaNGS> classes for feature
137             annotation, such as L<Bio::ViennaNGS::MinimalFeature>,
138             L<Bio::ViennaNGS::Feature>, L<Bio::ViennaNGS::FeatureChain> and
139             L<Bio::ViennaNGS::FeatureLine>.
140              
141             =head1 METHODS
142              
143             =over
144              
145             =item _build_length
146              
147             Title : _build_length
148             Usage : C<<$obj->_build_length();>>
149             Function: Compute the length of a BED12 interval block / line, i.e.
150             the sum over the lengths of all intervals that make up a
151             BED12 entry.
152             Args :
153             Returns :
154              
155             =item as_bed_line
156              
157             Title : as_bed_line
158             Usage : C<<$obj->as_bed_line($bedtype);>>
159             Function: Dump the contents of the object as BED6 or BED12 line.
160             Args : C<$bedtype> can either be 6 or 12, determining BED6 or BED12
161             output.
162             Returns : A (tab-separated) BED6 or BED12 line as string.
163              
164              
165             =back
166              
167             =head1 DEPENDENCIES
168              
169             =over
170              
171             =item L<Carp>
172              
173             =back
174              
175             =head1 AUTHORS
176              
177             Michael T. Wolfinger E<lt>michael@wolfinger.euE<gt>
178              
179             =head1 COPYRIGHT AND LICENSE
180              
181             Copyright (C) 2015 Michael T. Wolfinger E<lt>michael@wolfinger.euE<gt>
182              
183             This library is free software; you can redistribute it and/or modify
184             it under the same terms as Perl itself, either Perl version 5.10.0 or,
185             at your option, any later version of Perl 5 you may have available.
186              
187             This program is distributed in the hope that it will be useful, but
188             WITHOUT ANY WARRANTY; without even the implied warranty of
189             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
190             General Public License for more details.
191              
192              
193             =cut