File Coverage

blib/lib/Bio/RNA/BarMap/Mapping/Type.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 2 100.0
condition n/a
subroutine 10 10 100.0
pod 5 5 100.0
total 39 39 100.0


line stmt bran cond sub pod time code
1             # All methods are class methods, it's not meant to be instantiated. It just
2             # manages the type name string and converts it to arrows, etc.
3             package Bio::RNA::BarMap::Mapping::Type;
4             our $VERSION = '0.03';
5              
6 5     5   105 use 5.012;
  5         19  
7 5     5   28 use warnings;
  5         10  
  5         123  
8              
9 5     5   25 use Moose;
  5         10  
  5         35  
10 5     5   32294 use Moose::Util::TypeConstraints; # for enum()
  5         15  
  5         46  
11 5     5   11691 use namespace::autoclean;
  5         11  
  5         100  
12              
13              
14             has '_type' => (
15             is => 'ro',
16             isa => enum([qw(EXACT APPROX)]),
17             required => 1,
18             );
19              
20             # Only allow construction from a single arrow string.
21             around BUILDARGS => sub {
22             my $orig = shift;
23             my $class = shift;
24              
25             confess 'Pass a single arrow string to construct a Mapping::Type object'
26             if @_ != 1 or ref $_[0];
27              
28             my $arrow = shift; # arrow string passed
29             if ($arrow eq '->') {
30             return $class->$orig(_type => 'EXACT')
31             }
32             elsif ($arrow eq '~>') {
33             return $class->$orig(_type => 'APPROX')
34             }
35             else {
36             confess 'Unknown arrow string in constructor';
37             }
38             };
39              
40             # Returns a new mapping type object of type 'exact'.
41 20     20 1 760 sub exact { return $_[0]->new('->'); }
42              
43             # Returns a new mapping type object of type 'approx'.
44 12     12 1 395 sub approx { return $_[0]->new('~>'); }
45              
46             # Returns true iff the object is of EXACT type.
47             sub is_exact {
48 18     18 1 2893 my ($self) = @_;
49 18         627 return $self->_type() eq 'EXACT';
50             }
51              
52             # Returns true iff the object is of APPROX type.
53             sub is_approx {
54 147     147 1 2961 my ($self) = @_;
55 147         4259 return $self->_type() eq 'APPROX';
56             }
57              
58             # Return the arrow representation of this object, i.e. '->' for exact and '~>'
59             # for approx mapping type objects.
60             sub arrow {
61 12     12 1 3790 my ($self) = @_;
62 12 100       39 return $self->is_exact ? '->' : '~>';
63             }
64              
65              
66             __PACKAGE__->meta->make_immutable;
67              
68             1; # End of Bio::RNA::BarMap::Mapping::Type
69              
70              
71             __END__
72              
73             =pod
74              
75             =encoding UTF-8
76              
77             =head1 NAME
78              
79             Bio::RNA::BarMap::Mapping::Type - Represents the type of a I<BarMap> mapping
80             (exact or approximate)
81              
82             =head1 SYNOPSIS
83              
84             use v5.12; # for 'say'
85             use Bio::RNA::BarMap;
86              
87             # Get a new mapping type object ... from arrow string:
88             my $type = Bio::RNA::BarMap::Mapping::Type->new('->'); # exact
89             $type = Bio::RNA::BarMap::Mapping::Type->new('~>'); # approx
90              
91             # ... or programmatically:
92             $type = Bio::RNA::BarMap::Mapping::Type->exact; # exact
93             $type = Bio::RNA::BarMap::Mapping::Type->approx; # approx
94              
95             # Verify mapping type.
96             say 'Mapping is ', $type->is_exact ? 'exact' : 'approximate';
97             say 'Mapping arrow: ', $type->arrow;
98              
99              
100             =head1 DESCRIPTION
101              
102             The objects of this class are used to represent the two possible types of a
103             mapping, either exact or approximate, and to easily convert between these two
104             values and their respective arrow representation. In I<BarMap> files,
105             C<< -> >> denotes an exact mapping, and C<< ~> >> an approximate one. The
106             object is constructed from the arrow string via the constructor C<new()>, or
107             using the methods C<exact()> and C<approx()> to get a new object of the
108             respective type.
109              
110              
111             =head1 METHODS
112              
113             =head2 Bio::RNA::BarMap::Mapping::Type->new($arrow_string)
114              
115             Constructs a new type object from its arrow string representation, i. e.
116             C<< -> >> for the exact and C<< ~> >> for the approximate variant.
117              
118             =head2 Bio::RNA::BarMap::Mapping::Type->exact()
119              
120             Class method. Returns a new mapping type object of I<exact> type.
121              
122             =head2 Bio::RNA::BarMap::Mapping::Type->approx()
123              
124             Class method. Returns a new mapping type object of I<approximate> type.
125              
126             =head2 $type->is_exact()
127              
128             Returns true iff the current object is of I<exact> type.
129              
130             =head2 $type->is_approx()
131              
132             Returns true iff the current object is of I<approximate> type.
133              
134             =head2 $type->arrow()
135              
136             Returns the type of this object in its arrow string representation, i. e.
137             C<< -> >> for the exact and C<< ~> >> for the approximate.
138              
139             =head1 AUTHOR
140              
141             Felix Kuehnl, C<< <felix at bioinf.uni-leipzig.de> >>
142              
143             =head1 BUGS
144              
145             Please report any bugs or feature requests by raising an issue at
146             L<https://github.com/xileF1337/Bio-RNA-BarMap/issues>.
147              
148             You can also do so by mailing to C<bug-bio-rna-barmap at rt.cpan.org>,
149             or through the web interface at
150             L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bio-RNA-BarMap>. I will be
151             notified, and then you'll automatically be notified of progress on your bug as
152             I make changes.
153              
154              
155             =head1 SUPPORT
156              
157             You can find documentation for this module with the perldoc command.
158              
159             perldoc Bio::RNA::BarMap
160              
161              
162             You can also look for information at the official BarMap website:
163              
164             L<https://www.tbi.univie.ac.at/RNA/bar_map/>
165              
166              
167             =over 4
168              
169             =item * Github: the official repository
170              
171             L<https://github.com/xileF1337/Bio-RNA-BarMap>
172              
173             =item * RT: CPAN's request tracker (report bugs here)
174              
175             L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Bio-RNA-BarMap>
176              
177             =item * AnnoCPAN: Annotated CPAN documentation
178              
179             L<http://annocpan.org/dist/Bio-RNA-BarMap>
180              
181             =item * CPAN Ratings
182              
183             L<https://cpanratings.perl.org/d/Bio-RNA-BarMap>
184              
185             =item * Search CPAN
186              
187             L<https://metacpan.org/release/Bio-RNA-BarMap>
188              
189             =back
190              
191              
192             =head1 ACKNOWLEDGEMENTS
193              
194              
195             =head1 LICENSE AND COPYRIGHT
196              
197             Copyright 2019 Felix Kuehnl.
198              
199             This program is free software: you can redistribute it and/or modify
200             it under the terms of the GNU General Public License as published by
201             the Free Software Foundation, either version 3 of the License, or
202             (at your option) any later version.
203              
204             This program is distributed in the hope that it will be useful,
205             but WITHOUT ANY WARRANTY; without even the implied warranty of
206             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
207             GNU General Public License for more details.
208              
209             You should have received a copy of the GNU General Public License
210             along with this program. If not, see L<http://www.gnu.org/licenses/>.
211              
212              
213             =cut
214              
215             # End of Bio::RNA::BarMap::Mapping::Type / lib/Bio/RNA/BarMap/Mapping/Type.pm