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