This file is indexed.

/usr/share/perl5/Bio/Tree/Compatible.pm is in libbio-perl-perl 1.6.924-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#
# BioPerl module for Bio::Tree::Compatible
#
# Please direct questions and support issues to <bioperl-l@bioperl.org> 
#
# Cared for by Gabriel Valiente <valiente@lsi.upc.edu>
#
# Copyright Gabriel Valiente
#
# You may distribute this module under the same terms as Perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::Tree::Compatible - Testing compatibility of phylogenetic trees
with nested taxa.

=head1 SYNOPSIS

  use Bio::Tree::Compatible;
  use Bio::TreeIO;
  my $input = Bio::TreeIO->new('-format' => 'newick',
                               '-file'   => 'input.tre');
  my $t1 = $input->next_tree;
  my $t2 = $input->next_tree;

  my ($incompat, $ilabels, $inodes) = Bio::Tree::Compatible::is_compatible($t1,$t2);
  if ($incompat) {
    my %cluster1 = %{ Bio::Tree::Compatible::cluster_representation($t1) };
    my %cluster2 = %{ Bio::Tree::Compatible::cluster_representation($t2) };
    print "incompatible trees\n";
    if (scalar(@$ilabels)) {
      foreach my $label (@$ilabels) {
        my $node1 = $t1->find_node(-id => $label);
        my $node2 = $t2->find_node(-id => $label);
        my @c1 = sort @{ $cluster1{$node1} };
        my @c2 = sort @{ $cluster2{$node2} };
        print "label $label";
        print " cluster"; map { print " ",$_ } @c1;
        print " cluster"; map { print " ",$_ } @c2; print "\n";
      }
    }
    if (scalar(@$inodes)) {
      while (@$inodes) {
        my $node1 = shift @$inodes;
        my $node2 = shift @$inodes;
        my @c1 = sort @{ $cluster1{$node1} };
        my @c2 = sort @{ $cluster2{$node2} };
        print "cluster"; map { print " ",$_ } @c1;
        print " properly intersects cluster";
        map { print " ",$_ } @c2; print "\n";
      }
    }
  } else {
    print "compatible trees\n";
  }

=head1 DESCRIPTION

NB: This module has exclusively class methods that work on Bio::Tree::TreeI
objects. An instance of Bio::Tree::Compatible cannot itself represent a tree,
and so typically there is no need to create one.

Bio::Tree::Compatible is a Perl tool for testing compatibility of
phylogenetic trees with nested taxa represented as Bio::Tree::Tree
objects. It is based on a recent characterization of ancestral
compatibility of semi-labeled trees in terms of their cluster
representations.

A semi-labeled tree is a phylogenetic tree with some of its internal
nodes labeled, and it can represent a classification tree as well as a
phylogenetic tree with nested taxa, with labeled internal nodes
corresponding to taxa at a higher level of aggregation or nesting than
that of their descendents.

Two semi-labeled trees are compatible if their topological
restrictions to the common labels are such that for each node label,
the smallest clusters containing it in each of the trees coincide and,
furthermore, no cluster in one of the trees properly intersects a
cluster of the other tree.

Future extensions of Bio::Tree::Compatible include a
Bio::Tree::Supertree module for combining compatible phylogenetic
trees with nested taxa into a common supertree.

=head1 FEEDBACK

=head2 Mailing Lists

User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to the
Bioperl mailing list.  Your participation is much appreciated.

  bioperl-l@bioperl.org                  - General discussion
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists

=head2 Support 

Please direct usage questions or support issues to the mailing list:

I<bioperl-l@bioperl.org>

rather than to the module maintainer directly. Many experienced and 
reponsive experts will be able look at the problem and quickly 
address it. Please include a thorough description of the problem 
with code and data examples if at all possible.

=head2 Reporting Bugs

Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via the
web:

  https://github.com/bioperl/bioperl-live/issues

=head1 SEE ALSO

=over

=item * Philip Daniel and Charles Semple. Supertree Algorithms for
Nested Taxa. In: Olaf R. P. Bininda-Emonds (ed.) Phylogenetic
Supertrees: Combining Information to Reveal the Tree of Life,
I<Computational Biology>, vol. 4, chap. 7, pp. 151-171. Kluwer (2004).

=item * Charles Semple, Philip Daniel, Wim Hordijk, Roderic
D. M. Page, and Mike Steel: Supertree Algorithms for Ancestral
Divergence Dates and Nested Taxa. Bioinformatics B<20>(15), 2355-2360
(2004).

=item * Merce Llabres, Jairo Rocha, Francesc Rossello, and Gabriel
Valiente: On the Ancestral Compatibility of Two Phylogenetic Trees
with Nested Taxa. J. Math. Biol. B<53>(3), 340-364 (2006).

=back

=head1 AUTHOR - Gabriel Valiente

Email valiente@lsi.upc.edu

=head1 APPENDIX

The rest of the documentation details each of the object methods.

=cut

package Bio::Tree::Compatible;
use strict;

# Object preamble - inherits from Bio::Root::Root

use Set::Scalar;

use base qw(Bio::Root::Root);

=head2 postorder_traversal

 Title   : postorder_traversal
 Usage   : my @nodes = @{ $tree->postorder_traversal }
 Function: Return list of nodes in postorder
 Returns : reference to array of Bio::Tree::Node
 Args    : none

For example, the postorder traversal of the tree
C<(((A,B)C,D),(E,F,G));> is a reference to an array of nodes with
internal_id 0 through 9, because the Newick standard representation
for phylogenetic trees is based on a postorder traversal.

          +---A                    +---0
          |                        |
  +---+---C                +---4---2
  |   |   |                |   |   |
  |   |   +---B            |   |   +---1
  |   |                    |   |
  +   +-------D            9   +-------3
  |                        |
  |     +-----E            |     +-----5
  |     |                  |     |
  +-----+-----F            +-----8-----6
        |                        |
        +-----G                  +-----7

=cut

sub postorder_traversal {
  my($self) = @_;
  my @stack;
  my @queue;
  push @stack, $self->get_root_node;
  while (@stack) {
    my $node = pop @stack;
    push @queue, $node;
    foreach my $child ($node->each_Descendent(-sortby => 'internal_id')) {
      push @stack, $child;
    }
  }
  my @postorder = reverse @queue;
  return \@postorder;
}

=head2 cluster_representation

 Title   : cluster_representation
 Usage   : my %cluster = %{ $tree->cluster_representation }
 Function: Compute the cluster representation of a tree
 Returns : reference to hash of array of string indexed by
           Bio::Tree::Node
 Args    : none

For example, the cluster representation of the tree
C<(((A,B)C,D),(E,F,G));> is a reference to a hash associating an array
of string (descendent labels) to each node, as follows:

  0 --> [A]
  1 --> [B]
  2 --> [A,B,C]
  3 --> [D]
  4 --> [A,B,C,D]
  5 --> [E]
  6 --> [F]
  7 --> [G]
  8 --> [E,F,G]
  9 --> [A,B,C,D,E,F,G]

=cut

sub cluster_representation {
  my ($tree) = @_;
  my %cluster;
  my @postorder = @{ postorder_traversal($tree) };
  foreach my $node ( @postorder ) {
    my @labeled = map { $_->id } grep { $_->id } $node->get_Descendents;
    push @labeled, $node->id if $node->id;
    $cluster{$node} = \@labeled;
  }
  return \%cluster;
}

=head2 common_labels

 Title   : common_labels
 Usage   : my $labels = $tree1->common_labels($tree2);
 Function: Return set of common node labels
 Returns : Set::Scalar
 Args    : Bio::Tree::Tree

For example, the common labels of the tree C<(((A,B)C,D),(E,F,G));>
and the tree C<((A,B)H,E,(J,(K)G)I);> are: C<[A,B,E,G]>.

          +---A                 +---A
          |                     |
  +---+---C             +-------H
  |   |   |             |       |
  |   |   +---B         |       +---B
  |   |                 |
  +   +-------D         +-----------E
  |                     |
  |     +-----E         |   +-------J
  |     |               |   |
  +-----+-----F         +---I
        |                   |
        +-----G             +---G---K

=cut

sub common_labels {
  my($self,$arg) = @_;
  my @labels1 = map { $_->id } grep { $_->id } $self->get_nodes;
  my $common = Set::Scalar->new( @labels1 );
  my @labels2 = map { $_->id } grep { $_->id } $arg->get_nodes;
  my $temp = Set::Scalar->new( @labels2 );
  return $common->intersection($temp);
}

=head2 topological_restriction

 Title   : topological_restriction
 Usage   : $tree->topological_restriction($labels)
 Function: Compute the topological restriction of a tree to a subset
           of node labels
 Returns : Bio::Tree::Tree
 Args    : Set::Scalar

For example, the topological restrictions of each of the trees
C<(((A,B)C,D),(E,F,G));> and C<((A,B)H,E,(J,(K)G)I);> to the labels
C<[A,B,E,G]> are as follows:

          +---A             +---A
          |                 |
  +---+---+             +---+
  |       |             |   |
  |       +---B         |   +---B
  +                     |
  |       +---E         +-------E
  |       |             |
  +-------+             +---+---G
          |
          +---G

=cut

sub topological_restriction {
  my ($tree, $labels) = @_;
  for my $node ( @{ postorder_traversal($tree) } ) {
    unless (ref($node)) { # skip $node if already removed
      my @cluster = map { $_->id } grep { $_->id } $node->get_Descendents;
      push @cluster, $node->id if $node->id;
      my $cluster = Set::Scalar->new(@cluster);
      if ($cluster->is_disjoint($labels)) {
        $tree->remove_Node($node);
      } else {
        if ($node->id and not $labels->has($node->id)) {
          $node->{'_id'} = undef;
        }
      }
    }
  }
}

=head2 is_compatible

 Title   : is_compatible
 Usage   : $tree1->is_compatible($tree2)
 Function: Test compatibility of two trees
 Returns : boolean
 Args    : Bio::Tree::Tree

For example, the topological restrictions of the trees
C<(((A,B)C,D),(E,F,G));> and C<((A,B)H,E,(J,(K)G)I);> to their common
labels, C<[A,B,E,G]>, are compatible. The respective cluster
representations are as follows:

  [A]                  [A]
  [B]                  [B]
  [E]                  [E]
  [G]                  [G]
  [A,B]                [A,B]
  [E,G]                [A,B,E,G]
  [A,B,E,G]

As a second example, the trees C<(A,B);> and C<((B)A);> are
incompatible. Their respective cluster representations are as follows:

  [A]                  [B]
  [B]                  [A,B]
  [A,B]

The reason is, the smallest cluster containing label C<A> is C<[A]> in
the first tree but C<[A,B]> in the second tree.

 +---A         A---B
 |
 +
 |
 +---B

As a second example, the trees C<(((B,A),C),D);> and C<((A,(D,B)),C);>
are also incompatible. Their respective cluster representations are as
follows:

  [A]                  [A]
  [B]                  [B]
  [C]                  [C]
  [D]                  [D]
  [A,B]                [B,D]
  [A,B,C]              [A,B,D]
  [A,B,C,D]            [A,B,C,D]

The reason is, cluster C<[A,B]> properly intersects cluster
C<[B,D]>. There are further incompatibilities between these trees:
C<[A,B,C]> properly intersects both C<[B,D]> and C<[A,B,D]>.

          +---B             +-------A
          |                 |
      +---+             +---+   +---D
      |   |             |   |   |
  +---+   +---A         |   +---+
  |   |                 +       |
  +   +-------C         |       +---B
  |                     |
  +-----------D         +-----------C

=cut

sub is_compatible {
  my ($tree1, $tree2) = @_;
  my $common = $tree1->Bio::Tree::Compatible::common_labels($tree2);
  $tree1->Bio::Tree::Compatible::topological_restriction($common);
  $tree2->Bio::Tree::Compatible::topological_restriction($common);
  my @postorder1 = @{ postorder_traversal($tree1) };
  my @postorder2 = @{ postorder_traversal($tree2) };
  my %cluster1 = %{ cluster_representation($tree1) };
  my %cluster2 = %{ cluster_representation($tree2) };
  my $incompat = 0; # false
  my @labels;
  foreach my $label ( $common->elements ) {
    my $node1 = $tree1->find_node(-id => $label);
    my @labels1 = @{ $cluster1{$node1} };
    my $cluster1 = Set::Scalar->new(@labels1);
    my $node2 = $tree2->find_node(-id => $label);
    my @labels2 = @{ $cluster2{$node2} };
    my $cluster2 = Set::Scalar->new(@labels2);
    unless ( $cluster1->is_equal($cluster2) ) {
      $incompat = 1; # true
      push @labels, $label;
    }
  }
  my @nodes;
  foreach my $node1 ( @postorder1 ) {
    my @labels1 = @{ $cluster1{$node1} };
    my $cluster1 = Set::Scalar->new(@labels1);
    foreach my $node2 ( @postorder2 ) {
      my @labels2 = @{$cluster2{$node2} };
      my $cluster2 = Set::Scalar->new(@labels2);
      if ($cluster1->is_properly_intersecting($cluster2)) {
	$incompat = 1; # true
	push @nodes, $node1, $node2;
      }
    }
  }
  return ($incompat, \@labels, \@nodes);
}

1;