BioPerl
view release on metacpan or search on metacpan
Bio/Search/Tiling/MapTiling.pm view on Meta::CPAN
Title : range
Usage : $tiling->range(-type=>$type)
Function: Returns the extent of the longest tiling
as ($min_coord, $max_coord)
Returns : array of two scalar integers
Args : -type => one of 'hit', 'subject', 'query'
-context => strand/frame context string
=cut
sub range {
my ($self, $type, $context) = @_;
$self->_check_type_arg(\$type);
$self->_check_context_arg($type, \$context);
my @a = $self->_contig_intersection($type,$context);
return ($a[0][0], $a[-1][1]);
}
=head1 ACCESSORS
=head2 coverage_map
Title : coverage_map
Usage : $map = $tiling->coverage_map($type)
Function: Property to contain the coverage map calculated
by _calc_coverage_map() - see that for
details
Example :
Returns : value of coverage_map_$type as an array
Args : scalar $type: one of 'hit', 'subject', 'query'
default is 'query'
Note : getter
=cut
sub coverage_map{
my $self = shift;
my ($type, $context) = @_;
$self->_check_type_arg(\$type);
$self->_check_context_arg($type, \$context);
if (!defined $self->{"coverage_map_${type}_${context}"}) {
# following calculates coverage maps in all strands/frames
# if necessary
$self->_calc_coverage_map($type, $context);
}
# if undef is returned, then there were no hsps for given strand/frame
if (!defined $self->{"coverage_map_${type}_${context}"}) {
$self->warn("No HSPS present for type '$type' in context '$context' for this hit");
return undef;
}
return @{$self->{"coverage_map_${type}_${context}"}};
}
=head2 coverage_map_as_text
Title : coverage_map_as_text
Usage : $tiling->coverage_map_as_text($type, $legend_flag)
Function: Format a text-graphic representation of the
coverage map
Returns : an array of scalar strings, suitable for printing
Args : $type: one of 'query', 'hit', 'subject'
$context: strand/frame context string
$legend_flag: boolean; add a legend indicating
the actual interval coordinates for each component
interval and hsp (in the $type sequence context)
Example : print $tiling->coverage_map_as_text('query',1);
=cut
sub coverage_map_as_text{
my $self = shift;
my ($type, $context, $legend_q) = @_;
$self->_check_type_arg(\$type);
$self->_check_context_arg($type, \$context);
my @map = $self->coverage_map($type, $context);
my @ret;
my @hsps = $self->hit->hsps;
my %hsps_i;
require Tie::RefHash;
tie %hsps_i, 'Tie::RefHash';
@hsps_i{@hsps} = (0..$#hsps);
my @mx;
foreach (0..$#map) {
my @hspx = ('') x @hsps;
my @these_hsps = @{$map[$_]->[1]};
@hspx[@hsps_i{@these_hsps}] = ('*') x @these_hsps;
$mx[$_] = \@hspx;
}
untie %hsps_i;
push @ret, "\tIntvl\n";
push @ret, "HSPS\t", join ("\t", (0..$#map)), "\n";
foreach my $h (0..$#hsps) {
push @ret, join("\t", $h, map { $mx[$_][$h] } (0..$#map) ),"\n";
}
if ($legend_q) {
push @ret, "Interval legend\n";
foreach (0..$#map) {
push @ret, sprintf("%d\t[%d, %d]\n", $_, @{$map[$_][0]});
}
push @ret, "HSP legend\n";
my @ints = get_intervals_from_hsps($type,@hsps);
foreach (0..$#hsps) {
push @ret, sprintf("%d\t[%d, %d]\n", $_, @{$ints[$_]});
}
}
return @ret;
}
=head2 hit
Title : hit
Usage : $tiling->hit
Function:
Example :
Returns : The HitI object associated with the invocant
Args : none
Note : getter only
=cut
sub hit{
my $self = shift;
$self->warn("Getter only") if @_;
return $self->{'hit'};
}
=head2 hsps
Title : hsps
Usage : $tiling->hsps()
Function: Container for the HSP objects associated with invocant
Example :
Returns : an array of hsps associated with the hit
Args : on set, new value (an arrayref or undef, optional)
=cut
sub hsps{
my $self = shift;
return $self->{'hsps'} = shift if @_;
return @{$self->{'hsps'}};
}
=head2 contexts
Title : contexts
Usage : @contexts = $tiling->context($type) or
@indices = $tiling->context($type, $context)
Function: Retrieve the set of available contexts in the hit,
or the indices of hsps having the given context
(integer indices for the array returned by $self->hsps)
Returns : array of scalar context strings or
array of scalar positive integers
undef if no hsps in given context
Args : $type: one of 'query', 'hit', 'subject'
optional $context: context string
=cut
sub contexts{
( run in 1.580 second using v1.01-cache-2.11-cpan-39bf76dae61 )