Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
ea37ea6f
Commit
ea37ea6f
authored
21 years ago
by
Graham McVicker
Browse files
Options
Downloads
Patches
Plain Diff
finished AttributeAdaptor implementation
parent
57bffab9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/Bio/EnsEMBL/DBSQL/AttributeAdaptor.pm
+155
-35
155 additions, 35 deletions
modules/Bio/EnsEMBL/DBSQL/AttributeAdaptor.pm
with
155 additions
and
35 deletions
modules/Bio/EnsEMBL/DBSQL/AttributeAdaptor.pm
+
155
−
35
View file @
ea37ea6f
...
...
@@ -22,11 +22,9 @@ Bio::EnsEMBL::Attribute objects.
$attributes = $attribute_adaptor->fetch_all_by_Slice( $slice );
$attribute_
types = $attribute_adaptor->fetch_all_typ
es
(
);
$attribute_
adaptor->store_on_Slice( $slice, \@attribut
es
);
$attribute_adaptor->store_on_Slice( $slice, $attributes );
$attribute_adaptor->store_on_MiscFeature( $misc_feature, $attributes )
$attribute_adaptor->store_on_MiscFeature( $misc_feature, \@attributes )
=head1 DESCRIPTION
...
...
@@ -70,6 +68,7 @@ sub new {
my
$self
=
$class
->
SUPER::
new
(
@
_
);
# cache creation could go here
return
$self
;
}
...
...
@@ -91,6 +90,30 @@ sub new {
sub
fetch_all_by_MiscFeature
{
my
$self
=
shift
;
my
$mf
=
shift
;
if
(
!
ref
(
$mf
)
||
!
$mf
->
isa
('
Bio::EnsEMBL::MiscFeature
'))
{
throw
('
MiscFeature argument is required.
');
}
my
$mfid
=
$mf
->
dbID
();
if
(
!
defined
(
$mfid
))
{
throw
("
MiscFeature must have dbID.
");
}
my
$sth
=
$self
->
prepare
("
SELECT at.code, at.name, at.description,
"
.
"
ma.value
"
.
"
FROM misc_attrib ma, attrib_type at
"
.
"
WHERE ma.misc_feature_id = ?
"
.
"
AND at.attrib_type_id = ma.attrib_type_id
");
$sth
->
execute
(
$mfid
);
my
$results
=
$self
->
_obj_from_sth
(
$sth
);
$sth
->
finish
();
return
$results
;
}
...
...
@@ -110,27 +133,31 @@ sub fetch_all_by_MiscFeature {
sub
fetch_all_by_Slice
{
my
$self
=
shift
;
my
$slice
=
shift
;
}
if
(
!
ref
(
$slice
)
||
!
$slice
->
isa
('
Bio::EnsEMBL::Slice
'))
{
throw
('
Slice argument is required.
');
}
my
$seq_region_id
=
$slice
->
get_seq_region_id
();
=head2 fetch_all_types
Arg [1] : none, string, int, Bio::EnsEMBL::Example $formal_parameter_name
Additional description lines
list, listref, hashref
Example : ( optional )
Description: testable description
Returntype : none, txt, int, float, Bio::EnsEMBL::Example
Exceptions : none
Caller : object::methodname or just methodname
if
(
!
defined
(
$seq_region_id
))
{
throw
("
Could not get seq_region_id for provided slice:
"
.
$slice
->
name
());
}
=cut
my
$sth
=
$self
->
prepare
("
SELECT at.code, at.name, at.description,
"
.
"
sra.value
"
.
"
FROM seq_region_attrib sra, attrib_type at
"
.
"
WHERE sra.seq_region_id = ?
"
.
"
AND at.attrib_type_id = sra.attrib_type_id
");
sub
fetch_all_types
{
my
$self
=
shift
;
$sth
->
execute
(
$seq_region_id
);
my
$results
=
$self
->
_obj_from_sth
(
$sth
);
return
$all_types
;
$sth
->
finish
();
return
$results
;
}
...
...
@@ -166,7 +193,7 @@ sub store_on_Slice {
my
$seq_region_id
=
$slice
->
get_seq_region_id
();
if
(
!
$seq_region_id
)
{
throw
("
Could not get seq_region_id for provided slice:
"
$slice
->
name
());
throw
("
Could not get seq_region_id for provided slice:
"
.
$slice
->
name
());
}
my
$sth
=
$self
->
prepare
(
"
INSERT into seq_region_attrib
"
.
...
...
@@ -179,7 +206,7 @@ sub store_on_Slice {
"
argument expected.
");
}
my
$atid
=
$self
->
_store_type
(
$at
);
$sth
->
execute
(
$seq_region_id
,
$at
trib_
id
,
$at
trib
->
value
()
);
$sth
->
execute
(
$seq_region_id
,
$atid
,
$at
->
value
()
);
}
return
;
...
...
@@ -228,7 +255,7 @@ sub store_on_MiscFeature {
"
value = ?
"
);
for
my
$attrib
(
@$attributes
)
{
if
(
!
ref
(
$at
)
&&
$at
->
isa
('
Bio::EnsEMBL::Attribute
'))
{
if
(
!
ref
(
$at
trib
)
&&
$at
trib
->
isa
('
Bio::EnsEMBL::Attribute
'))
{
throw
("
Reference to list of Bio::EnsEMBL::Attribute objects
"
.
"
argument expected.
");
}
...
...
@@ -241,50 +268,143 @@ sub store_on_MiscFeature {
# _store_type
=head2 remove_from_Slice
Arg [1] : Bio::EnsEMBL::Slice $slice
The Slice to remove attributes from
Example : $attribute_adaptor->remove_from_Slice($slice);
Description: Removes all attributes which are stored in the database on
the provided Slice.
Returntype : none
Exceptions : throw on incorrect arguments
throw if cannot obtain seq_region_id from provided Slice
Caller : general
=cut
sub
remove_from_Slice
{
my
$self
=
shift
;
my
$slice
=
shift
;
if
(
!
ref
(
$slice
)
||
!
$slice
->
isa
('
Bio::EnsEMBL::Slice
'))
{
throw
("
Bio::EnsEMBL::Slice argument expected.
");
}
my
$srid
=
$slice
->
get_seq_region_id
();
if
(
!
$srid
)
{
throw
("
Could not get seq_region_id for provided slice:
"
.
$slice
->
name
());
}
my
$sth
=
$self
->
prepare
("
DELETE FROM seq_region_attrib
"
.
"
WHERE seq_region_id = ?
");
$sth
->
execute
(
$srid
);
$sth
->
finish
();
return
;
}
=head2 remove_from_MiscFeature
Arg [1] : Bio::EnsEMBL::MiscFeature $mf
The MiscFeature to remove attributes from
Example : $attribute_adaptor->remove_from_MiscFeature($mf);
Description: Removes all attributes which are stored in the database on
the provided MiscFeature.
Returntype : none
Exceptions : throw on incorrect arguments
throw if MiscFeature is not stored in this database
Caller : general
=cut
sub
remove_from_MiscFeature
{
my
$self
=
shift
;
my
$mf
=
shift
;
if
(
!
ref
(
$mf
)
||
!
$mf
->
isa
('
Bio::EnsEMBL::MiscFeature
'))
{
throw
("
Bio::EnsEMBL::MiscFeature argument is required.
");
}
my
$db
=
$self
->
db
();
if
(
!
$mf
->
is_stored
(
$db
))
{
throw
("
MiscFeature is not stored in this database.
");
}
my
$sth
=
$db
->
prepare
("
DELETE FROM misc_attrib
"
.
"
WHERE misc_feature_id = ?
");
$sth
->
execute
(
$mf
->
dbID
());
$sth
->
finish
();
return
;
}
# _store_type
sub
_store_type
{
my
$self
=
shift
;
my
$attrib
=
shift
;
my
$sth
=
$self
->
prepare
my
$sth
1
=
$self
->
prepare
("
INSERT IGNORE INTO attrib_type set code = ?, name = ?,
"
.
"
description = ?
"
);
$sth
->
execute
(
$attrib
->
code
(),
$attrib
->
name
(),
$attrib
->
description
()
);
my
$atid
=
$sth
->
{'
mysql_insertid
'};
my
$rows_inserted
=
$sth1
->
execute
(
$attrib
->
code
(),
$attrib
->
name
(),
$attrib
->
desc
()
);
$sth
->
finish
()
;
my
$atid
=
$sth
1
->
{'
mysql_insertid
'}
;
if
(
$self
->
db
->
db_handle
->
{'
mysql_info
'}
==
0
)
{
if
(
$rows_inserted
==
0
)
{
# the insert failed because the code is already stored
$sth
=
$self
->
prepare
my
$sth
2
=
$self
->
prepare
("
SELECT attrib_type_id FROM attrib_type
"
.
"
WHERE code = ?
");
$sth
->
execute
(
$code
);
(
$atid
)
=
$sth
->
fetchrow_array
();
$sth
2
->
execute
(
$
attrib
->
code
()
);
(
$atid
)
=
$sth
2
->
fetchrow_array
();
$sth
->
finish
();
$sth
2
->
finish
();
if
(
!
$atid
)
{
throw
("
Could not store or fetch attrib_type code [
$
code
]
\n
"
.
throw
("
Could not store or fetch attrib_type code [
"
.
$attrib
->
code
.
"
]
\n
"
.
"
Wrong database user/permissions?
");
}
}
$sth1
->
finish
();
return
$atid
;
}
sub
_obj_from_sth
{
my
$self
=
shift
;
my
$sth
=
shift
;
return
$
r
es
ults
;
}
my
(
$code
,
$name
,
$
d
es
c
,
$value
)
;
$sth
->
bind_columns
(
\
$code
,
\
$name
,
\
$desc
,
\
$value
);
my
@results
;
while
(
$sth
->
fetch
())
{
push
@results
,
Bio::EnsEMBL::
Attribute
->
new
(
-
CODE
=>
$code
,
-
NAME
=>
$name
,
-
DESC
=>
$desc
,
-
VALUE
=>
$value
);
}
return
\
@results
;
}
#
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment