| 1 | =head1 LICENSE | ||
| 2 | |||
| 3 | See the NOTICE file distributed with this work for additional information | ||
| 4 | regarding copyright ownership. | ||
| 5 | |||
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 7 | you may not use this file except in compliance with the License. | ||
| 8 | You may obtain a copy of the License at | ||
| 9 | |||
| 10 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 11 | |||
| 12 | Unless required by applicable law or agreed to in writing, software | ||
| 13 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 15 | See the License for the specific language governing permissions and | ||
| 16 | limitations under the License. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | |||
| 21 | =head1 CONTACT | ||
| 22 | |||
| 23 | Please email comments or questions to the public Ensembl | ||
| 24 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 25 | |||
| 26 | Questions may also be sent to the Ensembl help desk at | ||
| 27 | <http://www.ensembl.org/Help/Contact>. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Bio::EnsEMBL::DensityType - A type representing a density, or percentage | ||
| 34 | coverage etc. in a given region. | ||
| 35 | |||
| 36 | =head1 SYNOPSIS | ||
| 37 | |||
| 38 | use Bio::EnsEMBL::DensityType; | ||
| 39 | |||
| 40 | $type = Bio::EnsEMBL::DensityType->new( | ||
| 41 | -analysis => $analysis, | ||
| 42 | -blocksize => 1000000, | ||
| 43 | -value_type => $type | ||
| 44 | ); | ||
| 45 | |||
| 46 | =head1 DESCRIPTION | ||
| 47 | |||
| 48 | A density type represents a density, or percentage coverage etc. in a | ||
| 49 | given region. | ||
| 50 | |||
| 51 | =head1 METHODS | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | use strict; | ||
| 56 | use warnings; | ||
| 57 | |||
| 58 | package Bio::EnsEMBL::DensityType; | ||
| 59 | $Bio::EnsEMBL::DensityType::VERSION = '114.0.0'; | ||
| 60 | use Bio::EnsEMBL::Storable; | ||
| 61 | use Bio::EnsEMBL::Utils::Argument qw(rearrange); | ||
| 62 | use Bio::EnsEMBL::Utils::Exception qw(throw); | ||
| 63 | |||
| 64 | use vars qw(@ISA); | ||
| 65 | |||
| 66 | @ISA = qw(Bio::EnsEMBL::Storable); | ||
| 67 | |||
| 68 | =head2 new | ||
| 69 | |||
| 70 | Arg [..] : Takes a set of named arguments | ||
| 71 | Example : $dt = new Bio::EnsEMBL::DensityType::DensityType( | ||
| 72 | -analysis => $analysis, | ||
| 73 | -blocksize => 1e6, | ||
| 74 | -value_type => 'sum') | ||
| 75 | |||
| 76 | Description: Creates a new Density Type object | ||
| 77 | Returntype : Bio::EnsEMBL::DensityType | ||
| 78 | Exceptions : blocksize > 0, | ||
| 79 | valuetype must be 'sum' or 'ratio', | ||
| 80 | valid analysis object must be passed | ||
| 81 | Caller : general | ||
| 82 | Status : Stable | ||
| 83 | |||
| 84 | =cut | ||
| 85 | |||
| 86 | |||
| 87 | sub new { | ||
| 88 | my $class = shift; | ||
| 89 | |||
| 90 | my $self = $class->SUPER::new(@_); | ||
| 91 | |||
| 92 | my ($analysis, $block_size, $value_type, $region_features) = | ||
| 93 | rearrange(['ANALYSIS','BLOCK_SIZE','VALUE_TYPE','REGION_FEATURES'],@_); | ||
| 94 | |||
| 95 | if($analysis) { | ||
| 96 | if(!ref($analysis) || !$analysis->isa('Bio::EnsEMBL::Analysis')) { | ||
| 97 | throw('-ANALYSIS argument must be a Bio::EnsEMBL::Analysis not '. | ||
| 98 | $analysis); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | if($value_type ne "sum" and $value_type ne "ratio"){ | ||
| 103 | throw('-VALUE_TYPE argument must be "ratio" or "sum" not *'. | ||
| 104 | $value_type."*"); | ||
| 105 | } | ||
| 106 | |||
| 107 | $block_size ||= 0; | ||
| 108 | $region_features ||= 0; | ||
| 109 | |||
| 110 | if($block_size && $region_features){ | ||
| 111 | throw('Set either -BLOCK_SIZE or -REGION_FEATURES, not both'); | ||
| 112 | } | ||
| 113 | |||
| 114 | if( $block_size <0 or $region_features < 0 ) { | ||
| 115 | throw( 'No negative values for -BLOCK_SIZE or -REGION_FEATURES' ); | ||
| 116 | } | ||
| 117 | |||
| 118 | |||
| 119 | $self->{'analysis'} = $analysis; | ||
| 120 | $self->{'block_size'} = $block_size; | ||
| 121 | $self->{'value_type'} = $value_type; | ||
| 122 | $self->{'region_features'} = $region_features; | ||
| 123 | |||
| 124 | return $self; | ||
| 125 | } | ||
| 126 | |||
| 127 | =head2 analysis | ||
| 128 | |||
| 129 | Arg [1] : Bio::EnsEMBL::Analysis | ||
| 130 | Description: get/set for attribute analysis | ||
| 131 | Returntype : Bio::EnsEMBL::Analysis | ||
| 132 | Exceptions : none | ||
| 133 | Caller : general | ||
| 134 | Status : Stable | ||
| 135 | |||
| 136 | =cut | ||
| 137 | |||
| 138 | sub analysis{ | ||
| 139 | my $self = shift; | ||
| 140 | |||
| 141 | if(@_) { | ||
| 142 | my $a = shift; | ||
| 143 | if(defined($a) && (!ref($a) || !$a->isa('Bio::EnsEMBL::Analysis'))) { | ||
| 144 | throw("Argument must be undef or a Bio::EnsEMBL::Analysis object."); | ||
| 145 | } | ||
| 146 | $self->{'analysis'} = $a; | ||
| 147 | } | ||
| 148 | return $self->{'analysis'}; | ||
| 149 | } | ||
| 150 | |||
| 151 | =head2 value_type | ||
| 152 | |||
| 153 | Arg [1] : string $value_type | ||
| 154 | Description: gettter/setter for the type | ||
| 155 | Returntype : float | ||
| 156 | Exceptions : none | ||
| 157 | Caller : general | ||
| 158 | Status : Stable | ||
| 159 | |||
| 160 | =cut | ||
| 161 | |||
| 162 | sub value_type{ | ||
| 163 | my $self = shift; | ||
| 164 | $self->{'value_type'} = shift if(@_); | ||
| 165 | return $self->{'value_type'}; | ||
| 166 | } | ||
| 167 | |||
| 168 | |||
| 169 | =head2 block_size | ||
| 170 | |||
| 171 | Arg [1] : int | ||
| 172 | Description: getter/setter for attribute block_size | ||
| 173 | Returntype : int | ||
| 174 | Exceptions : none | ||
| 175 | Caller : general | ||
| 176 | Status : Stable | ||
| 177 | |||
| 178 | =cut | ||
| 179 | |||
| 180 | sub block_size{ | ||
| 181 | my $self = shift; | ||
| 182 | $self->{'block_size'} = shift if(@_); | ||
| 183 | return $self->{'block_size'}; | ||
| 184 | } | ||
| 185 | |||
| 186 | |||
| 187 | =head2 region_features | ||
| 188 | |||
| 189 | Arg [1] : int $region_features | ||
| 190 | Example : The number of features per seq_region inside this density_type.. | ||
| 191 | Description: get/set for attribute region_features | ||
| 192 | Returntype : string | ||
| 193 | Exceptions : none | ||
| 194 | Caller : general | ||
| 195 | |||
| 196 | =cut | ||
| 197 | |||
| 198 | sub region_features { | ||
| 199 | my $self = shift; | ||
| 200 | $self->{'region_features'} = shift if( @_ ); | ||
| 201 | return $self->{'region_features'}; | ||
| 202 | } | ||
| 203 | |||
| 204 | |||
| 205 | 1; |