<commit_before>package WebComponent::PhyloTree;

# PhyloTree - component to create phylogenetic tree views

use strict;
use warnings;

use base qw( WebComponent );

1;

use Conf;
use GD;
use GD::Polyline;
use WebComponent::WebGD;
use Math::Trig;
use WebColors;

use Data::Dumper;

use constant PI => 4 * atan2 1, 1;
use constant RAD => 2 * PI / 360;

=pod

=head1 NAME

PhyloTree - component to create phylogenetic tree views

=head1 DESCRIPTION

Creates an inline image for a phylogenetic tree view

=head1 METHODS

=over 4


=item * B<new> ()

Called when the object is initialized. Expands SUPER::new.

=cut

sub new {

  my $self = shift->SUPER::new(@_);

  $self->{color_set} = $self->define_colors;
  $self->{colors} = [];
  $self->{image} = undef;
  $self->{nodes} = {};
  $self->{name_level_map} = {};
  $self->application->register_component('Hover', 'PhyloTreeHoverComponent'.$self->id());
  $self->application->register_component('PieChart', 'HoverPie'.$self->id());

  $self->{total_value} = 0;

  $self->{size} = 800;
  $self->{data} = undef;
  $self->{depth} = 4;
  $self->{level_distance} = 40;
  $self->{coloring_method} = "abundance";
  $self->{title_space} = 300;
  $self->{node_size} = 12;

  $self->{show_titles} = 1;
  $self->{shade_titles} = 0;
  $self->{font_size} = 15;
  $self->{show_leaf_weight} = 1;
  $self->{leaf_weight_type} = 'bar';
  $self->{leaf_weight_space} = 0;
  $self->{link_action} = "";
  $self->{color_leafs_only} = 0;
  $self->{enable_click} = 0;
  $self->{sample_names} = [ 'A', 'B' ];
  $self->{reroot_id} = undef;
  $self->{reroot_field} = undef;
  $self->{legend} = "";
  $self->{style} = "";
  $self->{show_sample_colors} = 1;

  $self->{show_tooltip} = 1;

  return $self;
}

=item * B<output> ()

Returns the html output of the PhyloTree component.

=cut

sub output {
  my ($self) = @_;

  my $application = $self->application;
  my $cgi = $application->cgi;

  my $leaf_weight_width = $cgi->param('leaf_weight_width') || 2;
  my $sample_names = $self->sample_names;

  unless (defined($self->data())) {
    return "no data passed to PhyloTree component";
  }

  # parse the input data
  $self->parse_data;

  # check for rerooting
  if ($self->reroot_id) {
    $self->reroot();
  }

  # get the hover component
  my $hover_component = $self->application->component('PhyloTreeHoverComponent'.$self->id());
  
  # initialize image
  $self->image();

  # make space for the titles
  my $title_space = 0;
  if ($self->show_titles) {
    $title_space = $self->title_space;
  }

  # make space for the leaf weights
  my $leaf_weight_space = 0;
  if ($self->show_leaf_weight) {
    $leaf_weight_space = $self->{leaf_weight_space} || $self->level_distance;
  }

  # get font
  my $courier = '/soft/packages/fonts/Verdana.ttf';  

  my $thick = $self->{thick} || 3;
  $self->image->setThickness($thick);

  # get the pie
  my $pie = $application->component("HoverPie".$self->id);
  $pie->show_tooltip(0);
  $pie->size(100);

  # initialize imagemap array
  my @map_spots = ();
  my $depth = $self->depth;
  my $circumference = $self->size * 2 * PI;
  my $level_distance = $self->level_distance * 2;
  my $radius = $self->size();
  my $leafs = $self->nodes_for_level($depth - 1);
  my $num_leafs = scalar(@$leafs) + $self->num_root_level;
  my $leaf_distance = ($circumference - ($circumference % $num_leafs)) / $num_leafs;
  my $curr_pos = 0;
  my $factor = 360 / $num_leafs;
  my $rim = 0;
  my $last_parent = "";
  my $parent_pos = {};<commit_msg>fixed path for font in phylo tree<commit_after>package WebComponent::PhyloTree;

# PhyloTree - component to create phylogenetic tree views

use strict;
use warnings;

use base qw( WebComponent );

1;

use Conf;
use GD;
use GD::Polyline;
use WebComponent::WebGD;
use Math::Trig;
use WebColors;

use Data::Dumper;

use constant PI => 4 * atan2 1, 1;
use constant RAD => 2 * PI / 360;

=pod

=head1 NAME

PhyloTree - component to create phylogenetic tree views

=head1 DESCRIPTION

Creates an inline image for a phylogenetic tree view

=head1 METHODS

=over 4


=item * B<new> ()

Called when the object is initialized. Expands SUPER::new.

=cut

sub new {

  my $self = shift->SUPER::new(@_);

  $self->{color_set} = $self->define_colors;
  $self->{colors} = [];
  $self->{image} = undef;
  $self->{nodes} = {};
  $self->{name_level_map} = {};
  $self->application->register_component('Hover', 'PhyloTreeHoverComponent'.$self->id());
  $self->application->register_component('PieChart', 'HoverPie'.$self->id());

  $self->{total_value} = 0;

  $self->{size} = 800;
  $self->{data} = undef;
  $self->{depth} = 4;
  $self->{level_distance} = 40;
  $self->{coloring_method} = "abundance";
  $self->{title_space} = 300;
  $self->{node_size} = 12;

  $self->{show_titles} = 1;
  $self->{shade_titles} = 0;
  $self->{font_size} = 15;
  $self->{show_leaf_weight} = 1;
  $self->{leaf_weight_type} = 'bar';
  $self->{leaf_weight_space} = 0;
  $self->{link_action} = "";
  $self->{color_leafs_only} = 0;
  $self->{enable_click} = 0;
  $self->{sample_names} = [ 'A', 'B' ];
  $self->{reroot_id} = undef;
  $self->{reroot_field} = undef;
  $self->{legend} = "";
  $self->{style} = "";
  $self->{show_sample_colors} = 1;

  $self->{show_tooltip} = 1;

  return $self;
}

=item * B<output> ()

Returns the html output of the PhyloTree component.

=cut

sub output {
  my ($self) = @_;

  my $application = $self->application;
  my $cgi = $application->cgi;

  my $leaf_weight_width = $cgi->param('leaf_weight_width') || 2;
  my $sample_names = $self->sample_names;

  unless (defined($self->data())) {
    return "no data passed to PhyloTree component";
  }

  # parse the input data
  $self->parse_data;

  # check for rerooting
  if ($self->reroot_id) {
    $self->reroot();
  }

  # get the hover component
  my $hover_component = $self->application->component('PhyloTreeHoverComponent'.$self->id());
  
  # initialize image
  $self->image();

  # make space for the titles
  my $title_space = 0;
  if ($self->show_titles) {
    $title_space = $self->title_space;
  }

  # make space for the leaf weights
  my $leaf_weight_space = 0;
  if ($self->show_leaf_weight) {
    $leaf_weight_space = $self->{leaf_weight_space} || $self->level_distance;
  }

  # get font
  my $courier = "$Conf::ROOT/fonts/Verdana.ttf";  

  my $thick = $self->{thick} || 3;
  $self->image->setThickness($thick);

  # get the pie
  my $pie = $application->component("HoverPie".$self->id);
  $pie->show_tooltip(0);
  $pie->size(100);

  # initialize imagemap array
  my @map_spots = ();
  my $depth = $self->depth;
  my $circumference = $self->size * 2 * PI;
  my $level_distance = $self->level_distance * 2;
  my $radius = $self->size();
  my $leafs = $self->nodes_for_level($depth - 1);
  my $num_leafs = scalar(@$leafs) + $self->num_root_level;
  my $leaf_distance = ($circumference - ($circumference % $num_leafs)) / $num_leafs;
  my $curr_pos = 0;
  my $factor = 360 / $num_leafs;
  my $rim = 0;
  my $last_parent = "";
  my $parent_pos = {};
{'fraction_non_alphanumeric': 0.1801685955136448, 'fraction_numerical': 0.014573510501500214, 'mean_word_length': 3.884856943475227, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 145, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1075010', 'n_tokens_mistral': 2833, 'n_tokens_neox': 2637, 'n_words': 596}