Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Richness estimation 2024 #918

Merged
merged 22 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4537f52
optimise RichnessEstimation.pm
shawnlaffan Feb 14, 2024
e626399
RichnessEstimation.pm: fold two loops together
shawnlaffan Feb 14, 2024
83d2016
RichnessEstimation.pm: unify the ACE and ICE variance methods
shawnlaffan Feb 14, 2024
5a49b7d
RichnessEstimation.pm: iterate over arrays in ACE/ICE variance
shawnlaffan Feb 14, 2024
147cd47
RichnessEstimation.pm: reduce the _get_ace_ice_cov argument burden
shawnlaffan Feb 14, 2024
63036f1
RichnessEstimation.pm: add array args variant of _get_ace_ice_cov
shawnlaffan Feb 14, 2024
289448a
RichnessEstimation.pm: use grep to avoid some calcs, and refalias a hash
shawnlaffan Feb 14, 2024
4ec59a8
Indices::calc_nonempty_elements_used: make direct use of element list…
shawnlaffan Feb 14, 2024
d67b246
Add Faster::Maths to Makefile.PL and cpanfile
shawnlaffan Feb 14, 2024
499eccc
Indices: ace_differential: Refactor the coverage estimate
shawnlaffan Feb 19, 2024
0cdef07
Indices: ace_differential: Refactor ($n_rare - 1)
shawnlaffan Feb 19, 2024
8e77c16
Indices: ice_differential: Refactor ($t - 1)
shawnlaffan Feb 19, 2024
0f84deb
Indices: ice_differential: Refactor ($n_infreq - 1)
shawnlaffan Feb 19, 2024
e964fdd
GUI legend: handle non-sequential categorical classes
shawnlaffan Feb 20, 2024
b9ec589
RichnessEstimation.pm: metadata indices are categorical
shawnlaffan Feb 20, 2024
78f80d4
Categorical indices: update test expectations
shawnlaffan Feb 20, 2024
4faa269
Refactor colour palettes into a Common:: subpackage.
shawnlaffan Feb 20, 2024
47c79f0
Colour palettes: generalise names, add more palettes
shawnlaffan Feb 20, 2024
fbef787
RichnessEstimation.pm: use modified method names for palettes
shawnlaffan Feb 20, 2024
102fd12
Formatting
shawnlaffan Feb 20, 2024
527511f
Remove non-needed module loads, mostly Readonly and Carp
shawnlaffan Feb 20, 2024
18232bd
Add version to ColourPalettes.pm
shawnlaffan Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use ExtUtils::MakeMaker;
# these are from the cpanfile
# need to look at https://metacpan.org/pod/ExtUtils::MakeMaker::CPANfile
my %common_reqs = (
"Class::Inspector" => 0,
"Clone" => "0.35",
"Cpanel::JSON::XS" => "3",
"Class::Inspector" => 0,
"Clone" => "0.35",
"Cpanel::JSON::XS" => "3",
"Data::Structure::Util" => 0,
"Data::Compare" => 0,
"Exception::Class" => 0,
"Exporter::Easy" => 0,
"Data::Compare" => 0,
"Exception::Class" => 0,
"Exporter::Easy" => 0,
"Faster::Maths" => 0,
"File::BOM" => 0,
"File::Find::Rule" => 0,
"Geo::Converter::dms2dd" => "0.05",
Expand Down
3 changes: 2 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ requires "Excel::ValueReader::XLSX";
requires "Exception::Class";
requires "Exporter::Easy";
#requires "FFI::Platypus::Declare";
requires "Faster::Maths";
requires "File::BOM";
requires "File::Find::Rule";
requires "Geo::Converter::dms2dd", "0.05";
Expand Down Expand Up @@ -49,7 +50,7 @@ requires "rlib";
#requires "Math::AnyNum"; # until we don't
requires "Statistics::Descriptive::PDL", "0.15";

suggests "Panda::Lib";
# suggests "Panda::Lib";
suggests "Data::Recursive";

#test_requires => sub {
Expand Down
91 changes: 91 additions & 0 deletions lib/Biodiverse/Common/ColourPalettes.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package Biodiverse::Common::ColourPalettes;
use strict;
use warnings;

our $VERSION = '4.99_002';

# A set of colour palettes.
# Add to as needed.

sub get_palette_colorbrewer_paired {
# Paired colour scheme from colorbrewer, plus a dark grey
# note - this works poorly when 9 or fewer groups are selected
no warnings 'qw'; # we know the hashes are not comments
my @palette = (
'#A6CEE3', '#1F78B4', '#B2DF8A', '#33A02C',
'#FB9A99', '#E31A1C', '#FDBF6F', '#FF7F00',
'#CAB2D6', '#6A3D9A', '#FFFF99', '#B15928',
'#4B4B4B',
);
return wantarray ? @palette : [@palette];
}

sub get_palette_colorbrewer_set1 {
# 9 class colour scheme from www.colorbrewer2.org
my @palette = (
'#E41A1C', '#377EB8', '#4DAF4A', '#984EA3',
'#FF7F00', '#FFFF33', '#A65628', '#F781BF',
'#999999',
);
return wantarray ? @palette : [@palette];
}

sub get_palette_colorbrewer_set2 {
# 8 class colour scheme from www.colorbrewer2.org
my @palette = (
'#66c2a5', '#fc8d62', '#8da0cb', '#e78ac3',
'#a6d854', '#ffd92f', '#e5c494', '#b3b3b3',
);
return wantarray ? @palette : [@palette];
}

sub get_palette_colorbrewer_set3 {
# 12 class colour scheme from www.colorbrewer2.org
my @palette = (
'#8dd3c7', '#ffffb3', '#bebada', '#fb8072',
'#80b1d3', '#fdb462', '#b3de69', '#fccde5',
'#d9d9d9', '#bc80bd', '#ccebc5', '#ffed6f',
);
return wantarray ? @palette : [@palette];
}

sub get_palette_colorbrewer_pastel1 {
# 9 class colour scheme from www.colorbrewer2.org
my @palette = (
'#fbb4ae', '#b3cde3', '#ccebc5', '#decbe4',
'#fed9a6', '#ffffcc', '#e5d8bd', '#fddaec',
'#f2f2f2'
);
return wantarray ? @palette : [@palette];
}

sub get_palette_colorbrewer_pastel2 {
# 8 class colour scheme from www.colorbrewer2.org
my @palette = (
'#b3e2cd', '#fdcdac', '#cbd5e8', '#f4cae4',
'#e6f5c9', '#fff2ae', '#f1e2cc', '#cccccc'
);
return wantarray ? @palette : [@palette];
}

sub get_palette_colorbrewer_accent {
# 8 class colour scheme from www.colorbrewer2.org
my @palette = (
'#7fc97f', '#beaed4', '#fdc086', '#ffff99',
'#386cb0', '#f0027f', '#bf5b17', '#666666'
);
return wantarray ? @palette : [@palette];
}

sub get_palette_colorbrewer_dark2 {
# 8 class colour scheme from www.colorbrewer2.org
my @palette = (
'#1b9e77', '#d95f02', '#7570b3', '#e7298a',
'#66a61e', '#e6ab02', '#a6761d', '#666666',
);
return wantarray ? @palette : [@palette];
}



1;
1 change: 0 additions & 1 deletion lib/Biodiverse/GUI/GUIManager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use Carp;
use Scalar::Util qw /blessed/;

use English ( -no_match_vars );
use Readonly;

use FindBin qw ( $Bin );
use Path::Tiny qw /path/;
Expand Down
6 changes: 4 additions & 2 deletions lib/Biodiverse/GUI/Legend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ sub make_rect {
my $label_hash = $self->{categorical}{labels};

my $n = (scalar keys %$label_hash) - 1;
my @classes = sort {$a <=> $b} keys %$label_hash;
$n = $#classes;
foreach my $row (0..($height - 1)) {
# cat 0 at the top
my $class = $n - int (0.5 + $n * $row / ($height - 1));
my $colour = $self->get_colour_categorical ($class);
my $class_iter = $n - int (0.5 + $n * $row / ($height - 1));
my $colour = $self->get_colour_categorical ($classes[$class_iter]);
$self->add_row($self->{legend_colours_group}, $row, $colour);
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/Biodiverse/GUI/Manager/BaseDatas.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use Carp;
use Scalar::Util qw /blessed/;

use English ( -no_match_vars );
use Readonly;

use FindBin qw ( $Bin );
use Text::Wrapper;
Expand Down
1 change: 0 additions & 1 deletion lib/Biodiverse/GUI/Tabs/CalculationsTree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use Text::Wrapper;

our $VERSION = '4.99_002';

#use Readonly;
my $i;
use constant MODEL_NAME_COL => $i || 0;
use constant MODEL_INDEX_COL => ++$i;
Expand Down
31 changes: 11 additions & 20 deletions lib/Biodiverse/Indices/Indices.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ sub calc_richness { # calculate the aggregate richness for a set of elements
my $self = shift;
my %args = @_; # rest of args into a hash

my %results = (RICHNESS_ALL => $args{ABC},
RICHNESS_SET1 => $args{A} + $args{B},
RICHNESS_SET2 => $args{A} + $args{C},
);
my %results = (
RICHNESS_ALL => $args{ABC},
RICHNESS_SET1 => $args{A} + $args{B},
RICHNESS_SET2 => $args{A} + $args{C},
);

return wantarray
? (%results)
: \%results;
return wantarray ? %results : \%results;
}

sub get_metadata_calc_redundancy {
Expand Down Expand Up @@ -1518,7 +1517,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 +1546,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
Loading
Loading