File Coverage

blib/lib/Bio/RNA/BarMap/Mapping.pm
Criterion Covered Total %
statement 132 171 77.1
branch 27 40 67.5
condition 12 18 66.6
subroutine 27 35 77.1
pod 15 16 93.7
total 213 280 76.0


line stmt bran cond sub pod time code
1             package Bio::RNA::BarMap::Mapping;
2             our $VERSION = '0.04';
3              
4 5     5   81 use 5.012;
  5         16  
5 5     5   29 use warnings;
  5         18  
  5         196  
6              
7 5     5   2806 use Moose;
  5         2373329  
  5         29  
8 5     5   41269 use MooseX::StrictConstructor;
  5         156364  
  5         20  
9 5     5   49959 use namespace::autoclean;
  5         14  
  5         25  
10              
11 5     5   3189 use autodie qw(:all);
  5         77227  
  5         31  
12 5     5   125276 use Scalar::Util qw(reftype);
  5         12  
  5         268  
13 5     5   33 use List::Util qw(any);
  5         9  
  5         260  
14 5     5   39 use File::Spec;
  5         10  
  5         139  
15              
16 5     5   2739 use Bio::RNA::BarMap::Mapping::MinMappingEntry;
  5         24  
  5         231  
17 5     5   3338 use Bio::RNA::BarMap::Mapping::FileMappingEntry;
  5         19  
  5         14694  
18              
19              
20             # Hash mapping each minimum to the one it is mapped to in the next landscape.
21             has '_min_mapping' => (
22             is => 'ro',
23             required => 1,
24             );
25              
26             # Hash mapping barrier files to each other, i.e. bar1 -> bar2 iff BarMap
27             # mapped the minima from bar1 to the minima of bar2.
28             has '_file_mapping' => (
29             is => 'ro',
30             init_arg => undef, # generated from list of mapped files
31             lazy => 1,
32             builder => '_build_file_mapping',
33             );
34              
35             # Array for keeping the order.
36             has '_mapped_files' => (
37             is => 'ro',
38             required => 1,
39             );
40              
41 5     5 1 9767 sub mapped_files { return @{ $_[0]->_mapped_files } } # dereference
  5         189  
42              
43             has 'file_name' => (
44             is => 'ro',
45             predicate => 'has_file_name',
46             );
47              
48             # The path builder is initialized with the path to this mapping's barmap
49             # file. Given another file name relative to the barmap, it constructs a
50             # path to this file from the current working directory. This is necessary
51             # because usually the bar files mentioned in the barmap file reside in the
52             # same directory and need to be prefixed with the same path.
53             has '_path_builder' => (
54             is => 'ro',
55             init_arg => undef,
56             lazy => 1,
57             builder => '_build_path_builder',
58             );
59              
60             # Returns a sub that builds file paths from given file names such that the
61             # files are in the same dir as the target file/dir given during
62             # construction.
63             # Args:
64             # target_file: from this file or dir, the target dir will be inferred
65             # Returns: sub that builds a path from the given file name.
66             sub _build_path_builder {
67 0     0   0 my $self = shift;
68 0 0       0 confess 'File name attribute needs to be set to build any paths'
69             unless $self->has_file_name;
70              
71 0         0 my ($target_file_path) = $self->file_name;
72              
73             # Volume is for compatibility, e.g. Windows
74 0         0 my ($file_volume, $file_dir, $target_file_name)
75             = File::Spec->splitpath($target_file_path);
76              
77             return sub {
78 0     0   0 my ($file_name) = @_;
79              
80 0         0 return File::Spec->catpath($file_volume, $file_dir, $file_name);
81             }
82 0         0 }
83              
84             # Returns the name of the first mapped Barriers file of this BarMap
85             # mapping.
86             sub first_mapped_file {
87 1     1 1 11 my $self = shift;
88 1         33 my $first_file = $self->_mapped_files->[0];
89 1         9 return $first_file;
90             }
91              
92             # Returns all minima of a given Barriers file of this BarMap mapping.
93             # Arguments:
94             # barriers_file: file from which all minima should be retrieved
95             sub mapped_mins {
96 2     2 1 4198 my ($self, $barriers_file) = @_;
97 2   66     80 my $min_mapping = $self->_min_mapping->{$barriers_file}
98             // confess "File '$barriers_file' not found in mapping";
99              
100             # Sort unordered hashkeys numerically. This should be numbers 1..n, but
101             # who knows what the user feeds us ...
102 1         24 my @mins = sort {$a <=> $b} keys %$min_mapping;
  135         204  
103              
104 1         10 return @mins;
105             }
106              
107             # Given a Barriers file, return its full path. The file is assumed to
108             # reside in the same directory as the BarMap mapping file.
109             # Arguments:
110             # barriers_file: The Barriers file for which the path is to be computed.
111             # Returns the path to the given barriers file.
112             sub path_of_file {
113 0     0 1 0 my ($self, $barriers_file) = @_;
114 0         0 my $barriers_file_path = $self->_path_builder->($barriers_file);
115 0         0 return $barriers_file_path;
116             }
117              
118             # Returns the path to the first mapped Barriers file of this BarMap
119             # mapping.
120             sub first_mapped_path {
121 0     0 1 0 my $self = shift;
122 0         0 my $first_path = $self->path_of_file($self->first_mapped_file);
123 0         0 return $first_path;
124             }
125              
126             around BUILDARGS => sub {
127             my ($orig, $class) = splice @_, 0, 2;
128             my @args;
129             if ( @_ == 1
130             and (not reftype $_[0]
131             or reftype $_[0] eq reftype \*STDIN
132             )
133             ) {
134             my $data_handle;
135             if (not reftype $_[0]) { # file name given
136             my $barmap_file_name = shift;
137             open $data_handle, '<', $barmap_file_name;
138             push @args, (file_name => $barmap_file_name);
139             }
140             elsif (reftype $_[0] eq reftype \*STDIN) { # file handle given
141             $data_handle = shift;
142             }
143             else {
144             confess 'Invalid constructor call';
145             }
146             my ($min_mapping, $mapped_files)
147             = $class->_process_barmap_file($data_handle);
148             push @args, (
149             _min_mapping => $min_mapping,
150             _mapped_files => $mapped_files,
151             );
152             }
153             else {
154             @args = @_;
155             }
156              
157             return $class->$orig(@args);
158             };
159              
160             sub BUILD {
161 4     4 0 13 my $self = shift;
162 4         152 $self->_min_mapping; # force construction of lazy attribute
163             }
164              
165             # Set up the file mapping objects as a "hashed double-linked list"
166             sub _build_file_mapping {
167 3     3   10 my ($self) = @_;
168             # my ($to_file, $from_file, );
169 3         14 my @mapped_files = $self->mapped_files;
170              
171             # Construct mapping entry objects
172             my %mapping
173 3         21 = map { $_ => Bio::RNA::BarMap::Mapping::FileMappingEntry->new(
  96         3534  
174             name => $_,
175             )
176             }
177             @mapped_files;
178              
179             # Set links to previous and following entries
180             $mapping{$mapped_files[$_]}->from($mapping{$mapped_files[$_-1]})
181 3         167 foreach 1..$#mapped_files;
182             $mapping{$mapped_files[$_]}->to($mapping{$mapped_files[$_+1]})
183 3         139 foreach 0..($#mapped_files-1);
184              
185 3         160 return \%mapping;
186             }
187              
188             sub _process_min_mapping_header {
189 4     4   10 my $class = shift;
190 4         9 my $data_handle = shift;
191              
192             # Read header, remove leading '#'
193 4         179 my $header_line = <$data_handle>;
194 4 50 33     70 confess 'BarMap file empty or header does not start with "#"'
195             unless defined $header_line and $header_line =~ s/^#//;
196 4         28 chomp $header_line;
197             # Header contains names of mapped files as column names
198 4         100 my @mapped_files = split /\s+/, $header_line;
199 4 50       26 confess 'Found only one mapped file' unless @mapped_files > 1;
200              
201 4         19 return \@mapped_files;
202             }
203              
204             # Split minima separated by ~> or -> and space.
205             sub _get_min_entry_mins_and_types {
206 1096     1096   1868 my $class = shift;
207 1096         3199 my ($line) = @_;
208              
209 1096         2732 chomp $line;
210 1096         5644 $line =~ s/^\s+//; # trim leading space
211 1096         2038 my @mapping_types = do { # store type of mapping (exact?)
212 1096         10928 my @arrows = $line =~ /[-~]>/g;
213             # Convert arrows to strings. Append undef for last minimum
214             # which is not mapped to anything (aligns indices or arrays).
215 1096         2541 ((map {Bio::RNA::BarMap::Mapping::Type->new($_)} @arrows), undef);
  12772         394570  
216             };
217 1096         19719 my @mins = split /\s*[-~]>\s*/, $line;
218 1096 100       4262 if ($mins[0] eq q{}) { # drop empty first field
219 1088         1934 shift @mins;
220 1088         2245 shift @mapping_types; # line started with an arrow
221             }
222             confess "Invalid minimum, needs to be a whole number in line\n$line"
223 1096 50   12780   38095 if any {not /^\d+$/} @mins;
  12780         28590  
224              
225 1096         5705 return (\@mins, \@mapping_types);
226             }
227              
228             sub _process_min_mapping_entries {
229 4     4   16 my $class = shift;
230 4         14 my ($data_handle, $mapped_files_ref) = @_;
231              
232 4         8 my %min_mapping;
233 4         64 my @rev_mapped_files = reverse @$mapped_files_ref;
234 4         68 while ((my $line = <$data_handle>)) {
235 1096         3422 my ($mins_ref, $mapping_types_ref)
236             = $class->_get_min_entry_mins_and_types($line);
237              
238             # Consider reversed arrays to easily align their ends
239 1096         6924 my @rev_mins = reverse @$mins_ref;
240 1096         3521 my @rev_mapping_types = reverse @$mapping_types_ref;
241 1096 50       2902 confess "Found too many minima in the following line:\n$line"
242             if @rev_mins > @rev_mapped_files;
243 1096 50       2601 confess 'Found wrong number of mapping arrows in the following ',
244             "line:\n$line"
245             if @rev_mins != @rev_mapping_types;
246              
247             # Create mapping entry for last file if not existent yet
248 1096         2728 my $to_file = $rev_mapped_files[0];
249             my $to_entry
250 1096   66     18477 = $min_mapping{$to_file}{$rev_mins[0]}
251             ||= Bio::RNA::BarMap::Mapping::MinMappingEntry->new(
252             index => $rev_mins[0],
253             );
254              
255             # Create mapping entries for all previous files if not existent yet
256 1096         3557 for my $i (1..$#rev_mins) {
257             # Create from-entry if non-existent
258 11684         26619 my $from_file = $rev_mapped_files[$i];
259             my $from_entry
260 11684   66     275907 = $min_mapping{$from_file}{$rev_mins[$i]}
261             //= Bio::RNA::BarMap::Mapping::MinMappingEntry->new(
262             index => $rev_mins[$i],
263             );
264              
265 11684 100       430152 if ($from_entry->has_to) {
266             # Check for mappings degenerated by coarsify_bmap.pl, i.e. one
267             # minimum mapped to several other minima.
268 4952 50       159324 confess join q{ }, 'State', $from_entry->index, 'from file',
269             "'$from_file' was already mapped to state",
270             $from_entry->to->index, "in file '$to_file', but is ",
271             'now remapped to state', $to_entry->index,
272             '(are you using a coarse-grained BarMap file?)'
273             if $from_entry->to->index != $to_entry->index;
274             }
275             else {
276             # Set forward and backward links for new mapping entries.
277 6732         221080 $from_entry->to($to_entry);
278 6732         235257 $from_entry->to_type($rev_mapping_types[$i]);
279 6732         17447 $to_entry->add_from($from_entry); # 'from' is a list
280             }
281              
282 11684         29130 $to_file = $from_file;
283 11684         58317 $to_entry = $from_entry; # next entry in line maps to current
284             }
285             }
286              
287 4         70 return \%min_mapping;
288             }
289              
290             # Construct the mininum mapping and the Barriers file mapping hashes by
291             # reading the BarMap file from the provided _data_handle.
292             sub _process_barmap_file {
293 4     4   14 my ($class, $barmap_handle) = @_;
294              
295 4         17 my $mapped_files_ref
296             = $class->_process_min_mapping_header($barmap_handle);
297              
298 4         58 my $min_mapping_ref
299             = $class->_process_min_mapping_entries(
300             $barmap_handle,
301             $mapped_files_ref
302             );
303              
304 4         24 return ($min_mapping_ref, $mapped_files_ref);
305             }
306              
307             # Map a Barriers file to its immediate successor file.
308             # Arguments:
309             # from_file: Barriers file to be mapped.
310             # Returns the immediate successor Barriers file of from_file, or undef if
311             # from_file points to the last Barriers file.
312             sub map_file {
313 149     149 1 3425 my ($self, $from_file) = @_;
314              
315 149         4456 my $file_map = $self->_file_mapping->{$from_file};
316 149 100       439 confess "Cannot map file '$from_file': not contained in BarMap file"
317             unless defined $file_map;
318              
319 147 100       4854 return defined $file_map->to ? $file_map->to->name
320             : undef;
321             }
322              
323             # Given a path to Barriers file, map the Barriers file to its immediate
324             # successor file and return its path.
325             # Arguments:
326             # from_path: Path of Barriers file to be mapped.
327             # Returns the path of the Barriers file that from_path was mapped to, or
328             # undef if from_path points to the last Barriers file.
329             sub map_path {
330 0     0 1 0 my ($self, $from_path) = @_;
331 0         0 my $from_file = (File::Spec->splitpath($from_path))[2];
332 0         0 my $to_file = $self->map_file($from_file);
333 0         0 my $to_path = $self->path_from_file($to_file);
334 0         0 return $to_path;
335             }
336              
337             # (Inversely) map a Barriers file to its immediate predecessor file.
338             # Arguments:
339             # to_file: Barriers file to be mapped to its predecessor.
340             # Returns the immediate predecessor Barriers file of to_file, or undef if
341             # to_file points to the first Barriers file.
342             sub map_file_inv {
343 5     5 1 4275 my ($self, $to_file) = @_;
344              
345 5         190 my $file_map = $self->_file_mapping->{$to_file};
346 5 100       25 confess "Cannot map file '$to_file': not contained in BarMap file"
347             unless defined $file_map;
348              
349 4 100       140 return defined $file_map->from ? $file_map->from->name
350             : undef;
351             }
352              
353             # Given a path to Barriers file, (inversely) map the Barriers file to its
354             # immediate predecessor file and return its path.
355             # Arguments:
356             # to_path: Path of Barriers file to be inversely mapped.
357             # Returns the path of the predecessor Barriers file of to_path, or undef
358             # if to_path points to the first Barriers file.
359             sub map_path_inv {
360 0     0 1 0 my ($self, $to_path) = @_;
361 0         0 my $to_file = (File::Spec->splitpath($to_path))[2];
362 0         0 my $from_file = $self->map_file_inv($to_file);
363 0         0 my $from_path = $self->path_from_file($from_file);
364 0         0 return $from_path;
365             }
366              
367             # Map a given minimum from a given Barriers file to its corresponding
368             # minimum in the next Barriers file. In list context, the mapping type is
369             # returned, too. The mapping type tells whether a minimum was mapped
370             # exactly (->) or approximately (~>), and is an object of class
371             # Bio::RNA::BarMap::Mapping::Type.
372             # Arguments:
373             # from_file: The Barriers file of from_min.
374             # from_min: The minimum to be mapped.
375             # In scalar context, returns the corresponding minimum of from_min in the
376             # next Barriers file, or undef if from_file is the last Barriers file of
377             # the mapping. In list context, the mapping type as well as the
378             # corresponding minimum is returned.
379             sub map_min_step {
380 153     153 1 26077 my ($self, $from_file, $from_min) = @_;
381              
382             # Get mappings of from_file.
383 153   66     4502 my $min_mapping = $self->_min_mapping->{$from_file}
384             // confess "File '$from_file' not found in mapping";
385              
386             # Get mapping of from_min in from_file.
387 152   100     511 my $to_map = $min_mapping->{$from_min}
388             // confess "Minimum $from_min not found in file '$from_file'";
389              
390             # If from_file is the final barriers file, the state won't map.
391 150 50       4865 return if not defined $to_map->to;
392              
393             # Map minimum.
394 150         4900 my $to_index = $to_map->to->index;
395 150         5003 my $to_mapping_type = $to_map->to_type;
396              
397 150 100       671 return wantarray ? ($to_mapping_type, $to_index) : $to_index;
398             }
399              
400             # Map given minimum from a given Barriers file to its corresponding
401             # minimum in another (successor) Barriers file. In list context, the
402             # mapping type is returned, too. The mapping type tells whether a minimum
403             # was mapped exactly (->) or approximately (~>), and is an object of class
404             # Bio::RNA::BarMap::Mapping::Type. The mapping is considered exact iff all
405             # mapping steps from the initial to the target Barriers file are exact;
406             # otherwise, the mapping is approximate. If the given successor Barriers
407             # file is not actually a successor of the initial Barriers file, an
408             # exception is raised.
409             # Arguments:
410             # from_file: The Barriers file of from_min.
411             # from_min: The minimum to be mapped.
412             # to_file: Target file for which the corresponding minimum is to be
413             # determined.
414             # In scalar context, returns the corresponding minimum of from_min in the
415             # target Barriers file. In list context, the mapping type as well as the
416             # corresponding minimum is returned.
417             sub map_min {
418 20     20 1 18718 my ($self, $from_file, $from_min, $to_file) = @_;
419              
420 20         40 my ($next_file, $next_min, $current_mapping_type);
421 20         69 my $mapping_type = Bio::RNA::BarMap::Mapping::Type->exact;
422 20         69 while (defined ($next_file = $self->map_file($from_file))) {
423 142         383 ($current_mapping_type, $next_min)
424             = $self->map_min_step($from_file, $from_min);
425             # One approx mapping step makes entire mapping chain approx.
426 141 100       400 $mapping_type = Bio::RNA::BarMap::Mapping::Type->approx
427             if $current_mapping_type->is_approx();
428              
429 141 100       645 return wantarray ? ($mapping_type, $next_min) : $next_min
    100          
430             if $next_file eq $to_file;
431              
432 124         572 ($from_file, $from_min) = ($next_file, $next_min);
433             # destination file not reached yet, continue
434             }
435 1         19 confess "File '$_[1]' is not mapped to file '$to_file'";
436             }
437              
438             # Convenience wrapper for map_min() which only returns the mapping type,
439             # but not the target minimum.
440             sub get_mapping_type {
441 8     8 1 1804 my ($self, $from_file, $from_min, $to_file) = @_;
442 8         20 my ($mapping_type) = $self->map_min($from_file, $from_min, $to_file);
443 8         26 return $mapping_type;
444             }
445              
446             # Convenience wrapper for map_min() which only returns the mapping type,
447             # converted to its corresponding arrow string. An exact mapping is
448             # converted to arrow '->', an approximate mapping to arrow '~>'.
449             sub get_mapping_arrow {
450 4     4 1 3401 my ($self, $from_file, $from_min, $to_file) = @_;
451 4         14 my $mapping_type
452             = $self->get_mapping_type($from_file, $from_min, $to_file);
453 4         15 my $mapping_arrow = $mapping_type->arrow();
454 4         129 return $mapping_arrow;
455             }
456              
457             # Get all minima in the preceding Barriers file that map to a given
458             # minimum from a given Barriers file.
459             # Arguments:
460             # to_file: The Barriers file of the target minimum.
461             # to_min: The target minimum to which the returned minima are mapped.
462             # Returns a list of all minima that are mapped to the target minimum.
463             sub map_min_inv_step {
464 0     0 1   my ($self, $to_file, $to_min) = @_;
465              
466             # Minima are only part of the mapping if they map to something or
467             # something maps to them, so the mins of the last Barriers file may
468             # not be contained.
469 0           my $to_min_entry = $self->_min_mapping->{$to_file}{$to_min};
470 0 0         return unless defined $to_min_entry;
471              
472 0           my @from_mins = $to_min_entry->get_from;
473 0           my @from_indices = map {$_->index} @from_mins;
  0            
474 0           return @from_indices;
475             }
476              
477             # Get all minima in a given Barriers file that map to a given
478             # minimum from another Barriers file.
479             # Arguments:
480             # to_file: The Barriers file of the target minimum.
481             # to_min: The target minimum to which the returned minima are mapped.
482             # from_file: The source Barriers file from which the returned minima
483             # are.
484             # Returns a list of all minima from the source Barriers file that are
485             # mapped to the target minimum in the target Barriers file.
486             sub map_min_inv {
487 0     0 1   my ($self, $to_file, $to_min, $from_file) = @_;
488              
489 0           my ($prev_file, @prev_mins);
490 0           my @to_mins = ($to_min);
491 0           while (defined ($prev_file = $self->map_file_inv($to_file))) {
492 0           @prev_mins = (); # clear list
493             push @prev_mins, $self->map_min_inv_step($to_file, $_)
494 0           foreach @to_mins;
495             # Do not return () before ensuring prev_file eq from_file, because
496             # otherwise we would not return an error if from_file is never
497             # reached.
498             #return () unless @to_mins; # no mins map, stop here
499 0 0         return @prev_mins if $prev_file eq $from_file;
500              
501 0           ($to_file, @to_mins) = ($prev_file, @prev_mins);
502             # destination file not reached yet, continue
503             }
504 0           confess "map_min_inv: '$from_file' is not mapped to '$_[1]'";
505             }
506              
507             __PACKAGE__->meta->make_immutable;
508              
509             1; # End of Bio::RNA::BarMap::Mapping
510              
511              
512             __END__
513              
514             =pod
515              
516             =encoding UTF-8
517              
518             =head1 NAME
519              
520             Bio::RNA::BarMap::Mapping - Parse and query I<BarMap> mappings.
521              
522             =head1 SYNOPSIS
523              
524             use v5.12; # for 'say()' and '//' a.k.a. logical defined-or
525             use Bio::RNA::BarMap;
526              
527             # Parse a BarMap output file.
528             my $barmap_file = 'N1M7_barmap_1.out'; # e.g. the test data in t/data/
529             my $mapping = Bio::RNA::BarMap::Mapping->new($barmap_file);
530              
531             # Print mapped Barriers files.
532             say join q{ }, $mapping->mapped_files;
533              
534             # Map a file.
535             my $from_file = '8.bar'; # one of the mapped .bar files
536             my $to_file = $mapping->map_file($from_file); # last file maps to undef
537             say "$from_file is mapped to ", $to_file // "nothing";
538             say "The other way round: predecessor file of $to_file is ",
539             $mapping->map_file_inv($to_file)
540              
541             # Map minimum 2 from file 8.bar to the next file.
542             my $from_min = 2;
543             my $to_min = $mapping->map_min_step($from_file, $from_min);
544              
545             # Map to an arbitrary file (only forward direction!)
546             $to_file = '15.bar';
547             $to_min = $mapping->map_min($from_file, $from_min, $to_file);
548              
549             =head1 DESCRIPTION
550              
551             This class is the main class of the Bio::RNA::BarMap distribution. It parses
552             the mapping generated by I<BarMap> and provides methods to easily query the
553             mapping of individual states and files.
554              
555             =head1 METHODS
556              
557             =head2 Bio::RNA::BarMap::Mapping->new($barmap_file)
558              
559             Construct a new mapping object from a path or a handle to a I<BarMap> mapping
560             file.
561              
562             =head2 $mapping->first_mapped_file()
563              
564             Returns the name of the first mapped I<Barriers> file of this I<BarMap>
565             mapping.
566              
567             =head2 $mapping->mapped_files()
568              
569             Returns a list of all I<Barriers> files of the mapping file.
570              
571             =head2 $mapping->mapped_mins($barriers_file)
572              
573             Returns a list of all minima from C<$barriers_file> found in the mapping file.
574              
575             =head2 $mapping->path_of_file($barriers_file)
576              
577             Given a C<$barriers_file>, return its full path. The file is assumed to
578             reside in the same directory as the I<BarMap> mapping file. Useful when the
579             mapping file is not in the current working directory.
580              
581             =head2 $mapping->first_mapped_path()
582              
583             Returns the path to the first mapped Barriers file of this I<BarMap>
584             mapping.
585              
586             =head2 $mapping->map_file($from_file)
587              
588             Return the immediate successor file of I<Barriers> file C<$from_file> in the
589             mapping, or C<undef> if C<$from_file> is the last one.
590              
591             =head2 $mapping->map_path($barriers_file_path)
592              
593             Like C<map_file()>, but takes and returns a full path to a I<Barriers> file.
594              
595             =head2 $mapping->map_file_inv($to_file)
596              
597             (Inversely) map I<Barriers> file C<to_file> to its immediate predecessor file
598             in the mapping, or to C<undef> if it is the first one.
599              
600             =head2 $mapping->map_path_inv()
601              
602             Like C<map_file_inv()>, but takes and returns a full path to a I<Barriers>
603             file.
604              
605             =head2 $mapping->map_min_step($from_file, $from_min)
606              
607             Map minimum C<$from_min> from I<Barriers> file C<$from_file> to its
608             corresponding minimum in the next I<Barriers> file.
609              
610             In scalar context, only the corresponding minimum is returned. In list
611             context, both the mapping type and the corresponding minimum are returned (in
612             that order). The mapping type tells whether a minimum was mapped exactly
613             (C<-E<gt>>) or approximately (C<~E<gt>>), and is an object of class
614             L<Bio::RNA::BarMap::Mapping::Type>.
615              
616             =head2 $mapping->map_min($from_file, $from_min, $to_file)
617              
618             Map minimum C<$from_min> from I<Barriers> file C<$from_file> to its
619             corresponding minimum in the I<Barriers> file C<$to_file>. This is achieved by
620             iteratively applying C<map_min_step()> until reaching the requested target
621             file.
622              
623             In scalar context, only the corresponding minimum is returned. In list
624             context, both the mapping type and the corresponding minimum are returned (in
625             that order). The mapping type tells whether a minimum was mapped exactly
626             (C<-E<gt>>) or approximately (C<~E<gt>>), and is an object of class
627             L<Bio::RNA::BarMap::Mapping::Type>. A mapping is considered exact if and only
628             if the mapping was exact in all individual mapping steps.
629              
630             =head2 $mapping->get_mapping_type($from_file, $from_min, $to_file)
631              
632             Convenience wrapper for C<map_min()> that only returns the mapping type,
633             but not the target minimum.
634              
635             =head2 $mapping->get_mapping_arrow()
636              
637             Convenience wrapper for C<map_min()> that only returns the arrow
638             representation of the mapping type, but not the target minimum. An exact
639             mapping is converted to arrow C<-E<gt>>, an approximate mapping to arrow
640             C<~E<gt>>.
641              
642             =head2 $mapping->map_min_inv_step($to_file, $to_min)
643              
644             Returns all minima in the preceding I<Barriers> file that map to
645             minimum C<$to_min> in file C<$to_file>.
646              
647             =head2 $mapping->map_min_inv($to_file, $to_min, $from_file)
648              
649             Returns all minima in I<Barriers> file C<$to_file> that map to
650             minimum C<$to_min> in file C<$to_file>.
651              
652              
653             =head1 AUTHOR
654              
655             Felix Kuehnl, C<< <felix at bioinf.uni-leipzig.de> >>
656              
657             =head1 BUGS
658              
659             Please report any bugs or feature requests by raising an issue at
660             L<https://github.com/xileF1337/Bio-RNA-BarMap/issues>.
661              
662             You can also do so by mailing to C<bug-bio-rna-barmap at rt.cpan.org>,
663             or through the web interface at
664             L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bio-RNA-BarMap>. I will be
665             notified, and then you'll automatically be notified of progress on your bug as
666             I make changes.
667              
668              
669             =head1 SUPPORT
670              
671             You can find documentation for this module with the perldoc command.
672              
673             perldoc Bio::RNA::BarMap
674              
675              
676             You can also look for information at the official BarMap website:
677              
678             L<https://www.tbi.univie.ac.at/RNA/bar_map/>
679              
680              
681             =over 4
682              
683             =item * Github: the official repository
684              
685             L<https://github.com/xileF1337/Bio-RNA-BarMap>
686              
687             =item * RT: CPAN's request tracker (report bugs here)
688              
689             L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Bio-RNA-BarMap>
690              
691             =item * AnnoCPAN: Annotated CPAN documentation
692              
693             L<http://annocpan.org/dist/Bio-RNA-BarMap>
694              
695             =item * CPAN Ratings
696              
697             L<https://cpanratings.perl.org/d/Bio-RNA-BarMap>
698              
699             =item * Search CPAN
700              
701             L<https://metacpan.org/release/Bio-RNA-BarMap>
702              
703             =back
704              
705              
706             =head1 ACKNOWLEDGEMENTS
707              
708              
709             =head1 LICENSE AND COPYRIGHT
710              
711             Copyright 2019-2021 Felix Kuehnl.
712              
713             This program is free software: you can redistribute it and/or modify
714             it under the terms of the GNU General Public License as published by
715             the Free Software Foundation, either version 3 of the License, or
716             (at your option) any later version.
717              
718             This program is distributed in the hope that it will be useful,
719             but WITHOUT ANY WARRANTY; without even the implied warranty of
720             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
721             GNU General Public License for more details.
722              
723             You should have received a copy of the GNU General Public License
724             along with this program. If not, see L<http://www.gnu.org/licenses/>.
725              
726             =cut
727              
728             # End of Bio::RNA::BarMap::Mapping / Bio/RNA/BarMap/Mapping.pm