Skip to content

Commit

Permalink
Indices::calc_nonempty_elements_used: make direct use of element list…
Browse files Browse the repository at this point in the history
… args

No need to pass them through calc_abc first.
  • Loading branch information
shawnlaffan committed Feb 14, 2024
1 parent 289448a commit 4ec59a8
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions lib/Biodiverse/Indices/Indices.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,6 @@ sub get_metadata_calc_nonempty_elements_used {
name => 'Non-empty element counts',
description => "Counts of non-empty elements in neighbour sets 1 and 2.\n",
type => 'Lists and Counts',
pre_calc => 'calc_abc',
uses_nbr_lists => 1, # how many sets of lists it must have
indices => {
EL_COUNT_NONEMPTY_SET1 => {
Expand Down Expand Up @@ -1548,24 +1547,17 @@ sub calc_nonempty_elements_used {
# should run a precalc_gobal to check if the
# basedata has empty groups as then we can shortcut
my $bd = $self->get_basedata_ref;
my $list = $args{element_list_all};

my %nonempty;
foreach my $gp (@$list) {
my $ref = $bd->get_labels_in_group_as_hash (group => $gp);
next if !scalar keys %$ref;
$nonempty{$gp}++;
}
my $non_empty_all = scalar keys %nonempty;
my $non_empty_set1 = grep {exists $nonempty{$_}} keys %{$args{element_list1} // {}};
my $non_empty_set2 = $args{element_list2}
? grep {exists $nonempty{$_}} keys %{$args{element_list2}}
my $non_empty_set1 = grep {$bd->get_richness_aa($_)} @{$args{element_list1} // []};
my $non_empty_set2
= $args{element_list2}
? grep {$bd->get_richness_aa($_)} @{$args{element_list2}}
: undef;

my %results = (
EL_COUNT_NONEMPTY_SET1 => $non_empty_set1,
EL_COUNT_NONEMPTY_SET2 => $non_empty_set2,
EL_COUNT_NONEMPTY_ALL => $non_empty_all,
EL_COUNT_NONEMPTY_ALL => $non_empty_set1 + ($non_empty_set2 // 0),
);

return wantarray ? %results : \%results;
Expand Down

0 comments on commit 4ec59a8

Please sign in to comment.