3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
45 package Bio::EnsEMBL::Map::DBSQL::MarkerAdaptor;
65 Example : @all_markers = @{$marker_adaptor->fetch_all};
66 Description: Retrieves all markers from the database
67 Returntype : listref of Bio::EnsEMBL::Map::Markers
78 my $sth = $self->prepare(
"SELECT m.marker_id, m.priority, m.left_primer,
79 m.right_primer, m.type,
80 m.min_primer_dist, m.max_primer_dist,
81 ms.marker_synonym_id, ms.name, ms.source
83 LEFT JOIN marker_synonym ms
84 ON ms.marker_synonym_id =
85 m.display_marker_synonym_id");
89 my( $marker_id, $priority, $left_primer, $right_primer, $type,
90 $min_pdist, $max_pdist, $ms_id, $ms_name, $ms_src);
92 $sth->bind_columns(\$marker_id, \$priority,
93 \$left_primer, \$right_primer, \$type, \$min_pdist, \$max_pdist,
94 \$ms_id, \$ms_name, \$ms_src);
98 #create a display marker synonym for each marker created, if one is defined
102 ($ms_id, $ms_src, $ms_name);
106 ($marker_id, $self, $left_primer, $right_primer, $min_pdist, $max_pdist,
107 $priority, $type, $synonym);
118 The
internal identifier of the
Marker to retrieve
119 Example : $marker = $marker_adaptor->fetch_by_dbID(123);
120 Description: Retrieves a marker
object from the database via its
internal
123 Exceptions : thrown
if no marker with $dbID is present in the database
133 $self->throw(
'dbID argument is required') unless($dbID);
135 my $sth = $self->prepare(
"SELECT m.marker_id, m.display_marker_synonym_id,
136 m.priority, m.left_primer, m.right_primer,
138 m.min_primer_dist, m.max_primer_dist,
139 ms.marker_synonym_id,
141 FROM marker m, marker_synonym ms
142 WHERE m.marker_id = ?
143 AND ms.marker_id = m.marker_id");
145 $sth->execute($dbID);
147 my( $marker_id, $display_ms_id, $priority, $left_primer, $right_primer,
148 $type, $min_pdist, $max_pdist, $ms_id, $ms_src, $ms_name);
150 $sth->bind_columns(\$marker_id, \$display_ms_id, \$priority,
151 \$left_primer, \$right_primer, \$type,
152 \$min_pdist, \$max_pdist,
153 \$ms_id, \$ms_src, \$ms_name);
158 #create a new synonym for each row
161 $display_synonym = $s
if($display_ms_id == $ms_id);
168 $self-> warning(
"marker with dbID=[$dbID] not present in database");
172 #now create the marker
174 $marker_id, $self, $left_primer, $right_primer,$min_pdist, $max_pdist,
175 $priority, $type,$display_synonym, \@synonyms);
179 =head2 fetch_all_by_synonym
181 Arg [1] :
string $synonym
182 An name of
this marker
183 Arg [2] : (opional)
string $source
184 The source of
this name
185 Example : @markers = @{$marker_adaptor->fetch_all_by_synonym($id)};
186 Description: Retrieves a list of markers with the synonym (alias) $synonym
187 and from source $source. In most cases the list will have a
188 single element, however it is possible that multiple markers
189 with the same synonym exist.
190 Returntype : listref of Bio::EnsEMBL::Map::Markers
197 sub fetch_all_by_synonym {
198 my ($self, $synonym, $source) = @_;
200 $self->throw(
"synonym argument is required") unless($synonym);
202 my $q =
"SELECT marker_id
203 FROM marker_synonym ms
206 my @bind_vals = ($synonym);
209 $q .=
" AND ms.source = ?";
210 push(@bind_vals, $source);
213 my $sth = $self->prepare($q);
214 $sth->execute(@bind_vals);
220 #fetch the markers and filter out duplictes
221 while(($marker_id) = $sth->fetchrow_array) {
222 next
if $seen{$marker_id};
224 # some synonyms point to markers that don't exist, so only add genuine ones
225 my $marker = $self->fetch_by_dbID($marker_id);
226 push @out, $marker
if ($marker);
227 $seen{$marker_id} = 1;
237 =head2 fetch_attributes
240 Example : $marker_adaptor->fetch_attributes($marker);
241 Description: Fetches the marker_synonym and map_location attributes of
242 a marker. This is done so that these attributes can be
243 lazy-loaded on request.
246 Caller : Bio::EnsEMBL::Map::Marker::marker
251 sub fetch_attributes {
255 my $m_id = $marker->
dbID;
257 $self->throw(
'Marker argument does not have a dbID') unless($m_id);
260 # First Retrieve synonyms for this marker
262 $marker->flush_MarkerSynonyms;
264 my $sth = $self->prepare(
"SELECT ms.marker_synonym_id, ms.source, ms.name
265 FROM marker_synonym ms
266 WHERE ms.marker_id = ?");
269 my ($ms_id, $ms_src, $ms_name);
271 $sth->execute($m_id);
272 $sth->bind_columns(\$ms_id, \$ms_src, \$ms_name);
279 $marker->add_MarkerSynonyms(@syns)
if(@syns);
282 # Now retrieve map locations for this marker
284 $marker->flush_MapLocations;
286 $sth = $self->prepare(
"SELECT mloc.chromosome_name, mloc.position,
287 mloc.lod_score, map.map_name, ms.name
288 FROM marker_map_location mloc, map map,
290 WHERE mloc.marker_id = ?
291 AND map.map_id = mloc.map_id
292 AND ms.marker_synonym_id = mloc.marker_synonym_id");
294 my($chr_name, $pos, $lod, $mname, $name);
297 $sth->execute($m_id);
299 $sth->bind_columns(\$chr_name, \$pos, \$lod, \$mname, \$name);
303 $chr_name,$pos,$lod));
308 $marker->add_MapLocations(@mlocs);
316 Example : $marker_adaptor->store(@markers);
317 Description: Stores a list of markers in
this database.
318 The dbID and adaptor of each marker will be set on successful
320 Returntype : 1 on success
321 Exceptions : thrown
if not all data needed
for storing is populated in the
329 my ($self, @markers) = @_;
331 MARKER:
foreach my $marker( @markers ){
334 if($self->fetch_by_dbID($marker->dbID)){
343 !$marker->isa(
'Bio::EnsEMBL::Map::Marker')) {
344 $self->throw(
'Incorrect argument [$marker] to store. Expected ' .
345 'Bio::EnsEMBL::Map::Marker');
348 # Don't store if already stored
349 if($marker->is_stored($self->db())) {
350 warning(
'Marker ['.$marker->dbID.
'] is already stored in this DB.');
354 # Get/test the display marker synonym
355 my $display_synonym = $marker->display_MarkerSynonym;
356 if(!$display_synonym || !ref($display_synonym) ||
357 !$display_synonym->isa(
'Bio::EnsEMBL::Map::MarkerSynonym')) {
358 $self->throw(
'Cannot store Marker without an associated '.
359 'display_MarkerSynonym');
362 # Store the Marker itself
364 INSERT INTO marker ( left_primer, right_primer,
365 min_primer_dist, max_primer_dist,
367 VALUES ( ?,?,?,?,?,?) );
369 my $sth = $self->prepare($q);
371 $sth->execute( $marker->left_primer ||
'',
372 $marker->right_primer ||
'',
373 $marker->min_primer_dist || 0,
374 $marker->max_primer_dist || 0,
378 my $dbID = $self->last_insert_id(
'marker_id', undef,
'marker');
379 $marker->dbID($dbID);
380 $marker->adaptor($self);
382 if(!$display_synonym->dbID) {
384 $self->_store_MarkerSynonym($marker,$display_synonym);
386 my $display_synonym_id = $display_synonym->dbID ||
387 $self->throw(
'display_MarkerSynonym must have dbID to store Marker');
389 # Update the marker with the display synonym
392 SET display_marker_synonym_id = $display_synonym_id
393 WHERE marker_id = ? );
394 my $sthup = $self->prepare($qup);
395 $sthup->execute($dbID);
397 # Loop through all MarkerSynonyms and store if needed
398 foreach my $synonym( @{$marker->get_all_MarkerSynonyms} ){
399 if(!$synonym->dbID) {
400 $self->_store_MarkerSynonym($marker,$synonym);
404 # Loop through all MapLocations and store if needed
405 foreach my $loc( @{$marker->get_all_MapLocations} ){
406 # Dunno how to implement this :( Just bomb out
407 $self->throw(
'Storing of MapLocation objects is not yet implemented' )
415 =head2 _store_MarkerSynonym
419 Example : $marker_adaptor->_store_MarkerSynonym($marker,$ms);
420 Description: Stores a marker synonym attached to the marker in the database
424 Exceptions : thrown
if not all data needed
for storing is populated
425 Caller : $self->store
430 sub _store_MarkerSynonym{
436 if(!$marker || !ref($marker) ||
437 !$marker->isa(
'Bio::EnsEMBL::Map::Marker')) {
438 $self->throw(
"Incorrect argument [$marker] to _store_MarkerSynonym." .
439 "Expected Bio::EnsEMBL::Map::Marker");
441 if(!$ms || !ref($ms) ||
442 !$ms->isa(
'Bio::EnsEMBL::Map::MarkerSynonym')) {
443 $self->throw(
"Incorrect argument [$ms] to _store_MarkerSynonym." .
444 "Expected Bio::EnsEMBL::Map::MarkerSynonym");
447 # Don't store if already stored
449 warning(
'MarkerSynonym ['.$ms->dbID.
'] is already stored in this DB.');
453 my $marker_id = $marker->dbID ||
454 throw(
"Marker has no dbID. Cannot store MarkerSynonym" );
458 INSERT INTO marker_synonym ( marker_id, source, name )
461 my $sth = $self->prepare($q);
463 $sth->execute( $marker_id,
467 my $dbID = $self->last_insert_id(
'marker_synonym_id', undef,
'marker_synonym');