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
4c94d6c2
Commit
4c94d6c2
authored
21 years ago
by
Graham McVicker
Browse files
Options
Downloads
Patches
Plain Diff
added several fetch methods, fixed some small bugs in store method
parent
3713e562
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/DensityTypeAdaptor.pm
+187
-47
187 additions, 47 deletions
modules/Bio/EnsEMBL/DBSQL/DensityTypeAdaptor.pm
with
187 additions
and
47 deletions
modules/Bio/EnsEMBL/DBSQL/DensityTypeAdaptor.pm
+
187
−
47
View file @
4c94d6c2
...
...
@@ -6,21 +6,6 @@
#
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
#mysql> desc density_type;
#+-----------------+---------------------+------+-----+---------+----------------+
#| Field | Type | Null | Key | Default | Extra |
#+-----------------+---------------------+------+-----+---------+----------------+
#| density_type_id | int(11) | | PRI | NULL | auto_increment |
#| analysis_id | int(11) | | MUL | 0 | |
#| block_size | int(11) | | | 0 | |
#| value_type | enum('sum','ratio') | | | sum | |
#+-----------------+---------------------+------+-----+---------+----------------+
=head1 NAME
Bio::EnsEMBL::DBSQL::DensityTypeAdaptor
...
...
@@ -28,13 +13,14 @@ Bio::EnsEMBL::DBSQL::DensityTypeAdaptor
=head1 SYNOPSIS
my $density_type_adaptor = $database_adaptor->get_DensityTypeAdaptor();
@density_types = @{$density_type_adaptor->fetch_all
_by_Slice($slice
)};
@density_types = @{$density_type_adaptor->fetch_all
(
)};
=head1 DESCRIPTION
my $dt = $density_type_adaptor->fetch_by_dbID(12);
Simple Feature Adaptor - database access for simple features
=head1 AUTHOR - Ewan Birney
=head1 DESCRIPTION
DensityTypeAdaptor - Performs database interaction for DensityType objects.
=head1 METHODS
...
...
@@ -44,11 +30,177 @@ package Bio::EnsEMBL::DBSQL::DensityTypeAdaptor;
use
vars
qw(@ISA)
;
use
strict
;
use
Bio::EnsEMBL::DBSQL::
BaseFeatureAdaptor
;
#use Bio::EnsEMBL::DensityType;
use
Bio::EnsEMBL::DBSQL::
BaseAdaptor
;
use
Bio::EnsEMBL::
DensityType
;
use
Bio::EnsEMBL::Utils::
Exception
qw(throw warning)
;
@ISA
=
qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor)
;
@ISA
=
qw(Bio::EnsEMBL::DBSQL::BaseAdaptor)
;
=head2 new
Arg [1] : see superclass (Bio::EnsEMBL::DBSQL::BaseAdaptor) arguments
Example : #use this instead of the constructor directly:
my $dta = $db_adaptor->get_DensityTypeAdaptor();
Description: Constructor. Creates a new DensityTypeAdaptor
Returntype : Bio::EnsEMBL::DBSQL::DensityTypeAdaptor
Exceptions : none
Caller : DBAdaptor
=cut
sub
new
{
my
$class
=
shift
;
my
$self
=
$class
->
SUPER::
new
(
@
_
);
$self
->
{'
dbID_cache
'}
=
{};
return
$self
;
}
=head2 fetch_all
Arg [1] : none
Example : my @density_types = @{$density_type_adaptor->fetch_all};
Description: Retrieves every density type in the database
Returntype : reference to list of Bio::EnsEMBL::DensityType objects
Exceptions : none
Caller : general, new
=cut
sub
fetch_all
{
my
$self
=
shift
;
my
@out
;
my
$sth
=
$self
->
prepare
("
SELECT density_type_id, analysis_id, block_size,
"
.
"
value_type
"
.
"
FROM density_type
");
$sth
->
execute
();
my
(
$dbID
,
$analysis_id
,
$blk_size
,
$vtype
);
$sth
->
bind_columns
(
\
$dbID
,
\
$analysis_id
,
\
$blk_size
,
\
$vtype
);
my
$analysis_adaptor
=
$self
->
db
->
get_AnalysisAdaptor
();
while
(
$sth
->
fetch
())
{
my
$analysis
=
$analysis_adaptor
->
fetch_by_dbID
(
$analysis_id
);
my
$dt
=
Bio::EnsEMBL::
DensityType
->
new
(
-
ADAPTOR
=>
$self
,
-
DBID
=>
$dbID
,
-
ANALYSIS
=>
$analysis
,
-
BLOCK_SIZE
=>
$blk_size
,
-
VALUE_TYPE
=>
$vtype
);
$self
->
{'
dbID_cache
'}
->
{
$dbID
}
=
$dt
;
push
@out
,
$dt
;
}
return
\
@out
;
}
=head2 fetch_by_dbID
Arg [1] : int $dbID
Example : my $dt = $density_type_adaptor->fetch_by_dbID($dbID);
Description: Retrieves a density type object via its internal identifier
Returntype : Bio::EnsEMBL::DensityType
Exceptions : throw if dbID argument not defined
Caller : general
=cut
sub
fetch_by_dbID
{
my
$self
=
shift
;
my
$dbID
=
shift
;
if
(
!
defined
(
$dbID
))
{
throw
("
dbID argument must be defined
");
}
if
(
$self
->
{'
dbID_cache
'}
->
{
$dbID
})
{
return
$self
->
{'
dbID_cache
'}
->
{
$dbID
};
}
# go back to database and refill caches
$self
->
fetch_all
();
return
$self
->
{'
dbID_cache
'}
->
{
$dbID
};
}
=head2 fetch_all_by_logic_name
Arg [1] : string $logic_name
Example : my @dts = @{$dtype_adaptor->fetch_all('repeat_coverage')};
Description: Retrieves all density types with a given logic name
Returntype : reference to list of Bio::EnsEMBL::DensityTypes
Exceptions : thrown if logic_name argument is not provided
Caller : general
=cut
sub
fetch_all_by_logic_name
{
my
$self
=
shift
;
my
$logic_name
=
shift
;
if
(
!
defined
(
$logic_name
))
{
throw
("
logic_name argument is required.
");
}
my
$analysis_adaptor
=
$self
->
db
()
->
get_AnalysisAdaptor
();
my
$analysis
=
$analysis_adaptor
->
fetch_by_logic_name
(
$logic_name
);
return
[]
if
(
!
$analysis
);
my
$sth
=
$self
->
prepare
("
SELECT density_type_id, block_size,
"
.
"
value_type
"
.
"
FROM density_type
"
.
"
WHERE analysis_id = ?
");
$sth
->
execute
(
$analysis
->
dbID
());
my
(
$dbID
,
$blk_size
,
$vtype
);
$sth
->
bind_columns
(
\
$dbID
,
\
$blk_size
,
\
$vtype
);
my
@out
;
while
(
$sth
->
fetch
())
{
my
$dt
=
Bio::EnsEMBL::
DensityType
->
new
(
-
ADAPTOR
=>
$self
,
-
DBID
=>
$dbID
,
-
ANALYSIS
=>
$analysis
,
-
BLOCK_SIZE
=>
$blk_size
,
-
VALUE_TYPE
=>
$vtype
);
$self
->
{'
dbID_cache
'}
->
{
$dbID
}
=
$dt
;
push
@out
,
$dt
;
}
return
\
@out
;
}
#
# garbage collection method, automatically called when DBAdaptor is cleaned up
#
sub
deleteObj
{
my
$self
=
shift
;
delete
$self
->
{'
dbID_cache
'};
$self
->
SUPER::
deleteObj
;
}
=head2 store
...
...
@@ -63,17 +215,8 @@ use Bio::EnsEMBL::Utils::Exception qw(throw warning);
Caller : general
=cut
#mysql> desc density_type;
#+-----------------+---------------------+------+-----+---------+----------------+
#| Field | Type | Null | Key | Default | Extra |
#+-----------------+---------------------+------+-----+---------+----------------+
#| density_type_id | int(11) | | PRI | NULL | auto_increment |
#| analysis_id | int(11) | | MUL | 0 | |
#| block_size | int(11) | | | 0 | |
#| value_type | enum('sum','ratio') | | | sum | |
#+-----------------+---------------------+------+-----+---------+----------------+
sub
store
{
sub
store
{
my
(
$self
,
@dt
)
=
@_
;
if
(
scalar
(
@dt
)
==
0
)
{
...
...
@@ -89,39 +232,36 @@ sub store{
my
$analysis_adaptor
=
$db
->
get_AnalysisAdaptor
();
FEATURE:
foreach
my
$dt
(
@dt
)
{
if
(
!
ref
$dt
||
!
$dt
->
isa
("
Bio::EnsEMBL::DensityType
")
)
{
throw
("
Density Type must be an Ensembl DensityType,
"
.
"
not a [
"
.
ref
(
$dt
)
.
"
]
");
}
if
(
$dt
->
is_stored
(
$db
))
{
warning
("
DensityType [
"
.
$dt
->
density_type_id
.
"
] is already stored
"
.
"
in this database.
");
next
FEATURE
;
}
if
(
!
defined
(
$dt
->
analysis
))
{
if
(
!
defined
(
$dt
->
analysis
()
))
{
throw
("
An analysis must be attached to the density type to be stored.
");
}
#store the analysis if it has not been stored yet
if
(
!
$dt
->
analysis
->
is_stored
(
$db
))
{
throw
("
Analysis must already exist???? But does not??
"
);
$analysis_adaptor
->
store
(
$dt
->
analysis
()
);
}
$sth
->
execute
(
$dt
->
analysis
->
dbID
(),
$dt
->
block_size
(),
$dt
->
value_type
());
$sth
->
execute
(
$dt
->
analysis
->
dbID
,
$dt
->
{'
block_size
'},
$dt
->
{'
value_type
'});
my
$dbID
=
$sth
->
{'
mysql_insertid
'};
# next two lines are to set the density type as stored
$dt
->
dbID
(
$
sth
->
{'
mysql_insertid
'}
);
$dt
->
dbID
(
$
dbID
);
$dt
->
adaptor
(
$self
);
$self
->
{'
dbID_cache
'}
->
{
$dbID
}
=
$dt
;
}
}
1
;
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