<commit_before>package Bio::EnsEMBL::GlyphSet::Vdensity;
use strict;
use warnings;
no warnings 'uninitialized';
use base qw(Bio::EnsEMBL::GlyphSet);

sub _init {
  my ($self) = @_;
  my $Config = $self->{'config'};
  my $chr    = $self->{'extras'}->{'chr'} || $self->{'container'}->{'chr'};

  my $slice_adapt   = $self->{'container'}->{'sa'};
  my $density_adapt = $self->{'container'}->{'da'};

  my $chr_slice = $slice_adapt->fetch_by_region('chromosome', $chr);
  my $v_offset = $Config->container_width() - ($chr_slice->length() || 1);

  my @objs = map { { 'key' => $_,'scale'=>1,'max_value'=>0} }
             @{ $self->my_config('keys')||[] };
  
  my $features = 0;
  my $max_value = 0;


## Pass one - get all the densities from the database...

  foreach(@objs) {
    $_->{'density'}   = $_->{'key'} ? $density_adapt->fetch_Featureset_by_Slice( $chr_slice, $_->{'key'}, 150, 1 ) : undef;
    next unless $_->{'density'};
    $_->{'max_value'} = $_->{'density'}->max_value;
    $max_value = $_->{'max_value'} if $_->{'max_value'} > $max_value;
    $features += $_->{'density'}->size;
  }
  return unless $max_value;

## Pass two - if they are all on the same scale - set scale factor to ratio with highest value..

  if( $self->my_config('same_scale') ) {
    $_->{'scale'} = $_->{'max_value'}/$max_value foreach(@objs);
  }

## Pass three - now rescale all images to fit track width, and get and store values

  foreach(@objs) {
    $_->{'values'} = [];
    next unless $_->{'density'};<commit_msg>support scaling across multiple tracks<commit_after>package Bio::EnsEMBL::GlyphSet::Vdensity;
use strict;
use warnings;
no warnings 'uninitialized';
use base qw(Bio::EnsEMBL::GlyphSet);

sub _init {
  my ($self) = @_;
  my $Config = $self->{'config'};
  my $chr    = $self->{'extras'}->{'chr'} || $self->{'container'}->{'chr'};

  my $slice_adapt   = $self->{'container'}->{'sa'};
  my $density_adapt = $self->{'container'}->{'da'};

  my $chr_slice = $slice_adapt->fetch_by_region('chromosome', $chr);
  my $v_offset = $Config->container_width() - ($chr_slice->length() || 1);

  my @objs = map { { 'key' => $_,'scale'=>1,'max_value'=>0} }
             @{ $self->my_config('keys')||[] };

  my $features = 0;
  my $max_value = 0;

  #get the maximum value from all shared types if we want to scale across multiple tracks
  if ($self->my_config('scale_all')) {
    foreach my $sv (@{ $Config->get_parameter('scale_values') })  {
#      if (grep {$sv eq $_->{'key'}} @objs) {
	my $density = $density_adapt->fetch_Featureset_by_Slice($chr_slice, $sv, 150, 1);
	my $this_max_value = $density->max_value;
	$max_value = $this_max_value if $this_max_value > $max_value;
 #     }
    }
  }


## Pass one - get all the densities from the database...
  foreach(@objs) {
    $_->{'density'}   = $_->{'key'} ? $density_adapt->fetch_Featureset_by_Slice( $chr_slice, $_->{'key'}, 150, 1 ) : undef;
    next unless $_->{'density'};
    $_->{'max_value'} = $_->{'density'}->max_value;
    $max_value = $_->{'max_value'} if $_->{'max_value'} > $max_value;
    $features += $_->{'density'}->size;
  }
  return unless $max_value;

## Pass two - if they are all on the same scale - set scale factor to ratio with highest value..

  if( $self->my_config('same_scale') || $self->my_config('scale_all') ) {
    $_->{'scale'} = $_->{'max_value'}/$max_value foreach(@objs);
  }

## Pass three - now rescale all images to fit track width, and get and store values

  foreach(@objs) {
    $_->{'values'} = [];
    next unless $_->{'density'};
{'fraction_non_alphanumeric': 0.2175886524822695, 'fraction_numerical': 0.00624113475177305, 'mean_word_length': 3.9453015427769986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 78, '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': '4879032', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1243, 'n_words': 298}