« EnsEMBL/Map/DBSQL/DitagFeatureAdaptor.pm
↑ Summary
EnsEMBL/DBSQL/AssemblyExceptionFeatureAdaptor.pm »
| 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::DBSQL::OperonAdaptor - Database adaptor for the retrieval and | ||
| 35 | storage of OperonTranscript objects | ||
| 36 | |||
| 37 | =head1 SYNOPSIS | ||
| 38 | |||
| 39 | |||
| 40 | my $operon_transcript_adaptor = Bio::EnsEMBL::DBSQL::OperonTranscriptAdaptor->new($dba); | ||
| 41 | $operon_transcript_adaptor->store($operon_transcript); | ||
| 42 | my $operon_transcript2 = $operon_transcript_adaptor->fetch_by_dbID( $operon->dbID() ); | ||
| 43 | my $operon_transcripts = $operon_transcript_adaptor->fetch_all_by_gene( $gene ); | ||
| 44 | |||
| 45 | =head1 DESCRIPTION | ||
| 46 | |||
| 47 | This is a database aware adaptor for the retrieval and storage of operon | ||
| 48 | transcript objects. | ||
| 49 | |||
| 50 | =head1 METHODS | ||
| 51 | |||
| 52 | =cut | ||
| 53 | |||
| 54 | package Bio::EnsEMBL::DBSQL::OperonTranscriptAdaptor; | ||
| 55 | $Bio::EnsEMBL::DBSQL::OperonTranscriptAdaptor::VERSION = '114.0.0_50'; # TRIAL | ||
| 56 | $Bio::EnsEMBL::DBSQL::OperonTranscriptAdaptor::VERSION = '114.0.050'; | ||
| 57 | use strict; | ||
| 58 | |||
| 59 | use Bio::EnsEMBL::Utils::Exception qw( throw warning ); | ||
| 60 | use Bio::EnsEMBL::Utils::Scalar qw( assert_ref ); | ||
| 61 | use Bio::EnsEMBL::DBSQL::SliceAdaptor; | ||
| 62 | use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor; | ||
| 63 | use Bio::EnsEMBL::DBSQL::DBAdaptor; | ||
| 64 | use Bio::EnsEMBL::Operon; | ||
| 65 | use Bio::EnsEMBL::OperonTranscript; | ||
| 66 | use Bio::EnsEMBL::Utils::SqlHelper; | ||
| 67 | |||
| 68 | use vars '@ISA'; | ||
| 69 | @ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor); | ||
| 70 | |||
| 71 | # _tables | ||
| 72 | # Arg [1] : none | ||
| 73 | # Description: PROTECTED implementation of superclass abstract method. | ||
| 74 | # Returns the names, aliases of the tables to use for queries. | ||
| 75 | # Returntype : list of listrefs of strings | ||
| 76 | # Exceptions : none | ||
| 77 | # Caller : interna | ||
| 78 | # Status : Stable | ||
| 79 | |||
| 80 | sub _tables { | ||
| 81 | return ( [ 'operon_transcript', 'o' ] ); | ||
| 82 | } | ||
| 83 | |||
| 84 | # _columns | ||
| 85 | # Arg [1] : none | ||
| 86 | # Example : none | ||
| 87 | # Description: PROTECTED implementation of superclass abstract method. | ||
| 88 | # Returns a list of columns to use for queries. | ||
| 89 | # Returntype : list of strings | ||
| 90 | # Exceptions : none | ||
| 91 | # Caller : internal | ||
| 92 | # Status : Stable | ||
| 93 | |||
| 94 | sub _columns { | ||
| 95 | my ($self) = @_; | ||
| 96 | |||
| 97 | my $created_date = | ||
| 98 | $self->db()->dbc()->from_date_to_seconds("o.created_date"); | ||
| 99 | my $modified_date = | ||
| 100 | $self->db()->dbc()->from_date_to_seconds("o.modified_date"); | ||
| 101 | |||
| 102 | return ( 'o.operon_transcript_id', 'o.seq_region_id', | ||
| 103 | 'o.seq_region_start', 'o.seq_region_end', | ||
| 104 | 'o.seq_region_strand', 'o.display_label', | ||
| 105 | 'o.analysis_id', 'o.stable_id', | ||
| 106 | 'o.version', $created_date, | ||
| 107 | $modified_date ); | ||
| 108 | } | ||
| 109 | |||
| 110 | =head2 list_dbIDs | ||
| 111 | |||
| 112 | Example : @ot_ids = @{$ot_adaptor->list_dbIDs()}; | ||
| 113 | Description: Gets an array of internal ids for all operon_transcripts in the current db | ||
| 114 | Arg[1] : <optional> int. not 0 for the ids to be sorted by the seq_region. | ||
| 115 | Returntype : Listref of Ints | ||
| 116 | Exceptions : none | ||
| 117 | Caller : general | ||
| 118 | Status : Stable | ||
| 119 | |||
| 120 | =cut | ||
| 121 | |||
| 122 | sub list_dbIDs { | ||
| 123 | my ( $self, $ordered ) = @_; | ||
| 124 | |||
| 125 | return $self->_list_dbIDs( "operon_transcript", undef, $ordered ); | ||
| 126 | } | ||
| 127 | |||
| 128 | =head2 list_stable_ids | ||
| 129 | |||
| 130 | Example : @stable_ot_ids = @{$ot_adaptor->list_stable_ids()}; | ||
| 131 | Description: Gets an listref of stable ids for all operon_transcripts in the current db | ||
| 132 | Returntype : reference to a list of strings | ||
| 133 | Exceptions : none | ||
| 134 | Caller : general | ||
| 135 | Status : Stable | ||
| 136 | |||
| 137 | =cut | ||
| 138 | |||
| 139 | sub list_stable_ids { | ||
| 140 | my ($self) = @_; | ||
| 141 | |||
| 142 | return $self->_list_dbIDs( "operon_transcript", "stable_id" ); | ||
| 143 | } | ||
| 144 | |||
| 145 | sub list_seq_region_ids { | ||
| 146 | my $self = shift; | ||
| 147 | |||
| 148 | return $self->_list_seq_region_ids('operon'); | ||
| 149 | } | ||
| 150 | |||
| 151 | =head2 fetch_by_stable_id | ||
| 152 | |||
| 153 | Arg [1] : String $id | ||
| 154 | The stable ID of the operon_transcript to retrieve | ||
| 155 | Example : $operon_transcript = $operon_transcript_adaptor->fetch_by_stable_id('T16152-16153-4840'); | ||
| 156 | Description: Retrieves a operon_transcript object from the database via its stable id. | ||
| 157 | The operon_transcript will be retrieved in its native coordinate system (i.e. | ||
| 158 | in the coordinate system it is stored in the database). It may | ||
| 159 | be converted to a different coordinate system through a call to | ||
| 160 | transform() or transfer(). If the operon_transcript is not found | ||
| 161 | undef is returned instead. | ||
| 162 | Returntype : Bio::EnsEMBL::OperonTranscript or undef | ||
| 163 | Exceptions : if we cant get the operon_transcript in given coord system | ||
| 164 | Caller : general | ||
| 165 | Status : Stable | ||
| 166 | |||
| 167 | =cut | ||
| 168 | |||
| 169 | sub fetch_by_stable_id { | ||
| 170 | my ( $self, $stable_id ) = @_; | ||
| 171 | |||
| 172 | my $constraint = "o.stable_id = ?"; | ||
| 173 | $self->bind_param_generic_fetch( $stable_id, SQL_VARCHAR ); | ||
| 174 | my ($operon_transcript) = @{ $self->generic_fetch($constraint) }; | ||
| 175 | |||
| 176 | # If we didn't get anything back, desperately try to see if there's | ||
| 177 | # a version number in the stable_id | ||
| 178 | if(!defined($operon_transcript) && (my $vindex = rindex($stable_id, '.'))) { | ||
| 179 | $operon_transcript = $self->fetch_by_stable_id_version(substr($stable_id,0,$vindex), | ||
| 180 | substr($stable_id,$vindex+1)); | ||
| 181 | } | ||
| 182 | |||
| 183 | return $operon_transcript; | ||
| 184 | } | ||
| 185 | |||
| 186 | =head2 fetch_by_stable_id_version | ||
| 187 | |||
| 188 | Arg [1] : String $id | ||
| 189 | The stable ID of the operon_transcript to retrieve | ||
| 190 | Arg [2] : Integer $version | ||
| 191 | The version of the stable_id to retrieve | ||
| 192 | Example : $operon_transcript = $operon_transcript_adaptor->fetch_by_stable_id('T16152-16153-4840', 2); | ||
| 193 | Description: Retrieves an operon_transcript object from the database via its stable id and version. | ||
| 194 | The operon_transcript will be retrieved in its native coordinate system (i.e. | ||
| 195 | in the coordinate system it is stored in the database). It may | ||
| 196 | be converted to a different coordinate system through a call to | ||
| 197 | transform() or transfer(). If the operon_transcript is not found | ||
| 198 | undef is returned instead. | ||
| 199 | Returntype : Bio::EnsEMBL::OperonTranscript or undef | ||
| 200 | Exceptions : if we cant get the operon_transcript in given coord system | ||
| 201 | Caller : general | ||
| 202 | Status : Stable | ||
| 203 | |||
| 204 | =cut | ||
| 205 | |||
| 206 | sub fetch_by_stable_id_version { | ||
| 207 | my ($self, $stable_id, $version) = @_; | ||
| 208 | |||
| 209 | # Enforce that version be numeric | ||
| 210 | return unless($version =~ /^\d+$/); | ||
| 211 | |||
| 212 | my $constraint = "o.stable_id = ? AND o.version = ?"; | ||
| 213 | $self->bind_param_generic_fetch($stable_id, SQL_VARCHAR); | ||
| 214 | $self->bind_param_generic_fetch($version, SQL_INTEGER); | ||
| 215 | my ($operon_transcript) = @{$self->generic_fetch($constraint)}; | ||
| 216 | |||
| 217 | return $operon_transcript; | ||
| 218 | } | ||
| 219 | |||
| 220 | =head2 fetch_by_name | ||
| 221 | |||
| 222 | Arg [1] : String $label - name of operon transcript to fetch | ||
| 223 | Example : my $operon_transcript = $operonAdaptor->fetch_by_name("ECK0012121342"); | ||
| 224 | Description: Returns the operon transcript which has the given display label or undef if | ||
| 225 | there is none. If there are more than 1, only the first is | ||
| 226 | reported. | ||
| 227 | Returntype : Bio::EnsEMBL::OperonTranscript | ||
| 228 | Exceptions : none | ||
| 229 | Caller : general | ||
| 230 | Status : Stable | ||
| 231 | |||
| 232 | =cut | ||
| 233 | |||
| 234 | sub fetch_by_name { | ||
| 235 | my $self = shift; | ||
| 236 | my $label = shift; | ||
| 237 | |||
| 238 | my $constraint = "o.display_label = ?"; | ||
| 239 | $self->bind_param_generic_fetch( $label, SQL_VARCHAR ); | ||
| 240 | my ($operon) = @{ $self->generic_fetch($constraint) }; | ||
| 241 | |||
| 242 | return $operon; | ||
| 243 | } | ||
| 244 | |||
| 245 | =head2 fetch_all | ||
| 246 | |||
| 247 | Example : $operon_transcripts = $operon_adaptor->fetch_all(); | ||
| 248 | Description : Retrieves all operon transcripts stored in the database. | ||
| 249 | Returntype : listref of Bio::EnsEMBL::OperonTranscript | ||
| 250 | Caller : general | ||
| 251 | Status : At Risk | ||
| 252 | |||
| 253 | =cut | ||
| 254 | |||
| 255 | sub fetch_all { | ||
| 256 | my ($self) = @_; | ||
| 257 | |||
| 258 | my $constraint = ''; | ||
| 259 | my @operon_transcripts = @{ $self->generic_fetch($constraint) }; | ||
| 260 | return \@operon_transcripts; | ||
| 261 | } | ||
| 262 | |||
| 263 | =head2 fetch_all_versions_by_stable_id | ||
| 264 | |||
| 265 | Arg [1] : String $stable_id | ||
| 266 | The stable ID of the operon_transcript to retrieve | ||
| 267 | Example : $operon_transcript = $operon_transcript_adaptor->fetch_all_versions_by_stable_id | ||
| 268 | ('ENSG00000148944'); | ||
| 269 | Description : Similar to fetch_by_stable_id, but retrieves all versions of a | ||
| 270 | operon_transcript stored in the database. | ||
| 271 | Returntype : listref of Bio::EnsEMBL::OperonTranscript | ||
| 272 | Exceptions : if we cant get the operon_transcript in given coord system | ||
| 273 | Caller : general | ||
| 274 | Status : At Risk | ||
| 275 | |||
| 276 | =cut | ||
| 277 | |||
| 278 | sub fetch_all_versions_by_stable_id { | ||
| 279 | my ( $self, $stable_id ) = @_; | ||
| 280 | |||
| 281 | my $constraint = "o.stable_id = ?"; | ||
| 282 | $self->bind_param_generic_fetch( $stable_id, SQL_VARCHAR ); | ||
| 283 | return $self->generic_fetch($constraint); | ||
| 284 | } | ||
| 285 | |||
| 286 | =head2 fetch_all_by_Slice | ||
| 287 | |||
| 288 | Arg [1] : Bio::EnsEMBL::Slice $slice | ||
| 289 | The slice to fetch operon_transcripts on. | ||
| 290 | Arg [2] : (optional) string $logic_name | ||
| 291 | the logic name of the type of features to obtain | ||
| 292 | Arg [3] : (optional) boolean $load_transcripts | ||
| 293 | if true, transcripts will be loaded immediately rather than | ||
| 294 | lazy loaded later. | ||
| 295 | Arg [4] : (optional) string $source | ||
| 296 | the source name of the features to obtain. | ||
| 297 | Arg [5] : (optional) string biotype | ||
| 298 | the biotype of the features to obtain. | ||
| 299 | Example : @operon_transcripts = @{$operon_transcript_adaptor->fetch_all_by_Slice()}; | ||
| 300 | Description: Overrides superclass method to optionally load transcripts | ||
| 301 | immediately rather than lazy-loading them later. This | ||
| 302 | is more efficient when there are a lot of operon_transcripts whose | ||
| 303 | transcripts are going to be used. | ||
| 304 | Returntype : reference to list of operon_transcripts | ||
| 305 | Exceptions : thrown if exon cannot be placed on transcript slice | ||
| 306 | Caller : Slice::get_all_OperonTranscripts | ||
| 307 | Status : Stable | ||
| 308 | |||
| 309 | =cut | ||
| 310 | |||
| 311 | sub fetch_all_by_Slice { | ||
| 312 | my ( $self, $slice, $logic_name, $load_transcripts ) = @_; | ||
| 313 | |||
| 314 | my $constraint = ''; | ||
| 315 | |||
| 316 | my $operons = | ||
| 317 | $self->SUPER::fetch_all_by_Slice_constraint( $slice, $constraint, | ||
| 318 | $logic_name ); | ||
| 319 | |||
| 320 | # If there are less than two operons, still do lazy-loading. | ||
| 321 | if ( !$load_transcripts || @$operons < 2 ) { | ||
| 322 | return $operons; | ||
| 323 | } | ||
| 324 | |||
| 325 | # Preload all of the transcripts now, instead of lazy loading later, | ||
| 326 | # faster than one query per transcript. | ||
| 327 | |||
| 328 | # First check if transcripts are already preloaded. | ||
| 329 | # FIXME: Should check all transcripts. | ||
| 330 | if ( exists( $operons->[0]->{'_operon_transcript_array'} ) ) { | ||
| 331 | return $operons; | ||
| 332 | } | ||
| 333 | |||
| 334 | # Get extent of region spanned by transcripts. | ||
| 335 | my ($min_start, $max_end); | ||
| 336 | my $ext_slice; | ||
| 337 | |||
| 338 | unless ($slice->is_circular()) { | ||
| 339 | foreach my $o (@$operons) { | ||
| 340 | if (!defined($min_start) || $o->seq_region_start() < $min_start) { | ||
| 341 | $min_start = $o->seq_region_start(); | ||
| 342 | } | ||
| 343 | if (!defined($max_end) || $o->seq_region_end() > $max_end) { | ||
| 344 | $max_end = $o->seq_region_end(); | ||
| 345 | } | ||
| 346 | } | ||
| 347 | |||
| 348 | if ($min_start >= $slice->start() && $max_end <= $slice->end()) { | ||
| 349 | $ext_slice = $slice; | ||
| 350 | } else { | ||
| 351 | my $sa = $self->db()->get_SliceAdaptor(); | ||
| 352 | $ext_slice = $sa->fetch_by_region($slice->coord_system->name(), $slice->seq_region_name(), $min_start, $max_end, $slice->strand(), $slice->coord_system->version()); | ||
| 353 | } | ||
| 354 | |||
| 355 | } else { | ||
| 356 | # feature might be crossing the origin of replication (i.e. seq_region_start > seq_region_end) | ||
| 357 | # the computation of min_start|end based on seq_region_start|end is not safe | ||
| 358 | # use feature start/end relative to the slice instead | ||
| 359 | my ($min_start_feature, $max_end_feature); | ||
| 360 | foreach my $o (@$operons) { | ||
| 361 | if (!defined($min_start) || ($o->start() >= 0 && $o->start() < $min_start)) { | ||
| 362 | $min_start = $o->start(); | ||
| 363 | $min_start_feature = $o; | ||
| 364 | } | ||
| 365 | if (!defined($max_end) || ($o->end() >= 0 && $o->end() > $max_end)) { | ||
| 366 | $max_end = $o->end(); | ||
| 367 | $max_end_feature = $o; | ||
| 368 | } | ||
| 369 | } | ||
| 370 | |||
| 371 | # now we can reassign min_start|end to seq_region_start|end of | ||
| 372 | # the feature which spans the largest region | ||
| 373 | $min_start = $min_start_feature->seq_region_start(); | ||
| 374 | $max_end = $max_end_feature->seq_region_end(); | ||
| 375 | |||
| 376 | my $sa = $self->db()->get_SliceAdaptor(); | ||
| 377 | $ext_slice = | ||
| 378 | $sa->fetch_by_region($slice->coord_system->name(), | ||
| 379 | $slice->seq_region_name(), | ||
| 380 | $min_start, | ||
| 381 | $max_end, | ||
| 382 | $slice->strand(), | ||
| 383 | $slice->coord_system->version()); | ||
| 384 | } | ||
| 385 | |||
| 386 | |||
| 387 | # Associate transcript identifiers with operon_transcripts. | ||
| 388 | |||
| 389 | my %o_hash = map { $_->dbID => $_ } @{$operons}; | ||
| 390 | |||
| 391 | my $o_id_str = join( ',', keys(%o_hash) ); | ||
| 392 | |||
| 393 | my $sth = | ||
| 394 | $self->prepare( "SELECT operon_id, operon_transcript_id " | ||
| 395 | . "FROM operon_transcript " | ||
| 396 | . "WHERE operon_id IN ($o_id_str)" ); | ||
| 397 | |||
| 398 | $sth->execute(); | ||
| 399 | |||
| 400 | my ( $o_id, $tr_id ); | ||
| 401 | $sth->bind_columns( \( $o_id, $tr_id ) ); | ||
| 402 | |||
| 403 | my %tr_o_hash; | ||
| 404 | |||
| 405 | while ( $sth->fetch() ) { | ||
| 406 | $tr_o_hash{$tr_id} = $o_hash{$o_id}; | ||
| 407 | } | ||
| 408 | |||
| 409 | my $ta = $self->db()->get_OperonTranscriptAdaptor(); | ||
| 410 | my $transcripts = | ||
| 411 | $ta->fetch_all_by_Slice( $ext_slice, | ||
| 412 | 1, undef, | ||
| 413 | sprintf( "ot.operon_transcript_id IN (%s)", | ||
| 414 | join( ',', | ||
| 415 | sort { $a <=> $b } | ||
| 416 | keys(%tr_o_hash) ) ) ); | ||
| 417 | |||
| 418 | # Move transcripts onto operon_transcript slice, and add them to operon_transcripts. | ||
| 419 | foreach my $tr ( @{$transcripts} ) { | ||
| 420 | if ( !exists( $tr_o_hash{ $tr->dbID() } ) ) { | ||
| 421 | next; | ||
| 422 | } | ||
| 423 | |||
| 424 | my $new_tr; | ||
| 425 | if ( $slice != $ext_slice ) { | ||
| 426 | $new_tr = $tr->transfer($slice); | ||
| 427 | if ( !defined($new_tr) ) { | ||
| 428 | throw("Unexpected. " | ||
| 429 | . "Transcript could not be transfered onto OperonTranscript slice." | ||
| 430 | ); | ||
| 431 | } | ||
| 432 | } else { | ||
| 433 | $new_tr = $tr; | ||
| 434 | } | ||
| 435 | |||
| 436 | $tr_o_hash{ $tr->dbID() }->add_OperonTranscript($new_tr); | ||
| 437 | } | ||
| 438 | |||
| 439 | return $operons; | ||
| 440 | } ## end sub fetch_all_by_Slice | ||
| 441 | |||
| 442 | =head2 fetch_by_Operon | ||
| 443 | |||
| 444 | Arg [1] : Bio::EnsEMBL::Operon | ||
| 445 | Example : $ot = $ot_adaptor->fetch_by_Operon($operon); | ||
| 446 | Description: Retrieves all operon transcripts belonging to an operon | ||
| 447 | Returntype : arrayref of Bio::EnsEMBL::OperonTranscript | ||
| 448 | Exceptions : none | ||
| 449 | Caller : general | ||
| 450 | Status : Stable | ||
| 451 | |||
| 452 | =cut | ||
| 453 | |||
| 454 | sub fetch_all_by_Operon { | ||
| 455 | my ( $self, $operon ) = @_; | ||
| 456 | return $self->fetch_by_operon_id( $operon->dbID() ); | ||
| 457 | } | ||
| 458 | |||
| 459 | =head2 fetch_by_operon_id | ||
| 460 | |||
| 461 | Arg [1] : Int id | ||
| 462 | Example : $ot = $ot_adaptor->fetch_by_operon_transcript($operon); | ||
| 463 | Description: Retrieves all operon transcripts belonging to an operon | ||
| 464 | Returntype : arrayref of Bio::EnsEMBL::OperonTranscript | ||
| 465 | Exceptions : none | ||
| 466 | Caller : general | ||
| 467 | Status : Stable | ||
| 468 | |||
| 469 | =cut | ||
| 470 | |||
| 471 | sub fetch_by_operon_id { | ||
| 472 | my ( $self, $operon_id ) = @_; | ||
| 473 | |||
| 474 | my $constraint = "o.operon_id = ?"; | ||
| 475 | $self->bind_param_generic_fetch( $operon_id, SQL_INTEGER ); | ||
| 476 | return $self->generic_fetch($constraint); | ||
| 477 | } | ||
| 478 | |||
| 479 | =head2 fetch_genes_by_operon_transcript | ||
| 480 | |||
| 481 | Arg [1] : Bio::EnsEMBL::OperonTranscript | ||
| 482 | Example : $ot = $ot_adaptor->fetch_genes_by_operon_transcript($operon_transcript); | ||
| 483 | Description: Retrieves all genes attached to an operon transcript | ||
| 484 | Returntype : arrayref of Bio::EnsEMBL::Gene | ||
| 485 | Exceptions : none | ||
| 486 | Caller : general | ||
| 487 | Status : Stable | ||
| 488 | |||
| 489 | =cut | ||
| 490 | |||
| 491 | sub fetch_genes_by_operon_transcript { | ||
| 492 | my ( $self, $operon_transcript ) = @_; | ||
| 493 | assert_ref( $operon_transcript, 'Bio::EnsEMBL::OperonTranscript' ); | ||
| 494 | return $self->fetch_genes_by_operon_transcript_id( | ||
| 495 | $operon_transcript->dbID() ); | ||
| 496 | } | ||
| 497 | |||
| 498 | =head2 fetch_genes_by_operon_transcript_id | ||
| 499 | |||
| 500 | Arg [1] : Int id | ||
| 501 | Example : $ot = $ot_adaptor->fetch_genes_by_operon_transcript($operon_transcript_id); | ||
| 502 | Description: Retrieves all genes attached to an operon transcript | ||
| 503 | Returntype : arrayref of Bio::EnsEMBL::Gene | ||
| 504 | Exceptions : none | ||
| 505 | Caller : general | ||
| 506 | Status : Stable | ||
| 507 | |||
| 508 | =cut | ||
| 509 | |||
| 510 | sub fetch_genes_by_operon_transcript_id { | ||
| 511 | my ( $self, $operon_transcript_id ) = @_; | ||
| 512 | my $helper = | ||
| 513 | Bio::EnsEMBL::Utils::SqlHelper->new( -DB_CONNECTION => $self->db->dbc() ); | ||
| 514 | |||
| 515 | my $gene_ids = | ||
| 516 | $helper->execute_simple( | ||
| 517 | -SQL => | ||
| 518 | 'SELECT gene_id FROM operon_transcript_gene tr WHERE operon_transcript_id =?', | ||
| 519 | -PARAMS => [$operon_transcript_id] ); | ||
| 520 | |||
| 521 | my $genes = []; | ||
| 522 | my $gene_adaptor = $self->db()->get_GeneAdaptor(); | ||
| 523 | for my $gene_id (@$gene_ids) { | ||
| 524 | push @$genes, $gene_adaptor->fetch_by_dbID($gene_id); | ||
| 525 | } | ||
| 526 | return $genes; | ||
| 527 | } | ||
| 528 | |||
| 529 | =head2 fetch_all_by_gene | ||
| 530 | |||
| 531 | Arg [1] : Bio::EnsEMBL::Gene | ||
| 532 | Example : $ots = $ot_adaptor->fetch_all_by_gene($gene); | ||
| 533 | Description: Retrieves all operon transcripts attached to a given gene | ||
| 534 | Returntype : arrayref of Bio::EnsEMBL::OperonTranscript | ||
| 535 | Exceptions : none | ||
| 536 | Caller : general | ||
| 537 | Status : Stable | ||
| 538 | |||
| 539 | =cut | ||
| 540 | |||
| 541 | sub fetch_all_by_gene { | ||
| 542 | my ( $self, $gene ) = @_; | ||
| 543 | assert_ref( $gene, 'Bio::EnsEMBL::Gene' ); | ||
| 544 | return $self->fetch_all_by_gene_id( $gene->dbID() ); | ||
| 545 | } | ||
| 546 | |||
| 547 | =head2 fetch_all_by_gene_id | ||
| 548 | |||
| 549 | Arg [1] : Int id of Bio::EnsEMBL::Gene | ||
| 550 | Example : $ots = $ot_adaptor->fetch_all_by_gene($gene); | ||
| 551 | Description: Retrieves all operon transcripts attached to a given gene | ||
| 552 | Returntype : arrayref of Bio::EnsEMBL::OperonTranscript | ||
| 553 | Exceptions : none | ||
| 554 | Caller : general | ||
| 555 | Status : Stable | ||
| 556 | |||
| 557 | =cut | ||
| 558 | |||
| 559 | sub fetch_all_by_gene_id { | ||
| 560 | my ( $self, $gene_id ) = @_; | ||
| 561 | my $helper = | ||
| 562 | Bio::EnsEMBL::Utils::SqlHelper->new( -DB_CONNECTION => $self->db->dbc() ); | ||
| 563 | |||
| 564 | my $ot_ids = $helper->execute_simple( | ||
| 565 | -SQL => | ||
| 566 | 'SELECT operon_transcript_id FROM operon_transcript_gene tr WHERE gene_id =?', | ||
| 567 | -PARAMS => [$gene_id] ); | ||
| 568 | |||
| 569 | my $ots = []; | ||
| 570 | for my $ot_id (@$ot_ids) { | ||
| 571 | push @$ots, $self->fetch_by_dbID($ot_id); | ||
| 572 | } | ||
| 573 | return $ots; | ||
| 574 | } | ||
| 575 | |||
| 576 | =head2 store | ||
| 577 | |||
| 578 | Arg [1] : Bio::EnsEMBL::OperonTranscript $gene | ||
| 579 | The gene to store in the database | ||
| 580 | Arg [2] : ignore_release in xrefs [default 1] set to 0 to use release info | ||
| 581 | in external database references | ||
| 582 | Example : $gene_adaptor->store($gene); | ||
| 583 | Description: Stores a gene in the database. | ||
| 584 | Returntype : the database identifier (dbID) of the newly stored gene | ||
| 585 | Exceptions : thrown if the $gene is not a Bio::EnsEMBL::OperonTranscript or if | ||
| 586 | $gene does not have an analysis object | ||
| 587 | Caller : general | ||
| 588 | Status : Stable | ||
| 589 | |||
| 590 | =cut | ||
| 591 | |||
| 592 | sub store { | ||
| 593 | my ( $self, $operon_transcript, $operon_id ) = @_; | ||
| 594 | |||
| 595 | assert_ref( $operon_transcript, 'Bio::EnsEMBL::OperonTranscript' ); | ||
| 596 | |||
| 597 | my $db = $self->db(); | ||
| 598 | |||
| 599 | if ( $operon_transcript->is_stored($db) ) { | ||
| 600 | return $operon_transcript->dbID(); | ||
| 601 | } | ||
| 602 | |||
| 603 | # ensure coords are correct before storing | ||
| 604 | #$operon->recalculate_coordinates(); | ||
| 605 | |||
| 606 | my $seq_region_id; | ||
| 607 | |||
| 608 | ( $operon_transcript, $seq_region_id ) = | ||
| 609 | $self->_pre_store($operon_transcript); | ||
| 610 | my $analysis = $operon_transcript->analysis(); | ||
| 611 | throw("OperonTranscripts must have an analysis object.") | ||
| 612 | if ( !defined($analysis) ); | ||
| 613 | my $analysis_id; | ||
| 614 | if ( $analysis->is_stored($db) ) { | ||
| 615 | $analysis_id = $analysis->dbID(); | ||
| 616 | } else { | ||
| 617 | $analysis_id = $db->get_AnalysisAdaptor->store($analysis); | ||
| 618 | } | ||
| 619 | my @columns = qw( | ||
| 620 | seq_region_id | ||
| 621 | seq_region_start | ||
| 622 | seq_region_end | ||
| 623 | seq_region_strand | ||
| 624 | display_label | ||
| 625 | operon_id | ||
| 626 | analysis_id | ||
| 627 | ); | ||
| 628 | my @canned_columns; | ||
| 629 | my @canned_values; | ||
| 630 | if ( defined($operon_transcript->stable_id()) ) { | ||
| 631 | push @columns, qw( | ||
| 632 | stable_id | ||
| 633 | version | ||
| 634 | ); | ||
| 635 | my $created = $self->db->dbc->from_seconds_to_date($operon_transcript->created_date()); | ||
| 636 | my $modified = $self->db->dbc->from_seconds_to_date($operon_transcript->modified_date()); | ||
| 637 | |||
| 638 | if ($created) { | ||
| 639 | push @canned_columns, 'created_date'; | ||
| 640 | push @canned_values, $created; | ||
| 641 | } | ||
| 642 | if ($modified) { | ||
| 643 | push @canned_columns, 'modified_date'; | ||
| 644 | push @canned_values, $modified; | ||
| 645 | } | ||
| 646 | } | ||
| 647 | my $i_columns = join(', ', @columns, @canned_columns); | ||
| 648 | my $i_values = join(', ', (('?') x scalar(@columns)), @canned_values); | ||
| 649 | my $store_operon_transcript_sql = qq( | ||
| 650 | INSERT INTO operon_transcript ( ${i_columns} ) VALUES ( $i_values ) | ||
| 651 | ); | ||
| 652 | |||
| 653 | my $sth = $self->prepare($store_operon_transcript_sql); | ||
| 654 | $sth->bind_param( 1, $seq_region_id, SQL_INTEGER ); | ||
| 655 | $sth->bind_param( 2, $operon_transcript->start(), SQL_INTEGER ); | ||
| 656 | $sth->bind_param( 3, $operon_transcript->end(), SQL_INTEGER ); | ||
| 657 | $sth->bind_param( 4, $operon_transcript->strand(), SQL_TINYINT ); | ||
| 658 | $sth->bind_param( 5, $operon_transcript->display_label(), SQL_VARCHAR ); | ||
| 659 | $sth->bind_param( 6, $operon_id, SQL_INTEGER ); | ||
| 660 | $sth->bind_param( 7, $analysis_id, SQL_INTEGER ); | ||
| 661 | |||
| 662 | if ( defined($operon_transcript->stable_id()) ) { | ||
| 663 | $sth->bind_param( 8, $operon_transcript->stable_id(), SQL_VARCHAR ); | ||
| 664 | my $version = ($operon_transcript->version()) ? $operon_transcript->version() : 1; | ||
| 665 | $sth->bind_param( 9, $version, SQL_INTEGER ); | ||
| 666 | } | ||
| 667 | |||
| 668 | $sth->execute(); | ||
| 669 | $sth->finish(); | ||
| 670 | |||
| 671 | my $operon_transcript_dbID = $self->last_insert_id('operon_transcript_id', undef, 'operon_transcript'); | ||
| 672 | |||
| 673 | # store the dbentries associated with this gene | ||
| 674 | my $dbEntryAdaptor = $db->get_DBEntryAdaptor(); | ||
| 675 | |||
| 676 | foreach my $dbe ( @{ $operon_transcript->get_all_DBEntries } ) { | ||
| 677 | $dbEntryAdaptor->store( $dbe, $operon_transcript_dbID, | ||
| 678 | "OperonTranscript" ); | ||
| 679 | } | ||
| 680 | |||
| 681 | # store operon attributes if there are any | ||
| 682 | my $attrs = $operon_transcript->get_all_Attributes(); | ||
| 683 | if ( $attrs && scalar @$attrs ) { | ||
| 684 | my $attr_adaptor = $db->get_AttributeAdaptor(); | ||
| 685 | $attr_adaptor->store_on_OperonTranscript( $operon_transcript, $attrs ); | ||
| 686 | } | ||
| 687 | |||
| 688 | # set the adaptor and dbID on the original passed in gene not the | ||
| 689 | # transfered copy | ||
| 690 | $operon_transcript->adaptor($self); | ||
| 691 | $operon_transcript->dbID($operon_transcript_dbID); | ||
| 692 | |||
| 693 | if ( defined $operon_transcript->{_gene_array} ) { | ||
| 694 | $self->store_genes_on_OperonTranscript( $operon_transcript, | ||
| 695 | $operon_transcript->{_gene_array} ); | ||
| 696 | } | ||
| 697 | |||
| 698 | return $operon_transcript_dbID; | ||
| 699 | } ## end sub store | ||
| 700 | |||
| 701 | =head2 store_genes_on_OperonTranscript | ||
| 702 | |||
| 703 | Arg [1] : Bio::EnsEMBL::OperonTranscript $ot | ||
| 704 | the operon_transcript to store genes on | ||
| 705 | Arg [2] : arrayref of Bio::EnsEMBL::Gene $gene | ||
| 706 | the genes to store on operon transcript | ||
| 707 | Example : $ot_adaptor->store_genes_on_OperonTranscript(\@genes); | ||
| 708 | Description: Associates genes with operon transcript | ||
| 709 | Returntype : none | ||
| 710 | Exceptions : throw on incorrect arguments | ||
| 711 | warning if operon_transcript is not stored in this database | ||
| 712 | Caller : general, store | ||
| 713 | Status : Stable | ||
| 714 | |||
| 715 | =cut | ||
| 716 | |||
| 717 | sub store_genes_on_OperonTranscript { | ||
| 718 | my ( $self, $operon_transcript, $genes ) = @_; | ||
| 719 | assert_ref( $operon_transcript, "Bio::EnsEMBL::OperonTranscript" ); | ||
| 720 | my $sth = $self->prepare( | ||
| 721 | 'insert into operon_transcript_gene(operon_transcript_id,gene_id) values(' | ||
| 722 | . $operon_transcript->dbID() | ||
| 723 | . ',?)' ); | ||
| 724 | for my $gene ( @{$genes} ) { | ||
| 725 | assert_ref( $gene, "Bio::EnsEMBL::Gene" ); | ||
| 726 | $sth->bind_param( 1, $gene->dbID(), SQL_INTEGER ); | ||
| 727 | $sth->execute(); | ||
| 728 | } | ||
| 729 | $sth->finish(); | ||
| 730 | return; | ||
| 731 | } | ||
| 732 | |||
| 733 | =head2 remove | ||
| 734 | |||
| 735 | Arg [1] : Bio::EnsEMBL::OperonTranscript $ot | ||
| 736 | the operon_transcript to remove from the database | ||
| 737 | Example : $ot_adaptor->remove($ot); | ||
| 738 | Description: Removes a operon transcript completely from the database. | ||
| 739 | Returntype : none | ||
| 740 | Exceptions : throw on incorrect arguments | ||
| 741 | warning if operon_transcript is not stored in this database | ||
| 742 | Caller : general | ||
| 743 | Status : Stable | ||
| 744 | |||
| 745 | =cut | ||
| 746 | |||
| 747 | sub remove { | ||
| 748 | my $self = shift; | ||
| 749 | my $operon_transcript = shift; | ||
| 750 | |||
| 751 | assert_ref( $operon_transcript, 'Bio::EnsEMBL::OperonTranscript' ); | ||
| 752 | |||
| 753 | if ( !$operon_transcript->is_stored( $self->db() ) ) { | ||
| 754 | warning( "Cannot remove operon transcript " | ||
| 755 | . $operon_transcript->dbID() | ||
| 756 | . ". Is not stored in " | ||
| 757 | . "this database." ); | ||
| 758 | return; | ||
| 759 | } | ||
| 760 | |||
| 761 | # remove all object xrefs associated with this gene | ||
| 762 | |||
| 763 | my $dbe_adaptor = $self->db()->get_DBEntryAdaptor(); | ||
| 764 | foreach my $dbe ( @{ $operon_transcript->get_all_DBEntries() } ) { | ||
| 765 | $dbe_adaptor->remove_from_object( $dbe, $operon_transcript, | ||
| 766 | 'OperonTranscript' ); | ||
| 767 | } | ||
| 768 | |||
| 769 | # # remove the attributes associated with this transcript | ||
| 770 | # my $attrib_adaptor = $self->db->get_AttributeAdaptor; | ||
| 771 | # $attrib_adaptor->remove_from_OperonTranscript($operon_transcript); | ||
| 772 | |||
| 773 | # remove from the database | ||
| 774 | my $sth = $self->prepare( | ||
| 775 | "DELETE FROM operon_transcript WHERE operon_transcript_id = ? "); | ||
| 776 | $sth->bind_param( 1, $operon_transcript->dbID, SQL_INTEGER ); | ||
| 777 | $sth->execute(); | ||
| 778 | $sth->finish(); | ||
| 779 | |||
| 780 | # unset the gene identifier and adaptor thereby flagging it as unstored | ||
| 781 | |||
| 782 | $operon_transcript->dbID(undef); | ||
| 783 | $operon_transcript->adaptor(undef); | ||
| 784 | |||
| 785 | return; | ||
| 786 | } ## end sub remove | ||
| 787 | |||
| 788 | # _objs_from_sth | ||
| 789 | |||
| 790 | # Arg [1] : StatementHandle $sth | ||
| 791 | # Arg [2] : Bio::EnsEMBL::AssemblyMapper $mapper | ||
| 792 | # Arg [3] : Bio::EnsEMBL::Slice $dest_slice | ||
| 793 | # Description: PROTECTED implementation of abstract superclass method. | ||
| 794 | # responsible for the creation of OperonTranscripts | ||
| 795 | # Returntype : listref of Bio::EnsEMBL::OperonTranscripts in target coordinate system | ||
| 796 | # Exceptions : none | ||
| 797 | # Caller : internal | ||
| 798 | # Status : Stable | ||
| 799 | |||
| 800 | sub _objs_from_sth { | ||
| 801 | my ($self, $sth, $mapper, $dest_slice) = @_; | ||
| 802 | |||
| 803 | # | ||
| 804 | # This code is ugly because an attempt has been made to remove as many | ||
| 805 | # function calls as possible for speed purposes. Thus many caches and | ||
| 806 | # a fair bit of gymnastics is used. | ||
| 807 | # | ||
| 808 | |||
| 809 | my $sa = $self->db()->get_SliceAdaptor(); | ||
| 810 | my $aa = $self->db()->get_AnalysisAdaptor(); | ||
| 811 | |||
| 812 | my @operons; | ||
| 813 | my %analysis_hash; | ||
| 814 | my %slice_hash; | ||
| 815 | my %sr_name_hash; | ||
| 816 | my %sr_cs_hash; | ||
| 817 | |||
| 818 | my ( | ||
| 819 | $operon_transcript_id, $seq_region_id, $seq_region_start, | ||
| 820 | $seq_region_end, $seq_region_strand, $display_label, | ||
| 821 | $analysis_id, $stable_id, $version, | ||
| 822 | $created_date, $modified_date ); | ||
| 823 | |||
| 824 | $sth->bind_columns( \( | ||
| 825 | $operon_transcript_id, $seq_region_id, $seq_region_start, | ||
| 826 | $seq_region_end, $seq_region_strand, $display_label, | ||
| 827 | $analysis_id, $stable_id, $version, | ||
| 828 | $created_date, $modified_date )); | ||
| 829 | |||
| 830 | my $dest_slice_start; | ||
| 831 | my $dest_slice_end; | ||
| 832 | my $dest_slice_strand; | ||
| 833 | my $dest_slice_length; | ||
| 834 | my $dest_slice_cs; | ||
| 835 | my $dest_slice_sr_name; | ||
| 836 | my $dest_slice_sr_id; | ||
| 837 | my $asma; | ||
| 838 | |||
| 839 | if ($dest_slice) { | ||
| 840 | $dest_slice_start = $dest_slice->start(); | ||
| 841 | $dest_slice_end = $dest_slice->end(); | ||
| 842 | $dest_slice_strand = $dest_slice->strand(); | ||
| 843 | $dest_slice_length = $dest_slice->length(); | ||
| 844 | $dest_slice_cs = $dest_slice->coord_system(); | ||
| 845 | $dest_slice_sr_name = $dest_slice->seq_region_name(); | ||
| 846 | $dest_slice_sr_id = $dest_slice->get_seq_region_id(); | ||
| 847 | $asma = $self->db->get_AssemblyMapperAdaptor(); | ||
| 848 | } | ||
| 849 | |||
| 850 | OPERON: while ( $sth->fetch() ) { | ||
| 851 | |||
| 852 | #get the analysis object | ||
| 853 | my $analysis = $analysis_hash{$analysis_id} ||= $aa->fetch_by_dbID($analysis_id); | ||
| 854 | $analysis_hash{$analysis_id} = $analysis; | ||
| 855 | |||
| 856 | #need to get the internal_seq_region, if present | ||
| 857 | $seq_region_id = $self->get_seq_region_id_internal($seq_region_id); | ||
| 858 | my $slice = $slice_hash{"ID:".$seq_region_id}; | ||
| 859 | |||
| 860 | if (!$slice) { | ||
| 861 | $slice = $sa->fetch_by_seq_region_id($seq_region_id); | ||
| 862 | $slice_hash{"ID:".$seq_region_id} = $slice; | ||
| 863 | $sr_name_hash{$seq_region_id} = $slice->seq_region_name(); | ||
| 864 | $sr_cs_hash{$seq_region_id} = $slice->coord_system(); | ||
| 865 | } | ||
| 866 | |||
| 867 | #obtain a mapper if none was defined, but a dest_seq_region was | ||
| 868 | if(!$mapper && $dest_slice && !$dest_slice_cs->equals($slice->coord_system)) { | ||
| 869 | $mapper = $asma->fetch_by_CoordSystems($dest_slice_cs, $slice->coord_system); | ||
| 870 | } | ||
| 871 | |||
| 872 | my $sr_name = $sr_name_hash{$seq_region_id}; | ||
| 873 | my $sr_cs = $sr_cs_hash{$seq_region_id}; | ||
| 874 | |||
| 875 | # | ||
| 876 | # remap the feature coordinates to another coord system | ||
| 877 | # if a mapper was provided | ||
| 878 | # | ||
| 879 | |||
| 880 | if ($mapper) { | ||
| 881 | |||
| 882 | if (defined $dest_slice && $mapper->isa('Bio::EnsEMBL::ChainedAssemblyMapper') ) { | ||
| 883 | ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) = | ||
| 884 | $mapper->map($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs, 1, $dest_slice); | ||
| 885 | |||
| 886 | } else { | ||
| 887 | ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) = | ||
| 888 | $mapper->fastmap($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs); | ||
| 889 | } | ||
| 890 | |||
| 891 | #skip features that map to gaps or coord system boundaries | ||
| 892 | next OPERON if ( !defined($seq_region_id) ); | ||
| 893 | |||
| 894 | #get a slice in the coord system we just mapped to | ||
| 895 | $slice = $slice_hash{"ID:".$seq_region_id} ||= $sa->fetch_by_seq_region_id($seq_region_id); | ||
| 896 | } | ||
| 897 | |||
| 898 | # | ||
| 899 | # If a destination slice was provided convert the coords. | ||
| 900 | # | ||
| 901 | if (defined($dest_slice)) { | ||
| 902 | my $seq_region_len = $dest_slice->seq_region_length(); | ||
| 903 | |||
| 904 | if ( $dest_slice_strand == 1 ) { | ||
| 905 | $seq_region_start = $seq_region_start - $dest_slice_start + 1; | ||
| 906 | $seq_region_end = $seq_region_end - $dest_slice_start + 1; | ||
| 907 | |||
| 908 | if ( $dest_slice->is_circular ) { | ||
| 909 | # Handle circular chromosomes. | ||
| 910 | |||
| 911 | if ( $seq_region_start > $seq_region_end ) { | ||
| 912 | # Looking at a feature overlapping the chromosome origin. | ||
| 913 | |||
| 914 | if ( $seq_region_end > $dest_slice_start ) { | ||
| 915 | # Looking at the region in the beginning of the chromosome | ||
| 916 | $seq_region_start -= $seq_region_len; | ||
| 917 | } | ||
| 918 | if ( $seq_region_end < 0 ) { | ||
| 919 | $seq_region_end += $seq_region_len; | ||
| 920 | } | ||
| 921 | } else { | ||
| 922 | if ($dest_slice_start > $dest_slice_end && $seq_region_end < 0) { | ||
| 923 | # Looking at the region overlapping the chromosome | ||
| 924 | # origin and a feature which is at the beginning of the | ||
| 925 | # chromosome. | ||
| 926 | $seq_region_start += $seq_region_len; | ||
| 927 | $seq_region_end += $seq_region_len; | ||
| 928 | } | ||
| 929 | } | ||
| 930 | } | ||
| 931 | } else { | ||
| 932 | |||
| 933 | my $start = $dest_slice_end - $seq_region_end + 1; | ||
| 934 | my $end = $dest_slice_end - $seq_region_start + 1; | ||
| 935 | |||
| 936 | if ($dest_slice->is_circular()) { | ||
| 937 | |||
| 938 | if ($dest_slice_start > $dest_slice_end) { | ||
| 939 | # slice spans origin or replication | ||
| 940 | |||
| 941 | if ($seq_region_start >= $dest_slice_start) { | ||
| 942 | $end += $seq_region_len; | ||
| 943 | $start += $seq_region_len if $seq_region_end > $dest_slice_start; | ||
| 944 | |||
| 945 | } elsif ($seq_region_start <= $dest_slice_end) { | ||
| 946 | # do nothing | ||
| 947 | } elsif ($seq_region_end >= $dest_slice_start) { | ||
| 948 | $start += $seq_region_len; | ||
| 949 | $end += $seq_region_len; | ||
| 950 | |||
| 951 | } elsif ($seq_region_end <= $dest_slice_end) { | ||
| 952 | $end += $seq_region_len if $end < 0; | ||
| 953 | |||
| 954 | } elsif ($seq_region_start > $seq_region_end) { | ||
| 955 | $end += $seq_region_len; | ||
| 956 | } | ||
| 957 | |||
| 958 | } else { | ||
| 959 | |||
| 960 | if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) { | ||
| 961 | # do nothing | ||
| 962 | } elsif ($seq_region_start > $seq_region_end) { | ||
| 963 | if ($seq_region_start <= $dest_slice_end) { | ||
| 964 | $start -= $seq_region_len; | ||
| 965 | } elsif ($seq_region_end >= $dest_slice_start) { | ||
| 966 | $end += $seq_region_len; | ||
| 967 | } | ||
| 968 | } | ||
| 969 | } | ||
| 970 | } | ||
| 971 | |||
| 972 | $seq_region_start = $start; | ||
| 973 | $seq_region_end = $end; | ||
| 974 | $seq_region_strand *= -1; | ||
| 975 | |||
| 976 | } ## end else [ if ( $dest_slice_strand...)] | ||
| 977 | |||
| 978 | # Throw away features off the end of the requested slice or on | ||
| 979 | # different seq_region. | ||
| 980 | if ($seq_region_end < 1 | ||
| 981 | || $seq_region_start > $dest_slice_length | ||
| 982 | || ($dest_slice_sr_id != $seq_region_id)) { | ||
| 983 | next OPERON; | ||
| 984 | } | ||
| 985 | $slice = $dest_slice; | ||
| 986 | } | ||
| 987 | |||
| 988 | push( @operons, | ||
| 989 | Bio::EnsEMBL::OperonTranscript->new( | ||
| 990 | -START => $seq_region_start, | ||
| 991 | -END => $seq_region_end, | ||
| 992 | -STRAND => $seq_region_strand, | ||
| 993 | -SLICE => $slice, | ||
| 994 | -DISPLAY_LABEL => $display_label, | ||
| 995 | -ADAPTOR => $self, | ||
| 996 | -DBID => $operon_transcript_id, | ||
| 997 | -STABLE_ID => $stable_id, | ||
| 998 | -VERSION => $version, | ||
| 999 | -CREATED_DATE => $created_date || undef, | ||
| 1000 | -MODIFIED_DATE => $modified_date || undef, | ||
| 1001 | -ANALYSIS => $analysis ) ); | ||
| 1002 | |||
| 1003 | } ## end while ( $sth->fetch() ) | ||
| 1004 | |||
| 1005 | return \@operons; | ||
| 1006 | } ## end sub _objs_from_sth | ||
| 1007 | |||
| 1008 | 1; | ||
| 1009 |