File Coverage

blib/lib/Bio/RNA/BarMap/Mapping/MinMappingEntry.pm
Criterion Covered Total %
statement 23 26 88.4
branch n/a
condition n/a
subroutine 8 9 88.8
pod 2 2 100.0
total 33 37 89.1


line stmt bran cond sub pod time code
1             # Bio/RNA/BarMap/Mapping/MinMappingEntry.pm
2              
3             package Bio::RNA::BarMap::Mapping::MinMappingEntry;
4             our $VERSION = '0.02';
5              
6 5     5   115 use 5.012;
  5         32  
7 5     5   27 use warnings;
  5         11  
  5         169  
8              
9 5     5   31 use Moose;
  5         10  
  5         45  
10 5     5   38279 use namespace::autoclean;
  5         13  
  5         55  
11              
12 5     5   514 use Scalar::Util qw( weaken );
  5         10  
  5         266  
13              
14 5     5   2873 use Bio::RNA::BarMap::Mapping::Type;
  5         17  
  5         280  
15 5     5   3127 use Bio::RNA::BarMap::Mapping::Set;
  5         23  
  5         1500  
16              
17              
18             has 'index' => (is => 'ro', required => 1);
19              
20             has 'to_type' => (
21             is => 'rw',
22             isa => 'Bio::RNA::BarMap::Mapping::Type',
23             );
24              
25             # Ensure object is cleaned after use => use weak refs
26             has '_from' => (
27             is => 'ro',
28             init_arg => undef, # use add_from() method to add elements
29             default => sub { Bio::RNA::BarMap::Mapping::Set->new },
30             );
31              
32             has 'to' => (
33             is => 'rw',
34             weak_ref => 1,
35             predicate => 'has_to',
36             isa => __PACKAGE__, # another entry
37             );
38              
39             # Always use this method to add 'from' minima. This ensures the refs
40             # are weakened and no memory leaks arise.
41             sub add_from {
42 6732     6732 1 15530 my ($self, @from) = @_;
43 6732         25179 weaken $_ foreach @from; # turn into weak references
44 6732         234668 $self->_from->insert(@from);
45             }
46              
47             sub get_from {
48 0     0 1   my ($self) = @_;
49 0           my @from = $self->_from->elements;
50 0           return @from;
51             }
52              
53             __PACKAGE__->meta->make_immutable;
54              
55             1; # End of Bio::RNA::BarMap::Mapping::MinMappingEntry
56              
57              
58             __END__
59              
60             =pod
61              
62             =encoding UTF-8
63              
64             =head1 NAME
65              
66             Bio::RNA::BarMap::Mapping::MinMappingEntry - Store I<BarMap> mappings of a
67             single minimum.
68              
69             =head1 SYNOPSIS
70              
71             use v5.12; # for 'say()' and '//' a.k.a. logical defined-or
72             use Bio::RNA::BarMap;
73              
74             my $entry = Bio::RNA::BarMap::Mapping::MinMappingEntry->new(
75             index => 3, # of minimum of this entry
76             to => $to_min, # the mininimum this one is mapped to
77             );
78              
79             # Query the entry.
80             if ($entry->has_to) { # maps to something
81             say 'This minimum maps ',
82             $entry->$to_type->is_exact ? 'exactly' : 'approximately',
83             ' to minimum ', $entry->to->index;
84             }
85              
86             $entry->add_from($from_min_1, $from_min_2); # add mins mapping to self
87             say "Minima mapped to this minimum:",
88             join q{, }, map {$_->index $entry->get_from();
89              
90              
91             =head1 DESCRIPTION
92              
93             Internal class used to store the mapping of a single minimum. Both the forward
94             direction ("target minimum", C<to()>) and the reverse direction ("source
95             minima", C<get_from()>) are provided. While the target minimum is unique, but
96             not necessarily defined (cf. C<has_to()>), there may be zero to many source
97             minima, and so these are stored in a set internally. Use C<add_from()> to add
98             to this set.
99              
100             =head1 METHODS
101              
102             =head2 Bio::RNA::BarMap::Mapping::MinMappingEntry->new(arg_name => $arg_val, ...)
103              
104             Constructor of the mapping entry class.
105              
106             =over
107              
108             =item Supported arguments:
109              
110             =over
111              
112             =item index
113              
114             Required. Index of the minimum described by this entry.
115              
116             =item to
117              
118             Optional. Reference to mapping entry object describing the minimum that this
119             minimum is mapped to.
120              
121             =back
122              
123             =item Non-argument:
124              
125             =over
126              
127             =item from
128              
129             To add source minima (i. e. minima that are mapped to this minimum), use the
130             method C<add_from()> instead.
131              
132             =back
133              
134             =back
135              
136             =head2 $entry->index
137              
138             Index of the minimum this entry is representing.
139              
140             =head2 $entry->to_type
141              
142             Type of the "to" mapping, either exact or approximate. Object of type
143             L<Bio::RNA::BarMap::Mapping::Type>.
144              
145             =head2 $entry->to
146              
147             Returns the entry this minimum is being mapped to. May be C<undef>.
148              
149             =head2 $entry->to($to_min_entry)
150              
151             Sets the C<to> attribute to point to C<$to_min_entry>.
152              
153             =head2 $entry->add_from(@from_entries)
154              
155             Adds entries to the set of source minima, i. e. those that are mapped to this
156             minimum. This method makes sure that the stored references are properly
157             weakened and no memory leaks arise.
158              
159             =head2 $entry->get_from
160              
161             Returns the entries of minima that are mapped to this minimum, as stored in
162             the source minima set.
163              
164             =head1 AUTHOR
165              
166             Felix Kuehnl, C<< <felix at bioinf.uni-leipzig.de> >>
167              
168              
169             =head1 BUGS
170              
171             Please report any bugs or feature requests by raising an issue at
172             L<https://github.com/xileF1337/Bio-RNA-BarMap/issues>.
173              
174             You can also do so by mailing to C<bug-bio-rna-barmap at rt.cpan.org>,
175             or through the web interface at
176             L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bio-RNA-BarMap>. I will be
177             notified, and then you'll automatically be notified of progress on your bug as
178             I make changes.
179              
180              
181             =head1 SUPPORT
182              
183             You can find documentation for this module with the perldoc command.
184              
185             perldoc Bio::RNA::BarMap
186              
187              
188             You can also look for information at the official BarMap website:
189              
190             L<https://www.tbi.univie.ac.at/RNA/bar_map/>
191              
192              
193             =over 4
194              
195             =item * Github: the official repository
196              
197             L<https://github.com/xileF1337/Bio-RNA-BarMap>
198              
199             =item * RT: CPAN's request tracker (report bugs here)
200              
201             L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Bio-RNA-BarMap>
202              
203             =item * AnnoCPAN: Annotated CPAN documentation
204              
205             L<http://annocpan.org/dist/Bio-RNA-BarMap>
206              
207             =item * CPAN Ratings
208              
209             L<https://cpanratings.perl.org/d/Bio-RNA-BarMap>
210              
211             =item * Search CPAN
212              
213             L<https://metacpan.org/release/Bio-RNA-BarMap>
214              
215             =back
216              
217              
218             =head1 LICENSE AND COPYRIGHT
219              
220             Copyright 2019-2021 Felix Kuehnl.
221              
222             This program is free software: you can redistribute it and/or modify
223             it under the terms of the GNU General Public License as published by
224             the Free Software Foundation, either version 3 of the License, or
225             (at your option) any later version.
226              
227             This program is distributed in the hope that it will be useful,
228             but WITHOUT ANY WARRANTY; without even the implied warranty of
229             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
230             GNU General Public License for more details.
231              
232             You should have received a copy of the GNU General Public License
233             along with this program. If not, see L<http://www.gnu.org/licenses/>.
234              
235              
236             =cut
237              
238             # End of Bio/RNA/BarMap/Mapping/MinMappingEntry.pm