| 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_50'; # TRIAL | ||
| 22 | $Bio::EnsEMBL::DBSQL::IntronSupportingEvidenceAdaptor::VERSION = '114.0.050'; | ||
| 23 | =pod | ||
| 24 | |||
| 25 | |||
| 26 | =head1 CONTACT | ||
| 27 | |||
| 28 | Please email comments or questions to the public Ensembl | ||
| 29 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 30 | |||
| 31 | Questions may also be sent to the Ensembl help desk at | ||
| 32 | <http://www.ensembl.org/Help/Contact>. | ||
| 33 | |||
| 34 | =head1 NAME | ||
| 35 | |||
| 36 | Bio::EnsEMBL::DBSQL::IntronSupportingEvidenceAdaptor | ||
| 37 | |||
| 38 | =head1 SYNOPSIS | ||
| 39 | |||
| 40 | my $isea = $dba->get_IntronSupportingEvidenceAdaptor(); | ||
| 41 | my $ise = $isea->fetch_by_dbID(1); | ||
| 42 | my $ise_array = $dfa->fetch_all(); | ||
| 43 | |||
| 44 | =head1 METHODS | ||
| 45 | |||
| 46 | =cut | ||
| 47 | |||
| 48 | use strict; | ||
| 49 | use warnings; | ||
| 50 | use base qw/Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor/; | ||
| 51 | |||
| 52 | use Bio::EnsEMBL::Intron; | ||
| 53 | use Bio::EnsEMBL::IntronSupportingEvidence; | ||
| 54 | use Bio::EnsEMBL::DBSQL::BaseAdaptor; | ||
| 55 | use Bio::EnsEMBL::Utils::Exception qw/throw/; | ||
| 56 | use Bio::EnsEMBL::Utils::Scalar qw/assert_ref/; | ||
| 57 | |||
| 58 | =head2 list_linked_transcript_ids | ||
| 59 | |||
| 60 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to search with | ||
| 61 | Example : my $transcript_ids = @{$isea->list_linked_transcript_ids($ise)}; | ||
| 62 | Description : Uses the given IntronSupportingEvidence to find all linked | ||
| 63 | transcript ids | ||
| 64 | Returntype : ArrayRef[Integer] of transcript_id | ||
| 65 | Exceptions : Thrown if arguments are not as stated and for DB errors | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | sub list_linked_transcript_ids { | ||
| 70 | my ($self, $sf) = @_; | ||
| 71 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_evidence'); | ||
| 72 | my $query = <<'SQL'; | ||
| 73 | select transcript_id from transcript_intron_supporting_evidence | ||
| 74 | where intron_supporting_evidence_id =? | ||
| 75 | SQL | ||
| 76 | return $self->dbc()->sql_helper()->execute_simple(-SQL => $query, -PARAMS => [$sf->dbID()]); | ||
| 77 | } | ||
| 78 | |||
| 79 | =head2 fetch_all_by_Transcript | ||
| 80 | |||
| 81 | Arg[1] : Bio::EnsEMBL::Transcript Transcript to search with | ||
| 82 | Example : my $ises = $isea->fetch_all_by_Transcript($transcript); | ||
| 83 | Description : Uses the given Transcript to search for all instances of | ||
| 84 | IntronSupportingEvidence linked to the transcript in the | ||
| 85 | database | ||
| 86 | Returntype : ArrayRef of IntronSupportingEvidence objects | ||
| 87 | Exceptions : Thrown if arguments are not as stated and for DB errors | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | sub fetch_all_by_Transcript { | ||
| 92 | my ($self, $transcript) = @_; | ||
| 93 | assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript'); | ||
| 94 | my $query = <<'SQL'; | ||
| 95 | select intron_supporting_evidence_id from transcript_intron_supporting_evidence where transcript_id =? | ||
| 96 | SQL | ||
| 97 | my $ids = $self->dbc()->sql_helper()->execute_simple(-SQL => $query, -PARAMS => [$transcript->dbID()]); | ||
| 98 | return $self->fetch_all_by_dbID_list($ids); | ||
| 99 | } | ||
| 100 | |||
| 101 | =head2 fetch_flanking_exon_ids | ||
| 102 | |||
| 103 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to search with | ||
| 104 | Arg[2] : Bio::EnsEMBL::Transcript Transcript to search with | ||
| 105 | Example : my ($prev_id, $next_id) = @{$isea->fetch_flanking_exon_ids($ise, $transcript)}; | ||
| 106 | Description : Uses the given IntronSupportingEvidence and Transcript to search | ||
| 107 | for the recorded previous and next exon database ids | ||
| 108 | Returntype : ArrayRef 1 row long but with 2 columns representing previous | ||
| 109 | and next IDs respectivly | ||
| 110 | Exceptions : Thrown if arguments are not as stated and for DB errors | ||
| 111 | |||
| 112 | =cut | ||
| 113 | |||
| 114 | sub fetch_flanking_exon_ids { | ||
| 115 | my ($self, $sf, $transcript) = @_; | ||
| 116 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_evidence'); | ||
| 117 | assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript'); | ||
| 118 | my $query = <<'SQL'; | ||
| 119 | select previous_exon_id, next_exon_id | ||
| 120 | from transcript_intron_supporting_evidence | ||
| 121 | where transcript_id =? and intron_supporting_evidence_id =? | ||
| 122 | SQL | ||
| 123 | my $ids = $self->dbc()->sql_helper()->execute(-SQL => $query, -PARAMS => [$transcript->dbID(), $sf->dbID()]); | ||
| 124 | return unless @{$ids}; | ||
| 125 | return @{$ids->[0]}; | ||
| 126 | } | ||
| 127 | |||
| 128 | sub _tables { | ||
| 129 | return ( [ 'intron_supporting_evidence', 'ise' ] ); | ||
| 130 | } | ||
| 131 | |||
| 132 | sub _columns { | ||
| 133 | return qw/ | ||
| 134 | ise.intron_supporting_evidence_id | ||
| 135 | ise.analysis_id | ||
| 136 | ise.seq_region_id ise.seq_region_start ise.seq_region_end ise.seq_region_strand | ||
| 137 | ise.hit_name ise.score ise.score_type | ||
| 138 | ise.is_splice_canonical | ||
| 139 | /; | ||
| 140 | } | ||
| 141 | |||
| 142 | # _objs_from_sth | ||
| 143 | |||
| 144 | # Arg [1] : StatementHandle $sth | ||
| 145 | # Arg [2] : Bio::EnsEMBL::AssemblyMapper $mapper | ||
| 146 | # Arg [3] : Bio::EnsEMBL::Slice $dest_slice | ||
| 147 | # Description: PROTECTED implementation of abstract superclass method. | ||
| 148 | # responsible for the creation of Intron supporting features | ||
| 149 | # Returntype : listref of Bio::EnsEMBL::IntronSupportingFeatures in target coordinate system | ||
| 150 | # Exceptions : none | ||
| 151 | # Caller : internal | ||
| 152 | # Status : Stable | ||
| 153 | |||
| 154 | sub _objs_from_sth { | ||
| 155 | my ($self, $sth, $mapper, $dest_slice) = @_; | ||
| 156 | |||
| 157 | # | ||
| 158 | # This code is ugly because an attempt has been made to remove as many | ||
| 159 | # function calls as possible for speed purposes. Thus many caches and | ||
| 160 | # a fair bit of gymnastics is used. | ||
| 161 | # | ||
| 162 | |||
| 163 | my $sa = $self->db()->get_SliceAdaptor(); | ||
| 164 | my $aa = $self->db()->get_AnalysisAdaptor(); | ||
| 165 | |||
| 166 | my @features; | ||
| 167 | my %analysis_hash; | ||
| 168 | my %slice_hash; | ||
| 169 | my %sr_name_hash; | ||
| 170 | my %sr_cs_hash; | ||
| 171 | |||
| 172 | my( | ||
| 173 | $id, $analysis_id, $seq_region_id, | ||
| 174 | $seq_region_start, $seq_region_end, $seq_region_strand, | ||
| 175 | $hit_name, $score, $score_type, | ||
| 176 | $splice_canonical); | ||
| 177 | |||
| 178 | $sth->bind_columns(\( | ||
| 179 | $id, $analysis_id, $seq_region_id, | ||
| 180 | $seq_region_start, $seq_region_end, $seq_region_strand, | ||
| 181 | $hit_name, $score, $score_type, | ||
| 182 | $splice_canonical)); | ||
| 183 | |||
| 184 | my $dest_slice_start; | ||
| 185 | my $dest_slice_end; | ||
| 186 | my $dest_slice_strand; | ||
| 187 | my $dest_slice_length; | ||
| 188 | my $dest_slice_cs; | ||
| 189 | my $dest_slice_sr_name; | ||
| 190 | my $dest_slice_sr_id; | ||
| 191 | my $asma; | ||
| 192 | |||
| 193 | if ($dest_slice) { | ||
| 194 | $dest_slice_start = $dest_slice->start(); | ||
| 195 | $dest_slice_end = $dest_slice->end(); | ||
| 196 | $dest_slice_strand = $dest_slice->strand(); | ||
| 197 | $dest_slice_length = $dest_slice->length(); | ||
| 198 | $dest_slice_cs = $dest_slice->coord_system(); | ||
| 199 | $dest_slice_sr_name = $dest_slice->seq_region_name(); | ||
| 200 | $dest_slice_sr_id = $dest_slice->get_seq_region_id(); | ||
| 201 | $asma = $self->db->get_AssemblyMapperAdaptor(); | ||
| 202 | } | ||
| 203 | |||
| 204 | FEATURE: while($sth->fetch()) { | ||
| 205 | |||
| 206 | #get the analysis object | ||
| 207 | my $analysis = $analysis_hash{$analysis_id} ||= $aa->fetch_by_dbID($analysis_id); | ||
| 208 | $analysis_hash{$analysis_id} = $analysis; | ||
| 209 | |||
| 210 | #need to get the internal_seq_region, if present | ||
| 211 | $seq_region_id = $self->get_seq_region_id_internal($seq_region_id); | ||
| 212 | my $slice = $slice_hash{"ID:".$seq_region_id}; | ||
| 213 | |||
| 214 | if (!$slice) { | ||
| 215 | $slice = $sa->fetch_by_seq_region_id($seq_region_id); | ||
| 216 | $slice_hash{"ID:".$seq_region_id} = $slice; | ||
| 217 | $sr_name_hash{$seq_region_id} = $slice->seq_region_name(); | ||
| 218 | $sr_cs_hash{$seq_region_id} = $slice->coord_system(); | ||
| 219 | } | ||
| 220 | |||
| 221 | #obtain a mapper if none was defined, but a dest_seq_region was | ||
| 222 | if(!$mapper && $dest_slice && !$dest_slice_cs->equals($slice->coord_system)) { | ||
| 223 | $mapper = $asma->fetch_by_CoordSystems($dest_slice_cs, $slice->coord_system); | ||
| 224 | } | ||
| 225 | |||
| 226 | my $sr_name = $sr_name_hash{$seq_region_id}; | ||
| 227 | my $sr_cs = $sr_cs_hash{$seq_region_id}; | ||
| 228 | |||
| 229 | # | ||
| 230 | # remap the feature coordinates to another coord system | ||
| 231 | # if a mapper was provided | ||
| 232 | # | ||
| 233 | |||
| 234 | if ($mapper) { | ||
| 235 | |||
| 236 | if (defined $dest_slice && $mapper->isa('Bio::EnsEMBL::ChainedAssemblyMapper') ) { | ||
| 237 | ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) = | ||
| 238 | $mapper->map($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs, 1, $dest_slice); | ||
| 239 | |||
| 240 | } else { | ||
| 241 | ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) = | ||
| 242 | $mapper->fastmap($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs); | ||
| 243 | } | ||
| 244 | |||
| 245 | #skip features that map to gaps or coord system boundaries | ||
| 246 | next FEATURE if (!defined($seq_region_id)); | ||
| 247 | |||
| 248 | #get a slice in the coord system we just mapped to | ||
| 249 | $slice = $slice_hash{"ID:".$seq_region_id} ||= $sa->fetch_by_seq_region_id($seq_region_id); | ||
| 250 | } | ||
| 251 | |||
| 252 | # | ||
| 253 | # If a destination slice was provided convert the coords. | ||
| 254 | # | ||
| 255 | if (defined($dest_slice)) { | ||
| 256 | my $seq_region_len = $dest_slice->seq_region_length(); | ||
| 257 | |||
| 258 | if ( $dest_slice_strand == 1 ) { | ||
| 259 | $seq_region_start = $seq_region_start - $dest_slice_start + 1; | ||
| 260 | $seq_region_end = $seq_region_end - $dest_slice_start + 1; | ||
| 261 | |||
| 262 | if ( $dest_slice->is_circular ) { | ||
| 263 | # Handle circular chromosomes. | ||
| 264 | |||
| 265 | if ( $seq_region_start > $seq_region_end ) { | ||
| 266 | # Looking at a feature overlapping the chromosome origin. | ||
| 267 | |||
| 268 | if ( $seq_region_end > $dest_slice_start ) { | ||
| 269 | # Looking at the region in the beginning of the chromosome | ||
| 270 | $seq_region_start -= $seq_region_len; | ||
| 271 | } | ||
| 272 | if ( $seq_region_end < 0 ) { | ||
| 273 | $seq_region_end += $seq_region_len; | ||
| 274 | } | ||
| 275 | } else { | ||
| 276 | if ($dest_slice_start > $dest_slice_end && $seq_region_end < 0) { | ||
| 277 | # Looking at the region overlapping the chromosome | ||
| 278 | # origin and a feature which is at the beginning of the | ||
| 279 | # chromosome. | ||
| 280 | $seq_region_start += $seq_region_len; | ||
| 281 | $seq_region_end += $seq_region_len; | ||
| 282 | } | ||
| 283 | } | ||
| 284 | } | ||
| 285 | } else { | ||
| 286 | |||
| 287 | my $start = $dest_slice_end - $seq_region_end + 1; | ||
| 288 | my $end = $dest_slice_end - $seq_region_start + 1; | ||
| 289 | |||
| 290 | if ($dest_slice->is_circular()) { | ||
| 291 | |||
| 292 | if ($dest_slice_start > $dest_slice_end) { | ||
| 293 | # slice spans origin or replication | ||
| 294 | |||
| 295 | if ($seq_region_start >= $dest_slice_start) { | ||
| 296 | $end += $seq_region_len; | ||
| 297 | $start += $seq_region_len if $seq_region_end > $dest_slice_start; | ||
| 298 | |||
| 299 | } elsif ($seq_region_start <= $dest_slice_end) { | ||
| 300 | # do nothing | ||
| 301 | } elsif ($seq_region_end >= $dest_slice_start) { | ||
| 302 | $start += $seq_region_len; | ||
| 303 | $end += $seq_region_len; | ||
| 304 | |||
| 305 | } elsif ($seq_region_end <= $dest_slice_end) { | ||
| 306 | $end += $seq_region_len if $end < 0; | ||
| 307 | |||
| 308 | } elsif ($seq_region_start > $seq_region_end) { | ||
| 309 | $end += $seq_region_len; | ||
| 310 | } | ||
| 311 | |||
| 312 | } else { | ||
| 313 | |||
| 314 | if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) { | ||
| 315 | # do nothing | ||
| 316 | } elsif ($seq_region_start > $seq_region_end) { | ||
| 317 | if ($seq_region_start <= $dest_slice_end) { | ||
| 318 | $start -= $seq_region_len; | ||
| 319 | } elsif ($seq_region_end >= $dest_slice_start) { | ||
| 320 | $end += $seq_region_len; | ||
| 321 | } | ||
| 322 | } | ||
| 323 | } | ||
| 324 | } | ||
| 325 | |||
| 326 | $seq_region_start = $start; | ||
| 327 | $seq_region_end = $end; | ||
| 328 | $seq_region_strand *= -1; | ||
| 329 | |||
| 330 | } ## end else [ if ( $dest_slice_strand...)] | ||
| 331 | |||
| 332 | # Throw away features off the end of the requested slice or on | ||
| 333 | # different seq_region. | ||
| 334 | if ($seq_region_end < 1 | ||
| 335 | || $seq_region_start > $dest_slice_length | ||
| 336 | || ($dest_slice_sr_id != $seq_region_id)) { | ||
| 337 | next FEATURE; | ||
| 338 | } | ||
| 339 | $slice = $dest_slice; | ||
| 340 | } | ||
| 341 | |||
| 342 | push( @features, | ||
| 343 | $self->_create_feature_fast( | ||
| 344 | 'Bio::EnsEMBL::IntronSupportingEvidence', { | ||
| 345 | 'start' => $seq_region_start, | ||
| 346 | 'end' => $seq_region_end, | ||
| 347 | 'strand' => $seq_region_strand, | ||
| 348 | 'slice' => $slice, | ||
| 349 | 'analysis' => $analysis, | ||
| 350 | 'adaptor' => $self, | ||
| 351 | 'dbID' => $id, | ||
| 352 | 'hit_name' => $hit_name, | ||
| 353 | 'score' => $score, | ||
| 354 | 'score_type' => $score_type, | ||
| 355 | 'is_splice_canonical' => $splice_canonical, | ||
| 356 | } ) ); | ||
| 357 | } | ||
| 358 | |||
| 359 | return \@features; | ||
| 360 | } | ||
| 361 | |||
| 362 | ####### STORAGE | ||
| 363 | |||
| 364 | =head2 store | ||
| 365 | |||
| 366 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to store | ||
| 367 | Example : $isea->store($ise); | ||
| 368 | Description : Stores the IntronSupportingEvidence in the database. Duplicates | ||
| 369 | are ignored. | ||
| 370 | Returntype : Integer The assigned database identifier | ||
| 371 | Exceptions : Thrown if the given object is not a IntronSupportingEvidence, | ||
| 372 | and for any DB exception. | ||
| 373 | |||
| 374 | =cut | ||
| 375 | |||
| 376 | sub store { | ||
| 377 | my ($self, $sf) = @_; | ||
| 378 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_feature'); | ||
| 379 | |||
| 380 | my $db = $self->db(); | ||
| 381 | |||
| 382 | if($sf->is_stored($db)) { | ||
| 383 | return $sf->dbID(); | ||
| 384 | } | ||
| 385 | |||
| 386 | my $analysis = $sf->analysis(); | ||
| 387 | my $analysis_id = $analysis->is_stored($db) ? $analysis->dbID() : $db->get_AnalysisAdaptor()->store($analysis); | ||
| 388 | |||
| 389 | my $seq_region_id; | ||
| 390 | ($sf, $seq_region_id) = $self->_pre_store($sf); | ||
| 391 | |||
| 392 | my $insert_ignore = $self->insert_ignore_clause(); | ||
| 393 | my $sql = qq{ | ||
| 394 | ${insert_ignore} into intron_supporting_evidence | ||
| 395 | (analysis_id, seq_region_id, seq_region_start, seq_region_end, seq_region_strand, hit_name, score, score_type, is_splice_canonical) | ||
| 396 | values (?,?,?,?,?,?,?,?,?) | ||
| 397 | }; | ||
| 398 | |||
| 399 | #Used later on for duplicate entry retrieval | ||
| 400 | my $query_params = [ | ||
| 401 | [$analysis_id, SQL_INTEGER], | ||
| 402 | [$seq_region_id, SQL_INTEGER], | ||
| 403 | [$sf->start(), SQL_INTEGER], | ||
| 404 | [$sf->end(), SQL_INTEGER], | ||
| 405 | [$sf->strand(), SQL_INTEGER], | ||
| 406 | [$sf->hit_name(), SQL_VARCHAR], | ||
| 407 | ]; | ||
| 408 | |||
| 409 | my $params = [ | ||
| 410 | @{$query_params}, | ||
| 411 | [$sf->score(), SQL_FLOAT], | ||
| 412 | [$sf->score_type(), SQL_VARCHAR], | ||
| 413 | [$sf->is_splice_canonical(), SQL_INTEGER], | ||
| 414 | ]; | ||
| 415 | |||
| 416 | $self->dbc()->sql_helper()->execute_update(-SQL => $sql, -PARAMS => $params, -CALLBACK => sub { | ||
| 417 | my ( $sth, $dbh, $rv ) = @_; | ||
| 418 | if ($rv > 0) { | ||
| 419 | $sf->dbID($self->last_insert_id('intron_supporting_evidence_id', undef, 'intron_supporting_evidence')); | ||
| 420 | } | ||
| 421 | return; | ||
| 422 | }); | ||
| 423 | $sf->adaptor($self); | ||
| 424 | |||
| 425 | if(!$sf->dbID()) { | ||
| 426 | my $query = <<'SQL'; | ||
| 427 | select intron_supporting_evidence_id | ||
| 428 | from intron_supporting_evidence | ||
| 429 | where analysis_id =? | ||
| 430 | and seq_region_id =? and seq_region_start =? and seq_region_end =? and seq_region_strand =? | ||
| 431 | and hit_name =? | ||
| 432 | SQL | ||
| 433 | my $id = $self->dbc()->sql_helper()->execute_single_result(-SQL => $query, -PARAMS => $query_params); | ||
| 434 | $sf->dbID($id); | ||
| 435 | } | ||
| 436 | |||
| 437 | return $sf->dbID(); | ||
| 438 | } | ||
| 439 | |||
| 440 | =head2 store_transcript_linkage | ||
| 441 | |||
| 442 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to link | ||
| 443 | Arg[2] : Bio::EnsEMBL::Transcript Transcript to link | ||
| 444 | Arg[3] : Integer an optional ID to give if the Transcript's own ID is possibly incorrect | ||
| 445 | Example : $isea->store_transcript_linkage($ise, $transcript); | ||
| 446 | $isea->store_transcript_linkage($ise, $transcript, $tid); | ||
| 447 | Description : Links a Transcript to a portion of Intron evidence | ||
| 448 | Returntype : None | ||
| 449 | Exceptions : Thrown if the given object is not a Transcript, if the | ||
| 450 | transcript is not stored, if the supporting evidence is not | ||
| 451 | stored and for any DB exception. | ||
| 452 | |||
| 453 | =cut | ||
| 454 | |||
| 455 | sub store_transcript_linkage { | ||
| 456 | my ($self, $sf, $transcript, $transcript_id) = @_; | ||
| 457 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_evidence'); | ||
| 458 | assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript'); | ||
| 459 | |||
| 460 | throw "Cannot perform the link. The IntronSupportingEvidence must be persisted first" unless $sf->is_stored($self->db()); | ||
| 461 | |||
| 462 | my $insert_ignore = $self->insert_ignore_clause(); | ||
| 463 | my $sql = qq{ | ||
| 464 | ${insert_ignore} into transcript_intron_supporting_evidence | ||
| 465 | (transcript_id, intron_supporting_evidence_id, previous_exon_id, next_exon_id) | ||
| 466 | values (?,?,?,?) | ||
| 467 | }; | ||
| 468 | |||
| 469 | my $intron = $sf->get_Intron($transcript); | ||
| 470 | my ($previous_exon, $next_exon) = ($intron->prev_Exon(), $intron->next_Exon()); | ||
| 471 | $transcript_id ||= $transcript->dbID(); | ||
| 472 | |||
| 473 | my $params = [ | ||
| 474 | [$transcript_id, SQL_INTEGER], | ||
| 475 | [$sf->dbID(), SQL_INTEGER], | ||
| 476 | [$previous_exon->dbID(), SQL_INTEGER], | ||
| 477 | [$next_exon->dbID(), SQL_INTEGER], | ||
| 478 | ]; | ||
| 479 | $self->dbc()->sql_helper()->execute_update(-SQL => $sql, -PARAMS => $params); | ||
| 480 | |||
| 481 | return; | ||
| 482 | } | ||
| 483 | |||
| 484 | ####### UPDATE | ||
| 485 | |||
| 486 | =head2 update | ||
| 487 | |||
| 488 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to update | ||
| 489 | Example : $isea->update($ise); | ||
| 490 | Description : Updates all attributes of an evidence object | ||
| 491 | Returntype : None | ||
| 492 | Exceptions : Thrown if the given object is not a IntronSupportingEvidence, | ||
| 493 | if the object is not stored and for normal DB errors | ||
| 494 | |||
| 495 | =cut | ||
| 496 | |||
| 497 | sub update { | ||
| 498 | my ($self, $sf) = @_; | ||
| 499 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_evidence'); | ||
| 500 | if (! $sf->is_stored($self->db())) { | ||
| 501 | throw "Cannot update the supporting evidence if it has not already been stored in this database"; | ||
| 502 | } | ||
| 503 | |||
| 504 | my $params = [ | ||
| 505 | [$sf->analysis()->dbID(), SQL_INTEGER], | ||
| 506 | [$sf->slice()->get_seq_region_id(), SQL_INTEGER], | ||
| 507 | [$sf->start(), SQL_INTEGER], | ||
| 508 | [$sf->end(), SQL_INTEGER], | ||
| 509 | [$sf->strand(), SQL_INTEGER], | ||
| 510 | [$sf->hit_name(), SQL_VARCHAR], | ||
| 511 | [$sf->score(), SQL_FLOAT], | ||
| 512 | [$sf->score_type(), SQL_VARCHAR], | ||
| 513 | [$sf->is_splice_canonical() || 0, SQL_INTEGER], | ||
| 514 | [$sf->dbID(), SQL_INTEGER], | ||
| 515 | ]; | ||
| 516 | |||
| 517 | my $sql = <<'SQL'; | ||
| 518 | UPDATE intron_supporting_evidence | ||
| 519 | SET analysis_id =?, seq_region_id =?, seq_region_start =?, | ||
| 520 | seq_region_end =?, seq_region_strand =?, hit_name =?, score =?, score_type =?, | ||
| 521 | is_splice_canonical =? | ||
| 522 | WHERE intron_supporting_evidence_id =? | ||
| 523 | SQL | ||
| 524 | |||
| 525 | $self->dbc()->sql_helper()->execute_update(-SQL => $sql, -PARAMS => $params); | ||
| 526 | return; | ||
| 527 | } | ||
| 528 | |||
| 529 | ####### DELETION | ||
| 530 | |||
| 531 | =head2 remove | ||
| 532 | |||
| 533 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence | ||
| 534 | Example : $isea->remove($ise); | ||
| 535 | Description : Deletes the given IntronSupportingEvidence from the database. | ||
| 536 | This can only occur if the object has no linked transcripts | ||
| 537 | Returntype : None | ||
| 538 | Exceptions : Thrown if the IntronSupportingEvidence is not stored, if | ||
| 539 | the object has linked transcripts and in the event of any | ||
| 540 | database error | ||
| 541 | |||
| 542 | =cut | ||
| 543 | |||
| 544 | sub remove { | ||
| 545 | my ($self, $sf) = @_; | ||
| 546 | assert_ref($sf, 'Bio::EnsEMBL::IntronSupportingEvidence', 'intron_supporting_evidence'); | ||
| 547 | if (! $sf->is_stored($self->db())) { | ||
| 548 | throw "Cannot delete the supporting evidence if it has not already been stored in this database"; | ||
| 549 | } | ||
| 550 | if($sf->has_linked_transcripts()) { | ||
| 551 | throw sprintf('Cannot delete supporting evidence %d. It still has transcripts attached', $sf->dbID()); | ||
| 552 | } | ||
| 553 | $self->dbc()->sql_helper()->execute_update( | ||
| 554 | -SQL => 'DELETE from intron_supporting_evidence where intron_supporting_evidence_id =?', | ||
| 555 | -PARAMS => [[$sf->dbID(), SQL_INTEGER]], | ||
| 556 | ); | ||
| 557 | return; | ||
| 558 | } | ||
| 559 | |||
| 560 | =head2 remove_all_transcript_linkages | ||
| 561 | |||
| 562 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence | ||
| 563 | Example : $isea->remove_all_transcript_linkages($ise); | ||
| 564 | Description : Deletes the transcript links to the given IntronSupportingEvidence | ||
| 565 | Returntype : None | ||
| 566 | Exceptions : See remove_transcript_linkage | ||
| 567 | |||
| 568 | =cut | ||
| 569 | |||
| 570 | sub remove_all_transcript_linkages { | ||
| 571 | my ($self, $sf) = @_; | ||
| 572 | foreach my $transcript_id (@{$self->list_linked_transcript_ids($sf)}) { | ||
| 573 | $self->_remove_transcript_linkage($sf, $transcript_id); | ||
| 574 | } | ||
| 575 | return; | ||
| 576 | } | ||
| 577 | |||
| 578 | =head2 remove_transcript_linkage | ||
| 579 | |||
| 580 | Arg[1] : Bio::EnsEMBL::IntronSupportingEvidence Evidence to unlink | ||
| 581 | Arg[2] : Bio::EnsEMBL::Transcript Transcript to unlink | ||
| 582 | Example : $isea->remove_transcript_linkages($ise, $transcript); | ||
| 583 | Description : Deletes a transcript's link to the given IntronSupportingEvidence | ||
| 584 | Returntype : None | ||
| 585 | Exceptions : Thrown if the given object is not a Transcript, if the | ||
| 586 | transcript is not stored, if the supporting evidence is not | ||
| 587 | stored and for any DB exception. | ||
| 588 | |||
| 589 | =cut | ||
| 590 | |||
| 591 | sub remove_transcript_linkage { | ||
| 592 | my ($self, $sf, $transcript) = @_; | ||
| 593 | assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript'); | ||
| 594 | if (! $transcript->is_stored($self->db())) { | ||
| 595 | throw "Cannot delete the supporting evidence to transcript linkage if the transcript has not already been stored in this database"; | ||
| 596 | } | ||
| 597 | $self->_remove_transcript_linkage($sf, $transcript->dbID()); | ||
| 598 | return; | ||
| 599 | } | ||
| 600 | |||
| 601 | sub _remove_transcript_linkage { | ||
| 602 | my ($self, $sf, $transcript_id) = @_; | ||
| 603 | if (! $sf->is_stored($self->db())) { | ||
| 604 | throw "Cannot delete the supporting evidence to transcript linkage if the evidence has not already been stored in this database"; | ||
| 605 | } | ||
| 606 | $self->dbc()->sql_helper()->execute_update( | ||
| 607 | -SQL => 'DELETE from transcript_intron_supporting_evidence where intron_supporting_evidence_id =? and transcript_id =?', | ||
| 608 | -PARAMS => [[$sf->dbID(), SQL_INTEGER], [$transcript_id, SQL_INTEGER]], | ||
| 609 | ); | ||
| 610 | return; | ||
| 611 | } | ||
| 612 | |||
| 613 | 1; |