<commit_before>package EnsEMBL::Web::Configuration::MultipleLocation;

use strict;
use EnsEMBL::Web::Configuration::Location;
our @ISA = qw( EnsEMBL::Web::Configuration::Location );
use POSIX qw(floor ceil);


## Function to configure contigview

sub dotterview {
  my $self   = shift;
  my $obj    = $self->{object};

  my @loc    = $obj->Locations;
  if( @loc < 2 ) {
    if( my $error_panel = $self->new_panel( '',
      'code' => 'error', 'caption' => 'DotterView - error',
      'content' => '<p>Error we do not have two slices</p>'
    ) ) {
      $error_panel->add_components(qw(
        error_message EnsEMBL::Web::Component::Dotter::dotter_error
      ));
      $self->add_panel( $error_panel );
    }
    return;
  }
  my $primary_species   = $obj->species_defs->SPECIES_COMMON_NAME;
  my $secondary_species = $obj->species_defs->other_species( $loc[1]->real_species, 'SPECIES_COMMON_NAME' );
  if( my $dotter = $self->new_panel( 'Image',
    'code' => 'dotter_#',
    'caption' => "Dotter for $primary_species vs $secondary_species"
  )) {
    $dotter->add_components(qw(
      image EnsEMBL::Web::Component::Dotter::dotterview
    ));
    $self->add_panel( $dotter );
  }
}

sub multicontigview {
  my $self   = shift;
  my $obj    = $self->{object};
  my $q_hash = $obj->generate_query_hash();
  $self->update_configs_from_parameter( 'bottom', 'thjviewbottom' );
  my $last_rendered_panel = undef;

  if( my $ideo = $self->new_panel( 'Image',
    'code' => "ideo_#", 'caption' => "Top level", 'status'  => "panel_ideogram", 'params' => $q_hash
  ) ) {
    $last_rendered_panel = $ideo if $obj->param('panel_ideogram') ne 'off';
    $ideo->add_components(qw(
      image   EnsEMBL::Web::Component::Location::multi_ideogram
    ));
    $self->add_panel( $ideo );
  }
  if( my $over = $self->new_panel( 'Image',
    'code'    => "top_#", 'caption' => "Navigational overview", 'status' => 'panel_top', 'params' => $q_hash
  ) ) {
    if( $obj->param('panel_top') ne 'off' ) {
      my $counter = 0;
      foreach my $loc ( $obj->Locations ) {
        my $max_length = ($obj->species_defs->other_species( $loc->real_species, 'ENSEMBL_GENOME_SIZE' )||1) * 1.001e6;
        my($start,$end) = $self->top_start_end( $loc, $max_length );
        $last_rendered_panel->add_option( "red_box_$counter", [$start,$end] ) if $last_rendered_panel;
        $over->add_option( "start_$counter", $start );
        $over->add_option( "end_$counter",   $end  );
        $counter++;
      }
      $over->add_option( 'red_edge', 'yes' );
      $last_rendered_panel = $over;
    }
    $over->add_components(qw(
      image   EnsEMBL::Web::Component::Location::multi_top
    ));
    $self->add_panel( $over );
  }
  $self->initialize_zmenu_javascript;
  $self->initialize_ddmenu_javascript;
  if( my $bottom = $self->new_panel( 'Image',
    'code'    => "bottom_#", 'caption' => "Detailed View", 'status' => 'panel_bottom', 'params' => $q_hash
  ) ) {
    if( $obj->param('panel_bottom') ne 'off' ) {
      my $counter = 0;
      foreach my $loc ( $obj->Locations ) {
        $last_rendered_panel->add_option( "red_box_$counter",
          [$loc->seq_region_start,$loc->seq_region_end] ) if $last_rendered_panel;
        $counter++;
      }
      $last_rendered_panel = $bottom;
     $bottom->add_option( 'red_edge', 'yes' );
    }
    $bottom->add_components(qw(
      image_menu  EnsEMBL::Web::Component::Location::multi_bottom_menu
      image_nav   EnsEMBL::Web::Component::Location::multi_bottom_nav
      image       EnsEMBL::Web::Component::Location::multi_bottom
    ));
    $self->{page}->content->add_panel( $bottom );
  }
  return;
    
}

sub context_menu {
  my $self = shift;
  $self->SUPER::context_menu();
  my( $p, @sec ) = $self->{object}->Locations;
  next unless @sec;
  my @options;
  my $flag = "contig$self->{'flag'}";

  #remove 'normal' link to contigview for primary species
  my $menu = $self->{'page'}->menu;
  $menu->delete_entry($flag,'cv_link');

  foreach ( $p, @sec ) {
    (my $HR = $_->real_species ) =~s/_/ /;
	my $srtn = $_->seq_region_type_and_name;
    my $title = "@{[$srtn]} @{[$_->thousandify(floor($_->seq_region_start))]}";
    if( floor($_->seq_region_start) != ceil($_->seq_region_end) ) {
      $title .= " - @{[$_->thousandify(ceil($_->seq_region_end))]}";
    }
    push @options, {
      'text' => "... <em>$HR $srtn </em>", 'raw'=>1,
      'href' => sprintf( "/%s/contigview?c=%s:%s;w=%s", $_->real_species, $_->seq_region_name, $_->centrepoint, $_->length ),
      'title' => "$HR $title"
    };
  }

  #add new link to contigview for primary and secondary slices
  $menu->add_entry_after($flag, 'mv_link', 'code' => 'cv',
					'text' => 'Graphical view of...',
					'title' => 'ContigView - genome browser view of primary and secondary slices', 
					'href' => $options[0]{'href'}, 'options'=> \@options );
}
1;<commit_msg>fixed bug<commit_after>package EnsEMBL::Web::Configuration::MultipleLocation;

use strict;
use EnsEMBL::Web::Configuration::Location;
our @ISA = qw( EnsEMBL::Web::Configuration::Location );
use POSIX qw(floor ceil);


## Function to configure contigview

sub dotterview {
  my $self   = shift;
  my $obj    = $self->{object};

  my @loc    = $obj->Locations;
  if( @loc < 2 ) {
    if( my $error_panel = $self->new_panel( '',
      'code' => 'error', 'caption' => 'DotterView - error',
      'content' => '<p>Error we do not have two slices</p>'
    ) ) {
      $error_panel->add_components(qw(
        error_message EnsEMBL::Web::Component::Dotter::dotter_error
      ));
      $self->add_panel( $error_panel );
    }
    return;
  }
  my $primary_species   = $obj->species_defs->SPECIES_COMMON_NAME;
  my $secondary_species = $obj->species_defs->other_species( $loc[1]->real_species, 'SPECIES_COMMON_NAME' );
  if( my $dotter = $self->new_panel( 'Image',
    'code' => 'dotter_#',
    'caption' => "Dotter for $primary_species vs $secondary_species"
  )) {
    $dotter->add_components(qw(
      image EnsEMBL::Web::Component::Dotter::dotterview
    ));
    $self->add_panel( $dotter );
  }
}

sub multicontigview {
  my $self   = shift;
  my $obj    = $self->{object};
  my $q_hash = $obj->generate_query_hash();
  $self->update_configs_from_parameter( 'bottom', 'thjviewbottom' );
  my $last_rendered_panel = undef;

  if( my $ideo = $self->new_panel( 'Image',
    'code' => "ideo_#", 'caption' => "Top level", 'status'  => "panel_ideogram", 'params' => $q_hash
  ) ) {
    $last_rendered_panel = $ideo if $obj->param('panel_ideogram') ne 'off';
    $ideo->add_components(qw(
      image   EnsEMBL::Web::Component::Location::multi_ideogram
    ));
    $self->add_panel( $ideo );
  }
  if( my $over = $self->new_panel( 'Image',
    'code'    => "top_#", 'caption' => "Navigational overview", 'status' => 'panel_top', 'params' => $q_hash
  ) ) {
    if( $obj->param('panel_top') ne 'off' ) {
      my $counter = 0;
      foreach my $loc ( $obj->Locations ) {
        my $max_length = ($obj->species_defs->other_species( $loc->real_species, 'ENSEMBL_GENOME_SIZE' )||1) * 1.001e6;
        my($start,$end) = $self->top_start_end( $loc, $max_length );
        $last_rendered_panel->add_option( "red_box_$counter", [$start,$end] ) if $last_rendered_panel;
        $over->add_option( "start_$counter", $start );
        $over->add_option( "end_$counter",   $end  );
        $counter++;
      }
      $over->add_option( 'red_edge', 'yes' );
      $last_rendered_panel = $over;
    }
    $over->add_components(qw(
      image   EnsEMBL::Web::Component::Location::multi_top
    ));
    $self->add_panel( $over );
  }
  $self->initialize_zmenu_javascript;
  $self->initialize_ddmenu_javascript;
  if( my $bottom = $self->new_panel( 'Image',
    'code'    => "bottom_#", 'caption' => "Detailed View", 'status' => 'panel_bottom', 'params' => $q_hash
  ) ) {
    if( $obj->param('panel_bottom') ne 'off' ) {
      my $counter = 0;
      foreach my $loc ( $obj->Locations ) {
        $last_rendered_panel->add_option( "red_box_$counter",
          [$loc->seq_region_start,$loc->seq_region_end] ) if $last_rendered_panel;
        $counter++;
      }
      $last_rendered_panel = $bottom;
     $bottom->add_option( 'red_edge', 'yes' );
    }
    $bottom->add_components(qw(
      image_menu  EnsEMBL::Web::Component::Location::multi_bottom_menu
      image_nav   EnsEMBL::Web::Component::Location::multi_bottom_nav
      image       EnsEMBL::Web::Component::Location::multi_bottom
    ));
    $self->{page}->content->add_panel( $bottom );
  }
  return;
    
}

sub context_menu {
  my $self = shift;
  $self->SUPER::context_menu();
  my( $p, @sec ) = $self->{object}->Locations;
  return unless @sec;
  my @options;
  my $flag = "contig$self->{'flag'}";

  #remove 'normal' link to contigview for primary species
  my $menu = $self->{'page'}->menu;
  $menu->delete_entry($flag,'cv_link');

  foreach ( $p, @sec ) {
    (my $HR = $_->real_species ) =~s/_/ /;
	my $srtn = $_->seq_region_type_and_name;
    my $title = "@{[$srtn]} @{[$_->thousandify(floor($_->seq_region_start))]}";
    if( floor($_->seq_region_start) != ceil($_->seq_region_end) ) {
      $title .= " - @{[$_->thousandify(ceil($_->seq_region_end))]}";
    }
    push @options, {
      'text' => "... <em>$HR $srtn </em>", 'raw'=>1,
      'href' => sprintf( "/%s/contigview?c=%s:%s;w=%s", $_->real_species, $_->seq_region_name, $_->centrepoint, $_->length ),
      'title' => "$HR $title"
    };
  }

  #add new link to contigview for primary and secondary slices
  $menu->add_entry_after($flag, 'mv_link', 'code' => 'cv',
					'text' => 'Graphical view of...',
					'title' => 'ContigView - genome browser view of primary and secondary slices', 
					'href' => $options[0]{'href'}, 'options'=> \@options );
}

1;
{'fraction_non_alphanumeric': 0.19311053984575835, 'fraction_numerical': 0.002673521850899743, 'mean_word_length': 3.5726375176304654, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 195, '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': '931400', 'n_tokens_mistral': 3671, 'n_tokens_neox': 3511, 'n_words': 656}