Skip to content

Commit

Permalink
Add code to check validity of CANAPE calcs
Browse files Browse the repository at this point in the history
And minor refactor of the spatial code

Updates #819
  • Loading branch information
shawnlaffan committed Sep 9, 2022
1 parent adccff9 commit 0bd3412
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 10 additions & 0 deletions lib/Biodiverse/Common.pm
Expand Up @@ -2483,6 +2483,16 @@ sub compare_lists_by_item {
return $results;
}
sub check_canape_protocol_is_valid {
my $self = shift;
# argh the hard coding of index names...
my $analysis_args = $self->get_param('SP_CALC_ARGS') || $self->get_param('ANALYSIS_ARGS');
my $valid_calcs = $analysis_args->{calculations} // $analysis_args->{spatial_calculations} // [];
my %vk;
@vk{@$valid_calcs} = (1) x @$valid_calcs;
return $vk{calc_phylo_rpe2} && $vk{calc_pe};
}

sub assign_canape_codes_from_p_rank_results {
my $self = shift;
Expand Down
11 changes: 6 additions & 5 deletions lib/Biodiverse/Spatial.pm
Expand Up @@ -193,7 +193,8 @@ sub calculate_canape {
return 1 if not scalar @$e_list;

# check if we have the relevant calcs here

return if !$self->check_canape_protocol_is_valid;

my $progress = Biodiverse::Progress->new();
my $progress_text = "Calculating Canape";
$progress->update ($progress_text, 0);
Expand Down Expand Up @@ -225,7 +226,9 @@ sub calculate_canape {
}
}

my $list_name = 'SPATIAL_RESULTS';
my $list_name = 'SPATIAL_RESULTS';
my $p_rank_list_name = $result_list_pfx . '>>p_rank>>' . $list_name;
my $result_list_name = $result_list_pfx . '>>CANAPE>>';

COMP_BY_ELEMENT:
foreach my $element ($self->get_element_list) {
Expand Down Expand Up @@ -255,12 +258,10 @@ sub calculate_canape {

my $p_rank_list_ref = $self->get_list_ref (
element => $element,
list => $result_list_pfx . '>>p_rank>>' . $list_name,
list => $p_rank_list_name,
autovivify => 0,
);

my $result_list_name = $result_list_pfx . '>>CANAPE';

my $result_list_ref = $self->get_list_ref (
element => $element,
list => $result_list_name,
Expand Down

0 comments on commit 0bd3412

Please sign in to comment.