3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
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
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.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
38 $pea = $database_adaptor->get_PredictionExonAdaptor();
42 $database_adaptor->get_SliceAdaptor->fetch_by_region(
'X', 1, 1e6 );
44 my @pexons = @{ $pea->fetch_all_by_Slice($slice) };
50 package Bio::EnsEMBL::DBSQL::PredictionExonAdaptor;
68 # Description: PROTECTED implementation of superclass abstract method
69 # returns the names, aliases of the tables to use for queries
70 # Returntype : list of listrefs of strings
76 return ([
'prediction_exon',
'pe' ] );
85 # Description: PROTECTED implementation of superclass abstract method
86 # returns a list of columns to use for queries
87 # Returntype : list of strings
94 return qw( pe.prediction_exon_id
109 # Description: PROTECTED implementation of superclass abstract method
110 # returns a default end for the SQL-query (ORDER BY)
111 # Returntype : string
116 return "ORDER BY pe.prediction_transcript_id, pe.exon_rank";
120 =head2 fetch_all_by_PredictionTranscript
122 Arg [1] : Bio::EnsEMBL::PredcitionTranscript $transcript
124 Description: Retrieves all Exons
for the Transcript in 5-3 order
126 Exceptions :
throws if transcript does not have a slice
127 Caller : Transcript->get_all_Exons()
132 sub fetch_all_by_PredictionTranscript {
133 my ( $self, $transcript ) = @_;
134 my $constraint =
"pe.prediction_transcript_id = ".$transcript->dbID();
136 # use 'keep_all' option to keep exons that are off end of slice
138 my $tslice = $transcript->slice();
142 throw(
"Transcript must have attached slice to retrieve exons.");
145 # use a small slice the same size as the prediction transcript
146 $slice = $self->db->get_SliceAdaptor->fetch_by_Feature($transcript);
148 my $exons = $self->fetch_all_by_Slice_constraint($slice, $constraint);
150 # remap exon coordinates if necessary
151 if($slice->name() ne $tslice->name()) {
153 foreach my $ex (@$exons) {
154 push @out, $ex->transfer($tslice);
167 The
exon to store in
this database
168 Arg [2] :
int $prediction_transcript_id
169 The
internal identifier of the prediction
exon that that
this
170 exon is associated with.
173 Example : $pexon_adaptor->store($pexon, 1211, 2);
174 Description: Stores a PredictionExon in the database
176 Exceptions : thrown
if exon does not have a slice attached
177 or
if $exon->start, $exon->end, $exon->strand, or $exon->phase
185 my ( $self, $pexon, $pt_id, $rank ) = @_;
187 if(!ref($pexon) || !$pexon->isa(
'Bio::EnsEMBL::PredictionExon') ) {
188 throw(
"Expected PredictionExon argument");
191 throw(
"Expected PredictionTranscript id argument.")
if(!$pt_id);
192 throw(
"Expected rank argument.")
if(!$rank);
194 my $db = $self->db();
196 if($pexon->is_stored($db)) {
197 warning(
'PredictionExon is already stored in this DB.');
198 return $pexon->dbID();
201 if( ! $pexon->start || ! $pexon->end ||
202 ! $pexon->strand || ! defined $pexon->phase ) {
203 throw(
"PredictionExon does not have all attributes to store.\n" .
204 "start, end, strand and phase attributes must be set.");
207 #maintain reference to original passed-in prediction exon
208 my $original = $pexon;
210 ($pexon, $seq_region_id) = $self->_pre_store($pexon);
212 my $sth = $db->dbc->prepare
213 (
"INSERT into prediction_exon (prediction_transcript_id, exon_rank, " .
214 "seq_region_id, seq_region_start, seq_region_end, " .
215 "seq_region_strand, start_phase, score, p_value) " .
216 "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )");
218 $sth->bind_param(1,$pt_id,SQL_INTEGER);
219 $sth->bind_param(2,$rank,SQL_SMALLINT);
220 $sth->bind_param(3,$seq_region_id,SQL_INTEGER);
221 $sth->bind_param(4,$pexon->start,SQL_INTEGER);
222 $sth->bind_param(5,$pexon->end,SQL_INTEGER);
223 $sth->bind_param(6,$pexon->strand,SQL_TINYINT);
224 $sth->bind_param(7,$pexon->phase,SQL_TINYINT);
225 $sth->bind_param(8,$pexon->score,SQL_DOUBLE);
226 $sth->bind_param(9,$pexon->p_value,SQL_DOUBLE);
230 my $dbID = $self->last_insert_id(
'prediction_transcript_id', undef,
'prediction_transcript');
232 #set the adaptor and dbID of the object they passed in
233 $original->dbID($dbID);
234 $original->adaptor($self);
244 the
exon to remove from the database
245 Example : $exon_adaptor->remove($exon);
246 Description: Removes an
exon from the database
258 my $db = $self->db();
260 if(!$pexon->is_stored($db)) {
261 warning(
'PredictionExon is not in this DB - not removing');
265 my $sth = $self->prepare(
266 "DELETE FROM prediction_exon WHERE prediction_exon_id = ?");
267 $sth->bind_param( 1, $pexon->dbID, SQL_INTEGER );
271 $pexon->adaptor(undef);
279 Example : @exon_ids = @{$exon_adaptor->list_dbIDs()};
280 Description: Gets an array of
internal ids
for all exons in the current db
281 Arg[1] : <optional>
int. not 0
for the ids to be sorted by the seq_region.
282 Returntype : list of ints
290 my ($self,$ordered) = @_;
292 return $self->_list_dbIDs(
"prediction_exon",undef, $ordered);
299 # Arg [1] : Hashreference $hashref
301 # Description: PROTECTED implementation of abstract superclass method.
302 # responsible for the creation of Genes
303 # Returntype : listref of Bio::EnsEMBL::Genes in target coordinate system
309 my ($self, $sth, $mapper, $dest_slice) = @_;
312 # This code is ugly because an attempt has been made to remove as many
313 # function calls as possible for speed purposes. Thus many caches and
314 # a fair bit of gymnastics is used.
316 my $sa = $self->db()->get_SliceAdaptor();
324 $prediction_exon_id, $seq_region_id,
325 $seq_region_start, $seq_region_end, $seq_region_strand,
326 $start_phase, $score, $p_value);
328 $sth->bind_columns(\(
329 $prediction_exon_id, $seq_region_id,
330 $seq_region_start, $seq_region_end, $seq_region_strand,
331 $start_phase, $score, $p_value));
333 my $dest_slice_start;
335 my $dest_slice_strand;
336 my $dest_slice_length;
338 my $dest_slice_sr_name;
339 my $dest_slice_sr_id;
343 $dest_slice_start = $dest_slice->start();
344 $dest_slice_end = $dest_slice->end();
345 $dest_slice_strand = $dest_slice->strand();
346 $dest_slice_length = $dest_slice->length();
347 $dest_slice_cs = $dest_slice->coord_system();
348 $dest_slice_sr_name = $dest_slice->seq_region_name();
349 $dest_slice_sr_id = $dest_slice->get_seq_region_id();
350 $asma = $self->db->get_AssemblyMapperAdaptor();
353 FEATURE:
while($sth->fetch()) {
355 #need to get the internal_seq_region, if present
356 $seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
357 my $slice = $slice_hash{
"ID:".$seq_region_id};
360 $slice = $sa->fetch_by_seq_region_id($seq_region_id);
361 $slice_hash{
"ID:".$seq_region_id} = $slice;
362 $sr_name_hash{$seq_region_id} = $slice->seq_region_name();
363 $sr_cs_hash{$seq_region_id} = $slice->coord_system();
366 #obtain a mapper if none was defined, but a dest_seq_region was
367 if(!$mapper && $dest_slice && !$dest_slice_cs->equals($slice->coord_system)) {
368 $mapper = $asma->fetch_by_CoordSystems($dest_slice_cs, $slice->coord_system);
371 my $sr_name = $sr_name_hash{$seq_region_id};
372 my $sr_cs = $sr_cs_hash{$seq_region_id};
375 # remap the feature coordinates to another coord system
376 # if a mapper was provided
381 if (defined $dest_slice && $mapper->isa(
'Bio::EnsEMBL::ChainedAssemblyMapper') ) {
382 ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) =
383 $mapper->map($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs, 1, $dest_slice);
386 ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) =
387 $mapper->fastmap($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs);
390 #skip features that map to gaps or coord system boundaries
391 next FEATURE
if (!defined($seq_region_id));
393 #get a slice in the coord system we just mapped to
394 $slice = $slice_hash{
"ID:".$seq_region_id} ||= $sa->fetch_by_seq_region_id($seq_region_id);
398 # If a destination slice was provided convert the coords.
400 if (defined($dest_slice)) {
401 my $seq_region_len = $dest_slice->seq_region_length();
403 if ( $dest_slice_strand == 1 ) {
404 $seq_region_start = $seq_region_start - $dest_slice_start + 1;
405 $seq_region_end = $seq_region_end - $dest_slice_start + 1;
407 if ( $dest_slice->is_circular ) {
408 # Handle circular chromosomes.
410 if ( $seq_region_start > $seq_region_end ) {
411 # Looking at a feature overlapping the chromosome origin.
413 if ( $seq_region_end > $dest_slice_start ) {
414 # Looking at the region in the beginning of the chromosome
415 $seq_region_start -= $seq_region_len;
417 if ( $seq_region_end < 0 ) {
418 $seq_region_end += $seq_region_len;
421 if ($dest_slice_start > $dest_slice_end && $seq_region_end < 0) {
422 # Looking at the region overlapping the chromosome
423 # origin and a feature which is at the beginning of the
425 $seq_region_start += $seq_region_len;
426 $seq_region_end += $seq_region_len;
432 my $start = $dest_slice_end - $seq_region_end + 1;
433 my $end = $dest_slice_end - $seq_region_start + 1;
435 if ($dest_slice->is_circular()) {
437 if ($dest_slice_start > $dest_slice_end) {
438 # slice spans origin or replication
440 if ($seq_region_start >= $dest_slice_start) {
441 $end += $seq_region_len;
442 $start += $seq_region_len
if $seq_region_end > $dest_slice_start;
444 } elsif ($seq_region_start <= $dest_slice_end) {
446 } elsif ($seq_region_end >= $dest_slice_start) {
447 $start += $seq_region_len;
448 $end += $seq_region_len;
450 } elsif ($seq_region_end <= $dest_slice_end) {
451 $end += $seq_region_len
if $end < 0;
453 } elsif ($seq_region_start > $seq_region_end) {
454 $end += $seq_region_len;
459 if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) {
461 } elsif ($seq_region_start > $seq_region_end) {
462 if ($seq_region_start <= $dest_slice_end) {
463 $start -= $seq_region_len;
464 } elsif ($seq_region_end >= $dest_slice_start) {
465 $end += $seq_region_len;
471 $seq_region_start = $start;
472 $seq_region_end = $end;
473 $seq_region_strand *= -1;
475 } ## end
else [
if ( $dest_slice_strand...)]
477 # Throw away features off the end of the requested slice or on
478 # different seq_region.
479 if ($seq_region_end < 1
480 || $seq_region_start > $dest_slice_length
481 || ($dest_slice_sr_id != $seq_region_id)) {
484 $slice = $dest_slice;
487 # Finally, create the new PredictionExon.
489 $self->_create_feature(
'Bio::EnsEMBL::PredictionExon', {
490 '-start' => $seq_region_start,
491 '-end' => $seq_region_end,
492 '-strand' => $seq_region_strand,
495 '-dbID' => $prediction_exon_id,
496 '-phase' => $start_phase,
498 '-p_value' => $p_value