Skip to content

Commit 9fcafcd

Browse files
authored
Merge pull request #1044 from shawnlaffan/sp_label_ancestor_range
spatial conditions: sp_in_label_ancestor_range
2 parents c316647 + 29081c4 commit 9fcafcd

File tree

9 files changed

+598
-100
lines changed

9 files changed

+598
-100
lines changed

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
- uses: shogo82148/actions-setup-perl@v1
2222
with:
23-
perl-version: "5.38"
23+
perl-version: "5.38.2"
2424
distribution: strawberry
2525
install-modules-with: cpanm
2626
install-modules-args: --with-develop --with-configure --verbose

lib/Biodiverse/BaseData.pm

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,17 +2717,8 @@ sub get_outputs_with_same_spatial_conditions {
27172717
|| croak "[BASEDATA] compare_with argument not specified\n";
27182718

27192719
my $sp_params = $compare->get_spatial_conditions;
2720-
my $def_query = $compare->get_def_query;
2721-
if ( defined $def_query && ( length $def_query ) == 0 ) {
2722-
$def_query = undef;
2723-
}
27242720

2725-
my $def_conditions;
2726-
if ( blessed $def_query) {
2727-
$def_conditions = $def_query->get_conditions_unparsed();
2728-
}
2729-
2730-
my @outputs = $self->get_output_refs_of_class( class => $compare );
2721+
my @outputs = $self->get_outputs_with_same_def_query (%args);
27312722

27322723
my @comparable_outputs;
27332724

@@ -2738,25 +2729,6 @@ sub get_outputs_with_same_spatial_conditions {
27382729
my $completed = $output->get_param('COMPLETED');
27392730
next LOOP_OUTPUTS if defined $completed and !$completed;
27402731

2741-
my $def_query_comp = $output->get_def_query;
2742-
if ( defined $def_query_comp && ( length $def_query_comp ) == 0 ) {
2743-
$def_query_comp = undef;
2744-
}
2745-
2746-
next LOOP_OUTPUTS
2747-
if ( defined $def_query ) ne ( defined $def_query_comp );
2748-
2749-
if ( defined $def_query ) {
2750-
2751-
# check their def queries match
2752-
my $def_conditions_comp =
2753-
eval { $def_query_comp->get_conditions_unparsed() }
2754-
// $def_query_comp;
2755-
my $def_conditions_text =
2756-
eval { $def_query->get_conditions_unparsed() } // $def_query;
2757-
next LOOP_OUTPUTS if $def_conditions_comp ne $def_conditions_text;
2758-
}
2759-
27602732
my $sp_params_comp = $output->get_spatial_conditions || [];
27612733

27622734
# must have same number of conditions
@@ -2767,6 +2739,12 @@ sub get_outputs_with_same_spatial_conditions {
27672739
next LOOP_OUTPUTS
27682740
if ( $sp_params->[$i]->get_param('CONDITIONS') ne
27692741
$sp_obj->get_conditions_unparsed() );
2742+
2743+
my $tree_ref = $sp_params->[$i]->get_tree_ref;
2744+
my $tree_ref_comp = $sp_obj->get_tree_ref;
2745+
next LOOP_OUTPUTS
2746+
if ($tree_ref // '') ne ($tree_ref_comp // '');
2747+
27702748
$i++;
27712749
}
27722750

@@ -2790,8 +2768,10 @@ sub get_outputs_with_same_def_query {
27902768
}
27912769

27922770
my $def_conditions;
2771+
my $tree_ref;
27932772
if ( blessed $def_query) {
27942773
$def_conditions = $def_query->get_conditions_unparsed();
2774+
$tree_ref = $def_query->get_tree_ref;
27952775
}
27962776

27972777
# could be more general with def queries
@@ -2828,6 +2808,9 @@ sub get_outputs_with_same_def_query {
28282808
my $def_conditions_text =
28292809
eval { $def_query->get_conditions_unparsed() } // $def_query;
28302810
next LOOP_OUTPUTS if $def_conditions_comp ne $def_conditions_text;
2811+
2812+
my $tree_ref_comp = $def_query_comp->get_tree_ref;
2813+
next LOOP_OUTPUTS if ($tree_ref // '') ne ($tree_ref_comp // '');
28312814
}
28322815

28332816
# if we get this far then we have a match

lib/Biodiverse/GUI/SpatialParams.pm

Lines changed: 100 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ sub new {
7676
$options_button->signal_connect_swapped(clicked => \&run_options_dialogue, $self);
7777
$options_button->set_tooltip_text('Control some of the processing options');
7878

79+
my $tree_combo = $self->update_dendrogram_combo;
80+
$tree_combo->show_all;
81+
7982
# Scrolled window for multi-line conditions
8083
my $scroll = Gtk3::ScrolledWindow->new;
8184
$scroll->set_policy('automatic', 'automatic');
@@ -86,16 +89,23 @@ sub new {
8689
my $frame = Gtk3::Frame->new();
8790
$frame->add($text_view_no_scroll);
8891

89-
my $hideable_widgets = [$scroll, $frame, $options_button, $syntax_button];
92+
my $hideable_widgets = [
93+
$scroll, $frame,
94+
$tree_combo,
95+
$options_button, $syntax_button,
96+
];
9097

9198
# HBox
9299
$hbox->pack_start($expander, 0, 0, 0);
93100
$hbox->pack_start($scroll, 1, 1, 0);
94101
$hbox->pack_start($frame, 1, 1, 0);
102+
$hbox->pack_start($tree_combo, 0, 1, 0);
95103
$hbox->pack_start($options_button, 0, 0, 0);
96104
$hbox->pack_end($syntax_button, 0, 0, 0);
97105
$hbox->show_all();
98106

107+
$self->{tree_combo} = $tree_combo;
108+
99109
my $cb_text_buffer = sub {
100110
if ($text_buffer->get_line_count > 1) {
101111
$scroll->show;
@@ -118,31 +128,33 @@ sub new {
118128

119129

120130
my $expander_cb = sub {
121-
my $expand = !$expander->get_expanded;
122-
my $method = $expand ? 'show' : 'hide';
131+
my $visible = !$expander->get_expanded;
123132
foreach my $widget (@$hideable_widgets) {
124-
if (not $widget =~ 'Button' and not $widget =~ $self->{current_text_view}) {
133+
if (not $widget =~ 'Button|ComboBox' and not $widget =~ $self->{current_text_view}) {
125134
$widget->hide; # hide the inactive textview regardless
126135
}
127136
else {
128-
$widget->$method;
137+
$widget->set_visible($visible);
129138
}
130139
}
131140
};
132-
$expander->set_tooltip_text ('Show or hide the edit and verify boxes. Use this to free up some screen real estate.');
141+
$expander->set_tooltip_text (
142+
'Show or hide the edit box and other widgets. '
143+
. 'Use this to free up some screen real estate.'
144+
);
133145
$expander->signal_connect_swapped (
134146
activate => $expander_cb,
135147
$self,
136148
);
137149
$expander->set_expanded(!$start_hidden);
138150

139-
my $method = $start_hidden ? 'hide' : 'show';
151+
my $visible = !$start_hidden;
140152
foreach my $widget (@$hideable_widgets) {
141-
if (not $widget =~ 'Button' and not $widget =~ $self->{current_text_view}) {
153+
if (not $widget =~ 'Button|ComboBox' and not $widget =~ $self->{current_text_view}) {
142154
$widget->hide; # hide the inactive textview regardless
143155
}
144156
else {
145-
$widget->$method;
157+
$widget->set_visible($visible);
146158
}
147159
}
148160

@@ -176,6 +188,7 @@ sub on_syntax_check {
176188
conditions => $expr,
177189
basedata_ref => $bd,
178190
promise_current_label => $self->{promise_current_label},
191+
tree_ref => $self->get_tree_ref,
179192
);
180193
};
181194
#croak $EVAL_ERROR if $EVAL_ERROR;
@@ -206,7 +219,8 @@ sub get_validated_conditions {
206219
my $self = shift;
207220

208221
my $conditions = $self->{validated_conditions};
209-
croak "Conditions not yet validated\n" if !defined $conditions;
222+
return if !defined $conditions;
223+
# croak "Conditions not yet validated\n" if !defined $conditions;
210224

211225
my $options = $self->get_options;
212226
$conditions->set_no_recycling_flag ($options->{no_recycling});
@@ -215,6 +229,26 @@ sub get_validated_conditions {
215229
return $conditions;
216230
}
217231

232+
sub get_tree_ref {
233+
my $self = shift;
234+
235+
my $combo = $self->{tree_combo};
236+
return if !$combo;
237+
238+
my $iter = $combo->get_active_iter;
239+
my $tree_ref = $iter ? $combo->get_model->get($iter, 1) : undef;
240+
241+
if ($tree_ref eq 'no tree') {
242+
$tree_ref = undef;
243+
}
244+
elsif ($tree_ref eq 'project') {
245+
my $gui = Biodiverse::GUI::GUIManager->instance;
246+
$tree_ref = $gui->get_project->get_selected_phylogeny;
247+
}
248+
249+
return $tree_ref;
250+
}
251+
218252
sub get_object {
219253
my $self = shift;
220254
return $self->{hbox};
@@ -314,6 +348,62 @@ sub get_options {
314348
return wantarray ? %$options : $options;
315349
}
316350

351+
sub update_dendrogram_combo {
352+
my $self = shift;
353+
354+
my $combobox = Gtk3::ComboBox->new;
355+
356+
my $renderer_text = Gtk3::CellRendererText->new();
357+
$combobox->pack_start($renderer_text, 1);
358+
$combobox->add_attribute($renderer_text, "text", 0);
359+
360+
# Clear the current entries.
361+
# We need to load a new ListStore to avoid crashes due
362+
# to them being destroyed somewhere in the refresh process
363+
# (Not sure that is still the case)
364+
my $model = Gtk3::ListStore->new('Glib::String', 'Glib::Scalar');
365+
366+
my @combo_items;
367+
368+
my $output_ref = eval {$self->get_validated_conditions};
369+
if ($output_ref && $output_ref->can('get_tree_ref') && $output_ref->get_tree_ref) {
370+
my $iter = $model->append();
371+
$model->set( $iter, 0 => 'analysis', 1 => $output_ref->get_tree_ref);
372+
push @combo_items, 'analysis';
373+
}
374+
375+
foreach my $option ('no tree', 'project') {
376+
my $iter = $model->append();
377+
$model->set( $iter, 0 => $option, 1 => $option );
378+
push @combo_items, $option;
379+
}
380+
381+
my $list = Biodiverse::GUI::GUIManager->instance->get_project->get_phylogeny_list;
382+
foreach my $tree (@$list) {
383+
my $name = $tree->get_name;
384+
my $iter = $model->append();
385+
$model->set( $iter, 0 => $name, 1 => $tree );
386+
}
387+
388+
$combobox->set_model ($model);
389+
390+
state $tooltip = <<~'EOT';
391+
Choose the tree to use in the spatial conditions.
392+
393+
The remainder of the options are the trees available at
394+
the project level. Note that this set is not updated as
395+
trees are added to and removed from the project.
396+
Changes can be triggered by closing and reopening the tab.
397+
EOT
398+
;
399+
400+
$combobox->set_tooltip_text ($tooltip);
401+
$combobox->set_active(0);
402+
# $combobox->show_all;
403+
404+
return $combobox;
405+
}
406+
317407

318408
1;
319409

lib/Biodiverse/Metadata/SpatialConditions.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ my %methods_and_defaults = (
2323
use_cell_distances => [],
2424
use_abs_cell_distances => [],
2525
is_volatile_cb => sub{},
26+
requires_tree_ref => undef,
2627
);
2728

2829
sub _get_method_default_hash {

lib/Biodiverse/SpatialConditions.pm

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ sub new {
8787
KEEP_LAST_DISTANCES => $args{keep_last_distances},
8888
);
8989
$self->set_promise_current_label($args{promise_current_label});
90+
$self->set_tree_ref($args{tree_ref});
9091

9192
eval {$self->parse_distances};
9293
croak $EVAL_ERROR if $EVAL_ERROR;
@@ -109,6 +110,20 @@ sub get_metadata {
109110
return $self->SUPER::get_metadata (@_, no_use_cache => 1);
110111
}
111112

113+
sub get_tree_ref {
114+
my ($self) = @_;
115+
$self->get_param('TREE_REF');
116+
}
117+
118+
sub set_tree_ref {
119+
my ($self, $tree_ref) = @_;
120+
if (my $old_tree = $self->get_tree_ref) {
121+
$self->delete_cached_values
122+
if ref $tree_ref ne ref $old_tree;
123+
}
124+
$self->set_param(TREE_REF => $tree_ref);
125+
}
126+
112127
sub get_conditions {
113128
my $self = shift;
114129
my %args = @_;
@@ -194,6 +209,17 @@ sub set_promise_current_label {
194209
return $self->{promise_current_label} = $promise;
195210
}
196211

212+
sub get_requires_tree_ref {
213+
my ($self) = @_;
214+
return $self->{requires_tree_ref};
215+
}
216+
217+
sub set_requires_tree_ref {
218+
my ($self, $bool) = @_;
219+
return $self->{requires_tree_ref} = $bool;
220+
}
221+
222+
197223
sub get_used_dists {
198224
my $self = shift;
199225
return $self->get_param('USES');
@@ -291,7 +317,10 @@ sub parse_distances {
291317
my $re_sub_names_text = '\b(?:' . join( q{|}, @subs_to_check ) . ')\b';
292318
my $re_sub_names = qr /$re_sub_names_text/xsm;
293319
my $is_volatile;
294-
320+
321+
# maybe the user calls this in the condition somewhere
322+
my $requires_tree_ref = $conditions =~ /\$self\s*\-\>\s*get_tree_ref\b/;
323+
295324
my %shape_hash;
296325

297326
my $str_len = length $conditions;
@@ -387,6 +416,8 @@ sub parse_distances {
387416
$is_volatile ||= $self->$cb(%hash_1);
388417
}
389418

419+
$requires_tree_ref ||= $metadata->get_requires_tree_ref;
420+
390421
# REALLY BAD CODE - does not allow for other
391422
# functions and operators
392423
$results_types .= ' ' . $metadata->get_result_type;
@@ -427,6 +458,12 @@ sub parse_distances {
427458
$self->set_param( USES => \%uses_distances );
428459
$self->set_param( SHAPE_TYPES => join ' ', sort keys %shape_hash);
429460
$self->set_volatile_flag($is_volatile);
461+
$self->set_requires_tree_ref($requires_tree_ref);
462+
463+
if (!$requires_tree_ref) {
464+
# clear the tree if we do not need it
465+
$self->set_tree_ref(undef);
466+
}
430467

431468
# do we need to calculate the distances? NEEDS A BIT MORE THOUGHT
432469
$self->set_param( CALC_DISTANCES => undef );

0 commit comments

Comments
 (0)