$Bio::EnsEMBL::Map::DBSQL::MarkerFeatureAdaptor::VERSION
=
'112.0.0'
;
@ISA
=
qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor)
;
sub
fetch_all_by_Marker {
my
$self
=
shift
;
my
$marker
=
shift
;
my
$constraint
=
'm.marker_id = '
.
$marker
->dbID;
return
$self
->generic_fetch(
$constraint
,
@_
);
}
sub
fetch_all_by_Slice_and_MarkerName {
my
(
$self
,
$slice
,
$name
) =
@_
;
return
unless
$slice
&&
$name
;
my
$constraint
=
'ms.name = "'
.
$name
.
'"'
;
my
$results
=
$self
->fetch_all_by_Slice_constraint(
$slice
,
$constraint
);
return
$results
;
}
sub
fetch_all_by_Slice_and_priority {
my
(
$self
,
$slice
,
$priority
,
$map_weight
,
@args
) =
@_
;
my
$constraint
=
''
;
if
(
defined
$priority
) {
$constraint
=
"m.priority > $priority"
;
}
if
(
defined
$map_weight
) {
if
(
$constraint
) {
$constraint
.=
" AND mf.map_weight < $map_weight"
;
}
else
{
$constraint
=
"mf.map_weight < $map_weight"
;
}
}
return
$self
->fetch_all_by_Slice_constraint(
$slice
,
$constraint
,
@args
);
}
sub
_columns {
my
$self
=
shift
;
return
(
'mf.marker_feature_id'
,
'mf.marker_id'
,
'mf.seq_region_id'
,
'mf.seq_region_start'
,
'mf.seq_region_end'
,
'mf.analysis_id'
,
'mf.map_weight'
,
'm.left_primer'
,
'm.right_primer'
,
'm.min_primer_dist'
,
'm.max_primer_dist'
,
'm.priority'
,
'm.type'
,
'ms.marker_synonym_id'
,
'ms.name'
,
'ms.source'
);
}
sub
_tables {
my
$self
=
shift
;
return
([
'marker_feature'
,
'mf'
],
[
'marker'
,
'm'
],
[
'marker_synonym'
,
'ms'
]);
}
sub
_left_join {
my
$self
=
shift
;
return
( [
'marker_synonym'
,
'm.display_marker_synonym_id = ms.marker_synonym_id'
] );
}
sub
_default_where_clause {
my
$self
=
shift
;
return
(
'mf.marker_id = m.marker_id'
);
}
sub
_objs_from_sth {
my
(
$self
,
$sth
,
$mapper
,
$dest_slice
) =
@_
;
my
(
$marker_feature_id
,
$marker_id
,
$seq_region_id
,
$seq_region_start
,
$seq_region_end
,
$analysis_id
,
$map_weight
,
$left_primer
,
$right_primer
,
$min_primer_dist
,
$max_primer_dist
,
$priority
,
$type
,
$ms_id
,
$ms_name
,
$ms_source
);
$sth
->bind_columns(\
$marker_feature_id
, \
$marker_id
,
\
$seq_region_id
, \
$seq_region_start
, \
$seq_region_end
,
\
$analysis_id
, \
$map_weight
,
\
$left_primer
, \
$right_primer
, \
$min_primer_dist
, \
$max_primer_dist
,
\
$priority
, \
$type
, \
$ms_id
, \
$ms_name
, \
$ms_source
);
my
@out
= ();
my
%marker_cache
;
my
%slice_hash
;
my
%sr_cs_hash
;
my
%analysis_cache
;
my
$marker_adp
=
$self
->db->get_MarkerAdaptor;
my
$sa
=
$self
->db->get_SliceAdaptor;
my
$analysis_adp
=
$self
->db->get_AnalysisAdaptor;
my
$asm_cs
;
my
$cmp_cs
;
my
$asm_cs_vers
;
my
$asm_cs_name
;
my
$cmp_cs_vers
;
my
$cmp_cs_name
;
if
(
$mapper
) {
$asm_cs
=
$mapper
->assembled_CoordSystem();
$cmp_cs
=
$mapper
->component_CoordSystem();
$asm_cs_name
=
$asm_cs
->name();
$asm_cs_vers
=
$asm_cs
->version();
$cmp_cs_name
=
$cmp_cs
->name();
$cmp_cs_vers
=
$cmp_cs
->version();
}
my
$dest_slice_start
;
my
$dest_slice_end
;
my
$dest_slice_strand
;
my
$dest_slice_length
;
if
(
$dest_slice
) {
$dest_slice_start
=
$dest_slice
->start();
$dest_slice_end
=
$dest_slice
->end();
$dest_slice_strand
=
$dest_slice
->strand();
$dest_slice_length
=
$dest_slice
->
length
();
}
FEATURE:
while
(
$sth
->fetch) {
my
$marker
;
if
(!(
$marker
=
$marker_cache
{
$marker_id
})) {
my
$ms
;
if
(
$ms_id
) {
$ms
= Bio::EnsEMBL::Map::MarkerSynonym->new
(
$ms_id
,
$ms_source
,
$ms_name
);
}
$marker
= Bio::EnsEMBL::Map::Marker->new
(
$marker_id
,
$marker_adp
,
$left_primer
,
$right_primer
,
$min_primer_dist
,
$max_primer_dist
,
$priority
,
$type
,
$ms
);
$marker_cache
{
$marker_id
} =
$marker
;
}
my
$slice
=
$slice_hash
{
$seq_region_id
};
if
(!
$slice
) {
$slice
=
$sa
->fetch_by_seq_region_id(
$seq_region_id
);
$slice_hash
{
$seq_region_id
} =
$slice
;
$sr_cs_hash
{
$seq_region_id
} =
$slice
->coord_system();
}
my
$analysis
;
unless
(
$analysis
=
$analysis_cache
{
$analysis_id
}) {
$analysis
=
$analysis_adp
->fetch_by_dbID(
$analysis_id
);
$analysis_cache
{
$analysis_id
} =
$analysis
;
}
if
(
$mapper
) {
my
$sr_cs
=
$sr_cs_hash
{
$seq_region_id
};
(
$seq_region_id
,
$seq_region_start
,
$seq_region_end
) =
$mapper
->fastmap(
$slice
->seq_region_name(),
$seq_region_start
,
$seq_region_end
, 0,
$sr_cs
);
next
FEATURE
if
(!
defined
(
$seq_region_id
));
$slice
=
$slice_hash
{
"$seq_region_id"
} ||=
$sa
->fetch_by_seq_region_id(
$seq_region_id
);
}
if
(
$dest_slice
) {
my
$seq_region_len
=
$dest_slice
->seq_region_length();
if
(
$dest_slice_strand
== 1) {
$seq_region_start
=
$seq_region_start
-
$dest_slice_start
+ 1;
$seq_region_end
=
$seq_region_end
-
$dest_slice_start
+ 1;
if
(
$dest_slice
->is_circular()) {
if
(
$seq_region_start
>
$seq_region_end
) {
if
(
$seq_region_end
>
$dest_slice_start
) {
$seq_region_start
-=
$seq_region_len
;
}
if
(
$seq_region_end
< 0) {
$seq_region_end
+=
$seq_region_len
;
}
}
else
{
if
(
$dest_slice_start
>
$dest_slice_end
&&
$seq_region_end
< 0) {
$seq_region_start
+=
$seq_region_len
;
$seq_region_end
+=
$seq_region_len
;
}
}
}
}
else
{
my
$start
=
$dest_slice_end
-
$seq_region_end
+ 1;
my
$end
=
$dest_slice_end
-
$seq_region_start
+ 1;
if
(
$dest_slice
->is_circular()) {
if
(
$dest_slice_start
>
$dest_slice_end
) {
if
(
$seq_region_start
>=
$dest_slice_start
) {
$end
+=
$seq_region_len
;
$start
+=
$seq_region_len
if
$seq_region_end
>
$dest_slice_start
;
}
elsif
(
$seq_region_start
<=
$dest_slice_end
) {
}
elsif
(
$seq_region_end
>=
$dest_slice_start
) {
$start
+=
$seq_region_len
;
$end
+=
$seq_region_len
;
}
elsif
(
$seq_region_end
<=
$dest_slice_end
) {
$end
+=
$seq_region_len
if
$end
< 0;
}
elsif
(
$seq_region_start
>
$seq_region_end
) {
$end
+=
$seq_region_len
;
}
else
{
}
}
else
{
if
(
$seq_region_start
<=
$dest_slice_end
and
$seq_region_end
>=
$dest_slice_start
) {
}
elsif
(
$seq_region_start
>
$seq_region_end
) {
if
(
$seq_region_start
<=
$dest_slice_end
) {
$start
-=
$seq_region_len
;
}
elsif
(
$seq_region_end
>=
$dest_slice_start
) {
$end
+=
$seq_region_len
;
}
else
{
}
}
}
}
$seq_region_start
=
$start
;
$seq_region_end
=
$end
;
}
if
(
$seq_region_end
< 1 ||
$seq_region_start
>
$dest_slice_length
) {
next
FEATURE;
}
$slice
=
$dest_slice
;
}
push
@out
, Bio::EnsEMBL::Map::MarkerFeature->new
(
$marker_feature_id
,
$self
,
$seq_region_start
,
$seq_region_end
,
$slice
,
$analysis
,
$marker_id
,
$map_weight
,
$marker
);
}
return
\
@out
;
}
sub
store {
my
(
$self
,
@mfs
) =
@_
;
foreach
my
$mf
(
@mfs
) {
if
(!
ref
(
$mf
) || !
$mf
->isa(
'Bio::EnsEMBL::Map::MarkerFeature'
)) {
$self
->throw(
"Incorrect argument [$mf] to store. Expected "
.
'Bio::EnsEMBL::Map::MarkerFeature'
);
}
if
(
$mf
->is_stored(
$self
->db())) {
warning(
'MarkerFeature ['
.
$mf
->dbID.
'] is already stored in this DB.'
);
next
;
}
my
$marker
=
$mf
->marker;
if
(!
$marker
|| !
ref
(
$marker
) ||
!
$marker
->isa(
'Bio::EnsEMBL::Map::Marker'
)) {
throw(
'Cannot store MarkerFeature without an associated Marker'
);
}
if
(!
$marker
->is_stored(
$self
->db())) {
my
$marker_adaptor
=
$self
->db->get_adaptor(
'Marker'
);
$marker_adaptor
->store(
$marker
);
}
my
$marker_id
=
$marker
->dbID ||
throw(
'Associated Marker must have dbID to store MarkerFeature'
);
my
$analysis
=
$mf
->analysis;
if
(!
$analysis
|| !
ref
(
$analysis
) ||
!
$analysis
->isa(
'Bio::EnsEMBL::Analysis'
)) {
throw(
'Cannot store MarkerFeature without an associated Analysis'
);
}
if
(!
$analysis
->is_stored(
$self
->db())) {
my
$analysis_adaptor
=
$self
->db->get_adaptor(
'Analysis'
);
$analysis_adaptor
->store(
$mf
->analysis());
}
my
$analysis_id
=
$analysis
->dbID ||
throw(
'Associated Analysis must have dbID to store MarkerFeature'
);
my
$original
=
$mf
;
my
$seq_region_id
;
(
$mf
,
$seq_region_id
) =
$self
->_pre_store(
$mf
);
my
$sth
=
$self
->prepare("INSERT INTO marker_feature (marker_id,
seq_region_id, seq_region_start, seq_region_end,
analysis_id, map_weight)
VALUES (?, ?, ?, ?, ?, ?)");
$sth
->execute(
$marker_id
,
$seq_region_id
,
$mf
->start,
$mf
->end,
$analysis_id
,
$mf
->map_weight || 0);
my
$dbID
=
$self
->last_insert_id(
'marker_feature_id'
,
undef
,
'marker_feature'
);
$original
->dbID(
$dbID
);
$original
->adaptor(
$self
);
}
}
1;