Skip to content

Commit

Permalink
Added ROBO criteria validation to the can_run method
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcam committed Aug 8, 2024
1 parent 54cb353 commit 7b828bb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LIST OF CHANGES FOR NPG-QC PACKAGE
{r,R}unParameters.xml), added an optional 'runfolder_path' attribute.
The attribute will have to be set by the caller.
2. Added a new applicability criteria type - 'sequencing_run'
3. To avoid running the reviewcheck unnecessary in the pipeline context,
moved ROBO criteria validation to the can_run method.

release 72.1.2 (2024-08-05)
- handle cases where the same tag sequence is seen in both index reads
Expand Down
48 changes: 31 additions & 17 deletions lib/npg_qc/autoqc/checks/review.pm
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,22 @@ for this product exists.

sub can_run {
my $self = shift;
(keys %{$self->_robo_config()}) and return 1;
$self->result->add_comment(
'Product configuration for RoboQC is absent');
return 0;
if (!keys %{$self->_robo_config}) {
$self->result->add_comment('Product configuration for RoboQC is absent');
return 0;
}
my $num_criteria;
try {
$num_criteria = @{$self->_applicable_criteria};
} catch {
$self->result->add_comment("Error validating RoboQC criteria: $_");
};
if (!$num_criteria) {
$self->result->add_comment('None of the applicability criteria is satisfied');
return 0;
}

return 1;
}

=head2 execute
Expand Down Expand Up @@ -476,9 +488,15 @@ sub _validate_criteria {
return;
}

sub _applicability_all {
my ($self, $criteria_objs) = @_;
has '_applicable_criteria' => (
isa => 'ArrayRef',
is => 'ro',
lazy_build => 1,
);
sub _build__applicable_criteria {
my $self = shift;

my $criteria_objs = $self->_robo_config->{$CRITERIA_KEY};
my @applicable = ();
foreach my $co ( @{$criteria_objs} ) {
my $c_applicable = 1;
Expand Down Expand Up @@ -538,23 +556,19 @@ sub _build__criteria {
$lib_type or croak 'Library type is not defined for ' . $self->_entity_desc;
$self->result->library_type($lib_type);

my $criteria_objs = $self->_robo_config->{$CRITERIA_KEY};
$criteria_objs = $self->_applicability_all($criteria_objs);
# Criteria objects with no lims criteria defined should be returned
# in the above array. An empty array means that all objects had lims
# criteria and none of them was satisfied.
@{$criteria_objs} or return {};

(@{$criteria_objs} == 1) or carp 'Multiple criteria sets are satisfied ' .
'in a robo config for ' . $self->_entity_desc;

my $num_criteria = scalar @{$self->_applicable_criteria};
if ($num_criteria == 0) {
return {};
} elsif ($num_criteria > 1) {
croak 'Multiple criteria sets are satisfied in a robo config';
}
#####
# A very simple criteria format - a list of strings - is used for now.
# Each string represents a math expression. It is assumed that the
# conjunction operator should be used to form the boolean expression
# that should give the result of the evaluation.
#
my @c = uniq sort @{$criteria_objs->[0]->{$ACCEPTANCE_CRITERIA_KEY}};
my @c = uniq sort @{$self->_applicable_criteria->[0]->{$ACCEPTANCE_CRITERIA_KEY}};

return @c ? {$CONJUNCTION_OP => \@c} : {};
}
Expand Down
9 changes: 5 additions & 4 deletions t/60-autoqc-checks-review.t
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ subtest 'constructing object, deciding whether to run' => sub {
conf_path => "$test_data_dir/with_na_criteria",
qc_in => $test_data_dir,
rpt_list => '27483:1:2');
ok ($check->can_run, 'can_run returns true');
ok (!$check->result->comments, 'No comments logged');
ok (!$check->can_run, 'can_run returns false');
is ($check->result->comments, 'None of the applicability criteria is satisfied',
'Comment logged');
};

subtest 'caching appropriate criteria object' => sub {
Expand Down Expand Up @@ -195,7 +196,7 @@ subtest 'execute when no criteria apply' => sub {
lives_ok { $check->execute }
'no error in execute when no criteria apply';
my $result = $check->result;
is ($result->comments, 'RoboQC is not applicable',
is ($result->comments, 'None of the applicability criteria is satisfied',
'correct comment logged');
is_deeply ($result->criteria, {}, 'empty criteria hash');
is_deeply ($result->qc_outcome, {}, 'empty qc_outcome hash');
Expand Down Expand Up @@ -413,7 +414,7 @@ subtest 'evaluation within the execute method' => sub {
qc_in => $dir,
rpt_list => $rpt_list
);
ok ($o->can_run, 'the check can be run');
ok (!$o->can_run, 'the check cannot be run');
is_deeply($o->_criteria, {}, 'no criteria to evaluate');
lives_ok { $o->execute } 'execute method runs OK';
is ($o->result->pass, undef, 'result pass attribute is unset');
Expand Down

0 comments on commit 7b828bb

Please sign in to comment.