| 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 | package Bio::EnsEMBL::DBSQL::IntronSupportingEvidenceAdaptor; | ||
| 21 | $Bio::EnsEMBL::DBSQL::IntronSupportingEvidenceAdaptor::VERSION = '114.0.0'; | ||
| 22 | =pod | ||
| 23 | |||
| 24 | |||
| 25 | =head1 CONTACT | ||
| 26 | |||
| 27 | Please email comments or questions to the public Ensembl | ||
| 28 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 29 | |||
| 30 | Questions may also be sent to the Ensembl help desk at | ||
| 31 | <http://www.ensembl.org/Help/Contact>. | ||
| 32 | |||
| 33 | =head1 NAME | ||
| 34 | |||
| 35 | Bio::EnsEMBL::DBSQL::IntronSupportingEvidenceAdaptor | ||
| 36 | |||
| 37 | =head1 SYNOPSIS | ||
| 38 | |||
| 39 | my $isea = $dba->get_IntronSupportingEvidenceAdaptor(); | ||
| 40 | my $ise = $isea->fetch_by_dbID(1); | ||
| 41 | my $ise_array = $dfa->fetch_all(); | ||
| 42 | |||
| 43 | =head1 METHODS | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | use strict; | ||
| 48 | use warnings; | ||
| 49 | use base qw/Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor/; | ||
| 50 | |||
| 51 | use Bio::EnsEMBL::Intron; | ||
| 52 | use Bio::EnsEMBL::IntronSupportingEvidence; | ||
| 53 | use Bio::EnsEMBL::DBSQL::BaseAdaptor; | ||
| 54 | use Bio::EnsEMBL::Utils::Exception qw/throw/; | ||
| 55 | use Bio::EnsEMBL::Utils::Scalar qw/assert_ref/; | ||
| 56 | |||
| 57 | =head2 list_linked_transcript_ids | ||
| 58 | |||
| 59 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to search with | ||
| 60 | Example : my $transcript_ids = @{$isea->list_linked_transcript_ids($ise)}; | ||
| 61 | Description : Uses the given IntronSupportingEvidence to find all linked | ||
| 62 | transcript ids | ||
| 63 | Returntype : ArrayRef[Integer] of transcript_id | ||
| 64 | Exceptions : Thrown if arguments are not as stated and for DB errors | ||
| 65 | |||
| 66 | =cut | ||
| 67 | |||
| 68 | sub list_linked_transcript_ids { | ||
| 69 | my ($self, $sf) = @_; | ||
| 70 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_evidence'); | ||
| 71 | my $query = <<'SQL'; | ||
| 72 | select transcript_id from transcript_intron_supporting_evidence | ||
| 73 | where intron_supporting_evidence_id =? | ||
| 74 | SQL | ||
| 75 | return $self->dbc()->sql_helper()->execute_simple(-SQL => $query, -PARAMS => [$sf->dbID()]); | ||
| 76 | } | ||
| 77 | |||
| 78 | =head2 fetch_all_by_Transcript | ||
| 79 | |||
| 80 | Arg[1] : Bio::EnsEMBL::Transcript Transcript to search with | ||
| 81 | Example : my $ises = $isea->fetch_all_by_Transcript($transcript); | ||
| 82 | Description : Uses the given Transcript to search for all instances of | ||
| 83 | IntronSupportingEvidence linked to the transcript in the | ||
| 84 | database | ||
| 85 | Returntype : ArrayRef of IntronSupportingEvidence objects | ||
| 86 | Exceptions : Thrown if arguments are not as stated and for DB errors | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | sub fetch_all_by_Transcript { | ||
| 91 | my ($self, $transcript) = @_; | ||
| 92 | assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript'); | ||
| 93 | my $query = <<'SQL'; | ||
| 94 | select intron_supporting_evidence_id from transcript_intron_supporting_evidence where transcript_id =? | ||
| 95 | SQL | ||
| 96 | my $ids = $self->dbc()->sql_helper()->execute_simple(-SQL => $query, -PARAMS => [$transcript->dbID()]); | ||
| 97 | return $self->fetch_all_by_dbID_list($ids); | ||
| 98 | } | ||
| 99 | |||
| 100 | =head2 fetch_flanking_exon_ids | ||
| 101 | |||
| 102 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to search with | ||
| 103 | Arg[2] : Bio::EnsEMBL::Transcript Transcript to search with | ||
| 104 | Example : my ($prev_id, $next_id) = @{$isea->fetch_flanking_exon_ids($ise, $transcript)}; | ||
| 105 | Description : Uses the given IntronSupportingEvidence and Transcript to search | ||
| 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 | ||
| 110 | |||
| 111 | =cut | ||
| 112 | |||
| 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'); | ||
| 117 | my $query = <<'SQL'; | ||
| 118 | select previous_exon_id, next_exon_id | ||
| 119 | from transcript_intron_supporting_evidence | ||
| 120 | where transcript_id =? and intron_supporting_evidence_id =? | ||
| 121 | SQL | ||
| 122 | my $ids = $self->dbc()->sql_helper()->execute(-SQL => $query, -PARAMS => [$transcript->dbID(), $sf->dbID()]); | ||
| 123 | return unless @{$ids}; | ||
| 124 | return @{$ids->[0]}; | ||
| 125 | } | ||
| 126 | |||
| 127 | sub _tables { | ||
| 128 | return ( [ 'intron_supporting_evidence', 'ise' ] ); | ||
| 129 | } | ||
| 130 | |||
| 131 | sub _columns { | ||
| 132 | return qw/ | ||
| 133 | ise.intron_supporting_evidence_id | ||
| 134 | ise.analysis_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 | ||
| 138 | /; | ||
| 139 | } | ||
| 140 | |||
| 141 | # _objs_from_sth | ||
| 142 | |||
| 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 | ||
| 149 | # Exceptions : none | ||
| 150 | # Caller : internal | ||
| 151 | # Status : Stable | ||
| 152 | |||
| 153 | sub _objs_from_sth { | ||
| 154 | my ($self, $sth, $mapper, $dest_slice) = @_; | ||
| 155 | |||
| 156 | # | ||
| 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. | ||
| 160 | # | ||
| 161 | |||
| 162 | my $sa = $self->db()->get_SliceAdaptor(); | ||
| 163 | my $aa = $self->db()->get_AnalysisAdaptor(); | ||
| 164 | |||
| 165 | my @features; | ||
| 166 | my %analysis_hash; | ||
| 167 | my %slice_hash; | ||
| 168 | my %sr_name_hash; | ||
| 169 | my %sr_cs_hash; | ||
| 170 | |||
| 171 | my( | ||
| 172 | $id, $analysis_id, $seq_region_id, | ||
| 173 | $seq_region_start, $seq_region_end, $seq_region_strand, | ||
| 174 | $hit_name, $score, $score_type, | ||
| 175 | $splice_canonical); | ||
| 176 | |||
| 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, | ||
| 181 | $splice_canonical)); | ||
| 182 | |||
| 183 | my $dest_slice_start; | ||
| 184 | my $dest_slice_end; | ||
| 185 | my $dest_slice_strand; | ||
| 186 | my $dest_slice_length; | ||
| 187 | my $dest_slice_cs; | ||
| 188 | my $dest_slice_sr_name; | ||
| 189 | my $dest_slice_sr_id; | ||
| 190 | my $asma; | ||
| 191 | |||
| 192 | if ($dest_slice) { | ||
| 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(); | ||
| 201 | } | ||
| 202 | |||
| 203 | FEATURE: while($sth->fetch()) { | ||
| 204 | |||
| 205 | #get the analysis object | ||
| 206 | my $analysis = $analysis_hash{$analysis_id} ||= $aa->fetch_by_dbID($analysis_id); | ||
| 207 | $analysis_hash{$analysis_id} = $analysis; | ||
| 208 | |||
| 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}; | ||
| 212 | |||
| 213 | if (!$slice) { | ||
| 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(); | ||
| 218 | } | ||
| 219 | |||
| 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); | ||
| 223 | } | ||
| 224 | |||
| 225 | my $sr_name = $sr_name_hash{$seq_region_id}; | ||
| 226 | my $sr_cs = $sr_cs_hash{$seq_region_id}; | ||
| 227 | |||
| 228 | # | ||
| 229 | # remap the feature coordinates to another coord system | ||
| 230 | # if a mapper was provided | ||
| 231 | # | ||
| 232 | |||
| 233 | if ($mapper) { | ||
| 234 | |||
| 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); | ||
| 238 | |||
| 239 | } else { | ||
| 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); | ||
| 242 | } | ||
| 243 | |||
| 244 | #skip features that map to gaps or coord system boundaries | ||
| 245 | next FEATURE if (!defined($seq_region_id)); | ||
| 246 | |||
| 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); | ||
| 249 | } | ||
| 250 | |||
| 251 | # | ||
| 252 | # If a destination slice was provided convert the coords. | ||
| 253 | # | ||
| 254 | if (defined($dest_slice)) { | ||
| 255 | my $seq_region_len = $dest_slice->seq_region_length(); | ||
| 256 | |||
| 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; | ||
| 260 | |||
| 261 | if ( $dest_slice->is_circular ) { | ||
| 262 | # Handle circular chromosomes. | ||
| 263 | |||
| 264 | if ( $seq_region_start > $seq_region_end ) { | ||
| 265 | # Looking at a feature overlapping the chromosome origin. | ||
| 266 | |||
| 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; | ||
| 270 | } | ||
| 271 | if ( $seq_region_end < 0 ) { | ||
| 272 | $seq_region_end += $seq_region_len; | ||
| 273 | } | ||
| 274 | } else { | ||
| 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 | ||
| 278 | # chromosome. | ||
| 279 | $seq_region_start += $seq_region_len; | ||
| 280 | $seq_region_end += $seq_region_len; | ||
| 281 | } | ||
| 282 | } | ||
| 283 | } | ||
| 284 | } else { | ||
| 285 | |||
| 286 | my $start = $dest_slice_end - $seq_region_end + 1; | ||
| 287 | my $end = $dest_slice_end - $seq_region_start + 1; | ||
| 288 | |||
| 289 | if ($dest_slice->is_circular()) { | ||
| 290 | |||
| 291 | if ($dest_slice_start > $dest_slice_end) { | ||
| 292 | # slice spans origin or replication | ||
| 293 | |||
| 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; | ||
| 297 | |||
| 298 | } elsif ($seq_region_start <= $dest_slice_end) { | ||
| 299 | # do nothing | ||
| 300 | } elsif ($seq_region_end >= $dest_slice_start) { | ||
| 301 | $start += $seq_region_len; | ||
| 302 | $end += $seq_region_len; | ||
| 303 | |||
| 304 | } elsif ($seq_region_end <= $dest_slice_end) { | ||
| 305 | $end += $seq_region_len if $end < 0; | ||
| 306 | |||
| 307 | } elsif ($seq_region_start > $seq_region_end) { | ||
| 308 | $end += $seq_region_len; | ||
| 309 | } | ||
| 310 | |||
| 311 | } else { | ||
| 312 | |||
| 313 | if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) { | ||
| 314 | # do nothing | ||
| 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; | ||
| 320 | } | ||
| 321 | } | ||
| 322 | } | ||
| 323 | } | ||
| 324 | |||
| 325 | $seq_region_start = $start; | ||
| 326 | $seq_region_end = $end; | ||
| 327 | $seq_region_strand *= -1; | ||
| 328 | |||
| 329 | } ## end else [ if ( $dest_slice_strand...)] | ||
| 330 | |||
| 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)) { | ||
| 336 | next FEATURE; | ||
| 337 | } | ||
| 338 | $slice = $dest_slice; | ||
| 339 | } | ||
| 340 | |||
| 341 | push( @features, | ||
| 342 | $self->_create_feature_fast( | ||
| 343 | 'Bio::EnsEMBL::IntronSupportingEvidence', { | ||
| 344 | 'start' => $seq_region_start, | ||
| 345 | 'end' => $seq_region_end, | ||
| 346 | 'strand' => $seq_region_strand, | ||
| 347 | 'slice' => $slice, | ||
| 348 | 'analysis' => $analysis, | ||
| 349 | 'adaptor' => $self, | ||
| 350 | 'dbID' => $id, | ||
| 351 | 'hit_name' => $hit_name, | ||
| 352 | 'score' => $score, | ||
| 353 | 'score_type' => $score_type, | ||
| 354 | 'is_splice_canonical' => $splice_canonical, | ||
| 355 | } ) ); | ||
| 356 | } | ||
| 357 | |||
| 358 | return \@features; | ||
| 359 | } | ||
| 360 | |||
| 361 | ####### STORAGE | ||
| 362 | |||
| 363 | =head2 store | ||
| 364 | |||
| 365 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to store | ||
| 366 | Example : $isea->store($ise); | ||
| 367 | Description : Stores the IntronSupportingEvidence in the database. Duplicates | ||
| 368 | are ignored. | ||
| 369 | Returntype : Integer The assigned database identifier | ||
| 370 | Exceptions : Thrown if the given object is not a IntronSupportingEvidence, | ||
| 371 | and for any DB exception. | ||
| 372 | |||
| 373 | =cut | ||
| 374 | |||
| 375 | sub store { | ||
| 376 | my ($self, $sf) = @_; | ||
| 377 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_feature'); | ||
| 378 | |||
| 379 | my $db = $self->db(); | ||
| 380 | |||
| 381 | if($sf->is_stored($db)) { | ||
| 382 | return $sf->dbID(); | ||
| 383 | } | ||
| 384 | |||
| 385 | my $analysis = $sf->analysis(); | ||
| 386 | my $analysis_id = $analysis->is_stored($db) ? $analysis->dbID() : $db->get_AnalysisAdaptor()->store($analysis); | ||
| 387 | |||
| 388 | my $seq_region_id; | ||
| 389 | ($sf, $seq_region_id) = $self->_pre_store($sf); | ||
| 390 | |||
| 391 | my $insert_ignore = $self->insert_ignore_clause(); | ||
| 392 | my $sql = qq{ | ||
| 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 (?,?,?,?,?,?,?,?,?) | ||
| 396 | }; | ||
| 397 | |||
| 398 | #Used later on for duplicate entry retrieval | ||
| 399 | my $query_params = [ | ||
| 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], | ||
| 406 | ]; | ||
| 407 | |||
| 408 | my $params = [ | ||
| 409 | @{$query_params}, | ||
| 410 | [$sf->score(), SQL_FLOAT], | ||
| 411 | [$sf->score_type(), SQL_VARCHAR], | ||
| 412 | [$sf->is_splice_canonical(), SQL_INTEGER], | ||
| 413 | ]; | ||
| 414 | |||
| 415 | $self->dbc()->sql_helper()->execute_update(-SQL => $sql, -PARAMS => $params, -CALLBACK => sub { | ||
| 416 | my ( $sth, $dbh, $rv ) = @_; | ||
| 417 | if ($rv > 0) { | ||
| 418 | $sf->dbID($self->last_insert_id('intron_supporting_evidence_id', undef, 'intron_supporting_evidence')); | ||
| 419 | } | ||
| 420 | return; | ||
| 421 | }); | ||
| 422 | $sf->adaptor($self); | ||
| 423 | |||
| 424 | if(!$sf->dbID()) { | ||
| 425 | my $query = <<'SQL'; | ||
| 426 | select intron_supporting_evidence_id | ||
| 427 | from intron_supporting_evidence | ||
| 428 | where analysis_id =? | ||
| 429 | and seq_region_id =? and seq_region_start =? and seq_region_end =? and seq_region_strand =? | ||
| 430 | and hit_name =? | ||
| 431 | SQL | ||
| 432 | my $id = $self->dbc()->sql_helper()->execute_single_result(-SQL => $query, -PARAMS => $query_params); | ||
| 433 | $sf->dbID($id); | ||
| 434 | } | ||
| 435 | |||
| 436 | return $sf->dbID(); | ||
| 437 | } | ||
| 438 | |||
| 439 | =head2 store_transcript_linkage | ||
| 440 | |||
| 441 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to link | ||
| 442 | Arg[2] : Bio::EnsEMBL::Transcript Transcript to link | ||
| 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 | ||
| 447 | Returntype : None | ||
| 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. | ||
| 451 | |||
| 452 | =cut | ||
| 453 | |||
| 454 | sub store_transcript_linkage { | ||
| 455 | my ($self, $sf, $transcript, $transcript_id) = @_; | ||
| 456 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_evidence'); | ||
| 457 | assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript'); | ||
| 458 | |||
| 459 | throw "Cannot perform the link. The IntronSupportingEvidence must be persisted first" unless $sf->is_stored($self->db()); | ||
| 460 | |||
| 461 | my $insert_ignore = $self->insert_ignore_clause(); | ||
| 462 | my $sql = qq{ | ||
| 463 | ${insert_ignore} into transcript_intron_supporting_evidence | ||
| 464 | (transcript_id, intron_supporting_evidence_id, previous_exon_id, next_exon_id) | ||
| 465 | values (?,?,?,?) | ||
| 466 | }; | ||
| 467 | |||
| 468 | my $intron = $sf->get_Intron($transcript); | ||
| 469 | my ($previous_exon, $next_exon) = ($intron->prev_Exon(), $intron->next_Exon()); | ||
| 470 | $transcript_id ||= $transcript->dbID(); | ||
| 471 | |||
| 472 | my $params = [ | ||
| 473 | [$transcript_id, SQL_INTEGER], | ||
| 474 | [$sf->dbID(), SQL_INTEGER], | ||
| 475 | [$previous_exon->dbID(), SQL_INTEGER], | ||
| 476 | [$next_exon->dbID(), SQL_INTEGER], | ||
| 477 | ]; | ||
| 478 | $self->dbc()->sql_helper()->execute_update(-SQL => $sql, -PARAMS => $params); | ||
| 479 | |||
| 480 | return; | ||
| 481 | } | ||
| 482 | |||
| 483 | ####### UPDATE | ||
| 484 | |||
| 485 | =head2 update | ||
| 486 | |||
| 487 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to update | ||
| 488 | Example : $isea->update($ise); | ||
| 489 | Description : Updates all attributes of an evidence object | ||
| 490 | Returntype : None | ||
| 491 | Exceptions : Thrown if the given object is not a IntronSupportingEvidence, | ||
| 492 | if the object is not stored and for normal DB errors | ||
| 493 | |||
| 494 | =cut | ||
| 495 | |||
| 496 | sub update { | ||
| 497 | my ($self, $sf) = @_; | ||
| 498 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_evidence'); | ||
| 499 | if (! $sf->is_stored($self->db())) { | ||
| 500 | throw "Cannot update the supporting evidence if it has not already been stored in this database"; | ||
| 501 | } | ||
| 502 | |||
| 503 | my $params = [ | ||
| 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], | ||
| 514 | ]; | ||
| 515 | |||
| 516 | my $sql = <<'SQL'; | ||
| 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 =? | ||
| 522 | SQL | ||
| 523 | |||
| 524 | $self->dbc()->sql_helper()->execute_update(-SQL => $sql, -PARAMS => $params); | ||
| 525 | return; | ||
| 526 | } | ||
| 527 | |||
| 528 | ####### DELETION | ||
| 529 | |||
| 530 | =head2 remove | ||
| 531 | |||
| 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 | ||
| 536 | Returntype : None | ||
| 537 | Exceptions : Thrown if the IntronSupportingEvidence is not stored, if | ||
| 538 | the object has linked transcripts and in the event of any | ||
| 539 | database error | ||
| 540 | |||
| 541 | =cut | ||
| 542 | |||
| 543 | sub remove { | ||
| 544 | my ($self, $sf) = @_; | ||
| 545 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_evidence'); | ||
| 546 | if (! $sf->is_stored($self->db())) { | ||
| 547 | throw "Cannot delete the supporting evidence if it has not already been stored in this database"; | ||
| 548 | } | ||
| 549 | if($sf->has_linked_transcripts()) { | ||
| 550 | throw sprintf('Cannot delete supporting evidence %d. It still has transcripts attached', $sf->dbID()); | ||
| 551 | } | ||
| 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]], | ||
| 555 | ); | ||
| 556 | return; | ||
| 557 | } | ||
| 558 | |||
| 559 | =head2 remove_all_transcript_linkages | ||
| 560 | |||
| 561 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence | ||
| 562 | Example : $isea->remove_all_transcript_linkages($ise); | ||
| 563 | Description : Deletes the transcript links to the given IntronSupportingEvidence | ||
| 564 | Returntype : None | ||
| 565 | Exceptions : See remove_transcript_linkage | ||
| 566 | |||
| 567 | =cut | ||
| 568 | |||
| 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); | ||
| 573 | } | ||
| 574 | return; | ||
| 575 | } | ||
| 576 | |||
| 577 | =head2 remove_transcript_linkage | ||
| 578 | |||
| 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); | ||
| 582 | Description : Deletes a transcript's link to the given IntronSupportingEvidence | ||
| 583 | Returntype : None | ||
| 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. | ||
| 587 | |||
| 588 | =cut | ||
| 589 | |||
| 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"; | ||
| 595 | } | ||
| 596 | $self->_remove_transcript_linkage($sf, $transcript->dbID()); | ||
| 597 | return; | ||
| 598 | } | ||
| 599 | |||
| 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"; | ||
| 604 | } | ||
| 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]], | ||
| 608 | ); | ||
| 609 | return; | ||
| 610 | } | ||
| 611 | |||
| 612 | 1; |