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.
20 package Bio::EnsEMBL::DBSQL::IntronSupportingEvidenceAdaptor;
27 Please email comments or questions to the
public Ensembl
28 developers list at <http:
30 Questions may also be sent to the Ensembl help desk at
39 my $isea = $dba->get_IntronSupportingEvidenceAdaptor();
41 my $ise_array = $dfa->fetch_all();
57 =head2 list_linked_transcript_ids
60 Example : my $transcript_ids = @{$isea->list_linked_transcript_ids($ise)};
63 Returntype : ArrayRef[Integer] of transcript_id
64 Exceptions : Thrown
if arguments are not as stated and
for DB errors
68 sub list_linked_transcript_ids {
70 assert_ref($sf,
'Bio::EnsEMBL::IntronSupportingEvidence',
'intron_supporting_evidence');
72 select transcript_id from transcript_intron_supporting_evidence
73 where intron_supporting_evidence_id =?
75 return $self->dbc()->sql_helper()->execute_simple(-SQL => $query, -PARAMS => [$sf->dbID()]);
78 =head2 fetch_all_by_Transcript
81 Example : my $ises = $isea->fetch_all_by_Transcript($transcript);
82 Description : Uses the given
Transcript to search
for all instances of
86 Exceptions : Thrown
if arguments are not as stated and
for DB errors
90 sub fetch_all_by_Transcript {
91 my ($self, $transcript) = @_;
92 assert_ref($transcript,
'Bio::EnsEMBL::Transcript',
'transcript');
94 select intron_supporting_evidence_id from transcript_intron_supporting_evidence where transcript_id =?
96 my $ids = $self->dbc()->sql_helper()->execute_simple(-SQL => $query, -PARAMS => [$transcript->dbID()]);
97 return $self->fetch_all_by_dbID_list($ids);
100 =head2 fetch_flanking_exon_ids
104 Example : my ($prev_id, $next_id) = @{$isea->fetch_flanking_exon_ids($ise, $transcript)};
106 for the recorded previous and next
exon database ids
107 Returntype : ArrayRef 1 row
long but with 2 columns representing previous
108 and next IDs respectivly
109 Exceptions : Thrown
if arguments are not as stated and
for DB errors
113 sub fetch_flanking_exon_ids {
114 my ($self, $sf, $transcript) = @_;
115 assert_ref($sf,
'Bio::EnsEMBL::IntronSupportingEvidence',
'intron_supporting_evidence');
116 assert_ref($transcript,
'Bio::EnsEMBL::Transcript',
'transcript');
118 select previous_exon_id, next_exon_id
119 from transcript_intron_supporting_evidence
120 where transcript_id =? and intron_supporting_evidence_id =?
122 my $ids = $self->dbc()->sql_helper()->execute(-SQL => $query, -PARAMS => [$transcript->dbID(), $sf->dbID()]);
123 return unless @{$ids};
128 return ( [
'intron_supporting_evidence',
'ise' ] );
133 ise.intron_supporting_evidence_id
135 ise.seq_region_id ise.seq_region_start ise.seq_region_end ise.seq_region_strand
136 ise.hit_name ise.score ise.score_type
137 ise.is_splice_canonical
143 # Arg [1] : StatementHandle $sth
144 # Arg [2] : Bio::EnsEMBL::AssemblyMapper $mapper
145 # Arg [3] : Bio::EnsEMBL::Slice $dest_slice
146 # Description: PROTECTED implementation of abstract superclass method.
147 # responsible for the creation of Intron supporting features
148 # Returntype : listref of Bio::EnsEMBL::IntronSupportingFeatures in target coordinate system
154 my ($self, $sth, $mapper, $dest_slice) = @_;
157 # This code is ugly because an attempt has been made to remove as many
158 # function calls as possible for speed purposes. Thus many caches and
159 # a fair bit of gymnastics is used.
162 my $sa = $self->db()->get_SliceAdaptor();
163 my $aa = $self->db()->get_AnalysisAdaptor();
172 $id, $analysis_id, $seq_region_id,
173 $seq_region_start, $seq_region_end, $seq_region_strand,
174 $hit_name, $score, $score_type,
177 $sth->bind_columns(\(
178 $id, $analysis_id, $seq_region_id,
179 $seq_region_start, $seq_region_end, $seq_region_strand,
180 $hit_name, $score, $score_type,
183 my $dest_slice_start;
185 my $dest_slice_strand;
186 my $dest_slice_length;
188 my $dest_slice_sr_name;
189 my $dest_slice_sr_id;
193 $dest_slice_start = $dest_slice->start();
194 $dest_slice_end = $dest_slice->end();
195 $dest_slice_strand = $dest_slice->strand();
196 $dest_slice_length = $dest_slice->length();
197 $dest_slice_cs = $dest_slice->coord_system();
198 $dest_slice_sr_name = $dest_slice->seq_region_name();
199 $dest_slice_sr_id = $dest_slice->get_seq_region_id();
200 $asma = $self->db->get_AssemblyMapperAdaptor();
203 FEATURE:
while($sth->fetch()) {
205 #get the analysis object
206 my $analysis = $analysis_hash{$analysis_id} ||= $aa->fetch_by_dbID($analysis_id);
207 $analysis_hash{$analysis_id} = $analysis;
209 #need to get the internal_seq_region, if present
210 $seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
211 my $slice = $slice_hash{
"ID:".$seq_region_id};
214 $slice = $sa->fetch_by_seq_region_id($seq_region_id);
215 $slice_hash{
"ID:".$seq_region_id} = $slice;
216 $sr_name_hash{$seq_region_id} = $slice->seq_region_name();
217 $sr_cs_hash{$seq_region_id} = $slice->coord_system();
220 #obtain a mapper if none was defined, but a dest_seq_region was
221 if(!$mapper && $dest_slice && !$dest_slice_cs->equals($slice->coord_system)) {
222 $mapper = $asma->fetch_by_CoordSystems($dest_slice_cs, $slice->coord_system);
225 my $sr_name = $sr_name_hash{$seq_region_id};
226 my $sr_cs = $sr_cs_hash{$seq_region_id};
229 # remap the feature coordinates to another coord system
230 # if a mapper was provided
235 if (defined $dest_slice && $mapper->isa(
'Bio::EnsEMBL::ChainedAssemblyMapper') ) {
236 ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) =
237 $mapper->map($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs, 1, $dest_slice);
240 ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) =
241 $mapper->fastmap($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs);
244 #skip features that map to gaps or coord system boundaries
245 next FEATURE
if (!defined($seq_region_id));
247 #get a slice in the coord system we just mapped to
248 $slice = $slice_hash{
"ID:".$seq_region_id} ||= $sa->fetch_by_seq_region_id($seq_region_id);
252 # If a destination slice was provided convert the coords.
254 if (defined($dest_slice)) {
255 my $seq_region_len = $dest_slice->seq_region_length();
257 if ( $dest_slice_strand == 1 ) {
258 $seq_region_start = $seq_region_start - $dest_slice_start + 1;
259 $seq_region_end = $seq_region_end - $dest_slice_start + 1;
261 if ( $dest_slice->is_circular ) {
262 # Handle circular chromosomes.
264 if ( $seq_region_start > $seq_region_end ) {
265 # Looking at a feature overlapping the chromosome origin.
267 if ( $seq_region_end > $dest_slice_start ) {
268 # Looking at the region in the beginning of the chromosome
269 $seq_region_start -= $seq_region_len;
271 if ( $seq_region_end < 0 ) {
272 $seq_region_end += $seq_region_len;
275 if ($dest_slice_start > $dest_slice_end && $seq_region_end < 0) {
276 # Looking at the region overlapping the chromosome
277 # origin and a feature which is at the beginning of the
279 $seq_region_start += $seq_region_len;
280 $seq_region_end += $seq_region_len;
286 my $start = $dest_slice_end - $seq_region_end + 1;
287 my $end = $dest_slice_end - $seq_region_start + 1;
289 if ($dest_slice->is_circular()) {
291 if ($dest_slice_start > $dest_slice_end) {
292 # slice spans origin or replication
294 if ($seq_region_start >= $dest_slice_start) {
295 $end += $seq_region_len;
296 $start += $seq_region_len
if $seq_region_end > $dest_slice_start;
298 } elsif ($seq_region_start <= $dest_slice_end) {
300 } elsif ($seq_region_end >= $dest_slice_start) {
301 $start += $seq_region_len;
302 $end += $seq_region_len;
304 } elsif ($seq_region_end <= $dest_slice_end) {
305 $end += $seq_region_len
if $end < 0;
307 } elsif ($seq_region_start > $seq_region_end) {
308 $end += $seq_region_len;
313 if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) {
315 } elsif ($seq_region_start > $seq_region_end) {
316 if ($seq_region_start <= $dest_slice_end) {
317 $start -= $seq_region_len;
318 } elsif ($seq_region_end >= $dest_slice_start) {
319 $end += $seq_region_len;
325 $seq_region_start = $start;
326 $seq_region_end = $end;
327 $seq_region_strand *= -1;
329 } ## end
else [
if ( $dest_slice_strand...)]
331 # Throw away features off the end of the requested slice or on
332 # different seq_region.
333 if ($seq_region_end < 1
334 || $seq_region_start > $dest_slice_length
335 || ($dest_slice_sr_id != $seq_region_id)) {
338 $slice = $dest_slice;
342 $self->_create_feature_fast(
343 'Bio::EnsEMBL::IntronSupportingEvidence', {
344 'start' => $seq_region_start,
345 'end' => $seq_region_end,
346 'strand' => $seq_region_strand,
348 'analysis' => $analysis,
351 'hit_name' => $hit_name,
353 'score_type' => $score_type,
354 'is_splice_canonical' => $splice_canonical,
366 Example : $isea->store($ise);
369 Returntype : Integer The assigned database identifier
371 and
for any DB exception.
376 my ($self, $sf) = @_;
377 assert_ref($sf,
'Bio::EnsEMBL::IntronSupportingEvidence',
'intron_supporting_feature');
379 my $db = $self->db();
381 if($sf->is_stored($db)) {
385 my $analysis = $sf->analysis();
386 my $analysis_id = $analysis->is_stored($db) ? $analysis->dbID() : $db->get_AnalysisAdaptor()->store($analysis);
389 ($sf, $seq_region_id) = $self->_pre_store($sf);
391 my $insert_ignore = $self->insert_ignore_clause();
393 ${insert_ignore} into intron_supporting_evidence
394 (analysis_id, seq_region_id, seq_region_start, seq_region_end, seq_region_strand, hit_name, score, score_type, is_splice_canonical)
395 values (?,?,?,?,?,?,?,?,?)
398 #Used later on for duplicate entry retrieval
400 [$analysis_id, SQL_INTEGER],
401 [$seq_region_id, SQL_INTEGER],
402 [$sf->start(), SQL_INTEGER],
403 [$sf->end(), SQL_INTEGER],
404 [$sf->strand(), SQL_INTEGER],
405 [$sf->hit_name(), SQL_VARCHAR],
410 [$sf->score(), SQL_FLOAT],
411 [$sf->score_type(), SQL_VARCHAR],
412 [$sf->is_splice_canonical(), SQL_INTEGER],
415 $self->dbc()->sql_helper()->execute_update(-SQL => $sql, -PARAMS => $params, -CALLBACK => sub {
416 my ( $sth, $dbh, $rv ) = @_;
418 $sf->dbID($self->last_insert_id(
'intron_supporting_evidence_id', undef,
'intron_supporting_evidence'));
426 select intron_supporting_evidence_id
427 from intron_supporting_evidence
429 and seq_region_id =? and seq_region_start =? and seq_region_end =? and seq_region_strand =?
432 my $id = $self->dbc()->sql_helper()->execute_single_result(-SQL => $query, -PARAMS => $query_params);
439 =head2 store_transcript_linkage
443 Arg[3] : Integer an optional ID to give
if the
Transcript's own ID is possibly incorrect
444 Example : $isea->store_transcript_linkage($ise, $transcript);
445 $isea->store_transcript_linkage($ise, $transcript, $tid);
446 Description : Links a Transcript to a portion of Intron evidence
448 Exceptions : Thrown if the given object is not a Transcript, if the
449 transcript is not stored, if the supporting evidence is not
450 stored and for any DB exception.
454 sub store_transcript_linkage {
455 my ($self, $sf, $transcript, $transcript_id) = @_;
459 throw "Cannot perform the link. The IntronSupportingEvidence must be persisted first" unless $sf->is_stored($self->db());
461 my $insert_ignore = $self->insert_ignore_clause();
463 ${insert_ignore} into transcript_intron_supporting_evidence
464 (transcript_id, intron_supporting_evidence_id, previous_exon_id, next_exon_id)
468 my $intron = $sf->get_Intron($transcript);
469 my ($previous_exon, $next_exon) = ($intron->prev_Exon(), $intron->next_Exon());
470 $transcript_id ||= $transcript->dbID();
473 [$transcript_id, SQL_INTEGER],
474 [$sf->dbID(), SQL_INTEGER],
475 [$previous_exon->dbID(), SQL_INTEGER],
476 [$next_exon->dbID(), SQL_INTEGER],
478 $self->dbc()->sql_helper()->execute_update(-SQL => $sql, -PARAMS => $params);
487 Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to update
488 Example : $isea->update($ise);
489 Description : Updates all attributes of an evidence object
491 Exceptions : Thrown if the given object is not a IntronSupportingEvidence,
492 if the object is not stored and for normal DB errors
497 my ($self, $sf) = @_;
499 if (! $sf->is_stored($self->db())) {
500 throw "Cannot update the supporting evidence if it has not already been stored in this database";
504 [$sf->analysis()->dbID(), SQL_INTEGER],
505 [$sf->slice()->get_seq_region_id(), SQL_INTEGER],
506 [$sf->start(), SQL_INTEGER],
507 [$sf->end(), SQL_INTEGER],
508 [$sf->strand(), SQL_INTEGER],
509 [$sf->hit_name(), SQL_VARCHAR],
510 [$sf->score(), SQL_FLOAT],
511 [$sf->score_type(), SQL_VARCHAR],
512 [$sf->is_splice_canonical() || 0, SQL_INTEGER],
513 [$sf->dbID(), SQL_INTEGER],
517 UPDATE intron_supporting_evidence
518 SET analysis_id =?, seq_region_id =?, seq_region_start =?,
519 seq_region_end =?, seq_region_strand =?, hit_name =?, score =?, score_type =?,
520 is_splice_canonical =?
521 WHERE intron_supporting_evidence_id =?
524 $self->dbc()->sql_helper()->execute_update(-SQL => $sql, -PARAMS => $params);
532 Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence
533 Example : $isea->remove($ise);
534 Description : Deletes the given IntronSupportingEvidence from the database.
535 This can only occur if the object has no linked transcripts
537 Exceptions : Thrown if the IntronSupportingEvidence is not stored, if
538 the object has linked transcripts and in the event of any
544 my ($self, $sf) = @_;
546 if (! $sf->is_stored($self->db())) {
547 throw "Cannot delete the supporting evidence if it has not already been stored in this database";
549 if($sf->has_linked_transcripts()) {
550 throw sprintf('Cannot
delete supporting evidence %d. It still has transcripts attached
', $sf->dbID());
552 $self->dbc()->sql_helper()->execute_update(
553 -SQL => 'DELETE from intron_supporting_evidence where intron_supporting_evidence_id =?
',
554 -PARAMS => [[$sf->dbID(), SQL_INTEGER]],
559 =head2 remove_all_transcript_linkages
561 Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence
562 Example : $isea->remove_all_transcript_linkages($ise);
563 Description : Deletes the transcript links to the given IntronSupportingEvidence
565 Exceptions : See remove_transcript_linkage
569 sub remove_all_transcript_linkages {
570 my ($self, $sf) = @_;
571 foreach my $transcript_id (@{$self->list_linked_transcript_ids($sf)}) {
572 $self->_remove_transcript_linkage($sf, $transcript_id);
577 =head2 remove_transcript_linkage
579 Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to unlink
580 Arg[2] : Bio::EnsEMBL::Transcript Transcript to unlink
581 Example : $isea->remove_transcript_linkages($ise, $transcript);
584 Exceptions : Thrown
if the given
object is not a
Transcript,
if the
585 transcript is not stored,
if the supporting evidence is not
586 stored and
for any DB exception.
590 sub remove_transcript_linkage {
591 my ($self, $sf, $transcript) = @_;
592 assert_ref($transcript,
'Bio::EnsEMBL::Transcript',
'transcript');
593 if (! $transcript->is_stored($self->db())) {
594 throw "Cannot delete the supporting evidence to transcript linkage if the transcript has not already been stored in this database";
596 $self->_remove_transcript_linkage($sf, $transcript->dbID());
600 sub _remove_transcript_linkage {
601 my ($self, $sf, $transcript_id) = @_;
602 if (! $sf->is_stored($self->db())) {
603 throw "Cannot delete the supporting evidence to transcript linkage if the evidence has not already been stored in this database";
605 $self->dbc()->sql_helper()->execute_update(
606 -SQL =>
'DELETE from transcript_intron_supporting_evidence where intron_supporting_evidence_id =? and transcript_id =?',
607 -PARAMS => [[$sf->dbID(), SQL_INTEGER], [$transcript_id, SQL_INTEGER]],