Skip to content
Snippets Groups Projects
Commit ad9f6b52 authored by Web Admin's avatar Web Admin
Browse files

update for sets

parent b6b27a92
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,7 @@ use strict;
use POSIX;
use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
use Bio::EnsEMBL::DensityFeature;
use Bio::EnsEMBL::DensityFeatureSet;
use Bio::EnsEMBL::DensityType;
use Bio::EnsEMBL::Utils::Exception qw(throw warning);
......@@ -499,5 +500,13 @@ sub store{
}
sub fetch_Featureset_by_Slice {
my $self = shift;
my $dfeats = $self->fetch_all_by_Slice(@_);
my $dfeatSet = new Bio::EnsEMBL::DensityFeatureSet($dfeats);
return ($dfeatSet);
}
1;
......@@ -100,8 +100,9 @@ sub new {
$self->{'density_value'} = $dv;
$self->{'slice'} = $seq_region;
$self->{'seq_region_start'} = $start;
$self->{'seq_region_end'} = $end;
$self->{'start'} = $start;
$self->{'end'} = $end;
return $self;
}
......@@ -217,6 +218,97 @@ sub density_type{
return $self->{'density_type'};
}
###BG########
=head2 start
Title : start
Usage : $obj->start($newval)
Function:
Returns : value of start
Args : newvalue (optional)
=cut
sub start{
my $obj = shift;
if( @_ ) {
my $value = shift;
$obj->{'start'} = $value;
}
return $obj->{'start'};
}
=head2 end
Title : end
Usage : $obj->end($newval)
Function:
Returns : value of end
Args : newvalue (optional)
=cut
sub end{
my $obj = shift;
if( @_ ) {
my $value = shift;
$obj->{'end'} = $value;
}
return $obj->{'end'};
}
=head2 scaledvalue
Title : scaledvalue
Usage : $obj->scaledvalue($newval)
Function:
Returns : this object's scaled value
Args : newvalue (optional)
=cut
sub scaledvalue{
my $obj = shift;
if( @_ ) {
my $scaledvalue = shift;
$obj->{'scaledvalue'} = $scaledvalue;
}
return $obj->{'scaledvalue'};
}
=head2 url
Title : url
Usage : $obj->url($newval)
Function:
Returns : this object's url
Args : newvalue (optional)
=cut
sub url{
my $obj = shift;
if( @_ ) {
my $url = shift;
$obj->{'url'} = $url;
}
return $obj->{'url'};
}
1;
......
#
# Ensembl module for Bio::EnsEMBL::DensityFeatureSet
#
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
=head1 NAME
Bio::EnsEMBL::DensityFeatureSet - A feature representing a set of density features
=head1 SYNOPSIS
use Bio::EnsEMBL::DensityFeatureSet;
my $densitySet = Bio::EnsEMBL::DensityFeatureSet->new
( -bin_array = @out,
-max_value = $max_value,
-min_value = $min_value,
);
=head1 DESCRIPTION
A density feature set is a wrap around a array of density features with additional information about the collective density feature set, such as max_min_values and scale factors etc.
a given region.
This module is part of the Ensembl project http://www.ensembl.org
=head1 CONTACT
Post comments/questions to the ensembl development list: ensembl-dev@ebi.ac.uk
=head1 METHODS
=cut
use strict;
use warnings;
package Bio::EnsEMBL::DensityFeatureSet;
use Bio::EnsEMBL::Utils::Argument qw(rearrange);
use Bio::EnsEMBL::Utils::Exception qw(throw);
use Data::Dumper;
=head2 new
Description: Creates a new density feature set.
Returntype : Bio::EnsEMBL::DensityFeatureSet
Exceptions : throw if invalid density value type is provided
Caller : general
=cut
sub new {
my $class = shift;
my $max_value = undef;
my $min_value = undef;
my($dfeats, $stretch, $scale_to_fit) =
rearrange(['FEATURES', 'STRETCH', 'SCALE_TO_FIT'], @_);
foreach (@$dfeats){
my $value = $_->density_value;
$max_value = $value if (!defined($max_value) || $value > $max_value);
$min_value = $value if (!defined($min_value) || $value < $min_value);
}
return bless {'bin_array' => $dfeats,
'stretch' => $stretch,
'scale_to_fit' => $scale_to_fit,
'min_value' => $min_value,
'max_value' => $max_value}, $class;
}
=head2 stretch
Title : stretch
Usage : $obj->stretch($newval)
Function: gets/sets a boolean for whether we should stretch the data over the
range (i.e. from min to max rather than absolute numbers).
Returns : value of _stretch
Args : newvalue (optional)
=cut
sub stretch{
my $self = shift;
$self->{'stretch'} = shift if(@_);
return $self->{'stretch'};
}
=head2 scale_to_fit
Title : scale_to_fit
Usage : $obj->scale_to_fit($newval)
Function: gets/sets the number that the BinValues are to be scaled against -
i.e. the greatest BinValue->value will be scaled to this number, and the rest
scaled in proportion.
Returns : scale_to_fit value
Args : newvalue (optional)
=cut
sub scale_to_fit{
my $self = shift;
$self->{'scale_to_fit'} = shift if (@_);
return $self->{'scale_to_fit'};
}
=head2 colour
Title : colour
Usage : $obj->colour($newval)
Function:
Returns : value of colour
Args : newvalue (optional)
=cut
sub colour{
my $self = shift;
$self->{'color'} = shift if(@_);
return $self->{'color'};
}
=head2 label
Title : label
Usage : $obj->label($newval)
Function:
Returns : value of label
Args : newvalue (optional)
=cut
sub label{
my $self = shift;
$self->{'label'} = shift if (@_);
return $self->{'label'};
}
=head2 label2
Title : label2
Usage : $obj->label2($newval)
Function:
Returns : value of label2
Args : newvalue (optional)
=cut
sub label2{
my $self = shift;
$self->{'label2'} = shift if (@_);
return $self->{'label2'};
}
=head2 get_all_binvalues
Title : get_all_binvalues
Usage : my @binvalue_objects = @{$BVSet->get_all_binvalues};
Function: scales all the binvalues by the scale_factor and returns them.
Example :
Returns : array of BinValue objects
Args : none
=cut
sub get_all_binvalues{
my $self = shift;
my $max_value = $self->max_value();
my $min_value = $self->min_value();
return [] if(!@{$self->{'bin_array'}});
my $width = $self->scale_to_fit() || $self->throw("Cannot scale values - scale_to_fit has not been set");
if ($self->stretch && ($max_value-$min_value) ){
foreach my $bv (@{ $self->{'bin_array'}}){
my $scaledval = (($bv->density_value - $min_value) / ($max_value-$min_value) )* $width;
$bv->scaledvalue($scaledval);
}
} elsif($max_value) {
foreach my $bv (@{ $self->{'bin_array'}}){
my $scaledval = ($bv->density_value / $max_value) * $width;
$bv->scaledvalue($scaledval);
}
} else {
foreach my $bv (@{ $self->{'bin_array'}}){
$bv->scaledvalue(0);
}
}
return $self->{'bin_array'};
}
sub max_value{ $_[0]->{'max_value'};}
sub min_value{ $_[0]->{'min_value'};}
1;
sub size {
my $self = shift;
return scalar @{$self->{'bin_array'}};
}
1;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment