Archive Ensembl HomeArchive Ensembl Home
DensityType.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 
00019 =cut
00020 
00021 =head1 NAME
00022 
00023 Bio::EnsEMBL::DensityType - A type representing a density, or percentage
00024 coverage etc. in a given region.
00025 
00026 =head1 SYNOPSIS
00027 
00028   use Bio::EnsEMBL::DensityType;
00029 
00030   $type = Bio::EnsEMBL::DensityType->new(
00031     -analysis   => $analysis,
00032     -blocksize  => 1000000,
00033     -value_type => $type
00034   );
00035 
00036 =head1 DESCRIPTION
00037 
00038 A density type represents a density, or percentage coverage etc. in a
00039 given region.
00040 
00041 =head1 METHODS
00042 
00043 =cut
00044 
00045 use strict;
00046 use warnings;
00047 
00048 package Bio::EnsEMBL::DensityType;
00049 
00050 use Bio::EnsEMBL::Storable;
00051 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
00052 use Bio::EnsEMBL::Utils::Exception qw(throw);
00053 
00054 use vars qw(@ISA);
00055 
00056 @ISA = qw(Bio::EnsEMBL::Storable);
00057 
00058 =head2 new
00059 
00060   Arg [..]   :  Takes a set of named arguments
00061   Example    : $dt = new Bio::EnsEMBL::DensityType::DensityType(
00062                 -analysis  =>  $analysis,
00063                 -blocksize =>  1e6,
00064                 -value_type => 'sum')
00065 
00066   Description: Creates a new Density Type object
00067   Returntype : Bio::EnsEMBL::DensityType
00068   Exceptions : blocksize > 0, 
00069                valuetype must be 'sum' or 'ratio',
00070                valid analysis object must be passed
00071   Caller     : general
00072   Status     : Stable
00073 
00074 =cut
00075 
00076 
00077 sub new {
00078   my $class = shift;
00079 
00080   my $self = $class->SUPER::new(@_);
00081 
00082   my ($analysis, $block_size, $value_type, $region_features) = 
00083     rearrange(['ANALYSIS','BLOCK_SIZE','VALUE_TYPE','REGION_FEATURES'],@_);
00084 
00085   if($analysis) {
00086     if(!ref($analysis) || !$analysis->isa('Bio::EnsEMBL::Analysis')) {
00087       throw('-ANALYSIS argument must be a Bio::EnsEMBL::Analysis not '.
00088             $analysis);
00089     }
00090   }
00091 
00092   if($value_type ne "sum" and $value_type ne "ratio"){
00093     throw('-VALUE_TYPE argument must be "ratio" or "sum" not *'.
00094       $value_type."*");
00095   }
00096 
00097   $block_size |= 0;
00098   $region_features |= 0;
00099 
00100   if(! ($block_size xor $region_features )){
00101     throw('Set either -BLOCK_SIZE or -REGION_FEATURES, not both'); 
00102   }
00103 
00104   if( $block_size <0 or $region_features < 0 ) {
00105     throw( 'No negative values for -BLOCK_SIZE or -REGION_FEATURES' );
00106   }
00107 
00108 
00109   $self->{'analysis'} = $analysis;
00110   $self->{'block_size'} = $block_size;
00111   $self->{'value_type'} = $value_type;
00112   $self->{'region_features'} = $region_features;
00113 
00114   return $self;
00115 }
00116 
00117 =head2 analysis
00118 
00119   Arg [1]    : Bio::EnsEMBL::Analysi
00120   Example    : none
00121   Description: get/set for attribute analysis
00122   Returntype : Bio::EnsEMBL::Analysis
00123   Exceptions : none
00124   Caller     : general
00125   Status     : Stable
00126 
00127 =cut
00128 
00129 sub analysis{
00130   my $self = shift;
00131 
00132   if(@_) {
00133     my $a = shift;
00134     if(defined($a) && (!ref($a) || !$a->isa('Bio::EnsEMBL::Analysis'))) {
00135       throw("Argument must be undef or a Bio::EnsEMBL::Analysis object.");
00136     }
00137     $self->{'analysis'} = $a;
00138   }
00139   return $self->{'analysis'};
00140 }
00141 
00142 =head2 value_type
00143 
00144   Arg [1]    : string $value_type
00145   Example    : none
00146   Description: gettter/setter for the 
00147   Returntype : float
00148   Exceptions : none
00149   Caller     : general
00150   Status     : Stable
00151 
00152 =cut
00153 
00154 sub value_type{
00155   my $self = shift;
00156   $self->{'value_type'} = shift if(@_);
00157   return $self->{'value_type'};
00158 }
00159 
00160 
00161 =head2 block_size
00162 
00163   Arg [1]    : int
00164   Example    : none
00165   Description: getter/setter for attribute block_size
00166   Returntype : int
00167   Exceptions : none
00168   Caller     : general
00169   Status     : Stable
00170 
00171 =cut
00172 
00173 sub block_size{
00174   my $self = shift;
00175   $self->{'block_size'} = shift if(@_);
00176   return $self->{'block_size'};
00177 }
00178 
00179 
00180 =head2 region_features
00181 
00182   Arg [1]    : int $region_features
00183   Example    : The number of features per seq_region inside this density_type..
00184   Description: get/set for attribute region_features
00185   Returntype : string
00186   Exceptions : none
00187   Caller     : general
00188 
00189 =cut
00190 
00191 sub region_features {
00192    my $self = shift;
00193   $self->{'region_features'} = shift if( @_ );
00194   return $self->{'region_features'};
00195 }
00196 
00197 
00198 1;