<commit_before>package Bio::EnsEMBL::GlyphSet::blast_hit_btop;

use strict;
use warnings;
no warnings 'uninitialized';

use base qw(Bio::EnsEMBL::GlyphSet);

use Bio::EnsEMBL::Analysis;
use Bio::EnsEMBL::Feature;

sub colour_key {return 'blast';}
sub title {}

sub features {
  my $self = shift;
  my $slice = $self->{'container'};
  my @features; 

  my $tools_object = $self->{'config'}->{'hub'}->{'_core_objects'}->{'tools'};
  return unless $tools_object;

  my $ticket = $tools_object->ticket;

  my @result_lines = @{$tools_object->get_all_hits_from_ticket_in_region($slice, $ticket->ticket_id)};
  my %extra;

  my $analysis = new Bio::EnsEMBL::Analysis (
    -id               => 1,
    -logic_name       => 'blast_search', 
    -db               => undef,
    -db_version       => undef,
    -db_file          => undef, 
    -program          => 'blast',
    -program_version  => undef,
    -program_file     => undef,
    -gff_source       => undef, 
    -gff_feature      => undef,
    -module           => undef,
    -module_version   => undef,
    -parameters       => undef, 
    -created          => undef,
    -display_label    => 'test',
  );

  
  foreach (sort {$a->[1]->{'score'} <=> $b->[1]->{'score'}} @result_lines){

    my $hit = $_->[1];
    next if $hit->{'gori'} ne $self->strand;
    my $id = $_->[0];
    my $coords = $hit->{'g_coords'} || undef;
    my $identity            = sprintf("%.1f", ($hit->{'pident'} /100));
    my $colours = $self->get_colour_scale;  
    my $colour  = $colours->{$identity};
    my $slice_length = $slice->length; 
    my $db_type = $hit->{'db_type'};
    my $method = $self->{'config'}->hub->param('method');
    my $draw_btop = $slice_length < 10000 && $method =~/^blastn/i  ? 1 :undef 

    my $btop;
    if ($draw_btop) { 
      $btop  =  $db_type =~/cdna/i ?  $tools_object->map_btop_to_genomic_coords($hit, $_->[0]) : $hit->{'aln'};
      if ($btop && $hit->{'gori'} ne '1' && $hit->{'db_type'}=~/latest/i){
        $btop = $tools_object->reverse_btop($btop);
      }
    } else {
      if (lc($method) eq 'tblastn' || $db_type =~/latest/i ){
        $coords->[0]->{'start'} = $hit->{'gstart'};
        $coords->[0]->{'end'}   = $hit->{'gend'};
      } 
    }

    my $feature = new Bio::EnsEMBL::Feature (
      -dbID           => $id,
      -slice          => $slice,
      -start          => $hit->{'gstart'},
      -end            => $hit->{'gend'},
      -strand         => $hit->{'gori'},
      -analysis       => $analysis,
    );

     my %feat_info = (    
      btop_string    => $btop,
      coords         => $coords,
      target_strand  => $hit->{'tori'},
      ticket_name    => $ticket->ticket_name,
      colour         => $colour,
      db_type        => $db_type,
    );

    $extra{$id} = \%feat_info;
    push @features, $feature;
  }

  return (\@features,  \%extra);  
}

sub get_colour_scale {
  my $self = shift;
  my %pointer_defaults    = EnsEMBL::Web::ToolsConstants::KARYOTYPE_POINTER_DEFAULTS;<commit_msg>TODO warnings added for later implementation<commit_after>package Bio::EnsEMBL::GlyphSet::blast_hit_btop;

use strict;
use warnings;
no warnings 'uninitialized';

use base qw(Bio::EnsEMBL::GlyphSet);

use Bio::EnsEMBL::Analysis;
use Bio::EnsEMBL::Feature;

sub colour_key {return 'blast';}
sub title {}

sub features {warn "NOT IMPLEMENTED";
  my $self = shift;
  my $slice = $self->{'container'};
  my @features; 

  my $tools_object = $self->{'config'}->{'hub'}->{'_core_objects'}->{'tools'};
  return unless $tools_object;

  my $ticket = $tools_object->ticket;

  my @result_lines = @{$tools_object->get_all_hits_from_ticket_in_region($slice, $ticket->ticket_id)}; # TODO - get_all_hits_in_slice_region
  my %extra;

  my $analysis = new Bio::EnsEMBL::Analysis (
    -id               => 1,
    -logic_name       => 'blast_search', 
    -db               => undef,
    -db_version       => undef,
    -db_file          => undef, 
    -program          => 'blast',
    -program_version  => undef,
    -program_file     => undef,
    -gff_source       => undef, 
    -gff_feature      => undef,
    -module           => undef,
    -module_version   => undef,
    -parameters       => undef, 
    -created          => undef,
    -display_label    => 'test',
  );

  
  foreach (sort {$a->[1]->{'score'} <=> $b->[1]->{'score'}} @result_lines){

    my $hit = $_->[1];
    next if $hit->{'gori'} ne $self->strand;
    my $id = $_->[0];
    my $coords = $hit->{'g_coords'} || undef;
    my $identity            = sprintf("%.1f", ($hit->{'pident'} /100));
    my $colours = $self->get_colour_scale;  
    my $colour  = $colours->{$identity};
    my $slice_length = $slice->length; 
    my $db_type = $hit->{'db_type'};
    my $method = $self->{'config'}->hub->param('method');
    my $draw_btop = $slice_length < 10000 && $method =~/^blastn/i  ? 1 :undef 

    my $btop;
    if ($draw_btop) { 
      $btop  =  $db_type =~/cdna/i ?  $tools_object->map_btop_to_genomic_coords($hit, $_->[0]) : $hit->{'aln'};
      if ($btop && $hit->{'gori'} ne '1' && $hit->{'db_type'}=~/latest/i){
        $btop = $tools_object->reverse_btop($btop);
      }
    } else {
      if (lc($method) eq 'tblastn' || $db_type =~/latest/i ){
        $coords->[0]->{'start'} = $hit->{'gstart'};
        $coords->[0]->{'end'}   = $hit->{'gend'};
      } 
    }

    my $feature = new Bio::EnsEMBL::Feature (
      -dbID           => $id,
      -slice          => $slice,
      -start          => $hit->{'gstart'},
      -end            => $hit->{'gend'},
      -strand         => $hit->{'gori'},
      -analysis       => $analysis,
    );

     my %feat_info = (    
      btop_string    => $btop,
      coords         => $coords,
      target_strand  => $hit->{'tori'},
      ticket_name    => $ticket->ticket_name,
      colour         => $colour,
      db_type        => $db_type,
    );

    $extra{$id} = \%feat_info;
    push @features, $feature;
  }

  return (\@features,  \%extra);  
}

sub get_colour_scale {
  my $self = shift;use Carp qw(croak); croak 'TODO';
  my %pointer_defaults    = ();#EnsEMBL::Web::BlastConstants::KARYOTYPE_POINTER_DEFAULTS; #use blast_pointer_style
{'fraction_non_alphanumeric': 0.1968810916179337, 'fraction_numerical': 0.006172839506172839, 'mean_word_length': 2.3626433642818134, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 143, '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': '7655125', 'n_tokens_mistral': 2358, 'n_tokens_neox': 2211, 'n_words': 423}