| 1 | package Bio::RNA::BarMap::Mapping; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use 5.012; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use autodie qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use List::Util qw(any); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use Bio::RNA::BarMap::Mapping::MinMappingEntry; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Bio::RNA::BarMap::Mapping::FileMappingEntry; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # Hash mapping each minimum to the one it is mapped to in the next landscape. | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | 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 | 5 | 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 | 5 | has '_mapped_files' => ( | |||||||||||||||||||||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | ▶ | sub mapped_files { return @{ $_[0]->_mapped_files } } # dereference | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mapped_files: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | 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 | 5 | 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 | 0 | ▶ | sub _build_path_builder { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_path_builder: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | confess 'File name attribute needs to be set to build any paths' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | unless $self->has_file_name; | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my ($target_file_path) = $self->file_name; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # Volume is for compatibility, e.g. Windows | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my ($file_volume, $file_dir, $target_file_name) | |||||||||||||||||||||||||||||||||||||||||
| 75 | = File::Spec->splitpath($target_file_path); | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my ($file_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return File::Spec->catpath($file_volume, $file_dir, $file_name); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # Returns the name of the first mapped Barriers file of this BarMap | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # mapping. | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | sub first_mapped_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_mapped_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | my $first_file = $self->_mapped_files->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | 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 | 2 | ▶ | sub mapped_mins { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mapped_mins: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | my ($self, $barriers_file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | my $min_mapping = $self->_min_mapping->{$barriers_file} | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_min_mapping->{$barriers_file} // confess("File '${barriers_file}' not found in mapping")
MC/DC100%1/1
$self->_min_mapping->{$barriers_file} // confess("File '${barriers_file}' not found in mapping")
$self->_min_mapping->{$barriers_file}
Truth table100%2/2
A
A= $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 | my @mins = sort {$a <=> $b} keys %$min_mapping; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | 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 | 0 | ▶ | sub path_of_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_of_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my ($self, $barriers_file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $barriers_file_path = $self->_path_builder->($barriers_file); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return $barriers_file_path; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | # Returns the path to the first mapped Barriers file of this BarMap | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # mapping. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub first_mapped_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_mapped_path: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $first_path = $self->path_of_file($self->first_mapped_file); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return $first_path; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 4 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | my ($orig, $class) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 4 | my @args; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | ▶ | if ( @_ == 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@_ == 1 and !builtin::reftype($_[0]) || builtin::reftype($_[0]) eq builtin::reftype(\*STDIN)
not builtin::reftype($_[0]) or builtin::reftype($_[0]) eq builtin::reftype(\*STDIN)
MC/DC0%0/3
@_ == 1 and !builtin::reftype($_[0]) || builtin::reftype($_[0]) eq builtin::reftype(\*STDIN)
@_ == 1
not builtin::reftype($_[0])
builtin::reftype($_[0]) eq builtin::reftype(\*STDIN)
Truth table25%1/4
A and not(B) or C
A= @_ == 1B= not builtin::reftype($_[0])C= builtin::reftype($_[0]) eq builtin::reftype(\*STDIN)
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | and (not reftype $_[0] | ||||||||||||||||||||||||||||||||||||||||||
| 131 | or reftype $_[0] eq reftype \*STDIN | ||||||||||||||||||||||||||||||||||||||||||
| 132 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 133 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 4 | my $data_handle; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 4 | ▶ | if (not reftype $_[0]) { # file name given | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $barmap_file_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | open $data_handle, '<', $barmap_file_name; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | push @args, (file_name => $barmap_file_name); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | elsif (reftype $_[0] eq reftype \*STDIN) { # file handle given | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 4 | $data_handle = shift; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | confess 'Invalid constructor call'; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | my ($min_mapping, $mapped_files) | |||||||||||||||||||||||||||||||||||||||||
| 147 | = $class->_process_barmap_file($data_handle); | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | push @args, ( | |||||||||||||||||||||||||||||||||||||||||
| 149 | _min_mapping => $min_mapping, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | _mapped_files => $mapped_files, | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 4 | return $class->$orig(@args); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 4 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | $self->_min_mapping; # force construction of lazy attribute | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | # Set up the file mapping objects as a "hashed double-linked list" | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 3 | ▶ | sub _build_file_mapping { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_file_mapping: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 168 | # my ($to_file, $from_file, ); | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | my @mapped_files = $self->mapped_files; | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | # Construct mapping entry objects | ||||||||||||||||||||||||||||||||||||||||||
| 172 | my %mapping | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | = map { $_ => Bio::RNA::BarMap::Mapping::FileMappingEntry->new( | |||||||||||||||||||||||||||||||||||||||||
| 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 | foreach 1..$#mapped_files; | |||||||||||||||||||||||||||||||||||||||||
| 182 | $mapping{$mapped_files[$_]}->to($mapping{$mapped_files[$_+1]}) | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 3 | foreach 0..($#mapped_files-1); | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | return \%mapping; | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 4 | ▶ | sub _process_min_mapping_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_min_mapping_header: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 4 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 4 | my $data_handle = shift; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | # Read header, remove leading '#' | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 4 | my $header_line = <$data_handle>; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | ▶ | confess 'BarMap file empty or header does not start with "#"' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $header_line and $header_line =~ s/^#//u
MC/DC0%0/2
defined $header_line and $header_line =~ s/^#//u
defined $header_line
$header_line =~ s/^#//u
Truth table33%1/3
A and B
A= defined $header_lineB= $header_line =~ s/^#//u
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | unless defined $header_line and $header_line =~ s/^#//; | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 4 | chomp $header_line; | |||||||||||||||||||||||||||||||||||||||||
| 197 | # Header contains names of mapped files as column names | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | my @mapped_files = split /\s+/, $header_line; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | ▶ | confess 'Found only one mapped file' unless @mapped_files > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 4 | return \@mapped_files; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | # Split minima separated by ~> or -> and space. | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 1096 | ▶ | sub _get_min_entry_mins_and_types { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_min_entry_mins_and_types: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 1096 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 1096 | my ($line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 1096 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 1096 | $line =~ s/^\s+//; # trim leading space | |||||||||||||||||||||||||||||||||||||||||
| 211 | 1096 | my @mapping_types = do { # store type of mapping (exact?) | |||||||||||||||||||||||||||||||||||||||||
| 212 | 1096 | 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 | ((map {Bio::RNA::BarMap::Mapping::Type->new($_)} @arrows), undef); | |||||||||||||||||||||||||||||||||||||||||
| 216 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 1096 | my @mins = split /\s*[-~]>\s*/, $line; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 1096 | ▶ | if ($mins[0] eq q{}) { # drop empty first field | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 1088 | shift @mins; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 1088 | 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 | ▶ | if any {not /^\d+$/} @mins; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 1096 | return (\@mins, \@mapping_types); | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | ▶ | sub _process_min_mapping_entries { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_min_mapping_entries: called CC=9 SCAR=22.2
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 4 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | my ($data_handle, $mapped_files_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 4 | my %min_mapping; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | my @rev_mapped_files = reverse @$mapped_files_ref; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | ▶ | while ((my $line = <$data_handle>)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 1096 | 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 | my @rev_mins = reverse @$mins_ref; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 1096 | my @rev_mapping_types = reverse @$mapping_types_ref; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 1096 | ▶ | confess "Found too many minima in the following line:\n$line" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | if @rev_mins > @rev_mapped_files; | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 1096 | ▶ | confess 'Found wrong number of mapping arrows in the following ', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | my $to_file = $rev_mapped_files[0]; | |||||||||||||||||||||||||||||||||||||||||
| 249 | my $to_entry | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 1096 | ▶ | = $min_mapping{$to_file}{$rev_mins[0]} | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$min_mapping{$to_file}{$rev_mins[0]} ||= "Bio::RNA::BarMap::Mapping::MinMappingEntry"->new("index", $rev_mins[0])
MC/DC0%0/2
$min_mapping{$to_file}{$rev_mins[0]} ||= "Bio::RNA::BarMap::Mapping::MinMappingEntry"->new("index", $rev_mins[0])
$min_mapping{$to_file}{$rev_mins[0]}
"Bio::RNA::BarMap::Mapping::MinMappingEntry"->new("index", $rev_mins[0])
Truth table66%2/3
A ||= B
A= $min_mapping{$to_file}{$rev_mins[0]}B= "Bio::RNA::BarMap::Mapping::MinMappingEntry"->new("index", $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 | for my $i (1..$#rev_mins) { | |||||||||||||||||||||||||||||||||||||||||
| 257 | # Create from-entry if non-existent | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 11684 | my $from_file = $rev_mapped_files[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 259 | my $from_entry | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 11684 | ▶ | = $min_mapping{$from_file}{$rev_mins[$i]} | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$min_mapping{$from_file}{$rev_mins[$i]} //= "Bio::RNA::BarMap::Mapping::MinMappingEntry"->new("index", $rev_mins[$i])
MC/DC0%0/2
$min_mapping{$from_file}{$rev_mins[$i]} //= "Bio::RNA::BarMap::Mapping::MinMappingEntry"->new("index", $rev_mins[$i])
$min_mapping{$from_file}{$rev_mins[$i]}
"Bio::RNA::BarMap::Mapping::MinMappingEntry"->new("index", $rev_mins[$i])
Truth table66%2/3
A //= B
A= $min_mapping{$from_file}{$rev_mins[$i]}B= "Bio::RNA::BarMap::Mapping::MinMappingEntry"->new("index", $rev_mins[$i])
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | //= Bio::RNA::BarMap::Mapping::MinMappingEntry->new( | ||||||||||||||||||||||||||||||||||||||||||
| 262 | index => $rev_mins[$i], | ||||||||||||||||||||||||||||||||||||||||||
| 263 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 11684 | ▶ | if ($from_entry->has_to) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | # Check for mappings degenerated by coarsify_bmap.pl, i.e. one | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # minimum mapped to several other minima. | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 4952 | ▶ | confess join q{ }, 'State', $from_entry->index, 'from file', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | $from_entry->to($to_entry); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 6732 | $from_entry->to_type($rev_mapping_types[$i]); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 6732 | $to_entry->add_from($from_entry); # 'from' is a list | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 11684 | $to_file = $from_file; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 11684 | $to_entry = $from_entry; # next entry in line maps to current | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 4 | 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 | 4 | ▶ | sub _process_barmap_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_barmap_file: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 4 | my ($class, $barmap_handle) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 4 | my $mapped_files_ref | |||||||||||||||||||||||||||||||||||||||||
| 296 | = $class->_process_min_mapping_header($barmap_handle); | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | my $min_mapping_ref | |||||||||||||||||||||||||||||||||||||||||
| 299 | = $class->_process_min_mapping_entries( | ||||||||||||||||||||||||||||||||||||||||||
| 300 | $barmap_handle, | ||||||||||||||||||||||||||||||||||||||||||
| 301 | $mapped_files_ref | ||||||||||||||||||||||||||||||||||||||||||
| 302 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 4 | 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 | 149 | ▶ | sub map_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_file: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 149 | my ($self, $from_file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 149 | my $file_map = $self->_file_mapping->{$from_file}; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 149 | ▶ | confess "Cannot map file '$from_file': not contained in BarMap file" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | unless defined $file_map; | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 147 | ▶ | return defined $file_map->to ? $file_map->to->name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub map_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_path: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my ($self, $from_path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my $from_file = (File::Spec->splitpath($from_path))[2]; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | my $to_file = $self->map_file($from_file); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my $to_path = $self->path_from_file($to_file); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 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 | 5 | ▶ | sub map_file_inv { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_file_inv: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 5 | my ($self, $to_file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 5 | my $file_map = $self->_file_mapping->{$to_file}; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 5 | ▶ | confess "Cannot map file '$to_file': not contained in BarMap file" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | unless defined $file_map; | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 4 | ▶ | return defined $file_map->from ? $file_map->from->name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub map_path_inv { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_path_inv: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my ($self, $to_path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $to_file = (File::Spec->splitpath($to_path))[2]; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | my $from_file = $self->map_file_inv($to_file); | |||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my $from_path = $self->path_from_file($from_file); | |||||||||||||||||||||||||||||||||||||||||
| 364 | 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 | 153 | ▶ | sub map_min_step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_min_step: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 153 | my ($self, $from_file, $from_min) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | # Get mappings of from_file. | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 153 | ▶ | my $min_mapping = $self->_min_mapping->{$from_file} | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_min_mapping->{$from_file} // confess("File '${from_file}' not found in mapping")
MC/DC100%1/1
$self->_min_mapping->{$from_file} // confess("File '${from_file}' not found in mapping")
$self->_min_mapping->{$from_file}
Truth table100%2/2
A
A= $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 | ▶ | my $to_map = $min_mapping->{$from_min} | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$min_mapping->{$from_min} // confess("Minimum $from_min not found in file '${from_file}'")
MC/DC100%1/1
$min_mapping->{$from_min} // confess("Minimum $from_min not found in file '${from_file}'")
$min_mapping->{$from_min}
Truth table100%2/2
A
A= $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 | ▶ | return if not defined $to_map->to; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | # Map minimum. | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 150 | my $to_index = $to_map->to->index; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 150 | my $to_mapping_type = $to_map->to_type; | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 150 | ▶ | return wantarray ? ($to_mapping_type, $to_index) : $to_index; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 20 | ▶ | sub map_min { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_min: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | 20 | my ($self, $from_file, $from_min, $to_file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 20 | my ($next_file, $next_min, $current_mapping_type); | |||||||||||||||||||||||||||||||||||||||||
| 421 | 20 | my $mapping_type = Bio::RNA::BarMap::Mapping::Type->exact; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 20 | ▶ | while (defined ($next_file = $self->map_file($from_file))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 142 | ($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 | ▶ | $mapping_type = Bio::RNA::BarMap::Mapping::Type->approx | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | if $current_mapping_type->is_approx(); | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 141 | ▶ | return wantarray ? ($mapping_type, $next_min) : $next_min | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | if $next_file eq $to_file; | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 124 | ($from_file, $from_min) = ($next_file, $next_min); | |||||||||||||||||||||||||||||||||||||||||
| 433 | # destination file not reached yet, continue | ||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 1 | 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 | 8 | ▶ | sub get_mapping_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_mapping_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 8 | my ($self, $from_file, $from_min, $to_file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 8 | my ($mapping_type) = $self->map_min($from_file, $from_min, $to_file); | |||||||||||||||||||||||||||||||||||||||||
| 443 | 8 | 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 | 4 | ▶ | sub get_mapping_arrow { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_mapping_arrow: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 4 | my ($self, $from_file, $from_min, $to_file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 4 | my $mapping_type | |||||||||||||||||||||||||||||||||||||||||
| 452 | = $self->get_mapping_type($from_file, $from_min, $to_file); | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 4 | my $mapping_arrow = $mapping_type->arrow(); | |||||||||||||||||||||||||||||||||||||||||
| 454 | 4 | 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 | 0 | ▶ | sub map_min_inv_step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_min_inv_step: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | 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 | ▶ | return unless defined $to_min_entry; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my @from_mins = $to_min_entry->get_from; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my @from_indices = map {$_->index} @from_mins; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub map_min_inv { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_min_inv: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | 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))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | return @prev_mins if $prev_file eq $from_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 5 | 1; # End of Bio::RNA::BarMap::Mapping | |||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | __END__ | ||||||||||||||||||||||||||||||||||||||||||