<commit_before>package Bio::EnsEMBL::GlyphSet::ld;
use strict;
use base qw(Bio::EnsEMBL::GlyphSet);
use Sanger::Graphics::Glyph::Poly;
use Sanger::Graphics::Glyph::Text;
use POSIX;
use Data::Dumper;
use Bio::EnsEMBL::Utils::Eprof qw(eprof_start eprof_end eprof_dump); 

use Time::HiRes qw( time );

sub init_label {
  my $self = shift;
  my $key = $self->_key();
  $self->label(new Sanger::Graphics::Glyph::Text({
    'text'      => "LD ($key)",
    'font'      => 'Small',
    'absolutey' => 1,
  }));
}

sub _key { return $_[0]->my_config('key') || 'r2'; }

sub _init {
  my ($self) = @_;
  return unless ($self->strand() == -1);
  my $Config   = $self->{'config'};
  my $only_pop = $Config->{'_ld_population'};
  warn "****[ERROR]: No population defined in config $0" unless $only_pop;

  # Create array of arrayrefs containing $vf_id => $vf in start order
  my $data = $self->{'container'}->get_all_LD_values($only_pop);
  my @snps  = sort { $a->[1]->start <=> $b->[1]->start }
    map  { [ $_ => $data->{'variationFeatures'}{$_} ] }
      keys %{ $data->{'variationFeatures'} };

  my $key = $self->_key();
  my $number_of_snps = scalar(@snps);
  my $pop_adaptor = $self->{'container'}->adaptor->db->get_db_adaptor('variation')->get_PopulationAdaptor;
  my $pop_obj     = $pop_adaptor->fetch_by_dbID($only_pop);
  my $pop_name    = $pop_obj->name;
  my $length      = ($self->{'container'}->length -1)/1000;

  unless( $number_of_snps > 1 ) {
    $self->errorTrack( "No $key linkage data in $length kb window for population $pop_name" );
    return;
  }

  # Print GlyphSet::variation type bars above ld triangle
  my $text_height     = $Config->texthelper->height('Tiny');
  my $TAG_LENGTH      = 10;
  my $yoffset         = $TAG_LENGTH + $text_height;
  my $offset          = $self->{'container'}->start - 1;
  my $colours         = $self->my_config( 'colours');
  foreach my $snp ( @snps ) {
     $self->push( Sanger::Graphics::Glyph::Rect->new({
      'title'     => $snp->[1]->variation_name,
      'height'    => $TAG_LENGTH,
      'x'         => $snp->[1]->start - $offset,
      'y'         => $yoffset - $TAG_LENGTH,
      'width'     => 1,
      'absolutey' => 1,
      'colour'    => $colours->{$snp->[1]->get_consequence_type},
    })); 
  }

  my $height_ppb      = $Config->transform()->{'scalex'};

  # Make grey outline big triangle
  # Sanger::Graphics drawing code automatically scales coords on the x axis
  #   but not on the y.  This means y coords need to be scaled by $height_ppb
  my $first_start = $snps[  0 ]->[1]->start;<commit_msg>*** empty log message ***<commit_after>package Bio::EnsEMBL::GlyphSet::ld;
use strict;
use base qw(Bio::EnsEMBL::GlyphSet);
use Sanger::Graphics::Glyph::Poly;
use Sanger::Graphics::Glyph::Text;
use POSIX;
use Data::Dumper;
use Bio::EnsEMBL::Utils::Eprof qw(eprof_start eprof_end eprof_dump); 

use Time::HiRes qw( time );

sub init_label {
  my $self = shift;
  my $key = $self->_key();
  $self->label(new Sanger::Graphics::Glyph::Text({
    'text'      => "LD ($key)",
    'font'      => 'Small',
    'absolutey' => 1,
  }));
}

sub _key { return $_[0]->my_config('key') || 'r2'; }

sub _init {
  my ($self) = @_;
  return unless ($self->strand() == -1);
  my $Config   = $self->{'config'};
  my $only_pop = $Config->{'_ld_population'};
  warn "****[ERROR]: No population defined in config $0" unless $only_pop;

  # Create array of arrayrefs containing $vf_id => $vf in start order
  my $data = $self->{'container'}->get_all_LD_values($only_pop);
  my @snps  = sort { $a->[1]->start <=> $b->[1]->start }
    map  { [ $_ => $data->{'variationFeatures'}{$_} ] }
      keys %{ $data->{'variationFeatures'} };

  my $key = $self->_key();
  my $number_of_snps = scalar(@snps);
  my $pop_adaptor = $self->{'container'}->adaptor->db->get_db_adaptor('variation')->get_PopulationAdaptor;
  my $pop_obj     = $pop_adaptor->fetch_by_dbID($only_pop);
  my $pop_name    = $pop_obj->name if $pop_obj;
  my $length      = ($self->{'container'}->length -1)/1000;

  unless( $number_of_snps > 1 ) {
    $self->errorTrack( "No $key linkage data in $length kb window for population $pop_name" );
    return;
  }

  # Print GlyphSet::variation type bars above ld triangle
  my $text_height     = $Config->texthelper->height('Tiny');
  my $TAG_LENGTH      = 10;
  my $yoffset         = $TAG_LENGTH + $text_height;
  my $offset          = $self->{'container'}->start - 1;
  my $colours         = $self->my_config( 'colours');
  foreach my $snp ( @snps ) {
     $self->push( Sanger::Graphics::Glyph::Rect->new({
      'title'     => $snp->[1]->variation_name,
      'height'    => $TAG_LENGTH,
      'x'         => $snp->[1]->start - $offset,
      'y'         => $yoffset - $TAG_LENGTH,
      'width'     => 1,
      'absolutey' => 1,
      'colour'    => $colours->{$snp->[1]->get_consequence_type},
    })); 
  }

  my $height_ppb      = $Config->transform()->{'scalex'};

  # Make grey outline big triangle
  # Sanger::Graphics drawing code automatically scales coords on the x axis
  #   but not on the y.  This means y coords need to be scaled by $height_ppb
  my $first_start = $snps[  0 ]->[1]->start;
{'fraction_non_alphanumeric': 0.1923524844720497, 'fraction_numerical': 0.008928571428571428, 'mean_word_length': 3.341196293176074, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 117, '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': '1346168', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1866, 'n_words': 429}