| 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 | |||
| 22 | =head1 CONTACT | ||
| 23 | |||
| 24 | Please email comments or questions to the public Ensembl | ||
| 25 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 26 | |||
| 27 | Questions may also be sent to the Ensembl help desk at | ||
| 28 | <http://www.ensembl.org/Help/Contact>. | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | =head1 NAME | ||
| 33 | |||
| 34 | Bio::EnsEMBL::Operon - Object representing an operon | ||
| 35 | |||
| 36 | =head1 SYNOPSIS | ||
| 37 | |||
| 38 | my $operon = Bio::EnsEMBL::Operon->new( | ||
| 39 | -START => 123, | ||
| 40 | -END => 1045, | ||
| 41 | -STRAND => 1, | ||
| 42 | -SLICE => $slice, | ||
| 43 | -DISPLAY_LABEL => $name | ||
| 44 | ); | ||
| 45 | |||
| 46 | # print operon information | ||
| 47 | print("operon start:end:strand is " | ||
| 48 | . join( ":", map { $operon->$_ } qw(start end strand) ) | ||
| 49 | . "\n" ); | ||
| 50 | |||
| 51 | =head1 DESCRIPTION | ||
| 52 | |||
| 53 | A representation of an Operon within the Ensembl system. | ||
| 54 | An operon is a collection of one or more polycistronic transcripts which contain one or more genes. | ||
| 55 | |||
| 56 | =head1 METHODS | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | package Bio::EnsEMBL::Operon; | ||
| 61 | $Bio::EnsEMBL::Operon::VERSION = '114.0.0'; | ||
| 62 | use strict; | ||
| 63 | use warnings; | ||
| 64 | |||
| 65 | use Bio::EnsEMBL::Feature; | ||
| 66 | use Bio::EnsEMBL::Utils::Argument qw(rearrange); | ||
| 67 | use Bio::EnsEMBL::Utils::Exception qw(throw warning); | ||
| 68 | use Bio::EnsEMBL::Utils::Scalar qw(assert_ref); | ||
| 69 | |||
| 70 | use vars qw(@ISA); | ||
| 71 | @ISA = qw(Bio::EnsEMBL::Feature); | ||
| 72 | |||
| 73 | =head2 new | ||
| 74 | |||
| 75 | Arg [-START] : | ||
| 76 | int - start postion of the operon | ||
| 77 | Arg [-END] : | ||
| 78 | int - end position of the operon | ||
| 79 | Arg [-STRAND] : | ||
| 80 | int - 1,-1 the strand the operon is on | ||
| 81 | Arg [-SLICE] : | ||
| 82 | Bio::EnsEMBL::Slice - the slice the operon is on | ||
| 83 | Arg [-STABLE_ID] : | ||
| 84 | string - the stable identifier of this operon | ||
| 85 | Arg [-VERSION] : | ||
| 86 | int - the version of the stable identifier of this operon | ||
| 87 | Arg [-DISPLAY_LABEL]: | ||
| 88 | A name/label for this operon | ||
| 89 | Arg [-CREATED_DATE]: | ||
| 90 | string - the date the operon was created | ||
| 91 | Arg [-MODIFIED_DATE]: | ||
| 92 | string - the date the operon was last modified | ||
| 93 | |||
| 94 | Example : $gene = Bio::EnsEMBL::Operon->new(...); | ||
| 95 | Description: Creates a new operon object | ||
| 96 | Returntype : Bio::EnsEMBL::Operon | ||
| 97 | Exceptions : none | ||
| 98 | Caller : general | ||
| 99 | Status : Stable | ||
| 100 | |||
| 101 | =cut | ||
| 102 | |||
| 103 | sub new { | ||
| 104 | my $caller = shift; | ||
| 105 | |||
| 106 | my $class = ref($caller) || $caller; | ||
| 107 | my $self = $class->SUPER::new(@_); | ||
| 108 | my ( $stable_id, $version, $created_date, $modified_date,$display_label) = | ||
| 109 | rearrange( [ 'STABLE_ID', 'VERSION', | ||
| 110 | 'CREATED_DATE', 'MODIFIED_DATE', | ||
| 111 | 'DISPLAY_LABEL' ], | ||
| 112 | @_ ); | ||
| 113 | |||
| 114 | $self->stable_id($stable_id); | ||
| 115 | $self->version($version); | ||
| 116 | $self->{'created_date'} = $created_date; | ||
| 117 | $self->{'modified_date'} = $modified_date; | ||
| 118 | $self->display_label($display_label); | ||
| 119 | |||
| 120 | return $self; | ||
| 121 | } | ||
| 122 | |||
| 123 | =head2 created_date | ||
| 124 | |||
| 125 | Arg [1] : (optional) String - created date to set (as a UNIX time int) | ||
| 126 | Example : $gene->created_date('1141948800'); | ||
| 127 | Description: Getter/setter for attribute created_date | ||
| 128 | Returntype : String | ||
| 129 | Exceptions : none | ||
| 130 | Caller : general | ||
| 131 | Status : Stable | ||
| 132 | |||
| 133 | =cut | ||
| 134 | |||
| 135 | sub created_date { | ||
| 136 | my $self = shift; | ||
| 137 | $self->{'created_date'} = shift if ( @_ ); | ||
| 138 | return $self->{'created_date'}; | ||
| 139 | } | ||
| 140 | |||
| 141 | |||
| 142 | =head2 modified_date | ||
| 143 | |||
| 144 | Arg [1] : (optional) String - modified date to set (as a UNIX time int) | ||
| 145 | Example : $gene->modified_date('1141948800'); | ||
| 146 | Description: Getter/setter for attribute modified_date | ||
| 147 | Returntype : String | ||
| 148 | Exceptions : none | ||
| 149 | Caller : general | ||
| 150 | Status : Stable | ||
| 151 | |||
| 152 | =cut | ||
| 153 | |||
| 154 | sub modified_date { | ||
| 155 | my $self = shift; | ||
| 156 | $self->{'modified_date'} = shift if ( @_ ); | ||
| 157 | return $self->{'modified_date'}; | ||
| 158 | } | ||
| 159 | |||
| 160 | |||
| 161 | =head2 display_label | ||
| 162 | |||
| 163 | Arg [1] : (optional) String - the name/label to set | ||
| 164 | Example : $operon->name('accBCD'); | ||
| 165 | Description: Getter/setter for attribute name. | ||
| 166 | Returntype : String or undef | ||
| 167 | Exceptions : none | ||
| 168 | Caller : general | ||
| 169 | Status : Stable | ||
| 170 | |||
| 171 | =cut | ||
| 172 | |||
| 173 | sub display_label { | ||
| 174 | my $self = shift; | ||
| 175 | $self->{'display_label'} = shift if (@_); | ||
| 176 | return $self->{'display_label'}; | ||
| 177 | } | ||
| 178 | |||
| 179 | =head2 stable_id | ||
| 180 | |||
| 181 | Arg [1] : (optional) String - the stable ID to set | ||
| 182 | Example : $operon->stable_id("accR2"); | ||
| 183 | Description: Getter/setter for stable id for this operon. | ||
| 184 | Returntype : String | ||
| 185 | Exceptions : none | ||
| 186 | Caller : general | ||
| 187 | Status : Stable | ||
| 188 | |||
| 189 | =cut | ||
| 190 | |||
| 191 | sub stable_id { | ||
| 192 | my $self = shift; | ||
| 193 | $self->{'stable_id'} = shift if (@_); | ||
| 194 | return $self->{'stable_id'}; | ||
| 195 | } | ||
| 196 | |||
| 197 | =head2 version | ||
| 198 | |||
| 199 | Arg [1] : (optional) Int - the stable ID version to set | ||
| 200 | Example : $operon->version(1); | ||
| 201 | Description: Getter/setter for stable id version for this operon. | ||
| 202 | Returntype : Int | ||
| 203 | Exceptions : none | ||
| 204 | Caller : general | ||
| 205 | Status : Stable | ||
| 206 | |||
| 207 | =cut | ||
| 208 | sub version { | ||
| 209 | my $self = shift; | ||
| 210 | $self->{'version'} = shift if(@_); | ||
| 211 | return $self->{'version'}; | ||
| 212 | } | ||
| 213 | |||
| 214 | =head2 stable_id_version | ||
| 215 | |||
| 216 | Arg [1] : (optional) String - the stable ID with version to set | ||
| 217 | Example : $operon->stable_id("accR2.3"); | ||
| 218 | Description: Getter/setter for stable id with version for this operon. | ||
| 219 | Returntype : String | ||
| 220 | Exceptions : none | ||
| 221 | Caller : general | ||
| 222 | Status : Stable | ||
| 223 | |||
| 224 | =cut | ||
| 225 | |||
| 226 | sub stable_id_version { | ||
| 227 | my $self = shift; | ||
| 228 | if(my $stable_id = shift) { | ||
| 229 | # See if there's an embedded period, assume that's a | ||
| 230 | # version, might not work for some species but you | ||
| 231 | # should use ->stable_id() and version() if you're worried | ||
| 232 | # about ambiguity | ||
| 233 | my $vindex = rindex($stable_id, '.'); | ||
| 234 | # Set the stable_id and version pair depending on if | ||
| 235 | # we found a version delimiter in the stable_id | ||
| 236 | ($self->{stable_id}, $self->{version}) = ($vindex > 0 ? | ||
| 237 | (substr($stable_id,0,$vindex), substr($stable_id,$vindex+1)) : | ||
| 238 | $stable_id, undef); | ||
| 239 | } | ||
| 240 | return $self->{stable_id} . ($self->{version} ? ".$self->{version}" : ''); | ||
| 241 | } | ||
| 242 | |||
| 243 | =head2 get_all_OperonTranscripts | ||
| 244 | |||
| 245 | Example : my $ots = $operon->get_all_OperonTranscripts(); | ||
| 246 | Description: Retrieve all operon transcripts belonging to this operon | ||
| 247 | Returntype : Arrayref of Bio::EnsEMBL::OperonTranscript | ||
| 248 | Exceptions : none | ||
| 249 | Caller : general | ||
| 250 | Status : Stable | ||
| 251 | |||
| 252 | =cut | ||
| 253 | sub get_all_OperonTranscripts { | ||
| 254 | my $self = shift; | ||
| 255 | if ( !exists $self->{'_operon_transcript_array'} ) { | ||
| 256 | if ( defined $self->adaptor() ) { | ||
| 257 | my $ta = $self->adaptor()->db()->get_OperonTranscriptAdaptor(); | ||
| 258 | my $transcripts = $ta->fetch_all_by_Operon($self); | ||
| 259 | $self->{'_operon_transcript_array'} = $transcripts; | ||
| 260 | } | ||
| 261 | } | ||
| 262 | return $self->{'_operon_transcript_array'}; | ||
| 263 | } | ||
| 264 | |||
| 265 | =head2 add_OperonTranscript | ||
| 266 | |||
| 267 | Arg [1] : Bio::EnsEMBL::OperonTranscript - operon transcript to attach to this operon | ||
| 268 | Example : $operon->add_OperonTranscript($ot); | ||
| 269 | Description: Attach a polycistronic operon transcript to this operon | ||
| 270 | Exceptions : if argument is not Bio::EnsEMBL::OperonTranscript | ||
| 271 | Caller : general | ||
| 272 | Status : Stable | ||
| 273 | |||
| 274 | =cut | ||
| 275 | sub add_OperonTranscript { | ||
| 276 | my ( $self, $trans ) = @_; | ||
| 277 | |||
| 278 | assert_ref($trans,"Bio::EnsEMBL::OperonTranscript"); | ||
| 279 | |||
| 280 | $self->{'_operon_transcript_array'} ||= []; | ||
| 281 | push( @{ $self->{'_operon_transcript_array'} }, $trans ); | ||
| 282 | |||
| 283 | #$self->recalculate_coordinates(); | ||
| 284 | return; | ||
| 285 | } | ||
| 286 | |||
| 287 | =head2 add_DBEntry | ||
| 288 | |||
| 289 | Arg [1] : Bio::EnsEMBL::DBEntry $dbe | ||
| 290 | The dbEntry to be added | ||
| 291 | Example : my $dbe = Bio::EnsEMBL::DBEntery->new(...); | ||
| 292 | $operon->add_DBEntry($dbe); | ||
| 293 | Description: Associates a DBEntry with this operon. Note that adding DBEntries | ||
| 294 | will prevent future lazy-loading of DBEntries for this operon | ||
| 295 | (see get_all_DBEntries). | ||
| 296 | Returntype : none | ||
| 297 | Exceptions : thrown on incorrect argument type | ||
| 298 | Caller : general | ||
| 299 | Status : Stable | ||
| 300 | |||
| 301 | =cut | ||
| 302 | |||
| 303 | sub add_DBEntry { | ||
| 304 | my $self = shift; | ||
| 305 | my $dbe = shift; | ||
| 306 | |||
| 307 | unless($dbe && ref($dbe) && $dbe->isa('Bio::EnsEMBL::DBEntry')) { | ||
| 308 | throw('Expected DBEntry argument'); | ||
| 309 | } | ||
| 310 | |||
| 311 | $self->{'dbentries'} ||= []; | ||
| 312 | push @{$self->{'dbentries'}}, $dbe; | ||
| 313 | } | ||
| 314 | |||
| 315 | |||
| 316 | =head2 get_all_Attributes | ||
| 317 | |||
| 318 | Arg [1] : (optional) String $attrib_code | ||
| 319 | The code of the attribute type to retrieve values for | ||
| 320 | Example : my ($author) = @{ $operon->get_all_Attributes('author') }; | ||
| 321 | my @operon_attributes = @{ $operon->get_all_Attributes }; | ||
| 322 | Description: Gets a list of Attributes of this operon. | ||
| 323 | Optionally just get Attributes for given code. | ||
| 324 | Returntype : Listref of Bio::EnsEMBL::Attribute | ||
| 325 | Exceptions : warning if gene does not have attached adaptor and attempts lazy | ||
| 326 | load. | ||
| 327 | Caller : general | ||
| 328 | Status : Stable | ||
| 329 | |||
| 330 | =cut | ||
| 331 | |||
| 332 | sub get_all_Attributes { | ||
| 333 | my $self = shift; | ||
| 334 | my $attrib_code = shift; | ||
| 335 | |||
| 336 | if ( !exists $self->{'attributes'} ) { | ||
| 337 | if ( !$self->adaptor() ) { | ||
| 338 | return []; | ||
| 339 | } | ||
| 340 | |||
| 341 | my $attribute_adaptor = $self->adaptor->db->get_AttributeAdaptor(); | ||
| 342 | $self->{'attributes'} = $attribute_adaptor->fetch_all_by_Operon($self); | ||
| 343 | } | ||
| 344 | |||
| 345 | if ( defined $attrib_code ) { | ||
| 346 | my @results = | ||
| 347 | grep { uc( $_->code() ) eq uc($attrib_code) } | ||
| 348 | @{ $self->{'attributes'} }; | ||
| 349 | return \@results; | ||
| 350 | } else { | ||
| 351 | return $self->{'attributes'}; | ||
| 352 | } | ||
| 353 | } | ||
| 354 | |||
| 355 | =head2 get_all_DBEntries | ||
| 356 | |||
| 357 | Arg [1] : (optional) String, external database name | ||
| 358 | |||
| 359 | Arg [2] : (optional) String, external_db type | ||
| 360 | |||
| 361 | Example : @dbentries = @{ $gene->get_all_DBEntries() }; | ||
| 362 | |||
| 363 | Description: Retrieves DBEntries (xrefs) for this operon. This does | ||
| 364 | *not* include DBEntries that are associated with the | ||
| 365 | transcripts and corresponding translations of this | ||
| 366 | gene (see get_all_DBLinks()). | ||
| 367 | |||
| 368 | This method will attempt to lazy-load DBEntries | ||
| 369 | from a database if an adaptor is available and no | ||
| 370 | DBEntries are present on the gene (i.e. they have not | ||
| 371 | already been added or loaded). | ||
| 372 | |||
| 373 | Return type: Listref of Bio::EnsEMBL::DBEntry objects | ||
| 374 | Exceptions : none | ||
| 375 | Caller : get_all_DBLinks, OperonAdaptor::store | ||
| 376 | Status : Stable | ||
| 377 | |||
| 378 | =cut | ||
| 379 | |||
| 380 | sub get_all_DBEntries { | ||
| 381 | my ( $self, $db_name_exp, $ex_db_type ) = @_; | ||
| 382 | |||
| 383 | my $cache_name = 'dbentries'; | ||
| 384 | |||
| 385 | if ( defined($db_name_exp) ) { | ||
| 386 | $cache_name .= $db_name_exp; | ||
| 387 | } | ||
| 388 | |||
| 389 | if ( defined($ex_db_type) ) { | ||
| 390 | $cache_name .= $ex_db_type; | ||
| 391 | } | ||
| 392 | |||
| 393 | # if not cached, retrieve all of the xrefs for this gene | ||
| 394 | if ( !defined( $self->{$cache_name} ) && defined( $self->adaptor() ) ) { | ||
| 395 | $self->{$cache_name} = | ||
| 396 | $self->adaptor()->db()->get_DBEntryAdaptor() | ||
| 397 | ->fetch_all_by_Operon( $self, $db_name_exp, $ex_db_type ); | ||
| 398 | } | ||
| 399 | |||
| 400 | $self->{$cache_name} ||= []; | ||
| 401 | |||
| 402 | return $self->{$cache_name}; | ||
| 403 | } | ||
| 404 | |||
| 405 | 1; | ||
| 406 |