<commit_before>package Bio::EnsEMBL::GlyphSet::contig;
use strict;
use vars qw(@ISA);
use Bio::EnsEMBL::GlyphSet;
@ISA = qw(Bio::EnsEMBL::GlyphSet);
use Sanger::Graphics::Glyph::Rect;
use Sanger::Graphics::Glyph::Poly;
use Sanger::Graphics::Glyph::Space;
use Sanger::Graphics::Glyph::Text;
use Sanger::Graphics::Glyph::Composite;
use Sanger::Graphics::ColourMap;
use Data::Dumper;
$Data::Dumper::Indent=2;
use constant MAX_VIEWABLE_ASSEMBLY_SIZE => 5e6;

sub init_label {
  my ($self) = @_;
  return if( defined $self->{'config'}->{'_no_label'} );
  my $label = new Sanger::Graphics::Glyph::Text({
    'text'      => 'DNA(contigs)',
    'font'      => 'Small',
    'absolutey' => 1,
    'href'      => qq[javascript:X=hw('@{[$self->{container}{_config_file_name_}]}','$ENV{'ENSEMBL_SCRIPT'}','contig')],
    'zmenu'     => {
      'caption'                     => 'HELP',
      '01:Track information...'     => qq[javascript:X=hw(\'@{[$self->{container}{_config_file_name_}]}\',\'$ENV{'ENSEMBL_SCRIPT'}\',\'contig\')]
    }
  });
  $self->label($label);
}

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

  # only draw contigs once - on one strand
  return unless ($self->strand() == 1);
   
  my $vc = $self->{'container'};
  $self->{'vc'} = $vc;
  my $length = $vc->length();

  my $ystart = 3;

  my $gline = new Sanger::Graphics::Glyph::Rect({
    'x'         => 0,
    'y'         => $ystart + 7,
    'width'     => $length,
    'height'    => 0,
    'colour'    => 'grey50',
    'absolutey' => 1,
  });

  $self->push($gline);
  
  my @features = ();
  foreach my $segment (@{$vc->project('seqlevel')||[]}) {
    my $start      = $segment->from_start;
    my $end        = $segment->from_end;
    my $ctg_slice  = $segment->to_Slice;
    my $feature = { 'start' => $start, 'end' => $end, 'name' => $ctg_slice->seq_region_name };
    $feature->{'locations'}{ $ctg_slice->coord_system->name } = [ $ctg_slice->seq_region_name, $ctg_slice->start, $ctg_slice->end, $ctg_slice->strand  ];
    foreach( @{$vc->adaptor->db->get_CoordSystemAdaptor->fetch_all() || []} ) {
      my $path;
      eval { $path = $ctg_slice->project($_->name); };
      next unless(@$path == 1);
      $path = $path->[0]->to_Slice;
      $feature->{'locations'}{$_->name} = [ $path->seq_region_name, $path->start, $path->end, $path->strand ];
    }
    push @features, $feature;
  }
  if( @features) {
    $self->_init_non_assembled_contig($ystart, \@features);
  } else {
    $self->errorTrack("Golden path gap - no contigs to display!");
  }
}

sub _init_non_assembled_contig {
  my ($self, $ystart, $contig_tiling_path) = @_;

  my $vc = $self->{'vc'};
  my $length = $vc->length();
  my $ch = $vc->seq_region_name;

  my $Config = $self->{'config'};

  my $module = ref($self);
     $module = $1 if $module=~/::([^:]+)$/;
  my $threshold_navigation = ($Config->get($module, 'threshold_navigation')|| 2e6)*1001;
  my $navigation     = $Config->get($module, 'navigation') || 'on';
  my $show_navigation = ($length < $threshold_navigation) && ($navigation eq 'on');

  my $cmap     = $Config->colourmap();
 
########
# Vars used only for scale drawing
#
  my $black    = 'black';
  my $red      = 'red';
  my $highlights = join('|', $self->highlights());
     $highlights = $highlights ? "&highlight=$highlights" : '';
  my $clone_based = $Config->get('_settings','clone_based') eq 'yes';
  my $param_string   = $clone_based ? $Config->get('_settings','clone')       : ("chr=". $vc->seq_region_name());
  my $global_start   = $clone_based ? $Config->get('_settings','clone_start') : $vc->start();
  my $global_end     = $global_start + $length - 1;
  my $im_width = $Config->image_width();
#
########

#######
# Draw the Contig Tiling Path
#
  my ($w,$h)   = $Config->texthelper()->real_px2bp('Tiny');    
  my $i = 1;
  my @colours  = qw(contigblue1 contigblue2);
  foreach my $tile ( sort { $a->{'start'} <=> $b->{'start'} } @{$contig_tiling_path} ) {
    my $rend   = $tile->{'end'};
    my $rstart = $tile->{'start'};
    my $rid    = $tile->{'name'};
    my $strand = $tile->{'locations'}->{'chromosome'}->[3];
       $rstart = 1 if $rstart < 1;
       $rend   = $length if $rend > $length;
                
    my $glyph = new Sanger::Graphics::Glyph::Rect({
      'x'         => $rstart - 1,
      'y'         => $ystart+2,
      'width'     => $rend - $rstart+1,
      'height'    => 11,
      'colour'    => $colours[0],
      'absolutey' => 1, 
    });
    push @colours, shift @colours;
    
    if($navigation eq 'on') {
      foreach( qw(chunk supercontig clone scaffold contig) ) {
        if( my $Q = $tile->{'locations'}->{$_} ) {
          $glyph->{'href'} = qq(/@{[$self->{container}{_config_file_name_}]}/$ENV{'ENSEMBL_SCRIPT'}?ch=$ch&region=$Q->[0]);
        }
      }
    }
    my $label = '';
    if($show_navigation) {
      $glyph->{'zmenu'} = {
        'caption' => $rid,
      };
      my $POS = 10;
      foreach( qw(scaffold contig clone supercontig chunk) ) {
        if( my $Q = $tile->{'locations'}->{$_} ) {
          my $name =$Q->[0];<commit_msg>fixed strand<commit_after>package Bio::EnsEMBL::GlyphSet::contig;
use strict;
use vars qw(@ISA);
use Bio::EnsEMBL::GlyphSet;
@ISA = qw(Bio::EnsEMBL::GlyphSet);
use Sanger::Graphics::Glyph::Rect;
use Sanger::Graphics::Glyph::Poly;
use Sanger::Graphics::Glyph::Space;
use Sanger::Graphics::Glyph::Text;
use Sanger::Graphics::Glyph::Composite;
use Sanger::Graphics::ColourMap;
use Data::Dumper;
$Data::Dumper::Indent=2;
use constant MAX_VIEWABLE_ASSEMBLY_SIZE => 5e6;

sub init_label {
  my ($self) = @_;
  return if( defined $self->{'config'}->{'_no_label'} );
  my $label = new Sanger::Graphics::Glyph::Text({
    'text'      => 'DNA(contigs)',
    'font'      => 'Small',
    'absolutey' => 1,
    'href'      => qq[javascript:X=hw('@{[$self->{container}{_config_file_name_}]}','$ENV{'ENSEMBL_SCRIPT'}','contig')],
    'zmenu'     => {
      'caption'                     => 'HELP',
      '01:Track information...'     => qq[javascript:X=hw(\'@{[$self->{container}{_config_file_name_}]}\',\'$ENV{'ENSEMBL_SCRIPT'}\',\'contig\')]
    }
  });
  $self->label($label);
}

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

  # only draw contigs once - on one strand
  return unless ($self->strand() == 1);
   
  my $vc = $self->{'container'};
  $self->{'vc'} = $vc;
  my $length = $vc->length();

  my $ystart = 3;

  my $gline = new Sanger::Graphics::Glyph::Rect({
    'x'         => 0,
    'y'         => $ystart + 7,
    'width'     => $length,
    'height'    => 0,
    'colour'    => 'grey50',
    'absolutey' => 1,
  });

  $self->push($gline);
  
  my @features = ();
  foreach my $segment (@{$vc->project('seqlevel')||[]}) {
    my $start      = $segment->from_start;
    my $end        = $segment->from_end;
    my $ctg_slice  = $segment->to_Slice;
    my $ORI        = $ctg_slice->strand;
    my $feature = { 'start' => $start, 'end' => $end, 'name' => $ctg_slice->seq_region_name };
    $feature->{'locations'}{ $ctg_slice->coord_system->name } = [ $ctg_slice->seq_region_name, $ctg_slice->start, $ctg_slice->end, $ctg_slice->strand  ];
    foreach( @{$vc->adaptor->db->get_CoordSystemAdaptor->fetch_all() || []} ) {
      my $path;
      eval { $path = $ctg_slice->project($_->name); };
      next unless(@$path == 1);
      $path = $path->[0]->to_Slice;
      $feature->{'locations'}{$_->name} = [ $path->seq_region_name, $path->start, $path->end, $path->strand ];
    }
    $feature->{'ori'} = $ORI;
    push @features, $feature;
  }
  if( @features) {
    $self->_init_non_assembled_contig($ystart, \@features);
  } else {
    $self->errorTrack("Golden path gap - no contigs to display!");
  }
}

sub _init_non_assembled_contig {
  my ($self, $ystart, $contig_tiling_path) = @_;

  my $vc = $self->{'vc'};
  my $length = $vc->length();
  my $ch = $vc->seq_region_name;

  my $Config = $self->{'config'};

  my $module = ref($self);
     $module = $1 if $module=~/::([^:]+)$/;
  my $threshold_navigation = ($Config->get($module, 'threshold_navigation')|| 2e6)*1001;
  my $navigation     = $Config->get($module, 'navigation') || 'on';
  my $show_navigation = ($length < $threshold_navigation) && ($navigation eq 'on');

  my $cmap     = $Config->colourmap();
 
########
# Vars used only for scale drawing
#
  my $black    = 'black';
  my $red      = 'red';
  my $highlights = join('|', $self->highlights());
     $highlights = $highlights ? "&highlight=$highlights" : '';
  my $clone_based = $Config->get('_settings','clone_based') eq 'yes';
  my $param_string   = $clone_based ? $Config->get('_settings','clone')       : ("chr=". $vc->seq_region_name());
  my $global_start   = $clone_based ? $Config->get('_settings','clone_start') : $vc->start();
  my $global_end     = $global_start + $length - 1;
  my $im_width = $Config->image_width();
#
########

#######
# Draw the Contig Tiling Path
#
  my ($w,$h)   = $Config->texthelper()->real_px2bp('Tiny');    
  my $i = 1;
  my @colours  = qw(contigblue1 contigblue2);
  foreach my $tile ( sort { $a->{'start'} <=> $b->{'start'} } @{$contig_tiling_path} ) {
    my $rend   = $tile->{'end'};
    my $rstart = $tile->{'start'};
    my $rid    = $tile->{'name'};
    my $strand = $tile->{'ori'};
       $rstart = 1 if $rstart < 1;
       $rend   = $length if $rend > $length;
                
   warn Data::Dumper::Dumper( $tile->{'locations'}," " );
    my $glyph = new Sanger::Graphics::Glyph::Rect({
      'x'         => $rstart - 1,
      'y'         => $ystart+2,
      'width'     => $rend - $rstart+1,
      'height'    => 11,
      'colour'    => $colours[0],
      'absolutey' => 1, 
    });
    push @colours, shift @colours;
    
    if($navigation eq 'on') {
      foreach( qw(chunk supercontig clone scaffold contig) ) {
        if( my $Q = $tile->{'locations'}->{$_} ) {
          $glyph->{'href'} = qq(/@{[$self->{container}{_config_file_name_}]}/$ENV{'ENSEMBL_SCRIPT'}?ch=$ch&region=$Q->[0]);
        }
      }
    }
    my $label = '';
    if($show_navigation) {
      $glyph->{'zmenu'} = {
        'caption' => $rid,
      };
      my $POS = 10;
      foreach( qw(scaffold contig clone supercontig chunk) ) {
        if( my $Q = $tile->{'locations'}->{$_} ) {
          my $name =$Q->[0];
{'fraction_non_alphanumeric': 0.2251792202690759, 'fraction_numerical': 0.00815083963468526, 'mean_word_length': 3.1415209434729565, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 198, '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': '352494', 'n_tokens_mistral': 3911, 'n_tokens_neox': 3748, 'n_words': 714}