$Bio::EnsEMBL::Map::DBSQL::MarkerAdaptor::VERSION
=
'113.0.0'
;
@ISA
=
qw(Bio::EnsEMBL::DBSQL::BaseAdaptor)
;
sub
fetch_all {
my
$self
=
shift
;
my
$dbID
=
shift
;
my
$sth
=
$self
->prepare("SELECT m.marker_id, m.priority, m.left_primer,
m.right_primer, m.type,
m.min_primer_dist, m.max_primer_dist,
ms.marker_synonym_id, ms.name, ms.source
FROM marker m
LEFT JOIN marker_synonym ms
ON ms.marker_synonym_id =
m.display_marker_synonym_id");
$sth
->execute;
my
(
$marker_id
,
$priority
,
$left_primer
,
$right_primer
,
$type
,
$min_pdist
,
$max_pdist
,
$ms_id
,
$ms_name
,
$ms_src
);
$sth
->bind_columns(\
$marker_id
, \
$priority
,
\
$left_primer
, \
$right_primer
, \
$type
, \
$min_pdist
, \
$max_pdist
,
\
$ms_id
, \
$ms_name
, \
$ms_src
);
my
@out
;
while
(
$sth
->fetch) {
my
$synonym
;
if
(
$ms_id
) {
$synonym
= Bio::EnsEMBL::Map::MarkerSynonym->new
(
$ms_id
,
$ms_src
,
$ms_name
);
}
push
@out
, Bio::EnsEMBL::Map::Marker->new
(
$marker_id
,
$self
,
$left_primer
,
$right_primer
,
$min_pdist
,
$max_pdist
,
$priority
,
$type
,
$synonym
);
}
return
\
@out
;
}
sub
fetch_by_dbID {
my
$self
=
shift
;
my
$dbID
=
shift
;
$self
->throw(
'dbID argument is required'
)
unless
(
$dbID
);
my
$sth
=
$self
->prepare("SELECT m.marker_id, m.display_marker_synonym_id,
m.priority, m.left_primer, m.right_primer,
m.type,
m.min_primer_dist, m.max_primer_dist,
ms.marker_synonym_id,
ms.source, ms.name
FROM marker m, marker_synonym ms
WHERE m.marker_id = ?
AND ms.marker_id = m.marker_id");
$sth
->execute(
$dbID
);
my
(
$marker_id
,
$display_ms_id
,
$priority
,
$left_primer
,
$right_primer
,
$type
,
$min_pdist
,
$max_pdist
,
$ms_id
,
$ms_src
,
$ms_name
);
$sth
->bind_columns(\
$marker_id
, \
$display_ms_id
, \
$priority
,
\
$left_primer
, \
$right_primer
, \
$type
,
\
$min_pdist
, \
$max_pdist
,
\
$ms_id
, \
$ms_src
, \
$ms_name
);
my
$display_synonym
;
my
@synonyms
;
while
(
$sth
->fetch) {
my
$s
= new Bio::EnsEMBL::Map::MarkerSynonym->new(
$ms_id
,
$ms_src
,
$ms_name
);
$display_synonym
=
$s
if
(
$display_ms_id
==
$ms_id
);
push
@synonyms
,
$s
;
}
$sth
->finish;
unless
(
$marker_id
) {
$self
-> warning(
"marker with dbID=[$dbID] not present in database"
);
return
undef
;
}
return
new Bio::EnsEMBL::Map::Marker->new(
$marker_id
,
$self
,
$left_primer
,
$right_primer
,
$min_pdist
,
$max_pdist
,
$priority
,
$type
,
$display_synonym
, \
@synonyms
);
}
sub
fetch_all_by_synonym {
my
(
$self
,
$synonym
,
$source
) =
@_
;
$self
->throw(
"synonym argument is required"
)
unless
(
$synonym
);
my
$q
= "SELECT marker_id
FROM marker_synonym ms
WHERE ms.name = ?";
my
@bind_vals
= (
$synonym
);
if
(
$source
) {
$q
.=
" AND ms.source = ?"
;
push
(
@bind_vals
,
$source
);
}
my
$sth
=
$self
->prepare(
$q
);
$sth
->execute(
@bind_vals
);
my
@out
= ();
my
$marker_id
;
my
%seen
;
while
((
$marker_id
) =
$sth
->fetchrow_array) {
next
if
$seen
{
$marker_id
};
my
$marker
=
$self
->fetch_by_dbID(
$marker_id
);
push
@out
,
$marker
if
(
$marker
);
$seen
{
$marker_id
} = 1;
}
$sth
->finish;
return
\
@out
;
}
sub
fetch_attributes {
my
$self
=
shift
;
my
$marker
=
shift
;
my
$m_id
=
$marker
->dbID;
$self
->throw(
'Marker argument does not have a dbID'
)
unless
(
$m_id
);
$marker
->flush_MarkerSynonyms;
my
$sth
=
$self
->prepare("SELECT ms.marker_synonym_id, ms.source, ms.name
FROM marker_synonym ms
WHERE ms.marker_id = ?");
my
@syns
= ();
my
(
$ms_id
,
$ms_src
,
$ms_name
);
$sth
->execute(
$m_id
);
$sth
->bind_columns(\
$ms_id
, \
$ms_src
, \
$ms_name
);
while
(
$sth
->fetch) {
push
@syns
, Bio::EnsEMBL::Map::MarkerSynonym->new(
$ms_id
,
$ms_src
,
$ms_name
);
}
$sth
->finish;
$marker
->add_MarkerSynonyms(
@syns
)
if
(
@syns
);
$marker
->flush_MapLocations;
$sth
=
$self
->prepare("SELECT mloc.chromosome_name, mloc.position,
mloc.lod_score,
map
.map_name, ms.name
FROM marker_map_location mloc,
map
map
,
marker_synonym ms
WHERE mloc.marker_id = ?
AND
map
.map_id = mloc.map_id
AND ms.marker_synonym_id = mloc.marker_synonym_id");
my
(
$chr_name
,
$pos
,
$lod
,
$mname
,
$name
);
my
@mlocs
;
$sth
->execute(
$m_id
);
$sth
->bind_columns(\
$chr_name
, \
$pos
, \
$lod
, \
$mname
, \
$name
);
while
(
$sth
->fetch) {
push
(
@mlocs
, Bio::EnsEMBL::Map::MapLocation->new(
$name
,
$mname
,
$chr_name
,
$pos
,
$lod
));
}
$sth
->finish;
$marker
->add_MapLocations(
@mlocs
);
}
sub
store {
my
(
$self
,
@markers
) =
@_
;
MARKER:
foreach
my
$marker
(
@markers
){
if
(
$marker
->dbID){
if
(
$self
->fetch_by_dbID(
$marker
->dbID)){
next
MARKER;
}
}
if
(!
$marker
||
!
ref
(
$marker
) ||
!
$marker
->isa(
'Bio::EnsEMBL::Map::Marker'
)) {
$self
->throw(
'Incorrect argument [$marker] to store. Expected '
.
'Bio::EnsEMBL::Map::Marker'
);
}
if
(
$marker
->is_stored(
$self
->db())) {
warning(
'Marker ['
.
$marker
->dbID.
'] is already stored in this DB.'
);
next
;
}
my
$display_synonym
=
$marker
->display_MarkerSynonym;
if
(!
$display_synonym
|| !
ref
(
$display_synonym
) ||
!
$display_synonym
->isa(
'Bio::EnsEMBL::Map::MarkerSynonym'
)) {
$self
->throw(
'Cannot store Marker without an associated '
.
'display_MarkerSynonym'
);
}
my
$q
=
qq(
INSERT INTO marker ( left_primer, right_primer,
min_primer_dist, max_primer_dist,
priority, type)
VALUES ( ?,?,?,?,?,?) );
my
$sth
=
$self
->prepare(
$q
);
$sth
->execute(
$marker
->left_primer ||
''
,
$marker
->right_primer ||
''
,
$marker
->min_primer_dist || 0,
$marker
->max_primer_dist || 0,
$marker
->priority,
$marker
->type );
my
$dbID
=
$self
->last_insert_id(
'marker_id'
,
undef
,
'marker'
);
$marker
->dbID(
$dbID
);
$marker
->adaptor(
$self
);
if
(!
$display_synonym
->dbID) {
$self
->_store_MarkerSynonym(
$marker
,
$display_synonym
);
}
my
$display_synonym_id
=
$display_synonym
->dbID ||
$self
->throw(
'display_MarkerSynonym must have dbID to store Marker'
);
my
$qup
=
qq(
UPDATE marker
SET display_marker_synonym_id = $display_synonym_id
WHERE marker_id = ? )
;
my
$sthup
=
$self
->prepare(
$qup
);
$sthup
->execute(
$dbID
);
foreach
my
$synonym
( @{
$marker
->get_all_MarkerSynonyms} ){
if
(!
$synonym
->dbID) {
$self
->_store_MarkerSynonym(
$marker
,
$synonym
);
}
}
foreach
my
$loc
( @{
$marker
->get_all_MapLocations} ){
$self
->throw(
'Storing of MapLocation objects is not yet implemented'
)
}
}
return
1;
}
sub
_store_MarkerSynonym{
my
$self
=
shift
;
my
$marker
=
shift
;
my
$ms
=
shift
;
if
(!
$marker
|| !
ref
(
$marker
) ||
!
$marker
->isa(
'Bio::EnsEMBL::Map::Marker'
)) {
$self
->throw(
"Incorrect argument [$marker] to _store_MarkerSynonym."
.
"Expected Bio::EnsEMBL::Map::Marker"
);
}
if
(!
$ms
|| !
ref
(
$ms
) ||
!
$ms
->isa(
'Bio::EnsEMBL::Map::MarkerSynonym'
)) {
$self
->throw(
"Incorrect argument [$ms] to _store_MarkerSynonym."
.
"Expected Bio::EnsEMBL::Map::MarkerSynonym"
);
}
if
(
$ms
->dbID) {
warning(
'MarkerSynonym ['
.
$ms
->dbID.
'] is already stored in this DB.'
);
return
;
}
my
$marker_id
=
$marker
->dbID ||
throw(
"Marker has no dbID. Cannot store MarkerSynonym"
);
my
$q
=
qq(
INSERT INTO marker_synonym ( marker_id, source, name )
VALUES ( ?,?,?) );
my
$sth
=
$self
->prepare(
$q
);
$sth
->execute(
$marker_id
,
$ms
->source,
$ms
->name );
my
$dbID
=
$self
->last_insert_id(
'marker_synonym_id'
,
undef
,
'marker_synonym'
);
$ms
->dbID(
$dbID
);
return
$dbID
;
}
1;