Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
ensembl-gh-mirror
ensembl-hive
Commits
93a8d3c9
Commit
93a8d3c9
authored
Jun 14, 2004
by
Jessica Severin
Browse files
added AnalysisCtrlRule and adaptor (used in logic to 'unblock' analyses
when ALL of their conditions are 'DONE')
parent
d0438088
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
457 additions
and
0 deletions
+457
-0
modules/Bio/EnsEMBL/Hive/AnalysisCtrlRule.pm
modules/Bio/EnsEMBL/Hive/AnalysisCtrlRule.pm
+191
-0
modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisCtrlRuleAdaptor.pm
modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisCtrlRuleAdaptor.pm
+266
-0
No files found.
modules/Bio/EnsEMBL/Hive/AnalysisCtrlRule.pm
0 → 100755
View file @
93a8d3c9
# Perl module for Bio::EnsEMBL::Hive::AnalysisCtrlRule
#
# Creator: Jessica Severin <jessica@ebi.ac.uk>
# Date of creation: 22.03.2004
#
# Copyright EMBL-EBI 2000-2004
#
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
=head1 NAME
Bio::EnsEMBL::Hive::AnalysisCtrlRule
=head1 SYNOPSIS
=head1 DESCRIPTION
Needed a robust and simpler rule table
where Analyses in the pipeline can robustly define
new analyses and rules. New design has a single table where a 'rule'
is a simple link from one analysis to another.
Extended from design of SimpleRule concept to allow the 'to' analysis to
be specified with a network savy URL like
mysql://ensadmin:<pass>@ecs2:3361/compara_hive_test?analysis.logic_name='blast_NCBI34'
=head1 CONTACT
Contact Jessica Severin on EnsEMBL::Hive implemetation/design detail: jessica@ebi.ac.uk
Contact Ewan Birney on EnsEMBL in general: birney@sanger.ac.uk
=head1 APPENDIX
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
=cut
# Let the code begin...
package
Bio::EnsEMBL::Hive::
AnalysisCtrlRule
;
use
vars
qw(@ISA)
;
use
Bio::EnsEMBL::
Root
;
use
Bio::EnsEMBL::Hive::
URLFactory
;
use
Bio::EnsEMBL::Hive::
Extensions
;
use
strict
;
@ISA
=
qw( Bio::EnsEMBL::Root )
;
=head2 Constructor
Title : new
Usage : ...AnalysisCtrlRule->new;
Function: Constructor for empty AnalysisCtrlRule object
Returns : Bio::EnsEMBL::Hive::AnalysisCtrlRule
Args : none
=cut
sub
new
{
my
(
$class
,
@args
)
=
@_
;
my
$self
=
$class
->
SUPER::
new
(
@args
);
return
$self
;
}
sub
adaptor
{
my
(
$self
,
$adaptor
)
=
@_
;
$self
->
{'
_adaptor
'}
=
$adaptor
if
defined
$adaptor
;
return
$self
->
{'
_adaptor
'};
}
=head2 ctrled_analysis_id
Title : ctrled_analysis_id
Arg[1] : (optional) int $dbID
Usage : $self->ctrled_analysis_id($dbID);
Function: Get/set method for the 'controlled' analysis objects dbID of this rule.
Returns : integer
=cut
sub
ctrled_analysis_id
{
my
(
$self
,
$analysis_id
)
=
@_
;
if
(
$analysis_id
)
{
$self
->
{'
_ctrled_analysis_id
'}
=
$analysis_id
;
$self
->
{'
_ctrled_analysis
'}
=
undef
;
}
return
$self
->
{'
_ctrled_analysis_id
'};
}
=head2 condition_analysis_url
Title : condition_analysis_url
Arg[1] : (optional) string $url
Usage : $self->condition_analysis_url($url);
Function: Get/set method for the 'to' analysis objects URL for this rule
Returns : string
=cut
sub
condition_analysis_url
{
my
(
$self
,
$url
)
=
@_
;
if
(
$url
)
{
$self
->
{'
_condition_analysis_url
'}
=
$url
;
$self
->
{'
_condition_analysis
'}
=
undef
;
}
return
$self
->
{'
_condition_analysis_url
'};
}
=head2 ctrled_analysis
Title : ctrled_analysis
Usage : $self->ctrled_analysis($anal);
Function: Get/set method for the condition analysis object of this rule.
Returns : Bio::EnsEMBL::Analysis
Args : Bio::EnsEMBL::Analysis
=cut
sub
ctrled_analysis
{
my
(
$self
,
$analysis
)
=
@_
;
# setter mode
if
(
defined
$analysis
)
{
unless
(
$analysis
->
isa
('
Bio::EnsEMBL::Analysis
'))
{
$self
->
throw
(
"
ctrled_analysis arg must be a [Bio::EnsEMBL::Analysis]
"
.
"
not a [
$analysis
]
");
}
$self
->
{'
_ctrled_analysis
'}
=
$analysis
;
$self
->
{'
_ctrled_analysis_id
'}
=
$analysis
->
dbID
;
}
# lazy load the analysis object if I can
if
(
!
defined
(
$self
->
{'
_ctrled_analysis
'})
and
defined
(
$self
->
ctrled_analysis_id
)
and
defined
(
$self
->
adaptor
))
{
$self
->
{'
_ctrled_analysis
'}
=
$self
->
adaptor
->
db
->
get_AnalysisAdaptor
->
fetch_by_dbID
(
$self
->
ctrled_analysis_id
);
}
return
$self
->
{'
_ctrled_analysis
'};
}
=head2 condition_analysis
Title : condition_analysis
Usage : $self->condition_analysis($anal);
Function: Get/set method for the goal analysis object of this rule.
Returns : Bio::EnsEMBL::Analysis
Args : Bio::EnsEMBL::Analysis
=cut
sub
condition_analysis
{
my
(
$self
,
$analysis
)
=
@_
;
if
(
defined
$analysis
)
{
unless
(
$analysis
->
isa
('
Bio::EnsEMBL::Analysis
'))
{
$self
->
throw
(
"
condition_analysis arg must be a [Bio::EnsEMBL::Analysis]
"
.
"
not a [
$analysis
]
");
}
$self
->
{'
_condition_analysis
'}
=
$analysis
;
#if the 'condition' and 'ctrled' share the same adaptor, then use a simple logic_name
#for the URL rather than a full network distributed URL
if
(
$self
->
ctrled_analysis
and
(
$self
->
ctrled_analysis
->
adaptor
==
$analysis
->
adaptor
))
{
$self
->
{'
_condition_analysis_url
'}
=
$analysis
->
logic_name
;
}
else
{
$self
->
{'
_condition_analysis_url
'}
=
$analysis
->
url
;
}
}
# lazy load the analysis object if I can
if
(
!
defined
(
$self
->
{'
_condition_analysis
'})
and
defined
(
$self
->
condition_analysis_url
))
{
my
$analyis
=
Bio::EnsEMBL::Hive::
URLFactory
->
fetch
(
$self
->
condition_analysis_url
);
unless
(
$analysis
)
{
$analysis
=
$self
->
adaptor
->
db
->
get_AnalysisAdaptor
->
fetch_by_logic_name
(
$self
->
condition_analysis_url
);
}
$self
->
{'
_condition_analysis
'}
=
$analysis
;
}
return
$self
->
{'
_condition_analysis
'};
}
sub
print_rule
{
my
$self
=
shift
;
print
("
AnalysisCtrlRule
",
"
ctrled_analysis_id=
",
$self
->
ctrled_analysis_id
,
"
condition_analysis_url=
",
$self
->
condition_analysis
->
url
,
"
\n
");
}
1
;
modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisCtrlRuleAdaptor.pm
0 → 100755
View file @
93a8d3c9
# Perl module for Bio::EnsEMBL::Hive::DBSQL::AnalysisCtrlRuleAdaptor
#
# Date of creation: 22.03.2004
# Original Creator : Jessica Severin <jessica@ebi.ac.uk>
#
# Copyright EMBL-EBI 2004
#
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
=head1 NAME
Bio::EnsEMBL::Hive::DBSQL::AnalysisCtrlRuleAdaptor
=head1 SYNOPSIS
$AnalysisCtrlRuleAdaptor = $db_adaptor->get_AnalysisCtrlRuleAdaptor;
$analysisCtrlRuleAdaptor = $analysisCtrlRuleObj->adaptor;
=head1 DESCRIPTION
Module to encapsulate all db access for persistent class AnalysisCtrlRule.
There should be just one per application and database connection.
=head1 CONTACT
Contact Jessica Severin on implemetation/design detail: jessica@ebi.ac.uk
Contact Ewan Birney on EnsEMBL in general: birney@sanger.ac.uk
=head1 APPENDIX
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
=cut
# Let the code begin...
package
Bio::EnsEMBL::Hive::DBSQL::
AnalysisCtrlRuleAdaptor
;
use
strict
;
use
Carp
;
use
Bio::EnsEMBL::DBSQL::
BaseAdaptor
;
use
Bio::EnsEMBL::Hive::
AnalysisCtrlRule
;
our
@ISA
=
qw(Bio::EnsEMBL::DBSQL::BaseAdaptor)
;
=head2 fetch_by_ctrled_analysis_id
Arg [1] : int $id
the unique database identifier for the feature to be obtained
Example : $feat = $adaptor->fetch_by_dbID(1234);
Description: Returns the Member created from the database defined by the
the id $id.
Returntype : listref of Bio::EnsEMBL::Hive::AnalysisCtrlRule
Exceptions : thrown if $id is not defined
Caller : general
=cut
sub
fetch_by_ctrled_analysis_id
{
my
(
$self
,
$id
)
=
@_
;
unless
(
defined
$id
)
{
$self
->
throw
("
fetch_by_ctrled_analysis_id must have an id
");
}
my
$constraint
=
"
r.ctrled_analysis_id =
$id
";
return
$self
->
_generic_fetch
();
}
=head2 fetch_all
Arg : None
Example :
Description:
Returntype :
Exceptions :
Caller :
=cut
sub
fetch_all
{
my
$self
=
shift
;
return
$self
->
_generic_fetch
();
}
=head2 store
Title : store
Usage : $self->store( $rule );
Function: Stores a rule in db
Sets adaptor and dbID in AnalysisCtrlRule
Returns : -
Args : Bio::EnsEMBL::Hive::AnalysisCtrlRule
=cut
sub
store
{
my
(
$self
,
$rule
)
=
@_
;
#print("\nAnalysisCtrlRuleAdaptor->store()\n");
my
$sth
=
$self
->
prepare
(
q{INSERT ignore INTO analysis_ctrl_rule
SET ctrled_analysis_id = ?, condition_analysis_url = '?' }
);
if
(
$sth
->
execute
(
$rule
->
ctrled_analysis_id
,
$rule
->
condition_analysis_url
))
{
$sth
->
finish
();
}
$rule
->
adaptor
(
$self
);
}
=head2 remove
Title : remove
Usage : $self->remove( $rule );
Function: removes given object from database.
Returns : -
Args : Bio::EnsEMBL::Hive::AnalysisCtrlRule which must be persistent.
( dbID set )
=cut
sub
remove
{
my
(
$self
,
$rule
)
=
@_
;
my
$dbID
=
$rule
->
dbID
;
if
(
!
defined
$dbID
)
{
$self
->
throw
(
"
AnalysisCtrlRuleAdaptor->remove called with non persistent AnalysisCtrlRule
"
);
}
my
$sth
=
$self
->
prepare
("
DELETE FROM analysis_ctrl_rule WHERE ctrled_analysis_id = ?, condition_analysis_url = '?'
");
$sth
->
execute
(
$rule
->
ctrled_analysis_id
,
$rule
->
condition_analysis_url
);
}
sub
create_rule
{
my
(
$self
,
$conditionAnalysis
,
$ctrledAnalysis
)
=
@_
;
return
unless
(
$conditionAnalysis
and
$ctrledAnalysis
);
my
$rule
=
Bio::EnsEMBL::Hive::
AnalysisCtrlRule
->
new
();
$rule
->
condition_analysis
(
$conditionAnalysis
);
$rule
->
ctrled_analysis
(
$ctrledAnalysis
);
$self
->
store
(
$rule
);
}
############################
#
# INTERNAL METHODS
# (pseudo subclass methods)
#
############################
#internal method used in multiple calls above to build objects from table data
sub
_tables
{
my
$self
=
shift
;
return
(['
analysis_ctrl_rule
',
'
r
']);
}
sub
_columns
{
my
$self
=
shift
;
return
qw (r.ctrled_analysis_id
r
.
condition_analysis_url
);
}
sub
_objs_from_sth
{
my
(
$self
,
$sth
)
=
@_
;
my
@rules
=
();
my
(
$ctrled_analysis_id
,
$condition_analysis_url
);
$sth
->
bind_columns
(
\
$ctrled_analysis_id
,
\
$condition_analysis_url
);
while
(
$sth
->
fetch
())
{
my
$rule
=
Bio::EnsEMBL::Hive::
AnalysisCtrlRule
->
new
;
$rule
->
adaptor
(
$self
);
$rule
->
ctrled_analysis_id
(
$ctrled_analysis_id
);
$rule
->
condition_analysis_url
(
$condition_analysis_url
);
push
@rules
,
$rule
;
}
return
\
@rules
;
}
sub
_default_where_clause
{
my
$self
=
shift
;
return
'';
}
sub
_final_clause
{
my
$self
=
shift
;
return
'';
}
###############################################################################
#
# General access methods that could be moved
# into a superclass
#
###############################################################################
=head2 _generic_fetch
Arg [1] : (optional) string $constraint
An SQL query constraint (i.e. part of the WHERE clause)
Arg [2] : (optional) string $logic_name
the logic_name of the analysis of the features to obtain
Example : $fts = $a->_generic_fetch('contig_id in (1234, 1235)', 'Swall');
Description: Performs a database fetch and returns feature objects in
contig coordinates.
Returntype : listref of Bio::EnsEMBL::Hive::AnalysisCtrlRule
Exceptions : none
=cut
sub
_generic_fetch
{
my
(
$self
,
$constraint
,
$join
)
=
@_
;
my
@tables
=
$self
->
_tables
;
my
$columns
=
join
('
,
',
$self
->
_columns
());
if
(
$join
)
{
foreach
my
$single_join
(
@
{
$join
})
{
my
(
$tablename
,
$condition
,
$extra_columns
)
=
@
{
$single_join
};
if
(
$tablename
&&
$condition
)
{
push
@tables
,
$tablename
;
if
(
$constraint
)
{
$constraint
.=
"
AND
$condition
";
}
else
{
$constraint
=
"
$condition
";
}
}
if
(
$extra_columns
)
{
$columns
.=
"
,
"
.
join
('
,
',
@
{
$extra_columns
});
}
}
}
#construct a nice table string like 'table1 t1, table2 t2'
my
$tablenames
=
join
('
,
',
map
({
join
('
',
@
$_
)
}
@tables
));
my
$sql
=
"
SELECT
$columns
FROM
$tablenames
";
my
$default_where
=
$self
->
_default_where_clause
;
my
$final_clause
=
$self
->
_final_clause
;
#append a where clause if it was defined
if
(
$constraint
)
{
$sql
.=
"
WHERE
$constraint
";
if
(
$default_where
)
{
$sql
.=
"
AND
$default_where
";
}
}
elsif
(
$default_where
)
{
$sql
.=
"
WHERE
$default_where
";
}
#append additional clauses which may have been defined
$sql
.=
"
$final_clause
";
my
$sth
=
$self
->
prepare
(
$sql
);
$sth
->
execute
;
# print STDERR $sql,"\n";
return
$self
->
_objs_from_sth
(
$sth
);
}
1
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment